ThePrimeagen / kata-machine

1.28k stars 1.27k forks source link

add: twocrystalball - case of perfect sqrts #37

Open biplobmanna opened 1 year ago

biplobmanna commented 1 year ago

algo shown in FEM - twocrystalballs misses a case where index of first true is perfect sqrt-factor of arr size (arr must be perfect sq size)

adding test case to check for such instance

example:

arr = [ F, F, F, F, F, F, F, F, T, T, T, T, T, T, T ,T]
// size = 16
// jmp = 4
// ix = 8

in the above example, return = -1 based on the algo shown on FEM

error due to classic case of exclusion of the index where true is found in the first for loop (first ball smash)

biplobmanna commented 1 year ago

It might be a little difficult to realize that there is a small issue in the algorithm for two crystal balls as shown in FEM-DSA course, so here's a short snippet show casing the original test cases passing, and the new test case failing for the original code. Also, the modified code passes the newly added test case.

https://user-images.githubusercontent.com/5135690/223803971-04393800-1dc3-44e8-afe6-d99853ec3336.mp4