Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ insert_final_newline = true
[Makefile]
indent_style = tab
indent_size = 4

17 changes: 17 additions & 0 deletions .github/workflows/day-00-example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: day-00-example
on:
push:
paths:
- 'day-00-example/**'

jobs:
test:
runs-on: ubuntu-latest
container:
image: jonasjso/adventofcode2020
steps:
- uses: actions/checkout@v2
- name: Print versions
run: ./scripts/print-versions.sh
- name: Run test
run: ./day-00-example/test.sh
28 changes: 0 additions & 28 deletions .github/workflows/test.yaml

This file was deleted.

27 changes: 24 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
FROM ubuntu:latest
LABEL github=https://github.com/Arxcis/adventofcode2020

# Apt install all the things
# Configure TZ, so we don't get interactive prompt
ENV TZ=Europe/Kiev
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

RUN apt update && apt install -yqq\
curl\
unzip;

# Tell ubuntu that we want to install node from nodesource
RUN curl -sL https://deb.nodesource.com/setup_15.x | bash -

# Install all the things
RUN apt update && apt install -yqq\
# python3 v3.8.6
python3\
python-is-python3\
;
# golang 1.14
golang\
# nodejs v15.x
nodejs

# deno v1.5.3
RUN curl -fsSL https://deno.land/x/install/install.sh | sh\
&& mv -v /root/.deno/bin/* /bin/

# @TODO Enable rust support rust v1.48
#RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y\
# && mv -v /root/.cargo/bin/* /bin/
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
test:
echo "hello test"
./day-00-example/test.sh

dockerbuild: Dockerfile
docker build . --tag jonasjso/adventofcode2020

dockerpush:
docker push jonasjso/adventofcode2020:latest

versions:
./scripts/print-versions.sh

.PHONY: dockerbuild dockerpush test
workflows:
./scripts/make-workflows.sh

scaffold:
./scripts/make-scaffold.sh

.PHONY: dockerbuild dockerpush test versions workflows scaffold
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
# adventofcode2020
Solving the 2020 edition of https://adventofcode.com/ in many languages, and test the solutions using Github CI
Solving the 2020 edition of https://adventofcode.com/ in many languages, and test the solutions using Github CI.

## Contributing
1. Make a branch. Example: `git checkout -b jonas/day-03`
2. Write a program, in the language of your choice. Example: `vim day-03/cmd/super-optimized.py`
3. Test your program.

```sh
cat day-03/input | python3 day-03/cmd/super-optimized.py | diff - day-03/output
```

4. Make sure your program is automatically tested by the Github CI, by adding a line of code to `day-03/test.sh`.
*Example line:*
```sh
$DIR/../scripts/test-py.sh $DIR "cmd/super-optimized.py"
```

5. Make a Pull Request to the `main` branch.
6. Get merged!

**How are programs tested?**

Every program gets the `input`-challenge delivered to `stdin`, and every program is expected to answer, by writing the `output`-answer to `stdout`.

```sh
#!/bin/bash
cat input | <run-program> | diff - output
```

**The CI does not support my favourite language. What do I do?**

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.

## Status
![day-00-example](https://github.com/Arxcis/adventofcode2020/workflows/day-00-example/badge.svg)

## References
- Last attempt https://github.com/Arxcis/adventofcode2018/
12 changes: 12 additions & 0 deletions day-00-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# day-00-example

This example-folder sets the precedence, for how the rest of the folders should be laid out.

## --- Part 1 ---

Sum all numbers

## --- Part 2 ---

Sum all odd numbers

16 changes: 16 additions & 0 deletions day-00-example/cmd/main.deno.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { readLines } from "https://deno.land/std@0.78.0/io/bufio.ts";

let sumAll = 0;
let sumOdd = 0;
for await (const line of readLines(Deno.stdin)) {
if (line === "") continue;

const num = parseInt(line);
sumAll += num;
sumOdd += num % 2 === 0 ? 0 : num;
}

// = Answer
console.log(`${sumAll}`);
console.log(`${sumOdd}`);
// ================
27 changes: 27 additions & 0 deletions day-00-example/cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import (
"bufio"
"fmt"
"os"
"strconv"
)

func main() {
scanner := bufio.NewScanner(os.Stdin)

var sumAll int64 = 0
var sumOdd int64 = 0
for scanner.Scan() {
line := scanner.Text()
num, _ := strconv.ParseInt(line, 10, 64)
sumAll += num

if num%2 != 0 {
sumOdd += num
}
}

fmt.Println(sumAll)
fmt.Println(sumOdd)
}
19 changes: 19 additions & 0 deletions day-00-example/cmd/main.node.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import readline from "readline";

const lines = readline.createInterface({
input: process.stdin,
});

let sumAll = 0;
let sumOdd = 0;
for await (const line of lines) {
const num = parseInt(line);
sumAll += num;
sumOdd += num % 2 === 0 ? 0 : num

}

// = Answer
console.log(`${sumAll}`)
console.log(`${sumOdd}`)
// ================
18 changes: 18 additions & 0 deletions day-00-example/cmd/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env python3
#-*- coding:utf-8 -*-

import fileinput

sum_all = 0
sum_odd = 0

for line in fileinput.input():
num = int(line)
sum_all += num
if num % 2 != 0:
sum_odd += num

# = Answer
print(str(sum_all))
print(str(sum_odd))
# ================
8 changes: 8 additions & 0 deletions day-00-example/input
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
1
2
3
4
8
12
3000
28731
2 changes: 2 additions & 0 deletions day-00-example/output
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
31761
28735
8 changes: 8 additions & 0 deletions day-00-example/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
DIR=$(dirname $(realpath $0))

# Run tests
$DIR/../scripts/test-deno.sh $DIR "cmd/main.deno.ts"
$DIR/../scripts/test-go.sh $DIR "cmd/main.go"
$DIR/../scripts/test-node.sh $DIR "cmd/main.node.mjs"
$DIR/../scripts/test-py.sh $DIR "cmd/main.py"
34 changes: 34 additions & 0 deletions scripts/make-scaffold.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

for i in {01,02}
do
mkdir -p "./day-$i/cmd"
cat > "./day-$i/cmd/.keep" << KEEP
KEEP

cat > "./day-$i/README.md" << README
# day-$i
## --- Part 1 ---
## --- Part 2 ---
README

cat > "./day-$i/input" << INPUT
<insert input>
INPUT

cat > "./day-$i/output" << OUTPUT
<insert output>
OUTPUT

cat > "./day-$i/test.sh" << 'TEST'
#!/bin/bash
set -e
DIR=$(dirname $(realpath $0))

# Run tests
# Example: $DIR/../scripts/test-deno.sh $DIR ./cmd/main.deno.ts
TEST

chmod +x ./day-$i/test.sh
done

24 changes: 24 additions & 0 deletions scripts/make-workflows.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

for i in {01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24}
do
cat > "./.github/workflows/day-$i.yaml" << WORKFLOW
name: day-${i}
on:
push:
paths:
- 'day-${i}/**'

jobs:
test:
runs-on: ubuntu-latest
container:
image: jonasjso/adventofcode2020
steps:
- uses: actions/checkout@v2
- name: Print versions
run: ./scripts/print-versions.sh
- name: Run test
run: ./day-${i}/test.sh
WORKFLOW
done
18 changes: 16 additions & 2 deletions scripts/print-versions.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
#!/bin/bash
echo ""
echo "$ uname -a"
uname -a
echo ""

echo "$ deno --version"
deno --version
echo ""

echo "$ go version"
go version
echo ""

echo "$ node --version"
node --version
echo ""

echo "$ python3 --version"
python3 --version
echo ""
python --version
11 changes: 11 additions & 0 deletions scripts/test-deno.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -e

# Usage: ../test-deno.sh DIR CMD
# Example: ../test-deno.sh /adventofcode2020/day-03 cmd/main.deno.ts

DIR=$1
CMD=$2

cat "$DIR/input" | deno run "$DIR/$CMD" | diff - "$DIR/output"
echo "$DIR / deno run $CMD ✅"
11 changes: 11 additions & 0 deletions scripts/test-go.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -e

# Usage: ../test-go.sh DIR CMD
# Example: ../test-go.sh /adventofcode2020/day-03 cmd/main.go

DIR=$1
CMD=$2

cat "$DIR/input" | go run "$DIR/$CMD" | diff - "$DIR/output"
echo "$DIR / go run $CMD ✅"
11 changes: 11 additions & 0 deletions scripts/test-node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -e

# Usage: ../test-node.sh DIR CMD
# Example: ../test-node.sh /adventofcode2020/day-03 cmd/main.node.mjs

DIR=$1
CMD=$2

cat "$DIR/input" | node "$DIR/$CMD" | diff - "$DIR/output"
echo "$DIR / node $CMD ✅"
11 changes: 11 additions & 0 deletions scripts/test-py.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -e

# Usage: ../test-py.sh DIR CMD
# Example: ../test-py.sh /adventofcode2020/day-03 cmd/main.py

DIR=$1
CMD=$2

cat "$DIR/input" | python3 "$DIR/$CMD" | diff - "$DIR/output"
echo "$DIR / python3 $CMD ✅"