This website works better with JavaScript.
Home
Help
Sign In
jlelse
/
AdventOfCode2020
Watch
1
Star
0
Fork
0
Code
Releases
0
Activity
Browse Source
Day 13
master
Jan-Lukas Else
4 months ago
parent
3c00fde640
commit
576b414008
2 changed files
with
58 additions
and
0 deletions
Split View
Diff Options
Show Stats
Download Patch File
Download Diff File
+2
-0
13/input.txt
+56
-0
13/main.go
+ 2
- 0
13/input.txt
View File
@ -0,0 +1,2 @@
1002561
17,x,x,x,x,x,x,x,x,x,x,37,x,x,x,x,x,409,x,29,x,x,x,x,x,x,x,x,x,x,13,x,x,x,x,x,x,x,x,x,23,x,x,x,x,x,x,x,373,x,x,x,x,x,x,x,x,x,41,x,x,x,x,x,x,x,x,19
+ 56
- 0
13/main.go
View File
@ -0,0 +1,56 @@
package
main
import
(
"bufio"
"fmt"
"math"
"os"
"strconv"
"strings"
)
func
main
(
)
{
var
earliest
int
var
buslines
[
]
int
file
,
_
:=
os
.
Open
(
"input.txt"
)
defer
file
.
Close
(
)
scanner
:=
bufio
.
NewScanner
(
file
)
scanner
.
Scan
(
)
earliest
,
_
=
strconv
.
Atoi
(
scanner
.
Text
(
)
)
scanner
.
Scan
(
)
for
_
,
s
:=
range
strings
.
Split
(
scanner
.
Text
(
)
,
","
)
{
if
s
!=
"x"
{
line
,
_
:=
strconv
.
Atoi
(
s
)
buslines
=
append
(
buslines
,
line
)
}
else
{
buslines
=
append
(
buslines
,
-
1
)
}
}
favLine
:=
0
waitTime
:=
math
.
MaxInt64
for
_
,
l
:=
range
buslines
{
if
l
!=
-
1
{
if
t
:=
l
-
earliest
%
l
;
t
<
waitTime
{
favLine
=
l
waitTime
=
t
}
}
}
fmt
.
Println
(
"Part 1:"
,
favLine
*
waitTime
)
t
,
step
:=
0
,
1
for
i
,
l
:=
range
buslines
{
if
l
==
-
1
{
continue
}
for
(
t
+
i
)
%
l
!=
0
{
t
+=
step
}
step
*=
l
}
fmt
.
Println
(
"Part 2:"
,
t
)
}
Write
Preview
Loading…
Cancel
Save