DEV Community

Discussion on: Advent of Code 2019 Solution Megathread - Day 4: Secure Container

Collapse
 
farahanjum profile image
Farah Anjum

Where in part1() are you checking that 2 adjacent digits are the same?

Collapse
 
jbristow profile image
Jon Bristow • Edited

Here’s my math/logic for n=3 that expands to a general case simply in my mind (if it doesn’t I can work on a more formal proof)

Given:

  • a<=b<=c
  • a==b OR b==c

Therefore:

  • distinct(a,b,c) must be equal to (a,c) OR (a)
  • aba is never a legal pattern

Explanation of the second therefore: By looking at a 4 digit number that is abca we see that since this implies c<=a<=b that this isn’t a legal string. We can also insert any number of digits (that follow the rules) between b and c and the contradiction with given #1 still occurs.