Adding chalenges

This commit is contained in:
Oxbian 2023-04-06 14:33:48 +02:00
parent 9dd0d0a832
commit 86fb727850
36 changed files with 447 additions and 0 deletions

0
C/Easy_Challenges/defibrillators.c Normal file → Executable file
View File

0
C/Easy_Challenges/horse-racing-duals.c Normal file → Executable file
View File

0
C/Easy_Challenges/onboarding.c Normal file → Executable file
View File

66
Easy_Challenges/ascii_art.c Executable file
View File

@ -0,0 +1,66 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
int main()
{
int L;
scanf("%d", &L);
int H;
scanf("%d", &H); fgetc(stdin);
char tab[L][1025];
char T[257];
scanf("%[^\n]", T); fgetc(stdin);
for (int i = 0; i < H; i++) {
char ROW[1025];
scanf("%[^\n]", ROW); fgetc(stdin);
for (int j=0; j<1025; j++)
tab[i][j] = ROW[j];
}
int size=0;
//On compte la taille du mot
for (int i =0; i < 257; i++)
{
if (T[i] != '\0')
{
size++;
//On convertit notre mot
if (T[i] > 96 && T[i] < 123)
T[i] -= 32;
}
else
break;
}
//Affichage du mot
for (int i = 0; i < H; i++) //On répète ça le nombre de lignes
{
for (int j = 0; j< size; j++) //Répétition du nombre de lettre pour afficher la ligne i de chaque lettre
{
int id = T[j] - 65;
//fprintf(stderr,"T = %d Id= %d\n",T[j],id);
if ((id >= 0 && id < 26))
{
for (int k =(id*L); k<((id+1)*(L)); k++)
{
printf("%c",tab[i][k]);
}
}
else
{
for (int k =(26*L); k<(27*(L)); k++)
{
printf("%c",tab[i][k]);
}
}
}
printf("\n");
}
// Write an answer using printf(). DON'T FORGET THE TRAILING \n
// To debug: fprintf(stderr, "Debug messages...\n");
return 0;
}

50
Easy_Challenges/chuck_norris.c Executable file
View File

@ -0,0 +1,50 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//Convert char into binary ascii
void charToBin(char c, char *buffer)
{
for (int i = 6; i >=0; i--)
{
buffer[i] = '0' + c%2;
c/=2;
}
buffer[7] = '\n';
}
int main()
{
char MESSAGE[101], binary[8], binMessage[707], prev;
int i = 0, j = 0, count = 0;
scanf("%[^\n]", MESSAGE);
binMessage[0] = '\0'; //Reset the string
for (int i = 0; i < strlen(MESSAGE); i++)
{
charToBin(MESSAGE[i], binary);
strncat(binMessage,binary,7); //Adding the binary of each char into the binMessage string
}
for (i =0; binMessage[i] != '\0'; i++)
{
if (binMessage[i] != prev)
{
for (j=0; j<count; j++)
printf("0");
if (count != 0)
printf(" ");
printf((binMessage[i] == '0') ? "00 " : "0 ");
count =1;
}
else
count++;
prev = binMessage[i];
}
for (int j = 0 ; j < count ; j++) //Showing the rest of the binMessage string
printf("0");
return 0;
}

View File

@ -0,0 +1,49 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main()
{
// the number of points used to draw the surface of Mars.
int surface_n;
scanf("%d", &surface_n);
for (int i = 0; i < surface_n; i++) {
// X coordinate of a surface point. (0 to 6999)
int land_x;
// Y coordinate of a surface point. By linking all the points together in a sequential fashion, you form the surface of Mars.
int land_y;
scanf("%d%d", &land_x, &land_y);
}
// game loop
while (1) {
int X;
int Y;
// the horizontal speed (in m/s), can be negative.
int h_speed;
// the vertical speed (in m/s), can be negative.
int v_speed;
// the quantity of remaining fuel in liters.
int fuel;
// the rotation angle in degrees (-90 to 90).
int rotate;
// the thrust power (0 to 4).
int power;
scanf("%d%d%d%d%d%d%d", &X, &Y, &h_speed, &v_speed, &fuel, &rotate, &power);
// Write an action using printf(). DON'T FORGET THE TRAILING \n
// To debug: fprintf(stderr, "Debug messages...\n");
int final_power = 0;
// 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).
if (Y > 1500)
final_power = 3;
if (Y < 1500 && v_speed < -35)
final_power = 4;
printf("0 %d\n",final_power);
}
return 0;
}

