Advent of code Day 15

Goal: Finding PPCM

Ref: http://adventofcode.com/2016/day/15


In [1]:
disc1 = seq(((7-0)-1), 5000000, by = 7)
disc2 = seq(((13-0)-2), 5000000, by = 13)
disc3 = seq(((3-2)-3), 5000000, by = 3)
disc4 = seq(((5-2)-4), 5000000, by = 5)
disc5 = seq(((17-0)-5), 5000000, by = 17)
disc6 = seq(((19-7)-6), 5000000, by = 19)
disc7 = seq(((11-0)-7), 5000000, by = 11)

In [2]:
Q1 <- min(Reduce(intersect, list(disc1,disc2,disc3,disc4,disc5,disc6)))
Q1


121834

In [3]:
Q2 <- Reduce(intersect, list(disc1,disc2,disc3,disc4,disc5,disc6,disc7))
Q2


3208099

In [4]:
cat("Q1 - To get the first capsule press a Time = ", Q1, '\n')
cat("Q2 - To get the sencond capsule press a Time = ", Q2, '\n')


Q1 - To get the first capsule press a Time =  121834 
Q2 - To get the sencond capsule press a Time =  3208099