prog.sf 556 B

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/ruby
  2. # Least k such that the decimal representation of 2^k contains all possible n-digit strings
  3. # https://oeis.org/A360656
  4. # Known terms:
  5. # 68, 975, 16963, 239697, 2994863
  6. func a(n, from=0) {
  7. var v = gather {
  8. @(0..9).variations_with_repetition(n, {|*a|
  9. take(a.join)
  10. })
  11. }
  12. for k in (from..Inf) {
  13. var t = (2**k -> to_s)
  14. if (v.all { t.contains(_) }) {
  15. return k
  16. }
  17. }
  18. }
  19. for n in (1..100) {
  20. say "a(#{n}) = #{a(n)}"
  21. }
  22. __END__
  23. a(1) = 68
  24. a(2) = 975
  25. a(3) = 16963