Roderic Day 4 роки тому
джерело
коміт
13e75058ab
4 змінених файлів з 68 додано та 0 видалено
  1. +11
    -0
      y2015/p02.py
  2. +12
    -0
      y2015/p03.py
  3. +23
    -0
      y2015/p04.py
  4. +22
    -0
      y2015/p05.py

+ 11
- 0
y2015/p02.py Переглянути файл

@@ -0,0 +1,11 @@
import sys


ans1 = 0
ans2 = 0
for line in sys.stdin.readlines():
a, b, c = sorted(map(int, line.split('x')))
ans1 += 2 * (a * b + b * c + a * c) + a * b
ans2 += a * b * c + 2 * (a + b)
print(ans1)
print(ans2)

+ 12
- 0
y2015/p03.py Переглянути файл

@@ -0,0 +1,12 @@
import sys
from itertools import accumulate as acc


text = sys.stdin.read()
dirs = dict(zip('<>^v', [-1, 1, -1j, 1j]))

ans1 = len({*acc(map(dirs.get, text))})
print(ans1)

ans2 = len({*acc(map(dirs.get, text[::2])), *acc(map(dirs.get, text[1::2]))})
print(ans2)

+ 23
- 0
y2015/p04.py Переглянути файл

@@ -0,0 +1,23 @@
import sys
from hashlib import md5
from multiprocessing import Pool


def mine(code, i):
hasher = md5()
hasher.update(f'{code}{i}'.encode())
return i, hasher.hexdigest()


if __name__ == '__main__':
code = sys.stdin.read().strip()
ans1 = None
ans2 = None
with Pool() as pool:
for i, coin in pool.starmap(mine, [(code, i) for i in range(10**7)]):
if ans1 is None and coin.startswith('00000'):
ans1 = i
if ans2 is None and coin.startswith('000000'):
ans2 = i
print(ans1)
print(ans2)

+ 22
- 0
y2015/p05.py Переглянути файл

@@ -0,0 +1,22 @@
import re
import sys


def checks1(string):
yield len(re.findall(r'([aeiou])', string)) >= 3
yield len(re.findall(r'(.)\1', string))
yield len(re.findall(r'(ab|cd|pq|xy)', string)) == 0


def checks2(string):
yield len(re.findall(r'(.)(.).*\1\2', string)) >= 1
yield len(re.findall(r'(.).\1', string)) >= 1


ans1 = 0
ans2 = 0
for line in sys.stdin.read().splitlines():
ans1 += all(checks1(line))
ans2 += all(checks2(line))
print(ans1)
print(ans2)

Завантаження…
Відмінити
Зберегти