added day4 part 1
This commit is contained in:
parent
7b65e60352
commit
d778165476
10 changed files with 1138 additions and 36 deletions
|
@ -39,11 +39,6 @@ func ConvertToUsefulData(s []string) [][]uint {
|
||||||
func main() {
|
func main() {
|
||||||
result := Part1(ConvertToUsefulData(GetData("./data")))
|
result := Part1(ConvertToUsefulData(GetData("./data")))
|
||||||
fmt.Printf("The Power consumption is: %d\n", result)
|
fmt.Printf("The Power consumption is: %d\n", result)
|
||||||
|
|
||||||
oxy, co2 := Part2(ConvertToUsefulData(GetData("./test-data")))
|
|
||||||
for _, f := range data {
|
|
||||||
fmt.Println(f)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Part1(data [][]uint) uint {
|
func Part1(data [][]uint) uint {
|
||||||
|
@ -83,40 +78,12 @@ func dataSliceConvert(data [][]uint) [][]uint {
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
func WhichIsMore(data []uint) int {
|
func OxygenRate(data [][]uint) uint {
|
||||||
dict := make(map[uint]uint)
|
|
||||||
for _, entry := range data {
|
|
||||||
dict[entry] = dict[entry] + 1
|
|
||||||
}
|
|
||||||
if dict[0] == dict[1] {
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
if dict[0] < dict[1] {
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
if dict[0] > dict[1] {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
func Co2Rate(data [][]uint) uint {
|
||||||
|
|
||||||
func Cycle(data [][]uint, i int) [][]uint {
|
return 0
|
||||||
var result [][]uint
|
|
||||||
|
|
||||||
test := make([]uint, len(data))
|
|
||||||
for j := range data {
|
|
||||||
test[j] = data[j][i]
|
|
||||||
}
|
|
||||||
more := uint(WhichIsMore(test))
|
|
||||||
//fmt.Println(more)
|
|
||||||
//fmt.Println(test)
|
|
||||||
for _, odata := range data {
|
|
||||||
if odata[i] == more {
|
|
||||||
result = append(result, odata)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Part2(data [][]uint) (uint, uint) {
|
func Part2(data [][]uint) (uint, uint) {
|
||||||
|
|
8
2023/day1/.idea/.gitignore
generated
vendored
Normal file
8
2023/day1/.idea/.gitignore
generated
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
9
2023/day1/.idea/day1.iml
generated
Normal file
9
2023/day1/.idea/day1.iml
generated
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="WEB_MODULE" version="4">
|
||||||
|
<component name="Go" enabled="true" />
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
8
2023/day1/.idea/modules.xml
generated
Normal file
8
2023/day1/.idea/modules.xml
generated
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/day1.iml" filepath="$PROJECT_DIR$/.idea/day1.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
6
2023/day1/.idea/vcs.xml
generated
Normal file
6
2023/day1/.idea/vcs.xml
generated
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
1000
2023/day1/data
Normal file
1000
2023/day1/data
Normal file
File diff suppressed because it is too large
Load diff
3
2023/day1/go.mod
Normal file
3
2023/day1/go.mod
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
module day1
|
||||||
|
|
||||||
|
go 1.21
|
66
2023/day1/main.go
Normal file
66
2023/day1/main.go
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"unicode"
|
||||||
|
)
|
||||||
|
|
||||||
|
var SNUMBER = []string{"one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}
|
||||||
|
|
||||||
|
func readData(s string) []string {
|
||||||
|
var result []string
|
||||||
|
fileReader, err := os.Open(s)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
lines := bufio.NewScanner(fileReader)
|
||||||
|
lines.Split(bufio.ScanLines)
|
||||||
|
for lines.Scan() {
|
||||||
|
result = append(result, lines.Text())
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
func getRealDigits(s string) []int {
|
||||||
|
var result []int
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
}
|
||||||
|
func getDigits(s string) []int {
|
||||||
|
var result []int
|
||||||
|
a := []rune(s)
|
||||||
|
for _, r := range a {
|
||||||
|
if unicode.IsDigit(r) {
|
||||||
|
result = append(result, int(r-'0'))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
func main() {
|
||||||
|
fmt.Println("Goo Fast!")
|
||||||
|
//Part1()
|
||||||
|
Part2()
|
||||||
|
}
|
||||||
|
func Part1() {
|
||||||
|
data := readData("./data")
|
||||||
|
var result int
|
||||||
|
for _, line := range data {
|
||||||
|
d := getDigits(line)
|
||||||
|
fmt.Println(line)
|
||||||
|
number := d[0]*10 + d[len(d)-1]
|
||||||
|
result += number
|
||||||
|
}
|
||||||
|
fmt.Println("the result of part 1 is: ", result)
|
||||||
|
}
|
||||||
|
func Part2() {
|
||||||
|
data := readData("./test-data")
|
||||||
|
var result int
|
||||||
|
for _, line := range data {
|
||||||
|
d := getDigits(line)
|
||||||
|
fmt.Println(line)
|
||||||
|
number := d[0]*10 + d[len(d)-1]
|
||||||
|
result += number
|
||||||
|
}
|
||||||
|
}
|
28
2023/day1/task.txt
Normal file
28
2023/day1/task.txt
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
--- Day 1: Trebuchet?! ---
|
||||||
|
|
||||||
|
Something is wrong with global snow production, and you've been selected to take a look. The Elves have even given you a map; on it, they've used stars to mark the top fifty locations that are likely to be having problems.
|
||||||
|
|
||||||
|
You've been doing this long enough to know that to restore snow operations, you need to check all fifty stars by December 25th.
|
||||||
|
|
||||||
|
Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck!
|
||||||
|
|
||||||
|
You try to ask why they can't just use a weather machine ("not powerful enough") and where they're even sending you ("the sky") and why your map looks mostly blank ("you sure ask a lot of questions") and hang on did you just say the sky ("of course, where do you think snow comes from") when you realize that the Elves are already loading you into a trebuchet ("please hold still, we need to strap you in").
|
||||||
|
|
||||||
|
As they're making the final adjustments, they discover that their calibration document (your puzzle input) has been amended by a very young Elf who was apparently just excited to show off her art skills. Consequently, the Elves are having trouble reading the values on the document.
|
||||||
|
|
||||||
|
The newly-improved calibration document consists of lines of text; each line originally contained a specific calibration value that the Elves now need to recover. On each line, the calibration value can be found by combining the first digit and the last digit (in that order) to form a single two-digit number.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
1abc2
|
||||||
|
pqr3stu8vwx
|
||||||
|
a1b2c3d4e5f
|
||||||
|
treb7uchet
|
||||||
|
|
||||||
|
In this example, the calibration values of these four lines are 12, 38, 15, and 77. Adding these together produces 142.
|
||||||
|
|
||||||
|
Consider your entire calibration document. What is the sum of all of the calibration values?
|
||||||
|
|
||||||
|
To begin, get your puzzle input.
|
||||||
|
|
||||||
|
Answer:
|
7
2023/day1/test-data
Normal file
7
2023/day1/test-data
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
two1nine
|
||||||
|
eightwothree
|
||||||
|
abcone2threexyz
|
||||||
|
xtwone3four
|
||||||
|
4nineeightseven2
|
||||||
|
zoneight234
|
||||||
|
7pqrstsixteen
|
Loading…
Add table
Add a link
Reference in a new issue