Libraryless. Click here for Pure Java version (2723L/17K).
1 | static BigInt collatzLength(long n) { |
2 | ret collatzLength(bigInt(n)); |
3 | } |
4 | |
5 | static BigInt collatzLength(BigInt n) { |
6 | BigInt one = BigInt.ONE, three = bigInt(3); |
7 | BigInt counter = one; |
8 | while ping (neq(n, one)) { |
9 | counter = plus(counter, one); |
10 | if (even(n.intValue())) |
11 | n = div(n, BigInt.TWO); |
12 | else |
13 | n = plus(mul(n, three), one); |
14 | } |
15 | ret counter; |
16 | } |
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
Snippet ID: | #1030359 |
Snippet name: | collatzLength - length of Collatz sequence for a number |
Eternal ID of this version: | #1030359/1 |
Text MD5: | 67d4186c78ee2901fb58ca9c918cbb1f |
Transpilation MD5: | 0da204c11a8b07cd584111aa30ab7dc1 |
Author: | stefan |
Category: | javax / maths |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-12-09 15:03:29 |
Source code size: | 384 bytes / 16 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 163 / 246 |
Referenced in: | [show references] |