Discuss Scratch

Takeshi64
Scratcher
7 posts

How to find which number is closest to another number?

I looked around and I saw the sorting values page on the wiki talking about bubble sort. I understand the basic logic around how the sorting works, but the script they showed made no sense to me. It doesn't even have to be that method of sorting, any way to find which number is closest to another is fine. Thanks for reading.
drmcw
Scratcher
1000+ posts

How to find which number is closest to another number?

Sorting uses comparison to sort items but finding the closest to a number is different. To find the closest number loop through the list of numbers and find the smallest
absoftargetnumber-testnumber
Takeshi64
Scratcher
7 posts

How to find which number is closest to another number?

Okay, thank you so much for helping! I will try to work the whole system out on my own, hopefully I don't run into too many more problems.
LJayDaGoat
Scratcher
32 posts

How to find which number is closest to another number?

whenclickedsettargetto50setthresholdto5setnumberToCheckto47ifabsofnumberToCheck-target<thresholdthensayThe number is near the target!elsesayThe number is not near the target.```

Last edited by LJayDaGoat (Feb. 24, 2025 15:23:46)

Powered by DjangoBB