Skip to content

Commit

Permalink
2017 day 4 solution
Browse files Browse the repository at this point in the history
Signed-off-by: Lance-Drane <ldraneutk@gmail.com>
  • Loading branch information
Lance-Drane committed Jan 14, 2024
1 parent 84d54ad commit 9ac3b17
Show file tree
Hide file tree
Showing 5 changed files with 556 additions and 0 deletions.
14 changes: 14 additions & 0 deletions 2017/04/1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import sys
from itertools import pairwise

total = 0
for line in sys.stdin.readlines():
ok = True
for pair in pairwise(sorted(line.split())):
if pair[0] == pair[1]:
ok = False
break
if ok:
total += 1

print(total)
1 change: 1 addition & 0 deletions 2017/04/1_out.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
337
28 changes: 28 additions & 0 deletions 2017/04/2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import sys


def get_anagram_hash(word: str) -> (int, int, int):
str_hash = 0
str_sum = 0
for char in word:
# input file has only lowercase letters and whitespace
char2int = ord(char) - 97
str_hash += 1 << char2int
str_sum += char2int
return len(word), str_hash, str_sum


total = 0
for line in sys.stdin.readlines():
anagram_hashes = set()
ok = True
for word in line.split():
anagram_hash = get_anagram_hash(word)
if anagram_hash in anagram_hashes:
ok = False
break
anagram_hashes.add(anagram_hash)
if ok:
total += 1

print(total)
1 change: 1 addition & 0 deletions 2017/04/2_out.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
231
Loading

0 comments on commit 9ac3b17

Please sign in to comment.