We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Sorry for asking old topic but does anyone finish this challenge by ruby?
I can't finish when set the max number is 5*10^6, seem like the speed of ruby is not enough :(
this is my code, please help me find out :(
# Enter your code here. Read input from STDIN. Print output to STDOUTt=gets.strip.to_idefstepsnstart=0loopdobreakifn==1ifn%2==0n=n/2elsen=3*n+1endstart+=1endstartendnumbers=[1,1,2]max=5000000current_number=2current_step=1(3..max).eachdo|number|pnumberstep=steps(number)ifstep>=current_stepcurrent_number=numbercurrent_step=stependnumbers<<current_numberendt.timesdo|time|n=gets.strip.to_ipnumbers[n]end
Project Euler #14: Longest Collatz sequence
You are viewing a single comment's thread. Return to all comments →
Sorry for asking old topic but does anyone finish this challenge by ruby? I can't finish when set the max number is 5*10^6, seem like the speed of ruby is not enough :( this is my code, please help me find out :(