How to resolve the algorithm Hailstone sequence step by step in the zkl programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Hailstone sequence step by step in the zkl programming language
Table of Contents
Problem Statement
The Hailstone sequence of numbers can be generated from a starting positive integer, n by:
The (unproven) Collatz conjecture is that the hailstone sequence for any starting number always terminates.
This sequence was named by Lothar Collatz in 1937 (or possibly in 1939), and is also known as (the):
The hailstone sequence is also known as hailstone numbers (because the values are usually subject to multiple descents and ascents like hailstones in a cloud).
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Hailstone sequence step by step in the zkl programming language
Source code in the zkl programming language
fcn collatz(n,z=L()){ z.append(n); if(n==1) return(z);
if(n.isEven) return(self.fcn(n/2,z)); return(self.fcn(n*3+1,z)) }
[2..0d100_000].pump(Void, // loop n from 2 to 100,000
collatz, // generate Collatz sequence(n)
fcn(c,n){ // if new longest sequence, save length/C, return longest
if(c.len()>n[0]) n.clear(c.len(),c[0]); n}.fp1(L(0,0)))
You may also check:How to resolve the algorithm Loops/Infinite step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm Circles of given radius through two points step by step in the Haskell programming language
You may also check:How to resolve the algorithm Find the intersection of two lines step by step in the Python programming language
You may also check:How to resolve the algorithm String prepend step by step in the J programming language
You may also check:How to resolve the algorithm Euler method step by step in the Sidef programming language