From 01f53ae30cd55e306d33b52d0b5258421d476743 Mon Sep 17 00:00:00 2001
From: Anna Wiggins <annabunches@gmail.com>
Date: Sat, 1 Dec 2018 22:13:08 -0500
Subject: [PATCH] Re-implement a solution for the first day 1 puzzle, move
 common code into a library package.

---
 2018/day01-1.go                               | 18 +++++++++++++
 2018/day01-2.go                               | 25 +++++++++++++++++++
 .../calibration/calibration.go}               | 20 +--------------
 3 files changed, 44 insertions(+), 19 deletions(-)
 create mode 100644 2018/day01-1.go
 create mode 100644 2018/day01-2.go
 rename 2018/{day01.go => internal/calibration/calibration.go} (70%)

diff --git a/2018/day01-1.go b/2018/day01-1.go
new file mode 100644
index 0000000..6ab6bbc
--- /dev/null
+++ b/2018/day01-1.go
@@ -0,0 +1,18 @@
+package main
+
+import (
+	"fmt"
+	"os"
+
+	"internal/calibration"
+)
+
+// Provide a filename as input, get the result on stdout
+func main() {
+	x := 0
+	seen := calibration.Set{} // we don't use this until day01-2, just added here for backwards compatibility
+
+	x, _ = calibration.ScanFrequencies(os.Args[1], &seen, x)
+
+	fmt.Println("Frequency list scanned, calibration complete: ", x)
+}
diff --git a/2018/day01-2.go b/2018/day01-2.go
new file mode 100644
index 0000000..69fa62b
--- /dev/null
+++ b/2018/day01-2.go
@@ -0,0 +1,25 @@
+package main
+
+import (
+	"fmt"
+	"os"
+
+	"internal/calibration"
+)
+
+// Provide a filename as input, get the result on stdout
+func main() {
+	x := 0
+	found := false
+	seen := calibration.Set{0: struct{}{}}
+
+	for {
+		x, found = calibration.ScanFrequencies(os.Args[1], &seen, x)
+		if found {
+			break
+		}
+		fmt.Println("All frequencies scanned, repeating...")
+	}
+
+	fmt.Println("Repeat frequency detected, calibration complete: ", x)
+}
diff --git a/2018/day01.go b/2018/internal/calibration/calibration.go
similarity index 70%
rename from 2018/day01.go
rename to 2018/internal/calibration/calibration.go
index fa4e26d..b11311b 100644
--- a/2018/day01.go
+++ b/2018/internal/calibration/calibration.go
@@ -1,31 +1,13 @@
-package main
+package calibration
 
 import (
 	"bufio"
-	"fmt"
 	"os"
 	"strconv"
 )
 
 type Set map[int]struct{}
 
-// Provide a filename as input, get the result on stdout
-func main() {
-	x := 0
-	found := false
-	seen := Set{0: struct{}{}}
-
-	for {
-		x, found = ScanFrequencies(os.Args[1], &seen, x)
-		if found {
-			break
-		}
-		fmt.Println("All frequencies scanned, repeating...")
-	}
-
-	fmt.Println("Repeat frequency detected, calibration complete: ", x)
-}
-
 // ScanFrequencies iterates over a list of frequencies (provided as an open
 // file handle), compares against a list of frequencies already seen and a 'current' frequency counter,
 // and returns `true` when a duplicate frequency is found. Integer value returned is the new, adjusted frequency