RE: [Golfing] Collatz Conjecture 08-22-2015, 01:18 AM
#21
| [Golfing] Collatz Conjecture filter_list | |
RE: [Golfing] Collatz Conjecture 08-22-2015, 02:42 AM
#22
(08-22-2015, 01:18 AM)Akane Wrote: Could you explain how the while loops work?
Sure!
So, in this instance, h is the character that triggers the while-loop. What it does is pop off the top three items from the stack:
- A string, which is the body of the while loop.
- A string, which is the condition the while loop executes on
- A value, which is passed to the condition and body.
- _2%;_3*1+;2/?p is the body of the loop.
- 1> is the condition
- i is the value (coming from user input in this case).
So, what this code does is:
- Take user input.
- While this user input is greater than 1:
- Check if it's divisible by 2.
- If so, divide it by 2.
- If not, multiply by 3 and add 1.
- Print out the result.
- Check if it's divisible by 2.
That's basically it!
It's essentially a direct conversion of the Python code.
![[Image: CDUAq9d.png]](http://i.imgur.com/CDUAq9d.png)
RE: [Golfing] Collatz Conjecture 08-22-2015, 02:51 AM
#23
(08-22-2015, 02:42 AM)Shebang Wrote: Sure!
So, in this instance, h is the character that triggers the while-loop. What it does is pop off the top three items from the stack:In this case:
- A string, which is the body of the while loop.
- A string, which is the condition the while loop executes on
- A value, which is passed to the condition and body.
- _2%;_3*1+;2/?p is the body of the loop.
- 1> is the condition
- i is the value (coming from user input in this case).
So, what this code does is:
- Take user input.
- While this user input is greater than 1:
- Check if it's divisible by 2.
- If so, divide it by 2.
- If not, multiply by 3 and add 1.
- Print out the result.
That's basically it!It's essentially a direct conversion of the Python code.
Exact conversation of the JS code, too.
RE: [Golfing] Collatz Conjecture 08-22-2015, 03:47 AM
#24
I know this isn't exactly the smallest, and is quite large compared to some other entries, but I am entering since this is sort of a unique entry. I used the Wolfram language, which breaks off from both the Python and NodeJS entries. 
Also 69 byte master race!

Also 69 byte master race!
Code:
n=10;While[1!=n,Print[n];n=Part[{n/2,(n*3)+1},Mod[n,2]+1]]; Print[n];
![[Image: BXqGARG.png]](https://i.imgur.com/BXqGARG.png)
RE: [Golfing] Collatz Conjecture 08-22-2015, 03:50 AM
#25
(08-22-2015, 03:47 AM)Stocking Wrote: I know this isn't exactly the smallest, and is quite large compared to some other entries, but I am entering since this is sort of a unique entry. I used the Wolfram language, which breaks off from both the Python and NodeJS entries.
Also 69 byte master race!
Code:n=10;While[1!=n,Print[n];n=Part[{n/2,(n*3)+1},Mod[n,2]+1]]; Print[n]
[img]-snip-[/img]
(08-21-2015, 04:09 PM)eclipse Wrote: from the input
I don't see you inputting anything.
RE: [Golfing] Collatz Conjecture 08-22-2015, 03:53 AM
#26
(08-22-2015, 03:50 AM)Lux Wrote: I don't see you inputting anything.
;w; Completely missed that part
(I don't know how to get input from Wolfram, and honestly don't care to learn, so I guess that means I'm disqualified. meh)
![[Image: BXqGARG.png]](https://i.imgur.com/BXqGARG.png)
RE: [Golfing] Collatz Conjecture 08-22-2015, 03:55 AM
#27
(08-22-2015, 03:53 AM)Stocking Wrote: ;w;
(I don't know how to get input from Wolfram, and honestly don't care to learn, so I guess that means I'm disqualified. meh)
It should still be considered, just a penalty applied. (Such as +10 bytes to score).
Go fast Haskell))) https://www.haskell.org/
RE: [Golfing] Collatz Conjecture 08-22-2015, 03:58 AM
#28
(08-22-2015, 03:55 AM)Lux Wrote: It should still be considered, just a penalty applied. (Such as +10 bytes to score).
Go fast Haskell))) https://www.haskell.org/
I guess technically it would be input, since the Wolfram programming cloud itself is in an interactive-mode type of input, though still not the input wanted in this challenge.
![[Image: BXqGARG.png]](https://i.imgur.com/BXqGARG.png)
RE: [Golfing] Collatz Conjecture 08-22-2015, 08:35 AM
#29
(08-22-2015, 03:47 AM)Stocking Wrote: I know this isn't exactly the smallest, and is quite large compared to some other entries, but I am entering since this is sort of a unique entry. I used the Wolfram language, which breaks off from both the Python and NodeJS entries.
Also 69 byte master race!
Code:n=10;While[1!=n,Print[n];n=Part[{n/2,(n*3)+1},Mod[n,2]+1]]; Print[n];
(08-22-2015, 03:55 AM)Lux Wrote: It should still be considered, just a penalty applied. (Such as +10 bytes to score).
Go fast Haskell))) https://www.haskell.org/
I agree with Lux, but your program isn't as small as Shebang's so you wouldn't win anyway, and I'd hate to add points to 69, so I'll accept your solution as-is.
RE: [Golfing] Collatz Conjecture 08-22-2015, 09:55 AM
#30
(08-21-2015, 06:58 PM)Shebang Wrote: Well, firstly, that code doesn't work rightIt'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
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]](http://i.imgur.com/dHJ4Beo.gif)
Hidden Lesson: Reactions are always instinctive whereas responses are always well thought of.
Users browsing this thread: 1 Guest(s)



![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)






















