Rename shared packages by day instead of vaguely by purpose.

This commit is contained in:
Anna Rose 2018-12-10 01:06:47 -05:00
parent 42cb05ba7f
commit 31f60eca0e
No known key found for this signature in database
GPG Key ID: 8D9ACA841015C59A
22 changed files with 49 additions and 50 deletions

View File

@ -4,15 +4,15 @@ import (
"fmt" "fmt"
"os" "os"
"internal/calibration" "internal/day01"
) )
// Provide a filename as input, get the result on stdout // Provide a filename as input, get the result on stdout
func main() { func main() {
x := 0 x := 0
seen := calibration.Set{} // we don't use this until day01-2, just added here for backwards compatibility seen := day01.Set{} // we don't use this until day01-2, just added here for backwards compatibility
x, _ = calibration.ScanFrequencies(os.Args[1], &seen, x) x, _ = day01.ScanFrequencies(os.Args[1], &seen, x)
fmt.Println("Frequency list scanned, calibration complete: ", x) fmt.Println("Frequency list scanned, calibration complete: ", x)
} }

View File

@ -4,17 +4,17 @@ import (
"fmt" "fmt"
"os" "os"
"internal/calibration" "internal/day01"
) )
// Provide a filename as input, get the result on stdout // Provide a filename as input, get the result on stdout
func main() { func main() {
x := 0 x := 0
found := false found := false
seen := calibration.Set{0: struct{}{}} seen := day01.Set{0: struct{}{}}
for { for {
x, found = calibration.ScanFrequencies(os.Args[1], &seen, x) x, found = day01.ScanFrequencies(os.Args[1], &seen, x)
if found { if found {
break break
} }

View File

@ -3,14 +3,14 @@ package main
import ( import (
"fmt" "fmt"
"internal/fabric" "internal/day03"
"internal/util" "internal/util"
) )
func main() { func main() {
data := util.ReadInput() data := util.ReadInput()
claims, maxX, maxY := fabric.ParseClaims(data) claims, maxX, maxY := day03.ParseClaims(data)
grid := fabric.PopulateGrid(claims, maxX, maxY) grid := day03.PopulateGrid(claims, maxX, maxY)
count := 0 count := 0
for y := 0; y < len(grid); y++ { for y := 0; y < len(grid); y++ {

View File

@ -3,14 +3,14 @@ package main
import ( import (
"fmt" "fmt"
"internal/fabric" "internal/day03"
"internal/util" "internal/util"
) )
func main() { func main() {
data := util.ReadInput() data := util.ReadInput()
claims, maxX, maxY := fabric.ParseClaims(data) claims, maxX, maxY := day03.ParseClaims(data)
fabric.PopulateGrid(claims, maxX, maxY) // ignoring return value because we only want the side effect here day03.PopulateGrid(claims, maxX, maxY) // ignoring return value because we only want the side effect here
id := -1 id := -1
count := 0 count := 0

View File

@ -3,14 +3,14 @@ package main
import ( import (
"fmt" "fmt"
"internal/guards" "internal/day04"
"internal/util" "internal/util"
) )
func main() { func main() {
data := util.ReadInput() data := util.ReadInput()
shifts := guards.ParseInput(data) shifts := day04.ParseInput(data)
guards := guards.BuildGuards(shifts) guards := day04.BuildGuards(shifts)
sleepiest, sleepiestMinute := FindSleepiestData(guards) sleepiest, sleepiestMinute := FindSleepiestData(guards)
@ -19,8 +19,8 @@ func main() {
fmt.Printf("Result: %d\n", sleepiest.ID*sleepiestMinute) fmt.Printf("Result: %d\n", sleepiest.ID*sleepiestMinute)
} }
func FindSleepiestData(data map[int]*guards.Guard) (*guards.Guard, int) { func FindSleepiestData(data map[int]*day04.Guard) (*day04.Guard, int) {
var sleepiest *guards.Guard var sleepiest *day04.Guard
for _, guard := range data { for _, guard := range data {
if sleepiest == nil { if sleepiest == nil {
sleepiest = guard sleepiest = guard

View File

@ -3,14 +3,14 @@ package main
import ( import (
"fmt" "fmt"
"internal/guards" "internal/day04"
"internal/util" "internal/util"
) )
func main() { func main() {
data := util.ReadInput() data := util.ReadInput()
shifts := guards.ParseInput(data) shifts := day04.ParseInput(data)
guards := guards.BuildGuards(shifts) guards := day04.BuildGuards(shifts)
sleepiest, sleepiestMinute := FindSleepiestData(guards) sleepiest, sleepiestMinute := FindSleepiestData(guards)
@ -19,8 +19,8 @@ func main() {
fmt.Printf("Result: %d\n", sleepiest.ID*sleepiestMinute) fmt.Printf("Result: %d\n", sleepiest.ID*sleepiestMinute)
} }
func FindSleepiestData(data map[int]*guards.Guard) (*guards.Guard, int) { func FindSleepiestData(data map[int]*day04.Guard) (*day04.Guard, int) {
var sleepiest *guards.Guard var sleepiest *day04.Guard
var minute, value int var minute, value int
for _, guard := range data { for _, guard := range data {

View File

@ -3,12 +3,12 @@ package main
import ( import (
"fmt" "fmt"
"internal/polymer" "internal/day05"
"internal/util" "internal/util"
) )
func main() { func main() {
data := util.ReadInputBytes() data := util.ReadInputBytes()
result := polymer.ApplyReactions(data) result := day05.ApplyReactions(data)
fmt.Println(len(result)) fmt.Println(len(result))
} }

View File

@ -3,7 +3,7 @@ package main
import ( import (
"fmt" "fmt"
"internal/polymer" "internal/day05"
"internal/util" "internal/util"
) )
@ -12,8 +12,8 @@ func main() {
result := [26][]byte{} result := [26][]byte{}
for i := 0; i < 26; i++ { for i := 0; i < 26; i++ {
result[i] = polymer.StripElement(data, rune('a'+i)) result[i] = day05.StripElement(data, rune('a'+i))
result[i] = polymer.ApplyReactions(result[i]) result[i] = day05.ApplyReactions(result[i])
} }
shortest := len(result[0]) shortest := len(result[0])

View File

@ -3,15 +3,15 @@ package main
import ( import (
"fmt" "fmt"
"internal/coords" "internal/day06"
"internal/util" "internal/util"
) )
func main() { func main() {
data := util.ReadInput() data := util.ReadInput()
points := coords.ParsePoints(data) points := day06.ParsePoints(data)
coords.ComputeRectilinearAreas(points) day06.ComputeRectilinearAreas(points)
biggest := points[0] biggest := points[0]
for _, point := range points { for _, point := range points {

View File

@ -3,14 +3,14 @@ package main
import ( import (
"fmt" "fmt"
"internal/coords" "internal/day06"
"internal/util" "internal/util"
) )
func main() { func main() {
data := util.ReadInput() data := util.ReadInput()
points := coords.ParsePoints(data) points := day06.ParsePoints(data)
area := coords.ComputeNearnessRegion(points, 10000) area := day06.ComputeNearnessRegion(points, 10000)
fmt.Println(area) fmt.Println(area)
} }

View File

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"strings" "strings"
"internal/tree" "internal/day07"
"internal/util" "internal/util"
) )
@ -12,10 +12,10 @@ func main() {
data := util.ReadInput() data := util.ReadInput()
// Build a tree of dependencies. // Build a tree of dependencies.
root := tree.BuildDependencyTree(data) root := day07.BuildDependencyTree(data)
// Walk the tree and determine the correct ordering. // Walk the tree and determine the correct ordering.
order := tree.FindOrder(root) order := day07.FindOrder(root)
output := strings.Builder{} output := strings.Builder{}
for _, node := range order { for _, node := range order {

View File

@ -3,7 +3,7 @@ package main
import ( import (
"fmt" "fmt"
"internal/tree" "internal/day07"
"internal/util" "internal/util"
) )
@ -11,9 +11,9 @@ func main() {
data := util.ReadInput() data := util.ReadInput()
// Build a tree of dependencies. // Build a tree of dependencies.
root := tree.BuildDependencyTree(data) root := day07.BuildDependencyTree(data)
// Build // Build
time := tree.SimulateConstruction(root) time := day07.SimulateConstruction(root)
fmt.Println(time) fmt.Println(time)
} }

View File

@ -1,4 +1,4 @@
package calibration package day01
import ( import (
"bufio" "bufio"

View File

@ -1,5 +1,4 @@
// Used by both parts of day 03 package day03
package fabric
import ( import (
"strconv" "strconv"

View File

@ -1,4 +1,4 @@
package guards package day04
import ( import (
"sort" "sort"

View File

@ -1,5 +1,5 @@
// Functions for operating on polymers from day 5. // Functions for operating on polymers from day 5.
package polymer package day05
import ( import (
"bytes" "bytes"

View File

@ -1,4 +1,4 @@
package coords package day06
import ( import (
"strconv" "strconv"

View File

@ -1,7 +1,7 @@
// BreadthFirstOrder and its companion functions ended up not giving the // BreadthFirstOrder and its companion functions ended up not giving the
// right solution, but I'm leaving them here as a useful generic tree // right solution, but I'm leaving them here as a useful generic tree
// algorithm. // algorithm.
package tree package day07
func BreadthFirstOrder(root *Node) []*Node { func BreadthFirstOrder(root *Node) []*Node {
seen := make(map[rune]bool) seen := make(map[rune]bool)

View File

@ -1,4 +1,4 @@
package tree package day07
func SimulateConstruction(root *Node) int { func SimulateConstruction(root *Node) int {
working := make(map[rune]*Node) working := make(map[rune]*Node)

View File

@ -1,4 +1,4 @@
package tree package day07
import ( import (
"fmt" "fmt"

View File

@ -1,4 +1,4 @@
package tree package day07
// FindOrder determines the correct order according to these rules: // FindOrder determines the correct order according to these rules:
// 1. A node cannot come before all of its parents have been included. // 1. A node cannot come before all of its parents have been included.

View File

@ -1,4 +1,4 @@
package tree package day07
import ( import (
"regexp" "regexp"