DLV4V3KAK2TKD77QGXMG65FUJ6OTCRJJZ3BHOBXD2ISJWNJWUQ4AC
package main
import (
"bufio"
"fmt"
"log"
"os"
"strconv"
)
const MIGHTY = 2020
func main() {
if err := realMain(); err != nil {
log.Println(err)
}
}
func realMain() error {
nums, err := readFile()
if err != nil {
return err
}
for i, n := range nums {
for j := i + 1; j < len(nums); j++ {
if n+nums[j] == MIGHTY {
log.Println(n * nums[j])
return nil
}
}
}
return fmt.Errorf("pair have not found")
}
func readFile() ([]int, error) {
fd, err := os.Open("input.txt")
if err != nil {
return nil, err
}
defer fd.Close()
ret := []int{}
buff := bufio.NewScanner(fd)
for buff.Scan() {
curr, err := strconv.Atoi(buff.Text())
if err != nil {
return nil, err
}
ret = append(ret, curr)
}
return ret, nil
}
1714
1960
1256
1597
1853
1609
1936
2003
1648
1903
1248
1525
1330
1281
1573
1892
1563
1500
1858
176
1802
1370
1708
1453
1342
1830
1580
1607
1848
1626
1602
1919
1640
1574
1414
766
1581
1924
1727
1949
1406
323
957
1862
1354
1427
1583
1067
1863
1553
1923
1990
691
1372
1357
1887
1485
1799
1270
1743
1601
1457
1723
1888
1272
1600
1880
1381
1413
1452
277
1866
1542
1693
1760
1637
1675
1975
1304
1327
1985
1842
1255
1915
1266
1944
1824
1770
1392
1259
1313
1547
1293
1393
1896
1828
1642
1979
1871
1502
1548
1508
710
1786
1845
1334
1362
1940
2009
1271
1448
1964
1676
1654
1804
1835
1910
1939
1298
1572
1704
1841
1399
1576
1164
1868
1035
262
1569
1639
1669
1543
1616
1658
1750
1765
1718
1861
1351
1531
1665
1771
1348
1289
875
1408
1486
1275
1625
1594
1816
704
1800
1564
1291
1234
1981
1843
1387
1938
1827
1883
1911
1755
1353
1808
1498
1416
2006
1916
1411
1539
1963
1874
1898
1951
1292
1366
1912
1369
1478
1359
1859
1421
1384
1534
1283
1913
1794
1494
1860
1312
1869
1730
1510
1319
1428
1706
1432
1532
module main
go 1.17