1
razorraz
21d

I need help in this?
Create a function name divisers/Divisers that makes an inter n>1 and returns an array with all of the interger’s divisors(except for 1 and the number itself), from smallest to largest. If the number is prime return the string ‘(interger) is prime’ (null in C#)(use Either string a in Haskell and Result<Vec<u32>, String> in Rust)

Comments
  • 0
    What have you tried so far?
  • 0
    I need help in this?
  • 0
    @tekashi I have tried this
    def divisers (n)
    from math import sqrt
    max_n = int(sqrt(n) + 1)

    divs = [(I, n / I) for I in xrange(2, max_n) if n % i ==0]

    if len(divs) ==0;
    return %d is prime % n
    else;
    return sorted(set(div for div_pair in divs in div_pair]))
    End
  • 0
    Rust isn't functional right? So by the sound of it you're about to split a number into it's prime factors.

    Basically what you wanna do is take the number, ckeck if you can divide it by two, then ever time you can you add 2 to the result array and then divide the number by 2. Then when you can't divide by 2 any more you (make a new loop where you) check if you can divide by three (then 5, 7, 9, all of the uneven numbers until the iterating number is less than the number you're checking), where you check for division by three (then 5, 7, etc) and if that is possible you divide the number by three and add three to the result array.

    Or if you want to cheat and look at code https://github.com/inabahare/...
  • 1
    This is devRant, not devHelp… that said, please search for Euler problem 3, it is very similar, and a solution to that is quite trivial to modify so it does what you want. Solutions in all sorts of languages can be easily found.
Add Comment