Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,55 @@
import strformat
proc iseban(n: int): bool =
if n == 0:
return false
var b = n div 1_000_000_000
var r = n mod 1_000_000_000
var m = r div 1_000_000
r = r mod 1_000_000
var t = r div 1_000
r = r mod 1_000
m = if m in 30..66: m mod 10 else: m
t = if t in 30..66: t mod 10 else: t
r = if r in 30..66: r mod 10 else: r
return {b, m, t, r} <= {0, 2, 4, 6}
echo "eban numbers up to and including 1000:"
for i in 0..100:
if iseban(i):
stdout.write(&"{i} ")
echo "\n\neban numbers between 1000 and 4000 (inclusive):"
for i in 1_000..4_000:
if iseban(i):
stdout.write(&"{i} ")
var count = 0
for i in 0..10_000:
if iseban(i):
inc count
echo &"\n\nNumber of eban numbers up to and including {10000:8}: {count:4}"
count = 0
for i in 0..100_000:
if iseban(i):
inc count
echo &"\nNumber of eban numbers up to and including {100000:8}: {count:4}"
count = 0
for i in 0..1_000_000:
if iseban(i):
inc count
echo &"\nNumber of eban numbers up to and including {1000000:8}: {count:4}"
count = 0
for i in 0..10_000_000:
if iseban(i):
inc count
echo &"\nNumber of eban numbers up to and including {10000000:8}: {count:4}"
count = 0
for i in 0..100_000_000:
if iseban(i):
inc count
echo &"\nNumber of eban numbers up to and including {100000000:8}: {count:4}"

View file

@ -0,0 +1,44 @@
import math, strutils, strformat
#---------------------------------------------------------------------------------------------------
func ebanCount(p10: Natural): Natural =
## Return the count of eban numbers 1..10^p10.
let
n = p10 - p10 div 3
p5 = n div 2
p4 = (n + 1) div 2
result = 5^p5 * 4^p4 - 1
#---------------------------------------------------------------------------------------------------
func eban(n: Natural): bool =
## Return true if n is an eban number (only fully tested to 10e9).
if n == 0: return false
var n = n
while n != 0:
let thou = n mod 1000
if thou div 100 != 0: return false
if thou div 10 notin {0, 3, 4, 5, 6}: return false
if thou mod 10 notin {0, 2, 4, 6}: return false
n = n div 1000
result = true
#———————————————————————————————————————————————————————————————————————————————————————————————————
var s: seq[Natural]
for i in 0..1000:
if eban(i): s.add(i)
echo fmt"Eban to 1000: {s.join("", "")} ({s.len} items)"
s.setLen(0)
for i in 1000..4000:
if eban(i): s.add(i)
echo fmt"Eban 1000..4000: {s.join("", "")} ({s.len} items)"
import times
let t0 = getTime()
for i in 0..21:
echo fmt"ebanCount(10^{i}): {ebanCount(i)}"
echo ""
echo fmt"Time: {getTime() - t0}"