r/dailyprogrammer • u/nottoobadguy • Feb 20 '12
[2/20/2012] Challenge #12 [intermediate]
Create a program that will factor a number. for example:
12 = 2 * 2 * 3
14 = 7 * 2
20 = 2 * 2 * 5
thanks to bears_in_bowlers for todays challenge!
18
Upvotes
2
u/JerMenKoO 0 0 Feb 20 '12
Python:
My solution :]
2
u/eruonna Feb 20 '12
Haskell:
1
u/prophile Feb 20 '12
And done.
1
u/namekuseijin Feb 20 '12
scheme:
1
u/drb226 0 0 Feb 21 '12
Haskell, some efficiency included:
Could be made more efficient by checking only the list of prime numbers. Usage:
1
u/Crystal_Cuckoo Feb 21 '12 edited Feb 21 '12
I remember reading a factorisation function in a ProjectEuler solution in Python, and I've tried to recreate that here from memory:
EDIT: Found it, here is the source code. It's more efficient as candidates doesn't start from 2 every time but from the last factor found (start):
1
u/nothingatall544 Feb 21 '12
Again it's not super awesome, but it gets the job done with a lot of overhead.
Java:
}
1
u/joe_ally Feb 22 '12
Python. I tried to avoid using loops in an attempt to get comfortable with functional style programming.
1
u/[deleted] Feb 22 '12
C++: for some reason, putting std::stringstream uberss in the while loop gave me a working program, while putting it at the beginning of int main() gave me a bunch of two's. Can anyone explain to me why this is? I really fail to understand how iostreams and such work.
1
u/kirk_o Feb 23 '12
C++
1
u/Should_I_say_this Jul 10 '12
1
u/kuzux 0 0 Feb 20 '12
Clojure
0
u/[deleted] Feb 20 '12
[deleted] — view deleted comment