Project Euler 315 - Digital Root Clock

Official link:

Thought Process

Almost no thought process involved, the real challenge was finding the bugs in my code. I had 4 functions

  1. LinesNeededSam(number)

    • Given a number this function outputs the amount of transitions to turn the number off

  2. SamClock(startnumber)

    • Given a starting number, N, this function will continuously add LinesNeededSam(N), LinesNeededSam(digit_sum(N)), etc

  3. LinesNeededMax(start, end)

    • This is where the debugging really starts, given 2 integers start, end, this function will output the transitions needed to go from start to end

  4. MaxClock(startnumber)

    • Given a starting number, N, this function goes digit by digit through LinesNeededMax(N), LinesNeededMax(sum_digit(N)), etc

Nothing really smart here, code takes about 20 seconds, we also need to generate the primes first, see my digit sum and prime generation functions in my Essential Functions Page

Interactive Code

Enter 2 integers spereated by a space (a, b)

Code will output transition difference for all primes between a and b