Skip to content

Instantly share code, notes, and snippets.

View maestroviktorin's full-sized avatar

Viktor Starodubtsev maestroviktorin

View GitHub Profile
@maestroviktorin
maestroviktorin / task-5714.py
Created January 8, 2023 19:49
Solution to the problem #5714 by V. Petrov from the website of K. Polyakov.
GRAPH = {'А': ('Б', 'В', 'Г'),
'Б': ('Д',),
'В': ('Д', 'Е'),
'Г': ('В', 'Е', 'Ж'),
'Д': ('К', 'З'),
'Е': ('Д', 'Ж', 'З', 'И'),
'Ж': ('И', 'М', 'Н'),
'З': ('К', 'М'),
'И': ('З', 'М'),
'К': ('Л', 'М'),
@maestroviktorin
maestroviktorin / task-5834.py
Created January 9, 2023 19:16
Solution to the problem #5834 by E. Usov from the website of K. Polyakov.
# Helpful hashmaps.
HEX_DEC = dict(zip('0123456789abcdef', tuple(range(16)))) # Pairs of digits - `hexadecimal`: `decimal`
DEC_HEX = dict(zip(tuple(range(16)), '0123456789abcdef')) # Pairs of digits - `decimal`: `hexadecimal`
# Implementation of the algorithm described in the problem.
def detective(n: int) -> str:
hex_n = hex(n)[2:]
hex_n += '0' if n % 2 else 'f'
@maestroviktorin
maestroviktorin / task-5404.py
Created January 11, 2023 20:38
Solution to the problem #5404 by E. Jobs from the website of K. Polyakov.
# This code is applicable only to the task No. 5404 by E. Jobs from the website of K. Polyakov
# and cannot be applied to other similar tasks.
from math import prod
def f(start: int):
if start < 8:
return 0
@maestroviktorin
maestroviktorin / task-4297.py
Created January 26, 2023 09:11
Solution to the problem #4297 by E. Jobs from the website of K. Polyakov.
"""
Problem #4297 from the website of K. Polyakov.
`3-4.csv` is the `Family ties` sheet, already prepared in Excel.
Each row looks like this:
`Parent ID`,`Child ID`,`City of the parent`,`City of the child`
The `City` values are pulled from the `People` sheet via `VLOOKUP`.
@maestroviktorin
maestroviktorin / task-4322.py
Created January 29, 2023 19:23
Solution to the problem #4322 by /dev/inf from kompege.ru
"""
Solution to the problem No. 4322 by /dev/inf from kompege.ru
`10.txt` is a text file in which the beginning and each line of type `Глава \d+`
must be deleted manually in the Notebook for example.
"""
import re
@maestroviktorin
maestroviktorin / task-6040.py
Created April 14, 2023 10:00
Solution to the problem #6040 by A. Rogov from the website of K. Polyakov.
with open('26-100.txt') as file:
rows = file.readlines()
N, M = tuple(int(x) for x in rows[0].split())
pipes = sorted(int(x) for x in rows[1:])
for i in range(N):
pipeline = [pipes[i]]
@maestroviktorin
maestroviktorin / task-6092.py
Created April 14, 2023 20:57
Solution to the problem #6092 from the website of K. Polyakov.
with open('26-101.txt') as file:
rows = file.readlines()
N, K = tuple(int(x) for x in rows[0].split())
crates = sorted((int(x) for x in rows[1:]), reverse=True)
blocks = list()
while crates:
block = [crates.pop(0)]
@maestroviktorin
maestroviktorin / task-7709.py
Last active May 15, 2023 19:57
Solution to the problem #7709 from kompege.ru
# Problem No. 7709 on https://www.kompege.ru
def does_not_intercept(pair_a: tuple[int, int], pair_b: tuple[int, int]) -> bool:
return all(x < pair_b[0] for x in pair_a) or all(x > pair_b[1] for x in pair_a)
with open('26_7709.txt') as file:
rows = file.readlines()
K = int(rows[0])
@maestroviktorin
maestroviktorin / task-8432.py
Last active May 15, 2023 20:04
Solution to the problem #8432 from kompege.ru
# Problem No. 8432 on https://www.kompege.ru
class Vehicle:
'''
Kind of struct describing a vehicle.
'''
def __init__(self, start: int, duration: int, _type: str):
self.start = start
self.end = start + duration
from random import randint
def print_info():
information = \
"""
Лабораторная работа № 2
Вариант № 20. Выполнил студент группы 6104-020302D Стародубцев Виктор
1. В списке целочисленных элементов найти максимальный нечётный элемент
2. С использованием цикла `while` найти в списке индекс последнего