Hacker News new | past | comments | ask | show | jobs | submit login

What it is really doing is checking if the length of a string is a prime number or not. And as coded, it is checking specifically if the length of a string consisting of some number of '1' characters is prime or not.



I've done some Codewars problems where you have to write a regex to check whether an input number is divisible by a specific number, so I was really interested to see how that would work for primes.

Nope, it's just playing with lengths.


- it is turning the number into a string of 1s 3 => 111 4 => 1111 and so on

- then trying to simulate divisibility test by trying to find perfect groups of '11' to simulate division by 2 failing which (that is the backtracking part) and trying find perfect groups of '111' to simulate division by 3 and so on...

Clever but very inefficient




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: