Login Register


[Golfing] Collatz Conjecture filter_list
Author
Message
RE: [Golfing] Collatz Conjecture #21
(08-21-2015, 10:45 PM)Shebang Wrote: Done! Biggrin

This doesn't count for anything since I added it after the challenge started though Tongue

Code:
i"1>""_2%;_3*1+;2/?p"h

Could you explain how the while loops work?

Reply

RE: [Golfing] Collatz Conjecture #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.
In this case:
  • _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! Smile It's essentially a direct conversion of the Python code.
[Image: CDUAq9d.png]

Reply

RE: [Golfing] Collatz Conjecture #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:
  • 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.
In this case:
  • _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! Smile It's essentially a direct conversion of the Python code.

Exact conversation of the JS code, too.

Reply

RE: [Golfing] Collatz Conjecture #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. Smile

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: r750IJq.png]
[Image: BXqGARG.png]

Reply

RE: [Golfing] Collatz Conjecture #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. Smile

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. Wink

Reply

RE: [Golfing] Collatz Conjecture #26
(08-22-2015, 03:50 AM)Lux Wrote: I don't see you inputting anything. Wink

;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]

Reply

RE: [Golfing] Collatz Conjecture #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/

Reply

RE: [Golfing] Collatz Conjecture #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]

Reply

RE: [Golfing] Collatz Conjecture #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. Smile

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: r750IJq.png]

(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. Tongue

Reply

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







Users browsing this thread: 1 Guest(s)