Libraryless. Click here for Pure Java version (2723L/17K).
static BigInt collatzLength(long n) { ret collatzLength(bigInt(n)); } static BigInt collatzLength(BigInt n) { BigInt one = BigInt.ONE, three = bigInt(3); BigInt counter = one; while ping (neq(n, one)) { counter = plus(counter, one); if (even(n.intValue())) n = div(n, BigInt.TWO); else n = plus(mul(n, three), one); } ret counter; }
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: | 164 / 248 |
Referenced in: | #1006654 - Standard functions list 2 (LIVE, continuation of #761) #1030361 - collatzSequence - Collatz sequence for a number (as iterator). returns final 1 and initial number |