Login Register


[Golfing] Collatz Conjecture filter_list
Author
Message
RE: [Golfing] Collatz Conjecture #30
(08-21-2015, 06:58 PM)Shebang Wrote: Well, firstly, that code doesn't work right Tongue It's printing 10 5 1 for 20, when it should be printing 10 5 16 8 4 2 1. Once you fix that I'll show you a couple ways of shortening it Smile

Oh, I divided the odd number by 3. XD

Code:
#include <iostream> int main(){int n;std::cin >> n;while(n > 1){n%2==0?n/=2:n=n*3+1;std::cout<<n<<" ";}return 0;}

I wonder why n*=3+1 doesn't work, like n=n*3+1 ??? Anyway, it's 114 bytes now.

Code:
#include <iostream> int main(){int n;std::cin>>n;while(n>1){n%2==0?n/=2:n=n*3+1;std::cout<<n<<" ";}return 0;}

110 bytes after removing some spaces. :3
[Image: dHJ4Beo.gif]
Hidden Lesson: Reactions are always instinctive whereas responses are always well thought of.

Reply





Messages In This Thread
[Golfing] Collatz Conjecture - by Eclipse - 08-21-2015, 04:09 PM
RE: [Golfing] Collatz Conjecture - by Shebang - 08-21-2015, 04:26 PM
RE: [Golfing] Collatz Conjecture - by Jolly - 08-21-2015, 04:37 PM
RE: [Golfing] Collatz Conjecture - by Shebang - 08-21-2015, 04:44 PM
RE: [Golfing] Collatz Conjecture - by Jolly - 08-21-2015, 08:46 PM
RE: [Golfing] Collatz Conjecture - by Shebang - 08-21-2015, 09:13 PM
RE: [Golfing] Collatz Conjecture - by Equinox - 08-21-2015, 07:59 PM
RE: [Golfing] Collatz Conjecture - by Shebang - 08-21-2015, 10:45 PM
RE: [Golfing] Collatz Conjecture - by Eclipse - 08-21-2015, 04:27 PM
RE: [Golfing] Collatz Conjecture - by Shebang - 08-21-2015, 04:31 PM
RE: [Golfing] Collatz Conjecture - by Eclipse - 08-21-2015, 04:53 PM
RE: [Golfing] Collatz Conjecture - by lux - 08-21-2015, 06:10 PM
RE: [Golfing] Collatz Conjecture - by OversouL - 08-21-2015, 06:23 PM
RE: [Golfing] Collatz Conjecture - by Shebang - 08-21-2015, 06:58 PM
RE: [Golfing] Collatz Conjecture - by OversouL - 08-22-2015, 09:55 AM
RE: [Golfing] Collatz Conjecture - by Shebang - 08-22-2015, 12:29 PM
RE: [Golfing] Collatz Conjecture - by Eclipse - 08-21-2015, 08:48 PM
RE: [Golfing] Collatz Conjecture - by Jolly - 08-21-2015, 08:57 PM
RE: [Golfing] Collatz Conjecture - by lux - 08-21-2015, 08:58 PM
RE: [Golfing] Collatz Conjecture - by Eclipse - 08-21-2015, 09:04 PM
RE: [Golfing] Collatz Conjecture - by Eclipse - 08-21-2015, 10:55 PM
RE: [Golfing] Collatz Conjecture - by lux - 08-21-2015, 11:14 PM
RE: [Golfing] Collatz Conjecture - by Akane - 08-22-2015, 01:18 AM
RE: [Golfing] Collatz Conjecture - by Shebang - 08-22-2015, 02:42 AM
RE: [Golfing] Collatz Conjecture - by lux - 08-22-2015, 02:51 AM
RE: [Golfing] Collatz Conjecture - by Equinox - 08-22-2015, 03:47 AM
RE: [Golfing] Collatz Conjecture - by lux - 08-22-2015, 03:50 AM
RE: [Golfing] Collatz Conjecture - by Equinox - 08-22-2015, 03:53 AM
RE: [Golfing] Collatz Conjecture - by lux - 08-22-2015, 03:55 AM
RE: [Golfing] Collatz Conjecture - by Equinox - 08-22-2015, 03:58 AM
RE: [Golfing] Collatz Conjecture - by Eclipse - 08-22-2015, 08:35 AM
RE: [Golfing] Collatz Conjecture - by lux - 08-22-2015, 02:48 PM
RE: [Golfing] Collatz Conjecture - by OversouL - 08-22-2015, 04:16 PM
RE: [Golfing] Collatz Conjecture - by lux - 08-22-2015, 03:58 PM
RE: [Golfing] Collatz Conjecture - by Eclipse - 08-22-2015, 04:07 PM
RE: [Golfing] Collatz Conjecture - by lux - 08-22-2015, 04:18 PM
RE: [Golfing] Collatz Conjecture - by OversouL - 08-22-2015, 04:46 PM
RE: [Golfing] Collatz Conjecture - by Eclipse - 08-22-2015, 05:28 PM



Users browsing this thread: 1 Guest(s)