View File

@ -0,0 +1,49 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
int main()
{
// the X position of the light of power
int light_x;
// the Y position of the light of power
int light_y;
// Thor's starting X position
int initial_tx;
// Thor's starting Y position
int initial_ty;
scanf("%d%d%d%d", &light_x, &light_y, &initial_tx, &initial_ty);
// game loop
while (1)
{
// The remaining amount of turns Thor can move. Do not remove this line.
int remaining_turns;
scanf("%d", &remaining_turns);
char *dirX = "";
char *dirY = "";
if ((initial_tx >= 0 && initial_tx < 40) && (initial_ty >= 0 && initial_ty < 18))
{
if (initial_tx > light_x)
dirX = "W", initial_tx--;
else if (initial_tx < light_x)
dirX = "E", initial_tx++;
else
dirX = "";
if (initial_ty > light_y)
dirY = "N", initial_ty--;
else if (initial_ty < light_y)
dirY = "S", initial_ty++;
else
dirY = "";
}
printf("%s%s\n", dirY, dirX);
}
return 0;
}

40
Easy_Challenges/temperatures.c Executable file
View File

@ -0,0 +1,40 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#define TAILLE_MAX 10000
int main()
{
// the number of temperatures to analyse
int n,min=TAILLE_MAX;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
// a temperature expressed as an integer ranging from -273 to 5526
int t;
scanf("%d", &t);
if (abs((0-t)) < abs(0-min))
{
min = t;
}
else if (min == t)
{
min = t;
}
else if (abs(t) == abs(min))
{
min = abs(min);
}
}
// Write an answer using printf(). DON'T FORGET THE TRAILING \n
// To debug: fprintf(stderr, "Debug messages...\n");
if (min == TAILLE_MAX)
printf("0");
else
printf("%d",min);
return 0;
}

27
Easy_Challenges/the_descent.c Executable file
View File

@ -0,0 +1,27 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
int main()
{
// game loop
while (1) {
int mountain_max = 0, mountain_Id = 0;
for (int i = 0; i < 8; i++) {
// represents the height of one mountain.
int mountain_h;
scanf("%d", &mountain_h);
if (mountain_h > mountain_max)
{
mountain_max = mountain_h;
mountain_Id = i;
}
}
printf("%d\n",mountain_Id);
}
return 0;
}

View File

@ -0,0 +1,42 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
int main()
{
int W,H;
scanf("%d%d", &W, &H);
int N;
scanf("%d", &N);
int X0,Y0;
scanf("%d%d", &X0, &Y0);
int LX = 0, LY = 0, HX = W - 1, HY = H - 1;
// game loop
while (1) {
// the direction of the bombs from batman's current location (U, UR, R, DR, D, DL, L or UL)
char bomb_dir[4];
scanf("%s", bomb_dir);
fprintf(stderr,"La bombe est dans la direction: %s",bomb_dir);
if (bomb_dir[0] == 'L' || bomb_dir[1] == 'L')
HX = X0 - 1;
else if (bomb_dir[0] == 'R' || bomb_dir[1] == 'R')
LX = X0 + 1;
if (bomb_dir[0] == 'U')
HY = Y0 - 1;
else
LY = Y0 + 1;
X0 = (HX + LX) /2;
Y0 = (HY + LY) /2;
// the location of the next window Batman should jump to.
printf("%d %d\n",X0,Y0);
}
return 0;
}

View File

@ -0,0 +1,20 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
int main()
{
int n, v, max = 0, max_lost =0, curr_lost = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &v);
curr_lost = v-max;
if (curr_lost < max_lost) max_lost = curr_lost;
if (v>max) max = v;
}
printf("%d\n",max_lost);
return 0;
}

