2018 Day 02 Complete
This commit is contained in:
parent
2e0459813d
commit
97d81128f1
76
2018/day02/day02.go
Normal file
76
2018/day02/day02.go
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
inp := StdinToStringSlice()
|
||||||
|
part1(inp)
|
||||||
|
part2(inp)
|
||||||
|
}
|
||||||
|
|
||||||
|
func part1(inp []string) {
|
||||||
|
var twos, threes int
|
||||||
|
for _, v := range inp {
|
||||||
|
var vintwos, vinthrees bool
|
||||||
|
for i := range v {
|
||||||
|
if !vintwos && strings.Count(v, string(v[i])) == 2 {
|
||||||
|
twos++
|
||||||
|
vintwos = true
|
||||||
|
}
|
||||||
|
if !vinthrees && strings.Count(v, string(v[i])) == 3 {
|
||||||
|
threes++
|
||||||
|
vinthrees = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Println(twos * threes)
|
||||||
|
}
|
||||||
|
|
||||||
|
func part2(inp []string) {
|
||||||
|
for _, v1 := range inp {
|
||||||
|
for _, v2 := range inp {
|
||||||
|
if v1 == v2 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var diff int
|
||||||
|
for k := range v1 {
|
||||||
|
if v1[k] != v2[k] {
|
||||||
|
diff++
|
||||||
|
}
|
||||||
|
if diff > 1 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if diff == 1 {
|
||||||
|
fmt.Println(v1)
|
||||||
|
fmt.Println(v2)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func StdinToStringSlice() []string {
|
||||||
|
var input []string
|
||||||
|
scanner := bufio.NewScanner(os.Stdin)
|
||||||
|
for scanner.Scan() {
|
||||||
|
input = append(input, scanner.Text())
|
||||||
|
}
|
||||||
|
return input
|
||||||
|
}
|
||||||
|
|
||||||
|
func Atoi(i string) int {
|
||||||
|
var ret int
|
||||||
|
var err error
|
||||||
|
if ret, err = strconv.Atoi(i); err != nil {
|
||||||
|
log.Fatal("Invalid Atoi")
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
1
2018/day02/go.mod
Normal file
1
2018/day02/go.mod
Normal file
@ -0,0 +1 @@
|
|||||||
|
module day02
|
250
2018/day02/input
Normal file
250
2018/day02/input
Normal file
@ -0,0 +1,250 @@
|
|||||||
|
myhposlqgeauywfikztndcvrqr
|
||||||
|
mbhposlxfeauywoikztndcvjqi
|
||||||
|
mbhpoulxgeagywfikytndcvjqr
|
||||||
|
jbhposlxgeauywdikztndcvjqk
|
||||||
|
mbhpsslxueauywfikzfndcvjqr
|
||||||
|
mbhposnxgeauzyfikztndcvjqr
|
||||||
|
ibhposlxgetvywfikztndcvjqr
|
||||||
|
mbcposlxgeauywfikztxdcvjqv
|
||||||
|
mlhposltgeauywfikitndcvjqr
|
||||||
|
mbhpostxgeauywfikztndjvjqy
|
||||||
|
mboboslxglauywfikztndcvjqr
|
||||||
|
mbhpoglxgeahywfikztndcvjqp
|
||||||
|
mbhposlxgeapydpikztndcvjqr
|
||||||
|
mbhposlxseauywfikztnncljqr
|
||||||
|
mbhposlxgeauydfisztndcvjqj
|
||||||
|
mbhposlxgeaugwwikzlndcvjqr
|
||||||
|
mbhpoklxgeauywfikztndvvmqr
|
||||||
|
mbhposlxgeauywfikdtndcmjqx
|
||||||
|
mbhposlxaeauapfikztndcvjqr
|
||||||
|
mbwposgxgeauymfikztndcvjqr
|
||||||
|
mbhposlxgeauvwfirzcndcvjqr
|
||||||
|
mbhpozlxgeaqywfykztndcvjqr
|
||||||
|
mahqoslxgeauywfikzgndcvjqr
|
||||||
|
mbhposlcgexbywfikztndcvjqr
|
||||||
|
ykhposlxgeeuywfikztndcvjqr
|
||||||
|
mbhgoswxgeauywfikztndhvjqr
|
||||||
|
mbhposlxgeauywfikztnocmjqp
|
||||||
|
mbvposfageauywfikztndcvjqr
|
||||||
|
mbhpnslxgeauywfikztndgejqr
|
||||||
|
mblposfxgeauypfikztndcvjqr
|
||||||
|
mbhposlxyeauywfikzpndcvmqr
|
||||||
|
ibhposlbgeauywfikotndcvjqr
|
||||||
|
mbmposlxgeauywfiktwndcvjqr
|
||||||
|
mbhposlxgeduywfikztndfvoqr
|
||||||
|
mbhpoklxdeauywfikztndcvuqr
|
||||||
|
mbhposlxgeauywfikltnlcvuqr
|
||||||
|
mbhposlbgsauywfikztndsvjqr
|
||||||
|
mbhposlxgeauywfirzfndcbjqr
|
||||||
|
mphposlxgeauywfikztndcvjgg
|
||||||
|
mohposlcgeauywfikzsndcvjqr
|
||||||
|
mbhpovlxgeauyqfikotndcvjqr
|
||||||
|
qbhpgslxgeauywqikztndcvjqr
|
||||||
|
mbhposlxweauywfikztndtvjqm
|
||||||
|
pbhposlxgeauywfikztnncvjqm
|
||||||
|
mbbposlxpeauuwfikztndcvjqr
|
||||||
|
mbhposlxgmauyrfikztndcvjir
|
||||||
|
pbhposlqgefuywfikztndcvjqr
|
||||||
|
mbhkoslxgeauywfikztndciwqr
|
||||||
|
mbtpoflxgeauywfikztndrvjqr
|
||||||
|
mbhcoslxveguywfikztndcvjqr
|
||||||
|
mbhpovlxgeauywfhkdtndcvjqr
|
||||||
|
mbhposlxgeauywftrztndcujqr
|
||||||
|
mbhposlxgeaoywfdkzpndcvjqr
|
||||||
|
mbnposlxgeyuywfikztldcvjqr
|
||||||
|
mbaposlxweauywfikftndcvjqr
|
||||||
|
mbhposljgeauywfikztcdcvvqr
|
||||||
|
nbhpkslxgeauywfikzwndcvjqr
|
||||||
|
mbhtoslxgeauywfikzkndcvjdr
|
||||||
|
mbhposxxgeaxywfikztndsvjqr
|
||||||
|
mbdpoflxgeauywfisztndcvjqr
|
||||||
|
mbhposvxgeauywfikztnscvnqr
|
||||||
|
mbcposlxghauywfikztndcgjqr
|
||||||
|
mbhpovlxgeauywpckztndcvjqr
|
||||||
|
mbhpfslxgeauywbikntndcvjqr
|
||||||
|
mbhpowyxgeauywfikztndcvjcr
|
||||||
|
mbhposlxoeatywfikztndcvoqr
|
||||||
|
mchpfslxgeauywfikztidcvjqr
|
||||||
|
mbhposvxgearywfikztndcvjcr
|
||||||
|
mbhposlxgeauywfpcztnduvjqr
|
||||||
|
mbhposlxgmauyyfiqztndcvjqr
|
||||||
|
mbhposlxteauuwfikwtndcvjqr
|
||||||
|
mbhpotlspeauywfikztndcvjqr
|
||||||
|
mbhpoelxgeauywfikztndckjkr
|
||||||
|
mbhpnslxgeauywfikztndcvkqs
|
||||||
|
mbhpksfxgwauywfikztndcvjqr
|
||||||
|
mxhwoglxgeauywfdkztndcvjqr
|
||||||
|
mbhphsbjgeauywfikztndcvjqr
|
||||||
|
mbhposlxgeauwifixztndcvjqr
|
||||||
|
mbhposqxguauywfikztndcwjqr
|
||||||
|
mbhposlngeauywfikztedcvjor
|
||||||
|
nbhposlxgeauywiikztndcyjqr
|
||||||
|
mbhposlxgeauawfykztndcvbqr
|
||||||
|
mbhplslxgeauywcikztndcvjrr
|
||||||
|
fshposlxgeagywfikztndcvjqr
|
||||||
|
mbhposlxgeauymcikztndcxjqr
|
||||||
|
mbhponlxgeauyloikztndcvjqr
|
||||||
|
mbhposrxzeanywfikztndcvjqr
|
||||||
|
mbhtoslxgeajyifikztndcvjqr
|
||||||
|
mbhposixkeauywfikhtndcvjqr
|
||||||
|
mahhoslxgeaufwfikztndcvjqr
|
||||||
|
mbhpdslxteauywfikzvndcvjqr
|
||||||
|
mfhposlxgeauywfiqttndcvjqr
|
||||||
|
mbhplslxheauywfikztnscvjqr
|
||||||
|
mbhpoylxgeauywbizztndcvjqr
|
||||||
|
mbhposlhgeawywfjkztndcvjqr
|
||||||
|
mbhkoslxgkauywfilztndcvjqr
|
||||||
|
mbhposnxgeauywfikztkdcvlqr
|
||||||
|
mvhpxslxgevuywfikztndcvjqr
|
||||||
|
mbhpohlxgeauyrficztndcvjqr
|
||||||
|
mbhsosuxgewuywfikztndcvjqr
|
||||||
|
mbhpoxlxgeauywuikztnhcvjqr
|
||||||
|
mbhposlxqeauyqfikztndcvrqr
|
||||||
|
mbhpchlxgeauywfikztnhcvjqr
|
||||||
|
mbhposlxgeauywoikztndcfqqr
|
||||||
|
pbhposlxgeagmwfikztndcvjqr
|
||||||
|
mxhwoglxgeauywfikztndcvjqr
|
||||||
|
mbhpospxgaauywfikstndcvjqr
|
||||||
|
mbhwoxlxgeauywfgkztndcvjqr
|
||||||
|
mbhposlxgeauywfikvtndhvsqr
|
||||||
|
mbbposlxgesuywfikztnicvjqr
|
||||||
|
mhhjoslxgeauywfikztndccjqr
|
||||||
|
mbhkoslxgeagywffkztndcvjqr
|
||||||
|
mbhposlxgesqywfukztndcvjqr
|
||||||
|
mbdposlxgeauywfilztndcvjqp
|
||||||
|
mbhposlxgeakqwfikztedcvjqr
|
||||||
|
mbhposuxgeayywficztndcvjqr
|
||||||
|
mbhposlxgeauywfxkztndcloqr
|
||||||
|
mchposlxgeauywoiiztndcvjqr
|
||||||
|
tbhporlxgeauywfikztndcvyqr
|
||||||
|
mbhposlxoevuywfikzindcvjqr
|
||||||
|
qbhposlxfevuywfikztndcvjqr
|
||||||
|
mbhposlxfeauvwfikztndcvgqr
|
||||||
|
mbjposlxgsauywfikztnwcvjqr
|
||||||
|
vbhposlxgeauvwfikztndcvjqk
|
||||||
|
pbhposlxguauyrfikztndcvjqr
|
||||||
|
mbhposlcgeauywfiketndcviqr
|
||||||
|
mbsposlxgvauywfikztndcviqr
|
||||||
|
mbhposlxgeauynfxkztndcvjbr
|
||||||
|
mbhposlxtentywfikztndcvjqr
|
||||||
|
mbhposlxgeavywfikztndhvjnr
|
||||||
|
mbhpsvlxgeauywfikztndcvzqr
|
||||||
|
mzhpotlxgeauywfiyztndcvjqr
|
||||||
|
mbhposkqgeauywfiwztndcvjqr
|
||||||
|
mbhposlxoeakywfikztndcvjqt
|
||||||
|
mbhposlxghauywfikbdndcvjqr
|
||||||
|
mbhpossxgeauywfikqxndcvjqr
|
||||||
|
mbhposlxgearywhikztydcvjqr
|
||||||
|
mbhposlxgeaiywfikztndfvjur
|
||||||
|
mbhpxslxgoazywfikztndcvjqr
|
||||||
|
mbhposlxneauywfibqtndcvjqr
|
||||||
|
mnheoslxteauywfikztndcvjqr
|
||||||
|
mbhposlxgeauywfmkztrdcvuqr
|
||||||
|
mbhzowlxgeauywfizztndcvjqr
|
||||||
|
mbhloslxgeauyofikztnucvjqr
|
||||||
|
mbhposlxneagywfbkztndcvjqr
|
||||||
|
mbhposongeauywfikztnzcvjqr
|
||||||
|
mwyposlxgeauywfikztnqcvjqr
|
||||||
|
mbhpnqaxgeauywfikztndcvjqr
|
||||||
|
mboposlxzeauywfioztndcvjqr
|
||||||
|
mbhposledeauywfikztndqvjqr
|
||||||
|
mphpaslxgeauywfbkztndcvjqr
|
||||||
|
mbhposrxgeauywlikbtndcvjqr
|
||||||
|
ybhnoslxgeauywfihztndcvjqr
|
||||||
|
mbhposlxgeauywfikntxccvjqr
|
||||||
|
mbhposlxgeauqwfikutndcfjqr
|
||||||
|
mbhposlxglabywfikztidcvjqr
|
||||||
|
mbhpollxgeauywfikxtnscvjqr
|
||||||
|
mboposlggeaufwfikztndcvjqr
|
||||||
|
mbhposlxgeauywpikedndcvjqr
|
||||||
|
mbhpoklxgeauywpikztndcvjlr
|
||||||
|
mbhposhxgeauywfifztndcvpqr
|
||||||
|
mbhposlxgwagywfikztndcvjwr
|
||||||
|
mbhpokldgeauywfikztngcvjqr
|
||||||
|
nbhposlxgeauywfiketndcvjxr
|
||||||
|
mbhhoslxgexuywfikrtndcvjqr
|
||||||
|
mbhposlxgefujwfikztkdcvjqr
|
||||||
|
mbhposlxggagywfikztndchjqr
|
||||||
|
mbhposlxgeauyvfilztnicvjqr
|
||||||
|
mbhposlkgeauywfikzxndcvoqr
|
||||||
|
mbhposlxgeauvqfikztndcvuqr
|
||||||
|
zbhposlxgfauylfikztndcvjqr
|
||||||
|
mbhyoshxgeauywfikztndcvjqa
|
||||||
|
sbhposlxgeauyxfikztndavjqr
|
||||||
|
mlhposlxgeauywfikzmndcqjqr
|
||||||
|
mbhpaslxgekuywfikztnncvjqr
|
||||||
|
ibhhoslxteauywfikztndcvjqr
|
||||||
|
mbhposlxgeauyodibztndcvjqr
|
||||||
|
mbhposlxgkaoywfikztndcvpqr
|
||||||
|
mbhonslxgearywfikztndcvjqr
|
||||||
|
mbdpoolxgealywfikztndcvjqr
|
||||||
|
mbepfslxgvauywfikztndcvjqr
|
||||||
|
mbhposlygeauywfikztfdcvaqr
|
||||||
|
mthpoalxgeauywnikztndcvjqr
|
||||||
|
mbhpesbogeauywfikztndcvjqr
|
||||||
|
mbhposlxgjauywfikztnmcvjqj
|
||||||
|
mbhnoslxgeauydfikgtndcvjqr
|
||||||
|
mbhpxslxgeauywfikztndcvjcx
|
||||||
|
muhposlxgwauywfipztndcvjqr
|
||||||
|
mbhpcslxgeauywfiqztndcvjbr
|
||||||
|
mbhpomlxgeauywfioftndcvjqr
|
||||||
|
mbhposlfgepuywfikzmndcvjqr
|
||||||
|
mbhsosliteauywfikztndcvjqr
|
||||||
|
mbwposlxgeauywfikztnycveqr
|
||||||
|
mbhpfslxgeauywfqkztndcvjhr
|
||||||
|
mxhbvslxgeauywfikztndcvjqr
|
||||||
|
fbhposlxgeauywfikzcnmcvjqr
|
||||||
|
mbhfosfxgeauywfikztnduvjqr
|
||||||
|
tbhporlxgeauywfikztndcvjqm
|
||||||
|
mhhposlxgeauywfikctnecvjqr
|
||||||
|
mbhposlxgeqtywfikztnmcvjqr
|
||||||
|
qbhpjslxgeauywfikztndevjqr
|
||||||
|
tbhpxslxgeaunwfikztndcvjqr
|
||||||
|
wbhposlxgeadywfikztndcujqr
|
||||||
|
mbhposlvgeauywfpkotndcvjqr
|
||||||
|
mbhposlxgeagywfingtndcvjqr
|
||||||
|
mbnposlxgeauywfikztnvcjjqr
|
||||||
|
mohpoilxgeadywfikztndcvjqr
|
||||||
|
mbhposlsgeauywfikztnxcvgqr
|
||||||
|
mbhposlogeauywfikqtndcvjor
|
||||||
|
mbhroslxgeauypfikztndcvjqg
|
||||||
|
mblposuxgetuywfikztndcvjqr
|
||||||
|
mbhposlogeiuywfikztodcvjqr
|
||||||
|
mbhposlxgeauylfikztedcvrqr
|
||||||
|
mbhfoslxgeautwxikztndcvjqr
|
||||||
|
mbhouslxgeauywfikztnycvjqr
|
||||||
|
mbhposlxgeauywfvkqtndlvjqr
|
||||||
|
mbfposltgeauytfikztndcvjqr
|
||||||
|
mbhposlxgcapywfikztnddvjqr
|
||||||
|
hbhposlxgeasywfikztnxcvjqr
|
||||||
|
mbhposntgeauywfikztcdcvjqr
|
||||||
|
mbhponlxgfauywfirztndcvjqr
|
||||||
|
mbhposlxgeatywlikztndcvrqr
|
||||||
|
mohroslzgeauywfikztndcvjqr
|
||||||
|
mbhpojaxgeauywfifztndcvjqr
|
||||||
|
rbhposlxgwauywfikztndovjqr
|
||||||
|
mbhpoclxgeaeywfikztndcvjqo
|
||||||
|
mbhposllgeauywfikzondcvmqr
|
||||||
|
mbhpxslxgeauywfikzymdcvjqr
|
||||||
|
mbhposlxgeasywxikztndkvjqr
|
||||||
|
mbhposlxgeauywfivztndcmjqx
|
||||||
|
qbhposlxgpauywfikgtndcvjqr
|
||||||
|
mbhposlxgeauyqdikztqdcvjqr
|
||||||
|
cbhposlxgeauywfikttjdcvjqr
|
||||||
|
mbhgoslxgeanywfihztndcvjqr
|
||||||
|
mbhposlxgeajywfhkztndcvjvr
|
||||||
|
mbhpozlxgeauewfmkztndcvjqr
|
||||||
|
mbhposlxgeagywfbiztndcvjqr
|
||||||
|
mbhmoslxgeauywfikztndrnjqr
|
||||||
|
ybhposmxgeauywfikztndcviqr
|
||||||
|
mrwposlxgeauywfikztndpvjqr
|
||||||
|
mbhposlxneauywfikztndcbjqh
|
||||||
|
mbhpowlxheauywfikztndcojqr
|
||||||
|
mbeposlxgeauywfiwztnycvjqr
|
||||||
|
mbhposixgeapywfikztndcvvqr
|
||||||
|
mbhposlxgeauywfikztnbcvjap
|
||||||
|
mzhposixgenuywfikztndcvjqr
|
||||||
|
mbhposgxgeauywyikztndvvjqr
|
||||||
|
mbhposajgeauywfikztzdcvjqr
|
||||||
|
mbhyoslxgeauywfikzsndcvxqr
|
||||||
|
mbhposlxgdauywfikmtndcljqr
|
Loading…
Reference in New Issue
Block a user