this post was submitted on 27 Jul 2023
7 points (76.9% liked)

Julia

272 readers
2 users here now

founded 2 years ago
MODERATORS
 

I just tried my first problem on Codewars and realised: This solution feels like cheating

top 5 comments
sorted by: hot top controversial new old
[–] verstra 6 points 1 year ago (1 children)

What's the solution in Julia?

[–] [email protected] 3 points 1 year ago (1 children)

I first did something with findfirst, which needed some bounds checks. Then I saw another answer and they used searchsortedfirst which is just it ... Even the documentation reads like the problem description

[–] verstra 1 points 1 year ago (1 children)

Ah so the library is just made for problems like this. Who would have thought :)

[–] [email protected] 2 points 1 year ago (1 children)

Naahh… searchsortedfirst is simply faster than other search algorithms (in this specific case). Extremely useful in many applications.It ist there because Julia cares about efficiency

[–] [email protected] 1 points 1 year ago

This helped me realize how much this aligns with my problems (and I guess the spirit of this test problem). Sometimes you have special knowledge of your data and can use much more efficient functions that are just there in Julia.