Initial commit.
commit
847044d9ba
|
@ -0,0 +1,200 @@
|
||||||
|
1977
|
||||||
|
1802
|
||||||
|
1856
|
||||||
|
1309
|
||||||
|
2003
|
||||||
|
1854
|
||||||
|
1898
|
||||||
|
1862
|
||||||
|
1857
|
||||||
|
542
|
||||||
|
1616
|
||||||
|
1599
|
||||||
|
1628
|
||||||
|
1511
|
||||||
|
1848
|
||||||
|
1623
|
||||||
|
1959
|
||||||
|
1693
|
||||||
|
1444
|
||||||
|
1211
|
||||||
|
1551
|
||||||
|
1399
|
||||||
|
1855
|
||||||
|
1538
|
||||||
|
1869
|
||||||
|
1664
|
||||||
|
1719
|
||||||
|
1241
|
||||||
|
1875
|
||||||
|
1733
|
||||||
|
1547
|
||||||
|
1813
|
||||||
|
1531
|
||||||
|
1773
|
||||||
|
624
|
||||||
|
1336
|
||||||
|
1897
|
||||||
|
1179
|
||||||
|
1258
|
||||||
|
1205
|
||||||
|
1727
|
||||||
|
1364
|
||||||
|
1957
|
||||||
|
540
|
||||||
|
1970
|
||||||
|
1273
|
||||||
|
1621
|
||||||
|
1964
|
||||||
|
1723
|
||||||
|
1699
|
||||||
|
1847
|
||||||
|
1249
|
||||||
|
1254
|
||||||
|
1644
|
||||||
|
1449
|
||||||
|
1794
|
||||||
|
1797
|
||||||
|
1713
|
||||||
|
1534
|
||||||
|
1202
|
||||||
|
1951
|
||||||
|
1598
|
||||||
|
1926
|
||||||
|
1865
|
||||||
|
1294
|
||||||
|
1893
|
||||||
|
1641
|
||||||
|
1325
|
||||||
|
1432
|
||||||
|
1960
|
||||||
|
413
|
||||||
|
1517
|
||||||
|
1724
|
||||||
|
1715
|
||||||
|
1458
|
||||||
|
1775
|
||||||
|
1317
|
||||||
|
1694
|
||||||
|
1484
|
||||||
|
1840
|
||||||
|
1999
|
||||||
|
1811
|
||||||
|
1578
|
||||||
|
1658
|
||||||
|
1906
|
||||||
|
1481
|
||||||
|
1313
|
||||||
|
1997
|
||||||
|
1339
|
||||||
|
1592
|
||||||
|
1971
|
||||||
|
1453
|
||||||
|
1706
|
||||||
|
1884
|
||||||
|
1956
|
||||||
|
1384
|
||||||
|
1579
|
||||||
|
1689
|
||||||
|
1726
|
||||||
|
1217
|
||||||
|
1796
|
||||||
|
1536
|
||||||
|
1213
|
||||||
|
1867
|
||||||
|
1304
|
||||||
|
2010
|
||||||
|
1503
|
||||||
|
1665
|
||||||
|
1361
|
||||||
|
814
|
||||||
|
2007
|
||||||
|
1430
|
||||||
|
1625
|
||||||
|
1958
|
||||||
|
860
|
||||||
|
1799
|
||||||
|
1942
|
||||||
|
1876
|
||||||
|
1772
|
||||||
|
1198
|
||||||
|
1221
|
||||||
|
1814
|
||||||
|
1826
|
||||||
|
1667
|
||||||
|
1334
|
||||||
|
1504
|
||||||
|
1420
|
||||||
|
1164
|
||||||
|
1414
|
||||||
|
1934
|
||||||
|
1823
|
||||||
|
1507
|
||||||
|
1195
|
||||||
|
21
|
||||||
|
1752
|
||||||
|
1472
|
||||||
|
1196
|
||||||
|
1558
|
||||||
|
1322
|
||||||
|
1927
|
||||||
|
1556
|
||||||
|
1922
|
||||||
|
277
|
||||||
|
1828
|
||||||
|
1883
|
||||||
|
1280
|
||||||
|
1947
|
||||||
|
1231
|
||||||
|
1915
|
||||||
|
1235
|
||||||
|
1961
|
||||||
|
1494
|
||||||
|
1324
|
||||||
|
2009
|
||||||
|
1367
|
||||||
|
1545
|
||||||
|
1736
|
||||||
|
1575
|
||||||
|
1214
|
||||||
|
1704
|
||||||
|
1833
|
||||||
|
1663
|
||||||
|
1474
|
||||||
|
1894
|
||||||
|
1754
|
||||||
|
1564
|
||||||
|
1321
|
||||||
|
1119
|
||||||
|
1975
|
||||||
|
1987
|
||||||
|
1873
|
||||||
|
1834
|
||||||
|
1686
|
||||||
|
1574
|
||||||
|
1505
|
||||||
|
1656
|
||||||
|
1688
|
||||||
|
1896
|
||||||
|
1982
|
||||||
|
1554
|
||||||
|
1990
|
||||||
|
1902
|
||||||
|
1859
|
||||||
|
1293
|
||||||
|
1739
|
||||||
|
1282
|
||||||
|
1889
|
||||||
|
1981
|
||||||
|
1283
|
||||||
|
1687
|
||||||
|
1220
|
||||||
|
1443
|
||||||
|
1409
|
||||||
|
1252
|
||||||
|
1506
|
||||||
|
1742
|
||||||
|
1319
|
||||||
|
1882
|
||||||
|
951
|
||||||
|
1849
|
|
@ -0,0 +1,36 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
nums := []int{}
|
||||||
|
f, err := ioutil.ReadFile("input")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
reader := bufio.NewReader(bytes.NewReader(f))
|
||||||
|
for {
|
||||||
|
line, err := reader.ReadString('\n')
|
||||||
|
if err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
i, err := strconv.Atoi(strings.TrimSpace(line))
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
for _, num := range nums {
|
||||||
|
if i+num == 2020 {
|
||||||
|
fmt.Printf("%d", i*num)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
nums = append(nums, i)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
nums := []int{}
|
||||||
|
f, err := ioutil.ReadFile("input")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
reader := bufio.NewReader(bytes.NewReader(f))
|
||||||
|
for {
|
||||||
|
line, err := reader.ReadString('\n')
|
||||||
|
if err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
line = strings.TrimSpace(line)
|
||||||
|
if len(line) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
i, err := strconv.Atoi(line)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
nums = append(nums, i)
|
||||||
|
}
|
||||||
|
|
||||||
|
max := len(nums)
|
||||||
|
|
||||||
|
for p1 := 0; p1 < max; p1++ {
|
||||||
|
for p2 := 0; p2 < max; p2++ {
|
||||||
|
for p3 := 0; p3 < max; p3++ {
|
||||||
|
sum := nums[p1] + nums[p2] + nums[p3]
|
||||||
|
if sum == 2020 {
|
||||||
|
fmt.Printf("%d", nums[p1]*nums[p2]*nums[p3])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,44 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
f, err := ioutil.ReadFile("input")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
reader := bufio.NewReader(bytes.NewReader(f))
|
||||||
|
var valid int
|
||||||
|
for {
|
||||||
|
line, err := reader.ReadString('\n')
|
||||||
|
if err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
var pw string
|
||||||
|
var min, max int
|
||||||
|
var char rune
|
||||||
|
n, err := fmt.Sscanf(line, "%d-%d %c: %s", &min, &max, &char, &pw)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
if n != 4 {
|
||||||
|
panic("mismatched Scanf")
|
||||||
|
}
|
||||||
|
var count int
|
||||||
|
for _, currentChar := range pw {
|
||||||
|
if currentChar == char {
|
||||||
|
count++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if count >= min && count <= max {
|
||||||
|
valid++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.Printf("%d valid entries", valid)
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
f, err := ioutil.ReadFile("input")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
reader := bufio.NewReader(bytes.NewReader(f))
|
||||||
|
var valid int
|
||||||
|
for {
|
||||||
|
line, err := reader.ReadString('\n')
|
||||||
|
if err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
var pw string
|
||||||
|
var min, max int
|
||||||
|
var char rune
|
||||||
|
n, err := fmt.Sscanf(line, "%d-%d %c: %s", &min, &max, &char, &pw)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
if n != 4 {
|
||||||
|
panic("mismatched Scanf")
|
||||||
|
}
|
||||||
|
min--
|
||||||
|
max--
|
||||||
|
has1 := rune(pw[min]) == char
|
||||||
|
has2 := rune(pw[max]) == char
|
||||||
|
if has1 == has2 { // both false or both true
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
valid++
|
||||||
|
}
|
||||||
|
log.Printf("%d valid entries", valid)
|
||||||
|
}
|
Loading…
Reference in New Issue