diff --git a/C/Easy_Challenges/ascii_art.c b/C/Easy_Challenges/ascii_art.c index f174f4c..e9d7af0 100755 --- a/C/Easy_Challenges/ascii_art.c +++ b/C/Easy_Challenges/ascii_art.c @@ -1,11 +1,8 @@ -#include #include -#include -#include - int main() { + //Getting the data int L; scanf("%d", &L); int H; @@ -21,13 +18,14 @@ int main() } int size=0; - //On compte la taille du mot + + //Counting the size of the word for (int i =0; i < 257; i++) { if (T[i] != '\0') { size++; - //On convertit notre mot + //Convert the word if (T[i] > 96 && T[i] < 123) T[i] -= 32; } @@ -35,10 +33,10 @@ int main() break; } - //Affichage du mot - for (int i = 0; i < H; i++) //On répète ça le nombre de lignes + //Printing the word + for (int i = 0; i < H; i++) //Repeat number of line times { - for (int j = 0; j< size; j++) //Répétition du nombre de lettre pour afficher la ligne i de chaque lettre + for (int j = 0; j< size; j++) //Repeat number of letter times { int id = T[j] - 65; //fprintf(stderr,"T = %d Id= %d\n",T[j],id); @@ -59,8 +57,6 @@ int main() } printf("\n"); } - // Write an answer using printf(). DON'T FORGET THE TRAILING \n - // To debug: fprintf(stderr, "Debug messages...\n"); return 0; } \ No newline at end of file diff --git a/C/Easy_Challenges/defibrillators b/C/Easy_Challenges/defibrillators deleted file mode 100755 index 423e528..0000000 Binary files a/C/Easy_Challenges/defibrillators and /dev/null differ diff --git a/C/Easy_Challenges/horse-racing-duals.c b/C/Easy_Challenges/horse-racing-duals.c new file mode 100644 index 0000000..13547fa --- /dev/null +++ b/C/Easy_Challenges/horse-racing-duals.c @@ -0,0 +1,25 @@ +#include +#include + +int compare (const void *arg1, const void *arg2) { + return (*(int*)arg1 - *(int*)arg2); +} + +int main() +{ + int N, diff = 2147483647; + scanf("%d", &N); + int tab[N]; + for (int i = 0; i < N; i++) + scanf("%d", &tab[i]); + + qsort (tab,N,sizeof(int),compare); + for (int i =0; i -#include #include - int main() { // the number of points used to draw the surface of Mars. diff --git a/C/Easy_Challenges/onboarding.c b/C/Easy_Challenges/onboarding.c new file mode 100644 index 0000000..f01a82c --- /dev/null +++ b/C/Easy_Challenges/onboarding.c @@ -0,0 +1,23 @@ +int main() +{ + // game loop + while (1) { + char enemy1[257]; // name of enemy 1 + scanf("%s", enemy1); + int dist1; // distance to enemy 1 + scanf("%d", &dist1); + char enemy2[257]; // name of enemy 2 + scanf("%s", enemy2); + int dist2; // distance to enemy 2 + scanf("%d", &dist2); + + if (dist1 < dist2) { + printf("%s\n", enemy1); + } else { + printf("%s\n", enemy2); + } + + } + + return 0; +} \ No newline at end of file diff --git a/C/Easy_Challenges/power_of_thor_1.c b/C/Easy_Challenges/power_of_thor_1.c index a5e0960..f31fb16 100755 --- a/C/Easy_Challenges/power_of_thor_1.c +++ b/C/Easy_Challenges/power_of_thor_1.c @@ -1,7 +1,4 @@ -#include #include -#include -#include int main() { @@ -17,8 +14,7 @@ int main() scanf("%d%d%d%d", &light_x, &light_y, &initial_tx, &initial_ty); // game loop - while (1) - { + while (1) { // The remaining amount of turns Thor can move. Do not remove this line. int remaining_turns; scanf("%d", &remaining_turns); @@ -29,19 +25,37 @@ int main() if ((initial_tx >= 0 && initial_tx < 40) && (initial_ty >= 0 && initial_ty < 18)) { if (initial_tx > light_x) - dirX = "W", initial_tx--; + { + dirX = "W"; + initial_tx--; + } else if (initial_tx < light_x) - dirX = "E", initial_tx++; + { + dirX = "E"; + initial_tx++; + } else + { dirX = ""; + } if (initial_ty > light_y) - dirY = "N", initial_ty--; + { + dirY = "N"; + initial_ty--; + } else if (initial_ty < light_y) - dirY = "S", initial_ty++; + { + dirY = "S"; + initial_ty++; + } else + { dirY = ""; + } } + + printf("%s%s\n", dirY, dirX); } diff --git a/C/Easy_Challenges/chuck_norris.c b/C/Easy_Challenges/unary.c similarity index 96% rename from C/Easy_Challenges/chuck_norris.c rename to C/Easy_Challenges/unary.c index 5f2f4ec..b2793ac 100755 --- a/C/Easy_Challenges/chuck_norris.c +++ b/C/Easy_Challenges/unary.c @@ -1,6 +1,4 @@ #include -#include -#include //Convert char into binary ascii void charToBin(char c, char *buffer) diff --git a/C/Medium_Challenges/shadow_of_knight_1.c b/C/Medium_Challenges/shadow_of_knight_1.c index a7abf20..31863c7 100755 --- a/C/Medium_Challenges/shadow_of_knight_1.c +++ b/C/Medium_Challenges/shadow_of_knight_1.c @@ -1,7 +1,5 @@ -#include #include -#include -#include + int main() { diff --git a/C/Medium_Challenges/stock_exchange_losses.c b/C/Medium_Challenges/stock_exchange_losses.c index 9a805f4..9a9b25f 100755 --- a/C/Medium_Challenges/stock_exchange_losses.c +++ b/C/Medium_Challenges/stock_exchange_losses.c @@ -1,7 +1,4 @@ -#include #include -#include -#include int main() { diff --git a/Python/Easy_Challenges/defibrillators.py b/Python/Easy_Challenges/defibrillators.py new file mode 100644 index 0000000..1f7bd9f --- /dev/null +++ b/Python/Easy_Challenges/defibrillators.py @@ -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) diff --git a/Python/Easy_Challenges/horse_racing_duals.py b/Python/Easy_Challenges/horse_racing_duals.py new file mode 100644 index 0000000..3d1fd85 --- /dev/null +++ b/Python/Easy_Challenges/horse_racing_duals.py @@ -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) diff --git a/Python/Easy_Challenges/mars_lander_1.py b/Python/Easy_Challenges/mars_lander_1.py new file mode 100644 index 0000000..c92c91a --- /dev/null +++ b/Python/Easy_Challenges/mars_lander_1.py @@ -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)) diff --git a/Python/Easy_Challenges/mime-type.py b/Python/Easy_Challenges/mime-type.py new file mode 100644 index 0000000..4f48848 --- /dev/null +++ b/Python/Easy_Challenges/mime-type.py @@ -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") + \ No newline at end of file diff --git a/Python/Easy_Challenges/onboarding.py b/Python/Easy_Challenges/onboarding.py new file mode 100644 index 0000000..f406222 --- /dev/null +++ b/Python/Easy_Challenges/onboarding.py @@ -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) diff --git a/Python/Easy_Challenges/power_of_thor_1.py b/Python/Easy_Challenges/power_of_thor_1.py new file mode 100644 index 0000000..b6d99fc --- /dev/null +++ b/Python/Easy_Challenges/power_of_thor_1.py @@ -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) diff --git a/Python/Easy_Challenges/temperatures.py b/Python/Easy_Challenges/temperatures.py new file mode 100644 index 0000000..a3eb37e --- /dev/null +++ b/Python/Easy_Challenges/temperatures.py @@ -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) diff --git a/Python/Easy_Challenges/the_descent.py b/Python/Easy_Challenges/the_descent.py new file mode 100644 index 0000000..70c1507 --- /dev/null +++ b/Python/Easy_Challenges/the_descent.py @@ -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))) diff --git a/Python/Medium_Challenges/don't_panic_1.py b/Python/Medium_Challenges/don't_panic_1.py new file mode 100644 index 0000000..06ad5b2 --- /dev/null +++ b/Python/Medium_Challenges/don't_panic_1.py @@ -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 diff --git a/Python/Medium_Challenges/stock_exchange_losses.py b/Python/Medium_Challenges/stock_exchange_losses.py new file mode 100644 index 0000000..c264ba1 --- /dev/null +++ b/Python/Medium_Challenges/stock_exchange_losses.py @@ -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) \ No newline at end of file diff --git a/Python/Medium_Challenges/winamax_battle.py b/Python/Medium_Challenges/winamax_battle.py new file mode 100644 index 0000000..4f005b9 --- /dev/null +++ b/Python/Medium_Challenges/winamax_battle.py @@ -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) \ No newline at end of file diff --git a/README.md b/README.md index 43e8ac8..b94faae 100755 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ __Be careful, a lot of my solutions aren't optimized because I didn't took time |Unary | [x](https://github.com/ARKAGEDON/CodingGame/blob/main/C/Easy_Challenges/unary.c) | | |Power of Thor - Chapter 1| [x](https://github.com/ARKAGEDON/CodingGame/blob/main/C/Easy_Challenges/power_of_thor_1.c) | | |Onboarding | [x]() | | -|Mars Lander - Chapter 1 | [x](https://github.com/ARKAGEDON/CodingGame/blob/main/C/Easy_Challenges/mars_landers_1.c) | | +|Mars Lander - Chapter 1 | [x](https://github.com/ARKAGEDON/CodingGame/blob/main/C/Easy_Challenges/mars_lander_1.c) | | |Horse racing duals | [x]() | | |Defibrillators | [x](https://github.com/ARKAGEDON/CodingGame/blob/main/C/Easy_Challenges/defibrillators.c) | | |The descent | [x](https://github.com/ARKAGEDON/CodingGame/blob/main/C/Easy_Challenges/the_descent.c) | | diff --git a/codingameLogo.png b/codingameLogo.png new file mode 100644 index 0000000..6e09ad6 Binary files /dev/null and b/codingameLogo.png differ