getting rid of the separate folders
parent
da6e320bd9
commit
a7ff2d0273
@ -0,0 +1,2 @@
|
||||
dist*
|
||||
|
@ -1 +0,0 @@
|
||||
eval "$(lorri direnv)"
|
@ -1 +0,0 @@
|
||||
|
@ -1,3 +0,0 @@
|
||||
.stack-work/
|
||||
one.cabal
|
||||
*~
|
@ -1,3 +0,0 @@
|
||||
# Changelog for one
|
||||
|
||||
## Unreleased changes
|
@ -1,30 +0,0 @@
|
||||
Copyright Author name here (c) 2019
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer in the documentation and/or other materials provided
|
||||
with the distribution.
|
||||
|
||||
* Neither the name of Author name here nor the names of other
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
@ -1 +0,0 @@
|
||||
# one
|
@ -1,10 +0,0 @@
|
||||
module Main where
|
||||
|
||||
import Lib
|
||||
import Control.Monad
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
contents <- getContents
|
||||
putStrLn $ show $ sum $ map fuelRequired $ map (read :: String -> Int) $ lines contents
|
||||
|
@ -1,100 +0,0 @@
|
||||
51590
|
||||
53619
|
||||
101381
|
||||
81994
|
||||
139683
|
||||
53417
|
||||
124196
|
||||
127640
|
||||
99688
|
||||
116170
|
||||
127812
|
||||
95979
|
||||
73734
|
||||
105347
|
||||
130495
|
||||
89331
|
||||
116486
|
||||
65177
|
||||
143689
|
||||
130487
|
||||
57206
|
||||
74950
|
||||
141398
|
||||
100921
|
||||
114019
|
||||
137106
|
||||
137690
|
||||
70779
|
||||
61421
|
||||
121827
|
||||
122432
|
||||
108229
|
||||
65362
|
||||
70884
|
||||
56127
|
||||
83611
|
||||
126776
|
||||
91422
|
||||
51444
|
||||
52424
|
||||
69535
|
||||
110270
|
||||
115006
|
||||
97214
|
||||
85306
|
||||
77028
|
||||
102078
|
||||
82928
|
||||
101635
|
||||
91889
|
||||
58082
|
||||
72996
|
||||
74276
|
||||
135691
|
||||
113622
|
||||
118522
|
||||
56796
|
||||
115576
|
||||
138861
|
||||
63418
|
||||
64090
|
||||
131682
|
||||
93394
|
||||
61302
|
||||
98591
|
||||
67253
|
||||
69822
|
||||
121652
|
||||
133636
|
||||
106283
|
||||
83460
|
||||
53394
|
||||
65208
|
||||
66158
|
||||
113100
|
||||
52984
|
||||
126741
|
||||
75880
|
||||
124770
|
||||
54681
|
||||
69994
|
||||
138088
|
||||
83435
|
||||
75332
|
||||
114436
|
||||
141680
|
||||
68659
|
||||
111337
|
||||
56920
|
||||
74203
|
||||
96424
|
||||
86848
|
||||
69561
|
||||
53861
|
||||
118216
|
||||
79570
|
||||
136039
|
||||
120959
|
||||
122917
|
||||
122226
|
@ -1,100 +0,0 @@
|
||||
17194
|
||||
17871
|
||||
33791
|
||||
27329
|
||||
46559
|
||||
17803
|
||||
41396
|
||||
42544
|
||||
33227
|
||||
38721
|
||||
42602
|
||||
31991
|
||||
24576
|
||||
35113
|
||||
43496
|
||||
29775
|
||||
38826
|
||||
21723
|
||||
47894
|
||||
43493
|
||||
19066
|
||||
24981
|
||||
47130
|
||||
33638
|
||||
38004
|
||||
45700
|
||||
45894
|
||||
23591
|
||||
20471
|
||||
40607
|
||||
40808
|
||||
36074
|
||||
21785
|
||||
23626
|
||||
18707
|
||||
27868
|
||||
42256
|
||||
30472
|
||||
17146
|
||||
17472
|
||||
23176
|
||||
36754
|
||||
38333
|
||||
32402
|
||||
28433
|
||||
25674
|
||||
34024
|
||||
27640
|
||||
33876
|
||||
30627
|
||||
19358
|
||||
24330
|
||||
24756
|
||||
45228
|
||||
37872
|
||||
39505
|
||||
18930
|
||||
38523
|
||||
46285
|
||||
21137
|
||||
21361
|
||||
43892
|
||||
31129
|
||||
20432
|
||||
32861
|
||||
22415
|
||||
23272
|
||||
40548
|
||||
44543
|
||||
35425
|
||||
27818
|
||||
17796
|
||||
21734
|
||||
22050
|
||||
37698
|
||||
17659
|
||||
42245
|
||||
25291
|
||||
41588
|
||||
18225
|
||||
23329
|
||||
46027
|
||||
27809
|
||||
25108
|
||||
38143
|
||||
47224
|
||||
22884
|
||||
37110
|
||||
18971
|
||||
24732
|
||||
32139
|
||||
28947
|
||||
23185
|
||||
17951
|
||||
39403
|
||||
26521
|
||||
45344
|
||||
40317
|
||||
40970
|
||||
40740
|
@ -1 +0,0 @@
|
||||
4726527
|
@ -1,48 +0,0 @@
|
||||
name: one
|
||||
version: 0.1.0.0
|
||||
github: "githubuser/one"
|
||||
license: BSD3
|
||||
author: "Author name here"
|
||||
maintainer: "example@example.com"
|
||||
copyright: "2019 Author name here"
|
||||
|
||||
extra-source-files:
|
||||
- README.md
|
||||
- ChangeLog.md
|
||||
|
||||
# Metadata used when publishing your package
|
||||
# synopsis: Short description of your package
|
||||
# category: Web
|
||||
|
||||
# To avoid duplicated efforts in documentation and dealing with the
|
||||
# complications of embedding Haddock markup inside cabal files, it is
|
||||
# common to point users to the README.md file.
|
||||
description: Please see the README on GitHub at <https://github.com/githubuser/one#readme>
|
||||
|
||||
dependencies:
|
||||
- base >= 4.7 && < 5
|
||||
|
||||
library:
|
||||
source-dirs: src
|
||||
|
||||
executables:
|
||||
one-exe:
|
||||
main: Main.hs
|
||||
source-dirs: app
|
||||
ghc-options:
|
||||
- -threaded
|
||||
- -rtsopts
|
||||
- -with-rtsopts=-N
|
||||
dependencies:
|
||||
- one
|
||||
|
||||
tests:
|
||||
one-test:
|
||||
main: Spec.hs
|
||||
source-dirs: test
|
||||
ghc-options:
|
||||
- -threaded
|
||||
- -rtsopts
|
||||
- -with-rtsopts=-N
|
||||
dependencies:
|
||||
- one
|
@ -1,15 +0,0 @@
|
||||
module Lib
|
||||
( fuelRequired
|
||||
) where
|
||||
|
||||
import Data.List
|
||||
|
||||
fuelRequired :: Int -> Int
|
||||
fuelRequired mass = sum $ tail $ fuelUnfold mass
|
||||
|
||||
fuelUnfold :: Int -> [Int]
|
||||
fuelUnfold mass = unfoldr (\m -> calc m) mass
|
||||
|
||||
calc :: Int -> Maybe (Int, Int)
|
||||
calc 0 = Nothing
|
||||
calc mass = if mass <= 0 then Nothing else Just (mass, (mass `div` 3 - 2))
|
@ -1,66 +0,0 @@
|
||||
# This file was automatically generated by 'stack init'
|
||||
#
|
||||
# Some commonly used options have been documented as comments in this file.
|
||||
# For advanced use and comprehensive documentation of the format, please see:
|
||||
# https://docs.haskellstack.org/en/stable/yaml_configuration/
|
||||
|
||||
# Resolver to choose a 'specific' stackage snapshot or a compiler version.
|
||||
# A snapshot resolver dictates the compiler version and the set of packages
|
||||
# to be used for project dependencies. For example:
|
||||
#
|
||||
# resolver: lts-3.5
|
||||
# resolver: nightly-2015-09-21
|
||||
# resolver: ghc-7.10.2
|
||||
#
|
||||
# The location of a snapshot can be provided as a file or url. Stack assumes
|
||||
# a snapshot provided as a file might change, whereas a url resource does not.
|
||||
#
|
||||
# resolver: ./custom-snapshot.yaml
|
||||
# resolver: https://example.com/snapshots/2018-01-01.yaml
|
||||
resolver: lts-14.16
|
||||
|
||||
# User packages to be built.
|
||||
# Various formats can be used as shown in the example below.
|
||||
#
|
||||
# packages:
|
||||
# - some-directory
|
||||
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
|
||||
# subdirs:
|
||||
# - auto-update
|
||||
# - wai
|
||||
packages:
|
||||
- .
|
||||
# Dependency packages to be pulled from upstream that are not in the resolver.
|
||||
# These entries can reference officially published versions as well as
|
||||
# forks / in-progress versions pinned to a git hash. For example:
|
||||
#
|
||||
# extra-deps:
|
||||
# - acme-missiles-0.3
|
||||
# - git: https://github.com/commercialhaskell/stack.git
|
||||
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
|
||||
#
|
||||
# extra-deps: []
|
||||
|
||||
# Override default flag values for local packages and extra-deps
|
||||
# flags: {}
|
||||
|
||||
# Extra package databases containing global packages
|
||||
# extra-package-dbs: []
|
||||
|
||||
# Control whether we use the GHC we find on the path
|
||||
# system-ghc: true
|
||||
#
|
||||
# Require a specific version of stack, using version ranges
|
||||
# require-stack-version: -any # Default
|
||||
# require-stack-version: ">=2.1"
|
||||
#
|
||||
# Override the architecture used by stack, especially useful on Windows
|
||||
# arch: i386
|
||||
# arch: x86_64
|
||||
#
|
||||
# Extra directories used by stack for building
|
||||
# extra-include-dirs: [/path/to/dir]
|
||||
# extra-lib-dirs: [/path/to/dir]
|
||||
#
|
||||
# Allow a newer minor version of GHC than the snapshot specifies
|
||||
# compiler-check: newer-minor
|
@ -1,12 +0,0 @@
|
||||
# This file was autogenerated by Stack.
|
||||
# You should not edit this file by hand.
|
||||
# For more information, please see the documentation at:
|
||||
# https://docs.haskellstack.org/en/stable/lock_files
|
||||
|
||||
packages: []
|
||||
snapshots:
|
||||
- completed:
|
||||
size: 524804
|
||||
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/14/16.yaml
|
||||
sha256: 4d1519a4372d051d47a5eae2241cf3fb54e113d7475f89707ddb6ec06add2888
|
||||
original: lts-14.16
|
@ -1,2 +0,0 @@
|
||||
main :: IO ()
|
||||
main = putStrLn "Test suite not yet implemented"
|
@ -1 +0,0 @@
|
||||
806846-20191209-6701287d
|
@ -1,5 +0,0 @@
|
||||
with import <nixpkgs> {};
|
||||
mkShell {
|
||||
buildInputs = [ ghc stack ];
|
||||
}
|
||||
|
@ -1,3 +0,0 @@
|
||||
.stack-work/
|
||||
two.cabal
|
||||
*~
|
@ -1,3 +0,0 @@
|
||||
# Changelog for two
|
||||
|
||||
## Unreleased changes
|
@ -1,30 +0,0 @@
|
||||
Copyright Author name here (c) 2019
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer in the documentation and/or other materials provided
|
||||
with the distribution.
|
||||
|
||||
* Neither the name of Author name here nor the names of other
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
@ -1 +0,0 @@
|
||||
# two
|
@ -1,2 +0,0 @@
|
||||
import Distribution.Simple
|
||||
main = defaultMain
|
@ -1,11 +0,0 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
module Main where
|
||||
|
||||
import Lib
|
||||
|
||||
import qualified Data.Text.IO as T
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
contents <- T.getContents
|
||||
putStrLn $ show $ runProgram contents
|
@ -1 +0,0 @@
|
||||
1,12,2,3,1,1,2,3,1,3,4,3,1,5,0,3,2,1,9,19,1,10,19,23,2,9,23,27,1,6,27,31,2,31,9,35,1,5,35,39,1,10,39,43,1,10,43,47,2,13,47,51,1,10,51,55,2,55,10,59,1,9,59,63,2,6,63,67,1,5,67,71,1,71,5,75,1,5,75,79,2,79,13,83,1,83,5,87,2,6,87,91,1,5,91,95,1,95,9,99,1,99,6,103,1,103,13,107,1,107,5,111,2,111,13,115,1,115,6,119,1,6,119,123,2,123,13,127,1,10,127,131,1,131,2,135,1,135,5,0,99,2,14,0,0
|
@ -1 +0,0 @@
|
||||
1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,1,9,19,1,10,19,23,2,9,23,27,1,6,27,31,2,31,9,35,1,5,35,39,1,10,39,43,1,10,43,47,2,13,47,51,1,10,51,55,2,55,10,59,1,9,59,63,2,6,63,67,1,5,67,71,1,71,5,75,1,5,75,79,2,79,13,83,1,83,5,87,2,6,87,91,1,5,91,95,1,95,9,99,1,99,6,103,1,103,13,107,1,107,5,111,2,111,13,115,1,115,6,119,1,6,119,123,2,123,13,127,1,10,127,131,1,131,2,135,1,135,5,0,99,2,14,0,0
|
@ -1,55 +0,0 @@
|
||||
name: two
|
||||
version: 0.1.0.0
|
||||
github: "githubuser/two"
|
||||
license: BSD3
|
||||
author: "Author name here"
|
||||
maintainer: "example@example.com"
|
||||
copyright: "2019 Author name here"
|
||||
|
||||
extra-source-files:
|
||||
- README.md
|
||||
- ChangeLog.md
|
||||
|
||||
# Metadata used when publishing your package
|
||||
# synopsis: Short description of your package
|
||||
# category: Web
|
||||
|
||||
# To avoid duplicated efforts in documentation and dealing with the
|
||||
# complications of embedding Haddock markup inside cabal files, it is
|
||||
# common to point users to the README.md file.
|
||||
description: Please see the README on GitHub at <https://github.com/githubuser/two#readme>
|
||||
|
||||
dependencies:
|
||||
- base >= 4.7 && < 5
|
||||
- containers >= 0.6
|
||||
- text >= 1.2
|
||||
|
||||
library:
|
||||
source-dirs: src
|
||||
|
||||
executables:
|
||||
two-exe:
|
||||
main: Main.hs
|
||||
source-dirs: app
|
||||
ghc-options:
|
||||
- -threaded
|
||||
- -rtsopts
|
||||
- -with-rtsopts=-N
|
||||
dependencies:
|
||||
- two
|
||||
|
||||
tests:
|
||||
two-test:
|
||||
main: Spec.hs
|
||||
source-dirs: test
|
||||
ghc-options:
|
||||
- -threaded
|
||||
- -rtsopts
|
||||
- -with-rtsopts=-N
|
||||
dependencies:
|
||||
- two
|
||||
- tasty
|
||||
- tasty-hunit
|
||||
- tasty-th
|
||||
- tasty-hedgehog
|
||||
- hedgehog
|
@ -1,44 +0,0 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
module Intcode (DataTape, mkDataTape, loadProgram, parseProgram, executeProgram, computeInstruction) where
|
||||
|
||||
import Data.IntMap.Strict (IntMap)
|
||||
import qualified Data.IntMap.Strict as IntMap
|
||||
import qualified Data.Text as T
|
||||
import Data.Text.Read (decimal)
|
||||
|
||||
|
||||
type DataTape = IntMap Int
|
||||
|
||||
mkDataTape :: DataTape
|
||||
mkDataTape = IntMap.singleton (-1) 0
|
||||
|
||||
pointer :: DataTape -> Int -> Int
|
||||
pointer tape pos = tape IntMap.! pos
|
||||
|
||||
executeProgram :: DataTape -> DataTape
|
||||
executeProgram tape = let instruction = tape IntMap.! (-1)
|
||||
in case (tape IntMap.! instruction) of
|
||||
1 -> executeProgram $ computeInstruction (+) tape
|
||||
2 -> executeProgram $ computeInstruction (*) tape
|
||||
99 -> tape
|
||||
_ -> tape
|
||||
|
||||
computeInstruction :: (Int -> Int -> Int) -> DataTape -> DataTape
|
||||
computeInstruction f tape = let pointer' = pointer tape
|
||||
inst = pointer' (-1)
|
||||
frst = pointer' $ inst + 1
|
||||
scnd = pointer' $ inst + 2
|
||||
key = pointer' $ inst + 3
|
||||
val = f (pointer' frst) (pointer' scnd)
|
||||
in IntMap.insert (-1) (inst+4) $ IntMap.insert key val tape
|
||||
|
||||
loadProgram :: [Int] -> DataTape
|
||||
loadProgram input = IntMap.union mkDataTape $ IntMap.fromList $ zip [0..] input
|
||||
|
||||
parseProgram :: T.Text -> [Int]
|
||||
parseProgram input = map decimalize $ T.splitOn "," input
|
||||
where
|
||||
decimalize str = case decimal str of
|
||||
Right (i, rest) -> i
|
||||
Left message -> error message
|
||||
|
@ -1,13 +0,0 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
module Lib
|
||||
( runProgram
|
||||
) where
|
||||
|
||||
import Intcode
|
||||
import Data.IntMap.Strict (IntMap)
|
||||
import qualified Data.Text as T
|
||||
import Data.Text.Read (decimal)
|
||||
|
||||
|
||||
runProgram :: T.Text -> DataTape
|
||||
runProgram input = executeProgram $ loadProgram $ parseProgram input
|
@ -1,68 +0,0 @@
|
||||
# This file was automatically generated by 'stack init'
|
||||
#
|
||||
# Some commonly used options have been documented as comments in this file.
|
||||
# For advanced use and comprehensive documentation of the format, please see:
|
||||
# https://docs.haskellstack.org/en/stable/yaml_configuration/
|
||||
|
||||
# Resolver to choose a 'specific' stackage snapshot or a compiler version.
|
||||
# A snapshot resolver dictates the compiler version and the set of packages
|
||||
# to be used for project dependencies. For example:
|
||||
#
|
||||
# resolver: lts-3.5
|
||||
# resolver: nightly-2015-09-21
|
||||
# resolver: ghc-7.10.2
|
||||
#
|
||||
# The location of a snapshot can be provided as a file or url. Stack assumes
|
||||
# a snapshot provided as a file might change, whereas a url resource does not.
|
||||
#
|
||||
# resolver: ./custom-snapshot.yaml
|
||||
# resolver: https://example.com/snapshots/2018-01-01.yaml
|
||||
resolver: lts-14.16
|
||||
|
||||
# User packages to be built.
|
||||
# Various formats can be used as shown in the example below.
|
||||
#
|
||||
# packages:
|
||||
# - some-directory
|
||||
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
|
||||
# subdirs:
|
||||
# - auto-update
|
||||
# - wai
|
||||
packages:
|
||||
- .
|
||||
# Dependency packages to be pulled from upstream that are not in the resolver.
|
||||
# These entries can reference officially published versions as well as
|
||||
# forks / in-progress versions pinned to a git hash. For example:
|
||||
#
|
||||
# extra-deps:
|
||||
# - acme-missiles-0.3
|
||||
# - git: https://github.com/commercialhaskell/stack.git
|
||||
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
|
||||
#
|
||||
# extra-deps: []
|
||||
|
||||
# Override default flag values for local packages and extra-deps
|
||||
# flags: {}
|
||||
|
||||
# Extra package databases containing global packages
|
||||
# extra-package-dbs: []
|
||||
|
||||
# Control whether we use the GHC we find on the path
|
||||
# system-ghc: true
|
||||
#
|
||||
# Require a specific version of stack, using version ranges
|
||||
# require-stack-version: -any # Default
|
||||
# require-stack-version: ">=2.1"
|
||||
#
|
||||
# Override the architecture used by stack, especially useful on Windows
|
||||
# arch: i386
|
||||
# arch: x86_64
|
||||
#
|
||||
# Extra directories used by stack for building
|
||||
# extra-include-dirs: [/path/to/dir]
|
||||
# extra-lib-dirs: [/path/to/dir]
|
||||
#
|
||||
# Allow a newer minor version of GHC than the snapshot specifies
|
||||
# compiler-check: newer-minor
|
||||
nix:
|
||||
enable: true
|
@ -1,12 +0,0 @@
|
||||
# This file was autogenerated by Stack.
|
||||
# You should not edit this file by hand.
|
||||
# For more information, please see the documentation at:
|
||||
# https://docs.haskellstack.org/en/stable/lock_files
|
||||
|
||||
packages: []
|
||||
snapshots:
|
||||
- completed:
|
||||
size: 524804
|
||||
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/14/16.yaml
|
||||
sha256: 4d1519a4372d051d47a5eae2241cf3fb54e113d7475f89707ddb6ec06add2888
|
||||
original: lts-14.16
|
@ -1,89 +0,0 @@
|
||||
{-# LANGUAGE TemplateHaskell #-}
|
||||
module Main where
|
||||
|
||||
import Test.Tasty
|
||||
import Test.Tasty.TH
|
||||
import Test.Tasty.HUnit
|
||||
|
||||
import Test.Tasty.Hedgehog
|
||||
import qualified Hedgehog.Gen as Gen
|
||||
import qualified Hedgehog.Range as Range
|
||||
|
||||
import Data.IntMap.Strict (IntMap)
|
||||
import qualified Data.IntMap.Strict as IntMap
|
||||
import qualified Data.Text as T
|
||||
|
||||
import Intcode
|
||||
|
||||
|
||||
-- Intcode program datatapes
|
||||
|
||||
mkExampleTape :: [Int] -> DataTape
|
||||
mkExampleTape ints =
|
||||
IntMap.fromList $ zip [-1,0..] ints
|
||||
|
||||
-- mkDataTape
|
||||
|
||||
case_mkDataTape_has_instruction :: Assertion
|
||||
case_mkDataTape_has_instruction =
|
||||
mkDataTape IntMap.!? (-1) @?= Just 0
|
||||
|
||||
-- parseProgram
|
||||
|
||||
case_parseProgram_works_without_commas :: Assertion
|
||||
case_parseProgram_works_without_commas =
|
||||
parseProgram (T.pack "99") @?= [99]
|
||||
|
||||
case_parseProgram_works_with_commas :: Assertion
|
||||
case_parseProgram_works_with_commas =
|
||||
parseProgram (T.pack "99,99") @?= [99,99]
|
||||
|
||||
-- TODO property for strings of any length
|
||||
|
||||
case_loadProgram_single_instruction :: Assertion
|
||||
case_loadProgram_single_instruction =
|
||||
loadProgram [99] @?= IntMap.fromList [((-1), 0), (0, 99)]
|
||||
|
||||
case_loadProgram_two_instructions :: Assertion
|
||||
case_loadProgram_two_instructions =
|
||||
loadProgram [99,99] @?= IntMap.fromList [((-1), 0), (0, 99), (1, 99)]
|
||||
|
||||
-- TODO property for programs of any length
|
||||
|
||||
exampleOneBefore = mkExampleTape [0,1,9,10,3,2,3,11,0,99,30,40,50]
|
||||
exampleOneAfter = mkExampleTape [8,3500,9,10,70,2,3,11,0,99,30,40,50]
|
||||
|
||||
case_executeProgram_exampleOne :: Assertion
|
||||
case_executeProgram_exampleOne =
|
||||
exampleOneAfter @=? executeProgram exampleOneBefore
|
||||
|
||||
exampleTwoBefore = mkExampleTape [0,1,0,0,0,99]
|
||||
exampleTwoAfter = mkExampleTape [4,2,0,0,0,99]
|
||||
|
||||
case_executeProgram_exampleTwo :: Assertion
|
||||
case_executeProgram_exampleTwo =
|
||||
exampleTwoAfter @=? executeProgram exampleTwoBefore
|
||||
|
||||
exampleThreeBefore = mkExampleTape [0,2,3,0,3,99]
|
||||
exampleThreeAfter = mkExampleTape [4,2,3,0,6,99]
|
||||
|
||||
case_executeProgram_exampleThree :: Assertion
|
||||
case_executeProgram_exampleThree =
|
||||
exampleThreeAfter @=? executeProgram exampleThreeBefore
|
||||
|
||||
exampleFourBefore = mkExampleTape [0,2,4,4,5,99,0]
|
||||
exampleFourAfter = mkExampleTape [4,2,4,4,5,99,9801]
|
||||
|
||||
case_executeProgram_exampleFour :: Assertion
|
||||
case_executeProgram_exampleFour =
|
||||
exampleFourAfter @=? executeProgram exampleFourBefore
|
||||
|
||||
exampleFiveBefore = mkExampleTape [0,1,1,1,4,99,5,6,0,99]
|
||||
exampleFiveAfter = mkExampleTape [8,30,1,1,4,2,5,6,0,99]
|
||||
|
||||
case_executeProgram_exampleFive :: Assertion
|
||||
case_executeProgram_exampleFive =
|
||||
exampleFiveAfter @=? executeProgram exampleFiveBefore
|
||||
|
||||
main :: IO ()
|
||||
main = $(defaultMainGenerator)
|
@ -0,0 +1,5 @@
|
||||
# Revision history for x2020
|
||||
|
||||
## 0.1.0.0 -- YYYY-mm-dd
|
||||
|
||||
* First version. Released on an unsuspecting world.
|
@ -0,0 +1,4 @@
|
||||
module Main where
|
||||
|
||||
main :: IO ()
|
||||
main = putStrLn "Hello, Haskell!"
|
@ -0,0 +1,25 @@
|
||||
cabal-version: >=1.10
|
||||
-- Initial package description 'x2020.cabal' generated by 'cabal init'.
|
||||
-- For further documentation, see http://haskell.org/cabal/users-guide/
|
||||
|
||||
name: x2020
|
||||
version: 0.1.0.0
|
||||
-- synopsis:
|
||||
-- description:
|
||||
-- bug-reports:
|
||||
-- license:
|
||||
license-file: LICENSE
|
||||
author: sehqlr
|
||||
maintainer: hey@samhatfield.me
|
||||
-- copyright:
|
||||
-- category:
|
||||
build-type: Simple
|
||||
extra-source-files: CHANGELOG.md
|
||||
|
||||
executable x2020
|
||||
main-is: Main.hs
|
||||
-- other-modules:
|
||||
-- other-extensions:
|
||||
build-depends: base >=4.12 && <4.13
|
||||
-- hs-source-dirs:
|
||||
default-language: Haskell2010
|
@ -0,0 +1,13 @@
|
||||
let
|
||||
sources = import ./nix/sources.nix;
|
||||
haskellNix = import sources.haskellNix { };
|
||||
pkgsSrc = haskellNix.sources.nixpkgs-2009;
|
||||
pkgsArgs = haskellNix.nixpkgsArgs;
|
||||
in { pkgs ? import pkgsSrc pkgsArgs }:
|
||||
pkgs.haskell-nix.project {
|
||||
src = pkgs.haskell-nix.haskellLib.cleanGit {
|
||||
name = "advent-of-code-2020";
|
||||
src = ./.;
|
||||
};
|
||||
compiler-nix-name = "ghc8102";
|
||||
}
|
@ -1,4 +1,16 @@
|
||||
{
|
||||
"haskellNix": {
|
||||
"branch": "master",
|
||||
"description": "Alternative Haskell Infrastructure for Nixpkgs",
|
||||
"homepage": "https://input-output-hk.github.io/haskell.nix",
|
||||
"owner": "input-output-hk",
|
||||
"repo": "haskell.nix",
|
||||
"rev": "87eb7d1790e61234bda3b01bcbf8b1c73d294b14",
|
||||
"sha256": "0mdyjkx4sm8qrfs6y8airxxanzn4ijny148s7yki5amj43zvbdwh",
|
||||
"type": "tarball",
|
||||
"url": "https://github.com/input-output-hk/haskell.nix/archive/87eb7d1790e61234bda3b01bcbf8b1c73d294b14.tar.gz",
|
||||
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
|
||||
},
|
||||
"niv": {
|
||||
"branch": "master",
|
||||
"description": "Easy dependency management for Nix projects",
|
Loading…
Reference in New Issue