Skip to content

Commit 9a27564

Browse files
committed
day06: s/for loops/generators!
1 parent e5eed35 commit 9a27564

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

day06/1.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66

77
def main():
88
data = sys.stdin.read().strip()
9-
for i in range(len(data) - WINSIZ):
10-
if len(set(data[i:i + WINSIZ])) == WINSIZ:
11-
print(i + WINSIZ)
12-
break
9+
nchars = next(i + WINSIZ for i in range(len(data) - WINSIZ)
10+
if len(set(data[i:i + WINSIZ])) == WINSIZ)
11+
print(nchars)
1312

1413
if __name__ == '__main__':
1514
main()

day06/2.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66

77
def main():
88
data = sys.stdin.read().strip()
9-
for i in range(len(data) - WINSIZ):
10-
if len(set(data[i:i + WINSIZ])) == WINSIZ:
11-
print(i + WINSIZ)
12-
break
9+
nchars = next(i + WINSIZ for i in range(len(data) - WINSIZ)
10+
if len(set(data[i:i + WINSIZ])) == WINSIZ)
11+
print(nchars)
1312

1413
if __name__ == '__main__':
1514
main()

0 commit comments

Comments
 (0)