Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,12 @@
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)) }
h27:=collatz(27);
println("Hailstone(27)-->",h27[0,4].concat(","),"...",
h27[-4,*].concat(",")," length ",h27.len());
[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)))
.println();

View file

@ -0,0 +1,12 @@
#!/home/craigd/Bin/zkl
collatz:=Import("hailstone",False,False,False).collatz; // don't run constructor
d:=Dictionary();
[2..0d100_000].pump(Void, // loop n from 2 to 100,000
collatz, // generate Collatz sequence(n)
'wrap(c){ d.incV(c.len()) } // save length
);
println("Number of different lengths: ",d.len());
longest:=(0).max(d.values);
mostFreqLen:=d.filter1('wrap([(k,v)]){ v==longest })[0];
println("Most frequent length: %d; %d sequences of that length."
.fmt(mostFreqLen,longest));