diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..83e0e17 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +input linguist-vendored=true diff --git a/2015/day-01/input b/2015/day-01/input new file mode 100644 index 0000000..f1311c4 --- /dev/null +++ b/2015/day-01/input @@ -0,0 +1 @@ +()()(()()()(()()((()((()))((()((((()()((((()))()((((())(((((((()(((((((((()(((())(()()(()((()()(()(())(()((((()((()()()((((())((((((()(()(((()())(()((((()))())(())(()(()()))))))))((((((((((((()())()())())(())))(((()()()((((()(((()(()(()()(()(()()(()(((((((())(())(())())))((()())()((((()()((()))(((()()()())))(())))((((())(((()())(())(()))(()((((()())))())((()(())(((()((((()((()(())())))((()))()()(()(()))))((((((((()())((((()()((((()(()())(((((()(()())()))())(((()))()(()(()(()((((()(())(()))(((((()()(()()()(()(((())())(((()()(()()))(((()()(((())())(()(())())()()(())()()()((()(((()(())((()()((())()))((()()))((()()())((((()(()()(()(((()))()(()))))((()(((()()()))(()(((())()(()((()())(()(()()(()())(())()(((()(()())()((((()((()))))())()))((()()()()(())()())()()()((((()))))(()(((()()(((((((())()))()((((()((())()(()())(())()))(()(()())(((((((())))(((()))())))))()))())((())(()()((())()())()))))()((()()())(())((())((((()())())()()()(((()))())))()()))())(()()()(()((((((()()))())()))()(((()(((())((((()()()(()))())()()))))())()))())((())()())(((((())())((())())))(((())(((())(((((()(((((())(()(()())())(()(())(()))(()((((()))())()))))())))((()(()))))())))(((((())()))())()))))()))))(((()))()))))((()))((()((()(()(())()())))(()()()(())()))()((((())))))))(())(()((()()))(()))(()))(()((()))))))()()((((()()))()())()))))))()()()))(()((())(()))((()()()())()(((()((((())())))()((((()(()))))))())))()()())()))(()))))(()())()))))))((())))))))())()))()((())())))(()((()))()))(())))))(()))()())()()))((()(()))()()()()))))())()()))())(())()()))()))((()))))()()(()())))))()()()))((((()))()))))(()(())))(()())))((())())(()))()))))()())))()())()())))))))))()()))))())))((())((()))))())))(((()())))))))(()))()()))(()))()))))()())))))())((((()())))))))())))()()))))))))()))()))))()))))))(())))))))))())))))))))))))))())())((())))))))))()))((())))()))))))))())()(()))))))())))))()()()())()(()()()(()())(()))()()()(()())))())())))()))))())))))))()()()()())(())())()())()))))(()()()()()))))()))())())))((()())()())))()))()))))(()())))()))))))))(((()))()()))))))))))))))))))))(()))(()((()))())))())(()))(()(()(())))))()(()))()))()()))))))))))))()((()())(())())()(())))))())()())((()()))))(()()))))())()(())()))))))))))))))))))))()))(()(()())))))))()()((()))()))))))((())))()))))))))((()))())()()))())()()))((()))())))))))))))(()())()))(())((()(()()))(()())(())))()())(()(())()()))))()))()(()))))))(()))))))))))(()))())))))))))())))))())))(())))))()))))(())())))))))))()(()))))()())))())(()))()())))))))))))))())()()))))()))))))())))))()))))(())(()()()()((())()))())(()))((())()))())())(())(()()))))()))(())()()((())(())))(())))()))())))))))))()(((((())())))(())()))))(())))((()))()(((((((()))))()()))(())))))()(()))))(()()))()))())))))))(()())()))))))))())))(()))())()))(())()((())())()())())(()(()))))()))))))((()())(())()()(()())))()()))(())(())(()))())))()))(()))()()))((((()))))()))((()()()))))()))()))())))(()))()))))(())))()))())()(()))()())))())))))))())))())))()()))))))(()))())())))()))()()())())))))))))))))())))()))(()()))))())))())()(())))())))))))))))))))))()()())())))))()()()((()(()))()()(())()())()))()))))()()()))))))((()))))))))()(()(()((((((()()((()())))))))))))()))())))))((())())(()))())))())))))())()()())(())))())))()())())(())))))))()()(())))()))())))())())())()))))))))()))(()()()())())())))(())())))))))()()())()))))())))())()(())())))))))()())()))(()()(())())))()(()((()()((()()(((((())(()())()))(())()))(())))(())))))))()))()))((()))()))()))))))))()))))))))((()()())(()))(((()))(())))()))((())(((())))()())))())))))((())))))(())())((((((())())()(()))()(()((()())))((())()(()(()))))(())(()()())(())))())((()(((())())))(((()())())))())()(())())((((()()))))())((()))()()()()(())(((((((()()()((()))())(()())))(())())((((()()(()))))()((())))((())()))()(((()))())))()))((()(()))(())(()((((())((((()()(()()))(((())(()))))((((()(()))(())))))((()))(()))((()(((()(()))(()(()((()(())(()(()(()(()()((()))())(((())(()(()))))(()))()()))(())))(())()(((())(()))()((((()()))))())(()))))((())()((((()(((()))())())(((()))()())((())(())())(())()(())()(()()((((((()()))))()()(((()()))))()())()(((()(()))(()(()())(()(()))))(((((()(((())())))))(((((()((()()((())())((((((()(())(()()((()()()()()()()(()()))()(((()))()))(((((((())(((()((()())()((((())(((()(())))()((()(()()()((())((()())()))()))())))())((((((()))(()(()()()))(()((()(()(()))()((()(((()()()((())(((((())()(()))())())((()(())))(()(()())(())((())())())(((()()()(())))))())(()))))))()))))))())((()()()))((()((((((()))(((()((((()()()(((()))())()(()()(((()((()()()()())()()))()()()(()(())((()))))(()))())))))))()(()()(((((())()(()(((((()((()(()()())(()((((((((()((((((())()((((()()()((()((()((((((()))((())))))))())()))((()(()))()(()()(()((())((()()((((((((((((()())(()()()))((((()((((((())(()))())(()()((()()))()(((((((()((()()((((((()(((())))((())))((((((((()()(((((((())(((((()())(((())((())()((((()(((((((()(()(((()((((((()(((()(((((((((((()()((()()(()))((()()(((()(((())))((((())()(()(((())()(()(((())(((((((((((()))())))((((((())((()()((((()())())((((()()))((())(((((()(()()(()()()((())(()((()()((((()(((((()((()(()((((()())((((((()(((((()()(()(()((((())))(())(())(())((((()(()()((((()((((()()((()((((((())))(((((()))))()))(()((((((((()(((())())(((())))(()(()((())(((()((()()(((((()((()()(((())()(()))(((((((())(()(((((()))((()((()((()))(())())((((()((((())()(()))(((()(((((((((((((((())(((((((((()))(((()(()()()()((((((()((())()((((((((()(())(((((((((((()(()((())()((()()(()(()()((((()()((())(()((()()(()()((((()(((((((())))((((())(())()(((()()((()()((((()((()(((()((())(((()()()((((()((((()()(()(()((((((((())(()(((((())(()())(((((((()())()(()((((()((())(()()())((((()()(((()((((())(())(()()(((((((((()()))()(((())(()(()((((((())(()()())(()))()()(((()(((()((())(()(((((((()(()(()((()(((((()(()((()(()((((((()((((()()((((()(((()((())(()(()((()()((((()()(())()(())(((())(()((((((((()())(((((((((()(())()((((())))()))()()(((((()()((((((())(()()(((()(()(((((((()(()(((((((())(())((((()((()(())))((((()()())(()))((()())((((()(((((()(()(())(()(()()())(((((()(((((()((((()()((((((((()()))(()((((((())((((())()(()(((()()()(((()(()(())(())(((((()(())())((((())(())(()(((()(((((())((((())())((()(((((((()(((())(()(()))(((((((((()((()((()()(()((((())(((()((())((((())(()(((()(((()(()((((()(((())(()(((()(()()(()(()((()()(()())(())())((()(()(((()(((()(((()()(((((((((()(((((((((()()(((()(((()())((((()(()(((()()()((())((((((((((())(()(((()((((()())((((()((()))(((()()()(((((()(((((((())((()())(()((((())((((((((())(()((()((((((((((()()((()((()()))(((()())()())()(((()())()()(()(()(((((((())()))(())()))())()()((())()((()((((()((()((())(((((()((((((()(())))(()))())(((()))((()()(()(((()))((((())()(((()))))()(()(())()(((((())(()(()(())(())()((()()()((((()(())((()())(()(()))(()(()(()()(())()()(()((())()((()))))()))((()(()()()()((()())(()))())()(()(((((((((())())((()((()((((((())()((((())(((())((()(()()()((())(()((())(((()((((()()((()(()(((((())()))()((((((()))((())(((()()))(((())(())()))(((((((())(())())()(())(((((()))()((()))()(()()((()()()()()())((((((( diff --git a/2015/day-01/lib.fs b/2015/day-01/lib.fs new file mode 100644 index 0000000..31fb9ab --- /dev/null +++ b/2015/day-01/lib.fs @@ -0,0 +1,40 @@ +: parse-instructions ( ulen addr -- ) + 0 >r + 0 u+do + c@+ + dup 40 = if + r> r> r> + 1 + + >r >r >r + then + 41 = if + r> r> r> + 1 - + >r >r >r + then + loop + drop + r> +; + +256 Constant max-line +Create line-buffer max-line 2 + allot +0 Value fd-in + +: open-input ( addr u -- ) + r/o open-file throw to fd-in +; + +: close-input ( -- ) + fd-in close-file throw +; + +: parse-file ( -- u ) + 0 + begin + line-buffer max-line fd-in read-line throw + while + line-buffer swap parse-instructions + + repeat + drop +; diff --git a/2015/day-01/main.fs b/2015/day-01/main.fs deleted file mode 100755 index d196542..0000000 --- a/2015/day-01/main.fs +++ /dev/null @@ -1,56 +0,0 @@ -#! /usr/bin/env gforth - -: parse-instructions ( ulen addr -- ) - 0 >r - 0 u+do - c@+ - dup 40 = if - r> r> r> - 1 + - >r >r >r - then - 41 = if - r> r> r> - 1 - - >r >r >r - then - loop - r> ; - -s" (())" -parse-instructions -." return: " . cr drop - -s" ()()" -parse-instructions -." return: " . cr drop - -s" (((" -parse-instructions -." return: " . cr drop - -s" (()(()(" -parse-instructions -." return: " . cr drop - -s" ))(((((" -parse-instructions -." return: " . cr drop - -s" ())" -parse-instructions -." return: " . cr drop - -s" ))(" -parse-instructions -." return: " . cr drop - -s" )))" -parse-instructions -." return: " . cr drop - -s" )())())" -parse-instructions -." return: " . cr drop - -bye diff --git a/2015/day-01/stage-1.fs b/2015/day-01/stage-1.fs new file mode 100755 index 0000000..f8ec6e5 --- /dev/null +++ b/2015/day-01/stage-1.fs @@ -0,0 +1,9 @@ +#! /usr/bin/env gforth + +require lib.fs + +s" input" open-input +parse-file . cr +close-input + +bye diff --git a/2015/day-01/test.fs b/2015/day-01/test.fs new file mode 100755 index 0000000..c5f2a3e --- /dev/null +++ b/2015/day-01/test.fs @@ -0,0 +1,18 @@ +#! /usr/bin/env gforth + +require lib.fs +require ../../lib/tap.fs + +8 plan + +s" (())" parse-instructions 0 = ok +s" ()()" parse-instructions 0 = ok +s" (((" parse-instructions 3 = ok +s" (()(()(" parse-instructions 3 = ok +s" ))(((((" parse-instructions 3 = ok +s" ())" parse-instructions -1 = ok +s" ))(" parse-instructions -1 = ok +s" )))" parse-instructions -3 = ok +s" )())())" parse-instructions -3 = ok + +bye diff --git a/lib/tap.fs b/lib/tap.fs new file mode 100644 index 0000000..0d4f70a --- /dev/null +++ b/lib/tap.fs @@ -0,0 +1,12 @@ +Variable test# + +: plan ( n -- ) + ." 1.." . cr +; + +: ok ( f -- ) + 0= if ." not " then + ." ok " + test# dup @ 1+ dup . swap ! + cr +;