diff --git a/internal/puzzles/solutions/2016/day03/solution.go b/internal/puzzles/solutions/2016/day03/solution.go new file mode 100644 index 00000000..cb6a0d9b --- /dev/null +++ b/internal/puzzles/solutions/2016/day03/solution.go @@ -0,0 +1,30 @@ +// Package day03 contains solution for https://adventofcode.com/2016/day/3 puzzle. +package day03 + +import ( + "io" + + "github.com/obalunenko/advent-of-code/internal/puzzles" +) + +func init() { + puzzles.Register(solution{}) +} + +type solution struct{} + +func (s solution) Year() string { + return puzzles.Year2016.String() +} + +func (s solution) Day() string { + return puzzles.Day03.String() +} + +func (s solution) Part1(input io.Reader) (string, error) { + return "", puzzles.ErrNotImplemented +} + +func (s solution) Part2(input io.Reader) (string, error) { + return "", puzzles.ErrNotImplemented +} diff --git a/internal/puzzles/solutions/2016/day03/solution_test.go b/internal/puzzles/solutions/2016/day03/solution_test.go new file mode 100644 index 00000000..0d9b6ef7 --- /dev/null +++ b/internal/puzzles/solutions/2016/day03/solution_test.go @@ -0,0 +1,123 @@ +package day03 + +import ( + "errors" + "io" + "strings" + "testing" + "testing/iotest" + + "github.com/stretchr/testify/assert" +) + +func Test_solution_Year(t *testing.T) { + var s solution + + want := "2016" + got := s.Year() + + assert.Equal(t, want, got) +} + +func Test_solution_Day(t *testing.T) { + var s solution + + want := "3" + got := s.Day() + + assert.Equal(t, want, got) +} + +func Test_solution_Part1(t *testing.T) { + var s solution + + type args struct { + input io.Reader + } + + tests := []struct { + name string + args args + want string + wantErr assert.ErrorAssertionFunc + }{ + { + name: "test example from description", + args: args{ + input: strings.NewReader("5 10 25\n"), + }, + want: "0", + wantErr: assert.NoError, + }, + { + name: "test example from description", + args: args{ + input: strings.NewReader("5 10 7\n"), + }, + want: "1", + wantErr: assert.NoError, + }, + { + name: "", + args: args{ + input: iotest.ErrReader(errors.New("custom error")), + }, + want: "", + wantErr: assert.Error, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := s.Part1(tt.args.input) + if !tt.wantErr(t, err) { + return + } + + assert.Equal(t, tt.want, got) + }) + } +} + +func Test_solution_Part2(t *testing.T) { + var s solution + + type args struct { + input io.Reader + } + + tests := []struct { + name string + args args + want string + wantErr assert.ErrorAssertionFunc + }{ + { + name: "test example from description", + args: args{ + input: strings.NewReader(""), + }, + want: "230", + wantErr: assert.NoError, + }, + { + name: "", + args: args{ + input: iotest.ErrReader(errors.New("custom error")), + }, + want: "", + wantErr: assert.Error, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := s.Part2(tt.args.input) + if !tt.wantErr(t, err) { + return + } + + assert.Equal(t, tt.want, got) + }) + } +} diff --git a/internal/puzzles/solutions/2016/day03/spec.md b/internal/puzzles/solutions/2016/day03/spec.md new file mode 100644 index 00000000..779022a4 --- /dev/null +++ b/internal/puzzles/solutions/2016/day03/spec.md @@ -0,0 +1,18 @@ +# --- Day 3: Squares With Three Sides --- + +## --- Part One --- + +Now that you can think clearly, you move deeper into the labyrinth of hallways and office furniture that makes up this +part of Easter Bunny HQ. This must be a graphic design department; the walls are covered in specifications for +triangles. + +Or are they? + +The design document gives the side lengths of each triangle it describes, but... `5 10 25`? +Some of these aren't triangles. You can't help but mark the impossible ones. + +In a valid triangle, the sum of any two sides must be larger than the remaining side. + +For example, the "triangle" given above is impossible, because `5 + 10` is not larger than `25`. + +In your puzzle input, how many of the listed triangles are possible? \ No newline at end of file diff --git a/internal/puzzles/solutions/register_2016.go b/internal/puzzles/solutions/register_2016.go index 702bca8e..ec2b59c4 100644 --- a/internal/puzzles/solutions/register_2016.go +++ b/internal/puzzles/solutions/register_2016.go @@ -8,4 +8,6 @@ import ( _ "github.com/obalunenko/advent-of-code/internal/puzzles/solutions/2016/day01" // register day02 solution. _ "github.com/obalunenko/advent-of-code/internal/puzzles/solutions/2016/day02" + // register day03 solution. + _ "github.com/obalunenko/advent-of-code/internal/puzzles/solutions/2016/day03" )