step: find oeis sequence starting with smth.

This commit is contained in:
NunoSempere 2023-05-22 20:50:42 -04:00
parent 9aa7714f7c
commit 871419d6e2
7 changed files with 32 additions and 5 deletions

View File

@ -3,6 +3,17 @@
nimble install https://github.com/nim-lang/bigints
https://nimdocs.com/nim-lang/bigints/bigints.html
## Dependencies
The data folder is not included, but its contents are:
.
├── data
│   ├── stripped
│   └── stripped.gz
Where stripped.gz can be found at <https://oeis.org/wiki/JSON_Format,_Compressed_Files>
## To do
- [ ] Exploration of OEIS data

BIN
jit_bayes

Binary file not shown.

View File

@ -6,15 +6,30 @@ import bigints # type: BigInt
let file_path = "./data/stripped"
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
let f = open(file_path)
var line : string
var i = 0
var start = @["1", "2", "3"]
var seqs: seq[seq[string]]
while f.read_line(line):
if i > 3:
let arr = split(line, ",")
let l = arr.len
let nums = arr[1..(l-2)] # .map(proc (x: string): BigInt = initBigInt(x))
# echo nums
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

1
scratchpad/seqs.nim Normal file
View File

@ -0,0 +1 @@
echo @[ "1", "2" ] in @["1", "2", "3" ]