diff --git a/docs/examples/pi-montecarlo.md b/docs/examples/pi-montecarlo.md index 8291620c..72a67114 100644 --- a/docs/examples/pi-montecarlo.md +++ b/docs/examples/pi-montecarlo.md @@ -50,10 +50,8 @@ This method of filling coordinate points, counting them, and using the differenc ## Monte Carlo approximation of _pi_ ```blocks -let pir = 0 -let pid = 0 +let pi = 0 let y = 0 -let pin = 0 let x = 0 let r2 = 0 let r = 0 @@ -87,10 +85,7 @@ basic.forever(() => { // r * r * pi => inside / n ~= (r*r*pi) / (4*r*r) ~= // pi / 4 pi = inside / n * 4 // - pin = inside * 4 - // only integer arithmetic here... - pid = pin / n - pir = pin % n + pi = (inside * 4) / n // show results basic.showLeds(` # # # # # @@ -99,6 +94,6 @@ basic.forever(() => { . # . # . . # . . # `) - basic.showString(" " + pid + "." + pir) + basic.showString(" " + pi) }) ``` \ No newline at end of file diff --git a/docs/lessons/catch-the-egg-game/activity.md b/docs/lessons/catch-the-egg-game/activity.md index a67321ea..be2e54e6 100644 --- a/docs/lessons/catch-the-egg-game/activity.md +++ b/docs/lessons/catch-the-egg-game/activity.md @@ -15,7 +15,7 @@ basic.forever(function() { led.plot(eggX, eggY) basic.pause(300) let accX = input.acceleration(Dimension.X) - basketX = 2 + Math.min(2, Math.max(-2, accX / 200)) + basketX = 2 + Math.min(2, Math.max(-2, Math.idiv(accX, 200))) led.plot(basketX, 4) if (eggY > 4) { eggY = -1 @@ -46,7 +46,7 @@ basic.forever(function() { led.plot(eggX1, eggY1) basic.pause(300) let accX = input.acceleration(Dimension.X) - basketX1 = 2 + Math.min(2, Math.max(-2, accX / 200)) + basketX1 = 2 + Math.min(2, Math.max(-2, Math.idiv(accX, 200))) led.plot(basketX1, 4) if (eggY1 > 4) { eggY1 = -1 @@ -85,7 +85,7 @@ basic.forever(function() { led.plot(eggX2, eggY2) basic.pause(300) let accX2 = input.acceleration(Dimension.X) - basketX2 = 2 + Math.min(2, Math.max(-2, accX2 / 200)) + basketX2 = 2 + Math.min(2, Math.max(-2, Math.idiv(accX2, 200))) led.plot(basketX2, 4) if (eggY2 > 4) { eggY2 = -1 @@ -124,7 +124,7 @@ basic.forever(function() { led.plot(eggX3, eggY3) basic.pause(300) let accX3 = input.acceleration(Dimension.X) - basketX3 = 2 + Math.min(2, Math.max(-2, accX3 / 200)) + basketX3 = 2 + Math.min(2, Math.max(-2, Math.idiv(accX3, 200))) led.plot(basketX3, 4) if (eggY3 > 4) { eggY3 = -1