Circular primes


Fork me on GitHub
2014-09-23

Problem 035: Circular primes

Description:

The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime.

There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.

How many circular primes are there below one million?


Solution:
v          // Project Euler - Problem 35


# ... #
. . . .
.  .  .
. . . .
# ... #


>"d"45**:10p5"d"*:20p*00p230p" ":03p13pv    v0             p090<
v                                      <                      _^#`g03g00<
>"X"30g:10g%\10g/3+p30g>30g+:00g\`       #v_$>30g1+:30p:10g%\10g/3+g" "-|
   >90g"= ",,.@        ^p+3/g01\%g01:\" ":<  ^                          <
v                                           <
   ^_v#      !-g00p03:+1g03$<0                                                                                      <
                                              v                                 <                            >     v
>230p>30g::10g%\10g/3+g"X"-#^_:150p1\55+/:!#v_>:2%!#v_:5%!#v_55+/\55+*\50g1+50p:|>$60p:70p>::10g%\10g/3+g" "-|     :
                                            >                                   >^        |p05:-1g05+*g06%+55 \/+55<
                                                                                          >55+70g.,90g1+90p0> $>$   ^
                                                    >      >                                               $^> ^
This program is too big to display/execute here, click [download] to get the full program.

Explanation:

Thats one big sieve, even though not as big as the on in problem 10. Here we needed a way to "rotate" a number: value = value%10 * 10^digitcount + value/10. The rest is standard befunge stuff and trying to optimize it.


Interpreter steps: 176 748 467
Execution time (BefunExec): 27s (6.41 MHz)
Program size: 2000 x 516
Solution: 55
Solved at: 2014-09-23



made with vanilla PHP and MySQL, no frameworks, no bootstrap, no unnecessary* javascript