Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kylehoehns committed Nov 20, 2023
0 parents commit 546e9b2
Show file tree
Hide file tree
Showing 16 changed files with 565 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "Go",
"image": "mcr.microsoft.com/devcontainers/go:0-1.21-bullseye",
"portsAttributes": {
"9000": {
"label": "Hello Remote World",
"onAutoForward": "notify"
}
}
}
25 changes: 25 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Build and Test

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.21

- name: Build
run: go build -v ./...

- name: Test
run: go test -v ./...
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

.idea

.DS_Store
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 🎄 Advent of Code 2023 🎄

Working through problems for [Advent of Code 2023](https://adventofcode.com/2023).

Using [Go](https://go.dev/)

## Running

Use VS Code and open this project in a [Dev Container](https://code.visualstudio.com/docs/devcontainers/containers) without needing to install any tooling locally.

Inside the container, run the following command to test a given day's problem.

```shell
go test ./puzzles/day00
```

To run the given puzzle input for the day.

```shell
go run puzzles/day00/main.go
```
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/kylehoehns/aoc-2023-go

go 1.21
200 changes: 200 additions & 0 deletions puzzles/day00/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
1864
1192
1802
1850
1986
1514
1620
1910
1557
1529
1081
1227
1869
1545
1064
1509
1060
1590
1146
1855
667
1441
1241
1473
1321
1429
1534
1959
1188
1597
1256
1673
1879
1821
1423
1838
1392
1941
1124
1629
1780
1271
1190
1680
1379
1601
1670
1916
1787
1844
2000
1672
1276
1896
1746
1369
1687
1263
1948
1159
1710
1304
1806
1709
1286
1635
1075
1125
1607
1408
1903
1143
1736
1266
1645
1571
1488
1200
211
1148
1585
2005
1724
1071
1690
1189
1101
1315
1452
1622
1074
1486
1209
1253
1422
1235
1354
1399
1675
241
1229
1136
1901
1453
1344
1685
1985
1455
1764
1634
1935
1386
1772
1174
1743
1818
1156
1221
167
1398
1552
1816
1197
1829
1930
1812
1983
1185
1579
1928
1892
1978
1720
1584
1506
1245
1539
1653
1876
1883
1982
1114
1406
2002
1765
1175
1947
1519
1943
1566
1361
1830
1679
999
1366
1575
1556
1555
1065
1606
1508
1548
1162
1664
1525
1925
1975
1384
1076
1790
1656
1578
1671
1424
757
1485
1677
1583
1395
1793
1111
1522
1195
1128
1123
1151
1568
1559
1331
1191
1753
1630
1979
953
1480
1655
1100
1419
1560
1667
47 changes: 47 additions & 0 deletions puzzles/day00/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package main

import (
"fmt"
"strconv"

"github.com/kylehoehns/aoc-2023-go/utils/files"
)

// Example using 2020 Day 1 https://adventofcode.com/2020/day/1
func main() {
lines := files.ReadLines("input.txt")
var expenses []int
for _, line := range lines {
i, err := strconv.Atoi(line)
if err != nil {
panic(err)
}
expenses = append(expenses, i)
}
fmt.Println("Part 1: ", part1(expenses))
fmt.Println("Part 2: ", part2(expenses))
}

func part1(expenses []int) int {
for i, first := range expenses {
for j, second := range expenses {
if i < j && first+second == 2020 {
return first * second
}
}
}
return -1
}

func part2(expenses []int) int {
for _, first := range expenses {
for _, second := range expenses {
for _, third := range expenses {
if first+second+third == 2020 {
return first * second * third
}
}
}
}
return -1
}
31 changes: 31 additions & 0 deletions puzzles/day00/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package main

import "testing"

func TestPart1(t *testing.T) {

t.Run("Part 1", func(t *testing.T) {

expenses := []int{1721, 979, 366, 299, 675, 1456}
actual := part1(expenses)
expected := 514579
if actual != expected {
t.Errorf("Expected %d but actual was %d", expected, actual)
}
})

}

func TestPart2(t *testing.T) {

t.Run("Part 2", func(t *testing.T) {

expenses := []int{1721, 979, 366, 299, 675, 1456}
actual := part2(expenses)
expected := 241861950
if actual != expected {
t.Errorf("Expected %d but actual was %d", expected, actual)
}
})

}
Loading

0 comments on commit 546e9b2

Please sign in to comment.