step: small refactor.

This commit is contained in:
NunoSempere 2023-05-22 21:12:29 -04:00
parent 871419d6e2
commit 8a593e1eb5
2 changed files with 23 additions and 18 deletions

BIN
jit_bayes

Binary file not shown.

View File

@ -1,10 +1,22 @@
import strutils
import sequtils
import bigints # type: BigInt
# let x = initBigInt("810896098877923596128062174904361421866219158")
let file_path = "./data/stripped"
proc getOEIS(): seq[seq[string]] =
let f = open(file_path)
var i = 0
var line : string
var seqs: seq[seq[string]]
while f.read_line(line):
if i > 3:
let seq = split(line, ",")
let l = seq.len
let nums = seq[1..(l-2)]
seqs.add(nums)
i = i + 1
f.close()
return seqs
var seqs = getOEIS()
proc startsWithSubsequence(xs: seq[string], ys: seq[string]): bool =
if xs.len == 0:
@ -16,20 +28,13 @@ proc startsWithSubsequence(xs: seq[string], ys: seq[string]): bool =
else:
return false
let f = open(file_path)
var line : string
proc getSequencesWithStart(seqs: seq[seq[string]], start: seq[string]): seq[seq[string]] =
var continuations: seq[seq[string]]
for seq in seqs:
if startsWithSubsequence(start, seq):
continuations.add(seq)
return continuations
var i = 0
var start = @["1", "2", "3"]
var seqs: seq[seq[string]]
while f.read_line(line):
if i > 3:
let seq = split(line, ",")
let l = seq.len
let nums = seq[1..(l-2)] # .map(proc (x: string): BigInt = initBigInt(x))
if startsWithSubsequence(start, nums):
seqs.add(nums)
i = i + 1
f.close()
echo seqs
var continuations = getSequencesWithStart(seqs, start)
echo continuations