step: small refactor.
This commit is contained in:
parent
871419d6e2
commit
8a593e1eb5
|
@ -1,10 +1,22 @@
|
||||||
import strutils
|
import strutils
|
||||||
import sequtils
|
import sequtils
|
||||||
import bigints # type: BigInt
|
|
||||||
|
|
||||||
# let x = initBigInt("810896098877923596128062174904361421866219158")
|
|
||||||
|
|
||||||
let file_path = "./data/stripped"
|
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 =
|
proc startsWithSubsequence(xs: seq[string], ys: seq[string]): bool =
|
||||||
if xs.len == 0:
|
if xs.len == 0:
|
||||||
|
@ -16,20 +28,13 @@ proc startsWithSubsequence(xs: seq[string], ys: seq[string]): bool =
|
||||||
else:
|
else:
|
||||||
return false
|
return false
|
||||||
|
|
||||||
let f = open(file_path)
|
proc getSequencesWithStart(seqs: seq[seq[string]], start: seq[string]): seq[seq[string]] =
|
||||||
var line : 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 start = @["1", "2", "3"]
|
||||||
var seqs: seq[seq[string]]
|
var continuations = getSequencesWithStart(seqs, start)
|
||||||
while f.read_line(line):
|
echo continuations
|
||||||
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
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user