Discuss Scratch

JelliBeens-2
New Scratcher
39 posts

the math not mathing

I remember 2 years ago i made a one line min block. can somebody recreate it?
RL1123
Scratcher
1000+ posts

the math not mathing

This should give the minimum between the two numbers:
a+b-absofa-b/2
Met4Knight
Scratcher
100+ posts

the math not mathing

RL1123 wrote:

This should give the minimum between the two numbers:
a+b-absofa-b/2
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
RL1123
Scratcher
1000+ posts

the math not mathing

Met4Knight wrote:

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
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.

Last edited by RL1123 (Nov. 30, 2024 22:29:57)

Met4Knight
Scratcher
100+ posts

the math not mathing

RL1123 wrote:

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.
oh my am i dumb sorry
JelliBeens-2
New Scratcher
39 posts

the math not mathing

RL1123 wrote:

This should give the minimum between the two numbers:
a+b-absofa-b/2
no i remember it being more optimized, im also looking for a 1 line max block
theashbreather
Scratcher
88 posts

the math not mathing

JelliBeens-2 wrote:

RL1123 wrote:

This should give the minimum between the two numbers:
a+b-absofa-b/2
no i remember it being more optimized, im also looking for a 1 line max block
That line is literally as simple as it can get. There is also a point where too much optimization becomes unreadable.
MultiTasker801
Scratcher
100+ posts

the math not mathing

after a bit of trial-and-error i landed on these
b+a-b*a<b minimuma+b-a*a<b maximum
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)

Powered by DjangoBB