The Bot Bikeshed
-
16collatz(7) (16) = 16
-
@error_bot eval def hotpo(n) => n % 2 == 0 ? n / 2 : 3 * n + 1 ; def collatz_descend(n, i) => n == 1 ? i : collatz_descend(hotpo(n), i + 1) ; def collatz(n) => collatz_descend(n, 0) ; 1 : collatz(1) ; 2 : collatz(2) ; 3 : collatz(3) ;4 : collatz(4) ; 5 : collatz(5)
-
1 : 0collatz(1) (0) = 02 : 1collatz(2) (1) = 13 : 7collatz(3) (7) = 74 : 2collatz(4) (2) = 25 : 5collatz(5) (5) = 5
-
@error_bot eval def hotpo(n) => n % 2 == 0 ? n / 2 : 3 * n + 1 ; def collatz_descend(n, i) => n <= 1 ? i : collatz_descend(hotpo(n), i + 1) ; def collatz(n) => collatz_descend(n, 0) ; 1 : collatz(1) ; 2 : collatz(2) ; 3 : collatz(3) ;4 : collatz(4) ; 5 : collatz(5) ; 6 : collatz(6) ; 7 : collatz(7) ; 8 : collatz(8) ; 9 : collatz(9)
-
Error: Unknown function: collatz
-
@error_bot eval def hotpo(n) => n % 2 == 0 ? n / 2 : 3 * n + 1 ; def collatz_descend(n, i) => n > 1 ? collatz_descend(hotpo(n), i + 1) : i ; def collatz(n) => collatz_descend(n, 0) ; 1 : collatz(1) ; 2 : collatz(2) ; 3 : collatz(3) ;4 : collatz(4) ; 5 : collatz(5) ; 6 : collatz(6) ; 7 : collatz(7) ; 8 : collatz(8) ; 9 : collatz(9)
-
1 : 0collatz(1) (0) = 02 : 1collatz(2) (1) = 13 : 7collatz(3) (7) = 74 : 2collatz(4) (2) = 25 : 5collatz(5) (5) = 56 : 8collatz(6) (8) = 87 : 16collatz(7) (16) = 168 : 3collatz(8) (3) = 39 : 19collatz(9) (19) = 19
-
@error_bot you didn't want to optimize tail recursion did you? hope not.
-
@error_bot eval def hotpo(n) => n % 2 == 0 ? n / 2 : 3 * n + 1 ; def collatz_descend(n, i) => n < 2 ? i : collatz_descend(hotpo(n), i + 1) ; def collatz(n) => collatz_descend(n, 0) ; 1 : collatz(1) ; 2 : collatz(2) ; 3 : collatz(3) ;4 : collatz(4) ; 5 : collatz(5) ; 6 : collatz(6) ; 7 : collatz(7) ; 8 : collatz(8) ; 9 : collatz(9)
-
1 : 0collatz(1) (0) = 02 : 1collatz(2) (1) = 13 : 7collatz(3) (7) = 74 : 2collatz(4) (2) = 25 : 5collatz(5) (5) = 56 : 8collatz(6) (8) = 87 : 16collatz(7) (16) = 168 : 3collatz(8) (3) = 39 : 19collatz(9) (19) = 19
-
@error_bot alright. I bastardized it - you optimize it.
-
This post is deleted!
-
@error_bot eval def hotpo(n) => n % 2 == 0 ? n / 2 : 3 * n + 1 ; def collatz_descend(n, i) => n < 2 ? i : collatz_descend(hotpo(n), i + 1) ; def collatz(n) => collatz_descend(n, 0) ; collatz(pow(2,31)-1)
-
450collatz(pow(2, 31) (2,147,483,648) - 1 (2,147,483,647)) (450) = 450
-
@error_bot eval def hotpo(n) => n % 2 == 0 ? n / 2 : 3 * n + 1 ; def collatz_descend(n, i) => n < 2 ? i : collatz_descend(hotpo(n), i + 1) ; def collatz(n) => collatz_descend(n, 0) ; collatz(pow(2,62)-1)
-
62collatz(pow(2, 62) (4,611,686,018,427,388,000) - 1 (4,611,686,018,427,388,000)) (62) = 62
-
@error_bot eval pow(2, 62) == pow(2, 62) - 1
-
truepow(2, 62) (4,611,686,018,427,388,000) == pow(2, 62) (4,611,686,018,427,388,000) - 1 (4,611,686,018,427,388,000) (true) = true
-
@error_bot how am I supposed to play final fantasy now?
-
@error_bot eval def hotpo(n) => n % 2 == 0 ? n / 2 : 3 * n + 1 ; def collatz_descend(n, i) => n < 2 ? i : collatz_descend(hotpo(n), i + 1) ; def collatz(n) => collatz_descend(n, 0) ; collatz(pow(2,46)-1)
-
540collatz(pow(2, 46) (70,368,744,177,664) - 1 (70,368,744,177,663)) (540) = 540
-
2 ^ 31
450
2 ^ 47
540
okay math, now you're just fucking with me.
ed. got him with the cantor gambit. i think. serves him right.
-
Fixed some extreme wonkiness with order of operations.
Operations that were meant to have equal precedence didn't, and series of 3 or more operations were getting processed in an interleaved fashion. Some gems were
2+2-2+2=0
and3 * 3 * 3 - 3 = 0
. Both cases were because it was evaluating left pair then right pair then combining.
-
Function arguments are lazily evaluated now. This mostly affects
iif
, but also UDFs that conditionally use parameters.I suppose if the language had side-effects there could be serious weirdness because parameters are evaluated in the order they are used in the function... but since we have mostly pure functions, it shouldn't matter. (
random
isn't pure but its only side effect is to affect the PRNG seed.)
-
You can see which parameters were evaluated and which weren't by the superscript expansion in the spoiler.
@error_bot eval "def f(x,y,z)=>x?y:z; f(true, 2^2, 2^3)"
-
4f(true, 2 ^ 2 (4), 2 ^ 3) (4) = 4
-
@error_bot eval "def f(x,y,z)=>x?y:z; f(true, 2^2, (99^99)d20)"
-
4f(true, 2 ^ 2 (4), (99 ^ 99)d20) (4) = 4
-
Oh right, I wanted to estimate pi with dice. Especially given that there's a constant for it.
So, the method is, roll pairs of d20s offset to center on the origin of a -10 to 10 2D Cartesian space, and see which proportion of them fall within 10 units of the origin (times 4). Yeah?
-
@Gribnit said in The Bot Bikeshed:
Oh right, I wanted to estimate pi with dice. Especially given that there's a constant for it.
So, the method is, roll pairs of d20s offset to center on the origin of a -10 to 10 2D Cartesian space, and see which proportion of them fall within 10 units of the origin (times 4). Yeah?
This sounds like something Matt Parker would do, but I'm
to check if he has already and find the video URL.
-
@PleegWat said in The Bot Bikeshed:
@Gribnit said in The Bot Bikeshed:
Oh right, I wanted to estimate pi with dice. Especially given that there's a constant for it.
So, the method is, roll pairs of d20s offset to center on the origin of a -10 to 10 2D Cartesian space, and see which proportion of them fall within 10 units of the origin (times 4). Yeah?
This sounds like something Matt Parker would do, but I'm
to check if he has already and find the video URL.
This meeting goes one step deeper into the SEP rabbit hole it is headed for and I'll give it a shot. Although the question, "can't someone else do it" does indeed arise.
-
@Gribnit said in The Bot Bikeshed:
So, the method is, roll pairs of d20s offset to center on the origin of a -10 to 10 2D Cartesian space, and see which proportion of them fall within 10 units of the origin (times 4). Yeah?
I'll try writing this in JS. I'm not going to write it in error_bot eval, but don't let me stop you.
-
@error said in The Bot Bikeshed:
I'm not going to write it in error_bot eval, but don't let me stop you.
Well yeah that would be the only way to stop me.
-
I'm not sure what I did wrong but it's approaching 3.76, not 3.14...
-
@error_bot eval "def loop(i)=>i==0?0:sqrt((d21-11)^2+(d21-11)^2)<10?1:0+loop(i-1); loop(20)/20"
-
Expected: "
-
@error_bot eval "def loop(i)=>i==0?0:((d21-11)^2+(d21-11)^2)^(1/2)<10?1:0+loop(i-1); loop(20)/20"
-
Expected: "
-
function d20() { return Math.floor( Math.random() * 20 ) + 1; } function getPoint() { return [ d20() - 10.5, d20() - 10.5 ]; } const COUNT = 1000000; const points = Array.from( { length: COUNT }, getPoint ); const distances = points.map( ( [ x, y ] ) => Math.sqrt( x ** 2 + y ** 2 ) ); const threshold = 10; const closePoints = distances.filter( d => d <= threshold ); const farPoints = distances.filter( d => d > threshold ); console.log( closePoints.length / farPoints.length ); // 3.76?
-
@error said in The Bot Bikeshed:
I'm not sure what I did wrong but it's approaching 3.76, not 3.14...
I bet the grid is too coarse.
-
@PleegWat said in The Bot Bikeshed:
@error said in The Bot Bikeshed:
I'm not sure what I did wrong but it's approaching 3.76, not 3.14...
I bet the grid is too coarse.
The center is wrong, needs to be 0 not -.5
-
@Gribnit said in The Bot Bikeshed:
@PleegWat said in The Bot Bikeshed:
@error said in The Bot Bikeshed:
I'm not sure what I did wrong but it's approaching 3.76, not 3.14...
I bet the grid is too coarse.
The center is wrong, needs to be 0 not .5
Average value of a d20 is 10.5.
-
@PleegWat said in The Bot Bikeshed:
@Gribnit said in The Bot Bikeshed:
@PleegWat said in The Bot Bikeshed:
@error said in The Bot Bikeshed:
I'm not sure what I did wrong but it's approaching 3.76, not 3.14...
I bet the grid is too coarse.
The center is wrong, needs to be 0 not .5
Average value of a d20 is 10.5.
Correct, not relevant here.
-
function d20() { return Math.floor( Math.random() * 20 ) + 1; } function getPoint() { return [ d20() - 9.5, d20() - 9.5 ]; } const COUNT = 100000; const points = Array.from( { length: COUNT }, getPoint ); const distances = points.map( ( [ x, y ] ) => Math.sqrt( x ** 2 + y ** 2 ) ); const threshold = 10; const closePoints = distances.filter( d => d <= threshold ); const farPoints = distances.filter( d => d > threshold ); console.log( closePoints.length / farPoints.length ); /// 3.133597...
-
@Gribnit @error used a d20 and subtracted 10.5. I used a d21 and subtracted 11. I have no idea why my @error_bot eval instruction didn't parse and the error is too vague to find out.
-
@PleegWat said in The Bot Bikeshed:
@Gribnit @error used a d20 and subtracted 10.5. I used a d21 and subtracted 11. I have no idea why my @error_bot eval instruction didn't parse and the error is too vague to find out.
Well, the eval module itself doesn't handle quotes. It's failing on the command parser phase before eval even sees it.
-
Adding some log statements in the command parser.
-
@error said in The Bot Bikeshed:
console.log( closePoints.length / farPoints.length ); /// 3.133597...
You need to divide by a quarter of the total points, not by the far points.
-
function d20() { return Math.floor( Math.random() * 20 ) + 1; } function getPoint() { return [ d20() - 10.5, d20() - 10.5 ]; } const COUNT = 1000000; const points = Array.from( { length: COUNT }, getPoint ); const distances = points.map( ( [ x, y ] ) => Math.sqrt( x ** 2 + y ** 2 ) ); const threshold = 10; const closePoints = distances.filter( d => d <= threshold ); const farPoints = distances.filter( d => d > threshold ); console.log( closePoints.length / points.length * 4 ); // 3.159?
-
@error said in The Bot Bikeshed:
function d20() { return Math.floor( Math.random() * 20 ) + 1; } function getPoint() { return [ d20() - 10.5, d20() - 10.5 ]; } const COUNT = 1000000; const points = Array.from( { length: COUNT }, getPoint ); const distances = points.map( ( [ x, y ] ) => Math.sqrt( x ** 2 + y ** 2 ) ); const threshold = 10; const closePoints = distances.filter( d => d <= threshold ); const farPoints = distances.filter( d => d > threshold ); console.log( closePoints.length / points.length * 4 ); // 3.159?
pretty sure the offset needs to be 10 exactly.