prog.pl 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/perl
  2. # a(n) is the smallest number that requires at least n distinct repdigits to sum.
  3. # https://oeis.org/A336759
  4. # Known terms:
  5. # 1, 10, 21, 309, 2108, 21996
  6. # Conjecture:
  7. # a(7) = 220884 = 1 + 9 + 99 + 777 + 8888 + 99999 + 111111
  8. # a(8) = 2111105 = 1 + 9 + 99 + 999 + 9999 + 99999 + 888888 + 1111111
  9. use 5.014;
  10. use warnings;
  11. use ntheory qw(:all);
  12. use List::Util qw(uniq);
  13. #my $n = 8;
  14. #my $limit = 21996*11;
  15. #my $limit = 220884*11;
  16. my $n = 8;
  17. my $limit = 2111105;
  18. my @arr;
  19. for my $k (1 .. 9) {
  20. for my $j (1 .. length($limit)) {
  21. push @arr, "$k" x $j;
  22. }
  23. }
  24. @arr = sort { $a <=> $b } uniq(grep { $_ < $limit } @arr);
  25. say "Repdigits: ", join(', ', @arr);
  26. say "Length of array: ", scalar(@arr);
  27. say "Total number of steps required: ", vecsum(map { binomial(scalar(@arr), $_) } 1..$n);
  28. my %seen;
  29. for my $k (1 .. $n) {
  30. say "[$k] Requires ", binomial(scalar(@arr), $k), " steps";
  31. my $local_min = ~0;
  32. forcomb {
  33. my $t = vecsum(@arr[@_]);
  34. if (not exists $seen{$t}) {
  35. if ($k == $n and $t < $local_min) {
  36. say "a($n) <= $t = ", join(' + ', @arr[@_]);
  37. $local_min = $t;
  38. }
  39. $seen{$t} = $k;
  40. }
  41. } scalar(@arr), $k;
  42. }
  43. my $min = ~0;
  44. while (my ($key, $value) = each %seen) {
  45. if ($value == $n) {
  46. if ($key < $min) {
  47. $min = $key;
  48. }
  49. }
  50. }
  51. say "Final result: a($n) >= $min";