On Dream on (Aerosmith), I've always wondered if the couple "missing" notes from the arpeggio in 2:33 are intentional or a mistake.
reboot6675
I crafted a simple counter-example (single letters for brevity). The way the sequence goes totally depends on the instructions, and we don't have any guarantees on that. It could be anything. Of course, looking at the input data we could find what the instructions are, but the assumption doesn't hold in general.
A = (B, X)
B = (C, X)
C = (X, Z)
Z = (A, C)
X = (X, X)
L L R L L L R R R -> A B C Z A B C Z C Z
L L R R R L L L R -> A B C Z C Z A B C Z
Here the distance of Z cycling back into itself could be 2 or 4, depending on what the instruction string is doing.
Yeah I got annoyed too. Because this is not implied in the problem statement and it definitely doesn't hold up in general...
JavaScript and TypeScript too
Why would the joker remain unused? The problem clearly says joker acts as the card that makes the hand strongest, so in this case, 5 of a kind.
Golang
Pretty straightforward. The only optimization I did is that the pairs are symmetric (3ms hold and 4ms travel is the same as 4ms hold and 3ms travel).
Part 1
file, _ := os.Open("input.txt")
defer file.Close()
scanner := bufio.NewScanner(file)
scanner.Scan()
times := strings.Fields(strings.Split(scanner.Text(), ":")[1])
scanner.Scan()
distances := strings.Fields(strings.Split(scanner.Text(), ":")[1])
n := len(times)
countProduct := 1
for i := 0; i < n; i++ {
t, _ := strconv.Atoi(times[i])
d, _ := strconv.Atoi(distances[i])
count := 0
for j := 0; j <= t/2; j++ {
if j*(t-j) > d {
if t%2 == 0 && j == t/2 {
count++
} else {
count += 2
}
}
}
countProduct *= count
}
fmt.Println(countProduct)
Part 2
file, _ := os.Open("input.txt")
defer file.Close()
scanner := bufio.NewScanner(file)
scanner.Scan()
time := strings.ReplaceAll(strings.Split(scanner.Text(), ":")[1], " ", "")
scanner.Scan()
distance := strings.ReplaceAll(strings.Split(scanner.Text(), ":")[1], " ", "")
t, _ := strconv.Atoi(time)
d, _ := strconv.Atoi(distance)
count := 0
for j := 0; j <= t/2; j++ {
if j*(t-j) > d {
if t%2 == 0 && j == t/2 {
count++
} else {
count += 2
}
}
}
fmt.Println(count)
I've always had this question. When I login with Google, I know what data the website will get from my Google account. But what data can Google get from the website and my usage of it, if any? (besides, of course, that I have an account on said website).
Just a little nitpicking, O(N+10) and O(2N) are not "effectively" the same as O(N). They are truly the same.
La Haine (1995), amazing movie. The lives of others (2006), very good too.
Oh man I hadn't seen a git checkout -b
in years haha since they introduced switch
and restore
, never looked back
Golang
Avoided recursion by having an array of "pending paths". Whenever I hit a splitter, I follow one of the paths straight away, and push the starting point and direction of the other path to the array.
First time I ran it, hit an infinite loop. Handled it by skipping "|" and "-" if they have been visited already.
Part 2 is the same code as part 1 but I just check all the possible starting points.
Code