Avent of Code - Day 06 - Tuning TroublesteemCreated with Sketch.

in #adventofcodelast year (edited)

Advent of Code occurs at Dec 01 to 25 where each day, you will need to solve a puzzle. It is Festival and the problem statement is mostly related to Christmas.

Day 06 - Tuning Trouble

https://adventofcode.com/2022/day/6

image.png

Q1

import sys
from collections import defaultdict, deque

file1 = open(sys.argv[1], "r")

while True:
        line = file1.readline()
        if not line:
                break
        s = line.strip()
        break

n = len(s)
i = 4
print(s)
while i < n:
        if len(s[i-4:i]) == len(set(s[i-4:i])):
                print(i)
                break
        else:
                i += 1

Q2

import sys
from collections import defaultdict, deque

file1 = open(sys.argv[1], "r")

while True:
        line = file1.readline()
        if not line:
                break
        s = line.strip()
        break

n = len(s)
x = 14
i = x
print(s)
while i < n:
        if len(s[i-x:i]) == len(set(s[i-x:i])):
                print(i)
                break
        else:
                i += 1

Q1 and Q2 are basically the same - except one is looking for 4 characters and another for 14 characters. Checking String contains unique characters: See How to Check if a Given String has Unique Characters?


Steem to the Moon!

Coin Marketplace

STEEM 0.36
TRX 0.12
JST 0.040
BTC 70446.49
ETH 3571.68
USDT 1.00
SBD 4.73