Tweaked solution 9 a bit, to check all approaches are finding the same set of items
[summerofcode2018soln.git] / README.md
1 ---
2 title: "Summer of Code 2018"
3 output: html_document
4 css: modest.css
5 ---
6 Code to solve the [Summer of Code](https://learn2.open.ac.uk/course/view.php?id=206891) puzzles. These sample solutions are in [Python](https://www.python.org/) and [Haskell](https://wiki.haskell.org/Haskell).
7
8 # Python
9 I develop the solutions with [Jupyter Lab](https://github.com/jupyterlab/).
10
11 # Haskell
12
13 [Learn you a Haskell](http://learnyouahaskell.com/chapters), [Introduction to Haskell 98](https://www.haskell.org/tutorial/index.html), and [Hackage](https://hackage.haskell.org/) are good resources.
14
15 The [Stack documentation](https://docs.haskellstack.org/en/stable/README/) and [How I Start: Haskell](http://howistart.org/posts/haskell/1/) are good sources of using the tools.
16
17 ## Toolchain
18
19 I'm using the basic Haskell Platform installation, togeher with `stack` to manage the packages and dependencies (install with
20 ```
21 $ sudo aptitude install haskell-platform haskell-stack
22 ```
23 ).
24
25 ### Creating the repository and project
26 Create the repository as normal: create the project in Gitolite, clone it, and insert the `.gitignore` and `README.md` files.
27
28 There's just one package, with the code in sub-directories of the `src` directory. Each day will generate one (or more) entries in the `summerofcode2018soln.cabal` file.
29
30 Create the basic `stack` project. This will create a new directory. Note that this new directory name can't have a hyphen-delimited word that's just digits, so the project will have to be `advent-of-code`
31
32 ```
33 stack new summerofcode2018soln --bare simple
34 ```
35
36 Modify the `stack.yaml` file as needed, such as adding the `ghc-options` stanza.
37
38 ### Creating subsequent days
39
40 Each day lives in a separate directory within the `src` directory. It will also need it's own stanza in `summerofcode2018.cabal`.
41
42 Compile with
43 ```
44 stack build
45 ```
46 or
47 ```
48 stack build task1
49 ```
50
51 Run with
52 ```
53 stack exec task1
54 ```
55
56 Run interactively with
57 ```
58 stack ghci summerofcode2018soln:exe:task1
59 ```
60
61 To profile, use
62 ```
63 stack build --executable-profiling --library-profiling --ghc-options="-fprof-auto -rtsopts"
64 ```
65 then run with
66 ```
67 stack exec -- task1 +RTS -p -hy
68 ```
69 Make the profile graph visible with
70 ```
71 /usr/lib/ghc/bin/hp2ps task1.hp
72 ```
73
74 ## Packages
75
76 Stack is using the [12.9-lts resolver](https://www.stackage.org/lts-12.9) for packages, so make sure you read the [correct documentation for the packages included in it](https://www.stackage.org/lts-12.9/docs).
77
78 When you use a new package, use
79
80 ```
81 stack solver
82 ```
83 to see how the `stack.yaml` file needs to change, and
84 ```
85 stack solver --update-yaml
86 ```
87 to implement the changes.
88
89 # Readme
90
91 Build this readme file wth
92 ```
93 pandoc -s README.md > README.html
94 ```
95
96 (Using the [Modest style](https://github.com/markdowncss/modest).)