├── datasets ├── rosalind │ ├── perm.txt │ ├── sign.txt │ ├── fib.txt │ ├── fibd.txt │ ├── inod.txt │ ├── lia.txt │ ├── pper.txt │ ├── sset.txt │ ├── aspc.txt │ ├── iprb.txt │ ├── lexf.txt │ ├── rstr.txt │ ├── lexv.txt │ ├── iev.txt │ ├── pmch.txt │ ├── mmch.txt │ ├── eval.txt │ ├── prob.txt │ ├── mprt.txt │ ├── cat.txt │ ├── prtm.txt │ ├── revc.txt │ ├── rna.txt │ ├── dna.txt │ ├── subs.txt │ ├── mrna.txt │ ├── orf.txt │ ├── revp.txt │ ├── sseq.txt │ ├── spec.txt │ └── splc.txt ├── aoc2015 │ ├── day4.txt │ ├── day10.txt │ └── day9.txt └── aoc2020 │ ├── day23.txt │ ├── day15.txt │ ├── day25.txt │ ├── day17.txt │ ├── day13.txt │ ├── day22.txt │ └── day10.txt ├── aoc2015 ├── day1 │ ├── authors.txt │ ├── day1.factor │ ├── day1-tests.factor │ └── day1-docs.factor ├── day10 │ ├── authors.txt │ ├── day10-tests.factor │ ├── day10.factor │ └── day10-docs.factor ├── day2 │ ├── authors.txt │ ├── day2-tests.factor │ ├── day2.factor │ └── day2-docs.factor ├── day3 │ ├── authors.txt │ ├── day3-tests.factor │ ├── day3.factor │ └── day3-docs.factor ├── day4 │ ├── authors.txt │ └── day4.factor ├── day5 │ ├── authors.txt │ ├── day5-tests.factor │ └── day5.factor ├── day6 │ ├── authors.txt │ └── day6.factor ├── day7 │ ├── authors.txt │ ├── day7.factor │ └── day7-docs.factor ├── day8 │ ├── authors.txt │ ├── day8-tests.factor │ └── day8.factor └── day9 │ ├── authors.txt │ ├── day9.factor │ └── day9-docs.factor ├── aoc2020 ├── day1 │ ├── authors.txt │ ├── day1-tests.factor │ ├── day1.factor │ └── day1-docs.factor ├── day10 │ ├── authors.txt │ ├── day10-tests.factor │ ├── day10.factor │ └── day10-docs.factor ├── day11 │ ├── authors.txt │ ├── day11-tests.factor │ └── day11.factor ├── day12 │ ├── authors.txt │ ├── day12-tests.factor │ ├── day12.factor │ └── day12-docs.factor ├── day13 │ ├── authors.txt │ ├── day13-tests.factor │ └── day13.factor ├── day14 │ ├── authors.txt │ ├── day14-tests.factor │ └── day14.factor ├── day15 │ ├── authors.txt │ ├── day15-tests.factor │ └── day15.factor ├── day16 │ ├── authors.txt │ └── day16.factor ├── day17 │ ├── authors.txt │ ├── day17-tests.factor │ └── day17.factor ├── day18 │ ├── authors.txt │ └── day18.factor ├── day19 │ └── authors.txt ├── day2 │ ├── authors.txt │ ├── day2-tests.factor │ ├── day2.factor │ └── day2-docs.factor ├── day20 │ └── authors.txt ├── day21 │ └── authors.txt ├── day22 │ ├── authors.txt │ └── day22.factor ├── day23 │ ├── authors.txt │ └── day23.factor ├── day24 │ ├── authors.txt │ └── day24.factor ├── day25 │ ├── authors.txt │ ├── day25-tests.factor │ ├── day25.factor │ └── day25-docs.factor ├── day3 │ ├── authors.txt │ ├── day3-tests.factor │ ├── day3.factor │ └── day3-docs.factor ├── day4 │ ├── authors.txt │ ├── day4.factor │ └── day4-tests.factor ├── day5 │ ├── authors.txt │ ├── day5-tests.factor │ ├── day5.factor │ └── day5-docs.factor ├── day6 │ ├── authors.txt │ ├── day6-tests.factor │ ├── day6.factor │ └── day6-docs.factor ├── day7 │ ├── authors.txt │ ├── day7-tests.factor │ └── day7.factor ├── day8 │ ├── authors.txt │ ├── day8-tests.factor │ └── day8.factor └── day9 │ ├── authors.txt │ ├── day9-tests.factor │ ├── day9-docs.factor │ └── day9.factor ├── rosalind ├── aspc │ ├── authors.txt │ ├── aspc-tests.factor │ ├── aspc.factor │ └── aspc-docs.factor ├── cat │ ├── authors.txt │ ├── cat-tests.factor │ ├── cat.factor │ └── cat-docs.factor ├── cons │ ├── authors.txt │ ├── cons-tests.factor │ ├── cons.factor │ └── cons-docs.factor ├── corr │ ├── authors.txt │ ├── corr-tests.factor │ ├── corr.factor │ └── corr-docs.factor ├── dna │ ├── authors.txt │ ├── dna-tests.factor │ ├── dna.factor │ └── dna-docs.factor ├── edit │ ├── authors.txt │ ├── edit-tests.factor │ ├── edit.factor │ └── edit-docs.factor ├── eval │ ├── authors.txt │ ├── eval-tests.factor │ ├── eval.factor │ └── eval-docs.factor ├── fib │ ├── authors.txt │ ├── fib-tests.factor │ ├── fib.factor │ └── fib-docs.factor ├── fibd │ ├── authors.txt │ ├── fibd-tests.factor │ ├── fibd.factor │ └── fibd-docs.factor ├── gc │ ├── authors.txt │ ├── gc.factor │ ├── gc-docs.factor │ └── gc-tests.factor ├── grph │ ├── authors.txt │ ├── grph.factor │ ├── grph-tests.factor │ └── grph-docs.factor ├── hamm │ ├── authors.txt │ ├── hamm-tests.factor │ ├── hamm.factor │ └── hamm-docs.factor ├── iev │ ├── authors.txt │ ├── iev-tests.factor │ ├── iev.factor │ └── iev-docs.factor ├── inod │ ├── authors.txt │ ├── inod-tests.factor │ ├── inod.factor │ └── inod-docs.factor ├── iprb │ ├── authors.txt │ ├── iprb-tests.factor │ ├── iprb.factor │ └── iprb-docs.factor ├── kmer │ ├── authors.txt │ ├── kmer.factor │ ├── kmer-docs.factor │ └── kmer-tests.factor ├── kmp │ ├── authors.txt │ ├── kmp-tests.factor │ ├── kmp.factor │ └── kmp-docs.factor ├── lcsm │ ├── authors.txt │ └── lcsm-tests.factor ├── lcsq │ ├── authors.txt │ ├── lcsq-tests.factor │ ├── lcsq.factor │ └── lcsq-docs.factor ├── lexf │ ├── authors.txt │ ├── lexf-tests.factor │ ├── lexf.factor │ └── lexf-docs.factor ├── lexv │ ├── authors.txt │ ├── lexv-tests.factor │ ├── lexv.factor │ └── lexv-docs.factor ├── lgis │ ├── authors.txt │ ├── lgis-tests.factor │ ├── lgis.factor │ └── lgis-docs.factor ├── lia │ ├── authors.txt │ ├── lia-tests.factor │ ├── lia.factor │ └── lia-docs.factor ├── long │ ├── authors.txt │ ├── long-tests.factor │ ├── long.factor │ └── long-docs.factor ├── mmch │ ├── authors.txt │ ├── mmch-tests.factor │ ├── mmch.factor │ └── mmch-docs.factor ├── mprt │ ├── authors.txt │ ├── mprt-docs.factor │ └── mprt.factor ├── mrna │ ├── authors.txt │ ├── mrna-tests.factor │ ├── mrna.factor │ └── mrna-docs.factor ├── orf │ ├── authors.txt │ ├── orf-tests.factor │ ├── orf.factor │ └── orf-docs.factor ├── pdst │ ├── authors.txt │ ├── pdst-tests.factor │ ├── pdst.factor │ └── pdst-docs.factor ├── perm │ ├── authors.txt │ ├── perm-tests.factor │ ├── perm.factor │ └── perm-docs.factor ├── pmch │ ├── authors.txt │ ├── pmch-tests.factor │ ├── pmch.factor │ └── pmch-docs.factor ├── pper │ ├── authors.txt │ ├── pper-tests.factor │ ├── pper.factor │ └── pper-docs.factor ├── prob │ ├── authors.txt │ ├── prob-tests.factor │ ├── prob.factor │ └── prob-docs.factor ├── prot │ ├── authors.txt │ ├── prot-tests.factor │ ├── prot.factor │ └── prot-docs.factor ├── prtm │ ├── authors.txt │ ├── prtm-tests.factor │ ├── prtm.factor │ └── prtm-docs.factor ├── revc │ ├── authors.txt │ ├── revc-tests.factor │ ├── revc.factor │ └── revc-docs.factor ├── revp │ ├── authors.txt │ ├── revp-tests.factor │ ├── revp.factor │ └── revp-docs.factor ├── rna │ ├── authors.txt │ ├── rna-tests.factor │ ├── rna.factor │ └── rna-docs.factor ├── rstr │ ├── authors.txt │ ├── rstr-tests.factor │ ├── rstr.factor │ └── rstr-docs.factor ├── seto │ ├── authors.txt │ ├── seto-tests.factor │ ├── seto.factor │ └── seto-docs.factor ├── sign │ ├── authors.txt │ ├── sign-tests.factor │ ├── sign.factor │ └── sign-docs.factor ├── spec │ ├── authors.txt │ ├── spec-tests.factor │ ├── spec.factor │ └── spec-docs.factor ├── splc │ ├── authors.txt │ ├── splc-tests.factor │ ├── splc.factor │ └── splc-docs.factor ├── sseq │ ├── authors.txt │ ├── sseq-tests.factor │ ├── sseq.factor │ └── sseq-docs.factor ├── sset │ ├── authors.txt │ ├── sset-tests.factor │ ├── sset.factor │ └── sset-docs.factor ├── subs │ ├── authors.txt │ ├── subs-tests.factor │ ├── subs.factor │ └── subs-docs.factor ├── tran │ ├── authors.txt │ ├── tran-tests.factor │ ├── tran.factor │ └── tran-docs.factor ├── tree │ ├── authors.txt │ ├── tree-tests.factor │ ├── tree.factor │ └── tree-docs.factor └── common │ ├── authors.txt │ └── common.factor ├── projecteuler └── euler258 │ ├── authors.txt │ └── euler258.factor ├── tools └── problem-solving │ └── authors.txt ├── .gitpod.yml ├── .editorconfig ├── .gitpod.Dockerfile ├── .factor-rc ├── README.md └── LICENSE /datasets/rosalind/perm.txt: -------------------------------------------------------------------------------- 1 | 6 -------------------------------------------------------------------------------- /datasets/rosalind/sign.txt: -------------------------------------------------------------------------------- 1 | 5 -------------------------------------------------------------------------------- /datasets/aoc2015/day4.txt: -------------------------------------------------------------------------------- 1 | yzbqklnj -------------------------------------------------------------------------------- /datasets/rosalind/fib.txt: -------------------------------------------------------------------------------- 1 | 35 4 -------------------------------------------------------------------------------- /datasets/rosalind/fibd.txt: -------------------------------------------------------------------------------- 1 | 87 19 -------------------------------------------------------------------------------- /datasets/rosalind/inod.txt: -------------------------------------------------------------------------------- 1 | 9795 -------------------------------------------------------------------------------- /datasets/rosalind/lia.txt: -------------------------------------------------------------------------------- 1 | 6 15 -------------------------------------------------------------------------------- /datasets/rosalind/pper.txt: -------------------------------------------------------------------------------- 1 | 100 9 -------------------------------------------------------------------------------- /datasets/rosalind/sset.txt: -------------------------------------------------------------------------------- 1 | 853 -------------------------------------------------------------------------------- /aoc2015/day1/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /aoc2015/day10/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /aoc2015/day2/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /aoc2015/day3/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /aoc2015/day4/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /aoc2015/day5/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /aoc2015/day6/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /aoc2015/day7/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /aoc2015/day8/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /aoc2015/day9/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /aoc2020/day1/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /aoc2020/day10/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /aoc2020/day11/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /aoc2020/day12/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /aoc2020/day13/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /aoc2020/day14/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /aoc2020/day15/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /aoc2020/day16/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /aoc2020/day17/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /aoc2020/day18/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /aoc2020/day19/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /aoc2020/day2/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /aoc2020/day20/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /aoc2020/day21/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /aoc2020/day22/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /aoc2020/day23/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /aoc2020/day24/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /aoc2020/day25/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /aoc2020/day3/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /aoc2020/day4/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /aoc2020/day5/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /aoc2020/day6/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /aoc2020/day7/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /aoc2020/day8/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /aoc2020/day9/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /datasets/aoc2015/day10.txt: -------------------------------------------------------------------------------- 1 | 3113322113 -------------------------------------------------------------------------------- /datasets/aoc2020/day23.txt: -------------------------------------------------------------------------------- 1 | 789465123 -------------------------------------------------------------------------------- /datasets/rosalind/aspc.txt: -------------------------------------------------------------------------------- 1 | 1677 891 -------------------------------------------------------------------------------- /datasets/rosalind/iprb.txt: -------------------------------------------------------------------------------- 1 | 28 20 21 -------------------------------------------------------------------------------- /rosalind/aspc/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/cat/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/cons/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/corr/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/dna/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/edit/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/eval/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/fib/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/fibd/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/gc/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/grph/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/hamm/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/iev/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/inod/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/iprb/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/kmer/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/kmp/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/lcsm/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/lcsq/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/lexf/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/lexv/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/lgis/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/lia/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/long/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/mmch/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/mprt/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/mrna/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/orf/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/pdst/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/perm/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/pmch/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/pper/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/prob/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/prot/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/prtm/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/revc/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/revp/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/rna/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/rstr/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/seto/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/sign/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/spec/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/splc/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/sseq/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/sset/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/subs/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/tran/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /rosalind/tree/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /datasets/aoc2020/day15.txt: -------------------------------------------------------------------------------- 1 | 1,2,16,19,18,0 -------------------------------------------------------------------------------- /rosalind/common/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /datasets/aoc2020/day25.txt: -------------------------------------------------------------------------------- 1 | 3469259 2 | 13170438 -------------------------------------------------------------------------------- /projecteuler/euler258/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /tools/problem-solving/authors.txt: -------------------------------------------------------------------------------- 1 | Bubbler 2 | -------------------------------------------------------------------------------- /datasets/rosalind/lexf.txt: -------------------------------------------------------------------------------- 1 | A B C D E F G H I 2 | 3 -------------------------------------------------------------------------------- /datasets/rosalind/rstr.txt: -------------------------------------------------------------------------------- 1 | 80453 0.535716 2 | ATTCGGGT -------------------------------------------------------------------------------- /datasets/rosalind/lexv.txt: -------------------------------------------------------------------------------- 1 | K B I Q A T W Z N O J E 2 | 3 -------------------------------------------------------------------------------- /datasets/rosalind/iev.txt: -------------------------------------------------------------------------------- 1 | 16354 19363 19775 16799 17020 17888 -------------------------------------------------------------------------------- /.gitpod.yml: -------------------------------------------------------------------------------- 1 | image: 2 | file: .gitpod.Dockerfile 3 | tasks: 4 | - command: "cp .factor-rc ~/" -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | charset = utf-8 -------------------------------------------------------------------------------- /datasets/aoc2020/day17.txt: -------------------------------------------------------------------------------- 1 | #####..# 2 | #..###.# 3 | ###..... 4 | .#.#.#.. 5 | ##.#..#. 6 | ######.. 7 | .##..### 8 | ###.#### -------------------------------------------------------------------------------- /datasets/rosalind/pmch.txt: -------------------------------------------------------------------------------- 1 | >Rosalind_3614 2 | CGGAAUCUAUACGUGCGGCCGAACGAUGAUCAAUCACUCGCCGCUGCGGGGUUUAGGAUG 3 | AUCCUUACCACGGC -------------------------------------------------------------------------------- /datasets/rosalind/mmch.txt: -------------------------------------------------------------------------------- 1 | >Rosalind_5485 2 | CGAUAGUAAGGUCACCCUGGGCUCUCGAUAAACGUAGCAUGGCAUUGGUGGAGUGGACUC 3 | UUGCUACCACUUCCCCAAUGUCUGUCGUUCGA -------------------------------------------------------------------------------- /datasets/rosalind/eval.txt: -------------------------------------------------------------------------------- 1 | 817226 2 | CTCTGAGG 3 | 0.000 0.062 0.115 0.186 0.250 0.287 0.378 0.399 0.457 0.509 0.601 0.665 0.686 0.773 0.818 0.889 0.926 1.000 -------------------------------------------------------------------------------- /.gitpod.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM bubbler9903/factor-gitpod:latest 2 | 3 | USER root 4 | RUN apt-get update -y -q \ 5 | && apt-get install -y -q --no-install-recommends netpbm 6 | 7 | USER gitpod -------------------------------------------------------------------------------- /rosalind/seto/seto-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test rosalind.seto ; 4 | IN: rosalind.seto.tests 5 | -------------------------------------------------------------------------------- /datasets/aoc2020/day13.txt: -------------------------------------------------------------------------------- 1 | 1004098 2 | 23,x,x,x,x,x,x,x,x,x,x,x,x,41,x,x,x,x,x,x,x,x,x,509,x,x,x,x,x,x,x,x,x,x,x,x,13,17,x,x,x,x,x,x,x,x,x,x,x,x,x,x,29,x,401,x,x,x,x,x,37,x,x,x,x,x,x,x,x,x,x,x,x,19 -------------------------------------------------------------------------------- /datasets/rosalind/prob.txt: -------------------------------------------------------------------------------- 1 | CTTCGCCTCCATCTGCTGCTGTGCTGGAGAAGCCAGGAGGTTATAGAACTGTATAAAAGCCTTTCCTCATCAGGTATGTTCCCTT 2 | 0.107 0.141 0.175 0.238 0.328 0.334 0.394 0.492 0.524 0.563 0.614 0.668 0.727 0.827 0.839 0.917 -------------------------------------------------------------------------------- /rosalind/inod/inod-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test rosalind.inod ; 4 | IN: rosalind.inod.tests 5 | 6 | { 2 } [ 4 inod ] unit-test -------------------------------------------------------------------------------- /rosalind/sset/sset-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test rosalind.sset ; 4 | IN: rosalind.sset.tests 5 | 6 | { 8 } [ 3 sset ] unit-test -------------------------------------------------------------------------------- /rosalind/aspc/aspc-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test rosalind.aspc ; 4 | IN: rosalind.aspc.tests 5 | 6 | { 42 } [ 6 3 aspc ] unit-test -------------------------------------------------------------------------------- /rosalind/fib/fib-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test rosalind.fib ; 4 | IN: rosalind.fib.tests 5 | 6 | { 19 } [ 5 3 fib ] unit-test 7 | -------------------------------------------------------------------------------- /rosalind/fibd/fibd-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test rosalind.fibd ; 4 | IN: rosalind.fibd.tests 5 | 6 | { 4 } [ 6 3 fibd ] unit-test 7 | -------------------------------------------------------------------------------- /rosalind/mrna/mrna-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test rosalind.mrna ; 4 | IN: rosalind.mrna.tests 5 | 6 | { 12 } [ "MA" mrna ] unit-test 7 | -------------------------------------------------------------------------------- /rosalind/mmch/mmch-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test rosalind.mmch ; 4 | IN: rosalind.mmch.tests 5 | 6 | { 6 } [ "AUGCUUC" mmch ] unit-test 7 | -------------------------------------------------------------------------------- /rosalind/pper/pper-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test rosalind.pper ; 4 | IN: rosalind.pper.tests 5 | 6 | { 51200 } [ 21 7 pper ] unit-test 7 | -------------------------------------------------------------------------------- /rosalind/edit/edit-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test rosalind.edit ; 4 | IN: rosalind.edit.tests 5 | 6 | { 5 } [ "PLEASANTLY" "MEANLY" edit ] unit-test -------------------------------------------------------------------------------- /rosalind/iev/iev-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test rosalind.iev ; 4 | IN: rosalind.iev.tests 5 | 6 | { 7/2 } [ { 1 0 0 1 0 1 } iev ] unit-test 7 | -------------------------------------------------------------------------------- /rosalind/pmch/pmch-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test rosalind.pmch ; 4 | IN: rosalind.pmch.tests 5 | 6 | { 12 } [ "AGCUAGUCAU" pmch ] unit-test 7 | -------------------------------------------------------------------------------- /rosalind/revc/revc-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test rosalind.revc ; 4 | IN: rosalind.revc.tests 5 | 6 | { "ACCGGGTTTT" } [ "AAAACCCGGT" revc ] unit-test 7 | -------------------------------------------------------------------------------- /aoc2020/day25/day25-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test aoc2020.day25 ; 4 | IN: aoc2020.day25.tests 5 | 6 | { 14897079 } [ 5764801 17807724 day25-silver ] unit-test -------------------------------------------------------------------------------- /rosalind/lia/lia-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: math.functions rosalind.lia tools.test ; 4 | IN: rosalind.lia.tests 5 | 6 | { t } [ 2 1 lia 0.684 0.001 ~ ] unit-test 7 | -------------------------------------------------------------------------------- /rosalind/cat/cat-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test rosalind.cat ; 4 | IN: rosalind.cat.tests 5 | 6 | { 2 } [ "AUAU" cat ] unit-test 7 | { 2 } [ "UAGCGUGAUCAC" cat ] unit-test -------------------------------------------------------------------------------- /rosalind/hamm/hamm-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test rosalind.hamm ; 4 | IN: rosalind.hamm.tests 5 | 6 | { 7 } [ "GAGCCTACTAACGGGAT" "CATCGTAATGACGGCCT" hamm ] unit-test 7 | -------------------------------------------------------------------------------- /rosalind/prtm/prtm-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: math.functions rosalind.prtm tools.test ; 4 | IN: rosalind.prtm.tests 5 | 6 | { t } [ "SKADYEK" prtm 821.392 1e-3 ~ ] unit-test 7 | -------------------------------------------------------------------------------- /datasets/rosalind/mprt.txt: -------------------------------------------------------------------------------- 1 | Q8R1Y2 2 | P01106_MYC_HUMAN 3 | P80370_DLK_HUMAN 4 | B8CH81 5 | P08709_FA7_HUMAN 6 | P31096_OSTP_BOVIN 7 | P10761_ZP3_MOUSE 8 | P07204_TRBM_HUMAN 9 | B8GYE3 10 | P01046_KNL1_BOVIN 11 | Q5PA87 12 | P01008_ANT3_HUMAN 13 | P01589_IL2A_HUMAN -------------------------------------------------------------------------------- /rosalind/iprb/iprb-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: math.functions rosalind.iprb tools.test ; 4 | IN: rosalind.iprb.tests 5 | 6 | { t } [ 2 2 2 iprb 0.783333333333 1e-6 ~ ] unit-test 7 | -------------------------------------------------------------------------------- /rosalind/rna/rna-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test rosalind.rna ; 4 | IN: rosalind.rna.tests 5 | 6 | { "GAUGGAACUUGACUACGUAAAUU" } [ "GATGGAACTTGACTACGTAAATT" rna ] unit-test 7 | -------------------------------------------------------------------------------- /rosalind/rstr/rstr-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: math.functions rosalind.rstr tools.test ; 4 | IN: rosalind.rstr.tests 5 | 6 | { t } [ 90000 0.6 "ATAGCCGA" rstr 0.689 0.001 ~ ] unit-test -------------------------------------------------------------------------------- /rosalind/subs/subs-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: arrays tools.test rosalind.subs ; 4 | IN: rosalind.subs.tests 5 | 6 | { { 2 4 10 } } [ "GATATATGCATATACTT" "ATAT" subs >array ] unit-test -------------------------------------------------------------------------------- /rosalind/eval/eval-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test rosalind.eval ; 4 | IN: rosalind.eval.tests 5 | 6 | { t } [ 10 "AG" { 0.25 0.5 0.75 } eval { 0.422 0.563 0.422 } 0.001 v~ ] unit-test -------------------------------------------------------------------------------- /rosalind/lcsm/lcsm-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: rosalind.lcsm sequences tools.test ; 4 | IN: rosalind.lcsm.tests 5 | 6 | { 2 } [ { "GATTACA" "TAGACCA" "ATACA" } lcsm length ] unit-test 7 | -------------------------------------------------------------------------------- /rosalind/spec/spec-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test rosalind.spec ; 4 | IN: rosalind.spec.tests 5 | 6 | { "WMQS" } [ { 3524.8542 3710.9335 3841.974 3970.0326 4057.0646 } spec ] unit-test -------------------------------------------------------------------------------- /rosalind/tree/tree-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test rosalind.tree ; 4 | IN: rosalind.tree.tests 5 | 6 | { 3 } [ 10 { { 1 2 } { 2 8 } { 4 10 } { 5 9 } { 6 10 } { 7 9 } } tree ] unit-test 7 | -------------------------------------------------------------------------------- /rosalind/kmp/kmp-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test rosalind.kmp ; 4 | IN: rosalind.kmp.tests 5 | 6 | { V{ 0 0 0 1 2 0 0 0 0 0 0 1 2 1 2 3 4 5 3 0 0 } } [ "CAGCATGGTATCACAGCAGAG" kmp ] unit-test -------------------------------------------------------------------------------- /rosalind/perm/perm-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test rosalind.perm ; 4 | IN: rosalind.perm.tests 5 | 6 | { { { 1 2 3 } { 1 3 2 } { 2 1 3 } { 2 3 1 } { 3 1 2 } { 3 2 1 } } 6 } 7 | [ 3 perm ] unit-test 8 | -------------------------------------------------------------------------------- /rosalind/prot/prot-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test rosalind.prot ; 4 | IN: rosalind.prot.tests 5 | 6 | { "MAMAPRTEINSTRING" } [ "AUGGCCAUGGCGCCCAGAACUGAGAUCAAUAGUACCCGUAUUAACGGGUGA" prot ] unit-test 7 | -------------------------------------------------------------------------------- /.factor-rc: -------------------------------------------------------------------------------- 1 | USING: parser vocabs vocabs.loader sequences namespaces tools.scaffold 2 | environment ; 3 | vocab-roots [ "." suffix ] change 4 | { "sequences.extras" "assocs.extras" "grouping.extras" 5 | "tools.problem-solving" } [ require ] each 6 | "AUTHOR" os-env developer-name set-global 7 | auto-use -------------------------------------------------------------------------------- /rosalind/dna/dna-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test rosalind.dna ; 4 | IN: rosalind.dna.tests 5 | 6 | { "20 12 17 21" } [ "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC" dna ] unit-test 7 | -------------------------------------------------------------------------------- /aoc2020/day13/day13-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test aoc2020.day13 ; 4 | IN: aoc2020.day13.tests 5 | 6 | { 295 } [ 939 { 7 13 59 31 19 } day13-silver ] unit-test 7 | { 1068781 } [ { 7 13 f f 59 f 31 19 } day13-gold ] unit-test -------------------------------------------------------------------------------- /rosalind/lexf/lexf-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test rosalind.lexf ; 4 | IN: rosalind.lexf.tests 5 | 6 | { { "AA" "AC" "AG" "AT" "CA" "CC" "CG" "CT" "GA" "GC" "GG" "GT" "TA" "TC" "TG" "TT" } } 7 | [ "ACGT" 2 lexf ] unit-test 8 | -------------------------------------------------------------------------------- /datasets/rosalind/cat.txt: -------------------------------------------------------------------------------- 1 | >Rosalind_6229 2 | CAUGAUCACGCGAUCCAUGGCCUAGUAGUUAUAUAAAUUAUAUGCACGAGCUUGGGGCCU 3 | ACCCGCGUAUAGCCGCAUAUGGGAUAGCUCAGGCCUCGUGCUAUGCGAGCUGGGGCCGCC 4 | CCAGCAGCUGCGCAGAUCUAUAUCUAGGCAAUAUAAUUUUAAAUUCGCGAAUGAUUAUAC 5 | CCGCUCGCGACGUAUAAUGCGUACGACGUAAUACGCGUUGCGCGGCUUCUAGCCGCUAGC 6 | UAGGAUAAUAUAUAGAUAUCCG -------------------------------------------------------------------------------- /aoc2020/day1/day1-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test aoc2020.day1 ; 4 | IN: aoc2020.day1.tests 5 | 6 | { 514579 } [ { 1721 979 366 299 675 1456 } day1-silver ] unit-test 7 | { 241861950 } [ { 1721 979 366 299 675 1456 } day1-gold ] unit-test 8 | -------------------------------------------------------------------------------- /aoc2020/day5/day5-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test aoc2020.day5 ; 4 | IN: aoc2020.day5.tests 5 | 6 | { 567 } [ "BFFFBBFRRR" seatcode ] unit-test 7 | { 119 } [ "FFFBBBFRRR" seatcode ] unit-test 8 | { 820 } [ "BBFFBBFRLL" seatcode ] unit-test 9 | -------------------------------------------------------------------------------- /aoc2015/day10/day10-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: aoc2015.day10 kernel sequences tools.test ; 4 | IN: aoc2015.day10.tests 5 | 6 | { { { 1 1 } { 2 1 } { 1 2 1 1 } { 1 1 1 2 2 1 } { 3 1 2 2 1 1 } } } 7 | [ { 1 } 5 [ look-say dup ] replicate nip ] unit-test -------------------------------------------------------------------------------- /rosalind/revp/revp-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: rosalind.revp sets tools.test ; 4 | IN: rosalind.revp.tests 5 | 6 | { t } [ "TCAATGCATGCGGGTCTATATGCAT" revp 7 | { { 4 6 } { 5 4 } { 6 6 } { 7 4 } { 17 4 } { 18 4 } { 20 6 } { 21 4 } } set= ] unit-test 8 | -------------------------------------------------------------------------------- /rosalind/sseq/sseq-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: grouping kernel math rosalind.sseq sequences tools.test ; 4 | IN: rosalind.sseq.tests 5 | 6 | { t "GTA" } [ "ACGTACGTGACG" "GTA" sseq [ [ < ] monotonic? ] [ [ 1 - ] map "ACGTACGTGACG" nths ] bi ] unit-test 7 | -------------------------------------------------------------------------------- /aoc2020/day10/day10-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test aoc2020.day10 ; 4 | IN: aoc2020.day10.tests 5 | 6 | CONSTANT: example { 16 10 15 5 1 11 7 19 6 12 4 } 7 | 8 | { 35 } [ example day10-silver ] unit-test 9 | { 8 } [ example day10-gold ] unit-test 10 | -------------------------------------------------------------------------------- /aoc2020/day17/day17-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test aoc2020.day17 ; 4 | IN: aoc2020.day17.tests 5 | 6 | CONSTANT: example { { 0 1 0 } { 0 0 1 } { 1 1 1 } } 7 | 8 | { 112 } [ example day17-silver ] unit-test 9 | { 848 } [ example day17-gold ] unit-test 10 | -------------------------------------------------------------------------------- /rosalind/lexv/lexv-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: grouping math.order rosalind.lexv sequences tools.test ; 4 | IN: rosalind.lexv.tests 5 | 6 | { 39 } [ "DNA" 3 lexv length ] unit-test 7 | { t } [ "DNA" 3 lexv [ [ "DNA" index ] { } map-as ] map [ before? ] monotonic? ] unit-test -------------------------------------------------------------------------------- /rosalind/sign/sign-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: kernel rosalind.sign sets tools.test ; 4 | IN: rosalind.sign.tests 5 | 6 | CONSTANT: output { { -1 -2 } { -1 2 } { 1 -2 } { 1 2 } { -2 -1 } { -2 1 } { 2 -1 } { 2 1 } } 7 | 8 | { t 8 } [ 2 sign [ output set= ] dip ] unit-test -------------------------------------------------------------------------------- /rosalind/inod/inod.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: io.encodings.utf8 io.files math math.parser prettyprint ; 4 | IN: rosalind.inod 5 | 6 | : inod ( n -- m ) 2 - ; 7 | 8 | : inod-main ( -- ) "datasets/rosalind/inod.txt" utf8 file-contents dec> inod . ; 9 | 10 | MAIN: inod-main -------------------------------------------------------------------------------- /rosalind/prob/prob-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: math.vectors rosalind.prob tools.test ; 4 | IN: rosalind.prob.tests 5 | 6 | { t } [ 7 | "ACGATACAA" { 0.129 0.287 0.423 0.476 0.641 0.742 0.783 } prob 8 | { -5.737 -5.217 -5.263 -5.360 -5.958 -6.628 -7.009 } 0.001 v~ 9 | ] unit-test -------------------------------------------------------------------------------- /rosalind/sset/sset.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: io.encodings.utf8 io.files math math.parser prettyprint ; 4 | IN: rosalind.sset 5 | 6 | : sset ( n -- m ) 2^ 1000000 mod ; 7 | 8 | : sset-main ( -- ) "datasets/rosalind/sset.txt" utf8 file-contents dec> sset . ; 9 | 10 | MAIN: sset-main -------------------------------------------------------------------------------- /aoc2015/day2/day2-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test aoc2015.day2 ; 4 | IN: aoc2015.day2.tests 5 | 6 | { 58 } [ { 2 3 4 } wrapping-paper ] unit-test 7 | { 43 } [ { 1 1 10 } wrapping-paper ] unit-test 8 | 9 | { 34 } [ { 2 3 4 } ribbon ] unit-test 10 | { 14 } [ { 1 1 10 } ribbon ] unit-test -------------------------------------------------------------------------------- /rosalind/prtm/prtm.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: assocs io.encodings.utf8 io.files prettyprint sequences rosalind.common ; 4 | IN: rosalind.prtm 5 | 6 | : prtm ( protein -- mass ) [ protein-mass-table at ] { } map-as sum ; 7 | 8 | : prtm-main ( -- ) "datasets/rosalind/prtm.txt" utf8 file-contents 9 | prtm . ; 10 | 11 | MAIN: prtm-main -------------------------------------------------------------------------------- /rosalind/revc/revc.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: assocs io io.encodings.utf8 io.files sequences ; 4 | IN: rosalind.revc 5 | 6 | : revc ( dna-str -- reverse-complement ) 7 | [ H{ "AT" "CG" "GC" "TA" } at ] map reverse ; 8 | 9 | : revc-main ( -- ) "datasets/rosalind/revc.txt" utf8 file-contents revc print ; 10 | 11 | MAIN: revc-main -------------------------------------------------------------------------------- /rosalind/corr/corr-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: rosalind.corr sets tools.test ; 4 | IN: rosalind.corr.tests 5 | 6 | CONSTANT: input { "TCATC" "TTCAT" "TCATC" "TGAAA" "GAGGA" "TTTCA" "ATCAA" "TTGAT" "TTTCC" } 7 | CONSTANT: output { { "TTCAT" "TTGAT" } { "GAGGA" "GATGA" } { "TTTCC" "TTTCA" } } 8 | 9 | { t } [ input corr output set= ] unit-test -------------------------------------------------------------------------------- /rosalind/orf/orf-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: rosalind.orf sets tools.test ; 4 | IN: rosalind.orf.tests 5 | 6 | { t } 7 | [ "AGCCATGTAGCTAACTCAGGTTACATGGGGATGACCCCGCGACTTGGATTAGAGTCTCTTTTGGAATAAGCCTGAATGATCCGAGTAGCATCTCAG" orf 8 | { "MLLGSFRLIPKETLIQVAGSSPCNLS" 9 | "M" 10 | "MGMTPRLGLESLLE" 11 | "MTPRLGLESLLE" } set= ] unit-test -------------------------------------------------------------------------------- /aoc2020/day9/day9-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test aoc2020.day9 ; 4 | IN: aoc2020.day9.tests 5 | 6 | CONSTANT: example { 35 20 15 25 47 40 62 55 65 95 102 117 150 182 127 219 299 277 309 576 } 7 | 8 | { 127 } [ example 5 day9-silver ] unit-test 9 | { 62 } [ example 5 day9-gold-naive ] unit-test 10 | { 62 } [ example 5 day9-gold ] unit-test -------------------------------------------------------------------------------- /datasets/aoc2020/day22.txt: -------------------------------------------------------------------------------- 1 | Player 1: 2 | 41 3 | 48 4 | 12 5 | 6 6 | 1 7 | 25 8 | 47 9 | 43 10 | 4 11 | 35 12 | 10 13 | 13 14 | 23 15 | 39 16 | 22 17 | 28 18 | 44 19 | 42 20 | 32 21 | 31 22 | 24 23 | 50 24 | 34 25 | 29 26 | 14 27 | 28 | Player 2: 29 | 36 30 | 49 31 | 11 32 | 16 33 | 20 34 | 17 35 | 26 36 | 30 37 | 18 38 | 5 39 | 2 40 | 38 41 | 7 42 | 27 43 | 21 44 | 9 45 | 19 46 | 15 47 | 8 48 | 45 49 | 37 50 | 40 51 | 33 52 | 46 53 | 3 -------------------------------------------------------------------------------- /rosalind/rna/rna.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: io io.encodings.utf8 io.files kernel sequences ; 4 | IN: rosalind.rna 5 | 6 | CONSTANT: T CHAR: T 7 | CONSTANT: U CHAR: U 8 | 9 | : rna ( dna-str -- rna-str ) [ dup T = [ drop U ] when ] map ; 10 | 11 | : rna-main ( -- ) "datasets/rosalind/rna.txt" utf8 file-contents rna print ; 12 | 13 | MAIN: rna-main 14 | -------------------------------------------------------------------------------- /rosalind/iev/iev.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: io.encodings.utf8 io.files math math.parser math.vectors 4 | prettyprint sequences splitting ; 5 | IN: rosalind.iev 6 | 7 | : iev ( vec -- n ) 8 | { 2 2 2 3/2 1 0 } v. ; 9 | 10 | : iev-main ( -- ) "datasets/rosalind/iev.txt" utf8 file-contents 11 | " " split [ dec> ] map iev >float . ; 12 | 13 | MAIN: iev-main -------------------------------------------------------------------------------- /rosalind/tran/tran-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test rosalind.tran ; 4 | IN: rosalind.tran.tests 5 | 6 | { t } [ 7 | "GCAACGCACAACGAAAACCCTTAGGGACTGGATTATTTCGTGATCGTTGTAGTTATTGGAAGTACGGGCATCAACCCAGTT" 8 | "TTATCTGACAAAGAAAGCCGTCAACGGCTGGATAATTTCGCGATCGTGCTGGTTACTGGCGGTACGAGTGTTCCTTTGGGT" 9 | tran 1.21428571429 0.001 ~ 10 | ] unit-test 11 | -------------------------------------------------------------------------------- /rosalind/hamm/hamm.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: io.encodings.utf8 io.files kernel prettyprint sequences 4 | sequences.extras splitting ; 5 | IN: rosalind.hamm 6 | 7 | : hamm ( string1 string2 -- count ) 8 | [ = not ] 2count ; 9 | 10 | : hamm-main ( -- ) "datasets/rosalind/hamm.txt" utf8 file-contents 11 | "\n" split first2 hamm . ; 12 | 13 | MAIN: hamm-main -------------------------------------------------------------------------------- /rosalind/pdst/pdst-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test rosalind.pdst math.matrices ; 4 | IN: rosalind.pdst.tests 5 | 6 | CONSTANT: example { "TTTCCATTTA" "GATTCATTTC" "TTTCCATTTT" "GTTCCATTTA" } 7 | CONSTANT: ans { { 0.0 0.4 0.1 0.1 } { 0.4 0.0 0.4 0.3 } { 0.1 0.4 0.0 0.2 } { 0.1 0.3 0.2 0.0 } } 8 | 9 | { t } [ example pdst ans 0.001 m~ ] unit-test 10 | -------------------------------------------------------------------------------- /rosalind/pper/pper.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: io.encodings.utf8 io.files math math.combinatorics 4 | math.parser prettyprint sequences splitting ; 5 | IN: rosalind.pper 6 | 7 | : pper ( n k -- ans ) nPk 1000000 mod ; 8 | 9 | : pper-main ( -- ) "datasets/rosalind/pper.txt" utf8 file-contents 10 | " " split [ dec> ] map first2 pper . ; 11 | 12 | MAIN: pper-main -------------------------------------------------------------------------------- /aoc2015/day3/day3-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test aoc2015.day3 ; 4 | IN: aoc2015.day3.tests 5 | 6 | { 2 } [ ">" day3-silver ] unit-test 7 | { 4 } [ "^>v<" day3-silver ] unit-test 8 | { 2 } [ "^v^v^v^v^v" day3-silver ] unit-test 9 | 10 | { 3 } [ "^v" day3-gold ] unit-test 11 | { 3 } [ "^>v<" day3-gold ] unit-test 12 | { 11 } [ "^v^v^v^v^v" day3-gold ] unit-test -------------------------------------------------------------------------------- /rosalind/prot/prot.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: grouping io io.encodings.utf8 io.files kernel math 4 | sequences splitting rosalind.common ; 5 | IN: rosalind.prot 6 | 7 | : prot ( rna -- protein ) 8 | 3 group [ rna3>amino ] "" map-as 9 | "." split first ; 10 | 11 | : prot-main ( -- ) "datasets/rosalind/prot.txt" utf8 file-contents 12 | prot print ; 13 | 14 | MAIN: prot-main -------------------------------------------------------------------------------- /rosalind/dna/dna.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: assocs io io.encodings.utf8 io.files math math.parser 4 | math.statistics sequences sorting ; 5 | IN: rosalind.dna 6 | 7 | : dna ( str -- counts ) 8 | "ACGT" append histogram sort-keys values [ 1 - number>string ] map " " join ; 9 | 10 | : dna-main ( -- ) "datasets/rosalind/dna.txt" utf8 file-contents dna print ; 11 | 12 | MAIN: dna-main -------------------------------------------------------------------------------- /rosalind/tree/tree.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: io.encodings.utf8 io.files kernel math math.parser 4 | prettyprint sequences splitting ; 5 | IN: rosalind.tree 6 | 7 | : tree ( n adjlist -- ans ) length - 1 - ; 8 | 9 | : tree-main ( -- ) "datasets/rosalind/tree.txt" utf8 file-contents 10 | "\n" split unclip dec> swap [ " " split [ dec> ] map ] map tree . ; 11 | 12 | MAIN: tree-main -------------------------------------------------------------------------------- /aoc2020/day12/day12-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test aoc2020.day12 ; 4 | IN: aoc2020.day12.tests 5 | 6 | STRING: example 7 | F10 8 | N3 9 | F7 10 | R90 11 | F11 12 | ; 13 | 14 | : preprocessed ( -- seq ) 15 | example "\n" split [ unclip [ dec> ] dip 2array ] map ; 16 | 17 | { 25 } [ preprocessed day12-silver ] unit-test 18 | { 286 } [ preprocessed day12-gold ] unit-test 19 | -------------------------------------------------------------------------------- /rosalind/long/long-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: assocs multiline rosalind.common rosalind.long tools.test 4 | ; 5 | IN: rosalind.long.tests 6 | 7 | STRING: example 8 | >Rosalind_56 9 | ATTAGACCTG 10 | >Rosalind_57 11 | CCTGCCGGAA 12 | >Rosalind_58 13 | AGACCTGCCG 14 | >Rosalind_59 15 | GCCGGAATAC 16 | ; 17 | 18 | { "ATTAGACCTGCCGGAATAC" } [ example fasta>assoc values long ] unit-test 19 | -------------------------------------------------------------------------------- /rosalind/lia/lia.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: io.encodings.utf8 io.files kernel math math.parser 4 | math.polynomials prettyprint sequences splitting ; 5 | IN: rosalind.lia 6 | 7 | : lia ( k n -- p ) 8 | [ { 3/4 1/4 } ] 2dip [ 2^ p^ ] dip tail sum >float ; 9 | 10 | : lia-main ( -- ) "datasets/rosalind/lia.txt" utf8 file-contents 11 | " " split [ dec> ] map first2 lia . ; 12 | 13 | MAIN: lia-main -------------------------------------------------------------------------------- /rosalind/lgis/lgis-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test rosalind.lgis ; 4 | IN: rosalind.lgis.tests 5 | 6 | CONSTANT: example { 8 2 1 6 5 7 4 3 9 } 7 | : example-result ( -- seq ) example longest-increasing-subseq ; 8 | 9 | { 4 } [ example-result length ] unit-test 10 | { t } [ example-result [ < ] monotonic? ] unit-test 11 | { t } [ example-result [ example index ] map [ < ] monotonic? ] unit-test -------------------------------------------------------------------------------- /rosalind/fibd/fibd.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: io.encodings.utf8 io.files kernel math math.parser 4 | prettyprint sequences splitting ; 5 | IN: rosalind.fibd 6 | 7 | : fibd ( n m -- ans ) 8 | { 1 } swap 0 pad-tail swap 1 - [ dup rest sum prefix but-last ] times sum ; 9 | 10 | : fibd-main ( -- ) "datasets/rosalind/fibd.txt" utf8 file-contents 11 | " " split [ string>number ] map first2 fibd . ; 12 | 13 | MAIN: fibd-main -------------------------------------------------------------------------------- /rosalind/mrna/mrna.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: arrays assocs io.encodings.utf8 io.files math 4 | math.statistics prettyprint rosalind.common rosalind.prot 5 | sequences ; 6 | IN: rosalind.mrna 7 | 8 | : mrna ( protein -- n ) 9 | "." append >array amino-table histogram substitute product 1000000 mod ; 10 | 11 | : mrna-main ( -- ) "datasets/rosalind/mrna.txt" utf8 file-contents 12 | mrna . ; 13 | 14 | MAIN: mrna-main -------------------------------------------------------------------------------- /rosalind/fib/fib.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: fry io.encodings.utf8 io.files kernel math math.parser 4 | prettyprint sequences splitting ; 5 | IN: rosalind.fib 6 | 7 | : fib ( n k -- ans ) 8 | [ 1 1 ] 2dip [ 1 - ] dip 9 | '[ [ _ * + ] [ drop ] 2bi ] times nip ; 10 | 11 | : fib-main ( -- ) "datasets/rosalind/fib.txt" utf8 file-contents 12 | " " split [ string>number ] map first2 13 | fib . ; 14 | 15 | MAIN: fib-main 16 | -------------------------------------------------------------------------------- /rosalind/lexf/lexf.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: io.encodings.utf8 io.files kernel math.combinatorics 4 | math.parser sequences sets splitting ; 5 | IN: rosalind.lexf 6 | 7 | : lexf ( alphabet length -- strings ) selections ; 8 | 9 | : lexf-main ( -- ) "datasets/rosalind/lexf.txt" utf8 file-contents 10 | "\n" split first2 [ " " diff ] [ dec> ] bi* lexf 11 | "/tmp/output.txt" utf8 set-file-lines ; 12 | 13 | MAIN: lexf-main -------------------------------------------------------------------------------- /rosalind/subs/subs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: grouping io io.encodings.utf8 io.files kernel math 4 | math.parser sequences splitting ; 5 | IN: rosalind.subs 6 | 7 | : subs ( string motif -- indices ) 8 | [ length clump ] [ swap indices [ 1 + ] map ] bi ; 9 | 10 | : subs-main ( -- ) "datasets/rosalind/subs.txt" utf8 file-contents 11 | "\n" split first2 subs [ number>string ] map " " join print ; 12 | 13 | MAIN: subs-main -------------------------------------------------------------------------------- /rosalind/aspc/aspc.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: io.encodings.utf8 io.files kernel math math.combinatorics 4 | math.parser math.ranges prettyprint sequences splitting ; 5 | IN: rosalind.aspc 6 | 7 | : aspc ( n m -- ans ) 8 | [ drop ] [ swap [a,b] ] 2bi [ nCk ] with map sum 1000000 rem ; 9 | 10 | : aspc-main ( -- ) "datasets/rosalind/aspc.txt" utf8 file-contents 11 | " " split [ dec> ] map first2 aspc . ; 12 | 13 | MAIN: aspc-main -------------------------------------------------------------------------------- /rosalind/gc/gc.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: arrays assocs io io.encodings.utf8 io.files kernel math 4 | prettyprint sequences sorting splitting rosalind.common ; 5 | IN: rosalind.gc 6 | 7 | : gc ( assoc -- item ) [ [ [ "GC" member? ] count ] [ length ] bi /f 100 * ] assoc-map sort-values last ; 8 | 9 | : gc-main ( -- ) "datasets/rosalind/gc.txt" utf8 file-contents fasta>assoc 10 | gc first2 swap print . ; 11 | 12 | MAIN: gc-main -------------------------------------------------------------------------------- /rosalind/perm/perm.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: io io.encodings.utf8 io.files kernel math.combinatorics 4 | math.parser math.ranges prettyprint sequences ; 5 | IN: rosalind.perm 6 | 7 | : perm ( n -- perms length ) [ [1,b] all-permutations ] [ factorial ] bi ; 8 | 9 | : perm-main ( -- ) "datasets/rosalind/perm.txt" utf8 file-contents 10 | string>number perm . [ [ number>string ] map " " join print ] each ; 11 | 12 | MAIN: perm-main -------------------------------------------------------------------------------- /rosalind/pmch/pmch.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: arrays assocs io.encodings.utf8 io.files kernel 4 | math.factorials math.statistics prettyprint rosalind.common 5 | sequences ; 6 | IN: rosalind.pmch 7 | 8 | : pmch ( str -- counts ) 9 | histogram "AC" >array swap substitute [ n! ] map product ; 10 | 11 | : pmch-main ( -- ) "datasets/rosalind/pmch.txt" utf8 file-contents 12 | fasta>assoc values first pmch . ; 13 | 14 | MAIN: pmch-main -------------------------------------------------------------------------------- /rosalind/splc/splc-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test rosalind.splc rosalind.common ; 4 | IN: rosalind.splc.tests 5 | 6 | STRING: fasta-example 7 | >Rosalind_10 8 | ATGGTCTACATAGCTGACAAACAGCACGTAGCAATCGGTCGAATCTCGAGAGGCATATGGTCACATGATCGGTCGAGCGTGTTTCAAAGTTTGCGCCTAG 9 | >Rosalind_12 10 | ATCGGTCGAA 11 | >Rosalind_15 12 | ATCGGTCGAGCGTGT 13 | ; 14 | 15 | { "MVYIADKQHVASREAYGHMFKVCA" } [ fasta-example fasta>assoc splc ] unit-test 16 | -------------------------------------------------------------------------------- /rosalind/sseq/sseq.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: assocs fry io io.encodings.utf8 io.files kernel math 4 | math.parser rosalind.common sequences ; 5 | IN: rosalind.sseq 6 | 7 | : sseq ( str subseq -- indices ) 8 | 0 rot '[ swap _ index-from 1 + ] { } accumulate*-as ; 9 | 10 | : sseq-main ( -- ) "datasets/rosalind/sseq.txt" utf8 file-contents 11 | fasta>assoc values first2 sseq [ number>string ] map " " join print ; 12 | 13 | MAIN: sseq-main -------------------------------------------------------------------------------- /rosalind/grph/grph.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: assocs io io.encodings.utf8 io.files kernel 4 | math.combinatorics rosalind.common sequences ; 5 | IN: rosalind.grph 6 | 7 | : grph ( assoc -- edges ) 8 | 2 [ values first2 [ 3 tail* ] [ 3 head ] bi* = ] filter 9 | [ keys ] map ; 10 | 11 | : grph-main ( -- ) "datasets/rosalind/grph.txt" utf8 file-contents 12 | fasta>assoc grph [ " " join print ] each ; 13 | 14 | MAIN: grph-main -------------------------------------------------------------------------------- /aoc2020/day2/day2-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test aoc2020.day2 ; 4 | IN: aoc2020.day2.tests 5 | 6 | { t } [ "1-3 a: abcde" password-valid? ] unit-test 7 | { f } [ "1-3 b: cdefg" password-valid? ] unit-test 8 | { t } [ "2-9 c: ccccccccc" password-valid? ] unit-test 9 | 10 | { t } [ "1-3 a: abcde" password-valid?' ] unit-test 11 | { f } [ "1-3 b: cdefg" password-valid?' ] unit-test 12 | { f } [ "2-9 c: ccccccccc" password-valid?' ] unit-test 13 | -------------------------------------------------------------------------------- /aoc2020/day6/day6-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: aoc2020.day6 multiline sequences splitting tools.test ; 4 | IN: aoc2020.day6.tests 5 | 6 | STRING: example 7 | abc 8 | 9 | a 10 | b 11 | c 12 | 13 | ab 14 | ac 15 | 16 | a 17 | a 18 | a 19 | a 20 | 21 | b 22 | ; 23 | 24 | : example-input ( -- seq ) example "\n\n" split-subseq [ "\n" split ] map ; 25 | 26 | { 11 } [ example-input day6-silver ] unit-test 27 | { 6 } [ example-input day6-gold ] unit-test 28 | -------------------------------------------------------------------------------- /aoc2015/day1/day1.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: arrays io.encodings.utf8 io.files kernel math 4 | math.vectors prettyprint sequences ; 5 | IN: aoc2015.day1 6 | 7 | : day1-silver ( str -- n ) 8 | >array -1 swap n^v sum ; 9 | 10 | : day1-gold ( str -- n ) 11 | >array -1 swap n^v 0 [ + ] accumulate* -1 swap index 1 + ; 12 | 13 | : day1-main ( -- ) "datasets/aoc2015/day1.txt" utf8 file-contents 14 | [ day1-silver . ] [ day1-gold . ] bi ; 15 | 16 | MAIN: day1-main -------------------------------------------------------------------------------- /rosalind/mmch/mmch.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: assocs assocs.extras grouping io.encodings.utf8 io.files 4 | kernel math.combinatorics prettyprint rosalind.common sequences 5 | sorting ; 6 | IN: rosalind.mmch 7 | 8 | : mmch ( str -- ans ) 9 | "AUGC" counts values 2 group 10 | [ first2 sort-pair swap nPk ] map product ; 11 | 12 | : mmch-main ( -- ) 13 | "datasets/rosalind/mmch.txt" utf8 file-contents 14 | fasta>assoc values first mmch . ; 15 | 16 | MAIN: mmch-main -------------------------------------------------------------------------------- /rosalind/splc/splc.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: assocs fry grouping io io.encodings.utf8 io.files 4 | rosalind.common sequences splitting ; 5 | IN: rosalind.splc 6 | 7 | : splc ( assoc -- protein ) 8 | values 1 cut [ '[ _ split-subseq ] map concat ] each 9 | concat { "TU" } substitute 3 group [ rna3>amino ] "" map-as 10 | "." split first ; 11 | 12 | : splc-main ( -- ) "datasets/rosalind/splc.txt" utf8 file-contents 13 | fasta>assoc splc print ; 14 | 15 | MAIN: splc-main -------------------------------------------------------------------------------- /rosalind/iprb/iprb.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: io.encodings.utf8 io.files kernel locals math math.parser 4 | prettyprint sequences splitting ; 5 | IN: rosalind.iprb 6 | 7 | :: iprb ( k m n -- prob ) 8 | 1 m n 2 * + sq m n 4 * + - ! (m+2n)^2 - m - 4n 9 | k m n + + dup 1 - * 4 * /f - ! 1 - above / 4(k+m+n)(k+m+n-1) 10 | ; 11 | 12 | : iprb-main ( -- ) "datasets/rosalind/iprb.txt" utf8 file-contents 13 | " " split [ dec> ] map first3 iprb . ; 14 | 15 | MAIN: iprb-main 16 | -------------------------------------------------------------------------------- /aoc2020/day6/day6.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: io.encodings.utf8 io.files kernel prettyprint sequences 4 | sets splitting ; 5 | IN: aoc2020.day6 6 | 7 | : day6-silver ( answers -- sum ) 8 | [ combine length ] map sum ; 9 | 10 | : day6-gold ( answers -- sum ) 11 | [ intersection length ] map sum ; 12 | 13 | : day6-main ( -- ) "datasets/aoc2020/day6.txt" utf8 file-contents 14 | "\n\n" split-subseq [ "\n" split ] map 15 | [ day6-silver . ] [ day6-gold . ] bi ; 16 | 17 | MAIN: day6-main -------------------------------------------------------------------------------- /aoc2020/day8/day8-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: aoc2020.day8 arrays math.parser multiline sequences 4 | splitting tools.test ; 5 | IN: aoc2020.day8.tests 6 | 7 | STRING: example 8 | nop +0 9 | acc +1 10 | jmp +4 11 | acc +3 12 | jmp -3 13 | acc -99 14 | acc +1 15 | jmp -4 16 | acc +6 17 | ; 18 | 19 | : preprocessed ( -- str ) example "\n" split [ " " split first2 dec> 2array ] map ; 20 | 21 | { 5 } [ preprocessed day8-silver ] unit-test 22 | { 8 } [ preprocessed day8-gold ] unit-test 23 | -------------------------------------------------------------------------------- /rosalind/kmer/kmer.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: assocs grouping io io.encodings.utf8 io.files kernel 4 | math.combinatorics math.parser rosalind.common sequences sorting 5 | ; 6 | IN: rosalind.kmer 7 | 8 | : kmer ( str -- counts ) 9 | [ "ACGT" 4 selections [ 0 ] H{ } map>assoc ] dip 10 | 4 clump [ over inc-at ] each sort-keys values ; 11 | 12 | : kmer-main ( -- ) "datasets/rosalind/kmer.txt" utf8 file-contents 13 | fasta>assoc values first kmer [ 10 >base ] map " " join print ; 14 | 15 | MAIN: kmer-main -------------------------------------------------------------------------------- /rosalind/pdst/pdst.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: assocs io io.encodings.utf8 io.files kernel math 4 | math.parser rosalind.common sequences sequences.extras ; 5 | IN: rosalind.pdst 6 | 7 | : diff% ( seq1 seq2 -- % ) 8 | [ [ = not ] 2count ] [ nip length ] 2bi /f ; 9 | 10 | : pdst ( seq -- matrix ) 11 | dup [ diff% ] cartesian-map ; 12 | 13 | : pdst-main ( -- ) "datasets/rosalind/pdst.txt" utf8 file-contents 14 | fasta>assoc values pdst [ [ number>string ] map " " join print ] each ; 15 | 16 | MAIN: pdst-main -------------------------------------------------------------------------------- /aoc2020/day14/day14-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test aoc2020.day14 ; 4 | IN: aoc2020.day14.tests 5 | 6 | STRING: example1 7 | mask = XXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXX0X 8 | mem[8] = 11 9 | mem[7] = 101 10 | mem[8] = 0 11 | ; 12 | { 165 } [ example1 "\n" split day14-silver ] unit-test 13 | 14 | STRING: example2 15 | mask = 000000000000000000000000000000X1001X 16 | mem[42] = 100 17 | mask = 00000000000000000000000000000000X0XX 18 | mem[26] = 1 19 | ; 20 | { 208 } [ example2 "\n" split day14-gold ] unit-test -------------------------------------------------------------------------------- /aoc2015/day8/day8-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: aoc2015.day8 multiline sequences splitting tools.test ; 4 | IN: aoc2015.day8.tests 5 | 6 | STRING: testcases 7 | "" 8 | "abc" 9 | "aaa\"aaa" 10 | "\x27" 11 | ; 12 | 13 | { { 2 2 3 5 } } [ testcases "\n" split [ (day8-silver) ] map ] unit-test 14 | { { 2 2 3 5 } } [ testcases "\n" split [ (day8-silver)' ] map ] unit-test 15 | 16 | { { 4 4 6 5 } } [ testcases "\n" split [ (day8-gold) ] map ] unit-test 17 | { { 4 4 6 5 } } [ testcases "\n" split [ (day8-gold)' ] map ] unit-test -------------------------------------------------------------------------------- /aoc2020/day3/day3-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: aoc2020.day3 fry kernel multiline sequences splitting 4 | tools.test ; 5 | IN: aoc2020.day3.tests 6 | 7 | STRING: example 8 | ..##....... 9 | #...#...#.. 10 | .#....#..#. 11 | ..#.#...#.# 12 | .#...##..#. 13 | ..#.##..... 14 | .#.#.#....# 15 | .#........# 16 | #.##...#... 17 | #...##....# 18 | .#..#...#.# 19 | ; 20 | 21 | { 7 } [ example "\n" split 3 trees-on-slope ] unit-test 22 | { 336 } [ { 1 3 5 7 1/2 } example "\n" split '[ _ swap trees-on-slope ] map product ] unit-test 23 | -------------------------------------------------------------------------------- /rosalind/orf/orf.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: arrays assocs fry grouping io io.encodings.utf8 io.files 4 | kernel rosalind.common sequences sets ; 5 | IN: rosalind.orf 6 | 7 | : orf ( dna -- proteins ) 8 | dup reverse-complement 2array 9 | [ { "TU" } substitute 10 | dup 3 clump "AUG" swap indices 11 | swap '[ _ swap tail rna>protein ] map 12 | ] map concat sift members ; 13 | 14 | : orf-main ( -- ) "datasets/rosalind/orf.txt" utf8 file-contents 15 | fasta>assoc first second orf [ print ] each ; 16 | 17 | MAIN: orf-main -------------------------------------------------------------------------------- /rosalind/grph/grph-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test rosalind.grph multiline rosalind.common arrays ; 4 | IN: rosalind.grph.tests 5 | 6 | STRING: fasta-example 7 | >Rosalind_0498 8 | AAATAAA 9 | >Rosalind_2391 10 | AAATTTT 11 | >Rosalind_2323 12 | TTTTCCC 13 | >Rosalind_0442 14 | AAATCCC 15 | >Rosalind_5013 16 | GGGTGGG 17 | ; 18 | 19 | { { { "Rosalind_0498" "Rosalind_2391" } 20 | { "Rosalind_0498" "Rosalind_0442" } 21 | { "Rosalind_2391" "Rosalind_2323" } } } 22 | [ fasta-example fasta>assoc grph >array ] unit-test 23 | -------------------------------------------------------------------------------- /aoc2020/day1/day1.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: io io.encodings.utf8 io.files kernel math.combinatorics 4 | math.parser prettyprint sequences splitting ; 5 | IN: aoc2020.day1 6 | 7 | : day1-silver ( seq -- prod ) 8 | 2 all-combinations [ sum 2020 = ] find nip product ; 9 | 10 | : day1-gold ( seq -- prod ) 11 | 3 all-combinations [ sum 2020 = ] find nip product ; 12 | 13 | : day1-main ( -- ) "datasets/aoc2020/day1.txt" utf8 file-contents "\n" split [ string>number ] map 14 | [ day1-silver . ] [ day1-gold . ] bi ; 15 | 16 | MAIN: day1-main -------------------------------------------------------------------------------- /rosalind/prob/prob.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: arrays assocs fry io io.encodings.utf8 io.files kernel 4 | math math.functions math.parser sequences splitting ; 5 | IN: rosalind.prob 6 | 7 | : prob ( str gc-probs -- logprobs ) 8 | swap '[ 2 / 0.5 over - 2array dup append 9 | "GACT" swap zip _ >array swap substitute 10 | [ log10 ] map sum ] map ; 11 | 12 | : prob-main ( -- ) "datasets/rosalind/prob.txt" utf8 file-contents 13 | "\n" split first2 " " split [ dec> ] map prob [ number>string ] map " " join print ; 14 | 15 | MAIN: prob-main -------------------------------------------------------------------------------- /aoc2020/day11/day11-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: aoc2020.day11 arrays math.vectors multiline sequences 4 | splitting tools.test ; 5 | IN: aoc2020.day11.tests 6 | 7 | STRING: example 8 | L.LL.LL.LL 9 | LLLLLLL.LL 10 | L.L.L..L.. 11 | LLLL.LL.LL 12 | L.LL.LL.LL 13 | L.LLLLL.LL 14 | ..L.L..... 15 | LLLLLLLLLL 16 | L.LLLLLL.L 17 | L.LLLLL.LL 18 | ; 19 | 20 | : preprocessed ( -- matrix ) example "\n" split [ >array 76 v-n 30 v/n ] map ; 21 | 22 | { 37 } [ preprocessed day11-silver ] unit-test 23 | { 26 } [ preprocessed day11-gold ] unit-test 24 | -------------------------------------------------------------------------------- /rosalind/lexv/lexv.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: fry io.encodings.utf8 io.files kernel math.combinatorics 4 | math.parser math.ranges sequences sets sorting splitting ; 5 | IN: rosalind.lexv 6 | 7 | : lexv ( str n -- seqs ) 8 | over [ [1,b] ] [ length [0,b) ] bi* 9 | '[ _ swap selections ] map concat natural-sort 10 | swap '[ _ nths ] map ; 11 | 12 | : lexv-main ( -- ) "datasets/rosalind/lexv.txt" utf8 file-contents 13 | "\n" split first2 [ " " without ] [ dec> ] bi* lexv 14 | "/tmp/lexv.txt" utf8 set-file-lines ; 15 | 16 | MAIN: lexv-main -------------------------------------------------------------------------------- /rosalind/lcsq/lcsq-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: kernel rosalind.lcsq sequences tools.test ; 4 | IN: rosalind.lcsq.tests 5 | 6 | : subsequence? ( sub seq -- ? ) 7 | dup empty? [ 2drop f ] [ 8 | over empty? [ 2drop t ] [ 9 | 2dup [ first ] bi@ = 10 | [ [ rest ] bi@ ] [ rest ] if subsequence? 11 | ] if 12 | ] if ; 13 | 14 | { 6 } [ "AACCTTGG" "ACACTGTGA" lcsq length ] unit-test 15 | { t } [ "AACCTTGG" "ACACTGTGA" lcsq "AACCTTGG" subsequence? ] unit-test 16 | { t } [ "AACCTTGG" "ACACTGTGA" lcsq "ACACTGTGA" subsequence? ] unit-test -------------------------------------------------------------------------------- /rosalind/rstr/rstr.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: arrays assocs io io.encodings.utf8 io.files kernel locals 4 | math math.functions math.parser prettyprint sequences splitting 5 | ; 6 | IN: rosalind.rstr 7 | 8 | : 1-n ( n -- 1-n ) 1 swap - ; 9 | 10 | :: rstr ( trials gc-content str -- prob ) 11 | "GACT" gc-content dup 1-n 2array [ 2 / ] map dup append zip 12 | [ str >array ] dip substitute product 1-n trials ^ 1-n ; 13 | 14 | : rstr-main ( -- ) "datasets/rosalind/rstr.txt" utf8 file-contents 15 | " \n" split first3 [ [ dec> ] bi@ ] dip rstr . ; 16 | 17 | MAIN: rstr-main -------------------------------------------------------------------------------- /rosalind/sign/sign.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: io io.encodings.utf8 io.files kernel math.combinatorics 4 | math.parser math.ranges math.vectors prettyprint sequences ; 5 | IN: rosalind.sign 6 | 7 | : sign ( n -- seq len ) 8 | [ [1,b] all-permutations ] 9 | [ { -1 1 } swap selections ] bi 10 | [ v* ] cartesian-map concat dup length ; 11 | 12 | : sign-main ( -- ) "datasets/rosalind/sign.txt" utf8 file-contents dec> 13 | "/tmp/sign.txt" utf8 [ 14 | sign . [ [ number>string ] map " " join print ] each 15 | ] with-output-stream ; 16 | 17 | MAIN: sign-main -------------------------------------------------------------------------------- /aoc2015/day5/day5-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test aoc2015.day5 ; 4 | IN: aoc2015.day5.tests 5 | 6 | { t } [ "ugknbfddgicrmopn" nice-silver? ] unit-test 7 | { t } [ "aaa" nice-silver? ] unit-test 8 | { f } [ "jchzalrnumimnmhp" nice-silver? ] unit-test 9 | { f } [ "haegwjzuvuyypxyu" nice-silver? ] unit-test 10 | { f } [ "dvszwmarrgswjxmb" nice-silver? ] unit-test 11 | 12 | { t } [ "qjhvhtzxzqqjkmpb" nice-gold? ] unit-test 13 | { t } [ "xxyxx" nice-gold? ] unit-test 14 | { f } [ "uurcxstgmygtbstg" nice-gold? ] unit-test 15 | { f } [ "ieodomkazucvgmuy" nice-gold? ] unit-test -------------------------------------------------------------------------------- /aoc2015/day1/day1-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test aoc2015.day1 ; 4 | IN: aoc2015.day1.tests 5 | 6 | { 0 } [ "(())" day1-silver ] unit-test 7 | { 0 } [ "()()" day1-silver ] unit-test 8 | { 3 } [ "(((" day1-silver ] unit-test 9 | { 3 } [ "(()(()(" day1-silver ] unit-test 10 | { 3 } [ "))(((((" day1-silver ] unit-test 11 | { -1 } [ "())" day1-silver ] unit-test 12 | { -1 } [ "))(" day1-silver ] unit-test 13 | { -3 } [ ")))" day1-silver ] unit-test 14 | { -3 } [ ")())())" day1-silver ] unit-test 15 | 16 | { 1 } [ ")" day1-gold ] unit-test 17 | { 5 } [ "()())" day1-gold ] unit-test -------------------------------------------------------------------------------- /rosalind/sset/sset-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel math ; 4 | IN: rosalind.sset 5 | 6 | HELP: sset 7 | { $values 8 | { "n" integer } 9 | { "m" integer } 10 | } 11 | { $description "Solves the problem SSET on Rosalind: given the number of items in a set, calculate the number of its subsets modulo 1000000." } ; 12 | 13 | HELP: sset-main 14 | { $description "Solves the problem SSET on Rosalind, using a real dataset." } ; 15 | 16 | ARTICLE: "rosalind.sset" "rosalind.sset" 17 | { $vocab-link "rosalind.sset" } 18 | ; 19 | 20 | ABOUT: "rosalind.sset" 21 | -------------------------------------------------------------------------------- /rosalind/cons/cons-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: multiline rosalind.common rosalind.cons tools.test ; 4 | IN: rosalind.cons.tests 5 | 6 | STRING: fasta-example 7 | >Rosalind_1 8 | ATCCAGCT 9 | >Rosalind_2 10 | GGGCAACT 11 | >Rosalind_3 12 | ATGGATCT 13 | >Rosalind_4 14 | AAGCAACC 15 | >Rosalind_5 16 | TTGGAACT 17 | >Rosalind_6 18 | ATGCCATT 19 | >Rosalind_7 20 | ATGGCACT 21 | ; 22 | 23 | { 24 | { 25 | { 5 1 0 0 5 5 0 0 } 26 | { 0 0 1 4 2 0 6 1 } 27 | { 1 1 6 3 0 1 0 0 } 28 | { 1 5 0 0 0 1 1 6 } 29 | } 30 | "ATGCAACT" 31 | } [ fasta-example fasta>assoc cons ] unit-test -------------------------------------------------------------------------------- /rosalind/cons/cons.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: arrays assocs io io.encodings.utf8 io.files kernel math 4 | math.parser math.statistics prettyprint sequences sorting 5 | splitting strings rosalind.common ; 6 | IN: rosalind.cons 7 | 8 | : cons ( assoc -- histo consensus ) 9 | values flip [ [ "ACGT" append histogram sort-keys values [ 1 - ] map ] map flip ] 10 | [ [ mode ] map >string ] bi ; 11 | 12 | : cons-main ( -- ) "datasets/rosalind/cons.txt" utf8 file-contents fasta>assoc 13 | cons print "ACGT" [ write1 ": " write [ number>string ] map " " join print ] 2each ; 14 | 15 | MAIN: cons-main -------------------------------------------------------------------------------- /rosalind/pmch/pmch-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel math strings ; 4 | IN: rosalind.pmch 5 | 6 | HELP: pmch 7 | { $values 8 | { "str" string } 9 | { "counts" integer } 10 | } 11 | { $description "Solves the problem PMCH on Rosalind: count the number of distinct perfect matchings on the basepair graph of the given RNA." } ; 12 | 13 | HELP: pmch-main 14 | { $description "Solves the problem PMCH on Rosalind, using a real dataset." } ; 15 | 16 | ARTICLE: "rosalind.pmch" "rosalind.pmch" 17 | { $vocab-link "rosalind.pmch" } 18 | ; 19 | 20 | ABOUT: "rosalind.pmch" 21 | -------------------------------------------------------------------------------- /rosalind/prtm/prtm-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel ; 4 | IN: rosalind.prtm 5 | 6 | HELP: prtm 7 | { $values 8 | { "protein" "A protein string" } 9 | { "mass" "The total weight" } 10 | } 11 | { $description "Solves the problem PRTM on Rosalind: the weight of the given protein, ignoring the weight of a water molecule." } ; 12 | 13 | HELP: prtm-main 14 | { $description "Solves the problem PRTM on Rosalind, using a real dataset." } ; 15 | 16 | ARTICLE: "rosalind.prtm" "rosalind.prtm" 17 | { $vocab-link "rosalind.prtm" } 18 | ; 19 | 20 | ABOUT: "rosalind.prtm" 21 | -------------------------------------------------------------------------------- /aoc2020/day5/day5.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: assocs io.encodings.utf8 io.files kernel math.parser 4 | math.ranges math.statistics prettyprint sequences sets splitting 5 | ; 6 | IN: aoc2020.day5 7 | 8 | : seatcode ( string -- value ) 9 | "FBLR" "0101" zip substitute bin> ; 10 | 11 | : day5-silver ( strings -- highest ) 12 | [ seatcode ] map supremum ; 13 | 14 | : day5-gold ( strings -- n ) 15 | [ seatcode ] map [ minmax [a,b] ] [ diff ] bi first ; 16 | 17 | : day5-main ( -- ) "datasets/aoc2020/day5.txt" utf8 file-contents "\n" split 18 | [ day5-silver . ] [ day5-gold . ] bi ; 19 | 20 | MAIN: day5-main -------------------------------------------------------------------------------- /rosalind/aspc/aspc-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel math ; 4 | IN: rosalind.aspc 5 | 6 | HELP: aspc 7 | { $values 8 | { "n" integer } { "m" integer } 9 | { "ans" integer } 10 | } 11 | { $description "Solves the problem ASPC on Rosalind: Given a set with size n, compute how many subsets are of size m or higher, modulo 1000000." } ; 12 | 13 | HELP: aspc-main 14 | { $description "Solves the problem ASPC on Rosalind, using a real dataset." } ; 15 | 16 | ARTICLE: "rosalind.aspc" "rosalind.aspc" 17 | { $vocab-link "rosalind.aspc" } 18 | ; 19 | 20 | ABOUT: "rosalind.aspc" 21 | -------------------------------------------------------------------------------- /rosalind/pper/pper-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel ; 4 | IN: rosalind.pper 5 | 6 | HELP: pper 7 | { $values 8 | { "n" "An integer" } { "k" "An integer" } 9 | { "ans" "An integer" } 10 | } 11 | { $description "Solves the problem PPER on Rosalind: compute the number of length-k permutations out of n distinct items, modulo 1000000." } ; 12 | 13 | HELP: pper-main 14 | { $description "Solves the problem PPER on Rosalind, using a real dataset." } ; 15 | 16 | ARTICLE: "rosalind.pper" "rosalind.pper" 17 | { $vocab-link "rosalind.pper" } 18 | ; 19 | 20 | ABOUT: "rosalind.pper" 21 | -------------------------------------------------------------------------------- /rosalind/inod/inod-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel math ; 4 | IN: rosalind.inod 5 | 6 | HELP: inod 7 | { $values 8 | { "n" integer } 9 | { "m" integer } 10 | } 11 | { $description "Solves the problem INOD on Rosalind: compute the number of internal nodes of any unrooted binary tree having n leaves. By graph theory, the answer is n-2." } ; 12 | 13 | HELP: inod-main 14 | { $description "Solves the problem INOD on Rosalind, using a real dataset." } ; 15 | 16 | ARTICLE: "rosalind.inod" "rosalind.inod" 17 | { $vocab-link "rosalind.inod" } 18 | ; 19 | 20 | ABOUT: "rosalind.inod" 21 | -------------------------------------------------------------------------------- /rosalind/prot/prot-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel ; 4 | IN: rosalind.prot 5 | 6 | HELP: prot 7 | { $values 8 | { "rna" "An RNA string" } 9 | { "protein" "A string of amino acids" } 10 | } 11 | { $description "Solves the problem PROT on Rosalind: translate an RNA string into a protein string (which consists of amino acid alphabets)." } ; 12 | 13 | HELP: prot-main 14 | { $description "Solves the problem PROT on Rosalind, using a real dataset." } ; 15 | 16 | ARTICLE: "rosalind.prot" "rosalind.prot" 17 | { $vocab-link "rosalind.prot" } 18 | ; 19 | 20 | ABOUT: "rosalind.prot" 21 | -------------------------------------------------------------------------------- /aoc2015/day10/day10.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: arrays grouping.extras io.encodings.utf8 io.files kernel 4 | math math.parser prettyprint sequences ; 5 | IN: aoc2015.day10 6 | 7 | : day10-data ( -- data ) 8 | "datasets/aoc2015/day10.txt" utf8 file-contents string>digits ; 9 | 10 | : look-say ( seq -- seq' ) 11 | [ ] group-by [ first2 length swap 2array ] map concat ; 12 | 13 | : day10-silver ( seq -- n ) 40 [ look-say ] times length ; 14 | 15 | : day10-gold ( seq -- n ) 50 [ look-say ] times length ; 16 | 17 | : day10-main ( -- ) 18 | day10-data [ day10-silver . ] [ day10-gold . ] bi ; 19 | 20 | MAIN: day10-main -------------------------------------------------------------------------------- /rosalind/dna/dna-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel strings ; 4 | IN: rosalind.dna 5 | 6 | HELP: dna 7 | { $values 8 | { "str" "A DNA string" } 9 | { "counts" "A string representing nucleotide counts" } 10 | } 11 | { $description "Solves the problem DNA on Rosalind: count how many times each nucleotide A, C, G, and T appears in the input DNA string." } ; 12 | 13 | HELP: dna-main 14 | { $description "Solves the problem DNA on Rosalind, using a real dataset." } ; 15 | 16 | ARTICLE: "rosalind.dna" "rosalind.dna" 17 | { $vocab-link "rosalind.dna" } 18 | ; 19 | 20 | ABOUT: "rosalind.dna" 21 | -------------------------------------------------------------------------------- /rosalind/eval/eval.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: arrays assocs io io.encodings.utf8 io.files kernel math 4 | math.parser sequences splitting ; 5 | IN: rosalind.eval 6 | 7 | : (eval) ( n str gc-content -- prob ) 8 | 2 / 0.5 over - 2array dup append "CAGT" swap zip 9 | [ dup >array ] dip substitute product 10 | [ length - 1 + ] dip * ; 11 | 12 | : eval ( n str gc-contents -- seq ) [ (eval) ] 2with map ; 13 | 14 | : eval-main ( -- ) 15 | "datasets/rosalind/eval.txt" utf8 file-contents "\n" split first3 16 | [ dec> ] [ ] [ " " split [ dec> ] map ] tri* 17 | eval [ 10 >base ] map " " join print ; 18 | 19 | MAIN: eval-main -------------------------------------------------------------------------------- /rosalind/kmer/kmer-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel sequences strings ; 4 | IN: rosalind.kmer 5 | 6 | HELP: kmer 7 | { $values 8 | { "str" string } 9 | { "counts" sequence } 10 | } 11 | { $description "Solves the problem KMER on Rosalind: count occurrences of each 4-mer in the given DNA string, sorted in the lexicographical order of 4-mers." } ; 12 | 13 | HELP: kmer-main 14 | { $description "Solves the problem KMER on Rosalind, using a real dataset." } ; 15 | 16 | ARTICLE: "rosalind.kmer" "rosalind.kmer" 17 | { $vocab-link "rosalind.kmer" } 18 | ; 19 | 20 | ABOUT: "rosalind.kmer" 21 | -------------------------------------------------------------------------------- /rosalind/kmp/kmp.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: rosalind.common ; 4 | IN: rosalind.kmp 5 | 6 | :: ((kmp)) ( vec elem seq cur -- vec ) 7 | cur [ 8 | seq nth elem = [ vec cur 1 + suffix! ] [ 9 | vec elem seq cur 1 - vec ?nth ((kmp)) 10 | ] if 11 | ] [ vec 0 suffix! ] if* ; 12 | 13 | : (kmp) ( vec elem seq -- vec ) pick ?last ((kmp)) ; 14 | 15 | : kmp ( seq -- seq' ) 16 | f >vector over '[ _ (kmp) ] reduce ; 17 | 18 | : kmp-main ( -- ) "datasets/rosalind/kmp.txt" utf8 file-contents 19 | fasta>assoc values first kmp [ 10 >base ] map " " join 20 | "/tmp/kmp.txt" utf8 set-file-contents ; 21 | 22 | MAIN: kmp-main -------------------------------------------------------------------------------- /rosalind/hamm/hamm-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel strings ; 4 | IN: rosalind.hamm 5 | 6 | HELP: hamm 7 | { $values 8 | { "string1" "A DNA string" } { "string2" "A DNA string of same length" } 9 | { "count" "Count of point mutations" } 10 | } 11 | { $description "Solves the problem HAMM on Rosalind: compute the Hamming distance of two DNA strings." } ; 12 | 13 | HELP: hamm-main 14 | { $description "Solves the problem HAMM on Rosalind, using a real dataset." } ; 15 | 16 | ARTICLE: "rosalind.hamm" "rosalind.hamm" 17 | { $vocab-link "rosalind.hamm" } 18 | ; 19 | 20 | ABOUT: "rosalind.hamm" 21 | -------------------------------------------------------------------------------- /rosalind/revp/revp.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: arrays assocs fry grouping io io.encodings.utf8 io.files 4 | kernel math.parser rosalind.common sequences ; 5 | IN: rosalind.revp 6 | 7 | : reverse-palindrome? ( dna -- ? ) 8 | dup "ACGT" "TGCA" zip substitute reverse = ; 9 | 10 | : revp ( dna -- pairs ) 11 | { 4 6 8 10 12 } swap 12 | '[ _ over clump [ reverse-palindrome? ] map t swap indices [ 1 + ] map 13 | swap '[ _ 2array ] map ] map concat ; 14 | 15 | : revp-main ( -- ) "datasets/rosalind/revp.txt" utf8 file-contents 16 | fasta>assoc first second revp [ [ 10 >base ] map " " join print ] each ; 17 | 18 | MAIN: revp-main -------------------------------------------------------------------------------- /aoc2015/day3/day3.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: arrays assocs io.encodings.utf8 io.files kernel math 4 | math.vectors prettyprint sequences sequences.extras sets ; 5 | IN: aoc2015.day3 6 | 7 | : path-coords ( str -- seq ) 8 | >array ">^ path-coords ] [ path-coords ] bi 16 | append cardinality ; 17 | 18 | : day3-main ( -- ) "datasets/aoc2015/day3.txt" utf8 file-contents 19 | [ day3-silver . ] [ day3-gold . ] bi ; 20 | 21 | MAIN: day3-main -------------------------------------------------------------------------------- /aoc2020/day25/day25.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: io io.encodings.utf8 io.files kernel locals math 4 | math.functions math.parser prettyprint sequences splitting ; 5 | IN: aoc2020.day25 6 | 7 | :: modlog ( n -- m ) ! 7^x == n mod 20201227 8 | 1 20201227 [ drop [ 7 * 20201227 mod ] [ n = ] bi ] find-integer nip ; 9 | 10 | : day25-silver ( n m -- ans ) modlog 20201227 ^mod ; 11 | 12 | : day25-gold ( n m -- str ) 2drop "Yay, all stars complete!" ; 13 | 14 | : day25-main ( -- ) "datasets/aoc2020/day25.txt" utf8 file-contents 15 | "\n" split [ string>number ] map first2 16 | [ day25-silver . ] [ day25-gold print ] 2bi ; 17 | 18 | MAIN: day25-main -------------------------------------------------------------------------------- /rosalind/gc/gc-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: assocs help.markup help.syntax strings ; 4 | IN: rosalind.gc 5 | 6 | HELP: gc 7 | { $values 8 | { "assoc" "An assoc between the ID and the DNA string" } 9 | { "item" "A 2-item array of { ID, GC content% }" } 10 | } 11 | { $description "Solves the problem GC on Rosalind: given some DNA strings in FASTA format, identify the DNA that has the largest GC content." } ; 12 | 13 | HELP: gc-main 14 | { $description "Solves the problem GC on Rosalind, using a real dataset." } ; 15 | 16 | ARTICLE: "rosalind.gc" "rosalind.gc" 17 | { $vocab-link "rosalind.gc" } 18 | ; 19 | 20 | ABOUT: "rosalind.gc" 21 | -------------------------------------------------------------------------------- /rosalind/gc/gc-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: kernel math.functions multiline rosalind.common rosalind.gc sequences 4 | tools.test ; 5 | IN: rosalind.gc.tests 6 | 7 | STRING: fasta-example 8 | >Rosalind_6404 9 | CCTGCGGAAGATCGGCACTAGAATAGCCAGAACCGTTTCTCTGAGGCTTCCGGCCTTCCC 10 | TCCCACTAATAATTCTGAGG 11 | >Rosalind_5959 12 | CCATCGGTAGCGCATCCTTAGTCCAATTAAGTCCCTATCCAGGCGCTCCGCCGAAGGTCT 13 | ATATCCATTTGTCAGCAGACACGC 14 | >Rosalind_0808 15 | CCACCCTCGTGGTATGGCTAGGCATTCAGGAACCGGAGAACGCTTCAGACCAGCCCGGAC 16 | TGGGAACCTGCGGGCAGTAGGTGGAAT 17 | ; 18 | 19 | { t t } [ fasta-example fasta>assoc gc first2 [ "Rosalind_0808" = ] [ 60.919540 1e-4 ~ ] bi* ] unit-test 20 | -------------------------------------------------------------------------------- /rosalind/mmch/mmch-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel math strings ; 4 | IN: rosalind.mmch 5 | 6 | HELP: mmch 7 | { $values 8 | { "str" string } 9 | { "ans" integer } 10 | } 11 | { $description "Solves the problem MMCH on Rosalind: Given an RNA string where A and U (resp. G and C) may appear in different counts, count the number of possible maximum matchings of A-U and G-C." } ; 12 | 13 | HELP: mmch-main 14 | { $description "Solves the problem MMCH on Rosalind, using a real dataset." } ; 15 | 16 | ARTICLE: "rosalind.mmch" "rosalind.mmch" 17 | { $vocab-link "rosalind.mmch" } 18 | ; 19 | 20 | ABOUT: "rosalind.mmch" 21 | -------------------------------------------------------------------------------- /rosalind/grph/grph-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: assocs help.markup help.syntax kernel ; 4 | IN: rosalind.grph 5 | 6 | HELP: grph 7 | { $values 8 | { "assoc" "An assoc from FASTA data" } 9 | { "edges" "Edges of overlap graph" } 10 | } 11 | { $description "Solves the problem GRPH on Rosalind: output all edges of overlap graph where the last 3 chars of the first node equals the first 3 chars of the second." } ; 12 | 13 | HELP: grph-main 14 | { $description "Solves the problem GRPH on Rosalind, using a real dataset." } ; 15 | 16 | ARTICLE: "rosalind.grph" "rosalind.grph" 17 | { $vocab-link "rosalind.grph" } 18 | ; 19 | 20 | ABOUT: "rosalind.grph" 21 | -------------------------------------------------------------------------------- /rosalind/lcsq/lcsq.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: arrays assocs io io.encodings.utf8 io.files kernel locals 4 | math rosalind.common sequences vectors ; 5 | IN: rosalind.lcsq 6 | 7 | :: (lcsq) ( subseqs elem seq2 -- subseqs' ) 8 | "" 1vector seq2 [| elem2 idx | 9 | dup last idx 1 + subseqs nth 10 | elem elem2 = idx subseqs nth elem suffix "" ? 11 | 3array longest suffix! 12 | ] each-index ; 13 | 14 | :: lcsq ( seq1 seq2 -- seq ) 15 | seq2 length 1 + "" 16 | seq1 [ seq2 (lcsq) ] each last ; 17 | 18 | : lcsq-main ( -- ) "datasets/rosalind/lcsq.txt" utf8 file-contents 19 | fasta>assoc values first2 lcsq print ; 20 | 21 | MAIN: lcsq-main -------------------------------------------------------------------------------- /rosalind/lexf/lexf-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel ; 4 | IN: rosalind.lexf 5 | 6 | HELP: lexf 7 | { $values 8 | { "alphabet" "A string" } { "length" "An integer" } 9 | { "strings" "A sequence of strings" } 10 | } 11 | { $description "Solves the problem LEXF on Rosalind: generate all permutations of given length that can be formed out of the given alphabet, in lexicographic order." } ; 12 | 13 | HELP: lexf-main 14 | { $description "Solves the problem LEXF on Rosalind, using a real dataset." } ; 15 | 16 | ARTICLE: "rosalind.lexf" "rosalind.lexf" 17 | { $vocab-link "rosalind.lexf" } 18 | ; 19 | 20 | ABOUT: "rosalind.lexf" 21 | -------------------------------------------------------------------------------- /rosalind/mprt/mprt-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: assocs help.markup help.syntax ; 4 | IN: rosalind.mprt 5 | 6 | HELP: mprt 7 | { $values 8 | { "assoc" assoc } 9 | { "assoc'" assoc } 10 | } 11 | { $description "Solves the problem MPRT on Rosalind: given some protein IDs and the corresponding protein strings fetched from UniProt, return the ones that contain the motif N{P}[ST]{P} along with the 1-based positions." } ; 12 | 13 | HELP: mprt-main 14 | { $description "Solves the problem MPRT on Rosalind, using a real dataset." } ; 15 | 16 | ARTICLE: "rosalind.mprt" "rosalind.mprt" 17 | { $vocab-link "rosalind.mprt" } 18 | ; 19 | 20 | ABOUT: "rosalind.mprt" 21 | -------------------------------------------------------------------------------- /rosalind/mrna/mrna-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel ; 4 | IN: rosalind.mrna 5 | 6 | HELP: mrna 7 | { $values 8 | { "protein" "A protein string" } 9 | { "n" "The number of possible mRNAs, modulo 1000000" } 10 | } 11 | { $description "Solves the problem MRNA on Rosalind: given a protein string, calculate the number of possible mRNA strands that generates the protein, modulo 1000000." } ; 12 | 13 | HELP: mrna-main 14 | { $description "Solves the problem MRNA on Rosalind, using a real dataset." } ; 15 | 16 | ARTICLE: "rosalind.mrna" "rosalind.mrna" 17 | { $vocab-link "rosalind.mrna" } 18 | ; 19 | 20 | ABOUT: "rosalind.mrna" 21 | -------------------------------------------------------------------------------- /rosalind/spec/spec.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: assocs assocs.extras grouping.extras io io.encodings.utf8 4 | io.files kernel math math.functions math.parser prettyprint 5 | rosalind.common sequences sequences.extras sorting splitting 6 | strings ; 7 | IN: rosalind.spec 8 | 9 | : inv-mass-table ( -- assoc ) 10 | protein-mass-table [ 20 * round >integer ] map-values assoc-invert ; 11 | 12 | : spec ( seq -- ans ) 13 | natural-sort [ swap - 20 * round >integer ] 2clump-map 14 | inv-mass-table substitute >string ; 15 | 16 | : spec-main ( -- ) 17 | "datasets/rosalind/spec.txt" utf8 file-contents "\n" split [ dec> ] map 18 | spec print ; 19 | 20 | MAIN: spec-main -------------------------------------------------------------------------------- /rosalind/tran/tran.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: assocs combinators io.encodings.utf8 io.files kernel math 4 | math.statistics prettyprint rosalind.common sequences sorting 5 | strings ; 6 | IN: rosalind.tran 7 | 8 | : trans-type ( seq -- type/f ) 9 | natural-sort >string 10 | { { [ dup { "AG" "CT" } member? ] [ drop 1 ] } 11 | { [ dup first2 = not ] [ drop 2 ] } 12 | [ drop f ] } cond ; 13 | 14 | : tran ( str1 str2 -- ratio ) 15 | zip [ trans-type ] map sift histogram 16 | { 1 2 } swap substitute first2 /f ; 17 | 18 | : tran-main ( -- ) "datasets/rosalind/tran.txt" utf8 file-contents 19 | fasta>assoc values first2 tran . ; 20 | 21 | MAIN: tran-main -------------------------------------------------------------------------------- /rosalind/corr/corr.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: arrays assocs io io.encodings.utf8 io.files kernel locals 4 | rosalind.common sequences sequences.extras sets ; 5 | IN: rosalind.corr 6 | 7 | : rcmp-pair ( str -- pair ) 8 | dup reverse "ACGT" "TGCA" zip substitute 2array ; 9 | 10 | : 1diff? ( str1 str2 -- ? ) [ = not ] 2count 1 = ; 11 | 12 | :: corr ( strs -- corrections ) 13 | strs [ rcmp-pair ] map concat duplicates :> correct 14 | strs [| s | s correct [ s 1diff? ] find nip 2array ] map 15 | sift-values ; 16 | 17 | : corr-main ( -- ) "datasets/rosalind/corr.txt" utf8 file-contents 18 | fasta>assoc values corr [ "->" join print ] each ; 19 | 20 | MAIN: corr-main -------------------------------------------------------------------------------- /rosalind/edit/edit.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: arrays assocs io.encodings.utf8 io.files kernel locals 4 | math prettyprint rosalind.common sequences vectors ; 5 | IN: rosalind.edit 6 | 7 | :: (edit) ( dists elem seq2 -- dists' ) 8 | dists first 1 + 1vector seq2 [| elem2 idx | 9 | dup last 1 + idx 1 + dists nth 1 + 10 | elem elem2 = 0 1 ? idx dists nth + 11 | 3array infimum suffix! 12 | ] each-index ; 13 | 14 | :: edit ( seq1 seq2 -- n ) 15 | seq2 length 1 + 16 | seq1 [ seq2 (edit) ] each last ; 17 | 18 | : edit-main ( -- ) 19 | "datasets/rosalind/edit.txt" utf8 file-contents 20 | fasta>assoc values first2 edit . ; 21 | 22 | MAIN: edit-main -------------------------------------------------------------------------------- /rosalind/mprt/mprt.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: accessors assocs http.client io io.encodings.utf8 4 | io.files kernel math math.parser regexp rosalind.common 5 | sequences sequences.extras splitting ; 6 | IN: rosalind.mprt 7 | 8 | : mprt ( assoc -- assoc' ) 9 | [ R/ (?=N[^P][ST][^P])/ all-matching-slices [ from>> 1 + ] map ] map-values harvest-values ; 10 | 11 | : mprt-main ( -- ) "datasets/rosalind/mprt.txt" utf8 file-contents 12 | "\n" split [ dup "http://www.uniprot.org/uniprot/" ".fasta" surround http-get nip fasta>assoc first second ] { } map>assoc 13 | mprt [ [ print ] [ [ number>string ] map " " join print ] bi* ] assoc-each 14 | ; 15 | 16 | MAIN: mprt-main -------------------------------------------------------------------------------- /rosalind/orf/orf-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel ; 4 | IN: rosalind.orf 5 | 6 | HELP: orf 7 | { $values 8 | { "dna" "A DNA string" } 9 | { "proteins" "All possible distinct proteins that can be made out of input DNA" } 10 | } 11 | { $description "Solves the problem ORF on Rosalind: find all distinct proteins that can be made from both strands of the given DNA (the input DNA and its reverse complement)." } ; 12 | 13 | HELP: orf-main 14 | { $description "Solves the problem ORF on Rosalind, using a real dataset." } ; 15 | 16 | ARTICLE: "rosalind.orf" "rosalind.orf" 17 | { $vocab-link "rosalind.orf" } 18 | ; 19 | 20 | ABOUT: "rosalind.orf" 21 | -------------------------------------------------------------------------------- /rosalind/perm/perm-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel ; 4 | IN: rosalind.perm 5 | 6 | HELP: perm 7 | { $values 8 | { "n" "An integer" } 9 | { "perms" "A sequence containing all permutations of length n" } { "length" "The number of permutations of length n" } 10 | } 11 | { $description "Solves the problem PERM on Rosalind: given an integer n, output the permutations of length n and the total number." } ; 12 | 13 | HELP: perm-main 14 | { $description "Solves the problem PERM on Rosalind, using a real dataset." } ; 15 | 16 | ARTICLE: "rosalind.perm" "rosalind.perm" 17 | { $vocab-link "rosalind.perm" } 18 | ; 19 | 20 | ABOUT: "rosalind.perm" 21 | -------------------------------------------------------------------------------- /rosalind/subs/subs-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel strings ; 4 | IN: rosalind.subs 5 | 6 | HELP: subs 7 | { $values 8 | { "string" "A DNA string" } { "motif" "A DNA string" } 9 | { "indices" "A sequence of 1-based indices where motif appears in string" } 10 | } 11 | { $description "Solves the problem SUBS on Rosalind: find the 1-based indices where motif appears as a substring of a DNA string." } ; 12 | 13 | HELP: subs-main 14 | { $description "Solves the problem SUBS on Rosalind, using a real dataset." } ; 15 | 16 | ARTICLE: "rosalind.subs" "rosalind.subs" 17 | { $vocab-link "rosalind.subs" } 18 | ; 19 | 20 | ABOUT: "rosalind.subs" 21 | -------------------------------------------------------------------------------- /rosalind/revc/revc-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel ; 4 | IN: rosalind.revc 5 | 6 | HELP: revc 7 | { $values 8 | { "dna-str" "A DNA string" } 9 | { "reverse-complement" "Reverse complement of the input DNA string" } 10 | } 11 | { $description "Solves the problem REVC on Rosalind: given a DNA string, output the reverse complement of it (replace ACGT by TGCA respectively, and then reverse the string)." } ; 12 | 13 | HELP: revc-main 14 | { $description "Solves the problem REVC on Rosalind, using a real dataset." } ; 15 | 16 | ARTICLE: "rosalind.revc" "rosalind.revc" 17 | { $vocab-link "rosalind.revc" } 18 | ; 19 | 20 | ABOUT: "rosalind.revc" 21 | -------------------------------------------------------------------------------- /aoc2020/day3/day3.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: fry io.encodings.utf8 io.files kernel math math.vectors 4 | prettyprint sequences splitting grouping ; 5 | IN: aoc2020.day3 6 | 7 | : trees-on-slope ( lines slope -- count ) 8 | [ denominator group [ first ] map ] 9 | [ nip numerator '[ _ * over length mod swap nth ] map-index ] 2bi 10 | [ 35 = ] count ; 11 | 12 | : day3-silver ( lines -- count ) 13 | 3 trees-on-slope ; 14 | 15 | : day3-gold ( lines -- count ) 16 | { 1 3 5 7 1/2 } swap '[ _ swap trees-on-slope ] map product ; 17 | 18 | : day3-main ( -- ) "datasets/aoc2020/day3.txt" utf8 file-contents "\n" split 19 | [ day3-silver . ] [ day3-gold . ] bi ; 20 | 21 | MAIN: day3-main -------------------------------------------------------------------------------- /datasets/aoc2020/day10.txt: -------------------------------------------------------------------------------- 1 | 97 2 | 62 3 | 23 4 | 32 5 | 51 6 | 19 7 | 98 8 | 26 9 | 90 10 | 134 11 | 73 12 | 151 13 | 116 14 | 76 15 | 6 16 | 94 17 | 113 18 | 127 19 | 119 20 | 44 21 | 115 22 | 50 23 | 143 24 | 150 25 | 86 26 | 91 27 | 36 28 | 104 29 | 131 30 | 101 31 | 38 32 | 66 33 | 46 34 | 96 35 | 54 36 | 70 37 | 8 38 | 30 39 | 1 40 | 108 41 | 69 42 | 139 43 | 24 44 | 29 45 | 77 46 | 124 47 | 107 48 | 14 49 | 137 50 | 16 51 | 140 52 | 80 53 | 68 54 | 25 55 | 31 56 | 59 57 | 45 58 | 126 59 | 148 60 | 67 61 | 13 62 | 125 63 | 53 64 | 57 65 | 41 66 | 47 67 | 35 68 | 145 69 | 120 70 | 12 71 | 37 72 | 5 73 | 110 74 | 138 75 | 130 76 | 2 77 | 63 78 | 83 79 | 22 80 | 79 81 | 52 82 | 7 83 | 95 84 | 58 85 | 149 86 | 123 87 | 89 88 | 109 89 | 15 90 | 144 91 | 114 92 | 9 93 | 78 -------------------------------------------------------------------------------- /rosalind/splc/splc-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: assocs help.markup help.syntax kernel ; 4 | IN: rosalind.splc 5 | 6 | HELP: splc 7 | { $values 8 | { "assoc" "An assoc converted from FASTA format" } 9 | { "protein" "The protein produced after splicing" } 10 | } 11 | { $description "Solves the problem SPLC on Rosalind: given a long coding DNA and some introns, remove the introns, concatenate the exons, and translate it to a protein." } ; 12 | 13 | HELP: splc-main 14 | { $description "Solves the problem SPLC on Rosalind, using a real dataset." } ; 15 | 16 | ARTICLE: "rosalind.splc" "rosalind.splc" 17 | { $vocab-link "rosalind.splc" } 18 | ; 19 | 20 | ABOUT: "rosalind.splc" 21 | -------------------------------------------------------------------------------- /aoc2015/day2/day2.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: arrays io.encodings.utf8 io.files kernel math math.parser 4 | math.vectors prettyprint sequences sorting splitting ; 5 | IN: aoc2015.day2 6 | 7 | : wrapping-paper ( seq -- n ) 8 | natural-sort dup first3 rot 3array v* { 3 2 2 } v. ; 9 | 10 | : day2-silver ( seq -- n ) 11 | [ wrapping-paper ] map sum ; 12 | 13 | : ribbon ( seq -- n ) 14 | natural-sort [ { 2 2 0 } v. ] [ product ] bi + ; 15 | 16 | : day2-gold ( seq -- n ) 17 | [ ribbon ] map sum ; 18 | 19 | : day2-main ( -- ) "datasets/aoc2015/day2.txt" utf8 file-contents 20 | "\n" split [ "x" split [ dec> ] map ] map 21 | [ day2-silver . ] [ day2-gold . ] bi ; 22 | 23 | MAIN: day2-main -------------------------------------------------------------------------------- /rosalind/prob/prob-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel strings ; 4 | IN: rosalind.prob 5 | 6 | HELP: prob 7 | { $values 8 | { "str" "A DNA string" } { "gc-probs" "A sequence of floats" } 9 | { "logprobs" "A sequence of floats" } 10 | } 11 | { $description "Solves the problem PROB on Rosalind: for each of the GC-content, evaluate the log-likelihood of a random DNA of given length being exactly equal to the given DNA string." } ; 12 | 13 | HELP: prob-main 14 | { $description "Solves the problem PROB on Rosalind, using a real dataset." } ; 15 | 16 | ARTICLE: "rosalind.prob" "rosalind.prob" 17 | { $vocab-link "rosalind.prob" } 18 | ; 19 | 20 | ABOUT: "rosalind.prob" 21 | -------------------------------------------------------------------------------- /rosalind/sign/sign-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel sequences ; 4 | IN: rosalind.sign 5 | 6 | HELP: sign 7 | { $values 8 | { "n" "An integer" } 9 | { "seq" "A sequence" } { "len" "An integer" } 10 | } 11 | { $description "Solves the problem SIGN on Rosalind: output all signed permutations, along with the count of them. A signed permutation is defined as a permutation of 1 to n, where each number can have positive or negative sign attached." } ; 12 | 13 | HELP: sign-main 14 | { $description "Solves the problem SIGN on Rosalind, using a real dataset." } ; 15 | 16 | ARTICLE: "rosalind.sign" "rosalind.sign" 17 | { $vocab-link "rosalind.sign" } 18 | ; 19 | 20 | ABOUT: "rosalind.sign" 21 | -------------------------------------------------------------------------------- /rosalind/fib/fib-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel ; 4 | IN: rosalind.fib 5 | 6 | HELP: fib 7 | { $values 8 | { "n" "The number representing nth month" } { "k" "Reproduction factor" } 9 | { "ans" "The number of rabbit pairs in the nth month" } 10 | } 11 | { $description "Solves the problem FIB on Rosalind: suppose a mature rabbit pair produces k rabbit pairs every month. If we start with a pair of immature rabbits in the first month, calculate the number of rabbit pairs in the nth month." } ; 12 | 13 | HELP: fib-main 14 | { $description "Solves the problem FIB on Rosalind, using a real dataset." } ; 15 | 16 | ARTICLE: "rosalind.fib" "rosalind.fib" 17 | { $vocab-link "rosalind.fib" } 18 | ; 19 | 20 | ABOUT: "rosalind.fib" 21 | -------------------------------------------------------------------------------- /rosalind/lexv/lexv-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel strings ; 4 | IN: rosalind.lexv 5 | 6 | HELP: lexv 7 | { $values 8 | { "str" string } { "n" "An integer" } 9 | { "seqs" "A sequence of strings" } 10 | } 11 | { $description "Solves the problem LEXV on Rosalind: given a string of uppercase letters and an integer n, output all strings of length at least 1 and at most n ordered lexicographically. The sort order of each letter is determined by the appearance order in the input string." } ; 12 | 13 | HELP: lexv-main 14 | { $description "Solves the problem LEXV on Rosalind, using a real dataset." } ; 15 | 16 | ARTICLE: "rosalind.lexv" "rosalind.lexv" 17 | { $vocab-link "rosalind.lexv" } 18 | ; 19 | 20 | ABOUT: "rosalind.lexv" 21 | -------------------------------------------------------------------------------- /aoc2020/day10/day10.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: assocs fry grouping.extras io.encodings.utf8 io.files 4 | kernel math math.parser math.ranges math.statistics prettyprint 5 | sequences sorting splitting ; 6 | IN: aoc2020.day10 7 | 8 | : sort+minmax ( seq -- seq' ) 9 | natural-sort 0 prefix dup last 3 + suffix ; 10 | 11 | : day10-silver ( seq -- n ) 12 | sort+minmax [ swap - ] 2clump-map histogram 13 | { 1 3 } swap substitute first2 * ; 14 | 15 | : day10-gold ( seq -- n ) 16 | sort+minmax [ last [0,b] ] keep '[ _ member? 1 0 ? ] map 17 | { 1 0 0 } [ over sum * suffix rest ] reduce last ; 18 | 19 | : day10-main ( -- ) "datasets/aoc2020/day10.txt" utf8 file-contents "\n" split [ dec> ] map 20 | [ day10-silver . ] [ day10-gold . ] bi ; 21 | 22 | MAIN: day10-main -------------------------------------------------------------------------------- /datasets/aoc2015/day9.txt: -------------------------------------------------------------------------------- 1 | AlphaCentauri to Snowdin = 66 2 | AlphaCentauri to Tambi = 28 3 | AlphaCentauri to Faerun = 60 4 | AlphaCentauri to Norrath = 34 5 | AlphaCentauri to Straylight = 34 6 | AlphaCentauri to Tristram = 3 7 | AlphaCentauri to Arbre = 108 8 | Snowdin to Tambi = 22 9 | Snowdin to Faerun = 12 10 | Snowdin to Norrath = 91 11 | Snowdin to Straylight = 121 12 | Snowdin to Tristram = 111 13 | Snowdin to Arbre = 71 14 | Tambi to Faerun = 39 15 | Tambi to Norrath = 113 16 | Tambi to Straylight = 130 17 | Tambi to Tristram = 35 18 | Tambi to Arbre = 40 19 | Faerun to Norrath = 63 20 | Faerun to Straylight = 21 21 | Faerun to Tristram = 57 22 | Faerun to Arbre = 83 23 | Norrath to Straylight = 9 24 | Norrath to Tristram = 50 25 | Norrath to Arbre = 60 26 | Straylight to Tristram = 27 27 | Straylight to Arbre = 81 28 | Tristram to Arbre = 90 -------------------------------------------------------------------------------- /datasets/rosalind/prtm.txt: -------------------------------------------------------------------------------- 1 | YRNPFPMPTHYNTTIIHMCMWMMDTTEAYSIQYKANWPEEGHDYEWYDLCWGLKFVEKPKHKEIVFVKFTVKDDDQCAIPFVGAYLGHEHFVFMHDMDCFQKSMYGFVNPTQENFPSDYHGHTFKRFSAFLQKTRVDRVAWEYKKFSMQFGKCMFSKKKVTMHEANHDFALLPIDPVYALYEHERHETNGKLTAHGWVRQEYDHVNMLMKYKMDSCHNEWWVNLPRHMAGFSLDLEKATLNGSVMRGTYNSRFQGGGSGLMRYQRSVLHVHHNLTDRWTYRIAMQIMWCKYDHLNANIKIRREHCGYQIMKIAVTYYFHPYKKVFAQRMHACITHSYMNLLGQHKSEQSLAPPQLFQYCFEQLKAEFCWLKFTGAETTMMVYCPVASTQQEDASVEFGQWYCDWSILSAWLTRDNQYAIWWAMVEIHYTWIEMCYFDYKDEGNKKFSVCWIESAFEREPKPNHWPMMWSCPQNIEGLNAPTSMLSMSHWCCLSSNKIEWYTYIRLHMKHRTCFDEPDNSNMHVPYDIGLLTYQEDHTHEIRHLNKSCRVDPMKRLEMTWKYTNDGSCATCEMNYPSIDMYTYCALCNHRDWTDEFCKACGRDEINWFEQMHFWWYKMCCVNLEFPVWSSLTKMWWYNEQHYLWYELPFEDQTQKRMPGFQSEAADTDTACGIGGWNFEEPDVMYYFEQTSQCKLMDSTFWHKIKLSSAYVYRYDCAQRDHYFGLSNCCKLHKKNVTWCIDHIMCVHKFWSEDVAPFYVVWVCWNEKSRDNNREFFFGQIRMWICNSHMMCWSKMKTMLEEGLDIIARIHFCKVFDVPRMLAPHQHIVSEKLMVLTSFMAQLRKCHTDNTFSNP -------------------------------------------------------------------------------- /rosalind/tree/tree-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel ; 4 | IN: rosalind.tree 5 | 6 | HELP: tree 7 | { $values 8 | { "n" "An integer" } { "adjlist" "A sequence" } 9 | { "ans" "An integer" } 10 | } 11 | { $description "Solves the problem TREE on Rosalind: given the number of nodes and the adjacency list of a graph, compute how many additional edges are needed to make it a tree." { $nl "" } 12 | "Uses the fact that a tree of n nodes has n-1 edges, so the answer is (n-1) - (number of existing edges)." } ; 13 | 14 | HELP: tree-main 15 | { $description "Solves the problem TREE on Rosalind, using a real dataset." } ; 16 | 17 | ARTICLE: "rosalind.tree" "rosalind.tree" 18 | { $vocab-link "rosalind.tree" } 19 | ; 20 | 21 | ABOUT: "rosalind.tree" 22 | -------------------------------------------------------------------------------- /rosalind/lgis/lgis.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: binary-search fry io io.encodings.utf8 io.files kernel 4 | locals math math.order math.parser sequences splitting vectors ; 5 | IN: rosalind.lgis 6 | 7 | :: (longest-increasing-subseq) ( vec n -- vec ) 8 | vec [ last n >=< ] search [ ?1+ ] dip n suffix 9 | swap vec set-nth vec ; 10 | 11 | : longest-increasing-subseq ( seq -- seq' ) 12 | { -1/0. } 1vector [ (longest-increasing-subseq) ] reduce last rest ; 13 | 14 | : lgis ( seq -- seq+ seq- ) 15 | [ longest-increasing-subseq ] 16 | [ [ neg ] map longest-increasing-subseq [ neg ] map ] bi ; 17 | 18 | : lgis-main ( -- ) "datasets/rosalind/lgis.txt" utf8 file-contents 19 | "\n" split last " " split [ dec> ] map 20 | lgis [ [ 10 >base ] map " " join print ] bi@ ; 21 | 22 | MAIN: lgis-main -------------------------------------------------------------------------------- /rosalind/sseq/sseq-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel strings ; 4 | IN: rosalind.sseq 5 | 6 | HELP: sseq 7 | { $values 8 | { "str" string } { "subseq" string } 9 | { "indices" "A sequence of indices in str" } 10 | } 11 | { $description "Solves the problem SSEQ on Rosalind: given a DNA string s and a motif t, find any collection of indices in s such that the symbols of t appear as a subsequence of s." { $nl "" } 12 | "Since it is allowed to return any subsequence, the code finds the earliest collection of indices." } ; 13 | 14 | HELP: sseq-main 15 | { $description "Solves the problem SSEQ on Rosalind, using a real dataset." } ; 16 | 17 | ARTICLE: "rosalind.sseq" "rosalind.sseq" 18 | { $vocab-link "rosalind.sseq" } 19 | ; 20 | 21 | ABOUT: "rosalind.sseq" 22 | -------------------------------------------------------------------------------- /rosalind/pdst/pdst-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel math sequences ; 4 | IN: rosalind.pdst 5 | 6 | HELP: diff% 7 | { $values 8 | { "seq1" sequence } { "seq2" sequence } 9 | { "%" float } 10 | } 11 | { $description "Computes the p-distance (ratio of different positions) of the two equal-length sequences." } ; 12 | 13 | HELP: pdst 14 | { $values 15 | { "seq" sequence } 16 | { "matrix" object } 17 | } 18 | { $description "Solves the problem PDST on Rosalind: create a distance matrix of given DNA sequences." } ; 19 | 20 | HELP: pdst-main 21 | { $description "Solves the problem PDST on Rosalind, using a real dataset." } ; 22 | 23 | ARTICLE: "rosalind.pdst" "rosalind.pdst" 24 | { $vocab-link "rosalind.pdst" } 25 | ; 26 | 27 | ABOUT: "rosalind.pdst" 28 | -------------------------------------------------------------------------------- /aoc2020/day15/day15-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: tools.test aoc2020.day15 ; 4 | IN: aoc2020.day15.tests 5 | 6 | { 436 } [ { 0 3 6 } day15-silver ] unit-test 7 | { 1 } [ { 1 3 2 } day15-silver ] unit-test 8 | { 10 } [ { 2 1 3 } day15-silver ] unit-test 9 | { 27 } [ { 1 2 3 } day15-silver ] unit-test 10 | { 78 } [ { 2 3 1 } day15-silver ] unit-test 11 | { 438 } [ { 3 2 1 } day15-silver ] unit-test 12 | { 1836 } [ { 3 1 2 } day15-silver ] unit-test 13 | 14 | { 175594 } [ { 0 3 6 } day15-gold2 ] unit-test 15 | { 2578 } [ { 1 3 2 } day15-gold2 ] unit-test 16 | { 3544142 } [ { 2 1 3 } day15-gold2 ] unit-test 17 | { 261214 } [ { 1 2 3 } day15-gold2 ] unit-test 18 | { 6895259 } [ { 2 3 1 } day15-gold2 ] unit-test 19 | { 18 } [ { 3 2 1 } day15-gold2 ] unit-test 20 | { 362 } [ { 3 1 2 } day15-gold2 ] unit-test -------------------------------------------------------------------------------- /rosalind/rna/rna-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel ; 4 | IN: rosalind.rna 5 | 6 | HELP: T 7 | { $values 8 | { "value" "The character value of T" } 9 | } 10 | { $description "" } ; 11 | 12 | HELP: U 13 | { $values 14 | { "value" "The character value of U" } 15 | } 16 | { $description "" } ; 17 | 18 | HELP: rna 19 | { $values 20 | { "dna-str" "A DNA string" } 21 | { "rna-str" "An RNA string" } 22 | } 23 | { $description "Solves the problem RNA on Rosalind: given a DNA string, transcribe it into an RNA string by replacing T's into U's." } ; 24 | 25 | HELP: rna-main 26 | { $description "Solves the problem RNA on Rosalind, using a real dataset." } ; 27 | 28 | ARTICLE: "rosalind.rna" "rosalind.rna" 29 | { $vocab-link "rosalind.rna" } 30 | ; 31 | 32 | ABOUT: "rosalind.rna" 33 | -------------------------------------------------------------------------------- /aoc2020/day2/day2.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: fry io.encodings.utf8 io.files kernel math.order 4 | math.parser prettyprint sequences splitting ; 5 | IN: aoc2020.day2 6 | 7 | ! spec: "1-2 a: abcde" 8 | : spec> ( spec -- range char passwd ) 9 | " " split first3 [ "-" split [ string>number ] map ] [ first ] [ ] tri* ; 10 | 11 | : password-valid? ( spec -- ? ) 12 | spec> swap '[ _ = ] count swap first2 between? ; 13 | 14 | : day2-silver ( specs -- count ) 15 | [ password-valid? ] count ; 16 | 17 | : password-valid?' ( spec -- ? ) 18 | spec> swapd 0 prefix nths swap '[ _ = ] count 1 = ; 19 | 20 | : day2-gold ( specs -- count ) 21 | [ password-valid?' ] count ; 22 | 23 | : day2-main ( -- ) "datasets/aoc2020/day2.txt" utf8 file-contents "\n" split 24 | [ day2-silver . ] [ day2-gold . ] bi ; 25 | 26 | MAIN: day2-main -------------------------------------------------------------------------------- /rosalind/revp/revp-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel ; 4 | IN: rosalind.revp 5 | 6 | HELP: reverse-palindrome? 7 | { $values 8 | { "dna" "A DNA string" } 9 | { "?" boolean } 10 | } 11 | { $description "Tests if a given DNA string is a reverse palindrome." } ; 12 | 13 | HELP: revp 14 | { $values 15 | { "dna" "A DNA string" } 16 | { "pairs" "Reverse palindrome locations as (index, length) pairs" } 17 | } 18 | { $description "Solves the problem REVP on Rosalind: find all reverse palindrome substrings of lengths 4 to 12 in a given DNA." } ; 19 | 20 | HELP: revp-main 21 | { $description "Solves the problem REVP on Rosalind, using a real dataset." } ; 22 | 23 | ARTICLE: "rosalind.revp" "rosalind.revp" 24 | { $vocab-link "rosalind.revp" } 25 | ; 26 | 27 | ABOUT: "rosalind.revp" 28 | -------------------------------------------------------------------------------- /datasets/rosalind/revc.txt: -------------------------------------------------------------------------------- 1 | GCGCTTCTTGTAACCTGTAAAAAGTAGTGTAAGAGAAGATCTAGTCATCGATCGGTAAAACTGCGGCCCCCAAGAATAGCATGAAGTGGGAGGAGACTCGTATCAACGGAAGTTGCGTAATGAGATAGCCTAACCCTTCCTGGACACCACGCGCACGATTGCGGGCACGTTAAATGTCACTGAATATCGTGTAGACTTGACGCAACGGTCAGCGAAGGACGAGGTGTCACACCTTACAAGGGGTTTACAGAGTTTGCCCCTTGGATGTTGAGGCTGAGGCGATGATGCTAATGAGTCGTTCAATTTCTTAACAGCGCTTTCCAGTTAGGCGCATCCAATCAGACAGGTATGCACGGTCACATGTAAGCCTTAGGGCCTCATGGAGGGCACGTGCAAGATGGCCAAACACAACTTGGTAATGTCTCTACATACTTCATTAACTCCCTAGTGGTCCGTCGCACGCCCGATCGAGAATGTCAAATGCATCAACATATAAGAACGCTATGGGGCCCTCATCTTATATCATAGAGCTACCCATGGCCTTACATAACTCGCGTCGGTGGGTCATTACGATGTGTGAGACTCAGGGTCATCCCGATGTCCATGGTTCTTTCCTACTATAAATAACCCGAAATATTACGCACTGACGGATACGGGTAGTTCTCAGACTTATACGCACGATAAGTGACTCAGCTTGTTTGGCGTAATTCTTGCCTTATCTTGTCACCGTCACACACCACCGAGGGCCAGTGAAGACCCCCCCCATGAAACCTGCGTATAGATCGCGGCGTCGAACCGGCAAGACTGCATAGGGGGCGGGTTTCCGGTGCAGTCGTTGCGAACTAGTATCATCCACCTGTTGGATCTGCTGGGCTTTTTACCTACCTAAAAGGAGGTTCTCGTGGGA -------------------------------------------------------------------------------- /aoc2015/day9/day9.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: arrays assocs grouping io.encodings.utf8 io.files kernel 4 | locals math.combinatorics math.parser prettyprint sequences 5 | sequences.extras sets splitting ; 6 | IN: aoc2015.day9 7 | 8 | : day9-data ( -- data ) 9 | "datasets/aoc2015/day9.txt" utf8 file-contents "\n" split 10 | [ " = " split1 [ " to " split1 2array ] [ dec> ] bi* 2array ] map 11 | dup [ reverse ] map-keys append ; 12 | 13 | :: all-path-lengths ( distances -- path-lengths ) 14 | distances keys combine 15 | [ 2 clump [ distances at ] map sum ] map ; 16 | 17 | : day9-silver ( distances -- n ) all-path-lengths infimum ; 18 | 19 | : day9-gold ( distances -- n ) all-path-lengths supremum ; 20 | 21 | : day9-main ( -- ) 22 | day9-data [ day9-silver . ] [ day9-gold . ] bi ; 23 | 24 | MAIN: day9-main -------------------------------------------------------------------------------- /rosalind/iev/iev-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel ; 4 | IN: rosalind.iev 5 | 6 | HELP: iev 7 | { $values 8 | { "vec" "A 6-item sequence of integers" } 9 | { "n" "Expected offsprings with dominant phenotype" } 10 | } 11 | { $description "Solves the problem IEV on Rosalind: given the counts of six couple types, output the expected number of offsprings having dominant phenotype when each couple produces two offsprings. The six couple types are given as: AA-AA, AA-Aa, AA-aa, Aa-Aa, Aa-aa, aa-aa. In each case, the expected (dominant phenotype) offspring is 2, 2, 2, 3/2, 1, 0." } ; 12 | 13 | HELP: iev-main 14 | { $description "Solves the problem IEV on Rosalind, using a real dataset." } ; 15 | 16 | ARTICLE: "rosalind.iev" "rosalind.iev" 17 | { $vocab-link "rosalind.iev" } 18 | ; 19 | 20 | ABOUT: "rosalind.iev" 21 | -------------------------------------------------------------------------------- /aoc2015/day8/day8.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: assocs assocs.extras eval io.encodings.utf8 io.files 4 | kernel math prettyprint regexp sequences splitting ; 5 | IN: aoc2015.day8 6 | 7 | : day8-data ( -- data ) 8 | "datasets/aoc2015/day8.txt" utf8 file-contents "\n" split ; 9 | 10 | : (day8-silver) ( str -- n ) 11 | R/ \\("|\\|x..)/ all-matching-slices [ length 1 - ] map sum 2 + ; 12 | 13 | : (day8-silver)' ( str -- n ) 14 | dup eval( -- x ) [ length ] bi@ - ; 15 | 16 | : day8-silver ( strs -- n ) [ (day8-silver) ] map sum ; 17 | 18 | : (day8-gold) ( str -- n ) 19 | "\"\\" counts values sum 2 + ; 20 | 21 | : (day8-gold)' ( str -- n ) 22 | dup unparse [ length ] bi@ - neg ; 23 | 24 | : day8-gold ( strs -- n ) [ (day8-gold) ] map sum ; 25 | 26 | : day8-main ( -- ) 27 | day8-data [ day8-silver . ] [ day8-gold . ] bi ; 28 | 29 | MAIN: day8-main -------------------------------------------------------------------------------- /rosalind/long/long.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: arrays assocs grouping.extras hash-sets io 4 | io.encodings.utf8 io.files kernel math math.combinatorics 5 | rosalind.common sequences sets sets.extras ; 6 | IN: rosalind.long 7 | 8 | : overlap ( str1 str2 -- str ) 9 | [ [ dupd tail? ] find-last drop ?1+ head* ] keep append ; 10 | 11 | : find-most-overlapping-pair ( strs -- strs' ) 12 | 2 [ first2 2dup overlap 3array ] map 13 | [ [ length ] map first3 - + ] supremum-by ; 14 | 15 | : long ( strs -- str ) 16 | [ >hash-set ] keep length 1 - [ 17 | dup members find-most-overlapping-pair >hash-set symmetric-diff 18 | ] times members first ; 19 | 20 | : long-main ( -- ) "datasets/rosalind/long.txt" utf8 file-contents 21 | fasta>assoc values long 22 | "/tmp/long.txt" utf8 set-file-contents ; 23 | 24 | MAIN: long-main -------------------------------------------------------------------------------- /rosalind/cat/cat.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: arrays assocs combinators io.encodings.utf8 io.files 4 | kernel math math.functions memoize prettyprint rosalind.common 5 | sequences ; 6 | IN: rosalind.cat 7 | 8 | : unbalanced? ( seq -- ? ) sum 0 = not ; 9 | 10 | DEFER: noncrossing-matches 11 | 12 | : (noncrossing-matches) ( seq -- n ) 13 | unclip neg over indices 14 | [ cut rest [ noncrossing-matches ] bi@ * ] with map sum ; 15 | 16 | MEMO: noncrossing-matches ( seq -- n ) 17 | { { [ dup empty? ] [ drop 1 ] } 18 | { [ dup unbalanced? ] [ drop 0 ] } 19 | [ (noncrossing-matches) ] 20 | } cond ; 21 | 22 | : cat ( str -- n ) 23 | >array [ 2/ 1 i* swap ^ ] map 24 | noncrossing-matches 1000000 mod ; 25 | 26 | : cat-main ( -- ) 27 | "datasets/rosalind/cat.txt" utf8 file-contents 28 | fasta>assoc first second 29 | cat . ; 30 | 31 | MAIN: cat-main -------------------------------------------------------------------------------- /datasets/rosalind/rna.txt: -------------------------------------------------------------------------------- 1 | GGCGCTGGAATTGGACTTGCCCAAATACCAGATGGAAGAGAAGTTTGGGGCTCGGAGCTCCTAGTACGTCCCTTTTCCTGGTCACAGTGCGACCTAATGTGAACACACAACAGAAGTTATCGTGAATAATACTCTTGCCATACGCGGTCGTGTGTCACGCTGCAGACGTGTTTTCCGCTATGTTGAGTAGGATTGAAAGATCATGTACTAGAATAGTGTACAAAAGGGCATCGGCTAATGCGTCGCATCTAGGAGTTATTCGCCGCAAAGTCTCTCCTTTATGAGTACCGGCGGATAGCGTTCCCGTGCTATGTGCAGGTCCGTATCCCGTTTCCAACACACTTTGAGATCCACACAAGACCACAAAAGGCACCAAAACGTCCATGTGTCCATTGATCCTCAGCTGGTTGCGTTATCGGGCCAAGCCAGAGTCTTTACCTAGGCTCATTCCATCTCTATCGTATTGTTGGCTCTCACTCTTAACGGATGCAGGAAATGCATGGTTGGGCGGTTAGGACGAGTCCCGTATCGTGAGGATACGAAGGCGCAAACGATTTGTACCAGAGACGAAAACTTGAATTTCACAAAGAGAAGTTCTTTACTCGTTATACGGCGTTTATACGGTACTTTAACAATCCCCGCATTAGATAACTATATCCTAAGGGGCAGTCAGGCGGACTATTGAGCCGGAGTGTCTCCAATGAGGCATCTAATATAGTACCGTACCTGTTCTTGGGAGCCCACCTCATCGGTTGTCCTGACTGATGTAAAAGACGGCTCAGAGTCACTTACTGTATTGAAGGAACCCTCAGTGTACTTCTATCTAGTTTTCCGCCATCCTTTGCCTAATCAACTCGGCGCGTTGTACAAGGTCCATTATGGTAGGGCGAAAAAGATTAAAAGTATGTAACATTAAGATCAGTCTGGGCTCCGAAAATGCGGCAGCTCTGGG -------------------------------------------------------------------------------- /aoc2020/day13/day13.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: assocs fry io.encodings.utf8 io.files kernel math 4 | math.algebra math.parser prettyprint regexp sequences 5 | sequences.extras splitting ; 6 | IN: aoc2020.day13 7 | 8 | : day13-silver-preprocess ( lines -- n seq ) 9 | first2 [ dec> ] [ R/ \d+/ all-matching-subseqs [ dec> ] map ] bi* ; 10 | 11 | : day13-silver ( n seq -- ans ) 12 | swap neg '[ _ over rem ] { } map>assoc [ second ] infimum-by product ; 13 | 14 | : day13-gold-preprocess ( lines -- seq ) 15 | last "," split [ dec> ] map ; 16 | 17 | : day13-gold ( seq -- ans ) 18 | zip-index sift-keys [ neg ] map-values unzip swap chinese-remainder ; 19 | 20 | : day13-main ( -- ) "datasets/aoc2020/day13.txt" utf8 file-contents "\n" split 21 | [ day13-silver-preprocess day13-silver . ] 22 | [ day13-gold-preprocess day13-gold . ] 23 | bi ; 24 | 25 | MAIN: day13-main -------------------------------------------------------------------------------- /datasets/rosalind/dna.txt: -------------------------------------------------------------------------------- 1 | GCTTAACTCGGTACATGTCCGGGGGTGGCGCATGAAATGATAGTCGTAACCAGTCAGTTCCAGTGTGAGATGATCGCCCCCCGACGGCGGTAATCCACCAAACGTATAATAAGCCCGGGAATCTGAGCGGTGTTCTATATGGCTCCTTACGCCTGAACCTTCGCAAGCACACTAAATTTGGATAGCAGAGCCCTCAGCTAGAAAATAACATCTGGCACTTAACAAGCTATTCGGAACGTTTAGCATGGGGTCGGGGCACACTGCCCGGTGCGATTTTTCTAGCCAATCCGGCCCATCTTTCGATGCATCAGACCCGAGAGCCCTCATCCTGATGTAGTCGCCAAGAATCCTTGGGTTAGACGGCCTACGAATATACGGGGGGCACGCTGACATTCGACCCCCCTGGTCGTGTCTAGGCGCTATAGTAACGTCCGACGGAATTCGTTATCTTATACGGAGGGCCTGTCTCTCAGAAACTGGGGGACCCCTTAGGCGGGTTGGAAAAGTTCTAAAATCCCCACTTAGGGAGGATGCCCCCCTCCTCTCAACGAGTTCTGTTCAGTGACGAATGATATACACGCCGGGGTATGGCGGGATTTGGAGGGCCGAAATACATCACTCTGCAGGGTAACCACTTGATGCCGATCCAATACGGGGAAAGGCAATAGACCTATCCTATGAGTTGGGCTGTTGAGAATACCTTAAGGGTCCGCCCAAAGTGGAGTCGAGCCGGCGGGAAAGGATCCCCTCGGATCCCAAAGGTAAGATAGTTAGAGGCCCGAGGAAGAGCTAAAACCATCATCTACTCGCCGCCCAGAGTAGCGTAACCTGACCCCTCAGGTTCACGAGGTTAGTCGTATCTATTCAGAGCGTTCTAATTTAGACCACGGAGGCTGCATTGCCCCCCGGACTTTCATCGAGCATAATTAGGTTACAGGCGAGGCGATCCGGGTG -------------------------------------------------------------------------------- /rosalind/rstr/rstr-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel math strings ; 4 | IN: rosalind.rstr 5 | 6 | HELP: 1-n 7 | { $values 8 | { "n" number } 9 | { "1-n" number } 10 | } 11 | { $description "Evaluates the complement of the given probability." } ; 12 | 13 | HELP: rstr 14 | { $values 15 | { "trials" integer } { "gc-content" real } { "str" string } 16 | { "prob" real } 17 | } 18 | { $description "Solves the problem RSTR on Rosalind: Compute the probability that, if " { $snippet "trials" } " random DNA strings are constructed with the given GC content, the exact DNA string given appears at least once." } ; 19 | 20 | HELP: rstr-main 21 | { $description "Solves the problem RSTR on Rosalind, using a real dataset." } ; 22 | 23 | ARTICLE: "rosalind.rstr" "rosalind.rstr" 24 | { $vocab-link "rosalind.rstr" } 25 | ; 26 | 27 | ABOUT: "rosalind.rstr" 28 | -------------------------------------------------------------------------------- /datasets/rosalind/subs.txt: -------------------------------------------------------------------------------- 1 | CAGGGGCCAGGGGCACAGGGGCGAATCAGGGGCCAGGGGCTGTCCAGGGGCCCAGGGGCCAGGGGCGGACAGGGGCTGGTAAAAAGTCAGGGGCGTCGGCAGGGGCCAGGGGCCGCCAGGGGCTAGAGGGCTAGGCATTCTTACCAGGGGCCCTCAGGGGCCAGGGGCGAGACACTTTCAGGGGCAAAAGAAACCAGGGGCGCAGGGGCCCAGGGGCACCGCAGGGGCCAGGGGCCAGGGGCTCCCCCGCAGGGGCCAGGGGCCCGCAGGGGCCAGGGGCTCAGGGGCGAAGTGTCAGGGGCGGCAGGGGCGAGCAGGGGCATCAGGGGCGTCAGGGGCTCCAGGGGCCAGGGGCCAGGGGCCCAGGGGCTCGACTGCAGGGGCCAGGGGCCAGGGGCTAGACGACGCAGGGGCCAGGGGCACAGGGGCCTACAGGGGCACAGGGGCAGAGTCAGGGGCCAGGGGCTGCAGGGGCCAGGGGCCAGGGGCTCGTTGAGCAGGGGCCAGGGGCCAGGGGCCAACCTGAGCAGGGGCTGCAGGGGCAGACCCCAGGGGCGAGGTAACAGGGGCCAGGGGCCAGGGGCGTCAGGGGCAAGCAGGGGCGACAGGGGCGGAAGCAGGGGCTGTCAGGGGCCAGGGGCACAAAACTAAAGGTACGGGGGGCAGGGGCCCAGGGGCCAGGGGCCAGGGGCCAGGGGCACTGCCAGGGGCCAGGGGCAACGCAGGGGCACTCAGGGGCGATGTTCAATCAGGGGCGTTAACCAGGGGCACAGGGGCCAGGGGCGCGGTGCGTAGCAGGGGCCAGGGGCGAAATAATCGCAGGGGCGGTTACAGGGGCGGCAGGGGCCAGGGGCCTGACAGGGGCCAGGGGCGTACCACAGGGGCGCAGGGGCCAGGGGCAGGGGTCGCAGGGGCTCAGGGGCTCTAACGGCAGGGGCGACCAGGGGCTCAGGGGC 2 | CAGGGGCCA -------------------------------------------------------------------------------- /rosalind/lcsq/lcsq-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel sequences ; 4 | IN: rosalind.lcsq 5 | 6 | HELP: (lcsq) 7 | { $values 8 | { "subseqs" sequence } { "elem" object } { "seq2" sequence } 9 | { "subseqs'" sequence } 10 | } 11 | { $description "Runs the inner loop of the longest common subsequence algorithm." } ; 12 | 13 | HELP: lcsq 14 | { $values 15 | { "seq1" sequence } { "seq2" sequence } 16 | { "seq" sequence } 17 | } 18 | { $description "Solves the problem LCSQ on Rosalind: Given two sequences, compute the longest common subsequence. Uses the O(mn) DP algorithm, where m and n are the lengths of two input sequences." } ; 19 | 20 | HELP: lcsq-main 21 | { $description "Solves the problem LCSQ on Rosalind, using a real dataset." } ; 22 | 23 | ARTICLE: "rosalind.lcsq" "rosalind.lcsq" 24 | { $vocab-link "rosalind.lcsq" } 25 | ; 26 | 27 | ABOUT: "rosalind.lcsq" 28 | -------------------------------------------------------------------------------- /aoc2020/day7/day7-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: aoc2020.day7 assocs multiline sequences splitting 4 | tools.test ; 5 | IN: aoc2020.day7.tests 6 | 7 | STRING: example 8 | light red bags contain 1 bright white bag, 2 muted yellow bags. 9 | dark orange bags contain 3 bright white bags, 4 muted yellow bags. 10 | bright white bags contain 1 shiny gold bag. 11 | muted yellow bags contain 2 shiny gold bags, 9 faded blue bags. 12 | shiny gold bags contain 1 dark olive bag, 2 vibrant plum bags. 13 | dark olive bags contain 3 faded blue bags, 4 dotted black bags. 14 | vibrant plum bags contain 5 faded blue bags, 6 dotted black bags. 15 | faded blue bags contain no other bags. 16 | dotted black bags contain no other bags. 17 | ; 18 | 19 | : preprocessed ( -- assoc ) example "\n" split [ parse-line ] map H{ } assoc-like ; 20 | { 4 } [ preprocessed day7-silver ] unit-test 21 | { 32 } [ preprocessed day7-gold ] unit-test 22 | -------------------------------------------------------------------------------- /datasets/rosalind/mrna.txt: -------------------------------------------------------------------------------- 1 | MMLWQAFEWSAYRPWHQPVHSQRNDPNDEICPQKSNYPQLMLLLEWDSWPVVGHLCPAFMSFAHRVFQDHHSAEGWWIRYRGLRLLISWCMFMPDCQVLVYWALAPFEQWSWAWDNEGCNITIHVQFTHGYADLQDYEVSEGMKEQAWIMKGWDYAPDSDNTPHSNHWWHQENGFKKETARWNTKMRGWMWVAAQTDSGELNIYTTATFELNYYHLDQGFWDWNIPSMIDFTAQMFNWEPTPRTASKDMKSGLYVECDCLQNNDTELYNNFGIGSNYQRDMSNSYYKMLRRAFNHFIFSIHHMTIRQLCHPNIITSWGFYRSYCQWKMHMLFENWQCMCEVYITDIILTQQEWPTIGQPNGEDFGPHWPIAHPKFVKHFERPNHIHFLKPQQLNEMGMGERLINGSQIRFTKGWKYTRVVTGSLLYCMRMWYASHQCKHTCQTGRSNPFCCTKFPFNSDQAMYFMYGDVDHECNKHEFSVMCAFCRCWSLFGGHMLVNQCCYTNQHHRNTTYTSRVMQYWKHPRLSVSMNGMHRKLKENEILTSGSVGYHMAASGHRCADREHDDGHIISWEGRGAVSADVWMSPICIMAEYQQFKYCEDGHRLAVMCIYTRKHKSEMAQEGIHFKQILRLDYMEKDWTQTMIPNASTWRKFANHPNSPEPAAYLLMWPFGVFRRVACKDVNNDGWMTQHWGYSPVMNHKQSIWRVNYTWPQSTRFDEHYMKGQHLGPHQMAEFEMGIGQREYAARQRCQAKGMKYLCIMSEKCGARHHYATNWIMSQGLKWATFADSHMGGIILMSAVPPGMYCEERKRQDNRTMWNFRDDNIFAICADTHFIKISVGKKIVKGPCQIQHPIGNKQQWEYIKKSTYFNCSINRQMFTDLVSVAACFLGQDFAQVCYDSLLFNKAIWANLIRQEASLMERRIVHEGDAEFQDVKVCSQGMRPKMPWCEPMVGNDVFELHMRHYVHHYWVHKSHLKCQNEWDHCHYMSSWDWFYECCQCAK -------------------------------------------------------------------------------- /rosalind/seto/seto.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: arrays io io.encodings.utf8 io.files kernel math.parser 4 | math.ranges regexp sequences sets splitting ; 5 | IN: rosalind.seto 6 | 7 | : 2set-ops ( set1 set2 -- sets ) 8 | { [ union ] [ intersect ] [ diff ] [ swap diff ] } 9 | [ call( x x -- x ) ] 2with map ; 10 | 11 | : set-complements ( n set1 set2 -- sets ) 12 | 2array [ [1,b] ] dip [ diff ] with map ; 13 | 14 | : seto ( n set1 set2 -- sets ) 15 | [ nipd 2set-ops ] [ set-complements ] 3bi append ; 16 | 17 | : parse-set ( str -- seq ) 18 | R/ \d+/ all-matching-subseqs [ dec> ] map ; 19 | 20 | : print-set ( seq -- ) 21 | [ number>string ] map ", " join "{" "}" surround print ; 22 | 23 | : seto-main ( -- ) "datasets/rosalind/seto.txt" utf8 file-contents 24 | "\n" split first3 [ dec> ] [ parse-set ] dup tri* 25 | seto "/tmp/seto.txt" utf8 [ [ print-set ] each ] with-file-writer ; 26 | 27 | MAIN: seto-main -------------------------------------------------------------------------------- /rosalind/tran/tran-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel sequences strings ; 4 | IN: rosalind.tran 5 | 6 | HELP: tran 7 | { $values 8 | { "str1" string } { "str2" string } 9 | { "ratio" null } 10 | } 11 | { $description "Solves the problem TRAN on Rosalind: given two DNA strings of equal length, evaluate the ratio between transitions (A-G, C-T point mutations) and transversions (other kinds of point mutations)." } ; 12 | 13 | HELP: tran-main 14 | { $description "Solves the problem TRAN on Rosalind, using a real dataset." } ; 15 | 16 | HELP: trans-type 17 | { $values 18 | { "seq" sequence } 19 | { "type/f" null } 20 | } 21 | { $description "Given a sequence of two DNA symbols, classifies the mutation as a transition (1), transversion (2), or neither (f)." } ; 22 | 23 | ARTICLE: "rosalind.tran" "rosalind.tran" 24 | { $vocab-link "rosalind.tran" } 25 | ; 26 | 27 | ABOUT: "rosalind.tran" 28 | -------------------------------------------------------------------------------- /rosalind/cons/cons-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: assocs help.markup help.syntax kernel strings ; 4 | IN: rosalind.cons 5 | 6 | HELP: cons 7 | { $values 8 | { "assoc" "An assoc of ID string and DNA string" } 9 | { "histo" "Profile matrix" } { "consensus" "Consensus string" } 10 | } 11 | { $description "Solves the problem CONS on Rosalind: given a collection of DNA sequences, output the histogram of nucleotides at each position and the consensus string." { $nl "" } 12 | "A profile matrix is a 4×n matrix where each column shows the histogram of A, C, G, T nucleotides at that position in the given DNAs. A consensus string is a string formed by picking the most common symbol for each position." 13 | } ; 14 | 15 | HELP: cons-main 16 | { $description "Solves the problem CONS on Rosalind, using a real dataset." } ; 17 | 18 | ARTICLE: "rosalind.cons" "rosalind.cons" 19 | { $vocab-link "rosalind.cons" } 20 | ; 21 | 22 | ABOUT: "rosalind.cons" 23 | -------------------------------------------------------------------------------- /rosalind/spec/spec-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: assocs help.markup help.syntax kernel sequences strings ; 4 | IN: rosalind.spec 5 | 6 | HELP: inv-mass-table 7 | { $values 8 | { "assoc" assoc } 9 | } 10 | { $description "Returns an inverted mapping between the amino acid code and its mass. The mass is scaled 20x and rounded to integer in order to disambiguate between K and Q. I and L have totally identical mass, so L is used." } ; 11 | 12 | HELP: spec 13 | { $values 14 | { "seq" sequence } 15 | { "ans" string } 16 | } 17 | { $description "Solves the problem SPEC on Rosalind: Given a prefix spectrum (a collection of prefix weights) of length L, find a matching protein string of length L-1." } ; 18 | 19 | HELP: spec-main 20 | { $description "Solves the problem SPEC on Rosalind, using a real dataset." } ; 21 | 22 | ARTICLE: "rosalind.spec" "rosalind.spec" 23 | { $vocab-link "rosalind.spec" } 24 | ; 25 | 26 | ABOUT: "rosalind.spec" 27 | -------------------------------------------------------------------------------- /aoc2015/day1/day1-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel math strings ; 4 | IN: aoc2015.day1 5 | 6 | HELP: day1-gold 7 | { $values 8 | { "str" string } 9 | { "n" integer } 10 | } 11 | { $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." } ; 12 | 13 | HELP: day1-main 14 | { $description "Solves both parts of Day 1 of AoC2015, using a real dataset." } ; 15 | 16 | HELP: day1-silver 17 | { $values 18 | { "str" string } 19 | { "n" integer } 20 | } 21 | { $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 ")" } "." } ; 22 | 23 | ARTICLE: "aoc2015.day1" "aoc2015.day1" 24 | { $vocab-link "aoc2015.day1" } 25 | ; 26 | 27 | ABOUT: "aoc2015.day1" 28 | -------------------------------------------------------------------------------- /aoc2020/day6/day6-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel ; 4 | IN: aoc2020.day6 5 | 6 | HELP: day6-gold 7 | { $values 8 | { "answers" "Questionnaire answers grouped by teams" } 9 | { "sum" "Sum of yes-answers for each team" } 10 | } 11 | { $description "Solves Day 6, Part 2 of AoC2020: for each team, count all questions answered yes by all members, and find the sum." } ; 12 | 13 | HELP: day6-main 14 | { $description "Solves both parts of Day 6 of AoC2020, using a real dataset." } ; 15 | 16 | HELP: day6-silver 17 | { $values 18 | { "answers" "Questionnaire answers grouped by teams" } 19 | { "sum" "Sum of yes-answers for each team" } 20 | } 21 | { $description "Solves Day 6, Part 1 of AoC2020: for each team, count all questions answered yes by at least one member, and find the sum." } ; 22 | 23 | ARTICLE: "aoc2020.day6" "aoc2020.day6" 24 | { $vocab-link "aoc2020.day6" } 25 | ; 26 | 27 | ABOUT: "aoc2020.day6" 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # factor-problem-solving 2 | 3 | Solutions to various problems written in Factor 4 | 5 | ## How to add a solution 6 | 7 | * Add `AUTHOR` environment variable set as your name/username. (On Gitpod, you can do this in account settings.) 8 | * In non-Gitpod setting, copy the code in `.factor-rc` into your own. 9 | * Run `factor` in terminal at the git repo root, then enter: 10 | ``` 11 | USE: tools.scaffold 12 | "." "problem-site.problem-code" scaffold-vocab 13 | "problem-site.problem-code" scaffold-tests 14 | "problem-site.problem-code" scaffold-docs 15 | ``` 16 | * See `rosalind.dna` for an example. If a solution is worth an explanation, it should go to the description in the docs. 17 | * 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). -------------------------------------------------------------------------------- /datasets/rosalind/orf.txt: -------------------------------------------------------------------------------- 1 | >Rosalind_8159 2 | GAGCGAGAACAGGGAGCCGGAGACTTAGAGCTGAGCATTTGACCAAAAGTACCTATGAGC 3 | GTTTGCACCCCCCCATGCTACAGTCATGCGGATGTCTTAGCTACGCGCAGAATACTTACT 4 | GTATGGCAAGGTCCACATAGAACCGACTGGTCCGAAGGGTTTCTTCTTTCATGTGACATC 5 | CTATGTGCCAACCCATGCTGCCCTGAAGTCGTGGAACCGTAGGGACTTTACGTTTACCCA 6 | TTTCACTATTCAGCCTGACTTTCGCCGGAAACCTGTGTCTTTAATCACCAGCATCTTTCG 7 | TCTCGATACTCTATATGATCACGTAGCGCTTAATTCCTAAAATTCATTATGACACTTGGC 8 | GCTGGTCAGCACAACCGGACCAAGGAGTCGTCGGGATCATATCTTCAAGGATTTTGGGTA 9 | GTTATTGGCGTAGACAGTATGACGAACTCAGGAGAGGGGAGACGATGCTAGCTAGCATCG 10 | TCTCCCCTCTCCTGAGTTCGTCATAACGAGCCCCAGGGTGTAATCATTCTGAATATAAGT 11 | GTGCGCTAGTACCATCAGCTGGGGTATTTTCCTAAACAGCTATGGTTGAGTTTGCCAGAA 12 | GCCCTTAGTTATTCGGTGAAGTGATGCACGTCCAAAGTACAACTAATGATGCCGTGCACC 13 | CGAAGCCTTGTTATTGAGTTATGTTTCTATCGTCCCACGGGATTTTGGACGCCATAAAGC 14 | CCCCTTCAGGTTTAGTAAGTAGGAAGTCCCAGCCACCTTAACTCCCTGAAGGCTAACATT 15 | ATTCCCTCCCTCACTCAAGCAAAACGCTATGTCATGCATGACGGATGGGCGATCAAAGCC 16 | AAAGTCTATACGTCCATCTAATACTGTATTACACGTCACAACCTCTAGAGAGCCAGCGCC 17 | GCAGCCTCGACGGGGCCCAAGTTGCTCGTTAAACCTTACAGG -------------------------------------------------------------------------------- /rosalind/lia/lia-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel ; 4 | IN: rosalind.lia 5 | 6 | HELP: lia 7 | { $values 8 | { "k" "An integer" } { "n" "An integer" } 9 | { "p" "A float" } 10 | } 11 | { $description "Solves the problem LIA on Rosalind: starting with an organism with AaBb genotype at 0th generation, suppose that each organism mates with an AaBb and reproduces two children. At k-th generation, calculate the probability that there are at least n organisms with AaBb genotype." { $nl "" } 12 | "The code uses the fact that each organism at any generation has exactly 1/4 chance of being an AaBb. Polynomial power gives a sequence where i-th value is the chance of having exactly i AaBb's in the population." } ; 13 | 14 | HELP: lia-main 15 | { $description "Solves the problem LIA on Rosalind, using a real dataset." } ; 16 | 17 | ARTICLE: "rosalind.lia" "rosalind.lia" 18 | { $vocab-link "rosalind.lia" } 19 | ; 20 | 21 | ABOUT: "rosalind.lia" 22 | -------------------------------------------------------------------------------- /datasets/rosalind/revp.txt: -------------------------------------------------------------------------------- 1 | >Rosalind_3201 2 | CGCGGTGGTGGCGCGTCTCCTTAAAGCAGCTCTAACGCCTTTTTATCTGCTATATAAACC 3 | CTACCGTGCCGGTAGTCCGAGGGCAGCGACACGGGCTACTTATGTGACCTCGTGAGACTT 4 | CTTGCGCGACTATACACATGGAGTGCGATATTGGCCCCGTGATAAAGCTTACTCCCTTCG 5 | CTAAGCTAATTTCGCCGGTCGCGCGCACCGAGGGAAAAGGCAATTCGCAACGCTTTAGAT 6 | CATGATACCAAGGGGGTGCTGAGATGCTTTCCGACCATATCGATAAGACCTACGATCTCC 7 | GGCAATATATTTCGAGGACTCTTCTCAGAGCTAAGTCTCGCTGAGTCTACCACAGAAACC 8 | TCCTGGACTAAATCTTTTTGCATCAGGAACAAGCGCCCGATGTTCAGACTCGCGCGCAAT 9 | ATAGATGCTAAAGAAAATACCGATTGTACTGAAACGGCTATAATATCAGGGTGGGGGCAT 10 | GCCCCACCCACCATCCTCATGCGATCGGTTCGGCGCGAGGAGAAAGAGCAGATACCGTAC 11 | TTTTGAGGCAACATTGGTACACTAGACATCTCTTCAGTTCAGGCCTTCGCTGTCGTGAGA 12 | ACAACTCTCTCAACGCACAGCTTATAGATGGTGCTCGTTTGACTGAGGACTGGAAAGAAG 13 | ATACACTGTAATTCGCCAGAGCATATGATACGTTACAGTCTTTTCTATAGTGACCGTTAT 14 | TTAGGGTCGACTGGAGTACTTGTCATAAGAAGGGGGAACGCGAGGTTTACACACCACTTC 15 | CATGTGCTAAACTAATGTGATCGACTGGTGGCTGCATTCACAAGCGCAATGTAGGACTAC 16 | CGGCAGTAATGCAAGTAGCGCGAGGGATAACCTAATCTGAACCCAAGAACATTATTCAAA 17 | TACTGAGCCTCACTGACCTAGAACTATCGTTAGGCTCTCTTCCACGGTGTGCCCCGCG -------------------------------------------------------------------------------- /datasets/rosalind/sseq.txt: -------------------------------------------------------------------------------- 1 | >Rosalind_8969 2 | GTCTTAGCGGCTCTGGTCCCGGTTATCCTGGAGCGGGCGGCGTTTCCCAGAAGACTATAG 3 | TCGGGGCTCTCGGTTAATATTCTGCACCATCGCGGACTCCAGAGTTCTCGCTATGCTGGT 4 | GATGGTGACGTTATATTCCCTGGTGGGCCTCAGGACTTGGCCACATTGTTGCCTCTGTGT 5 | CAAAGTGAATACTTTTATTCGCTGAACCGGACACTCTCATTTAAATGAATGGGTGGTTTG 6 | CGGTCGAACGCATAGTAAAGCGATATTACTGACTATCCAAGGTAACTCAAACCCGCGCTC 7 | CAAAAGTCCTCATTAGAAACAACGTAGCTGAGCCTTGATTAGTTGGATAAGCCTCGTTCT 8 | GAGTCTGTTCCTGCAGGACACTGAAGTGTAACTCGTCGCGCAACTCGAATGCAGGTATTC 9 | GGTCGACGCCATCCTCGGCTGGTTCAGCCCAACTTAGGTATACATGGCGAGCGATTTTCT 10 | GTTAAGTGTTTGGGTGATCGTTGACTATCTCGGGTTCGATAGTTGATGTCTCTGCACGAG 11 | TATCTCAGTTAAAGACTGGGAGTGACATGTTTTAAAGCGTCTTTTACGCGTAGTCAGTCG 12 | TCCTTTGACATCGTTCCCAGCATCCAAGTCGGGGCTGTGCCCAAGGTTACCCAAATCCTA 13 | AAAACAATCACCCGCCACGGTTTTTCTACTTTTCCAAGGAACCTGGGGCGCAACAGCGAA 14 | CCGACGTATAGGGCCGTCGTATGATACTATCCAGCTGACTGTCGGCGTCTAAACGGAATA 15 | GCGGCAGATTAGTTGTTTTTAGGCACTCATCCTGAATTTTTGTCGACGAAGAGGAGTTTT 16 | AGATGGAGCGTTATATATTT 17 | >Rosalind_6007 18 | ATGGTGCAATGGGAGGTTACGGCGTCTTAGTGATACAAGTGCGCTATGATTAGCAGTGCC 19 | CGTCCAGGTTTGTCTCCTTAAGCCGGTAGCTAGTTAGGTA -------------------------------------------------------------------------------- /rosalind/edit/edit-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel math sequences ; 4 | IN: rosalind.edit 5 | 6 | HELP: (edit) 7 | { $values 8 | { "dists" sequence } { "elem" object } { "seq2" sequence } 9 | { "dists'" sequence } 10 | } 11 | { $description "Runs the inner loop of the edit distance algorithm. Code structure is the same as LCSQ, longest common subsequence problem." } ; 12 | 13 | HELP: edit 14 | { $values 15 | { "seq1" sequence } { "seq2" sequence } 16 | { "n" integer } 17 | } 18 | { $description "Solves the problem EDIT on Rosalind: Given two strings, find the edit distance. Uses the O(mn) DP algorithm, where m and n are the lengths of two input sequences. Code structure is the same as LCSQ, longest common subsequence problem." } ; 19 | 20 | HELP: edit-main 21 | { $description "Solves the problem EDIT on Rosalind, using a real dataset." } ; 22 | 23 | ARTICLE: "rosalind.edit" "rosalind.edit" 24 | { $vocab-link "rosalind.edit" } 25 | ; 26 | 27 | ABOUT: "rosalind.edit" 28 | -------------------------------------------------------------------------------- /rosalind/eval/eval-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel math sequences strings ; 4 | IN: rosalind.eval 5 | 6 | HELP: (eval) 7 | { $values 8 | { "n" integer } { "str" string } { "gc-content" real } 9 | { "prob" real } 10 | } 11 | { $description "Solves the problem EVAL for a single GC content value. Uses \"linearity of expectation\", which says that E(x+y) = E(x) + E(y) for any random variables x and y, even if they are dependent." } ; 12 | 13 | HELP: eval 14 | { $values 15 | { "n" integer } { "str" string } { "gc-contents" sequence } 16 | { "seq" sequence } 17 | } 18 | { $description "Solves the problem EVAL on Rosalind: Given a DNA string, evaluate the expected number of that string in a length-n random DNA string with the given GC contents." } ; 19 | 20 | HELP: eval-main 21 | { $description "Solves the problem EVAL on Rosalind, using a real dataset." } ; 22 | 23 | ARTICLE: "rosalind.eval" "rosalind.eval" 24 | { $vocab-link "rosalind.eval" } 25 | ; 26 | 27 | ABOUT: "rosalind.eval" 28 | -------------------------------------------------------------------------------- /aoc2020/day1/day1-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel sequences ; 4 | IN: aoc2020.day1 5 | 6 | HELP: day1-silver 7 | { $values 8 | { "seq" "A sequence of integers" } 9 | { "prod" "The answer" } 10 | } 11 | { $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." } ; 12 | 13 | HELP: day1-main 14 | { $description "Solves both parts of Day 1 of AoC2020, using a real dataset." } ; 15 | 16 | HELP: day1-gold 17 | { $values 18 | { "seq" "A sequence of integers" } 19 | { "prod" "The answer" } 20 | } 21 | { $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 "" } 22 | "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." } ; 23 | 24 | ARTICLE: "aoc2020.day1" "aoc2020.day1" 25 | { $vocab-link "aoc2020.day1" } 26 | ; 27 | 28 | ABOUT: "aoc2020.day1" 29 | -------------------------------------------------------------------------------- /rosalind/kmp/kmp-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel sequences ; 4 | IN: rosalind.kmp 5 | 6 | HELP: ((kmp)) 7 | { $values 8 | { "vec" vector } { "elem" object } { "seq" sequence } { "cur" integer } 9 | } 10 | { $description "Recursively computes the next item in the failure vector." } ; 11 | 12 | HELP: (kmp) 13 | { $values 14 | { "vec" vector } { "elem" object } { "seq" sequence } 15 | } 16 | { $description "Adds an item to the failure vector " { $snippet "vec" } "." } ; 17 | 18 | HELP: kmp 19 | { $values 20 | { "seq" sequence } 21 | { "seq'" sequence } 22 | } 23 | { $description "Solves the problem KMP on Rosalind: given a DNA string, compute the \"failure array\", where each element n at index i is the largest number that satisfies " { $snippet "seq[:n] = seq[i-n+1:i+1]" } "." } ; 24 | 25 | HELP: kmp-main 26 | { $description "Solves the problem KMP on Rosalind, using a real dataset." } ; 27 | 28 | ARTICLE: "rosalind.kmp" "rosalind.kmp" 29 | { $vocab-link "rosalind.kmp" } 30 | ; 31 | 32 | ABOUT: "rosalind.kmp" 33 | -------------------------------------------------------------------------------- /rosalind/lgis/lgis-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel math sequences vectors ; 4 | IN: rosalind.lgis 5 | 6 | HELP: (longest-increasing-subseq) 7 | { $values 8 | { "vec" vector } { "n" integer } 9 | } 10 | { $description "Implementation of the inner loop of the longest increasing subsequence algorithm." } ; 11 | 12 | HELP: lgis 13 | { $values 14 | { "seq" sequence } 15 | { "seq+" sequence } { "seq-" sequence } 16 | } 17 | { $description "Solves the problem LGIS on Rosalind: find the longest increasing subsequence and longest decresing subsequence of the given permutation." } ; 18 | 19 | HELP: lgis-main 20 | { $description "Solves the problem LGIS on Rosalind, using a real dataset." } ; 21 | 22 | HELP: longest-increasing-subseq 23 | { $values 24 | { "seq" sequence } 25 | { "seq'" sequence } 26 | } 27 | { $description "Implementation of the longest increasing subsequence algorithm." } ; 28 | 29 | ARTICLE: "rosalind.lgis" "rosalind.lgis" 30 | { $vocab-link "rosalind.lgis" } 31 | ; 32 | 33 | ABOUT: "rosalind.lgis" 34 | -------------------------------------------------------------------------------- /projecteuler/euler258/euler258.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: arrays grouping kernel locals math math.bits 4 | math.functions math.polynomials prettyprint sequences ; 5 | IN: projecteuler.euler258 6 | 7 | : p-sq' ( poly -- poly' ) 8 | 64 2^ swap polyval sq make-bits 64 group [ bits>number ] map ; 9 | 10 | :: polykm ( poly k m -- poly' ) 11 | poly length 2 - k >= [ k 0 1 suffix ] [ 12 | poly k 2/ m polykm 13 | p-sq' k odd? [ 0 prefix ] when 14 | poly p/mod nip [ m mod ] map 15 | ] if ; 16 | 17 | :: polykm-special ( n k m -- poly ) 18 | n 1 - k >= [ k 0 1 suffix ] [ 19 | n k 2/ m polykm-special 20 | p-sq' k odd? [ 0 prefix ] when 21 | 2 [ n short cut dup 0 prefix p+ p+ ] times [ m mod ] map 22 | ] if ; 23 | 24 | : euler258-slow ( n k m -- ans ) 25 | [ 2 - 0 { -1 -1 } { 1 } surround ] 2dip 26 | [ polykm sum ] keep mod ; 27 | 28 | : euler258-fast ( n k m -- ans ) 29 | [ polykm-special sum ] keep mod ; 30 | 31 | : euler258-main ( -- ) 32 | 2000 10 18 ^ 20092010 euler258-fast . ; 33 | 34 | MAIN: euler258-main 35 | -------------------------------------------------------------------------------- /rosalind/fibd/fibd-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel ; 4 | IN: rosalind.fibd 5 | 6 | HELP: fibd 7 | { $values 8 | { "n" "An integer, the number of months passed in total" } { "m" "An integer, a rabbit's lifespan" } 9 | { "ans" "An integer, the number of rabbit pairs in the nth month" } 10 | } 11 | { $description "Solves the problem FIBD on Rosalind: suppose a pair of immature rabbits appear in the first month, and mature rabbit pairs reproduce every month until they die. Given that a rabbit's lifespan is m months, calculate the number of rabbit pairs in the nth month." { $nl "" } 12 | "The solution uses an array of length m to keep track of rabbits at each age. In each iteration, the sum of mature rabbits is prepended (new generation), and the last number is discarded (dying generation)." } ; 13 | 14 | HELP: fibd-main 15 | { $description "Solves the problem FIBD on Rosalind, using a real dataset." } ; 16 | 17 | ARTICLE: "rosalind.fibd" "rosalind.fibd" 18 | { $vocab-link "rosalind.fibd" } 19 | ; 20 | 21 | ABOUT: "rosalind.fibd" 22 | -------------------------------------------------------------------------------- /aoc2015/day5/day5.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: combinators.short-circuit fry grouping grouping.extras 4 | io.encodings.utf8 io.files kernel math math.vectors prettyprint 5 | sequences sequences.extras sets splitting ; 6 | IN: aoc2015.day5 7 | 8 | : three-vowels? ( str -- ? ) [ "aeiou" in? ] count 3 >= ; 9 | : doubled-letter? ( str -- ? ) [ = ] 2clump-map vany? ; 10 | : no-specific-comb? ( str -- ? ) 2 clump [ { "ab" "cd" "pq" "xy" } in? ] none? ; 11 | 12 | : nice-silver? ( str -- ? ) 13 | { [ three-vowels? ] [ doubled-letter? ] [ no-specific-comb? ] } 1&& ; 14 | 15 | : day5-silver ( seq -- n ) [ nice-silver? ] count ; 16 | 17 | : pair-twice? ( str -- ? ) [ 2 clump ] keep '[ _ count-subseq 2 >= ] any? ; 18 | : char-repeat-1between? ( str -- ? ) [ nip = ] 3clump-map vany? ; 19 | 20 | : nice-gold? ( str -- ? ) 21 | { [ pair-twice? ] [ char-repeat-1between? ] } 1&& ; 22 | 23 | : day5-gold ( seq -- n ) [ nice-gold? ] count ; 24 | 25 | : day5-main ( -- ) "datasets/aoc2015/day5.txt" utf8 file-contents "\n" split 26 | [ day5-silver . ] [ day5-gold . ] bi ; 27 | 28 | MAIN: day5-main -------------------------------------------------------------------------------- /aoc2020/day25/day25-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel math strings ; 4 | IN: aoc2020.day25 5 | 6 | HELP: day25-gold 7 | { $values 8 | { "n" object } { "m" object } 9 | { "str" string } 10 | } 11 | { $description "There is no programming task for Day 25 Part 2. This word ignores the input and gives a celebration." } ; 12 | 13 | HELP: day25-main 14 | { $description "Solves both parts of Day 25 of AoC2020, using a real dataset." } ; 15 | 16 | HELP: day25-silver 17 | { $values 18 | { "n" integer } { "m" integer } 19 | { "ans" integer } 20 | } 21 | { $description "Solves Day 25, Part 1 of AoC2020: given two numbers, solve " { $snippet "7^i = n mod 20201227, 7^j = m mod 20201227" } " and evaluate " { $snippet "7^(i*j) mod 20201227" } "." } ; 22 | 23 | HELP: modlog 24 | { $values 25 | { "n" integer } 26 | { "m" integer } 27 | } 28 | { $description "Solves " { $snippet "7^m = n mod 20201227" } "." } ; 29 | 30 | ARTICLE: "aoc2020.day25" "aoc2020.day25" 31 | { $vocab-link "aoc2020.day25" } 32 | ; 33 | 34 | ABOUT: "aoc2020.day25" 35 | -------------------------------------------------------------------------------- /aoc2015/day3/day3-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel math sequences strings ; 4 | IN: aoc2015.day3 5 | 6 | HELP: day3-gold 7 | { $values 8 | { "str" string } 9 | { "n" integer } 10 | } 11 | { $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." } ; 12 | 13 | HELP: day3-main 14 | { $description "Solves both parts of Day 3 of AoC2015, using a real dataset." } ; 15 | 16 | HELP: day3-silver 17 | { $values 18 | { "str" string } 19 | { "n" integer } 20 | } 21 | { $description "Solves Day 3, Part 1 of AoC2015: Given the directions string, count the number of coordinates passed at least once." } ; 22 | 23 | HELP: path-coords 24 | { $values 25 | { "str" string } 26 | { "seq" sequence } 27 | } 28 | { $description "Given a directions string, returns the sequence of coordinates the path goes through." } ; 29 | 30 | ARTICLE: "aoc2015.day3" "aoc2015.day3" 31 | { $vocab-link "aoc2015.day3" } 32 | ; 33 | 34 | ABOUT: "aoc2015.day3" 35 | -------------------------------------------------------------------------------- /aoc2020/day7/day7.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: arrays assocs fry io.encodings.utf8 io.files kernel math 4 | math.parser prettyprint regexp sequences splitting strings ; 5 | IN: aoc2020.day7 6 | 7 | : parse-item ( str -- pair ) " " split1 swap dec> 2array ; 8 | 9 | : parse-line ( str -- pair ) 10 | " bags contain " split-subseq [ >string ] map first2 11 | dup "no other" swap subseq? 12 | [ drop { } ] [ R/ \sbags?[,.]\s?/ re-split but-last ] if [ parse-item ] map 2array ; 13 | 14 | : contains-shiny-gold? ( str assoc -- ? ) 15 | over "shiny gold" = [ 2drop t ] 16 | [ 2dup at -rot nip '[ _ contains-shiny-gold? ] any? ] if ; 17 | 18 | : day7-silver ( assoc -- n ) 19 | [ keys ] assoc-map [ keys ] keep '[ _ contains-shiny-gold? ] count 1 - ; 20 | 21 | : bag-count ( str assoc -- n ) 22 | [ at ] keep '[ swap _ bag-count * ] { } assoc>map sum 1 + ; 23 | 24 | : day7-gold ( assoc -- n ) 25 | "shiny gold" swap bag-count 1 - ; 26 | 27 | : day7-main ( -- ) "datasets/aoc2020/day7.txt" utf8 file-contents 28 | "\n" split [ parse-line ] map H{ } assoc-like 29 | [ day7-silver . ] [ day7-gold . ] bi ; 30 | 31 | MAIN: day7-main -------------------------------------------------------------------------------- /aoc2020/day5/day5-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel strings ; 4 | IN: aoc2020.day5 5 | 6 | HELP: day5-gold 7 | { $values 8 | { "strings" "A sequence of strings that represent seat positions" } 9 | { "n" "The seat ID to find" } 10 | } 11 | { $description "Solves Day 5, Part 2 of AoC2020: given that the seats form a range and they are full except for one, find the ID of that seat." } ; 12 | 13 | HELP: day5-main 14 | { $description "Solves both parts of Day 5 of AoC2020, using a real dataset." } ; 15 | 16 | HELP: day5-silver 17 | { $values 18 | { "strings" "A sequence of strings that represent seat positions" } 19 | { "highest" "The highest seat ID" } 20 | } 21 | { $description "Solves Day 5, Part 1 of AoC2020: given the seat strings, find the highest seat ID." } ; 22 | 23 | HELP: seatcode 24 | { $values 25 | { "string" "A string representing a seat position" } 26 | { "value" "The seat ID" } 27 | } 28 | { $description "Evaluates the seat ID from a seat position." } ; 29 | 30 | ARTICLE: "aoc2020.day5" "aoc2020.day5" 31 | { $vocab-link "aoc2020.day5" } 32 | ; 33 | 34 | ABOUT: "aoc2020.day5" 35 | -------------------------------------------------------------------------------- /aoc2015/day10/day10-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel math sequences ; 4 | IN: aoc2015.day10 5 | 6 | HELP: day10-data 7 | { $values 8 | { "data" sequence } 9 | } 10 | { $description "Reads the input data as an array of numbers." } ; 11 | 12 | HELP: day10-gold 13 | { $values 14 | { "seq" sequence } 15 | { "n" integer } 16 | } 17 | { $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." } ; 18 | 19 | HELP: day10-main 20 | { $description "Solves both parts of Day 10 of AoC2015, using a real dataset." } ; 21 | 22 | HELP: day10-silver 23 | { $values 24 | { "seq" sequence } 25 | { "n" integer } 26 | } 27 | { $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." } ; 28 | 29 | HELP: look-say 30 | { $values 31 | { "seq" sequence } 32 | { "seq'" sequence } 33 | } 34 | { $description "Apply look-and-say once." } ; 35 | 36 | ARTICLE: "aoc2015.day10" "aoc2015.day10" 37 | { $vocab-link "aoc2015.day10" } 38 | ; 39 | 40 | ABOUT: "aoc2015.day10" 41 | -------------------------------------------------------------------------------- /aoc2020/day15/day15.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: arrays assocs io.encodings.utf8 io.files kernel locals 4 | math math.parser prettyprint sequences splitting ; 5 | IN: aoc2020.day15 6 | 7 | : next-term ( seq -- n ) 8 | unclip-last swap reverse index ?1+ ; 9 | 10 | : day15-silver ( seq -- n ) 11 | 2020 [ dup next-term suffix ] times 2019 swap nth ; 12 | 13 | :: next-term' ( hash last i -- hash n i+1 ) 14 | last hash at [ i swap - ] [ 0 ] if* :> n 15 | i last hash set-at 16 | hash n i 1 + ; 17 | 18 | : day15-gold ( seq -- n ) 19 | unclip-last over length [ H{ } zip-index-as ] 2dip 20 | 29999999 over - [ next-term' ] times drop nip ; 21 | 22 | :: next-term'' ( array last i -- array n i+1 ) 23 | last array nth [ i swap - ] [ 0 ] if* :> n 24 | i last array set-nth 25 | array n i 1 + ; 26 | 27 | : day15-gold2 ( seq -- n ) 28 | [ but-last [ 30000000 f ] dip [ spin [ set-nth ] keep ] each-index ] keep 29 | unclip-last swap length 30 | 29999999 over - [ next-term'' ] times drop nip ; 31 | 32 | : day15-main ( -- ) "datasets/aoc2020/day15.txt" utf8 file-contents "," split [ dec> ] map 33 | [ day15-silver . ] [ day15-gold2 . ] bi ; 34 | 35 | MAIN: day15-main -------------------------------------------------------------------------------- /rosalind/corr/corr-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: assocs help.markup help.syntax kernel sequences strings ; 4 | IN: rosalind.corr 5 | 6 | HELP: 1diff? 7 | { $values 8 | { "str1" string } { "str2" string } 9 | { "?" boolean } 10 | } 11 | { $description "Tests if the two strings are different at exactly one position." } ; 12 | 13 | HELP: corr 14 | { $values 15 | { "strs" sequence } 16 | { "corrections" assoc } 17 | } 18 | { $description "Solves the problem CORR on Rosalind: Some DNA strings are given. Some are correct ones appearing more than once, and the rest are mutated at exactly one position, appearing exactly once. Given that some DNA strings may appear as reverse complement, identify and correct the mutated DNA strings." } ; 19 | 20 | HELP: corr-main 21 | { $description "Solves the problem CORR on Rosalind, using a real dataset." } ; 22 | 23 | HELP: rcmp-pair 24 | { $values 25 | { "str" string } 26 | { "pair" sequence } 27 | } 28 | { $description "Given a DNA string, returns a 2-item sequence of itself and its reverse complement." } ; 29 | 30 | ARTICLE: "rosalind.corr" "rosalind.corr" 31 | { $vocab-link "rosalind.corr" } 32 | ; 33 | 34 | ABOUT: "rosalind.corr" 35 | -------------------------------------------------------------------------------- /aoc2015/day4/day4.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: checksums checksums.md5 io.encodings.utf8 io.files kernel 4 | math math.parser prettyprint sequences ; 5 | IN: aoc2015.day4 6 | 7 | : append-md5 ( str n -- value ) 8 | number>string append md5 checksum-bytes ; 9 | 10 | : 5-leading-zeros? ( bytes -- ? ) 11 | first3 [ 0 = ] [ 0 = ] [ 16 < ] tri* and and ; 12 | 13 | : day4-silver ( str -- n ) 14 | 1/0. [ append-md5 5-leading-zeros? ] with find-integer ; 15 | 16 | : append-md5' ( checksum-state n -- value ) 17 | [ clone ] dip number>string add-checksum-bytes get-checksum ; 18 | 19 | : day4-silver2 ( str -- n ) 20 | md5 initialize-checksum-state swap add-checksum-bytes 21 | 1/0. [ append-md5' 5-leading-zeros? ] with find-integer ; 22 | 23 | : 6-leading-zeros? ( bytes -- ? ) 24 | 3 head [ 0 = ] all? ; 25 | 26 | : day4-gold ( str -- n ) 27 | 1/0. [ append-md5 6-leading-zeros? ] with find-integer ; 28 | 29 | : day4-gold2 ( str -- n ) 30 | md5 initialize-checksum-state swap add-checksum-bytes 31 | 1/0. [ append-md5' 6-leading-zeros? ] with find-integer ; 32 | 33 | : day4-main ( -- ) "datasets/aoc2015/day4.txt" utf8 file-contents 34 | [ day4-silver2 . ] [ day4-gold2 . ] bi ; 35 | 36 | MAIN: day4-main -------------------------------------------------------------------------------- /aoc2020/day8/day8.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: arrays assocs combinators fry io.encodings.utf8 io.files 4 | kernel locals math math.parser prettyprint sequences splitting ; 5 | IN: aoc2020.day8 6 | 7 | :: run-cmd ( acc pc cmd -- acc pc ) 8 | cmd first2 :> n { 9 | { "nop" [ acc pc 1 + ] } 10 | { "acc" [ acc n + pc 1 + ] } 11 | { "jmp" [ acc pc n + ] } 12 | } case ; 13 | 14 | :: (run-until-loop) ( prgm acc pc hist -- ? acc ) 15 | pc prgm bounds-check? [ 16 | pc hist member? [ f acc ] [ 17 | prgm acc pc pc prgm nth run-cmd 18 | hist pc suffix (run-until-loop) 19 | ] if 20 | ] [ t acc ] if ; 21 | 22 | : run-until-loop ( prgm -- ? acc ) 0 0 { } (run-until-loop) ; 23 | 24 | : day8-silver ( prgm -- acc ) run-until-loop nip ; 25 | 26 | : swap-nth-instr ( prgm n -- prgm ) 27 | '[ _ = [ first2 [ { "nop" "acc" "jmp" } dup reverse zip at ] dip 2array ] when ] map-index ; 28 | 29 | :: day8-gold ( prgm -- acc ) 30 | prgm [ [ drop prgm ] dip swap-nth-instr run-until-loop and ] map-index sift first ; 31 | 32 | : day8-main ( -- ) "datasets/aoc2020/day8.txt" utf8 file-contents 33 | "\n" split [ " " split first2 dec> 2array ] map 34 | [ day8-silver . ] [ day8-gold . ] bi ; 35 | 36 | MAIN: day8-main -------------------------------------------------------------------------------- /rosalind/long/long-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel sequences strings ; 4 | IN: rosalind.long 5 | 6 | HELP: find-most-overlapping-pair 7 | { $values 8 | { "strs" sequence } 9 | { "strs'" sequence } 10 | } 11 | { $description "Given a set of strings, greedily select two strings that form the most overlap, and return a 3-item sequence containing the two strings and their join." } ; 12 | 13 | HELP: long 14 | { $values 15 | { "strs" sequence } 16 | { "str" string } 17 | } 18 | { $description "Solves the problem LONG on Rosalind: given a collection of DNA segments and the information that gluing together pairs of reads that overlap by more than half their length gives a unique string, find the unique string." } ; 19 | 20 | HELP: long-main 21 | { $description "Solves the problem LONG on Rosalind, using a real dataset." } ; 22 | 23 | HELP: overlap 24 | { $values 25 | { "str1" string } { "str2" string } 26 | { "str" string } 27 | } 28 | { $description "Overlaps two strings to form the shortest superstring, which contains str1 as its head and str2 as its tail." } ; 29 | 30 | ARTICLE: "rosalind.long" "rosalind.long" 31 | { $vocab-link "rosalind.long" } 32 | ; 33 | 34 | ABOUT: "rosalind.long" 35 | -------------------------------------------------------------------------------- /aoc2020/day23/day23.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: arrays grouping io.encodings.utf8 io.files kernel locals 4 | math math.ranges prettyprint sequences vectors ; 5 | IN: aoc2020.day23 6 | 7 | : 1turn ( seq -- seq' ) 8 | unclip [ 3 cut ] dip [ suffix ] keep ! 3head 3tail item 9 | [ 2dup swap member? ] [ 2 - 9 rem 1 + ] do until over index 10 | 1 + cut surround ; 11 | 12 | : day23-silver ( seq -- seq' ) 100 [ 1turn ] times ; 13 | 14 | : circ-array ( seq -- seq' ) 15 | [ [ ] map ] keep dup first suffix 2 clump 16 | [ first2 swap pick set-nth ] each ; 17 | 18 | : take-from ( circ n k -- seq ) 19 | [ over nth dup ] collector [ times ] dip 2nip ; 20 | 21 | :: 1turn' ( circ n -- circ n' ) 22 | circ n 3 take-from dup last circ nth n circ set-nth 23 | n [ 2dup swap member? ] [ 1 - 1000000 rem ] do while :> m 24 | dup last m circ nth swap circ set-nth first m circ set-nth 25 | circ n over nth ; 26 | 27 | : day23-gold ( seq -- n ) 28 | [ 1 - ] map 9 999999 [a,b] append [ circ-array ] [ first ] bi 29 | 10000000 [ 1turn' ] times drop 0 2 take-from [ 1 + ] map product ; 30 | 31 | : day23-main ( -- ) "datasets/aoc2020/day23.txt" utf8 file-contents >array [ 48 - ] map 32 | [ day23-silver . ] [ day23-gold . ] bi ; 33 | 34 | MAIN: day23-main -------------------------------------------------------------------------------- /aoc2015/day7/day7.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: arrays assocs combinators combinators.short-circuit 4 | hashtables io.encodings.utf8 io.files kernel locals math 5 | math.parser prettyprint sequences sequences.extras splitting 6 | strings ; 7 | IN: aoc2015.day7 8 | 9 | : day7-data ( -- assoc ) 10 | "datasets/aoc2015/day7.txt" utf8 file-contents "\n" split 11 | [ " -> " split-subseq first2 >string swap " " split 2array ] map ; 12 | 13 | DEFER: eval-expr 14 | :: num-or-var ( cached assoc num/var -- cached n ) 15 | cached num/var 16 | { [ dec> ] [ cached [ assoc swap eval-expr ] cache ] } 1|| ; 17 | 18 | : eval-expr ( cached assoc str -- cached n ) 19 | over at dup length { 20 | { 1 [ first num-or-var ] } 21 | { 2 [ last num-or-var 65535 bitxor ] } 22 | [ drop [ [ num-or-var ] with map first2 ] keep second { 23 | { "AND" [ bitand ] } 24 | { "OR" [ bitor ] } 25 | { "LSHIFT" [ shift ] } 26 | { "RSHIFT" [ neg shift ] } 27 | } case ] 28 | } case ; 29 | 30 | : day7-silver ( assoc -- n ) f >hashtable swap "a" eval-expr nip ; 31 | 32 | : day7-gold ( assoc -- n ) 33 | [ day7-silver 10 >base 1array ] [ "b" swap set-at ] [ day7-silver ] tri ; 34 | 35 | : day7-main ( -- ) 36 | day7-data [ day7-silver . ] [ day7-gold . ] bi ; 37 | 38 | MAIN: day7-main -------------------------------------------------------------------------------- /aoc2020/day9/day9-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel ; 4 | IN: aoc2020.day9 5 | 6 | HELP: day9-gold 7 | { $values 8 | { "data" "A sequence of integers" } { "pre" "Length of preamble" } 9 | { "ans" "The answer" } 10 | } 11 | { $description "Solves Day 9, Part 2 of AoC2020: find the contiguous subsequence of multiple numbers in the list that sum to the part 1 answer, and return the sum of the minimum and maximum values in the subsequence." } ; 12 | 13 | HELP: day9-gold-naive 14 | { $values 15 | { "data" "A sequence of integers" } { "pre" "Length of preamble" } 16 | { "ans" "The answer" } 17 | } 18 | { $description "Solves Day 9, Part 2 of AoC2020 using a naive algorithm." } ; 19 | 20 | HELP: day9-main 21 | { $description "Solves both parts of Day 9 of AoC2020, using a real dataset." } ; 22 | 23 | HELP: day9-silver 24 | { $values 25 | { "data" "A sequence of integers" } { "pre" "Length of preamble" } 26 | { "ans" "The answer" } 27 | } 28 | { $description "Solves Day 9, Part 1 of AoC2020: each number after the preamble (of size x) must be a sum of two distinct numbers out of x previous ones. Find the first number that violates this rule." } ; 29 | 30 | ARTICLE: "aoc2020.day9" "aoc2020.day9" 31 | { $vocab-link "aoc2020.day9" } 32 | ; 33 | 34 | ABOUT: "aoc2020.day9" 35 | -------------------------------------------------------------------------------- /aoc2020/day12/day12.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: arrays combinators fry io.encodings.utf8 io.files kernel 4 | math math.functions math.parser prettyprint sequences splitting 5 | ; 6 | IN: aoc2020.day12 7 | 8 | : run-command ( pos dir cmd -- pos' dir' ) 9 | first2 { 10 | { CHAR: N [ '[ _ i* + ] dip ] } 11 | { CHAR: S [ '[ _ -i* + ] dip ] } 12 | { CHAR: E [ '[ _ + ] dip ] } 13 | { CHAR: W [ '[ _ - ] dip ] } 14 | { CHAR: L [ 90 / [ i* ] times ] } 15 | { CHAR: R [ 90 / [ -i* ] times ] } 16 | { CHAR: F [ [ * + ] keepd ] } 17 | } case ; 18 | 19 | : run-command' ( pos waypoint cmd -- pos' waypoint' ) 20 | first2 { 21 | { CHAR: N [ i* + ] } 22 | { CHAR: S [ -i* + ] } 23 | { CHAR: E [ + ] } 24 | { CHAR: W [ - ] } 25 | { CHAR: L [ 90 / [ i* ] times ] } 26 | { CHAR: R [ 90 / [ -i* ] times ] } 27 | { CHAR: F [ [ * + ] keepd ] } 28 | } case ; 29 | 30 | : day12-silver ( cmds -- ans ) 31 | [ 0 1 ] dip [ run-command ] each drop 32 | >rect [ abs ] bi@ + ; 33 | 34 | : day12-gold ( cmds -- ans ) 35 | [ 0 C{ 10 1 } ] dip [ run-command' ] each drop 36 | >rect [ abs ] bi@ + ; 37 | 38 | : day12-main ( -- ) "datasets/aoc2020/day12.txt" utf8 file-contents 39 | "\n" split [ unclip [ dec> ] dip 2array ] map 40 | [ day12-silver . ] [ day12-gold . ] bi ; 41 | 42 | MAIN: day12-main -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 2-Clause License 2 | 3 | Copyright (c) 2020, Bubbler-4 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /aoc2020/day9/day9.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: fry grouping io.encodings.utf8 io.files kernel locals 4 | math math.combinatorics math.parser math.ranges math.statistics 5 | math.vectors prettyprint sequences sequences.extras splitting ; 6 | IN: aoc2020.day9 7 | 8 | : 2sums ( seq -- sums ) 2 [ sum ] map-combinations ; 9 | 10 | : day9-silver ( data pre -- ans ) 11 | 1 + clump [ unclip-last swap 2sums member? not ] find nip last ; 12 | 13 | : drop-large-tail ( data s -- data' ) 14 | [ reverse ] dip '[ _ >= ] drop-while reverse ; 15 | 16 | :: find-subseq-sum ( data s -- item ) 17 | data all-subseqs data length tail [ sum s = ] find nip ; 18 | 19 | :: day9-gold-naive ( data pre -- ans ) 20 | data pre day9-silver :> s 21 | data s drop-large-tail s find-subseq-sum minmax + ; 22 | 23 | : sum-accum ( data -- accum ) 0 [ + ] accumulate* 0 prefix ; 24 | 25 | : 2+ranges ( data -- ranges ) 26 | length [0,b) 2 [ { 0 1 } v+ ] map-combinations ; 27 | 28 | :: day9-gold ( data pre -- ans ) 29 | data pre day9-silver :> s data sum-accum :> cumul 30 | data 2+ranges [ cumul nths first2 s - = ] find nip 31 | first2 data minmax + ; 32 | 33 | : day9-main ( -- ) "datasets/aoc2020/day9.txt" utf8 file-contents "\n" split [ dec> ] map 34 | [ 25 day9-silver . ] [ 25 day9-gold-naive . ] [ 25 day9-gold . ] tri ; 35 | 36 | MAIN: day9-main -------------------------------------------------------------------------------- /aoc2020/day4/day4.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: assocs io.encodings.utf8 io.files kernel math.order 4 | math.parser prettyprint regexp sequences sets splitting ; 5 | IN: aoc2020.day4 6 | 7 | : day4-silver ( assocs -- count ) 8 | [ keys { "byr" "iyr" "eyr" "hgt" "hcl" "ecl" "pid" } swap subset? ] count ; 9 | 10 | : valid-byr? ( str -- ? ) dec> dup 0 ? 1920 2002 between? ; 11 | : valid-iyr? ( str -- ? ) dec> dup 0 ? 2010 2020 between? ; 12 | : valid-eyr? ( str -- ? ) dec> dup 0 ? 2020 2030 between? ; 13 | : valid-hgt? ( str -- ? ) 2 cut* [ dec> dup 0 ? ] dip "cm" = [ 150 193 ] [ 59 76 ] if between? ; 14 | : valid-hcl? ( str -- ? ) R/ #[0-9a-f]{6}/ matches? ; 15 | : valid-ecl? ( str -- ? ) { "amb" "blu" "brn" "gry" "grn" "hzl" "oth" } member? ; 16 | : valid-pid? ( str -- ? ) R/ \d{9}/ matches? ; 17 | 18 | : day4-gold ( assocs -- count ) 19 | [ keys { "byr" "iyr" "eyr" "hgt" "hcl" "ecl" "pid" } swap subset? ] filter 20 | [ { "byr" "iyr" "eyr" "hgt" "hcl" "ecl" "pid" } swap substitute 21 | { [ valid-byr? ] [ valid-iyr? ] [ valid-eyr? ] [ valid-hgt? ] [ valid-hcl? ] [ valid-ecl? ] [ valid-pid? ] } 22 | [ call( elt -- ? ) ] 2all? 23 | ] count ; 24 | 25 | : day4-main ( -- ) "datasets/aoc2020/day4.txt" utf8 file-contents 26 | "\n\n" split-subseq [ "\n " split [ ":" split ] map ] map 27 | [ day4-silver . ] [ day4-gold . ] bi ; 28 | 29 | MAIN: day4-main -------------------------------------------------------------------------------- /rosalind/kmer/kmer-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: assocs kernel multiline rosalind.common rosalind.kmer 4 | sequences tools.test ; 5 | IN: rosalind.kmer.tests 6 | 7 | STRING: example 8 | >Rosalind_6431 9 | CTTCGAAAGTTTGGGCCGAGTCTTACAGTCGGTCTTGAAGCAAAGTAACGAACTCCACGG 10 | CCCTGACTACCGAACCAGTTGTGAGTACTCAACTGGGTGAGAGTGCAGTCCCTATTGAGT 11 | TTCCGAGACTCACCGGGATTTTCGATCCAGCCTCAGTCCAGTCTTGTGGCCAACTCACCA 12 | AATGACGTTGGAATATCCCTGTCTAGCTCACGCAGTACTTAGTAAGAGGTCGCTGCAGCG 13 | GGGCAAGGAGATCGGAAAATGTGCTCTATATGCGACTAAAGCTCCTAACTTACACGTAGA 14 | CTTGCCCGTGTTAAAAACTCGGCTCACATGCTGTCTGCGGCTGGCTGTATACAGTATCTA 15 | CCTAATACCCTTCAGTTCGCCGCACAAAAGCTGGGAGTTACCGCGGAAATCACAG 16 | ; 17 | CONSTANT: expected { 18 | 4 1 4 3 0 1 1 5 1 3 1 2 2 1 2 0 1 1 3 1 2 1 3 1 1 1 1 2 2 5 1 3 19 | 0 2 2 1 1 1 1 3 1 0 0 1 5 5 1 5 0 2 0 2 1 2 1 1 1 2 0 1 0 0 1 1 20 | 3 2 1 0 3 2 3 0 0 2 0 8 0 0 1 0 2 1 3 0 0 0 1 4 3 2 1 1 3 1 2 1 21 | 3 1 2 1 2 1 1 1 2 3 2 1 1 0 1 1 3 2 1 2 6 2 1 1 1 2 3 3 3 2 3 0 22 | 3 2 1 1 0 0 1 4 3 0 1 5 0 2 0 1 2 1 3 0 1 2 2 1 1 0 3 0 0 4 5 0 23 | 3 0 2 1 1 3 0 3 2 2 1 1 0 2 1 0 2 2 1 2 0 2 2 5 2 2 1 1 2 1 2 2 24 | 2 2 1 1 3 4 0 2 1 1 0 1 2 2 1 1 1 5 2 0 3 2 1 1 2 2 3 0 3 0 1 3 25 | 1 2 3 0 2 1 2 2 1 2 3 0 1 2 3 1 1 3 1 0 1 1 3 0 2 1 2 2 0 2 1 1 } 26 | : preprocessed ( -- str ) example fasta>assoc values first ; 27 | 28 | { t } [ preprocessed kmer expected = ] unit-test 29 | -------------------------------------------------------------------------------- /rosalind/common/common.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: arrays assocs grouping kernel math sequences splitting sequences.extras ; 4 | IN: rosalind.common 5 | 6 | : fasta>assoc ( str -- assoc ) 7 | ">" split [ "\n" split harvest ] map harvest 8 | [ [ first ] [ rest concat ] bi 2array ] map ; 9 | 10 | CONSTANT: amino-table "FFLLSSSSYY..CC.WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG" 11 | 12 | : rna3>amino ( rna3 -- amino ) 13 | [ "UCAG" index ] map 0 [ swap 4 * + ] reduce 14 | amino-table nth ; 15 | 16 | : rna>protein ( rna -- protein ) 17 | dup 3 head "AUG" = 18 | [ 3 group [ rna3>amino ] "" map-as 19 | "." split ?first2 swap f ? 20 | ] [ drop f ] if ; 21 | 22 | : reverse-complement ( dna -- dna' ) 23 | "ACGT" "TGCA" zip substitute reverse ; 24 | 25 | CONSTANT: protein-mass-table H{ 26 | { CHAR: A 71.03711 } 27 | { CHAR: C 103.00919 } 28 | { CHAR: D 115.02694 } 29 | { CHAR: E 129.04259 } 30 | { CHAR: F 147.06841 } 31 | { CHAR: G 57.02146 } 32 | { CHAR: H 137.05891 } 33 | { CHAR: I 113.08406 } 34 | { CHAR: K 128.09496 } 35 | { CHAR: L 113.08406 } 36 | { CHAR: M 131.04049 } 37 | { CHAR: N 114.04293 } 38 | { CHAR: P 97.05276 } 39 | { CHAR: Q 128.05858 } 40 | { CHAR: R 156.10111 } 41 | { CHAR: S 87.03203 } 42 | { CHAR: T 101.04768 } 43 | { CHAR: V 99.06841 } 44 | { CHAR: W 186.07931 } 45 | { CHAR: Y 163.06333 } 46 | } -------------------------------------------------------------------------------- /aoc2020/day10/day10-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel sequences ; 4 | IN: aoc2020.day10 5 | 6 | HELP: day10-gold 7 | { $values 8 | { "seq" sequence } 9 | { "n" "An integer" } 10 | } 11 | { $description "Solves Day 10, Part 2 of AoC2020: count the number of ways you can connect your device to the ground by using some or all of the adapters given." } ; 12 | 13 | HELP: day10-main 14 | { $description "Solves both parts of Day 10 of AoC2020, using a real dataset." } ; 15 | 16 | HELP: day10-silver 17 | { $values 18 | { "seq" sequence } 19 | { "n" "An integer" } 20 | } 21 | { $description "Solves Day 10, Part 1 of AoC2020: a collection of adapter output joltages are given, and you need to connect from ground (0) to your own device (which has the joltage of maximum given + 3). A device of output joltage x can be connected to input joltage of x-3 to x inclusive. If you use all the given adapters, count the 1-jolt and 3-jolt differences between connections (including ground and your device), and multiply the two values." } ; 22 | 23 | HELP: sort+minmax 24 | { $values 25 | { "seq" sequence } 26 | { "seq'" sequence } 27 | } 28 | { $description "Sorts the sequence and adds a 0 and maximum+3 to the sequence." } ; 29 | 30 | ARTICLE: "aoc2020.day10" "aoc2020.day10" 31 | { $vocab-link "aoc2020.day10" } 32 | ; 33 | 34 | ABOUT: "aoc2020.day10" 35 | -------------------------------------------------------------------------------- /aoc2015/day2/day2-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel math sequences strings ; 4 | IN: aoc2015.day2 5 | 6 | HELP: day2-gold 7 | { $values 8 | { "seq" sequence } 9 | { "n" integer } 10 | } 11 | { $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." } ; 12 | 13 | HELP: day2-main 14 | { $description "Solves both parts of Day 2 of AoC2015, using a real dataset." } ; 15 | 16 | HELP: day2-silver 17 | { $values 18 | { "seq" sequence } 19 | { "n" integer } 20 | } 21 | { $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." } ; 22 | 23 | HELP: ribbon 24 | { $values 25 | { "seq" sequence } 26 | { "n" integer } 27 | } 28 | { $description "Given the three dimensions of a box, computes the length of the ribbon (smallest perimeter of a face + volume of the box)." } ; 29 | 30 | HELP: wrapping-paper 31 | { $values 32 | { "seq" sequence } 33 | { "n" integer } 34 | } 35 | { $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)." } ; 36 | 37 | ARTICLE: "aoc2015.day2" "aoc2015.day2" 38 | { $vocab-link "aoc2015.day2" } 39 | ; 40 | 41 | ABOUT: "aoc2015.day2" 42 | -------------------------------------------------------------------------------- /aoc2015/day9/day9-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: assocs help.markup help.syntax kernel math sequences ; 4 | IN: aoc2015.day9 5 | 6 | HELP: all-path-lengths 7 | { $values 8 | { "distances" assoc } 9 | { "path-lengths" sequence } 10 | } 11 | { $description "Given the distances between pairs of cities, computes the path lengths for all possible paths." } ; 12 | 13 | HELP: day9-data 14 | { $values 15 | { "data" "an alist" } 16 | } 17 | { $description "Takes the input data and produces an alist, where the keys are pairs of cities and the values are their distances." } ; 18 | 19 | HELP: day9-gold 20 | { $values 21 | { "distances" assoc } 22 | { "n" integer } 23 | } 24 | { $description "Solves Day 9, Part 2 of AoC2015: Find the length of the longest route going through all the cities." } ; 25 | 26 | HELP: day9-main 27 | { $description "Solves both parts of Day 9 of AoC2015, using a real dataset." } ; 28 | 29 | HELP: day9-silver 30 | { $values 31 | { "distances" assoc } 32 | { "n" integer } 33 | } 34 | { $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." } ; 35 | 36 | ARTICLE: "aoc2015.day9" "aoc2015.day9" 37 | { $vocab-link "aoc2015.day9" } 38 | ; 39 | 40 | ABOUT: "aoc2015.day9" 41 | -------------------------------------------------------------------------------- /aoc2020/day14/day14.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: arrays assocs combinators fry io.encodings.utf8 io.files 4 | kernel math.parser prettyprint regexp sequences splitting 5 | strings ; 6 | IN: aoc2020.day14 7 | 8 | : bitmask ( bit mask -- bit' ) 9 | dup CHAR: X = -rot ? ; 10 | 11 | : execute-line ( hash mask str -- hash mask' ) 12 | " = " split-subseq [ >string ] map first2 over "mask" = 13 | [ 2nip ] 14 | [ [ >string R/ \d+/ first-match dec> ] [ dec> >bin 36 48 pad-head ] bi* 15 | pick [ bitmask ] 2map swap reach set-at 16 | ] if ; 17 | 18 | : day14-silver ( lines -- ans ) 19 | [ H{ } "" ] dip [ execute-line ] each 20 | drop values [ bin> ] map sum ; 21 | 22 | : bitmask' ( bits masks -- bits' ) 23 | { "" } [ 24 | { { CHAR: 0 [ 1string 1array ] } 25 | { CHAR: 1 [ drop { "1" } ] } 26 | [ 2drop { "0" "1" } ] 27 | } case [ append ] cartesian-map concat ] 2reduce ; 28 | 29 | : execute-line' ( hash mask str -- hash mask' ) 30 | " = " split-subseq [ >string ] map first2 over "mask" = 31 | [ 2nip ] 32 | [ [ >string R/ \d+/ first-match dec> >bin 36 48 pad-head ] [ dec> ] bi* 33 | [ over bitmask' ] dip reach '[ _ swap _ set-at ] each 34 | ] if ; 35 | 36 | : day14-gold ( lines -- ans ) 37 | [ H{ } "" ] dip [ execute-line' ] each 38 | drop values sum ; 39 | 40 | : day14-main ( -- ) "datasets/aoc2020/day14.txt" utf8 file-contents "\n" split 41 | [ day14-silver . ] [ day14-gold . ] bi ; 42 | 43 | MAIN: day14-main -------------------------------------------------------------------------------- /rosalind/seto/seto-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel math sequences strings ; 4 | IN: rosalind.seto 5 | 6 | HELP: 2set-ops 7 | { $values 8 | { "set1" sequence } { "set2" sequence } 9 | { "sets" sequence } 10 | } 11 | { $description "Computes set union, set intersection, and forward and backward set differences of the given two sets." } ; 12 | 13 | HELP: parse-set 14 | { $values 15 | { "str" string } 16 | { "seq" sequence } 17 | } 18 | { $description "Parses a string as a sequence of integers." } ; 19 | 20 | HELP: print-set 21 | { $values 22 | { "seq" sequence } 23 | } 24 | { $description "Prints a sequence in the form of a set." } ; 25 | 26 | HELP: set-complements 27 | { $values 28 | { "n" integer } { "set1" sequence } { "set2" sequence } 29 | { "sets" sequence } 30 | } 31 | { $description "Computes set complements of two sets, where the universe is defined as the integers from 1 to n inclusive." } ; 32 | 33 | HELP: seto 34 | { $values 35 | { "n" integer } { "set1" sequence } { "set2" sequence } 36 | { "sets" sequence } 37 | } 38 | { $description "Solves the problem SETO on Rosalind: Perform six set operations on the given two sets and the universe." } ; 39 | 40 | HELP: seto-main 41 | { $description "Solves the problem SETO on Rosalind, using a real dataset." } ; 42 | 43 | ARTICLE: "rosalind.seto" "rosalind.seto" 44 | { $vocab-link "rosalind.seto" } 45 | ; 46 | 47 | ABOUT: "rosalind.seto" 48 | -------------------------------------------------------------------------------- /aoc2020/day3/day3-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel ; 4 | IN: aoc2020.day3 5 | 6 | HELP: day3-gold 7 | { $values 8 | { "lines" "A sequence of strings, representing the grid" } 9 | { "count" "The answer" } 10 | } 11 | { $description "Solves Day 3, Part 2 of AoC2020: given a grid which repeats infinitely to the right, start at top left corner, moving in the slope 1, 3, 5, 7, and 1/2, and count the hashes you will step over. Return their product." } ; 12 | 13 | HELP: day3-main 14 | { $description "Solves both parts of Day 3 of AoC2020, using a real dataset." } ; 15 | 16 | HELP: day3-silver 17 | { $values 18 | { "lines" "A sequence of strings, representing the grid" } 19 | { "count" "The answer" } 20 | } 21 | { $description "Solves Day 3, Part 1 of AoC2020: given a grid which repeats infinitely to the right, start at top left corner, moving 3 units east and 1 unit south, and count the hashes you will step over." } ; 22 | 23 | HELP: trees-on-slope 24 | { $values 25 | { "lines" "A sequence of strings, representing the grid" } { "slope" "The slope of movement east/south" } 26 | { "count" "Count of hashes stepped over" } 27 | } 28 | { $description "Given a grid which repeats infinitely to the right, start at the top left corner, moving units east and units south, and count the hashes stepped over." } ; 29 | 30 | ARTICLE: "aoc2020.day3" "aoc2020.day3" 31 | { $vocab-link "aoc2020.day3" } 32 | ; 33 | 34 | ABOUT: "aoc2020.day3" 35 | -------------------------------------------------------------------------------- /rosalind/iprb/iprb-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel ; 4 | IN: rosalind.iprb 5 | 6 | HELP: iprb 7 | { $values 8 | { "k" "The number of organisms with two copies of dominant gene" } 9 | { "m" "The number of organisms with single copy of dominant gene" } 10 | { "n" "The number of organisms with no copies of dominant gene" } 11 | { "prob" "The probability that an offspring has dominant phenotype" } 12 | } 13 | { $description "Solves the problem IPRB on Rosalind: suppose that k organisms have double dominant gene, m have single dominant gene, and n have double recessive gene. If two organisms are uniformly randomly selected to mate, output the chance that the offspring has dominant phenotype." { $nl "" } 14 | "If we consider all possible ordered pairs of genes, " { $snippet "2(k+m+n) * 2(k+m+n-1)" } " pairs are possible. To simplify a bit, we count the cases where the offspring has recessive phenotype and take the complement. If the first pick is from \"single dominant\" group, there are " { $snippet "m * (m-1 + 2*n)" } " cases. If the first pick is from \"double recessive\" group, there are " { $snippet "2n * (2n-2 + m)" } " cases. The sum of two cases can be simplified to " { $snippet "(m+2n)^2 - m - 4n" } "." } ; 15 | 16 | HELP: iprb-main 17 | { $description "Solves the problem IPRB on Rosalind, using a real dataset." } ; 18 | 19 | ARTICLE: "rosalind.iprb" "rosalind.iprb" 20 | { $vocab-link "rosalind.iprb" } 21 | ; 22 | 23 | ABOUT: "rosalind.iprb" 24 | -------------------------------------------------------------------------------- /rosalind/cat/cat-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel math sequences strings ; 4 | IN: rosalind.cat 5 | 6 | HELP: (noncrossing-matches) 7 | { $values 8 | { "seq" sequence } 9 | { "n" integer } 10 | } 11 | { $description "Handles the recursive case of " { $snippet "noncrossing-matches" } ". Extracts the first item of the sequence, splits the rest at the opposite base, and calculates the sum of products of non-crossing matches of each half." } ; 12 | 13 | HELP: cat 14 | { $values 15 | { "str" string } 16 | { "n" integer } 17 | } 18 | { $description "Solves the problem CAT on Rosalind: Given an RNA string, count non-crossing perfect matchings of base pairs modulo 1000000." } ; 19 | 20 | HELP: cat-main 21 | { $description "Solves the problem CAT on Rosalind, using a real dataset." } ; 22 | 23 | HELP: noncrossing-matches 24 | { $values 25 | { "seq" sequence } 26 | { "n" integer } 27 | } 28 | { $description "The main memoized routine for counting the non-crossing perfect matchings. The expected elements are one of 1, i, -1, or -i, so that each base pair sums to 0." } ; 29 | 30 | HELP: unbalanced? 31 | { $values 32 | { "seq" sequence } 33 | { "?" boolean } 34 | } 35 | { $description "Tests if the given string is unbalanced, which means that the number of perfect matchings (and therefore the number of non-crossing perfect matchings) is zero." } ; 36 | 37 | ARTICLE: "rosalind.cat" "rosalind.cat" 38 | { $vocab-link "rosalind.cat" } 39 | ; 40 | 41 | ABOUT: "rosalind.cat" 42 | -------------------------------------------------------------------------------- /aoc2020/day16/day16.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: arrays assocs fry grouping grouping.extras 4 | io.encodings.utf8 io.files kernel locals math math.parser 5 | math.ranges multiline prettyprint regexp sequences 6 | sequences.extras sets sorting splitting strings ; 7 | IN: aoc2020.day16 8 | 9 | : all-numbers ( obj -- seq ) 10 | >string R/ \d+/ all-matching-subseqs [ dec> ] map ; 11 | 12 | : day16-preprocess ( str -- ranges mine others ) 13 | "\n\n" split-subseq [ all-numbers ] map first3 [ 2 group ] 2dip ; 14 | 15 | : day16-silver ( ranges mine others -- ans ) 16 | nip swap [ first2 [a,b] ] map combine without sum ; 17 | 18 | : 2ranges ( ranges -- 2ranges ) 19 | [ first2 [a,b] ] map 2 group [ combine ] map ; 20 | 21 | : filtered-columns ( 2ranges mine others -- columns ) 22 | prepend over length group swap combine '[ _ subset? ] filter flip ; 23 | 24 | : sort-by-inserted-value ( assoc -- keys ) 25 | [ second length ] sort-with 26 | unzip { { } } prefix [ swap diff first ] 2clump-map zip 27 | sort-values keys ; 28 | 29 | : fitting-ranges ( 2ranges column -- indices ) 30 | '[ _ swap subset? ] find-all keys ; 31 | 32 | :: day16-gold ( ranges mine others -- ans ) 33 | ranges 2ranges :> 2ranges 34 | 2ranges mine others filtered-columns :> columns 35 | mine columns [ 2ranges swap fitting-ranges ] map zip 36 | sort-by-inserted-value 6 head product ; 37 | 38 | : day16-main ( -- ) "datasets/aoc2020/day16.txt" utf8 file-contents day16-preprocess 39 | [ day16-silver . ] [ day16-gold . ] 3bi ; 40 | 41 | MAIN: day16-main -------------------------------------------------------------------------------- /aoc2020/day22/day22.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: arrays hash-sets io.encodings.utf8 io.files kernel locals 4 | math math.parser math.ranges math.vectors prettyprint sequences 5 | sequences.extras sets sorting splitting ; 6 | IN: aoc2020.day22 7 | 8 | : 1turn ( deck1 deck2 -- deck1' deck2' ) 9 | [ unclip ] bi@ swapd 2dup < [ 2array natural-sort reverse { } ] dip [ swap ] when 10 | swapd [ append ] 2bi@ ; 11 | 12 | : day22-silver ( decks -- n ) first2 2dup shorter [ drop 1turn 2dup shorter ] until-empty longer 13 | dup length [1,b] reverse v. ; 14 | 15 | :: 1turn' ( history deck1 deck2 -- history deck1' deck2' ) 16 | deck1 deck2 2array history in? [ history deck1 { } ] [ 17 | deck1 deck2 2array history adjoin 18 | history deck1 deck2 1turn 19 | ] if ; 20 | 21 | : 1game ( deck1 deck2 -- deck1' deck2' ) 22 | [ { } >hash-set ] 2dip 2dup shorter [ drop 23 | 2dup [ [ first ] [ length ] bi < ] both? [ 24 | [ unclip 2dup head 3array ] bi@ 2array flip first3 ! decks cards newdecks 25 | first2 1game nip empty? 26 | [ [ first2 ] dip swap [ append ] dip ] [ [ first2 ] dip reverse append ] if ! p1 wins / p2 wins 27 | ] [ 1turn' ] if 28 | 2dup shorter 29 | ] until-empty nipd ; 30 | 31 | : day22-gold ( decks -- n ) first2 1game longer 32 | dup length [1,b] reverse v. ; 33 | 34 | : day22-main ( -- ) "datasets/aoc2020/day22.txt" utf8 file-contents "\n\n" split-subseq 35 | [ "\n" split rest [ dec> ] map ] map 36 | [ day22-silver . ] 37 | ! [ drop ] 38 | [ day22-gold . ] 39 | bi ; 40 | 41 | MAIN: day22-main -------------------------------------------------------------------------------- /aoc2020/day4/day4-tests.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: aoc2020.day4 multiline sequences splitting tools.test ; 4 | IN: aoc2020.day4.tests 5 | 6 | STRING: example1 7 | ecl:gry pid:860033327 eyr:2020 hcl:#fffffd 8 | byr:1937 iyr:2017 cid:147 hgt:183cm 9 | 10 | iyr:2013 ecl:amb cid:350 eyr:2023 pid:028048884 11 | hcl:#cfa07d byr:1929 12 | 13 | hcl:#ae17e1 iyr:2013 14 | eyr:2024 15 | ecl:brn pid:760753108 byr:1931 16 | hgt:179cm 17 | 18 | hcl:#cfa07d eyr:2025 pid:166559648 19 | iyr:2011 ecl:brn hgt:59in 20 | ; 21 | 22 | STRING: example2 23 | eyr:1972 cid:100 24 | hcl:#18171d ecl:amb hgt:170 pid:186cm iyr:2018 byr:1926 25 | 26 | iyr:2019 27 | hcl:#602927 eyr:1967 hgt:170cm 28 | ecl:grn pid:012533040 byr:1946 29 | 30 | hcl:dab227 iyr:2012 31 | ecl:brn hgt:182cm pid:021572410 eyr:2020 byr:1992 cid:277 32 | 33 | hgt:59cm ecl:zzz 34 | eyr:2038 hcl:74454a iyr:2023 35 | pid:3556412378 byr:2007 36 | ; 37 | 38 | STRING: example3 39 | pid:087499704 hgt:74in ecl:grn iyr:2012 eyr:2030 byr:1980 40 | hcl:#623a2f 41 | 42 | eyr:2029 ecl:blu cid:129 byr:1989 43 | iyr:2014 pid:896056539 hcl:#a97842 hgt:165cm 44 | 45 | hcl:#888785 46 | hgt:164cm byr:2001 iyr:2015 cid:88 47 | pid:545766238 ecl:hzl 48 | eyr:2022 49 | 50 | iyr:2010 hgt:158cm hcl:#b6652a ecl:blu byr:1944 eyr:2021 pid:093154719 51 | ; 52 | 53 | : pre-process ( str -- assocs ) 54 | "\n\n" split-subseq [ "\n " split [ ":" split ] map ] map ; 55 | 56 | { 2 } [ example1 pre-process day4-silver ] unit-test 57 | { 0 } [ example2 pre-process day4-gold ] unit-test 58 | { 4 } [ example3 pre-process day4-gold ] unit-test 59 | -------------------------------------------------------------------------------- /aoc2020/day18/day18.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: combinators eval io.encodings.utf8 io.files kernel math 4 | math.parser multiline peg.ebnf prettyprint regexp sequences 5 | sequences.extras sets splitting ; 6 | IN: aoc2020.day18 7 | 8 | : eval-expr ( str -- n ) 9 | " " without R/ [+*]\d/ [ reverse ] re-replace-with 10 | 10 [ 10 [ R/ [+*]\([^\(\)]+\)/ [ 2 cut [ but-last ] bi@ prepend ] re-replace-with ] times 11 | R/ \([^\(\)]+\)/ [ rest but-last ] re-replace-with ] times 12 | 32 interleaved eval( -- n ) ; 13 | 14 | EBNF: eval-expr2 [=[ 15 | num = [0-9]+ => [[ dec> ]] 16 | term = "(" expr ")" => [[ second ]] | num 17 | expr = expr " + " term => [[ first3 nip + ]] | expr " * " term => [[ first3 nip * ]] | term 18 | ]=] 19 | 20 | : day18-silver ( strs -- sum ) 21 | [ eval-expr2 ] map sum ; 22 | 23 | : eval-expr' ( str -- n ) "(" ")" surround 24 | [ [ [ R/ \d+( \+ \d+)+/ [ " + " split-subseq [ dec> ] map sum 10 >base ] re-replace-with ] to-fixed-point 25 | R/ (?<=\()\d+( \* \d+)+(?=\))/ [ " * " split-subseq [ dec> ] map product 10 >base ] re-replace-with ] to-fixed-point 26 | R/ \(\d+\)/ [ rest but-last ] re-replace-with ] to-fixed-point dec> ; 27 | 28 | EBNF: eval-expr2' [=[ 29 | num = [0-9]+ => [[ dec> ]] 30 | term = "(" expr ")" => [[ second ]] | num 31 | sum = sum " + " term => [[ first3 nip + ]] | term 32 | expr = expr " * " sum => [[ first3 nip * ]] | sum 33 | ]=] 34 | 35 | : day18-gold ( strs -- sum ) [ eval-expr2' ] map sum ; 36 | 37 | : day18-main ( -- ) "datasets/aoc2020/day18.txt" utf8 file-contents "\n" split 38 | [ day18-silver . ] [ day18-gold . ] bi ; 39 | 40 | MAIN: day18-main -------------------------------------------------------------------------------- /aoc2015/day7/day7-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: assocs help.markup help.syntax kernel math strings ; 4 | IN: aoc2015.day7 5 | 6 | HELP: day7-data 7 | { $values 8 | { "assoc" assoc } 9 | } 10 | { $description "Preprocesses the input as an assoc from a variable name to a tokenized expression." } ; 11 | 12 | HELP: day7-gold 13 | { $values 14 | { "assoc" assoc } 15 | { "n" integer } 16 | } 17 | { $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" } "." } ; 18 | 19 | HELP: day7-main 20 | { $description "Solves both parts of Day 7 of AoC2015, using a real dataset." } ; 21 | 22 | HELP: day7-silver 23 | { $values 24 | { "assoc" assoc } 25 | { "n" integer } 26 | } 27 | { $description "Solves Day 7, Part 1 of AoC2015: Given a collection of expressions, find the value of " { $snippet "a" } "." } ; 28 | 29 | HELP: eval-expr 30 | { $values 31 | { "cached" assoc } { "assoc" assoc } { "str" string } 32 | { "n" integer } 33 | } 34 | { $description "Evaluates the given variable." } ; 35 | 36 | HELP: num-or-var 37 | { $values 38 | { "cached" assoc } { "assoc" assoc } { "num/var" string } 39 | { "n" integer } 40 | } 41 | { $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." } ; 42 | 43 | ARTICLE: "aoc2015.day7" "aoc2015.day7" 44 | { $vocab-link "aoc2015.day7" } 45 | ; 46 | 47 | ABOUT: "aoc2015.day7" 48 | -------------------------------------------------------------------------------- /aoc2020/day2/day2-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel ; 4 | IN: aoc2020.day2 5 | 6 | HELP: day2-gold 7 | { $values 8 | { "specs" "A sequence of password specs" } 9 | { "count" "The answer" } 10 | } 11 | { $description "Solves Day 2, Part 2 of AoC2020: given some password specs, count the ones which are valid under the second rule." } ; 12 | 13 | HELP: day2-main 14 | { $description "Solves both parts of Day 2 of AoC2020, using a real dataset." } ; 15 | 16 | HELP: day2-silver 17 | { $values 18 | { "specs" "A sequence of password specs" } 19 | { "count" "The answer" } 20 | } 21 | { $description "Solves Day 2, Part 1 of AoC2020: given some password specs, count the ones which are valid under the first rule." } ; 22 | 23 | HELP: password-valid? 24 | { $values 25 | { "spec" "A string in the format of \"1-2 a: abcde\"" } 26 | { "?" boolean } 27 | } 28 | { $description "Checks if contains the between and times." } ; 29 | 30 | HELP: password-valid?' 31 | { $values 32 | { "spec" "A string in the format of \"1-2 a: abcde\"" } 33 | { "?" boolean } 34 | } 35 | { $description "Checks if exactly one of the positions and in equals the ." } ; 36 | 37 | HELP: spec> 38 | { $values 39 | { "spec" "A string in the format of \"1-2 a: abcde\"" } 40 | { "range" "A 2-item array of integers" } { "char" "A character" } { "passwd" "A string" } 41 | } 42 | { $description "Takes a string in specific format and returns the three parts of it." } ; 43 | 44 | ARTICLE: "aoc2020.day2" "aoc2020.day2" 45 | { $vocab-link "aoc2020.day2" } 46 | ; 47 | 48 | ABOUT: "aoc2020.day2" 49 | -------------------------------------------------------------------------------- /aoc2020/day12/day12-docs.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: help.markup help.syntax kernel ; 4 | IN: aoc2020.day12 5 | 6 | HELP: day12-gold 7 | { $values 8 | { "cmds" "A sequence of commands" } 9 | { "ans" "An integer" } 10 | } 11 | { $description "Solves Day 12, Part 2 of AoC2020: given the commands, compute the Manhattan distance from the origin to the ship's final position." } ; 12 | 13 | HELP: day12-main 14 | { $description "Solves both parts of Day 12 of AoC2020, using a real dataset." } ; 15 | 16 | HELP: day12-silver 17 | { $values 18 | { "cmds" "A sequence of commands" } 19 | { "ans" "An integer" } 20 | } 21 | { $description "Solves Day 12, Part 1 of AoC2020: given the commands, compute the Manhattan distance from the origin to the ship's final position." } ; 22 | 23 | HELP: run-command 24 | { $values 25 | { "pos" "A complex number" } { "dir" "A complex number" } { "cmd" "A command" } 26 | { "pos'" "A complex number" } { "dir'" "A complex number" } 27 | } 28 | { $description "Runs the given command: N, S, E, W moves the ship in that direction, L and R rotates the ship, and F moves the ship in the direction it is facing." } ; 29 | 30 | HELP: run-command' 31 | { $values 32 | { "pos" "A complex number" } { "waypoint" "A complex number" } { "cmd" "A command" } 33 | { "pos'" "A complex number" } { "waypoint'" "A complex number" } 34 | } 35 | { $description "Runs the given command: N, S, E, W moves the waypoint in that direction, L and R rotates the waypoint around the ship, and F moves the ship towards the waypoint." } ; 36 | 37 | ARTICLE: "aoc2020.day12" "aoc2020.day12" 38 | { $vocab-link "aoc2020.day12" } 39 | ; 40 | 41 | ABOUT: "aoc2020.day12" 42 | -------------------------------------------------------------------------------- /datasets/rosalind/spec.txt: -------------------------------------------------------------------------------- 1 | 2836.71542462 2 | 2950.75835462 3 | 3037.79038462 4 | 3108.82749462 5 | 3236.92245462 6 | 3333.97521462 7 | 3421.00724462 8 | 3535.05017462 9 | 3636.09785462 10 | 3733.15061462 11 | 3862.19320462 12 | 3977.22014462 13 | 4133.32125462 14 | 4246.40531462 15 | 4374.46389462 16 | 4431.48535462 17 | 4546.51229462 18 | 4732.59160462 19 | 4819.62363462 20 | 4906.65566462 21 | 5003.70842462 22 | 5117.75135462 23 | 5303.83066462 24 | 5466.89399462 25 | 5553.92602462 26 | 5690.98493462 27 | 5838.05334462 28 | 5951.13740462 29 | 6098.20581462 30 | 6155.22727462 31 | 6212.24873462 32 | 6343.28922462 33 | 6440.34198462 34 | 6596.44309462 35 | 6724.53805462 36 | 6827.54724462 37 | 6958.58773462 38 | 7057.65614462 39 | 7160.66533462 40 | 7275.69227462 41 | 7374.76068462 42 | 7503.80327462 43 | 7632.84586462 44 | 7733.89354462 45 | 7880.96195462 46 | 7980.03036462 47 | 8051.06747462 48 | 8188.12638462 49 | 8287.19479462 50 | 8450.25812462 51 | 8563.34218462 52 | 8749.42149462 53 | 8935.50080462 54 | 9032.55356462 55 | 9218.63287462 56 | 9332.67580462 57 | 9495.73913462 58 | 9608.82319462 59 | 9737.86578462 60 | 9794.88724462 61 | 9941.95565462 62 | 9998.97711462 63 | 10185.0564246 64 | 10314.0990146 65 | 10415.1466946 66 | 10472.1681546 67 | 10585.2522146 68 | 10698.3362746 69 | 10861.3996046 70 | 11008.4680146 71 | 11171.5313446 72 | 11357.6106546 73 | 11414.6321146 74 | 11577.6954446 75 | 11691.7383746 76 | 11828.7972846 77 | 11943.8242246 78 | 12090.8926346 79 | 12253.9559646 80 | 12440.0352746 81 | 12553.1193346 82 | 12640.1513646 83 | 12754.1942946 84 | 12917.2576246 85 | 13103.3369346 86 | 13240.3958446 87 | 13327.4278746 88 | 13398.4649846 89 | 13485.4970146 90 | 13572.5290446 91 | 13728.6301546 92 | 13884.7312646 93 | 13941.7527246 94 | 14028.7847546 -------------------------------------------------------------------------------- /datasets/rosalind/splc.txt: -------------------------------------------------------------------------------- 1 | >Rosalind_3050 2 | ATGCGTAGGTTAAGCTCGCGCATTCCGGCGATACCTCTGTAGTGCAACACACACCGACAA 3 | TATTTGACATAGAACGGCGCCTAGTGCTCCATCCGGCGATTAACTTCCGGTTGGACAATA 4 | TTCGCAGTTCTGTAATCGCCAATCTTCAAGCTATCTTAGTCAATCTCGACTCGTAGTCCC 5 | TCCAAAGTGTACGTTGTAACCGAACGTAACTAGTGGCGCAACGAATGTTAACGCCGTACT 6 | CCGCCCTATTCCGACCCAAGCCTAGCTGGAACAGAGACCCATGGAGAGTCAAGATGTCTT 7 | ATCGTAAGTTCTACTCGAAAGGCTTGAGGGCAAGATGTACCCGGTATGTGGAAACCTGAA 8 | TATTCGGCAGCTGCCACTCACAATATACGAAGCTCCTGCAGTCCTCTGAGGACCGACTCA 9 | GCCACGGCACGAACACTGTGTTTGGGAACCGGCATATTTGCCAGACTTGTTCACGCTCTA 10 | CTGTTATGTACTTTCGGATCTTGGGCTAAGATGTGATCAAAGTTGCTACGCCAGCTAGAC 11 | CAAGAAGCTTTGTGACTAGCCCGGACTTGCGCTTCGCTTAGTCAACGATCATGTACTCTG 12 | CGTCCGCCAGGTTTAAGCAGTCTACAGCTGAGTAAAAGGGGAGAGTGTGGGCGAGTCAGG 13 | TCGGGGAGCACTTTTGAAGTCTCCTTGGTCACCTCATCACACCGCTTCTATATTAACCCA 14 | CCGAACTACCCATTACATTCTTCATCGGGAGGCGCAGCGCCCTCGGGAGGGCTGGAGCCC 15 | TAACGCTTGCCGCACAGTTGCTTATCTAGGTTCCAGACTTGGCTAGTTTACAGTGCTGCC 16 | GTAGCGTTTTCGTCTTGAGCGTTCCTCCATGCGCCGCAGGATTCCCCGCATCCTGGGGAG 17 | TTTCAGTCTTGCAATGGTAAGAGGAAGAAGTGA 18 | >Rosalind_0992 19 | CGAACGTAACTAGTGGCGCAACGAATGTTAACGCC 20 | >Rosalind_6743 21 | CGCATTCCGGCGAT 22 | >Rosalind_8004 23 | CTACAGCTGAGTAAAAGGGGAGAGTGTGGGCGAGTCAGGTCGGGG 24 | >Rosalind_0288 25 | TTTTCGTCTTGAGCGTTCCTCCATGCGCCGCAGGATTCCCCGCATCCT 26 | >Rosalind_9121 27 | CCGACCCAAGCCTAGCTGGAACAGAGACCCATGGAGAGTCAAGATG 28 | >Rosalind_5762 29 | CTCCATCCGGCGATTAAC 30 | >Rosalind_8018 31 | CCAGACTTGTTCACGCTC 32 | >Rosalind_1483 33 | GGCGCAGCGCCCTCGGGAGGGCTGGAGCCCTAACGC 34 | >Rosalind_2392 35 | GCAAGATGTACCCGGT 36 | >Rosalind_4283 37 | AGCTAGACCAAGAAGCTTTGTGACTAGCCCGGACTTGCGCT 38 | >Rosalind_5341 39 | TCATCACACCGCTTCTATATTAACCCACCG 40 | >Rosalind_9241 41 | CGAAGCTCCTGCAGTCCTCTGAGGACCG 42 | >Rosalind_4956 43 | GTCAATCTCGACTCGTAGTCCCTC -------------------------------------------------------------------------------- /aoc2020/day11/day11.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: arrays combinators grouping io.encodings.utf8 io.files 4 | kernel locals math math.combinatorics math.ranges math.vectors 5 | prettyprint sequences sets splitting math.matrices ; 6 | IN: aoc2020.day11 7 | 8 | : matrix-pad0 ( matrix -- matrix' ) 9 | 2 [ [ 0 prefix 0 suffix ] map flip ] times ; 10 | 11 | : 3x3-count-1s ( matrix -- matrix' ) 12 | [ 3 clump [ [ 1 = ] count ] map ] map flip 13 | [ 3 clump [ sum ] map ] map flip ; 14 | 15 | : next-state ( occupied seat -- seat' ) 16 | { { -1 [ drop -1 ] } 17 | { 0 [ 0 = 1 0 ? ] } 18 | { 1 [ 4 <= 1 0 ? ] } } case ; 19 | 20 | : next-state-matrix ( occupied seats -- seats' ) 21 | [ [ next-state ] 2map ] 2map ; 22 | 23 | : 1iteration ( seats -- seats' ) 24 | [ matrix-pad0 3x3-count-1s ] keep next-state-matrix ; 25 | 26 | : day11-silver ( matrix -- matrix' ) 27 | [ 1iteration ] to-fixed-point concat [ 0 > ] count ; 28 | 29 | : mnth ( coord matrix -- item ) 30 | [ swap nth ] reduce ; 31 | 32 | :: 1iteration' ( seats -- seats' ) 33 | seats matrix-pad0 :> padded 34 | seats dim matrix-coordinates 35 | [ 1 v+n :> coord 36 | { { 0 1 } { 1 1 } { 1 0 } { 1 -1 } { 0 -1 } { -1 -1 } { -1 0 } { -1 1 } } [ 37 | :> dir 38 | coord -1 [ dup 0 < ] [ drop dir v+ dup padded mnth ] while 39 | nip 0 > 40 | ] count 41 | ] matrix-map 42 | seats next-state-matrix ; 43 | 44 | : day11-gold ( matrix -- matrix' ) 45 | [ 1iteration' ] to-fixed-point concat [ 0 > ] count ; 46 | 47 | : day11-main ( -- ) "datasets/aoc2020/day11.txt" utf8 file-contents 48 | "\n" split [ >array 76 v-n 30 v/n ] map 49 | [ day11-silver . ] [ day11-gold . ] bi ; 50 | 51 | MAIN: day11-main -------------------------------------------------------------------------------- /aoc2020/day24/day24.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: arrays assocs fry grouping io.encodings.utf8 io.files 4 | kernel math math.functions math.matrices math.statistics 5 | math.vectors prettyprint regexp sequences sequences.extras 6 | splitting ; 7 | IN: aoc2020.day24 8 | 9 | : day24-silver ( coords -- n ) 10 | histogram values [ odd? ] count ; 11 | 12 | : pad-matrix ( mat -- mat' ) 13 | dup [ first length 2 swap zero-matrix ] dup bi surround 14 | [ { 0 } { 0 } surround ] map ; 15 | 16 | : 5x3-sums ( mat -- mat' ) 17 | pad-matrix 5 clump [ flip 3 clump [ concat sum ] map ] map ; 18 | 19 | : flip-cells ( mat1 mat2 -- mat ) 20 | [ [ [ nip 2 = ] [ - -2 = ] 2bi or 1 0 ? ] 2map ] 2map ; 21 | 22 | : valid-coords ( coords -- coords' ) 23 | histogram [ nip odd? ] assoc-filter keys ; 24 | 25 | : offset-coords ( coords -- coords' ) 26 | dup vinfimum '[ _ v- ] map ; 27 | 28 | : to-01-matrix ( coords -- mat ) 29 | dup vsupremum 1 v+n first2 zero-matrix 30 | [ first2 swap pick nth 1 -rot set-nth ] reduce ; 31 | 32 | : next-gol-state ( mat -- mat' ) 33 | pad-matrix dup 5x3-sums flip-cells ; 34 | 35 | : day24-gold ( coords -- n ) 36 | valid-coords offset-coords to-01-matrix 37 | 100 [ next-gol-state ] times concat sum ; 38 | 39 | : str>offset ( str -- pair ) 40 | { { "e" { 2 0 } } { "se" { 1 1 } } { "sw" { -1 1 } } 41 | { "w" { -2 0 } } { "nw" { -1 -1 } } { "ne" { 1 -1 } } } at ; 42 | 43 | : str>coord ( str -- pair ) 44 | R/ e|se|sw|w|nw|ne/ all-matching-subseqs [ str>offset ] [ v+ ] map-reduce ; 45 | 46 | : day24-main ( -- ) 47 | "datasets/aoc2020/day24.txt" utf8 file-contents "\n" split [ str>coord ] map 48 | [ day24-silver . ] [ day24-gold . ] bi ; 49 | 50 | MAIN: day24-main -------------------------------------------------------------------------------- /aoc2020/day17/day17.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2020 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: arrays grouping.extras io.encodings.utf8 io.files kernel 4 | math math.matrices math.vectors prettyprint sequences 5 | sequences.extras splitting ; 6 | IN: aoc2020.day17 7 | 8 | : life3d-pad1 ( array -- array' ) 9 | [ ] [ length 2 + ] [ first [ [ drop 0 ] map ] map ] tri pad-center 10 | [ [ ] [ length 2 + ] [ first [ drop 0 ] map ] tri pad-center ] map 11 | [ [ [ ] [ length 2 + ] bi 0 pad-center ] map ] map ; 12 | 13 | : life3d-counts ( array -- array' ) 14 | [ m+ m+ ] 3clump-map 15 | [ [ v+ v+ ] 3clump-map ] map 16 | [ [ [ + + ] 3clump-map ] map ] map ; 17 | 18 | : life3d-next ( sums self -- next ) 19 | [ [ [ [ drop 3 = ] [ - 3 = ] 2bi or 1 0 ? ] 2map ] 2map ] 2map ; 20 | 21 | : life3d-1iter ( array -- array' ) 22 | life3d-pad1 [ life3d-pad1 life3d-counts ] keep life3d-next ; 23 | 24 | : life4d-pad1 ( array -- array' ) 25 | [ ] [ length 2 + ] [ first [ [ [ drop 0 ] map ] map ] map ] tri pad-center 26 | [ life3d-pad1 ] map ; 27 | 28 | : life4d-counts ( array -- array' ) 29 | [ [ m+ m+ ] 3map ] 3clump-map 30 | [ life3d-counts ] map ; 31 | 32 | : life4d-next ( sums self -- next ) 33 | [ life3d-next ] 2map ; 34 | 35 | : life4d-1iter ( array -- array' ) 36 | life4d-pad1 [ life4d-pad1 life4d-counts ] keep life4d-next ; 37 | 38 | : day17-silver ( array -- sum ) 39 | 1array 6 [ life3d-1iter ] times concat concat sum ; 40 | 41 | : day17-gold ( array -- sum ) 42 | 1array 1array 6 [ life4d-1iter ] times concat concat concat sum ; 43 | 44 | : day17-main ( -- ) "datasets/aoc2020/day17.txt" utf8 file-contents 45 | "\n" split [ >array [ CHAR: # = 1 0 ? ] map ] map 46 | [ day17-silver . ] [ day17-gold . ] bi ; 47 | 48 | MAIN: day17-main -------------------------------------------------------------------------------- /aoc2015/day6/day6.factor: -------------------------------------------------------------------------------- 1 | ! Copyright (C) 2021 Bubbler. 2 | ! See http://factorcode.org/license.txt for BSD license. 3 | USING: arrays byte-arrays combinators grouping io.encodings.utf8 4 | io.files kernel locals math math.order math.parser math.ranges 5 | prettyprint regexp sequences sequences.extras splitting strings 6 | ; 7 | IN: aoc2015.day6 8 | 9 | : extract-mode ( str -- mode ) 10 | R/ on|off|toggle/ first-match >string ; 11 | 12 | : extract-ranges ( str -- seq ) 13 | R/ \d+/ all-matching-subseqs [ dec> ] map 14 | 2 group flip ; 15 | 16 | : day6-data ( -- data ) 17 | "datasets/aoc2015/day6.txt" utf8 file-contents "\n" split 18 | [ [ extract-mode ] [ extract-ranges ] bi 2array ] map ; 19 | 20 | : init-matrix ( -- matrix ) 21 | 1000 f [ drop 1000 ] map ; 22 | 23 | :: change-matrix-range ( matrix xrange yrange quot: ( x -- x ) -- matrix ) 24 | yrange first2 [a,b] matrix 25 | [| row | xrange first2 [a,b] row quot change-nths row ] change-nths 26 | matrix ; inline 27 | 28 | : run-command-silver ( matrix cmd -- matrix ) 29 | first2 first2 rot { 30 | { "on" [ [ drop 1 ] change-matrix-range ] } 31 | { "off" [ [ drop 0 ] change-matrix-range ] } 32 | { "toggle" [ [ 1 swap - ] change-matrix-range ] } 33 | } case ; 34 | 35 | : run-command-gold ( matrix cmd -- matrix ) 36 | first2 first2 rot { 37 | { "on" [ [ 1 + ] change-matrix-range ] } 38 | { "off" [ [ 1 - 0 max ] change-matrix-range ] } 39 | { "toggle" [ [ 2 + ] change-matrix-range ] } 40 | } case ; 41 | 42 | : day6-silver ( seq -- n ) 43 | init-matrix [ run-command-silver ] reduce concat sum ; 44 | 45 | : day6-gold ( seq -- n ) 46 | init-matrix [ run-command-gold ] reduce concat sum ; 47 | 48 | : day6-main ( -- ) 49 | day6-data [ day6-silver . ] [ day6-gold . ] bi ; 50 | 51 | MAIN: day6-main --------------------------------------------------------------------------------