modular_tetration.sf 538 B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/ruby
  2. # Modular computation of the tetration operation, using Euler's theorem.
  3. # See also:
  4. # https://en.wikipedia.org/wiki/Tetration
  5. # https://www.youtube.com/watch?v=vzhzwLp_qrs
  6. func tetration(a, b, m) {
  7. return 0 if (m == 1)
  8. return 1 if (b == 0)
  9. powmod(a, __FUNC__(a, b-1, m.euler_phi), m)
  10. }
  11. for n in (2 .. 1000) {
  12. var k = n.prime
  13. if (tetration(10, 10, k) + 23 % k == 0) {
  14. say "#{'%3s' % k} | (10∆10 + 23)"
  15. }
  16. }
  17. __END__
  18. 3 | (10∆10 + 23)
  19. 13 | (10∆10 + 23)
  20. 673 | (10∆10 + 23)