1
0
Fork 0

Initial commit

main
Bubbler-4 2020-11-29 16:22:10 +09:00 committed by Michael Raitza
commit f996bda53d
306 changed files with 16739 additions and 0 deletions

6
.editorconfig Normal file
View File

@ -0,0 +1,6 @@
root = true
[*]
indent_style = space
indent_size = 2
charset = utf-8

7
.factor-rc Normal file
View File

@ -0,0 +1,7 @@
USING: parser vocabs vocabs.loader sequences namespaces tools.scaffold
environment ;
vocab-roots [ "." suffix ] change
{ "sequences.extras" "assocs.extras" "grouping.extras"
"tools.problem-solving" } [ require ] each
"AUTHOR" os-env developer-name set-global
auto-use

7
.gitpod.Dockerfile vendored Normal file
View File

@ -0,0 +1,7 @@
FROM bubbler9903/factor-gitpod:latest
USER root
RUN apt-get update -y -q \
&& apt-get install -y -q --no-install-recommends netpbm
USER gitpod

4
.gitpod.yml Normal file
View File

@ -0,0 +1,4 @@
image:
file: .gitpod.Dockerfile
tasks:
- command: "cp .factor-rc ~/"

25
LICENSE Normal file
View File

@ -0,0 +1,25 @@
BSD 2-Clause License
Copyright (c) 2020, Bubbler-4
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

18
README.md Normal file
View File

@ -0,0 +1,18 @@
# factor-problem-solving
Solutions to various problems written in Factor
## How to add a solution
* To work on advent-of-code problems, go to [[https://adventofcode.com]] and create an account. You will need to do this to receive the puzzle input individually for you. Later, you will be able to upload your answers and get it checked for correctness.
* Add an `AUTHOR` environment variable and set it as your name/username. (On Gitpod, you can do this in account settings.):
```
export AUTHOR="My Name"
```
* Run `factor playground.factor` in terminal at the git repo root, then enter the following replacing `N` with the number of the day:
```
"aoc2020.dayN" aoc-init
```
* See `aoc2020.day1` for an example. If a solution is worth an explanation, it should go to the description in the docs.
* By convention, the `MAIN:` function solves the exact task given, while the core function solves the core problem (no input parsing, no output formatting). Sometimes it solves a more generalized problem; sometimes it solves only a specific subset of the problem (which happens in AoC problems, when an input exploit is needed).

1
aoc2015/day1/authors.txt Normal file
View File

@ -0,0 +1 @@
Bubbler

View File

@ -0,0 +1,27 @@
! Copyright (C) 2021 Bubbler.
! See http://factorcode.org/license.txt for BSD license.
USING: help.markup help.syntax kernel math strings ;
IN: aoc2015.day1
HELP: day1-gold
{ $values
{ "str" string }
{ "n" integer }
}
{ $description "Solves Day 1, Part 2 of AoC2015: If the accumulator starts at 0, adds 1 at opening parens, and subtracts 1 at closing parens, find the first index (1-based) where it becomes negative." } ;
HELP: day1-main
{ $description "Solves both parts of Day 1 of AoC2015, using a real dataset." } ;
HELP: day1-silver
{ $values
{ "str" string }
{ "n" integer }
}
{ $description "Solves Day 1, Part 1 of AoC2015: Given a string made of " { $snippet "()" } " characters, add 1 for each of " { $snippet "(" } " and subtract 1 for each of " { $snippet ")" } "." } ;
ARTICLE: "aoc2015.day1" "aoc2015.day1"
{ $vocab-link "aoc2015.day1" }
;
ABOUT: "aoc2015.day1"

View File

@ -0,0 +1,17 @@
! Copyright (C) 2021 Bubbler.
! See http://factorcode.org/license.txt for BSD license.
USING: tools.test aoc2015.day1 ;
IN: aoc2015.day1.tests
{ 0 } [ "(())" day1-silver ] unit-test
{ 0 } [ "()()" day1-silver ] unit-test
{ 3 } [ "(((" day1-silver ] unit-test
{ 3 } [ "(()(()(" day1-silver ] unit-test
{ 3 } [ "))(((((" day1-silver ] unit-test
{ -1 } [ "())" day1-silver ] unit-test
{ -1 } [ "))(" day1-silver ] unit-test
{ -3 } [ ")))" day1-silver ] unit-test
{ -3 } [ ")())())" day1-silver ] unit-test
{ 1 } [ ")" day1-gold ] unit-test
{ 5 } [ "()())" day1-gold ] unit-test

16
aoc2015/day1/day1.factor Normal file
View File

@ -0,0 +1,16 @@
! Copyright (C) 2021 Bubbler.
! See http://factorcode.org/license.txt for BSD license.
USING: arrays io.encodings.utf8 io.files kernel math
math.vectors prettyprint sequences ;
IN: aoc2015.day1
: day1-silver ( str -- n )
>array -1 swap n^v sum ;
: day1-gold ( str -- n )
>array -1 swap n^v 0 [ + ] accumulate* -1 swap index 1 + ;
: day1-main ( -- ) "datasets/aoc2015/day1.txt" utf8 file-contents
[ day1-silver . ] [ day1-gold . ] bi ;
MAIN: day1-main

View File

@ -0,0 +1 @@
Bubbler

View File

@ -0,0 +1,40 @@
! Copyright (C) 2021 Bubbler.
! See http://factorcode.org/license.txt for BSD license.
USING: help.markup help.syntax kernel math sequences ;
IN: aoc2015.day10
HELP: day10-data
{ $values
{ "data" sequence }
}
{ $description "Reads the input data as an array of numbers." } ;
HELP: day10-gold
{ $values
{ "seq" sequence }
{ "n" integer }
}
{ $description "Solves Day 10, Part 2 of AoC2015: Given an initial digit string, apply look-and-say 50 times and find the length of the result." } ;
HELP: day10-main
{ $description "Solves both parts of Day 10 of AoC2015, using a real dataset." } ;
HELP: day10-silver
{ $values
{ "seq" sequence }
{ "n" integer }
}
{ $description "Solves Day 10, Part 1 of AoC2015: Given an initial digit string, apply look-and-say 40 times and find the length of the result." } ;
HELP: look-say
{ $values
{ "seq" sequence }
{ "seq'" sequence }
}
{ $description "Apply look-and-say once." } ;
ARTICLE: "aoc2015.day10" "aoc2015.day10"
{ $vocab-link "aoc2015.day10" }
;
ABOUT: "aoc2015.day10"

View File

@ -0,0 +1,7 @@
! Copyright (C) 2021 Bubbler.
! See http://factorcode.org/license.txt for BSD license.
USING: aoc2015.day10 kernel sequences tools.test ;
IN: aoc2015.day10.tests
{ { { 1 1 } { 2 1 } { 1 2 1 1 } { 1 1 1 2 2 1 } { 3 1 2 2 1 1 } } }
[ { 1 } 5 [ look-say dup ] replicate nip ] unit-test

View File

@ -0,0 +1,20 @@
! Copyright (C) 2021 Bubbler.
! See http://factorcode.org/license.txt for BSD license.
USING: arrays grouping.extras io.encodings.utf8 io.files kernel
math math.parser prettyprint sequences ;
IN: aoc2015.day10
: day10-data ( -- data )
"datasets/aoc2015/day10.txt" utf8 file-contents string>digits ;
: look-say ( seq -- seq' )
[ ] group-by [ first2 length swap 2array ] map concat ;
: day10-silver ( seq -- n ) 40 [ look-say ] times length ;
: day10-gold ( seq -- n ) 50 [ look-say ] times length ;
: day10-main ( -- )
day10-data [ day10-silver . ] [ day10-gold . ] bi ;
MAIN: day10-main

1
aoc2015/day2/authors.txt Normal file
View File

@ -0,0 +1 @@
Bubbler

View File

@ -0,0 +1,41 @@
! Copyright (C) 2021 Bubbler.
! See http://factorcode.org/license.txt for BSD license.
USING: help.markup help.syntax kernel math sequences strings ;
IN: aoc2015.day2
HELP: day2-gold
{ $values
{ "seq" sequence }
{ "n" integer }
}
{ $description "Solves Day 2, Part 2 of AoC2015: Given a set of dimensions of boxes, compute the total length of the ribbon required to wrap all of them." } ;
HELP: day2-main
{ $description "Solves both parts of Day 2 of AoC2015, using a real dataset." } ;
HELP: day2-silver
{ $values
{ "seq" sequence }
{ "n" integer }
}
{ $description "Solves Day 2, Part 1 of AoC2015: Given a set of dimensions of boxes, compute the total area of the wrapping paper required to wrap all of them." } ;
HELP: ribbon
{ $values
{ "seq" sequence }
{ "n" integer }
}
{ $description "Given the three dimensions of a box, computes the length of the ribbon (smallest perimeter of a face + volume of the box)." } ;
HELP: wrapping-paper
{ $values
{ "seq" sequence }
{ "n" integer }
}
{ $description "Given the three dimensions of a box, computes the area of the wrapping paper (total area of all faces + area of the smallest face)." } ;
ARTICLE: "aoc2015.day2" "aoc2015.day2"
{ $vocab-link "aoc2015.day2" }
;
ABOUT: "aoc2015.day2"

View File

@ -0,0 +1,10 @@
! Copyright (C) 2021 Bubbler.
! See http://factorcode.org/license.txt for BSD license.
USING: tools.test aoc2015.day2 ;
IN: aoc2015.day2.tests
{ 58 } [ { 2 3 4 } wrapping-paper ] unit-test
{ 43 } [ { 1 1 10 } wrapping-paper ] unit-test
{ 34 } [ { 2 3 4 } ribbon ] unit-test
{ 14 } [ { 1 1 10 } ribbon ] unit-test

23
aoc2015/day2/day2.factor Normal file
View File

@ -0,0 +1,23 @@
! Copyright (C) 2021 Bubbler.
! See http://factorcode.org/license.txt for BSD license.
USING: arrays io.encodings.utf8 io.files kernel math math.parser
math.vectors prettyprint sequences sorting splitting ;
IN: aoc2015.day2
: wrapping-paper ( seq -- n )
natural-sort dup first3 rot 3array v* { 3 2 2 } v. ;
: day2-silver ( seq -- n )
[ wrapping-paper ] map sum ;
: ribbon ( seq -- n )
natural-sort [ { 2 2 0 } v. ] [ product ] bi + ;
: day2-gold ( seq -- n )
[ ribbon ] map sum ;
: day2-main ( -- ) "datasets/aoc2015/day2.txt" utf8 file-contents
"\n" split [ "x" split [ dec> ] map ] map
[ day2-silver . ] [ day2-gold . ] bi ;
MAIN: day2-main

1
aoc2015/day3/authors.txt Normal file
View File

@ -0,0 +1 @@
Bubbler

View File

@ -0,0 +1,34 @@
! Copyright (C) 2021 Bubbler.
! See http://factorcode.org/license.txt for BSD license.
USING: help.markup help.syntax kernel math sequences strings ;
IN: aoc2015.day3
HELP: day3-gold
{ $values
{ "str" string }
{ "n" integer }
}
{ $description "Solves Day 3, Part 2 of AoC2015: If two agents are taking turns to follow the directions string, count the number of coordinates passed at least once by either agent." } ;
HELP: day3-main
{ $description "Solves both parts of Day 3 of AoC2015, using a real dataset." } ;
HELP: day3-silver
{ $values
{ "str" string }
{ "n" integer }
}
{ $description "Solves Day 3, Part 1 of AoC2015: Given the directions string, count the number of coordinates passed at least once." } ;
HELP: path-coords
{ $values
{ "str" string }
{ "seq" sequence }
}
{ $description "Given a directions string, returns the sequence of coordinates the path goes through." } ;
ARTICLE: "aoc2015.day3" "aoc2015.day3"
{ $vocab-link "aoc2015.day3" }
;
ABOUT: "aoc2015.day3"

View File

@ -0,0 +1,12 @@
! Copyright (C) 2021 Bubbler.
! See http://factorcode.org/license.txt for BSD license.
USING: tools.test aoc2015.day3 ;
IN: aoc2015.day3.tests
{ 2 } [ ">" day3-silver ] unit-test
{ 4 } [ "^>v<" day3-silver ] unit-test
{ 2 } [ "^v^v^v^v^v" day3-silver ] unit-test
{ 3 } [ "^v" day3-gold ] unit-test
{ 3 } [ "^>v<" day3-gold ] unit-test
{ 11 } [ "^v^v^v^v^v" day3-gold ] unit-test

21
aoc2015/day3/day3.factor Normal file
View File

@ -0,0 +1,21 @@
! Copyright (C) 2021 Bubbler.
! See http://factorcode.org/license.txt for BSD license.
USING: arrays assocs io.encodings.utf8 io.files kernel math
math.vectors prettyprint sequences sequences.extras sets ;
IN: aoc2015.day3
: path-coords ( str -- seq )
>array ">^<v" zip-index substitute C{ 0 1 } swap n^v
0 prefix 0 [ + ] accumulate* ;
: day3-silver ( str -- n )
path-coords cardinality ;
: day3-gold ( str -- n )
[ <evens> path-coords ] [ <odds> path-coords ] bi
append cardinality ;
: day3-main ( -- ) "datasets/aoc2015/day3.txt" utf8 file-contents
[ day3-silver . ] [ day3-gold . ] bi ;
MAIN: day3-main

1
aoc2015/day4/authors.txt Normal file
View File

@ -0,0 +1 @@
Bubbler

View File

@ -0,0 +1,70 @@
! Copyright (C) 2021 Bubbler.
! See http://factorcode.org/license.txt for BSD license.
USING: byte-vectors checksums help.markup help.syntax kernel
math strings ;
IN: aoc2015.day4
HELP: 5-leading-zeros?
{ $values
{ "bytes" byte-vector }
{ "?" boolean }
}
{ $description "Checks if the given checksum has five leading zeros in hex." } ;
HELP: 6-leading-zeros?
{ $values
{ "bytes" byte-vector }
{ "?" boolean }
}
{ $description "Checks if the given checksum has six leading zeros in hex." } ;
HELP: append-md5
{ $values
{ "str" string } { "n" integer }
{ "value" object }
}
{ $description "Appends the number to the string and computes its MD5 hash." } ;
HELP: append-md5'
{ $values
{ "checksum-state" checksum-state } { "n" integer }
{ "value" object }
}
{ $description "Takes an MD5 state, pushes " { $snippet "n" } " as a string, and returs the resulting MD5 hash. This is used in solution version 2 to cache the hash state of the input string." } ;
HELP: day4-gold
{ $values
{ "str" string }
{ "n" integer }
}
{ $description "Solves Day 4, Part 2 of AoC2015: Given an initial string, find the first integer that, when attached to the input, produces an MD5 hash that starts with six zeros. Uses a naive algorithm." } ;
HELP: day4-gold2
{ $values
{ "str" string }
{ "n" integer }
}
{ $description "Solves Day 4, Part 2 of AoC2015: Given an initial string, find the first integer that, when attached to the input, produces an MD5 hash that starts with six zeros. Caches the hash state of the input string. Caching every single state after adding each digit seems to make things worse, likely due to excessive object copies and GC triggers." } ;
HELP: day4-main
{ $description "Solves both parts of Day 4 of AoC2015, using a real dataset." } ;
HELP: day4-silver
{ $values
{ "str" string }
{ "n" integer }
}
{ $description "Solves Day 4, Part 1 of AoC2015: Given an initial string, find the first integer that, when attached to the input, produces an MD5 hash that starts with five zeros. Uses a naive algorithm." } ;
HELP: day4-silver2
{ $values
{ "str" string }
{ "n" integer }
}
{ $description "Solves Day 4, Part 1 of AoC2015: Given an initial string, find the first integer that, when attached to the input, produces an MD5 hash that starts with five zeros. Caches the hash state of the input string. Caching every single state after adding each digit seems to make things worse, likely due to excessive object copies and GC triggers." } ;
ARTICLE: "aoc2015.day4" "aoc2015.day4"
{ $vocab-link "aoc2015.day4" }
;
ABOUT: "aoc2015.day4"

36
aoc2015/day4/day4.factor Normal file
View File

@ -0,0 +1,36 @@
! Copyright (C) 2021 Bubbler.
! See http://factorcode.org/license.txt for BSD license.
USING: checksums checksums.md5 io.encodings.utf8 io.files kernel
math math.parser prettyprint sequences ;
IN: aoc2015.day4
: append-md5 ( str n -- value )
number>string append md5 checksum-bytes ;
: 5-leading-zeros? ( bytes -- ? )
first3 [ 0 = ] [ 0 = ] [ 16 < ] tri* and and ;
: day4-silver ( str -- n )
1/0. [ append-md5 5-leading-zeros? ] with find-integer ;
: append-md5' ( checksum-state n -- value )
[ clone ] dip number>string add-checksum-bytes get-checksum ;
: day4-silver2 ( str -- n )
md5 initialize-checksum-state swap add-checksum-bytes
1/0. [ append-md5' 5-leading-zeros? ] with find-integer ;
: 6-leading-zeros? ( bytes -- ? )
3 head [ 0 = ] all? ;
: day4-gold ( str -- n )
1/0. [ append-md5 6-leading-zeros? ] with find-integer ;
: day4-gold2 ( str -- n )
md5 initialize-checksum-state swap add-checksum-bytes
1/0. [ append-md5' 6-leading-zeros? ] with find-integer ;
: day4-main ( -- ) "datasets/aoc2015/day4.txt" utf8 file-contents
[ day4-silver2 . ] [ day4-gold2 . ] bi ;
MAIN: day4-main

1
aoc2015/day5/authors.txt Normal file
View File

@ -0,0 +1 @@
Bubbler

View File

@ -0,0 +1,76 @@
! Copyright (C) 2021 Bubbler.
! See http://factorcode.org/license.txt for BSD license.
USING: help.markup help.syntax kernel math sequences strings ;
IN: aoc2015.day5
HELP: char-repeat-1between?
{ $values
{ "str" string }
{ "?" boolean }
}
{ $description "Tests if a string has two copies of the same letter with one letter in between (e.g. aba, xyx, zzz). Part of Gold condition." } ;
HELP: day5-gold
{ $values
{ "seq" sequence }
{ "n" integer }
}
{ $description "Solves Day 5, Part 2 of AoC2015: Count how many strings are nice, according to the Gold condition." } ;
HELP: day5-main
{ $description "Solves both parts of Day 5 of AoC2015, using a real dataset." } ;
HELP: day5-silver
{ $values
{ "seq" sequence }
{ "n" integer }
}
{ $description "Solves Day 5, Part 1 of AoC2015: Count how many strings are nice, according to the Silver condition." } ;
HELP: doubled-letter?
{ $values
{ "str" string }
{ "?" boolean }
}
{ $description "Tests if a string has at least one letter that appears twice in a row. Part of Silver condition." } ;
HELP: nice-gold?
{ $values
{ "str" string }
{ "?" boolean }
}
{ $description "Tests if a string is nice, according to the Gold condition." } ;
HELP: nice-silver?
{ $values
{ "str" string }
{ "?" boolean }
}
{ $description "Tests if a string is nice, according to the Silver condition." } ;
HELP: no-specific-comb?
{ $values
{ "str" string }
{ "?" boolean }
}
{ $description "Tests if a string does not contain any of ab, cd, pq, or xy. Part of Silver condition." } ;
HELP: pair-twice?
{ $values
{ "str" string }
{ "?" boolean }
}
{ $description "Tests if a string contains at least two non-overlapping copies of some two-letter combination. Part of Gold condition." } ;
HELP: three-vowels?
{ $values
{ "str" string }
{ "?" boolean }
}
{ $description "Tests if a string contains at least three vowels. Part of Silver condition." } ;
ARTICLE: "aoc2015.day5" "aoc2015.day5"
{ $vocab-link "aoc2015.day5" }
;
ABOUT: "aoc2015.day5"

View File

@ -0,0 +1,15 @@
! Copyright (C) 2021 Bubbler.
! See http://factorcode.org/license.txt for BSD license.
USING: tools.test aoc2015.day5 ;
IN: aoc2015.day5.tests
{ t } [ "ugknbfddgicrmopn" nice-silver? ] unit-test
{ t } [ "aaa" nice-silver? ] unit-test
{ f } [ "jchzalrnumimnmhp" nice-silver? ] unit-test
{ f } [ "haegwjzuvuyypxyu" nice-silver? ] unit-test
{ f } [ "dvszwmarrgswjxmb" nice-silver? ] unit-test
{ t } [ "qjhvhtzxzqqjkmpb" nice-gold? ] unit-test
{ t } [ "xxyxx" nice-gold? ] unit-test
{ f } [ "uurcxstgmygtbstg" nice-gold? ] unit-test
{ f } [ "ieodomkazucvgmuy" nice-gold? ] unit-test

28
aoc2015/day5/day5.factor Normal file
View File

@ -0,0 +1,28 @@
! Copyright (C) 2021 Bubbler.
! See http://factorcode.org/license.txt for BSD license.
USING: combinators.short-circuit fry grouping grouping.extras
io.encodings.utf8 io.files kernel math math.vectors prettyprint
sequences sequences.extras sets splitting ;
IN: aoc2015.day5
: three-vowels? ( str -- ? ) [ "aeiou" in? ] count 3 >= ;
: doubled-letter? ( str -- ? ) [ = ] 2clump-map vany? ;
: no-specific-comb? ( str -- ? ) 2 clump [ { "ab" "cd" "pq" "xy" } in? ] none? ;
: nice-silver? ( str -- ? )
{ [ three-vowels? ] [ doubled-letter? ] [ no-specific-comb? ] } 1&& ;
: day5-silver ( seq -- n ) [ nice-silver? ] count ;
: pair-twice? ( str -- ? ) [ 2 clump ] keep '[ _ count-subseq 2 >= ] any? ;
: char-repeat-1between? ( str -- ? ) [ nip = ] 3clump-map vany? ;
: nice-gold? ( str -- ? )
{ [ pair-twice? ] [ char-repeat-1between? ] } 1&& ;
: day5-gold ( seq -- n ) [ nice-gold? ] count ;
: day5-main ( -- ) "datasets/aoc2015/day5.txt" utf8 file-contents "\n" split
[ day5-silver . ] [ day5-gold . ] bi ;
MAIN: day5-main

1
aoc2015/day6/authors.txt Normal file
View File

@ -0,0 +1 @@
Bubbler

View File

@ -0,0 +1,72 @@
! Copyright (C) 2021 Bubbler.
! See http://factorcode.org/license.txt for BSD license.
USING: help.markup help.syntax kernel math quotations sequences
strings ;
IN: aoc2015.day6
HELP: change-matrix-range
{ $values
{ "matrix" sequence } { "xrange" sequence } { "yrange" sequence } { "quot" quotation }
}
{ $description "A helper word to abstract modifications on a block region in a matrix." } ;
HELP: day6-data
{ $values
{ "data" sequence }
}
{ $description "Imports the input data, extracting the command (on, off, toggle) and horizontal and vertical ranges for each line." } ;
HELP: day6-gold
{ $values
{ "seq" sequence }
{ "n" integer }
}
{ $description "Solves Day 6, Part 2 of AoC2015: Run the commands over 1000x1000 grid, interpreting on=+1, off=-1 (minimum 0), toggle=+2 respectively. Find the sum of all values in the grid." } ;
HELP: day6-main
{ $description "Solves both parts of Day 6 of AoC2015, using a real dataset." } ;
HELP: day6-silver
{ $values
{ "seq" sequence }
{ "n" integer }
}
{ $description "Solves Day 6, Part 1 of AoC2015: Run the commands over 1000x1000 grid, interpreting on=set to 1, off=set to 0, toggle=alternate between 1 and 0 respectively. Find the sum of all values in the grid." } ;
HELP: extract-mode
{ $values
{ "str" string }
{ "mode" string }
}
{ $description "Extracts the string on/off/toggle from a line of command." } ;
HELP: extract-ranges
{ $values
{ "str" string }
{ "seq" sequence }
}
{ $description "Extracts the x- and y-ranges from a line of command." } ;
HELP: init-matrix
{ $values
{ "matrix" sequence }
}
{ $description "Creates a 1000x1000 matrix, which is an array of byte-arrays." } ;
HELP: run-command-gold
{ $values
{ "matrix" sequence } { "cmd" sequence }
}
{ $description "Run a single command over the given matrix, under the Gold rule. Modifies the matrix in place." } ;
HELP: run-command-silver
{ $values
{ "matrix" sequence } { "cmd" sequence }
}
{ $description "Run a single command over the given matrix, under the Silver rule. Modifies the matrix in place." } ;
ARTICLE: "aoc2015.day6" "aoc2015.day6"
{ $vocab-link "aoc2015.day6" }
;
ABOUT: "aoc2015.day6"

51
aoc2015/day6/day6.factor Normal file
View File

@ -0,0 +1,51 @@
! Copyright (C) 2021 Bubbler.
! See http://factorcode.org/license.txt for BSD license.
USING: arrays byte-arrays combinators grouping io.encodings.utf8
io.files kernel locals math math.order math.parser math.ranges
prettyprint regexp sequences sequences.extras splitting strings
;
IN: aoc2015.day6
: extract-mode ( str -- mode )
R/ on|off|toggle/ first-match >string ;
: extract-ranges ( str -- seq )
R/ \d+/ all-matching-subseqs [ dec> ] map
2 group flip ;
: day6-data ( -- data )
"datasets/aoc2015/day6.txt" utf8 file-contents "\n" split
[ [ extract-mode ] [ extract-ranges ] bi 2array ] map ;
: init-matrix ( -- matrix )
1000 f <array> [ drop 1000 <byte-array> ] map ;
:: change-matrix-range ( matrix xrange yrange quot: ( x -- x ) -- matrix )
yrange first2 [a,b] matrix
[| row | xrange first2 [a,b] row quot change-nths row ] change-nths
matrix ; inline
: run-command-silver ( matrix cmd -- matrix )
first2 first2 rot {
{ "on" [ [ drop 1 ] change-matrix-range ] }
{ "off" [ [ drop 0 ] change-matrix-range ] }
{ "toggle" [ [ 1 swap - ] change-matrix-range ] }
} case ;
: run-command-gold ( matrix cmd -- matrix )
first2 first2 rot {
{ "on" [ [ 1 + ] change-matrix-range ] }
{ "off" [ [ 1 - 0 max ] change-matrix-range ] }
{ "toggle" [ [ 2 + ] change-matrix-range ] }
} case ;
: day6-silver ( seq -- n )
init-matrix [ run-command-silver ] reduce concat sum ;
: day6-gold ( seq -- n )
init-matrix [ run-command-gold ] reduce concat sum ;
: day6-main ( -- )
day6-data [ day6-silver . ] [ day6-gold . ] bi ;
MAIN: day6-main

1
aoc2015/day7/authors.txt Normal file
View File

@ -0,0 +1 @@
Bubbler

View File

@ -0,0 +1,47 @@
! Copyright (C) 2021 Bubbler.
! See http://factorcode.org/license.txt for BSD license.
USING: assocs help.markup help.syntax kernel math strings ;
IN: aoc2015.day7
HELP: day7-data
{ $values
{ "assoc" assoc }
}
{ $description "Preprocesses the input as an assoc from a variable name to a tokenized expression." } ;
HELP: day7-gold
{ $values
{ "assoc" assoc }
{ "n" integer }
}
{ $description "Solves Day 7, Part 2 of AoC2015: Given a collection of expressions, find the value of " { $snippet "a" } ", feed it back to " { $snippet "b" } ", and find the changed value of " { $snippet "a" } "." } ;
HELP: day7-main
{ $description "Solves both parts of Day 7 of AoC2015, using a real dataset." } ;
HELP: day7-silver
{ $values
{ "assoc" assoc }
{ "n" integer }
}
{ $description "Solves Day 7, Part 1 of AoC2015: Given a collection of expressions, find the value of " { $snippet "a" } "." } ;
HELP: eval-expr
{ $values
{ "cached" assoc } { "assoc" assoc } { "str" string }
{ "n" integer }
}
{ $description "Evaluates the given variable." } ;
HELP: num-or-var
{ $values
{ "cached" assoc } { "assoc" assoc } { "num/var" string }
{ "n" integer }
}
{ $description "Checks if the given string is an integer or a variable. If it is an integer, returns the integer value. Otherwise, recursively calls " { $snippet "eval-expr" } ", caching the result for later use." } ;
ARTICLE: "aoc2015.day7" "aoc2015.day7"
{ $vocab-link "aoc2015.day7" }
;
ABOUT: "aoc2015.day7"

38
aoc2015/day7/day7.factor Normal file
View File

@ -0,0 +1,38 @@
! Copyright (C) 2021 Bubbler.
! See http://factorcode.org/license.txt for BSD license.
USING: arrays assocs combinators combinators.short-circuit
hashtables io.encodings.utf8 io.files kernel locals math
math.parser prettyprint sequences sequences.extras splitting
strings ;
IN: aoc2015.day7
: day7-data ( -- assoc )
"datasets/aoc2015/day7.txt" utf8 file-contents "\n" split
[ " -> " split-subseq first2 >string swap " " split 2array ] map ;
DEFER: eval-expr
:: num-or-var ( cached assoc num/var -- cached n )
cached num/var
{ [ dec> ] [ cached [ assoc swap eval-expr ] cache ] } 1|| ;
: eval-expr ( cached assoc str -- cached n )
over at dup length {
{ 1 [ first num-or-var ] }
{ 2 [ last num-or-var 65535 bitxor ] }
[ drop [ <evens> [ num-or-var ] with map first2 ] keep second {
{ "AND" [ bitand ] }
{ "OR" [ bitor ] }
{ "LSHIFT" [ shift ] }
{ "RSHIFT" [ neg shift ] }
} case ]
} case ;
: day7-silver ( assoc -- n ) f >hashtable swap "a" eval-expr nip ;
: day7-gold ( assoc -- n )
[ day7-silver 10 >base 1array ] [ "b" swap set-at ] [ day7-silver ] tri ;
: day7-main ( -- )
day7-data [ day7-silver . ] [ day7-gold . ] bi ;
MAIN: day7-main

1
aoc2015/day8/authors.txt Normal file
View File

@ -0,0 +1 @@
Bubbler

View File

@ -0,0 +1,61 @@
! Copyright (C) 2021 Bubbler.
! See http://factorcode.org/license.txt for BSD license.
USING: help.markup help.syntax kernel math sequences strings ;
IN: aoc2015.day8
HELP: (day8-gold)
{ $values
{ "str" string }
{ "n" integer }
}
{ $description "Counts the number of added characters for code representation, in an indirect way." } ;
HELP: (day8-gold)'
{ $values
{ "str" string }
{ "n" integer }
}
{ $description "Counts the number of added characters for code representation, using the built-in " { $snippet "unparse" } "." } ;
HELP: (day8-silver)
{ $values
{ "str" string }
{ "n" integer }
}
{ $description "Counts the number of reduced characters for interpreting the string literal, in an indirect way." } ;
HELP: (day8-silver)'
{ $values
{ "str" string }
{ "n" integer }
}
{ $description "Counts the number of reduced characters for interpreting the string literal, using the built-in " { $snippet "eval" } "." } ;
HELP: day8-data
{ $values
{ "data" sequence }
}
{ $description "Takes input from the data file." } ;
HELP: day8-gold
{ $values
{ "strs" sequence }
{ "n" integer }
}
{ $description "Solves Day 8, Part 2 of AoC2015: Given some strings, count the total difference between the lengths of the input and its code representation." } ;
HELP: day8-main
{ $description "Solves both parts of Day 8 of AoC2015, using a real dataset." } ;
HELP: day8-silver
{ $values
{ "strs" sequence }
{ "n" integer }
}
{ $description "Solves Day 8, Part 1 of AoC2015: Given some string literals, count the total difference between the lengths of the input and the actual string it represents." } ;
ARTICLE: "aoc2015.day8" "aoc2015.day8"
{ $vocab-link "aoc2015.day8" }
;
ABOUT: "aoc2015.day8"

View File

@ -0,0 +1,17 @@
! Copyright (C) 2021 Bubbler.
! See http://factorcode.org/license.txt for BSD license.
USING: aoc2015.day8 multiline sequences splitting tools.test ;
IN: aoc2015.day8.tests
STRING: testcases
""
"abc"
"aaa\"aaa"
"\x27"
;
{ { 2 2 3 5 } } [ testcases "\n" split [ (day8-silver) ] map ] unit-test
{ { 2 2 3 5 } } [ testcases "\n" split [ (day8-silver)' ] map ] unit-test
{ { 4 4 6 5 } } [ testcases "\n" split [ (day8-gold) ] map ] unit-test
{ { 4 4 6 5 } } [ testcases "\n" split [ (day8-gold)' ] map ] unit-test

29
aoc2015/day8/day8.factor Normal file
View File

@ -0,0 +1,29 @@
! Copyright (C) 2021 Bubbler.
! See http://factorcode.org/license.txt for BSD license.
USING: assocs assocs.extras eval io.encodings.utf8 io.files
kernel math prettyprint regexp sequences splitting ;
IN: aoc2015.day8
: day8-data ( -- data )
"datasets/aoc2015/day8.txt" utf8 file-contents "\n" split ;
: (day8-silver) ( str -- n )
R/ \\("|\\|x..)/ all-matching-slices [ length 1 - ] map sum 2 + ;
: (day8-silver)' ( str -- n )
dup eval( -- x ) [ length ] bi@ - ;
: day8-silver ( strs -- n ) [ (day8-silver) ] map sum ;
: (day8-gold) ( str -- n )
"\"\\" counts values sum 2 + ;
: (day8-gold)' ( str -- n )
dup unparse [ length ] bi@ - neg ;
: day8-gold ( strs -- n ) [ (day8-gold) ] map sum ;
: day8-main ( -- )
day8-data [ day8-silver . ] [ day8-gold . ] bi ;
MAIN: day8-main

1
aoc2015/day9/authors.txt Normal file
View File

@ -0,0 +1 @@
Bubbler

View File

@ -0,0 +1,40 @@
! Copyright (C) 2021 Bubbler.
! See http://factorcode.org/license.txt for BSD license.
USING: assocs help.markup help.syntax kernel math sequences ;
IN: aoc2015.day9
HELP: all-path-lengths
{ $values
{ "distances" assoc }
{ "path-lengths" sequence }
}
{ $description "Given the distances between pairs of cities, computes the path lengths for all possible paths." } ;
HELP: day9-data
{ $values
{ "data" "an alist" }
}
{ $description "Takes the input data and produces an alist, where the keys are pairs of cities and the values are their distances." } ;
HELP: day9-gold
{ $values
{ "distances" assoc }
{ "n" integer }
}
{ $description "Solves Day 9, Part 2 of AoC2015: Find the length of the longest route going through all the cities." } ;
HELP: day9-main
{ $description "Solves both parts of Day 9 of AoC2015, using a real dataset." } ;
HELP: day9-silver
{ $values
{ "distances" assoc }
{ "n" integer }
}
{ $description "Solves Day 9, Part 1 of AoC2015: Find the length of the shortest route going through all the cities. This is an instance of Traveling Salesperson Problem, but the graph has only seven vertices in the main input, so it can be easily solved by straightforward brute force." } ;
ARTICLE: "aoc2015.day9" "aoc2015.day9"
{ $vocab-link "aoc2015.day9" }
;
ABOUT: "aoc2015.day9"

24
aoc2015/day9/day9.factor Normal file
View File

@ -0,0 +1,24 @@
! Copyright (C) 2021 Bubbler.
! See http://factorcode.org/license.txt for BSD license.
USING: arrays assocs grouping io.encodings.utf8 io.files kernel
locals math.combinatorics math.parser prettyprint sequences
sequences.extras sets splitting ;
IN: aoc2015.day9
: day9-data ( -- data )
"datasets/aoc2015/day9.txt" utf8 file-contents "\n" split
[ " = " split1 [ " to " split1 2array ] [ dec> ] bi* 2array ] map
dup [ reverse ] map-keys append ;
:: all-path-lengths ( distances -- path-lengths )
distances keys combine <permutations>
[ 2 clump [ distances at ] map sum ] map ;
: day9-silver ( distances -- n ) all-path-lengths infimum ;
: day9-gold ( distances -- n ) all-path-lengths supremum ;
: day9-main ( -- )
day9-data [ day9-silver . ] [ day9-gold . ] bi ;
MAIN: day9-main

1
aoc2020/day1/authors.txt Normal file
View File

@ -0,0 +1 @@
Bubbler

View File

@ -0,0 +1,28 @@
! Copyright (C) 2020 Bubbler.
! See http://factorcode.org/license.txt for BSD license.
USING: help.markup help.syntax kernel sequences ;
IN: aoc2020.day1
HELP: day1-silver
{ $values
{ "seq" "A sequence of integers" }
{ "prod" "The answer" }
}
{ $description "Solves Day 1, Part 1 of AoC2020: given a sequence of integers, find the two numbers that sum to 2020, and output their product." } ;
HELP: day1-main
{ $description "Solves both parts of Day 1 of AoC2020, using a real dataset." } ;
HELP: day1-gold
{ $values
{ "seq" "A sequence of integers" }
{ "prod" "The answer" }
}
{ $description "Solves Day 1, Part 2 of AoC2020: given a sequence of integers, find the three numbers that sum to 2020, and output their product." { $nl "" }
"Uses naive method of generating a sequence of all 3-combinations and filtering on it, since it is sufficiently fast on a 200-item sequence." } ;
ARTICLE: "aoc2020.day1" "aoc2020.day1"
{ $vocab-link "aoc2020.day1" }
;
ABOUT: "aoc2020.day1"

View File

@ -0,0 +1,7 @@
! Copyright (C) 2020 Bubbler.
! See http://factorcode.org/license.txt for BSD license.
USING: tools.test aoc2020.day1 ;
IN: aoc2020.day1.tests
{ 514579 } [ { 1721 979 366 299 675 1456 } day1-silver ] unit-test
{ 241861950 } [ { 1721 979 366 299 675 1456 } day1-gold ] unit-test

16
aoc2020/day1/day1.factor Normal file
View File

@ -0,0 +1,16 @@
! Copyright (C) 2020 Bubbler.
! See http://factorcode.org/license.txt for BSD license.
USING: io io.encodings.utf8 io.files kernel math.combinatorics
math.parser prettyprint sequences splitting ;
IN: aoc2020.day1
: day1-silver ( seq -- prod )
2 all-combinations [ sum 2020 = ] find nip product ;
: day1-gold ( seq -- prod )
3 all-combinations [ sum 2020 = ] find nip product ;
: day1-main ( -- ) "datasets/aoc2020/day1.txt" utf8 file-contents "\n" split [ string>number ] map
[ day1-silver . ] [ day1-gold . ] bi ;
MAIN: day1-main

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
3113322113

1000
datasets/aoc2015/day2.txt Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
yzbqklnj

1000
datasets/aoc2015/day5.txt Normal file

File diff suppressed because it is too large Load Diff

300
datasets/aoc2015/day6.txt Normal file
View File

@ -0,0 +1,300 @@
turn on 887,9 through 959,629
turn on 454,398 through 844,448
turn off 539,243 through 559,965
turn off 370,819 through 676,868
turn off 145,40 through 370,997
turn off 301,3 through 808,453
turn on 351,678 through 951,908
toggle 720,196 through 897,994
toggle 831,394 through 904,860
toggle 753,664 through 970,926
turn off 150,300 through 213,740
turn on 141,242 through 932,871
toggle 294,259 through 474,326
toggle 678,333 through 752,957
toggle 393,804 through 510,976
turn off 6,964 through 411,976
turn off 33,572 through 978,590
turn on 579,693 through 650,978
turn on 150,20 through 652,719
turn off 782,143 through 808,802
turn off 240,377 through 761,468
turn off 899,828 through 958,967
turn on 613,565 through 952,659
turn on 295,36 through 964,978
toggle 846,296 through 969,528
turn off 211,254 through 529,491
turn off 231,594 through 406,794
turn off 169,791 through 758,942
turn on 955,440 through 980,477
toggle 944,498 through 995,928
turn on 519,391 through 605,718
toggle 521,303 through 617,366
turn off 524,349 through 694,791
toggle 391,87 through 499,792
toggle 562,527 through 668,935
turn off 68,358 through 857,453
toggle 815,811 through 889,828
turn off 666,61 through 768,87
turn on 27,501 through 921,952
turn on 953,102 through 983,471
turn on 277,552 through 451,723
turn off 64,253 through 655,960
turn on 47,485 through 734,977
turn off 59,119 through 699,734
toggle 407,898 through 493,955
toggle 912,966 through 949,991
turn on 479,990 through 895,990
toggle 390,589 through 869,766
toggle 593,903 through 926,943
toggle 358,439 through 870,528
turn off 649,410 through 652,875
turn on 629,834 through 712,895
toggle 254,555 through 770,901
toggle 641,832 through 947,850
turn on 268,448 through 743,777
turn off 512,123 through 625,874
turn off 498,262 through 930,811
turn off 835,158 through 886,242
toggle 546,310 through 607,773
turn on 501,505 through 896,909
turn off 666,796 through 817,924
toggle 987,789 through 993,809
toggle 745,8 through 860,693
toggle 181,983 through 731,988
turn on 826,174 through 924,883
turn on 239,228 through 843,993
turn on 205,613 through 891,667
toggle 867,873 through 984,896
turn on 628,251 through 677,681
toggle 276,956 through 631,964
turn on 78,358 through 974,713
turn on 521,360 through 773,597
turn off 963,52 through 979,502
turn on 117,151 through 934,622
toggle 237,91 through 528,164
turn on 944,269 through 975,453
toggle 979,460 through 988,964
turn off 440,254 through 681,507
toggle 347,100 through 896,785
turn off 329,592 through 369,985
turn on 931,960 through 979,985
toggle 703,3 through 776,36
toggle 798,120 through 908,550
turn off 186,605 through 914,709
turn off 921,725 through 979,956
toggle 167,34 through 735,249
turn on 726,781 through 987,936
toggle 720,336 through 847,756
turn on 171,630 through 656,769
turn off 417,276 through 751,500
toggle 559,485 through 584,534
turn on 568,629 through 690,873
toggle 248,712 through 277,988
toggle 345,594 through 812,723
turn off 800,108 through 834,618
turn off 967,439 through 986,869
turn on 842,209 through 955,529
turn on 132,653 through 357,696
turn on 817,38 through 973,662
turn off 569,816 through 721,861
turn on 568,429 through 945,724
turn on 77,458 through 844,685
turn off 138,78 through 498,851
turn on 136,21 through 252,986
turn off 2,460 through 863,472
turn on 172,81 through 839,332
turn on 123,216 through 703,384
turn off 879,644 through 944,887
toggle 227,491 through 504,793
toggle 580,418 through 741,479
toggle 65,276 through 414,299
toggle 482,486 through 838,931
turn off 557,768 through 950,927
turn off 615,617 through 955,864
turn on 859,886 through 923,919
turn on 391,330 through 499,971
toggle 521,835 through 613,847
turn on 822,787 through 989,847
turn on 192,142 through 357,846
turn off 564,945 through 985,945
turn off 479,361 through 703,799
toggle 56,481 through 489,978
turn off 632,991 through 774,998
toggle 723,526 through 945,792
turn on 344,149 through 441,640
toggle 568,927 through 624,952
turn on 621,784 through 970,788
toggle 665,783 through 795,981
toggle 386,610 through 817,730
toggle 440,399 through 734,417
toggle 939,201 through 978,803
turn off 395,883 through 554,929
turn on 340,309 through 637,561
turn off 875,147 through 946,481
turn off 945,837 through 957,922
turn off 429,982 through 691,991
toggle 227,137 through 439,822
toggle 4,848 through 7,932
turn off 545,146 through 756,943
turn on 763,863 through 937,994
turn on 232,94 through 404,502
turn off 742,254 through 930,512
turn on 91,931 through 101,942
toggle 585,106 through 651,425
turn on 506,700 through 567,960
turn off 548,44 through 718,352
turn off 194,827 through 673,859
turn off 6,645 through 509,764
turn off 13,230 through 821,361
turn on 734,629 through 919,631
toggle 788,552 through 957,972
toggle 244,747 through 849,773
turn off 162,553 through 276,887
turn off 569,577 through 587,604
turn off 799,482 through 854,956
turn on 744,535 through 909,802
toggle 330,641 through 396,986
turn off 927,458 through 966,564
toggle 984,486 through 986,913
toggle 519,682 through 632,708
turn on 984,977 through 989,986
toggle 766,423 through 934,495
turn on 17,509 through 947,718
turn on 413,783 through 631,903
turn on 482,370 through 493,688
turn on 433,859 through 628,938
turn off 769,549 through 945,810
turn on 178,853 through 539,941
turn off 203,251 through 692,433
turn off 525,638 through 955,794
turn on 169,70 through 764,939
toggle 59,352 through 896,404
toggle 143,245 through 707,320
turn off 103,35 through 160,949
toggle 496,24 through 669,507
turn off 581,847 through 847,903
turn on 689,153 through 733,562
turn on 821,487 through 839,699
turn on 837,627 through 978,723
toggle 96,748 through 973,753
toggle 99,818 through 609,995
turn on 731,193 through 756,509
turn off 622,55 through 813,365
turn on 456,490 through 576,548
turn on 48,421 through 163,674
turn off 853,861 through 924,964
turn off 59,963 through 556,987
turn on 458,710 through 688,847
toggle 12,484 through 878,562
turn off 241,964 through 799,983
turn off 434,299 through 845,772
toggle 896,725 through 956,847
turn on 740,289 through 784,345
turn off 395,840 through 822,845
turn on 955,224 through 996,953
turn off 710,186 through 957,722
turn off 485,949 through 869,985
turn on 848,209 through 975,376
toggle 221,241 through 906,384
turn on 588,49 through 927,496
turn on 273,332 through 735,725
turn on 505,962 through 895,962
toggle 820,112 through 923,143
turn on 919,792 through 978,982
toggle 489,461 through 910,737
turn off 202,642 through 638,940
turn off 708,953 through 970,960
toggle 437,291 through 546,381
turn on 409,358 through 837,479
turn off 756,279 through 870,943
turn off 154,657 through 375,703
turn off 524,622 through 995,779
toggle 514,221 through 651,850
toggle 808,464 through 886,646
toggle 483,537 through 739,840
toggle 654,769 through 831,825
turn off 326,37 through 631,69
turn off 590,570 through 926,656
turn off 881,913 through 911,998
turn on 996,102 through 998,616
turn off 677,503 through 828,563
turn on 860,251 through 877,441
turn off 964,100 through 982,377
toggle 888,403 through 961,597
turn off 632,240 through 938,968
toggle 731,176 through 932,413
turn on 5,498 through 203,835
turn on 819,352 through 929,855
toggle 393,813 through 832,816
toggle 725,689 through 967,888
turn on 968,950 through 969,983
turn off 152,628 through 582,896
turn off 165,844 through 459,935
turn off 882,741 through 974,786
turn off 283,179 through 731,899
toggle 197,366 through 682,445
turn on 106,309 through 120,813
toggle 950,387 through 967,782
turn off 274,603 through 383,759
turn off 155,665 through 284,787
toggle 551,871 through 860,962
turn off 30,826 through 598,892
toggle 76,552 through 977,888
turn on 938,180 through 994,997
toggle 62,381 through 993,656
toggle 625,861 through 921,941
turn on 685,311 through 872,521
turn on 124,934 through 530,962
turn on 606,379 through 961,867
turn off 792,735 through 946,783
turn on 417,480 through 860,598
toggle 178,91 through 481,887
turn off 23,935 through 833,962
toggle 317,14 through 793,425
turn on 986,89 through 999,613
turn off 359,201 through 560,554
turn off 729,494 through 942,626
turn on 204,143 through 876,610
toggle 474,97 through 636,542
turn off 902,924 through 976,973
turn off 389,442 through 824,638
turn off 622,863 through 798,863
turn on 840,622 through 978,920
toggle 567,374 through 925,439
turn off 643,319 through 935,662
toggle 185,42 through 294,810
turn on 47,124 through 598,880
toggle 828,303 through 979,770
turn off 174,272 through 280,311
turn off 540,50 through 880,212
turn on 141,994 through 221,998
turn on 476,695 through 483,901
turn on 960,216 through 972,502
toggle 752,335 through 957,733
turn off 419,713 through 537,998
toggle 772,846 through 994,888
turn on 881,159 through 902,312
turn off 537,651 through 641,816
toggle 561,947 through 638,965
turn on 368,458 through 437,612
turn on 290,149 through 705,919
turn on 711,918 through 974,945
toggle 916,242 through 926,786
toggle 522,272 through 773,314
turn on 432,897 through 440,954
turn off 132,169 through 775,380
toggle 52,205 through 693,747
toggle 926,309 through 976,669
turn off 838,342 through 938,444
turn on 144,431 through 260,951
toggle 780,318 through 975,495
turn off 185,412 through 796,541
turn on 879,548 through 892,860
turn on 294,132 through 460,338
turn on 823,500 through 899,529
turn off 225,603 through 483,920
toggle 717,493 through 930,875
toggle 534,948 through 599,968
turn on 522,730 through 968,950
turn off 102,229 through 674,529

339
datasets/aoc2015/day7.txt Normal file
View File

@ -0,0 +1,339 @@
af AND ah -> ai
NOT lk -> ll
hz RSHIFT 1 -> is
NOT go -> gp
du OR dt -> dv
x RSHIFT 5 -> aa
at OR az -> ba
eo LSHIFT 15 -> es
ci OR ct -> cu
b RSHIFT 5 -> f
fm OR fn -> fo
NOT ag -> ah
v OR w -> x
g AND i -> j
an LSHIFT 15 -> ar
1 AND cx -> cy
jq AND jw -> jy
iu RSHIFT 5 -> ix
gl AND gm -> go
NOT bw -> bx
jp RSHIFT 3 -> jr
hg AND hh -> hj
bv AND bx -> by
er OR es -> et
kl OR kr -> ks
et RSHIFT 1 -> fm
e AND f -> h
u LSHIFT 1 -> ao
he RSHIFT 1 -> hx
eg AND ei -> ej
bo AND bu -> bw
dz OR ef -> eg
dy RSHIFT 3 -> ea
gl OR gm -> gn
da LSHIFT 1 -> du
au OR av -> aw
gj OR gu -> gv
eu OR fa -> fb
lg OR lm -> ln
e OR f -> g
NOT dm -> dn
NOT l -> m
aq OR ar -> as
gj RSHIFT 5 -> gm
hm AND ho -> hp
ge LSHIFT 15 -> gi
jp RSHIFT 1 -> ki
hg OR hh -> hi
lc LSHIFT 1 -> lw
km OR kn -> ko
eq LSHIFT 1 -> fk
1 AND am -> an
gj RSHIFT 1 -> hc
aj AND al -> am
gj AND gu -> gw
ko AND kq -> kr
ha OR gz -> hb
bn OR by -> bz
iv OR jb -> jc
NOT ac -> ad
bo OR bu -> bv
d AND j -> l
bk LSHIFT 1 -> ce
de OR dk -> dl
dd RSHIFT 1 -> dw
hz AND ik -> im
NOT jd -> je
fo RSHIFT 2 -> fp
hb LSHIFT 1 -> hv
lf RSHIFT 2 -> lg
gj RSHIFT 3 -> gl
ki OR kj -> kk
NOT ak -> al
ld OR le -> lf
ci RSHIFT 3 -> ck
1 AND cc -> cd
NOT kx -> ky
fp OR fv -> fw
ev AND ew -> ey
dt LSHIFT 15 -> dx
NOT ax -> ay
bp AND bq -> bs
NOT ii -> ij
ci AND ct -> cv
iq OR ip -> ir
x RSHIFT 2 -> y
fq OR fr -> fs
bn RSHIFT 5 -> bq
0 -> c
14146 -> b
d OR j -> k
z OR aa -> ab
gf OR ge -> gg
df OR dg -> dh
NOT hj -> hk
NOT di -> dj
fj LSHIFT 15 -> fn
lf RSHIFT 1 -> ly
b AND n -> p
jq OR jw -> jx
gn AND gp -> gq
x RSHIFT 1 -> aq
ex AND ez -> fa
NOT fc -> fd
bj OR bi -> bk
as RSHIFT 5 -> av
hu LSHIFT 15 -> hy
NOT gs -> gt
fs AND fu -> fv
dh AND dj -> dk
bz AND cb -> cc
dy RSHIFT 1 -> er
hc OR hd -> he
fo OR fz -> ga
t OR s -> u
b RSHIFT 2 -> d
NOT jy -> jz
hz RSHIFT 2 -> ia
kk AND kv -> kx
ga AND gc -> gd
fl LSHIFT 1 -> gf
bn AND by -> ca
NOT hr -> hs
NOT bs -> bt
lf RSHIFT 3 -> lh
au AND av -> ax
1 AND gd -> ge
jr OR js -> jt
fw AND fy -> fz
NOT iz -> ja
c LSHIFT 1 -> t
dy RSHIFT 5 -> eb
bp OR bq -> br
NOT h -> i
1 AND ds -> dt
ab AND ad -> ae
ap LSHIFT 1 -> bj
br AND bt -> bu
NOT ca -> cb
NOT el -> em
s LSHIFT 15 -> w
gk OR gq -> gr
ff AND fh -> fi
kf LSHIFT 15 -> kj
fp AND fv -> fx
lh OR li -> lj
bn RSHIFT 3 -> bp
jp OR ka -> kb
lw OR lv -> lx
iy AND ja -> jb
dy OR ej -> ek
1 AND bh -> bi
NOT kt -> ku
ao OR an -> ap
ia AND ig -> ii
NOT ey -> ez
bn RSHIFT 1 -> cg
fk OR fj -> fl
ce OR cd -> cf
eu AND fa -> fc
kg OR kf -> kh
jr AND js -> ju