View File

@ -0,0 +1,64 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
int main()
{
// the number of cells on the X axis
int width;
scanf("%d", &width);
// the number of cells on the Y axis
int height;
scanf("%d", &height); fgetc(stdin);
// New grid which will contains all the stuff
char grid[30][30];
//Getting items from input and adding them into the grid
for (int i = 0; i < height; i++) {
char line[32];
scanf("%[^\n]", line); fgetc(stdin);
for(int j =0;j < 32; j++){
grid[i][j] = line[j];
}
}
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
//If we found a node, we print it's coordonnate and after check his neighbours
if (grid[y][x] == '0')
{
printf("%d %d ",x,y);
short x2, y2, ansX = -1, ansY = -1;
for (x2 = x+1; x2 < width; ++x2) //Checking if we found another node on the same line
{
if (grid[y][x2] == '0') //If node found we add it as neightbours and stop searching
{
ansX = x2;
ansY = y;
break;
}
}
printf("%d %d ",ansX, ansY);
ansX = -1; ansY = -1;
for (y2 = y+1; y2 < height; ++y2) //Checking if we found another node on the same column
{
if (grid[y2][x] == '0') //If we found we add it as neightbours and stop searching
{
ansX = x;
ansY = y2;
break;
}
}
printf("%d %d\n",ansX, ansY);
}
}
}
return 0;
}

0
Python/Easy_Challenges/defibrillators.py Normal file → Executable file
View File

0
Python/Easy_Challenges/horse_racing_duals.py Normal file → Executable file
View File

0
Python/Easy_Challenges/mars_lander_1.py Normal file → Executable file
View File

0
Python/Easy_Challenges/mime-type.py Normal file → Executable file
View File

0
Python/Easy_Challenges/onboarding.py Normal file → Executable file
View File

0
Python/Easy_Challenges/power_of_thor_1.py Normal file → Executable file
View File

0
Python/Easy_Challenges/temperatures.py Normal file → Executable file
View File

0
Python/Easy_Challenges/the_descent.py Normal file → Executable file
View File

0
Python/Medium_Challenges/conway_sequence.py Normal file → Executable file
View File

View File

@ -0,0 +1,18 @@
import sys
import math
r = int(input()) #Number of the origin
l = int(input()) #Line we want to found
tab = []
def conway(n,t):
if (t == l):
print(n); break
tab = n.split()
for i in range(tab.len(n)):
print("answer")

0
Python/Medium_Challenges/death_first_search_1.py Normal file → Executable file
View File

0
Python/Medium_Challenges/don't_panic_1.py Normal file → Executable file
View File

View File

0
Python/Medium_Challenges/mars_lander_2.py Normal file → Executable file
View File

0
Python/Medium_Challenges/mayan_calculations.py Normal file → Executable file
View File

View File

@ -0,0 +1,22 @@
import sys
x_min = 2**30
x_max = -2**30
y_list = []
nb_buildings = int(input())
for i in range(nb_buildings):
x, y = map(int, input().split())
y_list.append(y)
print(x,y, file=sys.stderr, flush=True)
if (x > x_max) : x_max = x
if (x < x_min) : x_min = x
cable_length = x_max - x_min
y_list.sort()
y_median : int = y_list[nb_buildings // 2]
for y in y_list:
cable_length += abs(y_median - y)
print(cable_length)

0
Python/Medium_Challenges/network_cabling.py Normal file → Executable file
View File

0
Python/Medium_Challenges/scrabble.py Normal file → Executable file
View File

0
Python/Medium_Challenges/stock_exchange_losses.py Normal file → Executable file
View File

0
Python/Medium_Challenges/telephone_numbers.py Normal file → Executable file
View File

0
Python/Medium_Challenges/the_fall_1.py Normal file → Executable file
View File

0
Python/Medium_Challenges/the_gift.py Normal file → Executable file
View File

0
Python/Medium_Challenges/winamax_battle.py Normal file → Executable file
View File

0
codingameLogo.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB