Skip to content

Commit

Permalink
move 2023 to subdir
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytro-spivakov committed Dec 1, 2024
1 parent d6c20e8 commit ab6db6b
Show file tree
Hide file tree
Showing 81 changed files with 215 additions and 55 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
121 changes: 121 additions & 0 deletions 2023/day19/day19.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package day19

import (
"bufio"
"log"
"os"
"regexp"
"strconv"
"strings"
)

type Part struct {
x int
m int
a int
s int
}

func (p *Part) getVal(field string) int {
switch field {
case "x":
return (*p).x
case "m":
return (*p).m
case "a":
return (*p).a
case "s":
return (*p).s
}

log.Fatalf("Part.getVal() unknown field %s\n", field)
return -1
}

type RuleSet struct {
name string
rawInput string
workflowSteps []func()
}

func (rs *RuleSet) init() {
// parse `rawInput` and populate `workflowSteps`
}

func Solution1(filepath string) int {
return -1
}

func Solution2(filepath string) int {
return -1
}

func parseInput(filepath string) ([]RuleSet, []Part) {
var ruleSets []RuleSet
var parts []Part

file, err := os.Open(filepath)
if err != nil {
log.Fatalf("Failed to open the input file: %v\n", err.Error())
}
scanner := bufio.NewScanner(file)
for scanner.Scan() {
currentLine := scanner.Text()

if strings.HasPrefix(currentLine, "{") {
parts = append(parts, parsePart(currentLine))
} else {
ruleSets = append(ruleSets, parseRuleSet(currentLine))
}
}
if err = scanner.Err(); err != nil {
log.Fatalf("Error during input file read: %v\n", err.Error())
}

return ruleSets, parts
}

func parseRuleSet(rawInput string) RuleSet {
// name := strings.Split(rawInput, "{")[0]
// ruleSet := RuleSet{
// name: name,
// rawInput: rawInput,
// }
// ruleSegments := strings.Split(rawInput, ",")
// var rules []func()
// for _, ruleSeg := range ruleSegments {
// samples:
// a<10:gd - conditinal transition
// A - unconditional transition

// rule func signature func(p Part) (applied bool, transitTo string)
// }

// return ruleSet
return RuleSet{}
}

func parsePart(rawInput string) Part {
numRegex := regexp.MustCompile(`\d+`)
matches := numRegex.FindAllString(rawInput, -1)
if len(matches) != 4 {
log.Fatalf("Failed to parse Part properly: input=%v, matches=%v\n", rawInput, matches)
}

// fields are always specified in the same order in the input
return Part{
x: parseInt(matches[0]),
m: parseInt(matches[1]),
a: parseInt(matches[2]),
s: parseInt(matches[3]),
}
}

func parseInt(strNum string) int {
num, err := strconv.ParseInt(strNum, 10, 64)
if err != nil {
log.Fatalf("Failed to parse number %v with %v\n", strNum, err.Error())
}

return int(num)
}
18 changes: 18 additions & 0 deletions 2023/day19/day19_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package day19

import (
"github.com/stretchr/testify/assert"
"testing"
)

func TestSolution1(t *testing.T) {
cases := map[string]int{
"test_input11": 19114,
}

for input, expectedResult := range cases {
result := Solution1(input)

assert.Equal(t, expectedResult, result, "Solution1()")
}
}
17 changes: 17 additions & 0 deletions 2023/day19/test_input11
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
px{a<2006:qkq,m>2090:A,rfg}
pv{a>1716:R,A}
lnx{m>1548:A,A}
rfg{s<537:gd,x>2440:R,A}
qs{s>3448:A,lnx}
qkq{x<1416:A,crn}
crn{x>2662:A,R}
in{s<1351:px,qqz}
qqz{s>2770:qs,m<1801:hdj,R}
gd{a>3333:R,R}
hdj{m>838:A,pv}

{x=787,m=2655,a=1222,s=2876}
{x=1679,m=44,a=2067,s=496}
{x=2036,m=264,a=79,s=2244}
{x=2461,m=1339,a=466,s=291}
{x=2127,m=1623,a=2188,s=1013}
114 changes: 59 additions & 55 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
package main

import (
"advent-of-code/day01"
"advent-of-code/day02"
"advent-of-code/day03"
"advent-of-code/day04"
"advent-of-code/day05"
"advent-of-code/day06"
"advent-of-code/day07"
"advent-of-code/day08"
"advent-of-code/day09"
"advent-of-code/day10"
"advent-of-code/day11"
"advent-of-code/day12"
"advent-of-code/day13"
"advent-of-code/day14"
"advent-of-code/day15"
"advent-of-code/day16"
"advent-of-code/day17"
"advent-of-code/day18"
aoc2023day01 "advent-of-code/2023/day01"
aoc2023day02 "advent-of-code/2023/day02"
aoc2023day03 "advent-of-code/2023/day03"
aoc2023day04 "advent-of-code/2023/day04"
aoc2023day05 "advent-of-code/2023/day05"
aoc2023day06 "advent-of-code/2023/day06"
aoc2023day07 "advent-of-code/2023/day07"
aoc2023day08 "advent-of-code/2023/day08"
aoc2023day09 "advent-of-code/2023/day09"
aoc2023day10 "advent-of-code/2023/day10"
aoc2023day11 "advent-of-code/2023/day11"
aoc2023day12 "advent-of-code/2023/day12"
aoc2023day13 "advent-of-code/2023/day13"
aoc2023day14 "advent-of-code/2023/day14"
aoc2023day15 "advent-of-code/2023/day15"
aoc2023day16 "advent-of-code/2023/day16"
aoc2023day17 "advent-of-code/2023/day17"
aoc2023day18 "advent-of-code/2023/day18"
aoc2023day19 "advent-of-code/2023/day19"
"fmt"
"time"
)
Expand All @@ -27,61 +28,64 @@ func runSolution(day, part int, s func() int) {
start := time.Now()
res := s()
elapsed := time.Since(start)
fmt.Printf("Day %d, solution %d: %v - %v\n", day, part, res, elapsed.Round(time.Microsecond))
fmt.Printf("Day %02d, solution %d: %v - %v\n", day, part, res, elapsed.Round(time.Microsecond))
}

func main() {
runSolution(1, 1, func() int { return day01.Solution1("inputs/day01") })
runSolution(1, 2, func() int { return day01.Solution2("inputs/day01") })
runSolution(1, 1, func() int { return aoc2023day01.Solution1("2023/inputs/day01") })
runSolution(1, 2, func() int { return aoc2023day01.Solution2("2023/inputs/day01") })

runSolution(2, 1, func() int { return day02.Solution1("inputs/day02") })
runSolution(2, 2, func() int { return day02.Solution2("inputs/day02") })
runSolution(2, 1, func() int { return aoc2023day02.Solution1("2023/inputs/day02") })
runSolution(2, 2, func() int { return aoc2023day02.Solution2("2023/inputs/day02") })

runSolution(3, 1, func() int { return day03.Solution1("inputs/day03") })
runSolution(3, 2, func() int { return day03.Solution2("inputs/day03") })
runSolution(3, 1, func() int { return aoc2023day03.Solution1("2023/inputs/day03") })
runSolution(3, 2, func() int { return aoc2023day03.Solution2("2023/inputs/day03") })

runSolution(4, 1, func() int { return day04.Solution1("inputs/day04") })
runSolution(4, 2, func() int { return day04.Solution2("inputs/day04") })
runSolution(4, 1, func() int { return aoc2023day04.Solution1("2023/inputs/day04") })
runSolution(4, 2, func() int { return aoc2023day04.Solution2("2023/inputs/day04") })

runSolution(5, 1, func() int { return day05.Solution1("inputs/day05") })
runSolution(5, 2, func() int { return day05.Solution2("inputs/day05") })
runSolution(5, 1, func() int { return aoc2023day05.Solution1("2023/inputs/day05") })
runSolution(5, 2, func() int { return aoc2023day05.Solution2("2023/inputs/day05") })

runSolution(6, 1, func() int { return day06.Solution1("inputs/day06") })
runSolution(6, 2, func() int { return day06.Solution2("inputs/day06") })
runSolution(6, 1, func() int { return aoc2023day06.Solution1("2023/inputs/day06") })
runSolution(6, 2, func() int { return aoc2023day06.Solution2("2023/inputs/day06") })

runSolution(7, 1, func() int { return day07.Solution1("inputs/day07") })
runSolution(7, 2, func() int { return day07.Solution2("inputs/day07") })
runSolution(7, 1, func() int { return aoc2023day07.Solution1("2023/inputs/day07") })
runSolution(7, 2, func() int { return aoc2023day07.Solution2("2023/inputs/day07") })

runSolution(8, 1, func() int { return day08.Solution1("inputs/day08") })
runSolution(8, 2, func() int { return day08.Solution2("inputs/day08") })
runSolution(8, 1, func() int { return aoc2023day08.Solution1("2023/inputs/day08") })
runSolution(8, 2, func() int { return aoc2023day08.Solution2("2023/inputs/day08") })

runSolution(9, 1, func() int { return day09.Solution1("inputs/day09") })
runSolution(9, 2, func() int { return day09.Solution2("inputs/day09") })
runSolution(9, 1, func() int { return aoc2023day09.Solution1("2023/inputs/day09") })
runSolution(9, 2, func() int { return aoc2023day09.Solution2("2023/inputs/day09") })

runSolution(10, 1, func() int { return day10.Solution1("inputs/day10") })
runSolution(10, 2, func() int { return day10.Solution2("inputs/day10") })
runSolution(10, 1, func() int { return aoc2023day10.Solution1("2023/inputs/day10") })
runSolution(10, 2, func() int { return aoc2023day10.Solution2("2023/inputs/day10") })

runSolution(11, 1, func() int { return day11.Solution1("inputs/day11") })
runSolution(11, 2, func() int { return day11.Solution2("inputs/day11") })
runSolution(11, 1, func() int { return aoc2023day11.Solution1("2023/inputs/day11") })
runSolution(11, 2, func() int { return aoc2023day11.Solution2("2023/inputs/day11") })

runSolution(12, 1, func() int { return day12.Solution1("inputs/day12") })
runSolution(12, 2, func() int { return day12.Solution2("inputs/day12") })
runSolution(12, 1, func() int { return aoc2023day12.Solution1("2023/inputs/day12") })
runSolution(12, 2, func() int { return aoc2023day12.Solution2("2023/inputs/day12") })

runSolution(13, 1, func() int { return day13.Solution1("inputs/day13") })
runSolution(13, 2, func() int { return day13.Solution2("inputs/day13") })
runSolution(13, 1, func() int { return aoc2023day13.Solution1("2023/inputs/day13") })
runSolution(13, 2, func() int { return aoc2023day13.Solution2("2023/inputs/day13") })

runSolution(14, 1, func() int { return day14.Solution1("inputs/day14") })
runSolution(14, 2, func() int { return day14.Solution2("inputs/day14") })
runSolution(14, 1, func() int { return aoc2023day14.Solution1("2023/inputs/day14") })
runSolution(14, 2, func() int { return aoc2023day14.Solution2("2023/inputs/day14") })

runSolution(15, 1, func() int { return day15.Solution1("inputs/day15") })
runSolution(15, 2, func() int { return day15.Solution2("inputs/day15") })
runSolution(15, 1, func() int { return aoc2023day15.Solution1("2023/inputs/day15") })
runSolution(15, 2, func() int { return aoc2023day15.Solution2("2023/inputs/day15") })

runSolution(16, 1, func() int { return day16.Solution1("inputs/day16") })
runSolution(16, 2, func() int { return day16.Solution2("inputs/day16") })
runSolution(16, 1, func() int { return aoc2023day16.Solution1("2023/inputs/day16") })
runSolution(16, 2, func() int { return aoc2023day16.Solution2("2023/inputs/day16") })

runSolution(17, 1, func() int { return day17.Solution1("inputs/day17") })
runSolution(17, 2, func() int { return day17.Solution2("inputs/day17") })
runSolution(17, 1, func() int { return aoc2023day17.Solution1("2023/inputs/day17") })
runSolution(17, 2, func() int { return aoc2023day17.Solution2("2023/inputs/day17") })

runSolution(18, 1, func() int { return day18.Solution1("inputs/day18") })
runSolution(18, 2, func() int { return day18.Solution2("inputs/day18") })
runSolution(18, 1, func() int { return aoc2023day18.Solution1("2023/inputs/day18") })
runSolution(18, 2, func() int { return aoc2023day18.Solution2("2023/inputs/day18") })

runSolution(19, 1, func() int { return aoc2023day19.Solution1("2023/inputs/day19") })
runSolution(19, 2, func() int { return aoc2023day19.Solution2("2023/inputs/day19") })
}

0 comments on commit ab6db6b

Please sign in to comment.