Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » the math not mathing
- JelliBeens-2
-
39 posts
the math not mathing
I remember 2 years ago i made a one line min block. can somebody recreate it?
- RL1123
-
1000+ posts
the math not mathing
This should give the minimum between the two numbers:
- Met4Knight
-
100+ posts
the math not mathing
it doesn't work, if a = 1 and b = 1 : This should give the minimum between the two numbers:
(a+b) = 2
(a-b) = 0 = abs(a-b)
(a+b)-(abs(a-b)) = 1-0 = 1
((a+b)-(abs(a-b)))/2 = 1/2 ≠ 1
- RL1123
-
1000+ posts
the math not mathing
a+b is 2, but you used it as 1 in the 3rd step. Try it again and you'll see that it's still works. it doesn't work, if a = 1 and b = 1 :
(a+b) = 2
(a-b) = 0 = abs(a-b)
(a+b)-(abs(a-b)) = 1-0 = 1
((a+b)-(abs(a-b)))/2 = 1/2 ≠ 1
Last edited by RL1123 (Nov. 30, 2024 22:29:57)
- Met4Knight
-
100+ posts
the math not mathing
oh my am i dumb sorry a+b is 2, but you used it as 1 in the 3rd step. Try it again and you'll see that it's still works.
- JelliBeens-2
-
39 posts
the math not mathing
no i remember it being more optimized, im also looking for a 1 line max block This should give the minimum between the two numbers:
- theashbreather
-
88 posts
the math not mathing
That line is literally as simple as it can get. There is also a point where too much optimization becomes unreadable.no i remember it being more optimized, im also looking for a 1 line max block This should give the minimum between the two numbers:
- MultiTasker801
-
100+ posts
the math not mathing
after a bit of trial-and-error i landed on these
edit:
i decided to try and test out just how fast it is. this solution and the other solution posted in this thread both take about 9.05 seconds to run 5,000,000 iterations on my machine. i do not believe the solution you select really matters here, so long as you don't use an if-else block which takes about 11 seconds (~22% slower) on my machine. i will continue searching for a faster solution
this doesn't make a whole lot of sense but it is pretty fast
edit:
i decided to try and test out just how fast it is. this solution and the other solution posted in this thread both take about 9.05 seconds to run 5,000,000 iterations on my machine. i do not believe the solution you select really matters here, so long as you don't use an if-else block which takes about 11 seconds (~22% slower) on my machine. i will continue searching for a faster solution
Last edited by MultiTasker801 (Dec. 16, 2024 05:11:38)
- Discussion Forums
- » Help with Scripts
-
» the math not mathing