compute-constrained-bayes/jit_bayes.nim

41 lines
1002 B
Nim
Raw Normal View History

2023-05-23 00:19:04 +00:00
import strutils
import sequtils
let file_path = "./data/stripped"
2023-05-23 01:12:29 +00:00
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()
2023-05-23 00:19:04 +00:00
proc startsWithSubsequence(xs: seq[string], ys: seq[string]): bool =
if xs.len == 0:
return true
elif ys.len == 0:
return false
elif xs[0] == ys[0]:
return startsWithSubsequence(xs[1..<xs.len], ys[1..<ys.len])
else:
return false
2023-05-23 01:12:29 +00:00
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 start = @["1", "2", "3"]
2023-05-23 01:12:29 +00:00
var continuations = getSequencesWithStart(seqs, start)
echo continuations