Skip to content

Instantly share code, notes, and snippets.

@remi-dupre
Created January 23, 2023 19:03
Show Gist options
  • Save remi-dupre/7acbd83c3802266a283e25513d0604d8 to your computer and use it in GitHub Desktop.
Save remi-dupre/7acbd83c3802266a283e25513d0604d8 to your computer and use it in GitHub Desktop.
Tech challenger
from collections import Counter
moves = Counter(map(int, input().split()))
max_num = max(moves.values())
min_num = min(moves.values())
max_res = max(x for x, c in moves.items() if c == max_num)
min_res = min(x for x, c in moves.items() if c == min_num)
print(max_res - min_res)
n = int(input().strip())
m = int(input().strip())
groups = [int(input().strip()) for _ in range(m)]
possible_sums = {0}
for x in groups:
new_possible_sums = set(possible_sums)
for part in possible_sums:
new_possible_sums.add(x + part)
possible_sums = new_possible_sums
min_target = ((n + sum(groups) + 1) // 2) - n
print(min(k for k in possible_sums if k >= min_target))
import sys
from math import lcm
def apply_move(pos, move):
x, y = pos
match move:
case "R":
return x + 1, y
case "L":
return x - 1, y
case "U":
return x, y + 1
case "D":
return x, y - 1
target_x, target_y = tuple(map(int, input().split()))
moves = input().strip()
final_x, final_y = 0, 0
for move in moves:
final_x, final_y = apply_move((final_x, final_y), move)
x, y = 0, 0
answers = []
for step, move in enumerate(moves):
# target = x * final + pos ?
x_mul, y_mul = target_x - x, target_y - y
if final_x * x_mul < 0 or final_y * y_mul < 0:
x, y = apply_move((x, y), move)
continue
mul = 1
if final_x == 0:
if x_mul != 0:
x, y = apply_move((x, y), move)
continue
elif x_mul % final_x != 0:
x, y = apply_move((x, y), move)
continue
else:
mul = x_mul // final_x
if final_y == 0:
if y_mul != 0:
x, y = apply_move((x, y), move)
continue
elif y_mul % final_y != 0:
x, y = apply_move((x, y), move)
continue
else:
mul = lcm(mul, y_mul // final_y)
if mul * len(moves) + step < 2**63:
answers.append(mul * len(moves) + step)
x, y = apply_move((x, y), move)
if answers:
print(min(answers))
else:
print("not possible")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment