day10

package
v0.0.0-...-aa75ebd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 9, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Example string
View Source
var Example2 string

Functions

This section is empty.

Types

type Day10

type Day10 struct {
	// contains filtered or unexported fields
}

func (*Day10) Parse

func (d *Day10) Parse(input string)

func (*Day10) ParseExample

func (d *Day10) ParseExample()

func (*Day10) ParseExample2

func (d *Day10) ParseExample2()

func (*Day10) Part1

func (d *Day10) Part1() any

func (*Day10) Part2

func (d *Day10) Part2() any

Part2 calculates the enclosed tiles using the shoelace formula and Pick's theorem. Pick's theorem can be rearranged to give

interiorPoints = area - perimeter/2 + 1

The perimeter is equal to the number of pipes in the loop, as each pipe is one unit apart. The area can be calculated using the shoelace formula

area = abs(sum(x_i*y_{i+1} - x_{i+1}*y_i)))/2

Credit to all the users on the reddit solutions thread for the idea

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL