goldbach_conjecture_possibilities.pl 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/perl
  2. # Author: Daniel "Trizen" Șuteu
  3. # License: GPLv3
  4. # Date: 29 July 2015
  5. # Website: https://github.com/trizen
  6. # Calculate the number of combinations for the Goldbach conjecture
  7. # for all the numbers ranging between the two exponents of e.
  8. # As it seems, the number of combinations increases,
  9. # with each power and it seems to go towards infinity.
  10. use 5.010;
  11. use strict;
  12. use warnings;
  13. use ntheory qw(forprimes is_prime pn_primorial nth_prime);
  14. my $primo = 2;
  15. my $count = 1;
  16. my %table;
  17. foreach my $i (1 .. pn_primorial(5)) {
  18. my $n = 2 * $i;
  19. my $partition = $i <= $primo ? $primo : do {
  20. $primo *= nth_prime(++$count);
  21. };
  22. forprimes {
  23. is_prime($n - $_)
  24. && ++$table{$partition};
  25. }
  26. ($n - 2);
  27. }
  28. use Data::Dump qw(pp);
  29. pp \%table;
  30. __END__
  31. Primorial partitions:
  32. {
  33. 2 => 1,
  34. 6 => 8,
  35. 30 => 149,
  36. 210 => 3696,
  37. 2310 => 218701,
  38. 30030 => 20096631
  39. }
  40. Logarithmic:
  41. {
  42. 1 => 2,
  43. 2 => 22,
  44. 3 => 109,
  45. 4 => 558,
  46. 5 => 2883,
  47. 6 => 15523,
  48. 7 => 85590,
  49. 8 => 484304,
  50. 9 => 2819301,
  51. 10 => 16797271,
  52. 11 => 101959227,
  53. }