Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jun 7, 2021. It is now read-only.

Commit be1496a

Browse files
Solve part2 of day four
1 parent be65a91 commit be1496a

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

‎day4/part2.py‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
def isanagram(a, b):
2+
return sorted(a) == sorted(b)
3+
4+
def valid(passphrase):
5+
for i, u in enumerate(passphrase):
6+
for j, v in enumerate(passphrase):
7+
if i!=j and isanagram(u, v):
8+
return False
9+
return True
10+
11+
def solution(inp):
12+
data = [row.split() for row in inp.splitlines()]
13+
count = 0
14+
for passphrase in data:
15+
if valid(passphrase):
16+
count = count + 1
17+
18+
return count
19+
20+
def main():
21+
with open('input.txt', 'r') as f:
22+
inp = f.read()
23+
print('[*] Reading input from input.txt...')
24+
print('[*] The solution is: ')
25+
print(solution(inp))
26+
27+
28+
if __name__=='__main__':
29+
main()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /