mirror of
https://github.com/Oxbian/CodingGame.git
synced 2025-07-06 20:05:27 +02:00
Adding python files
This commit is contained in:
25
Python/Easy_Challenges/defibrillators.py
Normal file
25
Python/Easy_Challenges/defibrillators.py
Normal file
@ -0,0 +1,25 @@
|
||||
import sys
|
||||
import math
|
||||
|
||||
def distance (latA, lonA, latB, lonB):
|
||||
x = (float(lonB) - float(lonA)) * math.cos((float(latA) + float(latB)) / 2)
|
||||
y = (float(latB) - float(latA))
|
||||
return math.sqrt(x**2 + y**2) * 6371
|
||||
|
||||
lon = input()
|
||||
lon = float(lon.replace(",", "."))
|
||||
lat = input()
|
||||
lat = float(lat.replace(",", "."))
|
||||
n = int(input())
|
||||
defib = [input() for i in range(n)]
|
||||
minDist = float('inf')
|
||||
minName = ""
|
||||
|
||||
for i in range(n):
|
||||
entry = defib[i].split(';')
|
||||
dist = distance(lat, lon, float(entry[5].replace(",", ".")), float(entry[4].replace(",", ".")))
|
||||
if (dist < minDist):
|
||||
minDist = dist
|
||||
minName = entry[1]
|
||||
|
||||
print(minName)
|
12
Python/Easy_Challenges/horse_racing_duals.py
Normal file
12
Python/Easy_Challenges/horse_racing_duals.py
Normal file
@ -0,0 +1,12 @@
|
||||
import sys
|
||||
import math
|
||||
|
||||
n = int(input())
|
||||
pi = [int(input()) for i in range(n)]
|
||||
pi.sort()
|
||||
min = float('inf')
|
||||
for i in range(1,n):
|
||||
if (pi[i] - pi[i-1] < min):
|
||||
min = pi[i] - pi[i-1]
|
||||
|
||||
print(min)
|
30
Python/Easy_Challenges/mars_lander_1.py
Normal file
30
Python/Easy_Challenges/mars_lander_1.py
Normal file
@ -0,0 +1,30 @@
|
||||
import sys
|
||||
import math
|
||||
|
||||
# Auto-generated code below aims at helping you parse
|
||||
# the standard input according to the problem statement.
|
||||
|
||||
surface_n = int(input()) # the number of points used to draw the surface of Mars.
|
||||
for i in range(surface_n):
|
||||
# land_x: X coordinate of a surface point. (0 to 6999)
|
||||
# land_y: Y coordinate of a surface point. By linking all the points together in a sequential fashion, you form the surface of Mars.
|
||||
land_x, land_y = [int(j) for j in input().split()]
|
||||
|
||||
# game loop
|
||||
while True:
|
||||
# h_speed: the horizontal speed (in m/s), can be negative.
|
||||
# v_speed: the vertical speed (in m/s), can be negative.
|
||||
# fuel: the quantity of remaining fuel in liters.
|
||||
# rotate: the rotation angle in degrees (-90 to 90).
|
||||
# power: the thrust power (0 to 4).
|
||||
x, y, h_speed, v_speed, fuel, rotate, power = [int(i) for i in input().split()]
|
||||
|
||||
# Write an action using print
|
||||
# To debug: print("Debug messages...", file=sys.stderr, flush=True)
|
||||
if (y > 1500):
|
||||
power = 3
|
||||
if (y < 1500 and v_speed < -35):
|
||||
power = 4
|
||||
|
||||
# 2 integers: rotate power. rotate is the desired rotation angle (should be 0 for level 1), power is the desired thrust power (0 to 4).
|
||||
print("0 " + str (power))
|
22
Python/Easy_Challenges/mime-type.py
Normal file
22
Python/Easy_Challenges/mime-type.py
Normal file
@ -0,0 +1,22 @@
|
||||
import sys
|
||||
import math
|
||||
|
||||
n = int(input()) # Number of elements which make up the association table.
|
||||
q = int(input()) # Number Q of file names to be analyzed.
|
||||
d = {}
|
||||
for i in range(n):
|
||||
# ext: file extension
|
||||
# mt: MIME type.
|
||||
ext, mt = input().split()
|
||||
d[ext.lower()] = mt
|
||||
|
||||
for i in range(q):
|
||||
fname = input().lower().split(".") # One file name per line.
|
||||
#print(stderr,fname)
|
||||
if (len(fname) == 2 and fname[1] in d):
|
||||
print(d[fname[1]])
|
||||
elif (len(fname) > 2 and fname[len(fname)-1] in d):
|
||||
print(d[fname[len(fname)-1]])
|
||||
else:
|
||||
print("UNKNOWN")
|
||||
|
11
Python/Easy_Challenges/onboarding.py
Normal file
11
Python/Easy_Challenges/onboarding.py
Normal file
@ -0,0 +1,11 @@
|
||||
# game loop
|
||||
while 1:
|
||||
enemy_1 = input() # name of enemy 1
|
||||
dist_1 = int(input()) # distance to enemy 1
|
||||
enemy_2 = input() # name of enemy 2
|
||||
dist_2 = int(input()) # distance to enemy 2
|
||||
|
||||
if (dist_1 < dist_2):
|
||||
print(enemy_1)
|
||||
else:
|
||||
print(enemy_2)
|
27
Python/Easy_Challenges/power_of_thor_1.py
Normal file
27
Python/Easy_Challenges/power_of_thor_1.py
Normal file
@ -0,0 +1,27 @@
|
||||
# light_x: the X position of the light of power
|
||||
# light_y: the Y position of the light of power
|
||||
# initial_tx: Thor's starting X position
|
||||
# initial_ty: Thor's starting Y position
|
||||
light_x, light_y, initial_tx, initial_ty = [int(i) for i in input().split()]
|
||||
|
||||
# game loop
|
||||
while True:
|
||||
remaining_turns = int(input()) # The remaining amount of turns Thor can move. Do not remove this line.
|
||||
result = ""
|
||||
|
||||
if (initial_ty > light_y):
|
||||
result += "N"
|
||||
initial_ty -= 1
|
||||
elif (initial_ty < light_y):
|
||||
result += "S"
|
||||
initial_ty += 1
|
||||
|
||||
if (initial_tx > light_x):
|
||||
result += "W"
|
||||
initial_tx += 1
|
||||
elif (initial_tx < light_x):
|
||||
result += "E"
|
||||
initial_tx -= 1
|
||||
|
||||
# A single line providing the move to be made: N NE E SE S SW W or NW
|
||||
print(result)
|
19
Python/Easy_Challenges/temperatures.py
Normal file
19
Python/Easy_Challenges/temperatures.py
Normal file
@ -0,0 +1,19 @@
|
||||
import sys
|
||||
import math
|
||||
|
||||
n = int(input()) # the number of temperatures to analyse
|
||||
min = float('inf')
|
||||
for i in input().split():
|
||||
# t: a temperature expressed as an integer ranging from -273 to 5526
|
||||
t = int(i)
|
||||
if (abs(0-t) < abs(0-min)):
|
||||
min = t
|
||||
elif min == t:
|
||||
min = t
|
||||
elif abs(min) == abs(t):
|
||||
min = abs(min)
|
||||
|
||||
if (min == float('inf')):
|
||||
print(0)
|
||||
else:
|
||||
print(min)
|
7
Python/Easy_Challenges/the_descent.py
Normal file
7
Python/Easy_Challenges/the_descent.py
Normal file
@ -0,0 +1,7 @@
|
||||
import sys
|
||||
import math
|
||||
|
||||
# game loop
|
||||
while True:
|
||||
mountain_h = [int(input()) for i in range(8)] # represents the height of one mountain.
|
||||
print(mountain_h.index(max(mountain_h)))
|
45
Python/Medium_Challenges/don't_panic_1.py
Normal file
45
Python/Medium_Challenges/don't_panic_1.py
Normal file
@ -0,0 +1,45 @@
|
||||
import sys
|
||||
import math
|
||||
|
||||
# Auto-generated code below aims at helping you parse
|
||||
# the standard input according to the problem statement.
|
||||
|
||||
# nb_floors: number of floors
|
||||
# width: width of the area
|
||||
# nb_rounds: maximum number of rounds
|
||||
# exit_floor: floor on which the exit is found
|
||||
# exit_pos: position of the exit on its floor
|
||||
# nb_total_clones: number of generated clones
|
||||
# nb_additional_elevators: ignore (always zero)
|
||||
# nb_elevators: number of elevators
|
||||
nb_floors, width, nb_rounds, exit_floor, exit_pos, nb_total_clones, nb_additional_elevators, nb_elevators = [int(i) for i in input().split()]
|
||||
print(exit_floor, exit_pos, file=sys.stderr, flush=True)
|
||||
d = {}
|
||||
for i in range(nb_elevators):
|
||||
# elevator_floor: floor on which this elevator is found
|
||||
# elevator_pos: position of the elevator on its floor
|
||||
elevator_floor, elevator_pos = [int(j) for j in input().split()]
|
||||
d[elevator_floor] = elevator_pos
|
||||
print(d, file=sys.stderr, flush=True)
|
||||
|
||||
round = 0
|
||||
# game loop
|
||||
while True:
|
||||
round += 1
|
||||
inputs = input().split()
|
||||
clone_floor = int(inputs[0]) # floor of the leading clone
|
||||
clone_pos = int(inputs[1]) # position of the leading clone on its floor
|
||||
direction = inputs[2] # direction of the leading clone: LEFT or RIGHT
|
||||
print(clone_pos, clone_floor, direction, file=sys.stderr, flush=True)
|
||||
if (clone_floor == exit_floor):
|
||||
if ((exit_pos < clone_pos and direction == "RIGHT") or (exit_pos > clone_pos and direction == "LEFT")):
|
||||
print("BLOCK")
|
||||
else:
|
||||
print("WAIT")
|
||||
else:
|
||||
if ((d.get(clone_floor, clone_pos+1) < clone_pos and direction == "RIGHT") or (d.get(clone_floor,clone_pos-1) > clone_pos and direction == "LEFT")):
|
||||
print("BLOCK")
|
||||
else:
|
||||
print("WAIT")
|
||||
# Write an action using print
|
||||
# To debug: print("Debug messages...", file=sys.stderr, flush=True
|
10
Python/Medium_Challenges/stock_exchange_losses.py
Normal file
10
Python/Medium_Challenges/stock_exchange_losses.py
Normal file
@ -0,0 +1,10 @@
|
||||
n = int(input())
|
||||
max = 0
|
||||
max_lost = 0
|
||||
for i in input().split():
|
||||
curr_lost = int(i) - max
|
||||
if (curr_lost < max_lost):
|
||||
max_lost = curr_lost
|
||||
if (int(i) > max):
|
||||
max = int(i)
|
||||
print(max_lost)
|
32
Python/Medium_Challenges/winamax_battle.py
Normal file
32
Python/Medium_Challenges/winamax_battle.py
Normal file
@ -0,0 +1,32 @@
|
||||
import sys
|
||||
import math
|
||||
|
||||
val = {'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9,'10':10,'J':11,'Q':12,'K':13,'A':14}
|
||||
|
||||
n = int(input()) # the number of cards for player 1
|
||||
cardp_1 = [val[input()[:-1]] for i in range(n)]
|
||||
m = int(input()) # the number of cards for player 2
|
||||
cardp_2 = [val[input()[:-1]] for i in range(m)]
|
||||
|
||||
round = 0
|
||||
|
||||
def smallest_deck(): return min(len(cardp_1), len(cardp_2))
|
||||
|
||||
while ( smallest_deck() > 0):
|
||||
round+=1
|
||||
print(cardp_1, cardp_2, file=sys.stderr, flush=True)
|
||||
compare = 0
|
||||
while (cardp_1[compare] == cardp_2[compare]):
|
||||
compare += 4
|
||||
if compare > smallest_deck(): print("PAT"); break
|
||||
|
||||
if cardp_1[compare] > cardp_2[compare]:
|
||||
cardp_1 = cardp_1[compare+1:] + cardp_1[:compare+1] + cardp_2[:compare+1]
|
||||
cardp_2 = cardp_2[compare+1:]
|
||||
else:
|
||||
cardp_2 = cardp_2[compare+1:] + cardp_1[:compare+1] + cardp_2[:compare+1]
|
||||
cardp_1 = cardp_1[compare+1:]
|
||||
|
||||
winner = 1 if len(cardp_2) == 0 else 2
|
||||
|
||||
print(winner, round)
|
Reference in New Issue
Block a user