It is the Sieve but starting at 'n'. Could be optimized by making divisible by 2 a special case.
Junilu Lacar wrote:If I understand the program correctly, it looks like it's trying to map numbers that are multiples of other numbers. Lines 24-27 basically prints out any number that isn't mapped. Seems to me just a more inefficient variation of the Sieve of Eratosthenes
The loop tries each regex in order. When you find a regex that matches then none of the remaining regexs can possibly match so there's no point in checking them. Break causes loop to abort because we already found one.
Babi Astimal Astimal wrote:can you explain the use of breck in your code ?
The question is slightly vague so I was just presenting an alternative that didn't involve making a string.
Campbell Ritchie wrote:If you think that is what the question means, Carey, it means I have completely misunderstood it. Sorry
wayne brandon wrote:Am I correct in saying that you can only return the characters at index 0 and 6 if they being added to a String in the return?