This commit is contained in:
Heavpoot 2021-04-21 10:59:21 +01:00
parent d7379bbb1d
commit 6d67ce11fb
7 changed files with 84 additions and 0 deletions

BIN
ntdb/ntdb.exe Normal file

Binary file not shown.

14
ntdb/ntdb.nimble Normal file
View File

@ -0,0 +1,14 @@
# Package
version = "0.1.0"
author = "Heav"
description = "A database of cellular automata patterns that can be searched in various ways."
license = "GPL-3.0-or-later"
srcDir = "src"
installExt = @["nim"]
bin = @["ntdb"]
# Dependencies
requires "nim >= 1.4.6"

8
ntdb/src/ntdb.nim Normal file
View File

@ -0,0 +1,8 @@
# This is just an example to get you started. A typical hybrid package
# uses this file as the main entry point of the application.
import ntdbpkg/submodule
import ntdbpkg/NTtables
when isMainModule:
echo parseOTfragment("23")

View File

@ -0,0 +1,6 @@
const
# all transitions with N neighbors
OTtable*: array[9, uint64] = [0b1u64 shl 0, 0b11 shl 1, 0b111111 shl 3, 0b1111111111 shl 9, 0b1111111111111 shl 19, 0b1111111111 shl 32, 0b111111 shl 42, 0b11 shl 48, 0b1 shl 50]
# all transitions in alphabetical order. PRs welcome. i haven't done it yet.

View File

@ -0,0 +1,43 @@
import NTtables
import strutils
# represents a 2d isotropic non-totalistic Moore neighborhood CA rule.
# each bit of b/s represents a transition.
# transitions start at the least significant bit and are
# in order from lowest number of neighbors to highest, alphabetically
# (w.r.t hensel notation)
# for example, 5 is "01e"
type INTRule* = object
b*: uint64
s*: uint64
# represents a "range" of rules.
# this is the set of all rules which have all the transitions of
# the minimum rule and no transitions that the maximum rule doesn't have.
# all evolutions of patterns have a rule range like this that they work in.
type INTRange* = object
min*: INTRule
max*: INTRule
# determine if a rule is within a rule range
proc inrange*(rule: INTRule, range: INTRange): bool =
# bitwise check for if all bits in the min rule are present in the given rule
# the parentheses are due to BEE where bee is
# xor somehow having a weird precedence and acting on a boolean without these.
if (rule.b xor range.min.b) != rule.b: result = false
elif (rule.s xor range.min.s) != rule.s: result = false
# bitwise check for if only bits in the max rule are present in the given rule
elif (rule.b or range.max.b) != range.max.b: result = false
elif (rule.s or range.max.s) != range.max.s: result = false
else: result = true
# converts a char digit to all transitions with that amount of neighbors
proc OTc(c: char): uint64 =
result = OTTable[int(c)-48]
# deprecated
proc parseOTfragment*(frag: string): uint64 =
for c in items(frag):
result = result or OTc(c)

1
ntdb/tests/config.nims Normal file
View File

@ -0,0 +1 @@
switch("path", "$projectDir/../src")

12
ntdb/tests/test1.nim Normal file
View File

@ -0,0 +1,12 @@
# This is just an example to get you started. You may wish to put all of your
# tests into a single file, or separate them into multiple `test1`, `test2`
# etc. files (better names are recommended, just make sure the name starts with
# the letter 't').
#
# To run these tests, simply execute `nimble test`.
import unittest
import projectspkg/submodule
test "correct welcome":
check getWelcomeMessage() == "Hello, World!"