step: find oeis sequence starting with smth.
This commit is contained in:
		
							parent
							
								
									9aa7714f7c
								
							
						
					
					
						commit
						871419d6e2
					
				
							
								
								
									
										11
									
								
								index.md
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								index.md
									
									
									
									
									
								
							|  | @ -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 | ||||
|  |  | |||
|  | @ -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
									
								
							
							
						
						
									
										1
									
								
								scratchpad/seqs.nim
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1 @@ | |||
| echo @[ "1", "2" ] in @["1", "2", "3" ] | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user