Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Binary Search with Chars
- wolfdude999_test
-
12 posts
Binary Search with Chars
I need help with coming up with an algorithm to search through a list of characters. I don't just wan't to cycle through the whole list because as it gets bigger and more parts are added to the program, it will lag. I have considered using a binary search, but I don't know how I would be able to do that with chars due to the fact that Scratch does not have some sort of ASCII interpreter to convert the chars to numbers. Does anyone know what I am talking about and would be able to help?
- andre_rifaut
-
100+ posts
Binary Search with Chars
Just iterate on a string that has all chars. Then when a math is found the index can be the basis of the identifier of the letter.
See function “encode” in http://scratch.mit.edu.ezproxyberklee.flo.org/projects/10087691
See function “encode” in http://scratch.mit.edu.ezproxyberklee.flo.org/projects/10087691
- DadOfMrLog
-
1000+ posts
Binary Search with Chars
Note that you can use greater than and less than on character strings. So ‘abc’>'aaa', for example.
The order is standard ASCII (dunno about other characters, like unicode…?)
But it doesn't matter what order scratch actually uses - just that it's consistent, and you use it consistently everywhere…
If you order your list of strings (or just characters in your case?) then you can perform a binary search on that list very easily.
The order is standard ASCII (dunno about other characters, like unicode…?)
But it doesn't matter what order scratch actually uses - just that it's consistent, and you use it consistently everywhere…
If you order your list of strings (or just characters in your case?) then you can perform a binary search on that list very easily.

- DadOfMrLog
-
1000+ posts
Binary Search with Chars
Oh, one issue though is that scratch treats upper case and lower case as identical.
If you don't care about that then it's fine, otherwise you have to use some hack to get around it…
If you don't care about that then it's fine, otherwise you have to use some hack to get around it…
- wolfdude999_test
-
12 posts
Binary Search with Chars
Thanks! That really helps, I didn't realize that the signs would work with chars Oh, one issue though is that scratch treats upper case and lower case as identical.
If you don't care about that then it's fine, otherwise you have to use some hack to get around it…
- Discussion Forums
- » Help with Scripts
-
» Binary Search with Chars