Skip to content

Commit 4ab9da6

Browse files
authored
Add day-00-example (#2)
* Add day-00-example * Improve README.md
1 parent db42584 commit 4ab9da6

File tree

21 files changed

+313
-37
lines changed

21 files changed

+313
-37
lines changed

.editorconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@ insert_final_newline = true
1111
[Makefile]
1212
indent_style = tab
1313
indent_size = 4
14-
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: day-00-example
2+
on:
3+
push:
4+
paths:
5+
- 'day-00-example/**'
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
container:
11+
image: jonasjso/adventofcode2020
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: Print versions
15+
run: ./scripts/print-versions.sh
16+
- name: Run test
17+
run: ./day-00-example/test.sh

.github/workflows/test.yaml

Lines changed: 0 additions & 28 deletions
This file was deleted.

Dockerfile

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
11
FROM ubuntu:latest
22
LABEL github=https://github.com/Arxcis/adventofcode2020
33

4-
# Apt install all the things
4+
# Configure TZ, so we don't get interactive prompt
5+
ENV TZ=Europe/Kiev
6+
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
7+
58
RUN apt update && apt install -yqq\
9+
curl\
10+
unzip;
11+
12+
# Tell ubuntu that we want to install node from nodesource
13+
RUN curl -sL https://deb.nodesource.com/setup_15.x | bash -
14+
15+
# Install all the things
16+
RUN apt update && apt install -yqq\
17+
# python3 v3.8.6
618
python3\
7-
python-is-python3\
8-
;
19+
# golang 1.14
20+
golang\
21+
# nodejs v15.x
22+
nodejs
23+
24+
# deno v1.5.3
25+
RUN curl -fsSL https://deno.land/x/install/install.sh | sh\
26+
&& mv -v /root/.deno/bin/* /bin/
927

28+
# @TODO Enable rust support rust v1.48
29+
#RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y\
30+
# && mv -v /root/.cargo/bin/* /bin/

Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
test:
2-
echo "hello test"
2+
./day-00-example/test.sh
33

44
dockerbuild: Dockerfile
55
docker build . --tag jonasjso/adventofcode2020
66

77
dockerpush:
88
docker push jonasjso/adventofcode2020:latest
99

10+
versions:
11+
./scripts/print-versions.sh
1012

11-
.PHONY: dockerbuild dockerpush test
13+
workflows:
14+
./scripts/make-workflows.sh
1215

16+
scaffold:
17+
./scripts/make-scaffold.sh
18+
19+
.PHONY: dockerbuild dockerpush test versions workflows scaffold

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,39 @@
11
# adventofcode2020
2-
Solving the 2020 edition of https://adventofcode.com/ in many languages, and test the solutions using Github CI
2+
Solving the 2020 edition of https://adventofcode.com/ in many languages, and test the solutions using Github CI.
3+
4+
## Contributing
5+
1. Make a branch. Example: `git checkout -b jonas/day-03`
6+
2. Write a program, in the language of your choice. Example: `vim day-03/cmd/super-optimized.py`
7+
3. Test your program.
8+
9+
```sh
10+
cat day-03/input | python3 day-03/cmd/super-optimized.py | diff - day-03/output
11+
```
12+
13+
4. Make sure your program is automatically tested by the Github CI, by adding a line of code to `day-03/test.sh`.
14+
*Example line:*
15+
```sh
16+
$DIR/../scripts/test-py.sh $DIR "cmd/super-optimized.py"
17+
```
18+
19+
5. Make a Pull Request to the `main` branch.
20+
6. Get merged!
21+
22+
**How are programs tested?**
23+
24+
Every program gets the `input`-challenge delivered to `stdin`, and every program is expected to answer, by writing the `output`-answer to `stdout`.
25+
26+
```sh
27+
#!/bin/bash
28+
cat input | <run-program> | diff - output
29+
```
30+
31+
**The CI does not support my favourite language. What do I do?**
32+
33+
If we don't support the language you want to write in, don't worry. Make an issue on `Github`, and we will add it.
34+
35+
## Status
36+
![day-00-example](https://github.com/Arxcis/adventofcode2020/workflows/day-00-example/badge.svg)
337

438
## References
539
- Last attempt https://github.com/Arxcis/adventofcode2018/

day-00-example/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# day-00-example
2+
3+
This example-folder sets the precedence, for how the rest of the folders should be laid out.
4+
5+
## --- Part 1 ---
6+
7+
Sum all numbers
8+
9+
## --- Part 2 ---
10+
11+
Sum all odd numbers
12+

day-00-example/cmd/main.deno.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { readLines } from "https://deno.land/[email protected]/io/bufio.ts";
2+
3+
let sumAll = 0;
4+
let sumOdd = 0;
5+
for await (const line of readLines(Deno.stdin)) {
6+
if (line === "") continue;
7+
8+
const num = parseInt(line);
9+
sumAll += num;
10+
sumOdd += num % 2 === 0 ? 0 : num;
11+
}
12+
13+
// = Answer
14+
console.log(`${sumAll}`);
15+
console.log(`${sumOdd}`);
16+
// ================

day-00-example/cmd/main.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
"fmt"
6+
"os"
7+
"strconv"
8+
)
9+
10+
func main() {
11+
scanner := bufio.NewScanner(os.Stdin)
12+
13+
var sumAll int64 = 0
14+
var sumOdd int64 = 0
15+
for scanner.Scan() {
16+
line := scanner.Text()
17+
num, _ := strconv.ParseInt(line, 10, 64)
18+
sumAll += num
19+
20+
if num%2 != 0 {
21+
sumOdd += num
22+
}
23+
}
24+
25+
fmt.Println(sumAll)
26+
fmt.Println(sumOdd)
27+
}

day-00-example/cmd/main.node.mjs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import readline from "readline";
2+
3+
const lines = readline.createInterface({
4+
input: process.stdin,
5+
});
6+
7+
let sumAll = 0;
8+
let sumOdd = 0;
9+
for await (const line of lines) {
10+
const num = parseInt(line);
11+
sumAll += num;
12+
sumOdd += num % 2 === 0 ? 0 : num
13+
14+
}
15+
16+
// = Answer
17+
console.log(`${sumAll}`)
18+
console.log(`${sumOdd}`)
19+
// ================

0 commit comments

Comments
 (0)