File tree 7 files changed +131
-12
lines changed
7 files changed +131
-12
lines changed Original file line number Diff line number Diff line change 1
1
*
2
2
! /** /
3
3
! * . *
4
+ ! Makefile
5
+ ! Dockerfile
4
6
5
7
* .hi
6
8
* .o
Original file line number Diff line number Diff line change 1
-
1
+ CONTAINER_NAME =haskell-aoc
2
2
SRC =./Day06.hs
3
3
TARGET =Day06
4
4
all : $(TARGET )
@@ -9,4 +9,17 @@ $(TARGET): $(SRC)
9
9
clean :
10
10
$(RM ) ./Day06 ./Day06.o ./Day06.hi
11
11
12
- .PHONY : all $(TARGET ) clean
12
+ setup : $(SRC )
13
+ docker cp $(SRC ) $(CONTAINER_NAME ) :/home/haskell/Main.hs
14
+ docker cp input.txt $(CONTAINER_NAME ) :/home/haskell/input.txt
15
+ docker cp shortinput.txt $(CONTAINER_NAME ) :/home/haskell/shortinput.txt
16
+
17
+ profiling : setup
18
+ docker exec -it ${CONTAINER_NAME} cabal build --enable-profiling
19
+ docker exec -it ${CONTAINER_NAME} ./profile input.txt
20
+
21
+ run : setup
22
+ docker exec -it ${CONTAINER_NAME} cabal build
23
+ docker exec -it ${CONTAINER_NAME} ./run input.txt
24
+
25
+ .PHONY : all $(TARGET ) clean profiling
Original file line number Diff line number Diff line change
1
+ FROM haskell:9.6.6
2
+
3
+ # Install best text editor
4
+ RUN apt-get update && apt-get install -y vim
5
+
6
+ RUN cabal update
7
+
8
+ # Copy base project to force cabal to install dependencies in the image
9
+ COPY ./haskell /home/haskell
10
+
11
+ WORKDIR /home/haskell
12
+
13
+ # Installing the program's dependencies
14
+ RUN cabal build
15
+
16
+ # Installing the profiling dependencies
17
+ RUN cabal build --enable-profiling
18
+
19
+ RUN echo '#!/bin/sh\n ./dist-newstyle/build/x86_64-linux/ghc-9.6.6/Main-0.1.0.0/x/Main/build/Main/Main +RTS -p -RTS $@' > profile && chmod u+x profile
20
+ RUN echo '#!/bin/sh\n ./dist-newstyle/build/x86_64-linux/ghc-9.6.6/Main-0.1.0.0/x/Main/build/Main/Main $@' > run && chmod u+x run
21
+
22
+ CMD ["bash" ]
Original file line number Diff line number Diff line change 1
1
# Advent-of-code
2
2
Advent of code, probably be in several languages for fun
3
3
4
+ ## Use
5
+
6
+ ### A new day :
7
+
8
+ Execute the ` build_day.sh ` file to generate the necessary files depending on the chosen language
9
+
10
+ You need to execute it like
11
+
12
+ ``` sh
13
+ . build_day.sh [hs]
14
+ ```
15
+
16
+ ### Profiling :
17
+
18
+ Build the Haskell Docker Image:
19
+
20
+ ``` sh
21
+ docker build -t haskell-aoc .
22
+
23
+ ```
24
+
25
+ Create a haskell Docker
26
+ ``` sh
27
+ docker run -it --rm --name haskell-aoc haskell-aoc
28
+ ```
29
+ Keep it running in the background in order to launch your solutions on it
30
+
4
31
## 2021
5
32
6
33
Started coding in Shell, was too difficult, so finished in Python..
7
34
8
35
## 2022
9
36
10
37
Starting in shell and Haskell, will see how it goes
38
+
39
+ ## 2023
40
+
41
+ ## 2024
42
+
43
+ Continuing in haskell
44
+
45
+ Having fun trying to automate stuff as well
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ is_sourced() {
10
10
}
11
11
12
12
if ! ` is_sourced` ; then
13
- echo " use as '. $0 '"
13
+ echo " use as '. $0 [hs] '"
14
14
echo exit 1
15
15
fi
16
16
@@ -46,11 +46,11 @@ type Output = Int
46
46
parseInput :: String -> Input
47
47
parseInput = lines
48
48
49
- -- part1 :: Input -> Output
50
- -- part1 input =
49
+ part1 :: Input -> Output
50
+ part1 input = -1
51
51
52
- -- part2 :: Input -> Output
53
- -- part2 input =
52
+ part2 :: Input -> Output
53
+ part2 input = -1
54
54
55
55
main :: IO ()
56
56
main = do
@@ -60,30 +60,50 @@ main = do
60
60
61
61
print input
62
62
63
- -- print $ part1 input
64
- -- print $ part2 input
63
+ print $ part1 input
64
+ print $ part2 input
65
65
EOF
66
66
67
67
cat << EOF > $FOLDER /Makefile
68
-
68
+ CONTAINER_NAME=haskell-aoc
69
69
SRC=./Day$DAY .hs
70
70
TARGET=Day$DAY
71
71
all: \$ (TARGET)
72
72
73
73
\$ (TARGET): \$ (SRC)
74
- ghc \$ (SRC)
74
+ ghc -O3 \$ (SRC)
75
+
76
+ profile: \$ (SRC)
77
+
75
78
76
79
clean:
77
80
\$ (RM) ./Day$DAY ./Day$DAY .o ./Day$DAY .hi
78
81
79
- .PHONY: all \$ (TARGET) clean
82
+ setup: \$ (SRC)
83
+ docker cp \$ (SRC) \$ (CONTAINER_NAME):/home/haskell/Main.hs
84
+ docker cp input.txt \$ (CONTAINER_NAME):/home/haskell/input.txt
85
+ docker cp shortinput.txt \$ (CONTAINER_NAME):/home/haskell/shortinput.txt
86
+
87
+ profiling: setup
88
+ docker exec -it \$ (CONTAINER_NAME) cabal build --enable-profiling
89
+ docker exec -it \$ (CONTAINER_NAME) ./profile input.txt
90
+
91
+ run: setup
92
+ docker exec -it \$ (CONTAINER_NAME) cabal build
93
+ docker exec -it \$ (CONTAINER_NAME) ./run input.txt
94
+
95
+ .PHONY: all \$ (TARGET) clean setup profiling run
80
96
EOF
81
97
82
98
;;
83
99
84
100
" " )
85
101
echo " No language specified"
86
102
;;
103
+ * )
104
+ echo " Unknown language specified"
105
+ ;;
106
+
87
107
esac
88
108
89
109
cd $FOLDER
Original file line number Diff line number Diff line change
1
+ cabal-version : 2.4
2
+ name : Main
3
+ version : 0.1.0.0
4
+ license : NONE
5
+ build-type : Simple
6
+ common warnings
7
+ ghc-options : -Wall -O2
8
+
9
+ executable Main
10
+ import : warnings
11
+
12
+ main-is : Main.hs
13
+
14
+ build-depends : base ^>= 4.18.2.1 ,
15
+ containers >= 0.6.7 ,
16
+ matrix >= 0.3.6.3 ,
17
+ parallel >= 3.2.2.0
18
+
19
+ -- Directories containing source files.
20
+ hs-source-dirs : .
21
+
22
+ -- Base language which the package is written in.
23
+ default-language : GHC2021
Original file line number Diff line number Diff line change
1
+
2
+ main :: IO ()
3
+ main = do
4
+ print 42
You can’t perform that action at this time.
0 commit comments