Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
razorraz15y@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 -
inaba45895yRust 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/... -
SomeNone7115yThis 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.
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)
question