advent2022

Advent of Code 2022 Solutions
git clone git://bsandro.tech/advent2022
Log | Files | Refs | README | LICENSE

commit 25b8bbe6203fa094f3e803a69779e4f87db9d6a3
parent d924f349626476d8aaf2adc258dafb23a2866476
Author: bsandro <email@bsandro.tech>
Date:   Sat,  3 Dec 2022 06:16:49 +0000

Day 03 part 1

Diffstat:
Aday03/input.txt | 300+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aday03/main.go | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aday03/sample.txt | 6++++++
3 files changed, 373 insertions(+), 0 deletions(-)

diff --git a/day03/input.txt b/day03/input.txt @@ -0,0 +1,300 @@ +mmbclcsDHCflDDlCrzzrDWjPJvjPvqJPjfpqZQdfWd +NNFLnFRNhgNQtMLSFSgwSwGJPZWLPvjpjjJGZJPvWPvJ +BnwFNgVVhwNwVQrmzbrrCHVTmDsm +CTsVssjPTWPbzhfbfqqpbqJq +RRttdQlRdnNpdmwBnBDhFrGrqDGBqJJfJD +HttgcggdNwQtgcpTsvjVPTcssjsv +bWrpnrpPcFNbfPtwVPddVVDw +jLgqqJgjZLhHjRqLHLjqHgftpmJVtTmwQmtGddwwDVJm +HhzgshZLpHLjqhLLZRZpLRbbrlBNsrrNsFWcCvvFCcNN +PCJJfJhjhzjjdBVBcd +RnNnMHnRNtWnBSQHVbqSzFcq +ZlnZZZNmLrNrgZmmccGJwGwmGPJs +hFZLsjjjMzwPPjqw +SQtTcpWWcpMSDlQpDCQJqbHzdSzPzJvPPwqqvH +tVfpGWGDVlCGGDCpVWppVcrZFMrnmnLfsrBrnngLmMBh +PFPhCmpfhSMWnmgrtgMW +RRQdGQvTQRzQDGQTQcRqTTQLvsntnltvrWZlsWlZftntrMtt +NQTzfGfzcdTBhPJSNJbCCVhJ +sbtqfrqNfcdqsJrfhzQmzhpvzvpQmpNG +SHsSDsZVHBHnRZDBZRWSVDnwFhzvphggwGhQzQhgwzmmPzmg +jjHVHBlHljMsJ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bVGWttmpmbbqDWgVGGGtWNvNCCsHLLFsvHMHHLFnFn +wQQSdDTfSTsLCNnFwvFv +dPDBTBjzDftcBqBVbGBg +LmsfRLwCfZslcjljcjDjwN +gdRSrHHrSbdrggBzHBShHlqVvVDvcNvlcccjGlGjqB +zgTnSFFJdngddTZTPTWmspWQWWPR +RMZMtdsVCsRdddbsVcfcqgNfNDqGqGfzPzmf +BpwQrJvrjnSnQpBBBJCJjBBQlzvmDPzmDmglPzPgDNfNmNgz +LjLTnSpwjQTrnnLCBJLQjhstbMhsRtTdtMHMtbtsZd +PfrPHmrCRmRhcHCcmCfhhmWMLVpwVqFvvGGLVpQSwwSvSFFP +sJnjsgsDDdjjjdTglTgDBsBnSLdvwSqpQQbwQSLLLFSpQpbL +tBlngnqgqZggTZWfCRZmMCHHmM +LGGPQLDLPWmQLVdVdLLGbdvMNjfvHNFNNBbZnNMlHlBf +CshzsJBqTTwhttzCJzRtcNcMljnnnMjHlFnMcvnHfM +gqJsCwzBrQWDSgGmSS +FWVzVJjmbbJVpPwjjJDQsQNDgtcrWtddDQMg +TqRqCfGGBTzgTzDNNs +qRffnhhGvvvpwbvFzp +gLmMTpTCmRhgTLhCCZBSScJFQQQclWWMQJSJQW +rvfbDGjGssqbbrRSJJWclqcSwzwScc +PsDfGfVRjfTTTZNBPTZT +hWqrPzzMhrfmfdNtdZLNrnGndn +SwvwSFslbbjRsspQwsRwzcnbnNdTnZDbGctZdTNtNt +wvJJFsvpSSvJFjlHjzplQwJhCfVVhmBmVWhHWmWVWqBqMW +GjQtgjhPhGgsQjgtthrrvBlvljCrpCdlqBMb +RFDHDRFRczzlbqlbvqvHdb +DDFcRWTWFbSwRWbGtSGtgPfGGSPPtg diff --git a/day03/main.go b/day03/main.go @@ -0,0 +1,67 @@ +package main + +import ( + "bufio" + "fmt" + "log" + "os" +) + +func main() { + if len(os.Args) > 1 { + day03(os.Args[1]) + } else if len(os.Args) == 1 { + fmt.Printf("usage: %s inputfile.txt\n", os.Args[0]) + } else { + fmt.Println("No input data") + } +} + +func day03(input_file string) { + fmt.Printf("day 03 input filename: %s\n", input_file) + input, err := os.Open(input_file) + if err != nil { + log.Fatal(err) + } + defer input.Close() + scanner := bufio.NewScanner(input) + var sum int32 = 0 + for scanner.Scan() { + same := findSame(scanner.Text()) + // unicode rune to fantasy scoring + if same >= 97 { // lowercase + same -= 96 + } else if same >= 65 { // uppercase + same -= 38 + } else { + log.Fatal("Invalid rune") + } + fmt.Printf("%v\n", same) + sum += same + } + fmt.Println("Part 1:", sum) + if err = scanner.Err(); err != nil { + log.Fatal(err) + } +} + +func findSame(in string) int32 { + strLen := len(in) + if strLen % 2 != 0 { + log.Fatal("invalid input string") + } + + comp1 := in[0:strLen/2] + comp2 := in[strLen/2:] + + // only 1 misplaced item per rucksack + for _, rune1 := range comp1 { + for _, rune2 := range comp2 { + if rune1 == rune2 { + return rune1 + } + } + } + + return 0 +} diff --git a/day03/sample.txt b/day03/sample.txt @@ -0,0 +1,6 @@ +vJrwpWtwJgWrhcsFMMfFFhFp +jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL +PmmdzqPrVvPwwTWBwg +wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn +ttgJtRGJQctTZtZT +CrZsJsPPZsGzwwsLwLmpwMDw