microcalc = iterative functional javascript
eval the code in the block and write the result as argument for the next iteration
(function definitions and arguments are editable)
jklm
// monte-carlo-pi
( ( n=0 , t=0 , pi=0 ) => [ ++n , Math.random()**2 + Math.random()**2 < 1 ? ++t : t , t/n*4] )
( )
// 1_000_000 × monte-carlo-pi
( (n=0,t=0,pi=0)=>[n=n+1_000_000,t=t+[...Array(1_000_000)].map(()=>Math.hypot(Math.random(),Math.random())<1).reduce((a,b)=>a+b),t/n*4] )
( )
// fibonacci sequence
( ( x=1 , y=0 , ...z ) => [ x + y , x , y , ...z ] )
( )
// square root
( ( x=1 , a=prompt() ) => [ ( x + a/x )/2 , a ] )
( )
// golden ratio
( x => 1 + 1/ x )
( 1 )
// wurzelgold
( x => Math.sqrt(1+x) )
( 1 )
// collatz sequence
// try 27 as input
( (x=prompt(),...z) => [ x%2 ? 3*x+1 : x/2 , x, ...z] )
( )
( (x=1) => x+1 )
( )
// prim numbers
( ( n , ...z ) => [ n+2 , z.reduce((a,b)=>(n+2)%b*a,1) ? [ n+2 , z ] : z ]
)
( 1, 2
)
123