<jupyter_start><jupyter_text>Algostudio Exercise<jupyter_code>import kotlin.random.Random
val range = (1..27 / 2)
range
// Multiplying two whole numbers gives a product. The numbers that we multiply are the factors of the product.
fun factorsOfNumber(num: Int): MutableSet<Int> {
    //set not Allowed Duplicate element
    val factors = mutableSetOf<Int>()
    if (num < 1)
        return factors
    (1..num / 2) // odd divided by odd CANNOT be even, should ok for this
        .filter { num % it == 0 } // filter each number is divisible by num
        .forEach { factors.add(it) } // add each filtered num to set
    factors.add(num)
    return factors
}

factorsOfNumber(28)
// Prime factors are factors of a number that are, themselves, prime numbers.
fun getPrimeFactors(number: Int): MutableSet<Int> {
    //set not Allowed Duplicate element
    val primeFactors = mutableSetOf<Int>()
    var state = number
    var i = 2 // Start with first prime number
    while (i <= state) {
        if (state % i == 0) { // when divisible by 2 try to divided again by 2 and if not increment i with 1
            // Add prime factor in Hash Set
            primeFactors.add(i)
            state /= i // change state number because divisible by i
            i--
        }
        i++
    }
    return primeFactors
}

getPrimeFactors(28)
// A perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself.
fun isPerfectNumber(number: Int): Int {
    var temp = 0 // sum of factor
    for (i in 1..number / 2) { // odd divided by odd CANNOT be even, should ok for this
        if (number % i == 0) {
            temp += i // add temporary number with number factor
        }
    }
    return temp
}

isPerfectNumber(28) == 28
// read input
// loop array of input
// check each item in array
// if item i == isPerfectNumber(item[i]) then  perfect
// if item i == item[i] - isPerfectNumber(item[i]) then almost
// else not perfect or almost

val randomValues = List(10) { Random.nextInt(0, 100) }
randomValues.forEach {
    when (it) {
        isPerfectNumber(it) -> println("$it Perfect") // 2n - 1
        isPerfectNumber(it) + 1 -> println("$it Almost") // n - 1
        else -> println("$it Null")
    }
}<jupyter_output>58 Null
88 Null
5 Null
43 Null
73 Null
12 Null
29 Null
22 Null
41 Null
54 Null
{'fraction_non_alphanumeric': 0.09923664122137404, 'fraction_numerical': 0.022900763358778626, 'mean_word_length': 2.4589442815249267, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '550688', 'license': 'MIT', 'n_tokens_mistral': 759, 'n_tokens_neox': 710, 'n_words': 295, 'path': 'kotlin exercises/Exercise (Algostudio).ipynb', 'repo_name': 'indramahkota/learn-kotlin', 'size': '2358'}