├── .gitignore ├── BOT PROGRAMMING ├── BACK TO THE CODE │ └── c++ │ │ ├── Readme.md │ │ └── back-to-the-code.cpp ├── BOOTERS OF THE GALAXY │ └── python3 │ │ ├── booters-of-the-galaxy-bronze.py │ │ ├── booters-of-the-galaxy-wood-1.py │ │ ├── booters-of-the-galaxy-wood-6-to-2.py │ │ └── booters-of-the-galaxy-wood-arhive.py ├── CODE OF KUTULU │ ├── c# │ │ └── code-of-kutulu.cs │ ├── c++ │ │ └── code-of-kutulu.cpp │ ├── go │ │ └── code-of-kutulu-wood-3-2-1.go │ └── python3 │ │ └── code-of-kutulu.py ├── CODE ROYALE │ ├── c# │ │ └── code-royale-bronze.cs │ └── python3 │ │ ├── code-royale-wood-1.py │ │ ├── code-royale-wood-2.py │ │ └── code-royale-wood-3.py ├── CODE4LIFE │ ├── python │ │ ├── Readme.md │ │ ├── code4life-gold.py │ │ └── code4life-silver.py │ └── python3 │ │ ├── code4life-bronze.py │ │ ├── code4life-wood-1.py │ │ └── code4life-wood-2.py ├── CODEBUSTERS │ └── java │ │ └── codebusters.java ├── CODERS OF THE CARRIBEAN │ └── python3 │ │ ├── coders-of-the-caribbean-alternative.py │ │ └── coders-of-the-caribbean.py ├── CODERS STRIKE BACK │ ├── README.md │ └── python3 │ │ ├── coders-strike-back-bronze.py │ │ ├── coders-strike-back-cold.py │ │ ├── coders-strike-back-silver.py │ │ ├── coders-strike-back-tutorial.py │ │ ├── coders-strike-wood-1.py │ │ ├── coders-strike-wood-2.py │ │ └── coders-strike-wood-3.py ├── FANTASTIC BITS │ ├── c++ │ │ └── fantastic-bits.cpp │ └── python3 │ │ └── fantastic-bits-wood-2.py ├── GAME OF DRONES │ ├── php │ │ ├── Readme.md │ │ └── game-of-drones-silver.php │ ├── python │ │ └── game-of-drones-silver.py │ └── python3 │ │ ├── game-of-drones-bronze.py │ │ ├── game-of-drones-wood-1.py │ │ └── game-of-drones-wood-2.py ├── GHOST IN THE CELL │ ├── python3 │ │ ├── ghost-in-the-cell-bronze.py │ │ └── ghost-in-the-cell-wood.py │ └── scala │ │ └── ghost-in-the-cell-bronze.scala ├── GREATE ESCAPE │ ├── c++ │ │ └── great-escape.cpp │ └── python3 │ │ └── great-escape-wood2.py ├── HYPERSONIC │ └── c++ │ │ └── hypersonic.cpp ├── LEGENDS OF CODE & MAGIC │ └── python3 │ │ ├── legends-of-code-magic-wood-2.py │ │ └── legends-of-code-magic-wood-3.py ├── MEAN MAX │ ├── java │ │ ├── Readme.md │ │ └── mean-max-bronze-silver-gold.java │ └── python3 │ │ ├── Readme.md │ │ ├── mean-max-bronze.py │ │ ├── mean-max-wood-1.py │ │ ├── mean-max-wood-2.py │ │ └── mean-max-wood-3.py ├── PLATINUM RIFT - EPISODE 1 │ └── с++ │ │ └── platinum-rift-episode-1.cpp ├── PLATINUM RIFT - EPISODE 2 │ ├── c# │ │ └── platinum-rift-episode-2.cs │ └── c++ │ │ └── platinum-rift-episode-2.cpp ├── POKER CHIP RACE │ └── javascript │ │ └── poker-chip-race.js ├── SMASH THE CODE │ └── java │ │ └── smash-the-code.java ├── TICTACTOE │ └── python3 │ │ ├── tic-tac-toe-bronze.py │ │ ├── tic-tac-toe-silver.py │ │ └── tic-tac-toe-wood.py ├── TRON BATTLE │ └── python3 │ │ └── tron-battle.py └── WONDEV WOMAN │ ├── c++ │ └── wondev-woman-wood-1-silver-gold.cpp │ └── python3 │ ├── wondev-woman-wood-2.py │ └── wondev-woman-wood-3.py ├── CLASHOFCODE ├── functions │ ├── debug.py │ └── only-some-charasters.py └── solutions │ ├── fastest │ ├── 01 │ │ ├── Readme.md │ │ ├── __init__.py │ │ └── solution.py │ ├── 02 │ │ ├── Readme.md │ │ ├── __init__.py │ │ └── solution.py │ ├── 03 │ │ ├── Readme.md │ │ ├── __init__.py │ │ └── solution.py │ ├── 04 │ │ ├── Readme.md │ │ ├── __init__.py │ │ └── solution.py │ ├── 05 │ │ ├── Readme.md │ │ ├── __init__.py │ │ └── solution.py │ └── 06 │ │ ├── Readme.md │ │ ├── __init__.py │ │ └── solution.py │ ├── reverse │ ├── 01 │ │ ├── Readme.md │ │ ├── __init__.py │ │ └── solution.py │ ├── 02 │ │ ├── Readme.md │ │ ├── __init__.py │ │ └── solution.py │ ├── 03 │ │ ├── Readme.md │ │ ├── __init__.py │ │ └── solution.py │ ├── 04 │ │ ├── Readme.md │ │ ├── __init__.py │ │ └── solution.py │ └── 05 │ │ ├── Readme.md │ │ ├── __init__.py │ │ └── solution.py │ └── shortest │ ├── 01 │ ├── readme.md │ ├── solution.py │ └── solution2.py │ ├── 02 │ ├── readme.md │ └── solution.py │ └── 03 │ ├── Readme.md │ └── solution.py ├── CODE GOLF ├── DONT PANIC │ └── python3 │ │ └── don't-panic.py ├── POWER OF THOR │ ├── php │ │ └── power-of-thor.php │ └── python3 │ │ └── power-of-thor.py └── TEMPERATURE │ └── python3 │ └── temperature-code-golf.py ├── COMMUNITY PUZZLES ├── ADVANCED TREE │ └── python3 │ │ └── ___advanced-tree.py ├── BUST SPEEDING VEHICLES │ └── python3 │ │ └── bust-speeding-vehicles.py ├── ELEMENTARY-CELLULAR-AUTOMATION │ └── python3 │ │ └── elementary-cellular-automaton.py ├── HIGHEST TRUNCADED PYRAMID │ └── python3 │ │ └── highest-truncated-pyramid.py ├── PAPER-FOLDING CURVE │ └── python3 │ │ └── paper-folding-curve.py ├── SPREADSHEET LABELS │ └── python3 │ │ └── spreadsheet-labels.py └── THE FASTEST │ └── python3 │ └── the-fastest.py ├── CONTEST ├── BOOTERS OF THE GALAXY │ └── python3 │ │ ├── botters-of-the-galaxy-wood-1.py │ │ ├── botters-of-the-galaxy-wood-2.py │ │ └── botters-of-the-galaxy-wood-3.py ├── CODE OF KUTULU │ └── python3 │ │ └── code-of-kutulu.py ├── CODE ROYALE │ └── python3 │ │ ├── arhive.py │ │ ├── code-royale-bronze.py │ │ ├── code-royale-silver.py │ │ ├── code-royale-wood-1.py │ │ ├── code-royale-wood-2.py │ │ ├── code-royale-wood-3.py │ │ └── new_logic.py ├── LEGENDS OF CODE AND MAGIC (SPRINT) │ └── python3 │ │ └── .gitignore └── Readme.md ├── EASY ├── ASCII ART │ ├── Readme.md │ ├── php │ │ └── ascii-art.php │ ├── python │ │ └── scii-art.py │ └── python3 │ │ └── scii-art.py ├── BANK ROBBERS │ └── python3 │ │ └── bank-robbers.py ├── CHACK NORIS │ ├── Readme.md │ ├── img │ │ └── cn.png │ ├── pyhon3 │ │ └── chuck-norris.py │ └── pyton │ │ └── chuck-norris.py ├── DEFIBRILLATORS │ ├── Readme.md │ ├── img │ │ └── heart.gif │ ├── php │ │ └── defibrillators.php │ ├── python │ │ └── defibrillators.py │ └── python3 │ │ └── defibrillators.py ├── GRAVITY TUMBER │ └── python3 │ │ └── gravity-tumbler.py ├── HORSE RASING DUALS │ ├── Readme.md │ ├── bash │ │ └── horse-racing-duals.bash │ ├── php │ │ └── horse-racing-duals.php │ ├── python │ │ └── horse-racing-duals.py │ └── python3 │ │ └── horse-racing-duals.py ├── MARS LANDER - EPISODE 1 │ ├── php │ │ └── mars-lander-episode-1.php │ ├── python │ │ └── mars-lander-episode-1.py │ └── python3 │ │ └── mars-lander-episode-1.py ├── MYME TYPE │ ├── Readme.md │ ├── php │ │ └── mime-type.php │ ├── python │ │ └── mime-type.py │ └── python3 │ │ └── mime-type.py ├── ONBOARDING │ ├── bash │ │ ├── onboarding.bash │ │ └── onboarding2.bash │ ├── c# │ │ └── onboarding.cs │ ├── c++ │ │ └── onboarding.cpp │ ├── c │ │ └── onboarding.c │ ├── clojure │ │ └── onboarding.clj │ ├── dart │ │ └── onboarding.dart │ ├── f# │ │ └── onboarding.fs │ ├── go │ │ └── onboarding.go │ ├── java │ │ └── onboarding.java │ ├── js │ │ └── onboarding.js │ ├── php │ │ └── onboarding.php │ ├── python │ │ └── onboarding.py │ └── python3 │ │ └── onboarding.py ├── ORDER OF SUCCESSION │ └── python3 │ │ └── order-of-succession.py ├── POWER OF THOR - EPISODE 1 │ ├── Readme.md │ ├── php │ │ └── power-of-thor-episode-1.php │ ├── python │ │ └── power-of-thor-episode-1.py │ └── python3 │ │ └── power-of-thor-episode-1.py ├── TEMPERATURES │ ├── Readme.md │ ├── bash │ │ └── temperatures.sh │ ├── c++ │ │ └── temperatures.cpp │ ├── img │ │ └── temp_fr.png │ ├── java │ │ └── temperatures.java │ ├── js │ │ └── temperatures.js │ ├── php │ │ └── temperatures.php │ ├── python │ │ └── temperatures.py │ └── python3 │ │ └── temperatures.py ├── THE DESCENT │ ├── php │ │ └── the-descent.php │ ├── python │ │ └── the-descent.py │ └── python3 │ │ └── the-descent.py ├── THE RIVER II. │ └── java │ │ └── the-river-ii-.java ├── THE RIVER II │ └── java │ │ └── the-river-ii-.java └── THE TRAVELLING SALESMAN PROBLEM │ └── java │ └── the-travelling-salesman-problem.java ├── HARD ├── 7-SEGMENT DISPLAY │ ├── __init__.py │ └── python │ │ ├── 7-segment-display.py │ │ └── __init__.py ├── BENDER - EPISODE 2 │ └── python3 │ │ └── bender-episode-2.py ├── BENDER - EPISODE 3 │ ├── kotlin │ │ └── bender-episode-3.kt │ └── python │ │ └── bender-episode-3.py ├── CGX FORMATTER │ ├── Readme.md │ ├── img │ │ ├── cgx5.png │ │ ├── cgx6.png │ │ └── cgx7.png │ └── python3 │ │ └── cgx-formatter.py ├── DON'T PANIC - EPISODE 2 │ └── java │ │ └── don't-panic-episode-2.java ├── GENOME SEQUENCING │ ├── Readme.md │ └── python3 │ │ └── genome-sequencing.py ├── POWER OF THOR - EPISODE 2 │ ├── Readme.md │ └── python3 │ │ ├── power-of-thor-episode-2-100-percent.py │ │ └── power-of-thor-episode-2-40-percent.py ├── ROLLER COASTER │ ├── Readme.md │ ├── img │ │ └── roller.png │ └── python3 │ │ └── roller-coaster.py ├── SKYNET REVOLUTION - EPISODE 2 │ ├── php │ │ └── skynet-revolution-episode-2.php │ ├── python3 │ │ └── skynet-revolution-episode-2-60-percent.py │ └── ruby │ │ └── skynet-revolution-episode-2.rb ├── SUPER COMPUTER │ ├── Readme.md │ └── python3 │ │ └── super-computer.py ├── SURFACE │ ├── Readme.md │ ├── img │ │ └── Painter.png │ └── python3 │ │ └── surface.py ├── TAN NETWORK │ ├── Readme.md │ └── python3 │ │ └── tan-network.py ├── THE BRIDGE │ └── js │ │ └── the-bridge-episode-2.js ├── THE HUNGRY DUCK - PART 1 │ ├── __init__.py │ ├── php │ │ └── the-hungry-duck---part-1.php │ └── python3 │ │ ├── __init__.py │ │ └── the-hungry-duck---part-1.py ├── THE HUNGRY DUCK - PART 2 │ ├── __init__.py │ ├── php │ │ └── the-hungry-duck---part-2.php │ └── python3 │ │ ├── __init__.py │ │ └── the-hungry-duck---part-2.py ├── THE LABYRINTH │ ├── Readme.md │ └── python3 │ │ └── the-labyrinth.py ├── THE LAST CRUSADE - EPISODE 2 │ └── c# │ │ └── the-last-crusade-episode-2.cs ├── THE-GREATEST-NUMBER │ ├── __init__.py │ └── python3 │ │ ├── __init__.py │ │ └── the-greatest-number.py ├── THERE IS NO SPOON - EPISODE 2 │ ├── c │ │ └── there-is-no-spoon-episode-2.c │ └── java │ │ └── there-is-no-spoon-episode-2.java ├── VOX CODEI - EPISODE 1 │ └── js │ │ └── vox-codei-episode-1.js ├── WINAMAX SPONSORED CONTEST │ └── python3 │ │ └── winamax-sponsored-contest.py └── __init__.py ├── MACHINE LEARNING └── python │ └── deep-learning-tensorflow.py ├── MEDIUM ├── BENDER - EPISODE 1 │ ├── Readme.md │ ├── img │ │ ├── bender1-small.png │ │ └── bender2-small.jpg │ └── python3 │ │ └── bender-episode-1.py ├── CONWAY SEQUENCE │ ├── Readme.md │ ├── php │ │ └── conway-sequence.php │ ├── python │ │ └── conway-sequence.py │ └── python3 │ │ └── conway-sequence.py ├── DON'T PANIC - EPISODE 1 │ └── python3 │ │ └── don't-panic-episode-1.py ├── DWARFS STANDING ON THE SHOULDERS OF GIANTS │ ├── Readme.md │ ├── img │ │ ├── dg1.png │ │ ├── dg2.png │ │ ├── dg3.png │ │ ├── dg4.png │ │ └── dg5.png │ └── python3 │ │ └── dwarfs-standing-on-the-shoulders-of-giants.py ├── GAME OF LIFE │ ├── __init__.py │ └── python3 │ │ ├── __init__.py │ │ └── game-of-life.py ├── MARS LANDER │ ├── python │ │ └── mars-lander-episode-2.py │ └── python3 │ │ └── mars-lander-episode-2.py ├── MAYAN CALCULATION │ └── python3 │ │ └── mayan-calculation.py ├── NETWORK CABLING │ ├── Readme.md │ ├── img │ │ └── img │ │ │ ├── example.png │ │ │ ├── example2.png │ │ │ └── fig1.png │ └── python3 │ │ └── network-cabling.py ├── SCRABBLE │ ├── Readme.md │ ├── python │ │ └── scrabble.py │ └── python3 │ │ └── scrabble.py ├── SHADOW OF THE KNIGHT - EPISODE 1 │ ├── php │ │ └── shadows-of-the-knight-episode-1.php │ ├── python │ │ └── shadows-of-the-knight-episode-1.py │ └── python3 │ │ └── shadows-of-the-knight-episode-1.py ├── SKYNET REVOLUTION - EPISODE 1 │ ├── Readme.md │ ├── img │ │ ├── Skynet1.jpg │ │ ├── Skynet1_2.jpg │ │ ├── Skynet1_3.jpg │ │ ├── Skynet1_4.jpg │ │ └── terminator_bike.png │ ├── python │ │ └── skynet-revolution-episode-1.py │ └── python3 │ │ └── skynet-revolution-episode-1.py ├── STOCK EXCHANGE LOSSES │ ├── Readme.md │ ├── img │ │ ├── perte1.png │ │ ├── perte2.png │ │ ├── profit.png │ │ └── stock_exchange_losses.jpg │ └── python3 │ │ └── stock-exchange-losses.py ├── TEADS SPONSORED CONTEST │ └── python3 │ │ ├── teads-sponsored-contest-100-percent.py │ │ └── teads-sponsored-contest-80-percent.py ├── TELEPHONE NUMBERS │ ├── Readme.md │ └── python3 │ │ └── telephone-numbers.py ├── TEXT ALIGNMENT │ ├── __init__.py │ ├── python │ │ ├── __init__.py │ │ └── text-alignment.py │ └── python3 │ │ ├── __init__.py │ │ └── text-alignment.py ├── THE GIFT │ └── python3 │ │ └── the-gift.py ├── THE LAST CRUSADE - EPISODE 1 │ └── python3 │ │ └── the-last-crusade-episode-1.py ├── THERE IS NO SPOON - EPISODE 1 │ ├── php │ │ └── there-is-no-spoon-episode-1.php │ └── python3 │ │ └── there-is-no-spoon-episode-1.py ├── WAR │ ├── python │ │ └── winamax-battle.py │ └── python3 │ │ └── winamax-battle.py └── __init__.py ├── MULTIPLAYER └── CODERS STRIKE BACK │ └── python3 │ └── 04_Silver_League.py ├── OPTIMISATION ├── CODE OF RINGS │ └── code-of-the-rings.py ├── CODE VS ZOMBIES │ └── python3 │ │ └── code-vs-zombies.py ├── CODINGAME SPONSORED CONTEST │ └── python3 │ │ └── codingame-sponsored-contest.py ├── MARS LANDER │ └── php │ │ └── mars-lander.php ├── NINTENDO SPONSORED CONTEST │ └── c++ │ │ └── contest.cpp └── WINAMAX SPONSORED CONTEST │ └── python3 │ └── winamax-sponsored-contest.py ├── README.md └── VERY HARD ├── MARS LANDER - EPISODE 3 └── java │ └── mars-lander-episode-3.java ├── MUSIC SCORES └── java │ └── music-scores.java ├── SHADOW OF THE KNIGHT - EPISODE 2 └── java │ └── shadows-of-the-knight-episode-2.java ├── THE LAST CRUSADE - EPISODE 3 └── java │ └── the-last-crusade-episode-3.java ├── THE RESISTANCE ├── c++ │ └── the-resistance.cpp └── java │ └── the-resistance.java └── VOX CODEI - EPISODE 2 └── c++ └── vox-codei-episode-2.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | .idea -------------------------------------------------------------------------------- /BOT PROGRAMMING/BACK TO THE CODE/c++/Readme.md: -------------------------------------------------------------------------------- 1 | @copyright https://github.com/DollarAkshay -------------------------------------------------------------------------------- /BOT PROGRAMMING/CODE4LIFE/python/Readme.md: -------------------------------------------------------------------------------- 1 | @copyright code4life-gold && code4life-silver https://github.com/Di0niz/ -------------------------------------------------------------------------------- /BOT PROGRAMMING/CODERS STRIKE BACK/README.md: -------------------------------------------------------------------------------- 1 | https://www.codingame.com/ide/puzzle/coders-strike-back -------------------------------------------------------------------------------- /BOT PROGRAMMING/CODERS STRIKE BACK/python3/coders-strike-back-tutorial.py: -------------------------------------------------------------------------------- 1 | # https://www.codingame.com/ide/puzzle/coders-strike-back 2 | # This code automatically collects game data in an infinite loop. 3 | # It uses the standard input to place data into the game variables such as x and y. 4 | # YOU DO NOT NEED TO MODIFY THE INITIALIZATION OF THE GAME VARIABLES. 5 | # game loop 6 | while True: 7 | # x: x position of your pod 8 | # y: y position of your pod 9 | # next_checkpoint_x: x position of the next check point 10 | # next_checkpoint_y: y position of the next check point 11 | x, y, next_checkpoint_x, next_checkpoint_y = [int(i) for i in input().split()] 12 | # Edit this line to output the target position 13 | # and thrust (0 <= thrust <= 100) 14 | # i.e.: "x y thrust" 15 | print(str(next_checkpoint_x) + " " + str(next_checkpoint_y) + " 100") 16 | -------------------------------------------------------------------------------- /BOT PROGRAMMING/CODERS STRIKE BACK/python3/coders-strike-wood-1.py: -------------------------------------------------------------------------------- 1 | # https://www.codingame.com/ide/puzzle/coders-strike-back 2 | # game loop 3 | while True: 4 | # next_checkpoint_x: x position of the next check point 5 | # next_checkpoint_y: y position of the next check point 6 | # next_checkpoint_dist: distance to the next checkpoint 7 | # next_checkpoint_angle: angle between your pod orientation and the direction of the next checkpoint 8 | x, y, next_checkpoint_x, next_checkpoint_y, next_checkpoint_dist, next_checkpoint_angle = [int(i) for i in 9 | input().split()] 10 | opponent_x, opponent_y = [int(i) for i in input().split()] 11 | trust = 0 12 | if next_checkpoint_angle > 90 or next_checkpoint_angle < -90: 13 | trust = str(10) 14 | else: 15 | if trust < 50: 16 | trust = 'BOOST' 17 | else: 18 | trust = str(100) 19 | 20 | # You have to output the target position 21 | # followed by the power (0 <= thrust <= 100) 22 | # i.e.: "x y thrust" 23 | print(str(next_checkpoint_x) + " " + str(next_checkpoint_y) + " " + trust) 24 | # result https://www.codingame.com/replay/246125257 -------------------------------------------------------------------------------- /BOT PROGRAMMING/CODERS STRIKE BACK/python3/coders-strike-wood-2.py: -------------------------------------------------------------------------------- 1 | # https://www.codingame.com/ide/puzzle/coders-strike-back 2 | # game loop 3 | while True: 4 | # next_checkpoint_x: x position of the next check point 5 | # next_checkpoint_y: y position of the next check point 6 | # next_checkpoint_dist: distance to the next checkpoint 7 | # next_checkpoint_angle: angle between your pod orientation and the direction of the next checkpoint 8 | x, y, next_checkpoint_x, next_checkpoint_y, next_checkpoint_dist, next_checkpoint_angle = [int(i) for i in input().split()] 9 | opponent_x, opponent_y = [int(i) for i in input().split()] 10 | if next_checkpoint_angle>90 or next_checkpoint_angle<-90: 11 | trust = 0 12 | else: 13 | trust = 100 14 | 15 | # You have to output the target position 16 | # followed by the power (0 <= thrust <= 100) 17 | # i.e.: "x y thrust" 18 | print(str(next_checkpoint_x) + " " + str(next_checkpoint_y) + " " + str(trust)) -------------------------------------------------------------------------------- /BOT PROGRAMMING/CODERS STRIKE BACK/python3/coders-strike-wood-3.py: -------------------------------------------------------------------------------- 1 | # https://www.codingame.com/ide/puzzle/coders-strike-back 2 | # This code automatically collects game data in an infinite loop. 3 | # It uses the standard input to place data into the game variables such as x and y. 4 | # YOU DO NOT NEED TO MODIFY THE INITIALIZATION OF THE GAME VARIABLES. 5 | # game loop 6 | while True: 7 | # x: x position of your pod 8 | # y: y position of your pod 9 | # next_checkpoint_x: x position of the next check point 10 | # next_checkpoint_y: y position of the next check point 11 | x, y, next_checkpoint_x, next_checkpoint_y = [int(i) for i in input().split()] 12 | # Edit this line to output the target position 13 | # and thrust (0 <= thrust <= 100) 14 | # i.e.: "x y thrust" 15 | print(str(next_checkpoint_x) + " " + str(next_checkpoint_y) + " 50") 16 | -------------------------------------------------------------------------------- /BOT PROGRAMMING/GAME OF DRONES/php/Readme.md: -------------------------------------------------------------------------------- 1 | @copyright https://github.com/niconoe-/ -------------------------------------------------------------------------------- /BOT PROGRAMMING/GAME OF DRONES/python3/game-of-drones-wood-1.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import math 3 | 4 | WIDTH = 4000 5 | HEIGHT = 1800 6 | 7 | 8 | class Act: 9 | zones = [] 10 | 11 | def __init__(self): 12 | # p: number of players in the game (2 to 4 players) 13 | # id: ID of your player (0, 1, 2, or 3) 14 | # d: number of drones in each team (3 to 11) 15 | # z: number of zones on the map (4 to 8) 16 | self.p, self.id, self.d, self.z = [int(i) for i in input().split()] 17 | for i in range(self.z): 18 | x, y = [int(j) for j in input().split()] 19 | self.zones.append({'x': x, 'y': y}) 20 | 21 | def scan(self): 22 | for i in range(self.z): 23 | tid = int( 24 | input()) # ID of the team controlling the zone (0, 1, 2, or 3) or -1 if it is not controlled. The zones are given in the same order as in the initialization. 25 | for i in range(self.p): 26 | for j in range(self.d): 27 | # dx: The first D lines contain the coordinates of drones of a player with the ID 0, the following D lines those of the drones of player 1, and thus it continues until the last player. 28 | dx, dy = [int(k) for k in input().split()] 29 | 30 | def run(self): 31 | for i in range(1, self.d + 1): 32 | zone = self.zones[(i + self.z) % self.z] 33 | # output a destination point to be reached by one of your drones. The first line corresponds to the first of your drones that you were provided as input, the next to the second, etc. 34 | print("{0} {1}".format(zone['x'], zone['y'])) 35 | 36 | 37 | act = Act() 38 | while True: 39 | act.scan() 40 | act.run() 41 | 42 | -------------------------------------------------------------------------------- /BOT PROGRAMMING/GAME OF DRONES/python3/game-of-drones-wood-2.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import math 3 | 4 | WIDTH = 4000 5 | HEIGHT = 1800 6 | 7 | 8 | class Act: 9 | zones = [] 10 | 11 | def __init__(self): 12 | # p: number of players in the game (2 to 4 players) 13 | # id: ID of your player (0, 1, 2, or 3) 14 | # d: number of drones in each team (3 to 11) 15 | # z: number of zones on the map (4 to 8) 16 | self.p, self.id, self.d, self.z = [int(i) for i in input().split()] 17 | for i in range(self.z): 18 | x, y = [int(j) for j in input().split()] 19 | self.zones.append({'x': x, 'y': y}) 20 | 21 | def scan(self): 22 | for i in range(self.z): 23 | tid = int( 24 | input()) # ID of the team controlling the zone (0, 1, 2, or 3) or -1 if it is not controlled. The zones are given in the same order as in the initialization. 25 | for i in range(self.p): 26 | for j in range(self.d): 27 | # dx: The first D lines contain the coordinates of drones of a player with the ID 0, the following D lines those of the drones of player 1, and thus it continues until the last player. 28 | dx, dy = [int(k) for k in input().split()] 29 | 30 | def run(self): 31 | for i in range(1, self.d + 1): 32 | zone = self.zones[(i + self.z) % self.z] 33 | # output a destination point to be reached by one of your drones. The first line corresponds to the first of your drones that you were provided as input, the next to the second, etc. 34 | print("{0} {1}".format(zone['x'], zone['y'])) 35 | 36 | 37 | act = Act() 38 | while True: 39 | act.scan() 40 | act.run() 41 | 42 | -------------------------------------------------------------------------------- /BOT PROGRAMMING/GREATE ESCAPE/python3/great-escape-wood2.py: -------------------------------------------------------------------------------- 1 | # https://www.codingame.com/ide/puzzle/great-escape 2 | import sys 3 | import math 4 | 5 | # Auto-generated code below aims at helping you parse 6 | # the standard input according to the problem statement. 7 | 8 | # w: width of the board 9 | # h: height of the board 10 | # player_count: number of players (2 or 3) 11 | # my_id: id of my player (0 = 1st player, 1 = 2nd player, ...) 12 | w, h, player_count, my_id = [int(i) for i in input().split()] 13 | 14 | # game loop 15 | while True: 16 | for i in range(player_count): 17 | # x: x-coordinate of the player 18 | # y: y-coordinate of the player 19 | # walls_left: number of walls available for the player 20 | x, y, walls_left = [int(j) for j in input().split()] 21 | wall_count = int(input()) # number of walls on the board 22 | for i in range(wall_count): 23 | # wall_x: x-coordinate of the wall 24 | # wall_y: y-coordinate of the wall 25 | # wall_orientation: wall orientation ('H' or 'V') 26 | wall_x, wall_y, wall_orientation = input().split() 27 | wall_x = int(wall_x) 28 | wall_y = int(wall_y) 29 | 30 | # Write an action using print 31 | # To debug: print("Debug messages...", file=sys.stderr) 32 | 33 | 34 | # action: LEFT, RIGHT, UP, DOWN or "putX putY putOrientation" to place a wall 35 | print("RIGHT") -------------------------------------------------------------------------------- /BOT PROGRAMMING/LEGENDS OF CODE & MAGIC/python3/legends-of-code-magic-wood-3.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import math 3 | import random 4 | 5 | 6 | # Auto-generated code below aims at helping you parse 7 | # the standard input according to the problem statement. 8 | class Cart: 9 | def __init__(self, card_number, instance_id, location, card_type, cost, attack, defense, abilities, 10 | my_health_change, opponent_health_change, card_draw): 11 | self.card_number = int(card_number) 12 | self.instance_id = int(instance_id) 13 | self.location = int(location) 14 | self.card_type = int(card_type) 15 | self.cost = int(cost) 16 | self.attack = int(attack) 17 | self.defense = int(defense) 18 | self.my_health_change = int(my_health_change) 19 | self.opponent_health_change = int(opponent_health_change) 20 | self.card_draw = int(card_draw) 21 | 22 | def __str__(self): 23 | return '{}'.format(self.card_number) 24 | 25 | 26 | class Game: 27 | def __init__(self): 28 | self.turn = 0 29 | self.phase = 'DRAFT' 30 | self.my_carts = [] 31 | 32 | def run(self): 33 | while True: 34 | self.upd_data() 35 | print(self.phase, file=sys.stderr) 36 | if (self.phase == 'DRAFT'): 37 | self.draft() 38 | else: 39 | self.battle() 40 | 41 | def upd_data(self): 42 | self.turn += 1 43 | for i in range(2): 44 | player_health, player_mana, player_deck, player_rune, player_draw = [int(j) for j in input().split()] 45 | 46 | opponent_hand, opponent_actions = [int(i) for i in input().split()] 47 | for i in range(opponent_actions): 48 | card_number_and_action = input() 49 | 50 | def draft(self): 51 | card_count, carts = int(input()), [] 52 | for i in range(card_count): 53 | data = input().split() 54 | carts.append(Cart(*data)) 55 | 56 | print(carts, file=sys.stderr) 57 | # Write an action using print 58 | # To debug: print("Debug messages...", file=sys.stderr) 59 | 60 | print('PICK {}'.format(random.randint(0, 2))) 61 | self.my_carts.append(carts[0]) 62 | if (len(self.my_carts) >= 30): 63 | self.phase = 'BATTLE' 64 | 65 | def battle(self): 66 | card_count, carts = int(input()), [] 67 | for i in range(card_count): 68 | data = input().split() 69 | carts.append(Cart(*data)) 70 | 71 | print('PASS') 72 | 73 | 74 | game = Game() 75 | game.run() 76 | 77 | -------------------------------------------------------------------------------- /BOT PROGRAMMING/MEAN MAX/java/Readme.md: -------------------------------------------------------------------------------- 1 | @copyright https://github.com/nmahoude -------------------------------------------------------------------------------- /BOT PROGRAMMING/MEAN MAX/python3/Readme.md: -------------------------------------------------------------------------------- 1 | @copyright mean-max-wood-1 https://github.com/dghy/ -------------------------------------------------------------------------------- /BOT PROGRAMMING/MEAN MAX/python3/mean-max-bronze.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/BOT PROGRAMMING/MEAN MAX/python3/mean-max-bronze.py -------------------------------------------------------------------------------- /BOT PROGRAMMING/MEAN MAX/python3/mean-max-wood-2.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import math 3 | 4 | 5 | # Auto-generated code below aims at helping you parse 6 | # the standard input according to the problem statement. 7 | # Distance function 8 | def distance(xi, xii, yi, yii): 9 | sq1 = (xi - xii) * (xi - xii) 10 | sq2 = (yi - yii) * (yi - yii) 11 | return math.sqrt(sq1 + sq2) 12 | 13 | 14 | chosed_x, chosed_y, throttle = 0, 0, 300 15 | # game loop 16 | while True: 17 | my_score = int(input()) 18 | enemy_score_1 = int(input()) 19 | enemy_score_2 = int(input()) 20 | my_rage = int(input()) 21 | enemy_rage_1 = int(input()) 22 | enemy_rage_2 = int(input()) 23 | unit_count = int(input()) 24 | for i in range(unit_count): 25 | unit_id, unit_type, player, mass, radius, x, y, vx, vy, extra, extra_2 = input().split() 26 | unit_id = int(unit_id) 27 | unit_type = int(unit_type) 28 | player = int(player) 29 | mass = float(mass) 30 | radius = int(radius) 31 | x = int(x) 32 | y = int(y) 33 | vx = int(vx) 34 | vy = int(vy) 35 | extra = int(extra) 36 | extra_2 = int(extra_2) 37 | if ((chosed_x, chosed_y) != (x, y)): 38 | throttle = 300 39 | elif (throttle > 10): 40 | throttle -= 100 41 | else: 42 | throttle -= 10 43 | print("{0} {1} {2}".format(x, y, throttle)) 44 | print("{0} {1} {2}".format(x, y, 300)) 45 | print("WAIT") 46 | # Write an action using print 47 | # To debug: print("Debug messages...", file=sys.stderr) 48 | 49 | 50 | -------------------------------------------------------------------------------- /BOT PROGRAMMING/MEAN MAX/python3/mean-max-wood-3.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import math 3 | 4 | 5 | # Auto-generated code below aims at helping you parse 6 | # the standard input according to the problem statement. 7 | # Distance function 8 | def distance(xi, xii, yi, yii): 9 | sq1 = (xi - xii) * (xi - xii) 10 | sq2 = (yi - yii) * (yi - yii) 11 | return math.sqrt(sq1 + sq2) 12 | 13 | 14 | chosed_x, chosed_y, throttle = 0, 0, 300 15 | # game loop 16 | while True: 17 | my_score = int(input()) 18 | enemy_score_1 = int(input()) 19 | enemy_score_2 = int(input()) 20 | my_rage = int(input()) 21 | enemy_rage_1 = int(input()) 22 | enemy_rage_2 = int(input()) 23 | unit_count = int(input()) 24 | for i in range(unit_count): 25 | unit_id, unit_type, player, mass, radius, x, y, vx, vy, extra, extra_2 = input().split() 26 | unit_id = int(unit_id) 27 | unit_type = int(unit_type) 28 | player = int(player) 29 | mass = float(mass) 30 | radius = int(radius) 31 | x = int(x) 32 | y = int(y) 33 | vx = int(vx) 34 | vy = int(vy) 35 | extra = int(extra) 36 | extra_2 = int(extra_2) 37 | if ((chosed_x, chosed_y) != (x, y)): 38 | throttle = 300 39 | elif (throttle > 0): 40 | throttle -= 30 41 | print("{0} {1} {2}".format(x, y, throttle)) 42 | print("WAIT") 43 | print("WAIT") 44 | # Write an action using print 45 | # To debug: print("Debug messages...", file=sys.stderr) 46 | 47 | 48 | -------------------------------------------------------------------------------- /BOT PROGRAMMING/PLATINUM RIFT - EPISODE 1/с++/platinum-rift-episode-1.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/BOT PROGRAMMING/PLATINUM RIFT - EPISODE 1/с++/platinum-rift-episode-1.cpp -------------------------------------------------------------------------------- /BOT PROGRAMMING/TRON BATTLE/python3/tron-battle.py: -------------------------------------------------------------------------------- 1 | def move_to_dir(old, new): 2 | if old[0] < new[0]: 3 | return "RIGHT" 4 | if old[1] < new[1]: 5 | return "DOWN" 6 | if old[0] > new[0]: 7 | return "LEFT" 8 | return "UP" 9 | 10 | 11 | def get_score(starts): 12 | graphs = {i: {} for i in range(n_players)} 13 | graphset = set(x for x in occupied) 14 | order = list(range(my_id, n_players)) + list(range(0, my_id)) 15 | it = 1 16 | while True: 17 | full = True 18 | moves = {} 19 | for o in order: 20 | for x in starts[o]: 21 | for n in NEIGHBOURS[x]: 22 | if n not in graphset or (n in moves and it == 1): 23 | full = False 24 | graphset.add(n) 25 | moves[n] = o 26 | for k, v in moves.items(): 27 | graphs[v][k] = it 28 | if full: 29 | break 30 | starts = [[k for k, v in moves.items() if v == i] for i in range(n_players)] 31 | it += 1 32 | num_my_tiles = len(graphs[my_id]) 33 | num_enemy_tiles = sum([len(graphs[i]) for i in range(n_players) if i != my_id]) 34 | enemies_dist = sum([sum(graphs[i].values()) for i in range(n_players) if i != my_id]) 35 | return sum([num_my_tiles * 10000000, num_enemy_tiles * -100000, enemies_dist]) 36 | 37 | NEIGHBOURS = {} 38 | for i in range(30): 39 | for j in range(20): 40 | neighbours = [] 41 | if i < 29: 42 | neighbours.append((i + 1, j)) 43 | if i > 0: 44 | neighbours.append((i - 1, j)) 45 | if j < 19: 46 | neighbours.append((i, j + 1)) 47 | if j > 0: 48 | neighbours.append((i, j - 1)) 49 | NEIGHBOURS[(i, j)] = neighbours 50 | 51 | occupied = {} 52 | while True: 53 | n_players, my_id = [int(i) for i in input().split()] 54 | curr_moves = [] 55 | for i in range(n_players): 56 | x0, y0, x1, y1 = [int(j) for j in input().split()] 57 | occupied[(x0, y0)] = i 58 | occupied[(x1, y1)] = i 59 | curr_moves.append((x1, y1)) 60 | for i, cm in enumerate(curr_moves): 61 | if cm == (-1, -1): 62 | occupied = {k: v for k, v in occupied.items() if v != i} 63 | for p in range(n_players): 64 | x1, y1 = curr_moves[p] 65 | if p == my_id: 66 | me = (x1, y1) 67 | scores = [] 68 | for neighbour in NEIGHBOURS[me]: 69 | if neighbour not in occupied: 70 | player_starts = [[x] for x in curr_moves.copy()] 71 | player_starts[my_id] = [neighbour] 72 | for i, cm in enumerate(curr_moves): 73 | if cm == (-1, -1): 74 | player_starts[i] = [] 75 | score = get_score(player_starts) 76 | scores.append((score, neighbour)) 77 | best_score_move = sorted(scores, key=lambda x: x[0], reverse=True)[0] 78 | print(move_to_dir(me, best_score_move[-1])) -------------------------------------------------------------------------------- /BOT PROGRAMMING/WONDEV WOMAN/python3/wondev-woman-wood-3.py: -------------------------------------------------------------------------------- 1 | # https://www.codingame.com/ide/puzzle/wondev-woman 2 | REVERSE = { 3 | 'N': 'S', 4 | 'S': 'N', 5 | 'E': 'W', 6 | 'W': 'E', 7 | 'NE': 'SW', 8 | 'NW': 'SE', 9 | 'SE': 'NW', 10 | 'SW': 'NE' 11 | } 12 | 13 | def get_back_action(atype, index, dir_1, dir_2): 14 | return "{0} {1} {2} {3}".format(atype, index, REVERSE[dir_1], REVERSE[dir_2]) 15 | 16 | first_action = second_action = None 17 | k = 2 18 | size = int(input()) 19 | units_per_player = int(input()) 20 | # game loop 21 | while True: 22 | map = [] 23 | for i in range(size): 24 | row = input() 25 | map.append(row) 26 | for i in range(units_per_player): 27 | unit_x, unit_y = [int(j) for j in input().split()] 28 | for i in range(units_per_player): 29 | other_x, other_y = [int(j) for j in input().split()] 30 | legal_actions = int(input()) 31 | for i in range(legal_actions): 32 | atype, index, dir_1, dir_2 = input().split() 33 | if (first_action is None): 34 | first_action = "{0} {1} {2} {3}".format(atype, index, dir_1, REVERSE[dir_1]) 35 | second_action = get_back_action(atype, index, REVERSE[REVERSE[dir_1]], REVERSE[dir_1]) 36 | index = int(index) 37 | 38 | if k % 2 == 0: 39 | print(first_action) 40 | else: 41 | print(second_action) 42 | k = k + 1 43 | 44 | -------------------------------------------------------------------------------- /CLASHOFCODE/functions/debug.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/CLASHOFCODE/functions/debug.py -------------------------------------------------------------------------------- /CLASHOFCODE/functions/only-some-charasters.py: -------------------------------------------------------------------------------- 1 | numbers = sum(c.isdigit() for c in s) 2 | words = sum(c.isalpha() for c in s) 3 | spaces = sum(c.isspace() for c in s) 4 | 5 | s=''.join(i for i in s if i.isdigit()) 6 | 7 | sum([int(c.islower()) for c in s]) #lower 8 | 9 | #odd 10 | odd = s[0::2] 11 | #even 12 | odd = s[1::2] -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/fastest/01/Readme.md: -------------------------------------------------------------------------------- 1 | The program: 2 | Your program must display the missing digit for each line. 3 | 4 | INPUT: 5 | Line 1 : An integer N, the number of lines to read. 6 | N next lines : A string line of 9 digits without spaces. 7 | 8 | OUTPUT: 9 | Line 1 : The missing digit. 10 | 11 | CONSTRAINTS: 12 | 0 < N < 1000 13 | 14 | EXAMPLE: 15 | Input 16 | 1 17 | 123456789 18 | Output 19 | 0 20 | -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/fastest/01/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/CLASHOFCODE/solutions/fastest/01/__init__.py -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/fastest/01/solution.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import math 3 | 4 | # Auto-generated code below aims at helping you parse 5 | # the standard input according to the problem statement. 6 | 7 | n = int(input()) 8 | for i in range(n): 9 | line = input() 10 | for j in range(10): 11 | if str(j) not in line: 12 | print(j) -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/fastest/02/Readme.md: -------------------------------------------------------------------------------- 1 | 2 | A contribution by CyberLemonade 3 | Approved by Stilgart , dwarfie and nicola 4 | Goal 5 | String Transformation: 6 | 7 | Transform a string according to the following criteria: 8 | 1. The final string has the same length as the original string 9 | 2. The character at index i of the encoded string is the character at index j of the original string, such that j is at a distance n from i, where n is the ith term of the series 1,3,6,10,15,21... 10 | 11 | --------------------------------------------------- xxx --------------------------------------------------- 12 | 13 | Explanation: 14 | 15 | Let L be the length of the string. 16 | Let i be the current index. 17 | Let n be the ith term of the given series 18 | So, index of the character at index i of the final string will be: 19 | index j = (i+n) MOD l 20 | 21 | --------------------------------------------------- xxx --------------------------------------------------- 22 | 23 | Example: 24 | 25 | consider the string FINE 26 | 27 | It has characters at index: 28 | 0 = F 29 | 1 = I 30 | 2 = N 31 | 3 = E 32 | 33 | In the final String: 34 | character at index 0 is at distance 1 from F = I (j = 1 MOD 4 = 1) 35 | character at index 1 is at distance 3 from I = F (j = 4 MOD 4 = 0) 36 | character at index 2 is at distance 6 from N = F (j = 8 MOD 4 = 0) 37 | character at index 3 is at distance 10 from E = I (j = 13 MOD 4 = 1) 38 | So the final string is IFFI 39 | 40 | --------------------------------------------------- xxx --------------------------------------------------- 41 | Input 42 | Line 1: A String STRING 43 | Output 44 | Line 1: The final String FINAL 45 | Constraints 46 | No constraints 47 | Example 48 | Input 49 | 50 | FINE 51 | 52 | Output 53 | 54 | IFFI 55 | 56 | -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/fastest/02/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/CLASHOFCODE/solutions/fastest/02/__init__.py -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/fastest/02/solution.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import math 3 | 4 | # Auto-generated code below aims at helping you parse 5 | # the standard input according to the problem statement. 6 | 7 | string = input() 8 | stri = "" 9 | # Write an action using print 10 | # To debug: print("Debug messages...", file=sys.stderr) 11 | t = len(string) 12 | s = 1 13 | for i in range(len(string)): 14 | stri += (string[(i + s) % t]) 15 | s += i + 2 16 | 17 | print(stri) -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/fastest/03/Readme.md: -------------------------------------------------------------------------------- 1 | 2 | Clash of Code - Fastest mode 3 | 14MN 47SC 4 | A contribution by Willian 5 | Approved by MadKnight , aCat and JBM 6 | Goal 7 | You have input string. You must divide the count of letters by the count of digits. Round the resulting number. 8 | Input 9 | 2<=Len(input)<=256 10 | Output 11 | Rounded Output 12 | Example 13 | Input 14 | 15 | He110 W0r1d! 16 | 17 | Output 18 | 19 | 1 20 | 21 | -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/fastest/03/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/CLASHOFCODE/solutions/fastest/03/__init__.py -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/fastest/03/solution.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import math 3 | 4 | # Auto-generated code below aims at helping you parse 5 | # the standard input according to the problem statement. 6 | 7 | s = input() 8 | 9 | numbers = sum(c.isdigit() for c in s) 10 | words = sum(c.isalpha() for c in s) 11 | spaces = sum(c.isspace() for c in s) 12 | print(int(round(words/numbers, 0))) -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/fastest/04/Readme.md: -------------------------------------------------------------------------------- 1 | 2 | A contribution by BlaiseEbuth 3 | Approved by codingWhale , MasakiKyosuke and Lanken 4 | Goal 5 | You have a list of speeds and distances as input and you must find the shortest travel time. 6 | Input 7 | Line 1: The number N of speed/distance pairs. 8 | Next N lines: A pair speed (in km/h) S/distance (in km) D. 9 | Output 10 | Line 1: The rounded shortest travel time in minutes. 11 | Constraints 12 | S>0 13 | D>0 14 | Example 15 | Input 16 | 17 | 2 18 | 103 26 19 | 162 54 20 | 21 | Output 22 | 23 | 15 24 | 25 | -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/fastest/04/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/CLASHOFCODE/solutions/fastest/04/__init__.py -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/fastest/04/solution.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import math 3 | 4 | # Auto-generated code below aims at helping you parse 5 | # the standard input according to the problem statement. 6 | 7 | n = int(input()) 8 | e=[] 9 | for i in range(n): 10 | s, d = [int(j) for j in input().split()] 11 | e.append(round(d/(s/60))) 12 | 13 | # Write an action using print 14 | # To debug: print("Debug messages...", file=sys.stderr) 15 | 16 | print(min(e)) -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/fastest/05/Readme.md: -------------------------------------------------------------------------------- 1 | The program: 2 | You must output for each participant in a race the traveled distance (in meters) at a given speed S (centimeters/second) in given amount of time T (minutes). 3 | 4 | INPUT: 5 | Line 1: An integer N for the number of participants. 6 | Next N lines: Two space separated integers S and T representing respectively the speed S and the time T. 7 | 8 | OUTPUT: 9 | N Lines: An Integer representing the distance traveled. 10 | 11 | CONSTRAINTS: 12 | 0 ≤ S ≤ 150 13 | 0 ≤ T ≤ 100000 14 | 15 | EXAMPLE: 16 | Input 17 | 1 18 | 20 10 19 | Output 20 | 120 21 | 22 | -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/fastest/05/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/CLASHOFCODE/solutions/fastest/05/__init__.py -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/fastest/05/solution.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import math 3 | n = int(input()) 4 | s = input() 5 | r = 0 6 | for i in s: 7 | t = int(i) 8 | if t==0: 9 | r=0 10 | else: 11 | r+=t 12 | print(r) -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/fastest/06/Readme.md: -------------------------------------------------------------------------------- 1 | The program: 2 | Your program must print the sum of the square of the numbers given as input. 3 | 4 | INPUT: 5 | Line 1: An integer N for the amount of numbers to use. 6 | Line 2: A line containing N space-separated integers Xi. 7 | 8 | OUTPUT: 9 | The sum of the squares of the Xi numbers. 10 | 11 | CONSTRAINTS: 12 | 0 < N < 100 13 | -1000 < Xi < 1000 14 | 15 | EXAMPLE: 16 | Input 17 | 3 18 | 1 2 3 19 | Output 20 | 14 21 | 22 | -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/fastest/06/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/CLASHOFCODE/solutions/fastest/06/__init__.py -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/fastest/06/solution.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import math 3 | 4 | # Auto-generated code below aims at helping you parse 5 | # the standard input according to the problem statement. 6 | 7 | n = int(input()) 8 | s = 0 9 | for i in input().split(): 10 | s+= int(i)**2 11 | 12 | # Write an action using print 13 | # To debug: print("Debug messages...", file=sys.stderr) 14 | 15 | print(s) -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/reverse/01/Readme.md: -------------------------------------------------------------------------------- 1 | 2 | The game mode is REVERSE: You do not have access to the statement. You have to guess what to do by observing the following set of tests: 3 | 01 4 | Test 1 5 | 6 | 4 7 | 0 8 | 1 9 | 2 10 | 3 11 | 12 | true 13 | false 14 | true 15 | false 16 | 17 | 02 18 | Test 2 19 | 20 | 1 21 | 44 22 | 23 | true 24 | 25 | 03 26 | Test 3 27 | 28 | 1 29 | 179 30 | 31 | false 32 | 33 | 04 34 | Test 4 35 | 36 | 3 37 | 3254 38 | 24 39 | 654 40 | 41 | true 42 | true 43 | true 44 | 45 | 05 46 | Test 5 47 | 48 | 3 49 | 0 50 | 9001 51 | 42 52 | 53 | true 54 | false 55 | true 56 | 57 | 06 58 | Test 6 59 | 60 | 4 61 | 2 62 | 4 63 | 6 64 | 8 65 | 66 | true 67 | true 68 | true 69 | true 70 | 71 | 07 72 | Test 7 73 | 74 | 3 75 | 10 76 | 7 77 | 11 78 | 79 | true 80 | false 81 | false 82 | 83 | 08 84 | Test 8 85 | 86 | 3 87 | 15 88 | 11 89 | 9 90 | 91 | false 92 | false 93 | false 94 | 95 | 09 96 | Test 9 97 | 98 | 3 99 | 22 100 | 11 101 | 212 102 | 103 | true 104 | false 105 | true 106 | 107 | 10 108 | Test 10 109 | 110 | 3 111 | 30 112 | 42 113 | 8 114 | 115 | true 116 | true 117 | true 118 | 119 | -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/reverse/01/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/CLASHOFCODE/solutions/reverse/01/__init__.py -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/reverse/01/solution.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import math 3 | 4 | # Auto-generated code below aims at helping you parse 5 | # the standard input according to the problem statement. 6 | 7 | n = int(input()) 8 | for i in range(n): 9 | print(['true', 'false'][int(input())%2]) -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/reverse/02/Readme.md: -------------------------------------------------------------------------------- 1 | 2 | The game mode is REVERSE: You do not have access to the statement. You have to guess what to do by observing the following set of tests: 3 | 01 4 | Test 1 5 | 6 | 54 7 | 8 | 63 9 | 10 | 02 11 | Test 2 12 | 13 | 65 14 | 15 | 76 16 | 17 | 03 18 | Test 3 19 | 20 | 2 21 | 22 | 4 23 | 24 | 04 25 | Test 4 26 | 27 | 17 28 | 29 | 25 30 | 31 | 05 32 | Test 5 33 | 34 | 75 35 | 36 | 87 37 | 38 | 06 39 | Test 6 40 | 41 | 134 42 | 43 | 142 44 | 45 | 07 46 | Test 7 47 | 48 | 1024 49 | 50 | 1031 51 | 52 | 08 53 | Test 8 54 | 55 | 2048 56 | 57 | 2062 58 | 59 | -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/reverse/02/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/CLASHOFCODE/solutions/reverse/02/__init__.py -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/reverse/02/solution.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import math 3 | 4 | def quer(i): 5 | sum=0 6 | for c in str(i): 7 | sum+=int(c) 8 | return sum 9 | 10 | n = int(input()) 11 | 12 | print(n+quer(n)) -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/reverse/03/Readme.md: -------------------------------------------------------------------------------- 1 | 2 | The game mode is REVERSE: You do not have access to the statement. You have to guess what to do by observing the following set of tests: 3 | 01 4 | Test 1 5 | 6 | DAMN IT'S hard 7 | 8 | 4 9 | 10 | 02 11 | Test 2 12 | 13 | Well ... I Think It's EZ to Solve 14 | 15 | 15 16 | 17 | 03 18 | Test 3 19 | 20 | HI! 21 | 22 | 0 23 | 24 | 04 25 | Test 4 26 | 27 | Have a nice day 28 | 29 | 11 30 | 31 | -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/reverse/03/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/CLASHOFCODE/solutions/reverse/03/__init__.py -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/reverse/03/solution.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import math 3 | 4 | # Auto-generated code below aims at helping you parse 5 | # the standard input according to the problem statement. 6 | 7 | s = input() 8 | 9 | # Write an action using print 10 | # To debug: print("Debug messages...", file=sys.stderr) 11 | 12 | print(sum([int(c.islower()) for c in s])) -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/reverse/04/Readme.md: -------------------------------------------------------------------------------- 1 | 2 | The game mode is REVERSE: You do not have access to the statement. You have to guess what to do by observing the following set of tests: 3 | 01 4 | Test 1 5 | 6 | H!e ldllor oW 7 | 8 | Hello World ! 9 | 10 | 02 11 | Test 2 12 | 13 | Huiob 14 | 15 | Hibou 16 | 17 | 03 18 | Test 3 19 | 20 | Pnioge 21 | 22 | Pigeon 23 | 24 | 04 25 | Test 4 26 | 27 | CeomdaiGn 28 | 29 | CodinGame 30 | 31 | 05 32 | Test 5 33 | 34 | Stuebciaglepn dloe vt uarvbriad iosd nearurqainlta vmeull etaucr briedpimse sa drieupm esnetton adtipsatre nbtaa iproarpr imguittcuirv stuebciaglepn dsoi igrryascsiAl iruempq usei iirny ssspAa triuat iaguitr rpoopr rtiugai tsuirl lcioulqonraartti sa vsrtai vmaamv idtiss tseenttnae gv eali tgarpasc ielniiusm qsueen mcoa mmeultocriuvm eprearl osminlelsi upqenra rt 35 | 36 | Subigendo turbidis errant vel turbidis adiumento distenta porrigitur subigendo graciliumque in spatia aut porrigitur coloratis stivam distenta vel graciliumque camelorum per omnes per tranquillis lare victum omnes sine spatia gentes stivam arva tranquillis aut porrigitur Assyriis per Assyriis placet victum pari ab raptantes per semper caelum aliquando arva vel placet 37 | 38 | 06 39 | Test 6 40 | 41 | 42 42 | 43 | 42 44 | 45 | -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/reverse/04/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/CLASHOFCODE/solutions/reverse/04/__init__.py -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/reverse/04/solution.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import math 3 | 4 | # Auto-generated code below aims at helping you parse 5 | # the standard input according to the problem statement. 6 | 7 | s = input() 8 | a = len(s)%2 9 | print("".join(s[0::2]+s[a*-1-1::-2])) -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/reverse/05/Readme.md: -------------------------------------------------------------------------------- 1 | 2 | The game mode is REVERSE: You do not have access to the statement. You have to guess what to do by observing the following set of tests: 3 | 01 4 | Test 1 5 | 6 | 0 7 | 8 | 0 9 | 10 | 02 11 | Test 2 12 | 13 | 44 14 | 15 | 4 16 | 17 | 03 18 | Test 3 19 | 20 | 179 21 | 22 | 9 23 | 24 | 04 25 | Test 4 26 | 27 | 3254 28 | 29 | 4 30 | 31 | 05 32 | Test 5 33 | 34 | 9001 35 | 36 | 1 37 | 38 | 06 39 | Test 6 40 | 41 | 9 42 | 43 | 9 44 | 45 | 07 46 | Test 7 47 | 48 | 10 49 | 50 | 0 51 | 52 | 08 53 | Test 8 54 | 55 | 15 56 | 57 | 5 58 | 59 | 09 60 | Test 9 61 | 62 | 22 63 | 64 | 2 65 | 66 | 10 67 | Test 10 68 | 69 | 30 70 | 71 | 0 72 | 73 | -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/reverse/05/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/CLASHOFCODE/solutions/reverse/05/__init__.py -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/reverse/05/solution.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import math 3 | 4 | # Auto-generated code below aims at helping you parse 5 | # the standard input according to the problem statement. 6 | 7 | n = int(input()) 8 | 9 | # Write an action using print 10 | # To debug: print("Debug messages...", file=sys.stderr) 11 | 12 | print(n%10) -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/shortest/01/readme.md: -------------------------------------------------------------------------------- 1 | The program: 2 | You must find the sum of the mods of a list of numbers. 3 | Modular arithmetic refers to the remainder of the divide function. A mod B = the remainder of A/B. 4 | 5 | For example: 6 | 5 mod 2 = 1 7 | 15 mod 6 = 3 8 | 9 | INPUT: 10 | Line 1: An integer M describing divisor. 11 | Line 2: The number N of values. 12 | Line 3: A list of N numbers E separated by spaces. 13 | 14 | OUTPUT: 15 | A single line: The sum of numbers E mod M in the list 16 | 17 | CONSTRAINTS: 18 | M > 1 19 | 1 ≤ N < 20 20 | 21 | EXAMPLE: 22 | Input 23 | 3 24 | 4 25 | 4 5 8 12 26 | Output 27 | 5 28 | -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/shortest/01/solution.py: -------------------------------------------------------------------------------- 1 | m,n=int(input()),input() 2 | print(sum([int(i)%m for i in input().split()])) -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/shortest/01/solution2.py: -------------------------------------------------------------------------------- 1 | O,I=int,input 2 | n,m=O(I()),I() 3 | print(sum([O(i)%n for i in I().split()])) -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/shortest/02/readme.md: -------------------------------------------------------------------------------- 1 | A contribution by Suitangi 2 | Goal 3 | In chemistry, simple alkanes are made of carbon and hydrogen atoms. According to the IUPAC nomenclature system, they are named by the number of carbons they contain (here are the first 5 alkanes): 4 | 5 | - methane CH4 (1 Carbon atom, 4 Hydrogen atoms) 6 | - ethane C2H6 (2 Carbon atoms , 6 Hydrogen atoms) 7 | - propane C3H8 (3 Carbon atoms, 8 Hydrogen atoms) 8 | - butane C4H10 (4 Carbon atoms, 10 Hydrogen atoms) 9 | - pentane C5H12 (5 Carbon atoms, 12 Hydrogen atoms) 10 | 11 | Given a diagram of a molecule find its nomenclature (its IUPAC name). 12 | Input 13 | Line 1: An integer N for the number of lines used to draw the diagram of a molecule. 14 | Next N lines: A diagram of a molecule consisting of characters H and C for the element hydrogen and carbon respectively; - and | to represent the bonds. 15 | Output 16 | A single line containing NONE if the given molecule is not an alkane. Otherwise, output the IUPAC name of the given molecule (methane, ethane, ...). 17 | Constraints 18 | 0 ≤ N ≤ 15 19 | Example 20 | Input 21 | 5 22 | H 23 | | 24 | H-C-H 25 | | 26 | H 27 | Output 28 | methane -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/shortest/02/solution.py: -------------------------------------------------------------------------------- 1 | r=input 2 | n,l,w = int(r()),'',{5:'methane',8:'ethane',11:'propane',14:'butane',17:'pentane'} 3 | for i in range(n):l+=r() 4 | print(w.get(l.count('C')+l.count('H'), 'NONE')) -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/shortest/03/Readme.md: -------------------------------------------------------------------------------- 1 | 2 | A contribution by Marcx 3 | Approved by Unihedron , WimpyKid and JohnnyYuge 4 | Goal 5 | You must output the sum digits of the power between two input number. 6 | 7 | Example: 8 | 9 | 10 | Input: 11 | 2 12 | 7 13 | 14 | Output: 15 | 11 16 | Input 17 | Line 1: An integer X for the base. 18 | Line 2: An integer Y for the exponent. 19 | Output 20 | A single line containing the sum of all digits from the result of X^Y 21 | Constraints 22 | 0 ≤ X ≤ 15 23 | 0 < Y ≤ 11 24 | Example 25 | Input 26 | 27 | 5 28 | 2 29 | 30 | Output 31 | 32 | 7 33 | 34 | -------------------------------------------------------------------------------- /CLASHOFCODE/solutions/shortest/03/solution.py: -------------------------------------------------------------------------------- 1 | i,u=int,input 2 | print(sum([i(x) for x in str(i(u())**i(u()))])) -------------------------------------------------------------------------------- /CODE GOLF/DONT PANIC/python3/don't-panic.py: -------------------------------------------------------------------------------- 1 | e,v,W,B={},[],"WAIT",'BLOCK' 2 | o,l,u,z,s,t,a,r=[int(i) for i in input().split()] 3 | for i in range(r):v.append([int(j) for j in input().split()]);e[v[i][0]]=v[i][1] 4 | while 1: 5 | f,p,d=input().split() 6 | f,p=int(f),int(p) 7 | if f==z or f==-1: 8 | y=(W,B)[(p>s and d[:1]=='R')or(pe[f] and d[:1]=='R')or(p$Y?"N":"")).($N<$X?"E":($N>$X?"W":""))."\n";$M+=($M<$Y)?1:($M>$Y?-1:0);$N+=$N<$X?1:($N>$X?-1:0);} -------------------------------------------------------------------------------- /CODE GOLF/POWER OF THOR/python3/power-of-thor.py: -------------------------------------------------------------------------------- 1 | x,y,z,w=[int(i)for i in input().split()] 2 | while 1:m,w=(((["",w],["N",w-1])[w>y]),["S",w+1])[wx]),[m+"E",z+1])[z0] 3 | for i in a:m=(m,i)[abs(m)>abs(i)or(abs(m)==abs(i)and i>m)] 4 | print(m) 5 | -------------------------------------------------------------------------------- /COMMUNITY PUZZLES/ADVANCED TREE/python3/___advanced-tree.py: -------------------------------------------------------------------------------- 1 | # https://github.com/cpj1352/codingame/blob/master/Community%20game/Advanced%20Tree.py 2 | # https://www.codingame.com/ide/puzzle/advanced-tree 3 | s="." 4 | 5 | text=["./Directory1/File1","./Directory1/File2","./Directory2/File3","./Directory1/File4","./Directory2/Directory3/File5","./File6"] 6 | 7 | 8 | for i in text: 9 | print i.split('/') -------------------------------------------------------------------------------- /COMMUNITY PUZZLES/BUST SPEEDING VEHICLES/python3/bust-speeding-vehicles.py: -------------------------------------------------------------------------------- 1 | # https://www.codingame.com/ide/puzzle/bust-speeding-vehicles 2 | def check_speed(cur_car, car, km, timestamp): 3 | kilometers = km - cur_car['km'] 4 | hours = (timestamp - cur_car['timestamp']) / 3600 5 | speed = kilometers / hours 6 | return speed 7 | L_MAX = 100 8 | L_MIN = 10 9 | N_MAX = 100 10 | C_MAX = 1000 11 | l = int(input()) 12 | n = int(input()) 13 | cars = {} 14 | ok = True 15 | for i in range(n): 16 | car, km, timestamp = input().split() 17 | cur_car = cars.get(car, None) 18 | if cur_car is not None: 19 | speed = check_speed(cur_car, car, int(km), int(timestamp)) 20 | if speed > l: 21 | print("{0} {1}".format(car, km)) 22 | ok = False 23 | cars[car] = {'car': car, 'km': int(km), 'timestamp': int(timestamp)} 24 | if ok: 25 | print("OK") -------------------------------------------------------------------------------- /COMMUNITY PUZZLES/ELEMENTARY-CELLULAR-AUTOMATION/python3/elementary-cellular-automaton.py: -------------------------------------------------------------------------------- 1 | # todo -------------------------------------------------------------------------------- /COMMUNITY PUZZLES/HIGHEST TRUNCADED PYRAMID/python3/highest-truncated-pyramid.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/COMMUNITY PUZZLES/HIGHEST TRUNCADED PYRAMID/python3/highest-truncated-pyramid.py -------------------------------------------------------------------------------- /COMMUNITY PUZZLES/PAPER-FOLDING CURVE/python3/paper-folding-curve.py: -------------------------------------------------------------------------------- 1 | # https://www.codingame.com/ide/puzzle/paper-folding-curve 2 | # from https://github.com/frostming/Codingame/blob/master/Puzzle-of-the-Week/paper_folding_curve.py 3 | import sys 4 | import math 5 | 6 | # Auto-generated code below aims at helping you parse 7 | # the standard input according to the problem statement. 8 | 9 | order = int(input()) 10 | s, e = [int(i) for i in input().split()] 11 | print(s, e, file=sys.stderr) 12 | # Write an action using print 13 | # To debug: print("Debug messages...", file=sys.stderr) 14 | 15 | original = '01101100' 16 | 17 | 18 | def get_bit(n): 19 | if not n & (n - 1): 20 | return '1' 21 | while n & 1 == 0: 22 | n >>= 1 23 | if n & 3 == 3: 24 | return '0' 25 | else: 26 | return '1' 27 | 28 | 29 | answer = ''.join(get_bit(i) for i in range(s + 1, e + 2)) 30 | print(answer) -------------------------------------------------------------------------------- /COMMUNITY PUZZLES/SPREADSHEET LABELS/python3/spreadsheet-labels.py: -------------------------------------------------------------------------------- 1 | # https://www.codingame.com/ide/8438790605ac521c07945072a3e554118f14408 2 | 3 | -------------------------------------------------------------------------------- /COMMUNITY PUZZLES/THE FASTEST/python3/the-fastest.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import math 3 | 4 | # Auto-generated code below aims at helping you parse 5 | # the standard input according to the problem statement. 6 | timew = '23:59:59' 7 | minimum = 23*60*60 + 59*60 + 59 8 | n = int(input()) 9 | for i in range(n): 10 | t = input() 11 | print(t, file=sys.stderr) 12 | temp = t.split(':') 13 | time = int(temp[0])*60*60 + int(temp[1])*60 + int(temp[2]) 14 | if time0: 22 | omessage.append(form_words(last_num, strike)) 23 | strike = 0 24 | last_num = nums[i] 25 | strike = strike + 1 26 | if strike>0: 27 | omessage.append(form_words(last_num, strike)) 28 | print("{0}".format(" ".join(omessage))) 29 | -------------------------------------------------------------------------------- /EASY/CHACK NORIS/pyton/chuck-norris.py: -------------------------------------------------------------------------------- 1 | # https://www.codingame.com/ide/puzzle/chuck-norris 2 | def string2bits(st=''): 3 | return ' '.join(format(ord(x), 'b') for x in st) 4 | def form_words(letter, strike): 5 | if letter == "1": 6 | result = "0 " 7 | else: 8 | result = "00 " 9 | return result + ("0" * strike) 10 | 11 | omessage = [] 12 | message = raw_input() 13 | last_num = "" 14 | strike = 0 15 | for letter in message: 16 | nums = str(string2bits(letter)) 17 | nums = ("0" * (7 - len(nums))) + nums 18 | for i in range(0, len(nums)): 19 | if last_num != nums[i]: 20 | if strike > 0: 21 | omessage.append(form_words(last_num, strike)) 22 | strike = 0 23 | last_num = nums[i] 24 | strike = strike + 1 25 | if strike > 0: 26 | omessage.append(form_words(last_num, strike)) 27 | print("{0}".format(" ".join(omessage))) 28 | -------------------------------------------------------------------------------- /EASY/DEFIBRILLATORS/Readme.md: -------------------------------------------------------------------------------- 1 | # Defibrillator 2 | 3 | The city of Montpellier has equipped its streets with defibrillators to help save victims of cardiac arrests. The data corresponding to the position of all defibrillators is available online. 4 | 5 | Based on the data, you decide to write a program that will allow users to find the defibrillator nearest to their location using their mobile phone. 6 | 7 | ![heartbeat](img/heart.gif 'heartbeat') 8 | 9 | The input data you require for your program is provided in _ASCII_ format. 10 | This data is comprised of lines, each of which represents a defibrillator. Each defibrillator is represented by the following fields: 11 | 12 | * A number identifying the defibrillator 13 | * Name 14 | * Adress 15 | * Contact Phone number 16 | * Longitude (degrees) 17 | * Latitude (degrees) 18 | * These fields are separated by a semicolon `;` 19 | 20 | ## Distance 21 | 22 | The distance ``d`` between two points ``A`` and ``B`` will be calculated using the following formula: 23 | 24 | x = (longitudeB - longitudeA) x cos( ( latitudeA + latitudeB ) / 2) 25 | 26 | y = latitudeB - latitudeA 27 | 28 | d = sqrt(pow(x) + pow(y)) x 6371 29 | ​ 30 | _Note: In this formula, the latitudes and longitudes are expressed in **radians**. 6371 corresponds to the radius of the earth in **km**._ 31 | 32 | The program will display the name of the defibrillator located the closest to the user’s position. This position is given as input to the program. 33 | 34 | ## Input 35 | 36 | * **Line 1**: User's longitude (in degrees) 37 | * **Line 2**: User's latitude (in degrees) 38 | * **Line 3**: The number _N_ of defibrillators located in the streets of Montpellier 39 | * **N lignes suivantes**: _N_ lines describing each defibrilator 40 | 41 | ## Output 42 | 43 | The name of the defibrillator located the closest to the user’s position. 44 | 45 | ## Constraints 46 | 47 | * 0 < N < 10000 48 | 49 | ## Example 50 | 51 | Input 52 | 53 | 3,879483 54 | 43,608177 55 | 3 56 | 1;Maison de la Prevention Sante;6 rue Maguelone 340000 Montpellier;;3,87952263361082;43,6071285339217 57 | 2;Hotel de Ville;1 place Georges Freche 34267 Montpellier;;3,89652239197876;43,5987299452849 58 | 3;Zoo de Lunaret;50 avenue Agropolis 34090 Mtp;;3,87388031141133;43,6395872778854 59 | 60 | Output 61 | 62 | Maison de la Prevention Sante 63 | 64 | ## Conditions 65 | 66 | * Available RAM: 512MB 67 | * Timeout: 1 seconds 68 | * The program has to read inputs from standard input 69 | * The program has to write the solution to standard output 70 | * The program must run in the test environment -------------------------------------------------------------------------------- /EASY/DEFIBRILLATORS/img/heart.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/EASY/DEFIBRILLATORS/img/heart.gif -------------------------------------------------------------------------------- /EASY/DEFIBRILLATORS/php/defibrillators.php: -------------------------------------------------------------------------------- 1 | $DEFIB_TEMP[0], 28 | 'name'=>$DEFIB_TEMP[1], 29 | 'address'=>$DEFIB_TEMP[2], 30 | 'phone'=>$DEFIB_TEMP[3], 31 | 'long'=>$DEFIB_TEMP[4], 32 | 'lat'=>$DEFIB_TEMP[5], 33 | ]; 34 | $distance = get_distance(floatval(str_replace(',', '.', $lat)), floatval(str_replace(',', '.', $defib['lat'])), floatval(str_replace(',', '.', $lon)), floatval(str_replace(',', '.', $defib['long']))); 35 | if($distance<$closest){ 36 | $current = $defib; 37 | $closest = $distance; 38 | } 39 | } 40 | 41 | // Write an action using echo(). DON'T FORGET THE TRAILING \n 42 | // To debug (equivalent to var_dump): error_log(var_export($var, true)); 43 | 44 | echo("{$current['name']}\n"); 45 | ?> -------------------------------------------------------------------------------- /EASY/DEFIBRILLATORS/python/defibrillators.py: -------------------------------------------------------------------------------- 1 | # https://www.codingame.com/ide/puzzle/defibrillators 2 | import sys 3 | import math 4 | def get_distance(lat_a, lat_b, long_a, long_b): 5 | x = (long_b - long_a) * math.cos((lat_b + lat_a) / 2) 6 | y = lat_b - lat_a 7 | return math.sqrt(x * x + y * y) * 6371 8 | 9 | 10 | lon = raw_input() 11 | lat = raw_input() 12 | n = int(raw_input()) 13 | current = {} 14 | closest = 3.402823e+38 15 | for i in range(n): 16 | defib = {} 17 | defib['id'], defib['name'], defib['address'], defib['phone'], defib['long'], defib['lat'] = [j for j in 18 | raw_input().split(';')] 19 | distance = get_distance(float(lat.replace(',', '.')), float(defib['lat'].replace(',', '.')), 20 | float(lon.replace(',', '.')), float(defib['long'].replace(',', '.'))) 21 | if distance < closest: 22 | current = defib 23 | closest = distance 24 | print(current['name']) 25 | -------------------------------------------------------------------------------- /EASY/DEFIBRILLATORS/python3/defibrillators.py: -------------------------------------------------------------------------------- 1 | # https://www.codingame.com/ide/puzzle/defibrillators 2 | import math 3 | def get_distance(lat_a, lat_b, long_a, long_b): 4 | x = (long_b - long_a)*math.cos((lat_b + lat_a)/2) 5 | y = lat_b - lat_a 6 | return math.sqrt(x*x +y*y)*6371 7 | 8 | lon = input() 9 | lat = input() 10 | n = int(input()) 11 | current = {} 12 | closest = 3.402823e+38 13 | for i in range(n): 14 | defib = {} 15 | defib['id'], defib['name'], defib['address'], defib['phone'], defib['long'], defib['lat'] = [j for j in input().split(';')] 16 | distance = get_distance(float(lat.replace(',', '.')), float(defib['lat'].replace(',', '.')), float(lon.replace(',', '.')), float(defib['long'].replace(',', '.'))) 17 | if distancei of each horse. Pi is an integer. 12 | 13 | ## Output 14 | 15 | The difference ``D`` between the two closest strengths. ``D`` is a positive integer. 16 | 17 | ## Constraints 18 | 19 | * 1 < N < 100000 20 | * 0 < Pi ≤ 10000000 21 | 22 | ## Example 23 | 24 | Input 25 | 26 | 3 27 | 5 28 | 8 29 | 9 30 | 31 | Output 32 | 33 | 1 34 | 35 | ## Conditions 36 | 37 | * Available RAM: 512MB 38 | * Timeout: 1 seconds 39 | * The program has to read inputs from standard input 40 | * The program has to write the solution to standard output 41 | * The program must run in the test environment -------------------------------------------------------------------------------- /EASY/HORSE RASING DUALS/bash/horse-racing-duals.bash: -------------------------------------------------------------------------------- 1 | # from here https://github.com/Peekmo/CodinGame-Bash/blob/master/Horses.sh 2 | read n 3 | declare -a horses 4 | declare -a sorted 5 | lower=10000000; last=-1 6 | 7 | for((i=0 ; i$pi[$i+1]-$pi[$i]) $min = $pi[$i+1]-$pi[$i]; 8 | echo($min); 9 | ?> -------------------------------------------------------------------------------- /EASY/HORSE RASING DUALS/python/horse-racing-duals.py: -------------------------------------------------------------------------------- 1 | # https://www.codingame.com/ide/puzzle/horse-racing-duals 2 | pi = [] 3 | n = int(raw_input()) 4 | for i in range(n): 5 | pi.append(int(raw_input())) 6 | pi.sort() 7 | min = 10000000 8 | for i in range(n-1): 9 | if min>abs(pi[i]-pi[i+1]): 10 | min = abs(pi[i]-pi[i+1]) 11 | if min==0: 12 | break 13 | print(min) 14 | -------------------------------------------------------------------------------- /EASY/HORSE RASING DUALS/python3/horse-racing-duals.py: -------------------------------------------------------------------------------- 1 | # https://www.codingame.com/ide/puzzle/horse-racing-duals 2 | pi = [] 3 | n = int(input()) 4 | for i in range(n): 5 | pi.append(int(input())) 6 | pi.sort() 7 | 8 | min = 10000000 9 | for i in range(n-1): 10 | if min>abs(pi[i]-pi[i+1]): 11 | min = abs(pi[i]-pi[i+1]) 12 | if min==0: 13 | break 14 | print(min) 15 | -------------------------------------------------------------------------------- /EASY/MARS LANDER - EPISODE 1/php/mars-lander-episode-1.php: -------------------------------------------------------------------------------- 1 | 1200 and $v_speed>-45) 41 | $power = (int)($power*(1-$dist/3000)); 42 | 43 | // 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). 44 | echo "0 ".$power."\n"; 45 | } -------------------------------------------------------------------------------- /EASY/MARS LANDER - EPISODE 1/python/mars-lander-episode-1.py: -------------------------------------------------------------------------------- 1 | # https://www.codingame.com/ide/puzzle/mars-lander-episode-1 2 | surface_n = int(raw_input()) 3 | land_x_prev = land_y_prev = 0 4 | landing_start = 0 5 | landing_end = 7000 6 | landing_height = 0 7 | for i in range(surface_n): 8 | land_x, land_y = [int(j) for j in raw_input().split()] 9 | if(land_x_prev != 0 and land_y_prev == land_y): 10 | landing_height = land_y 11 | landing_start = land_x_prev 12 | landing_end = land_x 13 | land_x_prev, land_y_prev = land_x, land_y 14 | while True: 15 | # h_speed: the horizontal speed (in m/s), can be negative. 16 | # v_speed: the vertical speed (in m/s), can be negative. 17 | # fuel: the quantity of remaining fuel in liters. 18 | # rotate: the rotation angle in degrees (-90 to 90). 19 | # power: the thrust power (0 to 4). 20 | x, y, h_speed, v_speed, fuel, rotate, power = [int(i) for i in raw_input().split()] 21 | if(landing_start1200 and v_speed>-45): 28 | power = int(power*(1-dist/3000)) 29 | # 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). 30 | print("0 "+str(power)) 31 | 32 | -------------------------------------------------------------------------------- /EASY/MARS LANDER - EPISODE 1/python3/mars-lander-episode-1.py: -------------------------------------------------------------------------------- 1 | # https://www.codingame.com/ide/puzzle/mars-lander-episode-1 2 | surface_n = int(input()) # the number of points used to draw the surface of Mars. 3 | land_x_prev = land_y_prev = 0 4 | landing_start = 0 5 | landing_end = 7000 6 | landing_height = 0 7 | for i in range(surface_n): 8 | # land_x: X coordinate of a surface point. (0 to 6999) 9 | # land_y: Y coordinate of a surface point. By linking all the points together in a sequential fashion, you form the surface of Mars. 10 | land_x, land_y = [int(j) for j in input().split()] 11 | if(land_x_prev != 0 and land_y_prev == land_y): 12 | landing_height = land_y 13 | landing_start = land_x_prev 14 | landing_end = land_x 15 | land_x_prev, land_y_prev = land_x, land_y 16 | # game loop 17 | while True: 18 | # h_speed: the horizontal speed (in m/s), can be negative. 19 | # v_speed: the vertical speed (in m/s), can be negative. 20 | # fuel: the quantity of remaining fuel in liters. 21 | # rotate: the rotation angle in degrees (-90 to 90). 22 | # power: the thrust power (0 to 4). 23 | x, y, h_speed, v_speed, fuel, rotate, power = [int(i) for i in input().split()] 24 | if(landing_start1200 and v_speed>-45): 31 | power = int(power*(1-dist/3000)) 32 | # 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). 33 | print("0 "+str(power)) 34 | 35 | -------------------------------------------------------------------------------- /EASY/MYME TYPE/Readme.md: -------------------------------------------------------------------------------- 1 | # MIME types 2 | 3 | _MIME_ types are used in numerous internet protocols to associate a media type (html, image, video ...) with the content sent. The _MIME_ type is generally inferred from the extension of the file to be sent. 4 | You have to write a program that makes it possible to detect the _MIME_ type of a file based on its name. 5 | 6 | You are provided with a table which associates _MIME_ types to file extensions. You are also given a list of names of files to be transferred and for each one of these files, you must find the _MIME_ type to be used. 7 | 8 | The extension of a file is defined as the substring which follows the last occurrence, if any, of the dot character within the file name. 9 | 10 | If the extension for a given file can be found in the association table (case insensitive, e.g. TXT is treated the same way as txt), then print the corresponding _MIME_ type. If it is not possible to find the _MIME_ type corresponding to a file, or if the file doesn’t have an extension, print UNKNOWN. 11 | 12 | ## Input 13 | 14 | * **Line 1**: Number N of elements which make up the association table. 15 | * **Line 2**: Number Q of file names to be analyzed. 16 | * **N following lines**: One file extension per line and the corresponding _MIME_ type (separated by a blank space). 17 | * **Q following lines**: One file name per line. 18 | 19 | ## Output 20 | 21 | For each of the Q filenames, display on a line the corresponding _MIME_ type. If there is no corresponding type, then display ``UNKNOWN``. 22 | 23 | ## Constraints 24 | 25 | * 0 < N < 10000 26 | * 0 < Q < 10000 27 | * File extensions are composed of a maximum of 10 alphanumerical ASCII characters. 28 | * _MIME_ types are composed of a maximum 50 alphanumerical and punctuation ASCII characters. 29 | * File names are composed of a maximum of 256 alphanumerical ASCII characters and dots (full stops). 30 | * There are no spaces in the file names, extensions or _MIME_ types. 31 | 32 | ## Example 33 | 34 | Input 35 | 36 | 2 37 | 4 38 | html text/html 39 | png image/png 40 | test.html 41 | noextension 42 | portrait.png 43 | doc.TXT 44 | 45 | Output 46 | 47 | text/html 48 | UNKNOWN 49 | image/png 50 | UNKNOWN 51 | 52 | ## Conditions 53 | 54 | * Available RAM: 512MB 55 | * Timeout: 1 seconds 56 | * The program has to read inputs from standard input 57 | * The program has to write the solution to standard output 58 | * The program must run in the test environment -------------------------------------------------------------------------------- /EASY/MYME TYPE/php/mime-type.php: -------------------------------------------------------------------------------- 1 | 1){ 28 | $e = strtolower(end($farr)); 29 | if(isset($dictionary[$e])){ 30 | echo("{$dictionary[$e]}\n"); 31 | } 32 | else echo("UNKNOWN\n"); 33 | 34 | } else echo("UNKNOWN\n"); 35 | } 36 | 37 | // Write an action using echo(). DON'T FORGET THE TRAILING \n 38 | // To debug (equivalent to var_dump): error_log(var_export($var, true)); 39 | 40 | ?> -------------------------------------------------------------------------------- /EASY/MYME TYPE/python/mime-type.py: -------------------------------------------------------------------------------- 1 | # https://www.codingame.com/ide/puzzle/mime-type 2 | dictionary = {} 3 | n = int(raw_input()) # Number of elements which make up the association table. 4 | q = int(raw_input()) # Number Q of file names to be analyzed. 5 | for i in range(n): 6 | # ext: file extension 7 | # mt: MIME type. 8 | ext, mt = raw_input().split() 9 | dictionary[ext.lower()] = mt 10 | for i in range(q): 11 | fname = raw_input() # One file name per line. 12 | farr = fname.split('.') 13 | if len(farr)>1: 14 | try: 15 | print(dictionary[farr[-1].lower()]) 16 | except KeyError: 17 | print("UNKNOWN") 18 | except IndexError: 19 | print("UNKNOWN") 20 | else: 21 | print("UNKNOWN") 22 | # For each of the Q filenames, display on a line the corresponding MIME type. If there is no corresponding type, then display UNKNOWN. 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /EASY/MYME TYPE/python3/mime-type.py: -------------------------------------------------------------------------------- 1 | # https://www.codingame.com/ide/puzzle/mime-type 2 | dictionary = {} 3 | n = int(input()) # Number of elements which make up the association table. 4 | q = int(input()) # Number Q of file names to be analyzed. 5 | for i in range(n): 6 | # ext: file extension 7 | # mt: MIME type. 8 | ext, mt = input().split() 9 | dictionary[ext.lower()] = mt 10 | for i in range(q): 11 | fname = input() # One file name per line. 12 | farr = fname.split('.') 13 | if len(farr)>1: 14 | try: 15 | print(dictionary[farr[-1].lower()]) 16 | except KeyError: 17 | print("UNKNOWN") 18 | except IndexError: 19 | print("UNKNOWN") 20 | else: 21 | print("UNKNOWN") 22 | # For each of the Q filenames, display on a line the corresponding MIME type. If there is no corresponding type, then display UNKNOWN. 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /EASY/ONBOARDING/bash/onboarding.bash: -------------------------------------------------------------------------------- 1 | while true; do 2 | # enemy1: name of enemy 1 3 | read enemy1 4 | # dist1: distance to enemy 1 5 | read dist1 6 | # enemy2: name of enemy 2 7 | read enemy2 8 | # dist2: distance to enemy 2 9 | read dist2 10 | 11 | if [ $dist1 -lt $dist2 ] 12 | then 13 | echo $enemy1 14 | else 15 | echo $enemy2 16 | fi 17 | done -------------------------------------------------------------------------------- /EASY/ONBOARDING/bash/onboarding2.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | read n 4 | read temp 5 | temps=(${temp// / }) 6 | 7 | closest=10000 8 | for i in ${temps[@]}; do 9 | if [ $((${i#-})) -lt $((${closest#-})) ] || [[ $((${i#-})) -eq $((${closest#-})) && $((${closest})) -lt 0 ]]; then 10 | closest=$i 11 | fi 12 | done 13 | 14 | if [ $((n)) -eq 0 ]; then 15 | closest=0 16 | fi 17 | 18 | echo $closest -------------------------------------------------------------------------------- /EASY/ONBOARDING/c#/onboarding.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | class Player 4 | { 5 | static void Main(string[] args) 6 | { 7 | while (true) 8 | { 9 | string enemy1 = Console.ReadLine(); // name of enemy 1 10 | int dist1 = int.Parse(Console.ReadLine()); // distance to enemy 1 11 | string enemy2 = Console.ReadLine(); // name of enemy 2 12 | int dist2 = int.Parse(Console.ReadLine()); // distance to enemy 2 13 | 14 | if (dist1 < dist2) 15 | Console.WriteLine(enemy1); 16 | else 17 | Console.WriteLine(enemy2); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /EASY/ONBOARDING/c++/onboarding.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | while (1) { 8 | string enemy1; // name of enemy 1 9 | cin >> enemy1; cin.ignore(); 10 | int dist1; // distance to enemy 1 11 | cin >> dist1; cin.ignore(); 12 | string enemy2; // name of enemy 2 13 | cin >> enemy2; cin.ignore(); 14 | int dist2; // distance to enemy 2 15 | cin >> dist2; cin.ignore(); 16 | 17 | if (dist1 < dist2) 18 | cout << enemy1 << endl; 19 | else 20 | cout << enemy2 << endl; 21 | } 22 | } -------------------------------------------------------------------------------- /EASY/ONBOARDING/c/onboarding.c: -------------------------------------------------------------------------------- 1 | int main() 2 | { 3 | while (1) 4 | { 5 | char enemy1[257]; // name of enemy 1 6 | scanf("%s", enemy1); 7 | int dist1; // distance to enemy 1 8 | scanf("%d", &dist1); 9 | char enemy2[257]; // name of enemy 2 10 | scanf("%s", enemy2); 11 | int dist2; // distance to enemy 2 12 | scanf("%d", &dist2); 13 | 14 | if (dist1 < dist2) 15 | printf("%s\n", enemy1); 16 | else 17 | printf("%s\n", enemy2); 18 | } 19 | return 0; 20 | } -------------------------------------------------------------------------------- /EASY/ONBOARDING/clojure/onboarding.clj: -------------------------------------------------------------------------------- 1 | (ns Player 2 | (:gen-class)) 3 | 4 | (defn -main [& args] 5 | (while true 6 | (let [enemy1 (read) dist1 (read) enemy2 (read) dist2 (read)] 7 | ; enemy1: name of enemy 1 8 | ; dist1: distance to enemy 1 9 | ; enemy2: name of enemy 2 10 | ; dist2: distance to enemy 2 11 | 12 | (if (< dist1 dist2) (println enemy1) (println enemy2)) 13 | ))) -------------------------------------------------------------------------------- /EASY/ONBOARDING/dart/onboarding.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | void main() 4 | { 5 | while (true) 6 | { 7 | String enemy1 = stdin.readLineSync(); // name of enemy 1 8 | int dist1 = int.parse(stdin.readLineSync()); // distance to enemy 1 9 | String enemy2 = stdin.readLineSync(); // name of enemy 2 10 | int dist2 = int.parse(stdin.readLineSync()); // distance to enemy 2 11 | 12 | if (dist1 < dist2) 13 | print(enemy1); 14 | else 15 | print(enemy2); 16 | } 17 | } -------------------------------------------------------------------------------- /EASY/ONBOARDING/f#/onboarding.fs: -------------------------------------------------------------------------------- 1 | open System 2 | 3 | while true do 4 | let enemy1 = Console.In.ReadLine() (* name of enemy 1 *) 5 | let dist1 = int(Console.In.ReadLine()) (* distance to enemy 1 *) 6 | let enemy2 = Console.In.ReadLine() (* name of enemy 2 *) 7 | let dist2 = int(Console.In.ReadLine()) (* distance to enemy 2 *) 8 | 9 | if dist1 < dist2 then printfn "%s" enemy1 10 | else printfn "%s" enemy2 11 | 12 | () -------------------------------------------------------------------------------- /EASY/ONBOARDING/go/onboarding.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | for 7 | { 8 | // enemy1: name of enemy 1 9 | var enemy1 string 10 | fmt.Scan(&enemy1) 11 | 12 | // dist1: distance to enemy 1 13 | var dist1 int 14 | fmt.Scan(&dist1) 15 | 16 | // enemy2: name of enemy 2 17 | var enemy2 string 18 | fmt.Scan(&enemy2) 19 | 20 | // dist2: distance to enemy 2 21 | var dist2 int 22 | fmt.Scan(&dist2) 23 | 24 | if dist1 < dist2 { 25 | fmt.Println(enemy1) 26 | } else { 27 | fmt.Println(enemy2) 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /EASY/ONBOARDING/java/onboarding.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class Player 4 | { 5 | public static void main(String args[]) 6 | { 7 | Scanner in = new Scanner(System.in); 8 | while (true) 9 | { 10 | String enemy1 = in.next(); // name of enemy 1 11 | int dist1 = in.nextInt(); // distance to enemy 1 12 | String enemy2 = in.next(); // name of enemy 2 13 | int dist2 = in.nextInt(); // distance to enemy 2 14 | 15 | if (dist1 < dist2) 16 | System.out.println(enemy1); 17 | else 18 | System.out.println(enemy2); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /EASY/ONBOARDING/js/onboarding.js: -------------------------------------------------------------------------------- 1 | while (true) 2 | { 3 | var enemy1 = readline(); // name of enemy 1 4 | var dist1 = parseInt(readline()); // distance to enemy 1 5 | var enemy2 = readline(); // name of enemy 2 6 | var dist2 = parseInt(readline()); // distance to enemy 2 7 | 8 | if (dist1 < dist2) 9 | print(enemy1); 10 | else 11 | print(enemy2); 12 | } -------------------------------------------------------------------------------- /EASY/ONBOARDING/php/onboarding.php: -------------------------------------------------------------------------------- 1 | $lightY){ 11 | $move_string = "N"; 12 | $initialTY--; 13 | } 14 | if ($initialTX<$lightX){ 15 | $move_string .= "E"; 16 | $initialTX++; 17 | } 18 | elseif ($initialTX>$lightX){ 19 | $move_string .= "W"; 20 | $initialTX--; 21 | } 22 | echo($move_string."\n"); 23 | } 24 | -------------------------------------------------------------------------------- /EASY/POWER OF THOR - EPISODE 1/python/power-of-thor-episode-1.py: -------------------------------------------------------------------------------- 1 | # https://www.codingame.com/ide/puzzle/power-of-thor-episode-1 2 | light_x, light_y, initial_tx, initial_ty = [int(i) for i in raw_input().split()] 3 | current_x, current_y = initial_tx, initial_ty 4 | while True: 5 | remaining_turns = int(raw_input()) # The remaining amount of turns Thor can move. Do not remove this line. 6 | move_string = "" 7 | if current_ylight_y: 11 | move_string = "N" 12 | current_y = current_y - 1 13 | if current_xlight_x: 17 | move_string = move_string + "W" 18 | current_x = current_x - 1 19 | # A single line providing the move to be made: N NE E SE S SW W or NW 20 | print(move_string) 21 | 22 | -------------------------------------------------------------------------------- /EASY/POWER OF THOR - EPISODE 1/python3/power-of-thor-episode-1.py: -------------------------------------------------------------------------------- 1 | # https://www.codingame.com/ide/puzzle/power-of-thor-episode-1 2 | import sys 3 | import math 4 | 5 | # --- 6 | # Hint: You can use the debug stream to print initialTX and initialTY, if Thor seems not follow your orders. 7 | 8 | # light_x: the X position of the light of power 9 | # light_y: the Y position of the light of power 10 | # initial_tx: Thor's starting X position 11 | # initial_ty: Thor's starting Y position 12 | light_x, light_y, initial_tx, initial_ty = [int(i) for i in input().split()] 13 | current_x, current_y = initial_tx, initial_ty 14 | # game loop 15 | while True: 16 | remaining_turns = int(input()) # The remaining amount of turns Thor can move. Do not remove this line. 17 | move_string = "" 18 | if current_ylight_y: 22 | move_string = "N" 23 | current_y = current_y - 1 24 | if current_xlight_x: 28 | move_string = move_string + "W" 29 | current_x = current_x - 1 30 | # A single line providing the move to be made: N NE E SE S SW W or NW 31 | print(move_string) 32 | 33 | -------------------------------------------------------------------------------- /EASY/TEMPERATURES/Readme.md: -------------------------------------------------------------------------------- 1 | # Temperatures 2 | 3 | In this exercise, you have to analyze records of temperature to find the closest to zero. 4 | 5 | ![Sample temperatures](img/temp_fr.png "Here, -1 is the closest to 0.") 6 | 7 | Write a program that prints the temperature closest to 0 among input data. 8 | 9 | ## Input 10 | 11 | * **Line 1**: N, the number of temperatures to analyse 12 | * **Line 2**: The N temperatures expressed as integers ranging from _-273 to 5526_ 13 | 14 | ## Output 15 | 16 | * Display 0 (zero) if no temperature is provided 17 | * Otherwise, display the temperature closest to 0, 18 | * knowing that if two numbers are equally close to zero, 19 | * positive integer has to be considered closest to zero 20 | * (for instance, if the temperatures are -5 to 5, then display 5) 21 | 22 | ## Constraints 23 | 24 | * 0 ≤ N < 10000 25 | 26 | ## Example 27 | 28 | Input 29 | 30 | 5 31 | 1 -2 -8 4 5 32 | 33 | Output 34 | 35 | 1 36 | 37 | ## Conditions 38 | 39 | * Available RAM: 512MB 40 | * Timeout: 1 seconds 41 | * The program has to read inputs from standard input 42 | * The program has to write the solution to standard output 43 | * The program must run in the test environment -------------------------------------------------------------------------------- /EASY/TEMPERATURES/bash/temperatures.sh: -------------------------------------------------------------------------------- 1 | read n # n: the number of temperatures to analyse 2 | read -a temps # temps: the n temperatures expressed as integers ranging from -273 to 5526 3 | 4 | if [ $n == 0 ] 5 | then 6 | echo 0 7 | else 8 | tempsLength=${#temps[@]} 9 | closest=${temps[0]} 10 | pos=0 11 | 12 | if [[ $closest -lt 0 ]] 13 | then 14 | closest=$(( 0 - $closest )) 15 | fi 16 | 17 | for (( i=0;i<$tempsLength;i++)) 18 | do 19 | tempInt=${temps[${i}]} 20 | if [ $tempInt -lt 0 ] 21 | then 22 | tempInt=$(( 0 - $tempInt )) 23 | fi 24 | 25 | if [ $tempInt -lt $closest ] # && [ $tempInt -ge 0 ] 26 | then 27 | closest=$tempInt 28 | pos=$i 29 | elif [ $tempInt -eq $closest ] && [ ${temps[${i}]} -ge 0 ] 30 | then 31 | closest=$tempInt 32 | pos=$i 33 | fi 34 | done 35 | 36 | echo ${temps[${pos}]} 37 | fi -------------------------------------------------------------------------------- /EASY/TEMPERATURES/c++/temperatures.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | /** 11 | * Auto-generated code below aims at helping you parse 12 | * the standard input according to the problem statement. 13 | **/ 14 | int main() 15 | { 16 | int N; // the number of temperatures to analyse 17 | cin >> N; cin.ignore(); 18 | string TEMPS; // the N temperatures expressed as integers ranging from -273 to 5526 19 | getline(cin, TEMPS); 20 | 21 | istringstream iss(TEMPS); 22 | 23 | int min = numeric_limits::max(); 24 | for (int i = 0; i < N; ++i) 25 | { 26 | int nr; 27 | iss >> nr; 28 | 29 | if (abs(nr) < abs(min) or (abs(nr) == abs(min) and nr>min)) 30 | min = nr; 31 | } 32 | 33 | if (N > 0) 34 | cout << min << endl; 35 | else 36 | cout << 0 << endl; 37 | } -------------------------------------------------------------------------------- /EASY/TEMPERATURES/img/temp_fr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/EASY/TEMPERATURES/img/temp_fr.png -------------------------------------------------------------------------------- /EASY/TEMPERATURES/java/temperatures.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | import java.math.*; 4 | 5 | class Solution 6 | { 7 | public static void main(String args[]) 8 | { 9 | Scanner in = new Scanner(System.in); 10 | int n = in.nextInt(); // the number of temperatures to analyse 11 | in.nextLine(); 12 | String temps = in.nextLine(); // the n temperatures expressed as integers ranging from -273 to 5526 13 | 14 | int[] arr = new int[n]; 15 | if (n == 0) 16 | System.out.println(0); 17 | else 18 | { 19 | for (int i = 0; i < n; i++) 20 | { 21 | if (temps.indexOf(" ") != -1) 22 | { 23 | arr[i] = Integer.parseInt(temps.substring(0, temps.indexOf(" "))); 24 | temps = temps.substring(temps.indexOf(" ") + 1, temps.length()); 25 | } 26 | else 27 | { 28 | arr[i] = Integer.parseInt(temps); 29 | temps = ""; 30 | } 31 | } 32 | 33 | int max = 0; 34 | for (int i = 0; i < n; i++) 35 | { 36 | if (Math.abs(arr[i]) < Math.abs(arr[max]) || (Math.abs(arr[i]) == Math.abs(arr[max]) && arr[i] > 0)) 37 | max = i; 38 | } 39 | 40 | System.out.println(arr[max]); 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /EASY/TEMPERATURES/js/temperatures.js: -------------------------------------------------------------------------------- 1 | var N = parseInt(readline()); // the number of temperatures to analyse 2 | var TEMPS = readline(); // the N temperatures expressed as integers ranging from -273 to 5526 3 | 4 | if (TEMPS) { 5 | printErr(TEMPS); 6 | var temperatures = TEMPS.split(' '); 7 | var minus = -9999; 8 | var plus = 9999; 9 | 10 | for (i in temperatures) { 11 | var t = temperatures[i]; 12 | 13 | if (t < 0) { 14 | if (parseInt(minus) < parseInt(t)) minus = t; 15 | } else { 16 | if (parseInt(plus) > parseInt(t)) plus = t; 17 | } 18 | } 19 | 20 | if (-parseInt(minus) < parseInt(plus)) { 21 | print(minus); 22 | } else { 23 | print(plus); 24 | } 25 | } else { 26 | print('0'); 27 | } -------------------------------------------------------------------------------- /EASY/TEMPERATURES/php/temperatures.php: -------------------------------------------------------------------------------- 1 | abs($item) or (abs($min)==abs($item) and $item>$min)) 12 | $min = $item; 13 | } 14 | } 15 | else 16 | $min = 0; 17 | echo("$min\n"); 18 | -------------------------------------------------------------------------------- /EASY/TEMPERATURES/python/temperatures.py: -------------------------------------------------------------------------------- 1 | # https://www.codingame.com/ide/puzzle/temperatures 2 | n = int(raw_input()) # the number of temperatures to analyse 3 | temps = raw_input() # the n temperatures expressed as integers ranging from -273 to 5526 4 | if n !=0: 5 | array = temps.split(' ') 6 | min = int(array[0]) 7 | for i in range(1, n): 8 | if (abs(min)>abs(int(array[i])) or (abs(min)==abs(int(array[i])) and int(array[i])>min)): 9 | min = int(array[i]) 10 | else: 11 | min = 0 12 | print(str(min)) 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /EASY/TEMPERATURES/python3/temperatures.py: -------------------------------------------------------------------------------- 1 | # https://www.codingame.com/ide/puzzle/temperatures 2 | n = int(input()) # the number of temperatures to analyse 3 | temps = input() # the n temperatures expressed as integers ranging from -273 to 5526 4 | if n !=0: 5 | array = temps.split(' ') 6 | min = int(array[0]) 7 | for i in range(1, n): 8 | if (abs(min)>abs(int(array[i])) or (abs(min)==abs(int(array[i])) and int(array[i])>min)): 9 | min = int(array[i]) 10 | else: 11 | min = 0 12 | print(str(min)) 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /EASY/THE DESCENT/php/the-descent.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /EASY/THE DESCENT/python/the-descent.py: -------------------------------------------------------------------------------- 1 | # https://www.codingame.com/ide/puzzle/the-descent 2 | while True: 3 | mountain_max = 0 4 | index_max = 0 5 | for i in range(8): 6 | mountain_h = int(raw_input()) 7 | if mountain_max=2) {System.out.println("YES"); return;} 22 | } 23 | 24 | // Write an action using System.out.println() 25 | // To debug: System.err.println("Debug messages..."); 26 | 27 | System.out.println("NO"); 28 | } 29 | 30 | public static boolean willReach(int cnt,int TARGET) { 31 | if (used[cnt]) return eqt[cnt]; 32 | used[cnt] = true; 33 | int nxt = getNew(cnt); 34 | if (nxt==TARGET) return eqt[cnt]=true; 35 | else if (nxt>TARGET) return eqt[cnt]=false; 36 | return eqt[cnt]=willReach(nxt,TARGET); 37 | } 38 | 39 | public static int getNew(int cnt) { 40 | int copy = cnt; 41 | while (copy>0) { 42 | cnt+=copy%10; 43 | copy/=10; 44 | } 45 | return cnt; 46 | } 47 | } -------------------------------------------------------------------------------- /EASY/THE RIVER II/java/the-river-ii-.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | import java.math.*; 4 | 5 | /** 6 | * Auto-generated code below aims at helping you parse 7 | * the standard input according to the problem statement. 8 | **/ 9 | class Solution { 10 | static boolean eqt[]; 11 | static boolean used[]; 12 | //static StringBuffer CNT; 13 | public static void main(String args[]) { 14 | Scanner in = new Scanner(System.in); 15 | int r1 = in.nextInt(); 16 | eqt = new boolean[r1]; 17 | used = new boolean[r1]; 18 | int count = 0; 19 | for (int cnt = 1; cnt < r1; cnt++) { 20 | if (willReach(cnt,r1)) count++; 21 | if (count>=2) {System.out.println("YES"); return;} 22 | } 23 | 24 | // Write an action using System.out.println() 25 | // To debug: System.err.println("Debug messages..."); 26 | 27 | System.out.println("NO"); 28 | } 29 | 30 | public static boolean willReach(int cnt,int TARGET) { 31 | if (used[cnt]) return eqt[cnt]; 32 | used[cnt] = true; 33 | int nxt = getNew(cnt); 34 | if (nxt==TARGET) return eqt[cnt]=true; 35 | else if (nxt>TARGET) return eqt[cnt]=false; 36 | return eqt[cnt]=willReach(nxt,TARGET); 37 | } 38 | 39 | public static int getNew(int cnt) { 40 | int copy = cnt; 41 | while (copy>0) { 42 | cnt+=copy%10; 43 | copy/=10; 44 | } 45 | return cnt; 46 | } 47 | } -------------------------------------------------------------------------------- /EASY/THE TRAVELLING SALESMAN PROBLEM/java/the-travelling-salesman-problem.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | import java.math.*; 4 | import java.awt.*; 5 | 6 | /** 7 | * Auto-generated code below aims at helping you parse 8 | * the standard input according to the problem statement. 9 | **/ 10 | class Solution { 11 | 12 | static int seen = 0; 13 | static int N; 14 | static Point[] spots; 15 | static boolean[] used; 16 | static double path = 0.0; 17 | 18 | public static void main(String args[]) { 19 | Scanner in = new Scanner(System.in); 20 | //System.out.println("ENTER:"); 21 | N = in.nextInt(); 22 | spots = new Point[N]; 23 | used = new boolean[N]; 24 | for (int i = 0; i < N; i++) { 25 | int X = in.nextInt(); 26 | int Y = in.nextInt(); 27 | spots[i] = new Point(X,Y); 28 | } 29 | 30 | findPath(0); 31 | 32 | // Write an action using System.out.println() 33 | // To debug: System.err.println("Debug messages..."); 34 | 35 | System.out.println((int)(Math.round(path))); 36 | } 37 | 38 | public static void findPath(int index) { 39 | used[index] = true; 40 | Point p = spots[index]; 41 | double minDist = Integer.MAX_VALUE; 42 | int ind = 0; 43 | for (int i = 0; i < N; i++) { 44 | if (!used[i]&&i!=index) { 45 | double Dist = Math.sqrt(Math.pow(p.x-spots[i].x,2)+Math.pow(p.y-spots[i].y,2)); 46 | if (Dist) { 16 | // read standard input 17 | val input = Scanner(System.`in`) 18 | val nbPoints = input.nextInt() 19 | val points = ArrayList>(nbPoints) 20 | for (i in 0 until nbPoints) { 21 | val nbItems = input.nextInt() 22 | val time = input.nextInt() 23 | points.add(Pair(nbItems, time)) 24 | } 25 | 26 | // compute the most probable computational complexity 27 | var bestFit = "" 28 | var minNormVariance = Double.POSITIVE_INFINITY 29 | for (complexity in complexities) { 30 | val ratios = points.map { it.second / complexity.function(it.first.toDouble()) } 31 | 32 | // calculate the normalized variance 33 | val meanRatios = ratios.sum() / ratios.size 34 | val variances = ratios.map { Math.pow(it - meanRatios, 2.0) } 35 | val normVariance = variances.sum() / Math.pow(meanRatios, 2.0) 36 | 37 | if (normVariance < minNormVariance) { 38 | minNormVariance = normVariance 39 | bestFit = complexity.name() 40 | } 41 | } 42 | 43 | println("O($bestFit)") 44 | } 45 | 46 | interface Complexity { 47 | fun name(): String 48 | fun function(n: Double): Double 49 | } 50 | 51 | class Constant : Complexity { 52 | override fun name(): String { return "1" } 53 | override fun function(n: Double): Double { 54 | return 1.0 55 | } 56 | } 57 | 58 | class Logarithmic : Complexity { 59 | override fun name(): String { return "log n" } 60 | override fun function(n: Double): Double { 61 | return Math.log(n) 62 | } 63 | } 64 | 65 | class Linear : Complexity { 66 | override fun name(): String { return "n" } 67 | override fun function(n: Double): Double { 68 | return n 69 | } 70 | } 71 | 72 | class LogLinear : Complexity { 73 | override fun name(): String { return "n log n" } 74 | override fun function(n: Double): Double { 75 | return n * Math.log(n) 76 | } 77 | } 78 | 79 | class Quadratic : Complexity { 80 | override fun name(): String { return "n^2" } 81 | override fun function(n: Double): Double { 82 | return n * n 83 | } 84 | } 85 | 86 | class LogQuadratic : Complexity { 87 | override fun name(): String { return "n^2 log n" } 88 | override fun function(n: Double): Double { 89 | return n * n * Math.log(n) 90 | } 91 | } 92 | 93 | // for validator test #7 94 | class Cubic : Complexity { 95 | override fun name(): String { return "n^3" } 96 | override fun function(n: Double): Double { 97 | return Math.pow(n, 2.1) 98 | } 99 | } 100 | 101 | class Exponential : Complexity { 102 | override fun name(): String { return "2^n" } 103 | override fun function(n: Double): Double { 104 | return Math.pow(2.0, n) 105 | } 106 | } -------------------------------------------------------------------------------- /HARD/BENDER - EPISODE 3/python/bender-episode-3.py: -------------------------------------------------------------------------------- 1 | # adapted from https://github.com/aethersg/codingame-puzzle/blob/master/Python/hard/Bender-Episode%203.py 2 | import sys 3 | import math 4 | 5 | # Auto-generated code below aims at helping you parse 6 | # the standard input according to the problem statement. 7 | 8 | algo_names = ["1", "log n", "n", "n log n", "n^2", "n^2 log n", "n^3", "2^n"] 9 | complex = [lambda x: 1, 10 | lambda x: math.log(x), 11 | lambda x: x, 12 | lambda x: x * math.log(x), 13 | lambda x: x ** 2, 14 | lambda x: x ** 2 * math.log(x), 15 | lambda x: x ** 3, 16 | lambda x: math.pow(2, x)] 17 | 18 | upperLimit = [None, None, None, None, None, None, None, 500] 19 | 20 | x, pref = [], [] 21 | n = int(input()) 22 | for i in range(n): 23 | num, t = [int(j) for j in input().split()] 24 | x.append(num) 25 | pref.append(t) 26 | 27 | # Write an action using print 28 | # To debug: print >> sys.stderr, "Debug messages..." 29 | 30 | variances, minVariance, result = [], sys.maxsize, -1 31 | 32 | for i in range(len(complex)): 33 | f = complex[i] 34 | # takes upperLimit into account to avoid an overflow 35 | maxDataVolume = len(x) 36 | if upperLimit[i] is not None: 37 | for j in range(len(x)): 38 | if x[j] > upperLimit[i]: 39 | maxDataVolume = j - 1 40 | break 41 | 42 | ratio = [pref[j] / f(x[j]) for j in range(maxDataVolume)] 43 | if len(ratio) < 5: 44 | variances.append(-1) 45 | else: 46 | mean = sum(ratio) / len(ratio) 47 | variances.append(sum([(val - mean) ** 2 for val in ratio]) / mean ** 2) 48 | if variances[-1] < minVariance: 49 | minVariance = variances[-1] 50 | result = i 51 | 52 | print("O({})".format(algo_names[result])) -------------------------------------------------------------------------------- /HARD/CGX FORMATTER/img/cgx5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/HARD/CGX FORMATTER/img/cgx5.png -------------------------------------------------------------------------------- /HARD/CGX FORMATTER/img/cgx6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/HARD/CGX FORMATTER/img/cgx6.png -------------------------------------------------------------------------------- /HARD/CGX FORMATTER/img/cgx7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/HARD/CGX FORMATTER/img/cgx7.png -------------------------------------------------------------------------------- /HARD/CGX FORMATTER/python3/cgx-formatter.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import math 3 | 4 | 5 | def check_next_line(c, last_char): 6 | global temp_string 7 | global tabs 8 | if last_char == '=': 9 | print(ord(c), file=sys.stderr) 10 | if last_char == ')' and c != ';' and c != ')' and c != '(': 11 | temp_string += '\n' + (tabs * 4) * " " 12 | elif last_char == '(' and c != ")": 13 | temp_string += '\n' + (tabs * 4) * " " 14 | elif last_char == ';': 15 | temp_string += '\n' + (tabs * 4) * " " 16 | elif last_char == '=' and c == '(': 17 | temp_string += '\n' + (tabs * 4) * " " 18 | 19 | 20 | # Auto-generated code below aims at helping you parse 21 | # the standard input according to the problem statement. 22 | cgxlines = [] 23 | n = int(input()) 24 | for i in range(n): 25 | cgxline = input() 26 | cgxlines.append(cgxline) 27 | 28 | tabs = 0 29 | temp_string = '' 30 | string_started = False 31 | last_char = '' 32 | for line in cgxlines: 33 | for c in line: 34 | if c == '\'' and not (string_started): 35 | check_next_line(c, last_char) 36 | string_started = True 37 | temp_string += c 38 | elif string_started and c == '\'': 39 | string_started = False 40 | temp_string += c 41 | elif string_started: 42 | temp_string += c 43 | elif (c.isspace()): 44 | continue 45 | else: 46 | check_next_line(c, last_char) 47 | if c == '(': 48 | temp_string += "(" 49 | tabs += 1 50 | elif c == ')': 51 | tabs -= 1 52 | temp_string += '\n' + (tabs * 4) * " " + ")" 53 | else: 54 | temp_string += c 55 | last_char = c 56 | print(temp_string) 57 | # Write an action using print 58 | # To debug: print("Debug messages...", file=sys.stderr) 59 | -------------------------------------------------------------------------------- /HARD/GENOME SEQUENCING/Readme.md: -------------------------------------------------------------------------------- 1 | #Genome Sequence 2 | 3 | You are working as a computer scientist in a laboratory seeking to sequence the genome. A DNA sequence is represented by a character string _(of A, C, T and G)_ such as _GATTACA_. 4 | 5 | The problem is that biologists are only able to extract sub-sequences of the complete sequence. Your role is to combine these partial sub-sequences to recover the original sequence. 6 | ​ 7 | So if, for example, you have three sub-sequences _AGATTA, GATTACA, and TACAGA_ you should be able to find the sequence _AGATTACAGA_ which has the property of containing all of these. 8 | 9 | Note that in this example, there are other sequences which contain all of the sub-sequences such as _TACAGATTACAGATTA_. However, we prefer the former because it is shorter (10 characters instead of 16). 10 | ​ 11 | In this exercise you are asked to calculate the length of the shortest sequence that contains the N sub-sequences of the input data. 12 | There may be several sequences of the same minimum length and which fit the requirement. We are not asking you to list these, but only to return their length. 13 | 14 | Note that there is always a solution. One can indeed simply concatenate all the sub-sequences to obtain a valid sequence. But by nesting (even partially) the sub-sequences, it is generally possible to obtain a shorter sequence, as shown in the examples. 15 | 16 | ## Input 17 | 18 | * **Line 1**: The number N 19 | * **N Following lines**: one sub-sequence by line, represented by a string of characters from A, C, T and G. Each sub-sequence ranges from 1 to maximum 10 characters long. 20 | 21 | ## Output 22 | 23 | The length of the shortest sequence containing all the sub-sequences. 24 | 25 | ## Constraints 26 | 27 | * 0 < N < 6 28 | 29 | ## Examples 30 | 31 | Input 32 | 33 | 2 34 | AAC 35 | CCTT 36 | 37 | Output 38 | 39 | 6 40 | 41 | Input 42 | 43 | 3 44 | AGATTA 45 | GATTACA 46 | TACAGA 47 | 48 | Output 49 | 50 | 10 51 | 52 | Input 53 | 54 | 3 55 | TT 56 | AA 57 | ACT 58 | 59 | Output 60 | 61 | 5 62 | 63 | ## Conditions 64 | 65 | * Available RAM : 512MB 66 | * Timeout: 1 seconds 67 | * The program has to read inputs from standard input 68 | * The program has to write the solution to standard output 69 | * The program must run in the test environment 70 | -------------------------------------------------------------------------------- /HARD/GENOME SEQUENCING/python3/genome-sequencing.py: -------------------------------------------------------------------------------- 1 | # based on https://github.com/aethersg/codingame-puzzle/blob/master/Python/hard/Genome%20Sequencing.py 2 | import sys 3 | import math 4 | 5 | 6 | # Auto-generated code below aims at helping you parse 7 | # the standard input according to the problem statement. 8 | def nested(strings): 9 | res = strings.pop() 10 | while len(strings) > 0: 11 | new = strings.pop() 12 | for i in range(len(new) + 1): 13 | subLast = min(i + len(res), len(new)) 14 | if new[i:subLast] == res[:subLast - i]: 15 | res = new[:subLast] + res[subLast - i:] + new[i + len(res):] 16 | break 17 | return res 18 | 19 | 20 | def permutations(l): 21 | if len(l) == 0: 22 | return [[]] 23 | else: 24 | res = [] 25 | for head in l: 26 | l2 = l[:] 27 | l2.remove(head) 28 | for tail in permutations(l2): 29 | res.append([head] + tail) 30 | return res 31 | 32 | 33 | n = int(input()) 34 | strings = [] 35 | for i in range(n): 36 | subseq = input() 37 | strings.append(subseq) 38 | 39 | # Write an action using print 40 | # To debug: print >> sys.stderr, "Debug messages..." 41 | 42 | print(min(len(nested(p)) for p in permutations(strings))) -------------------------------------------------------------------------------- /HARD/POWER OF THOR - EPISODE 2/python3/power-of-thor-episode-2-40-percent.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import math 3 | 4 | WIDE = 4 5 | 6 | class Thor: 7 | tx = 0 8 | ty = 0 9 | h = 0 10 | n = 0 11 | giants = [] 12 | 13 | def __init__(self): 14 | self.tx, self.ty = [int(i) for i in input().split()] 15 | 16 | def scan(self): 17 | self.h, self.n = [int(i) for i in input().split()] 18 | self.giants.clear() 19 | for i in range(self.n): 20 | x, y = [int(j) for j in input().split()] 21 | self.giants.append({'x': x, 'y': y}) 22 | 23 | def find_the_middle(self): 24 | xsumm = ysumm = 0 25 | for giant in self.giants: 26 | xsumm += giant['x'] 27 | ysumm += giant['y'] 28 | return int(xsumm / self.n), int(ysumm / self.n) 29 | 30 | def check_if_strike(self): 31 | for giant in self.giants: 32 | if abs(self.tx - giant['x']) == 1 or abs(self.ty - giant['y']) == 1: 33 | return True 34 | return False 35 | 36 | def move(self): 37 | dir_x, dir_y = self.find_the_middle() 38 | if self.check_if_strike(): 39 | action = "STRIKE" 40 | else: 41 | action = '' 42 | if self.ty < dir_y: 43 | action = action + "S" 44 | self.ty += 1 45 | elif self.ty > dir_y: 46 | action = action + "N" 47 | self.ty -= 1 48 | if self.tx < dir_x: 49 | action = action + "E" 50 | self.tx += 1 51 | elif self.tx > dir_x: 52 | action = action + "W" 53 | self.tx -= 1 54 | if action == '': 55 | action = 'WAIT' 56 | print(action) 57 | 58 | 59 | thor = Thor() 60 | while True: 61 | thor.scan() 62 | thor.move() -------------------------------------------------------------------------------- /HARD/ROLLER COASTER/img/roller.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/HARD/ROLLER COASTER/img/roller.png -------------------------------------------------------------------------------- /HARD/ROLLER COASTER/python3/roller-coaster.py: -------------------------------------------------------------------------------- 1 | # based on https://github.com/cpj1352/codingame/blob/master/hard/Roller%20Coaster.py 2 | L, C, N = [int(i) for i in input().split()] 3 | text = [] 4 | idx = 0 5 | memory = {} 6 | for i in range(N): 7 | Pi = int(input()) 8 | text.append(Pi) 9 | num = 0 10 | while C > 0: 11 | origIdx = idx 12 | ride = 0 13 | try: 14 | num+=memory[idx][0] 15 | idx = memory[idx][1] 16 | except KeyError: 17 | Amount = 0 18 | while ride+text[idx]<=L: 19 | ride+=text[idx] 20 | num+=text[idx] 21 | Amount+=text[idx] 22 | idx = int((idx+1)%len(text)) 23 | if idx == origIdx: 24 | break 25 | memory[origIdx] = [Amount, idx] 26 | C-=1 27 | print(num) -------------------------------------------------------------------------------- /HARD/SKYNET REVOLUTION - EPISODE 2/python3/skynet-revolution-episode-2-60-percent.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import math 3 | 4 | 5 | # Auto-generated code below aims at helping you parse 6 | # the standard input according to the problem statement. 7 | 8 | def getBestBloker(si, gat): 9 | global relations 10 | global visited 11 | min_dist, p1, p2 = sys.maxsize, 0, 0 12 | for g in gat: 13 | # print(g, file=sys.stderr) 14 | if g in relations: 15 | for r in relations[g]: 16 | visited.clear() 17 | dist = distanceMin(r, si) 18 | print(dist, file=sys.stderr) 19 | if min_dist > dist: 20 | min_dist, p1, p2 = dist, r, g 21 | return [p1, p2] 22 | 23 | 24 | def distanceMin(num, si, cnt=1): 25 | global relations 26 | global visited 27 | being = visited.get(num, False) 28 | if being != False: 29 | if being > cnt: 30 | visited[num] = cnt 31 | else: 32 | return sys.maxsize 33 | else: 34 | visited[num] = cnt 35 | 36 | if num == si: 37 | return cnt 38 | min_dist = sys.maxsize 39 | relation_list = relations.get(num, []) 40 | for rel in relation_list: 41 | min = distanceMin(rel, si, cnt + 1) 42 | if min_dist >= min: 43 | min_dist = min 44 | return min_dist 45 | 46 | 47 | def unsetter(c1, c2): 48 | global relations 49 | relations[c1].remove(c2) 50 | relations[c2].remove(c1) 51 | 52 | 53 | # n: the total number of nodes in the level, including the gateways 54 | # l: the number of links 55 | # e: the number of exit gateways 56 | gat = [] 57 | relations = {} 58 | visited = {} 59 | n, l, e = [int(i) for i in input().split()] 60 | for i in range(l): 61 | # n1: N1 and N2 defines a link between these nodes 62 | n1, n2 = [int(j) for j in input().split()] 63 | relations.setdefault(n2, []).append(n1) 64 | relations.setdefault(n1, []).append(n2) 65 | 66 | print(relations, file=sys.stderr) 67 | for i in range(e): 68 | ei = int(input()) # the index of a gateway node 69 | gat.append(ei) 70 | 71 | # game loop 72 | while True: 73 | si = int(input()) # The index of the node on which the Skynet agent is positioned this turn 74 | 75 | # Write an action using print 76 | # To debug: print("Debug messages...", file=sys.stderr) 77 | c1, c2 = getBestBloker(si, gat) 78 | unsetter(c1, c2) 79 | print("{0} {1}".format(c1, c2)) 80 | # Example: 3 4 are the indices of the nodes you wish to sever the link between -------------------------------------------------------------------------------- /HARD/SUPER COMPUTER/Readme.md: -------------------------------------------------------------------------------- 1 | # Super Computer 2 | 3 | In the Computer2000 data center, you are responsible for planning the usage of a supercomputer for scientists. 4 | 5 | ​Therefore you've decided to organize things a bit by planning everybody’s tasks. The logic is simple: the higher the number of calculations which can be performed, the more people you can satisfy. 6 | Scientists give you the starting day of their calculation and the number of consecutive days they need to reserve the calculator. 7 | 8 | ## For example: 9 | 10 | Calculation Starting Day Duration 11 | A 2 5 12 | B 9 7 13 | C 15 6 14 | D 9 3 15 | 16 | * Calculation A starts on day 2 and ends on day 6 17 | * Calculation B starts on day 9 and ends on day 15 18 | * Calculation starts on day 15 and ends on day 20 19 | * Calculation D starts on day 9 and ends on day 11 20 | * In this example, 21 | * it’s not possible to carry out all the calculations because the periods for B and C overlap. 22 | * 3 calculations maximum can be carried out: A, D and C. . 23 | 24 | ## Input 25 | 26 | * **Line 1**: The number N of calculations 27 | * **The N following lines**: on each line, the starting day J and the duration D of reservation, separated by a blank space. 28 | 29 | ## Output 30 | 31 | The maximum number of calculations that can be carried out. 32 | 33 | ## Constraints 34 | 35 | * 0 < N < 100000 36 | * 0 < J < 1000000 37 | * 0 < D < 1000 38 | 39 | ## Examples 40 | 41 | Input 42 | 43 | 4 44 | 2 5 45 | 9 7 46 | 15 6 47 | 9 3 48 | 49 | Output 50 | 51 | 3 52 | 53 | 54 | Input 55 | 56 | 5 57 | 3 5 58 | 9 2 59 | 24 5 60 | 16 9 61 | 11 6 62 | 63 | Output 64 | 65 | 4 66 | 67 | ## Conditions 68 | 69 | * Available RAM: 512MB 70 | * Timeout: 1 seconds 71 | * The program has to read inputs from standard input 72 | * The program has to write the solution to standard output 73 | * The program must run in the test environment 74 | -------------------------------------------------------------------------------- /HARD/SUPER COMPUTER/python3/super-computer.py: -------------------------------------------------------------------------------- 1 | # based on https://github.com/aethersg/codingame-puzzle/blob/master/Python/hard/Super%20Computer.py 2 | import sys 3 | import math 4 | 5 | # Auto-generated code below aims at helping you parse 6 | # the standard input according to the problem statement. 7 | 8 | n = int(input()) 9 | array = [] 10 | last_date = 0 11 | for i in range(n): 12 | j, d = [int(j) for j in input().split()] 13 | array.append((j, j + d)) 14 | last_date = max(last_date, array[i][1]) 15 | 16 | array.sort(key=lambda a: a[1]) 17 | 18 | timeline = [0] * last_date 19 | answer = 0 20 | for a in array: 21 | if not 1 in timeline[a[0]:a[1]]: 22 | answer += 1 23 | timeline[a[0]:a[1]] = [1] * (a[1] - a[0]) 24 | 25 | print(answer) -------------------------------------------------------------------------------- /HARD/SURFACE/Readme.md: -------------------------------------------------------------------------------- 1 | # Surface 2 | 3 | "The wars of the 21st century will be fought over water." 4 | Although freshwater is available in limited quantity, it’s not actually scarce. There’s more than enough to satisfy the current needs of the global population, but only if it were possible to locate and measure the bodies of water available in a geographical area! 5 | 6 | ## Your mission 7 | 8 | Pinpoint the surface areas of water. You have a map which describes the contents of each square meter of a geographical zone. One square meter is composed of either land or water. 9 | 10 | Here’s an example of a map: 11 | 12 | ![Example map](img/Painter.png 'Example map') 13 | 14 | The green squares represent land, and the blue squares represent water. A lake is made up of a set of water squares which are horizontally or vertically adjacent. Two squares which are only diagonally adjacent are not part of the same lake. 15 | 16 | Your program receives as input a list of coordinates. For each one you must determine the surface area of the lake which is located there. If there is no lake, then the surface area equals 0. In this example, the lake which is located in coordinates (1, 2) has a surface area of 3 square meters. 17 | 18 | ## Map format 19 | 20 | A map in ASCII format is provided as input. The character # represents land and the letter O (uppercase) represents water. In this format, the map shown above will be represented as follows: 21 | 22 | #### 23 | ##O# 24 | #OO# 25 | #### 26 | 27 | One map can contain several bodies of water. 28 | ​ 29 | ## Input 30 | 31 | * **Line 1**: the width L of the map 32 | * **Line 2**: the height H of the map 33 | * **H following lines**: L characters # or O 34 | * **Following line**: the number N of coordinates to be tested 35 | * **N following lines**: the coordinates X Y to be tested, separated by a space 36 | 37 | ## Output 38 | 39 | * N lines, each displaying the surface area of the lake located at the coordinates given in input. 40 | 41 | ## Constraints 42 | 43 | * 0 < L < 10000 44 | * 0 < H < 10000 45 | * 0 <= X < L 46 | * 0 <= Y < H 47 | * 0 < N < 1000 48 | 49 | ## Example 50 | 51 | Input 52 | 53 | 4 54 | 4 55 | #### 56 | ##O# 57 | #OO# 58 | #### 59 | 3 60 | 0 0 61 | 1 2 62 | 2 1 63 | 64 | Output 65 | 66 | 0 67 | 3 68 | 3 69 | 70 | ## Conditions 71 | 72 | * Available RAM: 512MB 73 | * Timeout: 1 seconds 74 | * The program has to read inputs from standard input 75 | * The program has to write the solution to standard output 76 | * The program must run in the test environment -------------------------------------------------------------------------------- /HARD/SURFACE/img/Painter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/HARD/SURFACE/img/Painter.png -------------------------------------------------------------------------------- /HARD/SURFACE/python3/surface.py: -------------------------------------------------------------------------------- 1 | # adopted from https://github.com/JohnPrime/CodinGame/blob/master/Surface/Surface.py 2 | import sys 3 | import math 4 | 5 | # Auto-generated code below aims at helping you parse 6 | # the standard input according to the problem statement. 7 | 8 | l = int(input()) 9 | h = int(input()) 10 | 11 | 12 | def search(map, x, y): 13 | visit_map = [[False] * l for i in range(h)] 14 | 15 | list = [[x, y]] 16 | 17 | surface = 0 18 | 19 | while len(list) != 0: 20 | cell = list[len(list) - 1] 21 | list.pop() 22 | 23 | if visit_map[cell[1]][cell[0]] == False: 24 | visit_map[cell[1]][cell[0]] = True 25 | 26 | if map[cell[1]][cell[0]] == 'O': 27 | surface += 1 28 | 29 | if cell[0] > 0: 30 | if visit_map[cell[1]][cell[0] - 1] == False and map[cell[1]][cell[0] - 1] == 'O': 31 | list.append([cell[0] - 1, cell[1]]) 32 | if cell[0] < l - 1: 33 | if visit_map[cell[1]][cell[0] + 1] == False and map[cell[1]][cell[0] + 1] == 'O': 34 | list.append([cell[0] + 1, cell[1]]) 35 | if cell[1] > 0: 36 | if visit_map[cell[1] - 1][cell[0]] == False and map[cell[1] - 1][cell[0]] == 'O': 37 | list.append([cell[0], cell[1] - 1]) 38 | if cell[1] < h - 1: 39 | if visit_map[cell[1] + 1][cell[0]] == False and map[cell[1] + 1][cell[0]] == 'O': 40 | list.append([cell[0], cell[1] + 1]) 41 | 42 | return surface 43 | 44 | 45 | map = [] 46 | for i in range(h): 47 | row = input() 48 | map.append(row) 49 | 50 | n = int(input()) 51 | for i in range(n): 52 | x, y = [int(j) for j in input().split()] 53 | print(search(map, x, y)) -------------------------------------------------------------------------------- /HARD/TAN NETWORK/python3/tan-network.py: -------------------------------------------------------------------------------- 1 | # solution from https://github.com/DollarAkshay 2 | import sys 3 | import math 4 | import heapq 5 | 6 | class Heap(object): 7 | """ A neat min-heap wrapper which allows storing items by priority 8 | and get the lowest item out first (pop()). 9 | Also implements the iterator-methods, so can be used in a for 10 | loop, which will loop through all items in increasing priority order. 11 | Remember that accessing the items like this will iteratively call 12 | pop(), and hence empties the heap! """ 13 | 14 | def __init__(self): 15 | """ create a new min-heap. """ 16 | self._heap = [] 17 | 18 | def push(self, priority, item): 19 | """ Push an item with priority into the heap. 20 | Priority 0 is the highest, which means that such an item will 21 | be popped first.""" 22 | assert priority >= 0 23 | heapq.heappush(self._heap, (priority, item)) 24 | 25 | def pop(self): 26 | """ Returns the item with lowest priority. """ 27 | item = heapq.heappop(self._heap)[1] # (prio, item)[1] == item 28 | return item 29 | 30 | def __len__(self): 31 | return len(self._heap) 32 | 33 | def __iter__(self): 34 | """ Get all elements ordered by asc. priority. """ 35 | return self 36 | 37 | def next(self): 38 | """ Get all elements ordered by their priority (lowest first). """ 39 | try: 40 | return self.pop() 41 | except IndexError: 42 | raise StopIteration 43 | 44 | # Auto-generated code below aims at helping you parse 45 | # the standard input according to the problem statement. 46 | 47 | 48 | 49 | 50 | def distr(s1, s2): 51 | x = (stops[s2][2]-stops[s1][2])*math.cos( math.radians((stops[s1][1]+stops[s2][1])/2) ) 52 | y = (stops[s2][1]-stops[s1][1]) 53 | return math.sqrt(x*x+y*y)*6371 54 | 55 | stops = {} 56 | graph = {} 57 | dist = {} 58 | v = {} 59 | 60 | 61 | s = input() 62 | s=s[9:] 63 | e = input() 64 | e=e[9:] 65 | n = int(input()) 66 | 67 | for i in range(n): 68 | stop = input().split(",") 69 | stop[0] = stop[0][9:] 70 | stops[stop[0]] = [stop[1].strip("\""), float(stop[3]), float(stop[4])] 71 | dist[stop[0]] = 1000000000000 72 | v[stop[0]] = 0 73 | ##print(stops) 74 | 75 | m = int(input()) 76 | for i in range(m): 77 | s1,s2 = input().split(); 78 | s1=s1[9:] 79 | s2=s2[9:] 80 | if s1 not in graph: 81 | graph[s1] = [] 82 | graph[s1].append( [s2, distr(s1,s2)]) 83 | ##print(graph) 84 | 85 | 86 | parent = {} 87 | minheap = Heap() 88 | parent[s] = 'NULL' 89 | dist[s] = 0 90 | minheap.push(0, s) 91 | u = s 92 | 93 | pos = 1 94 | 95 | while u != e : 96 | v[u] = 1 97 | dest = graph[u] 98 | for i in dest: 99 | if v[i[0]] == 0 and dist[u]+i[1] < dist[i[0]]: 100 | parent[i[0]] = u 101 | dist[i[0]] = dist[u]+i[1] 102 | minheap.push(dist[i[0]], i[0]) 103 | if len(minheap)==0: 104 | pos=0 105 | break 106 | else: 107 | u = minheap.pop() 108 | 109 | if pos==1: 110 | revstops = [] 111 | while u!='NULL': 112 | revstops.append(stops[u][0]) 113 | u = parent[u] 114 | 115 | revstops = revstops[::-1] 116 | 117 | for i in revstops: 118 | print(i) 119 | else: 120 | print("IMPOSSIBLE") -------------------------------------------------------------------------------- /HARD/THE HUNGRY DUCK - PART 1/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/HARD/THE HUNGRY DUCK - PART 1/__init__.py -------------------------------------------------------------------------------- /HARD/THE HUNGRY DUCK - PART 1/php/the-hungry-duck---part-1.php: -------------------------------------------------------------------------------- 1 | =$W) 13 | $right = 0; 14 | else 15 | $right = get($x+1, $y); 16 | if($y+1>=$H) 17 | $down = 0; 18 | else 19 | $down = get($x, $y+1); 20 | $current+=$down>$right?$down:$right; 21 | return $current; 22 | } 23 | 24 | fscanf(STDIN, "%d %d", 25 | $W, 26 | $H 27 | ); 28 | $food = []; 29 | for ($i = 0; $i < $H; $i++) 30 | { 31 | $inputs = fgets(STDIN); 32 | $inputs = explode(" ",$inputs); 33 | $food[$i] = []; 34 | for ($j = 0; $j < $W; $j++) 35 | { 36 | $food[$i][$j] = intval($inputs[$j]); 37 | } 38 | } 39 | 40 | // Write an action using echo(). DON'T FORGET THE TRAILING \n 41 | // To debug (equivalent to var_dump): error_log(var_export($var, true)); 42 | 43 | echo(get()."\n"); -------------------------------------------------------------------------------- /HARD/THE HUNGRY DUCK - PART 1/python3/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/HARD/THE HUNGRY DUCK - PART 1/python3/__init__.py -------------------------------------------------------------------------------- /HARD/THE HUNGRY DUCK - PART 1/python3/the-hungry-duck---part-1.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import math 3 | 4 | 5 | def get(x=0, y=0): 6 | global food 7 | global w 8 | global h 9 | 10 | current = food[y][x] 11 | if x + 1 >= w: 12 | right = 0 13 | else: 14 | right = get(x + 1, y) 15 | if y + 1 >= h: 16 | down = 0 17 | else: 18 | down = get(x, y + 1) 19 | current += (right, down)[down > right] 20 | return current 21 | 22 | 23 | food = [] 24 | w, h = [int(i) for i in input().split()] 25 | for i in range(h): 26 | food.append([]) 27 | for j in input().split(): 28 | food[i].append(int(j)) 29 | print(food, file=sys.stderr) 30 | # Write an action using print 31 | # To debug: print("Debug messages...", file=sys.stderr) 32 | 33 | print(get()) -------------------------------------------------------------------------------- /HARD/THE HUNGRY DUCK - PART 2/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/HARD/THE HUNGRY DUCK - PART 2/__init__.py -------------------------------------------------------------------------------- /HARD/THE HUNGRY DUCK - PART 2/php/the-hungry-duck---part-2.php: -------------------------------------------------------------------------------- 1 | =$W) 15 | $right = 0; 16 | else 17 | $right = get($x+1, $y); 18 | if($y+1>=$H) 19 | $down = 0; 20 | else 21 | $down = get($x, $y+1); 22 | $current+=$down>$right?$down:$right; 23 | $visited[$x][$y] = $current; 24 | return $current; 25 | } 26 | $visited = []; 27 | fscanf(STDIN, "%d %d", 28 | $W, 29 | $H 30 | ); 31 | $food = []; 32 | for ($i = 0; $i < $H; $i++) 33 | { 34 | $inputs = fgets(STDIN); 35 | $inputs = explode(" ",$inputs); 36 | $food[$i] = []; 37 | for ($j = 0; $j < $W; $j++) 38 | { 39 | $food[$i][$j] = intval($inputs[$j]); 40 | } 41 | } 42 | 43 | // Write an action using echo(). DON'T FORGET THE TRAILING \n 44 | // To debug (equivalent to var_dump): error_log(var_export($var, true)); 45 | 46 | echo(get()."\n"); -------------------------------------------------------------------------------- /HARD/THE HUNGRY DUCK - PART 2/python3/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/HARD/THE HUNGRY DUCK - PART 2/python3/__init__.py -------------------------------------------------------------------------------- /HARD/THE HUNGRY DUCK - PART 2/python3/the-hungry-duck---part-2.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import math 3 | 4 | 5 | def get(x=0, y=0): 6 | global food 7 | global w 8 | global h 9 | global visited 10 | have = visited.get((x,y), False) 11 | if have: 12 | return have 13 | current = food[y][x] 14 | if x + 1 >= w: 15 | right = 0 16 | else: 17 | right = get(x + 1, y) 18 | if y + 1 >= h: 19 | down = 0 20 | else: 21 | down = get(x, y + 1) 22 | current += (right, down)[down > right] 23 | visited[(x,y)] = current 24 | return current 25 | 26 | visited = {} 27 | food = [] 28 | w, h = [int(i) for i in input().split()] 29 | for i in range(h): 30 | food.append([]) 31 | for j in input().split(): 32 | food[i].append(int(j)) 33 | print(food, file=sys.stderr) 34 | # Write an action using print 35 | # To debug: print("Debug messages...", file=sys.stderr) 36 | #print(1) 37 | print(get()) -------------------------------------------------------------------------------- /HARD/THE-GREATEST-NUMBER/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/HARD/THE-GREATEST-NUMBER/__init__.py -------------------------------------------------------------------------------- /HARD/THE-GREATEST-NUMBER/python3/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/HARD/THE-GREATEST-NUMBER/python3/__init__.py -------------------------------------------------------------------------------- /HARD/THE-GREATEST-NUMBER/python3/the-greatest-number.py: -------------------------------------------------------------------------------- 1 | # adapted from https://github.com/texus/codingame/blob/master/Community%20Puzzles/The%20greatest%20number.cs 2 | import sys 3 | n = int(input()) 4 | chars = input().split() 5 | chars.sort() 6 | if chars[-1] == "0": 7 | print(0, end='') 8 | exit(0) 9 | 10 | if chars[0] == "-": 11 | print('-', end='') 12 | if chars[1] == ".": 13 | print(chars[2], end='') 14 | print('.', end='') 15 | for i in range(3, len(chars)): 16 | print(chars[i], end='') 17 | else: 18 | index = 1 19 | while (chars[index] == "0"): 20 | index += 1; 21 | for i in range(index, len(chars)): 22 | print(chars[i], end='') 23 | else: 24 | if (chars[0] == "."): 25 | print(chars[-1], end='') 26 | for i in range(len(chars) - 2, 1, -1): 27 | print(chars[i], end='') 28 | if (chars[1] != "0"): 29 | print('.', end='') 30 | print(chars[1], end='') 31 | else: 32 | index = 1 33 | while (chars[index] == "0"): 34 | index += 1 35 | for i in range(len(chars), 0, -1): 36 | print(chars[i - 1], end='') 37 | -------------------------------------------------------------------------------- /HARD/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/HARD/__init__.py -------------------------------------------------------------------------------- /MACHINE LEARNING/python/deep-learning-tensorflow.py: -------------------------------------------------------------------------------- 1 | #Completely copy-pasted from link 2 | 3 | # MNIST For ML Beginners! 4 | 5 | # This tutorial is intended for readers who are new to both machine learning and TensorFlow. 6 | # Just like programming has Hello World, machine learning has MNIST. 7 | # MNIST is a simple computer vision dataset. It consists of images of handwritten digits. 8 | # Source: https://goo.gl/rLXVsR 9 | 10 | # Please help us to improve this section by sending us your 11 | # feedbacks and comments on: https://docs.google.com/forms/d/16fH20Qf8gJ2o31Vnlss2uLJ7wL9vq76TeUGqghTY0uI/viewform 12 | 13 | # Removing annoying warnings 14 | import os 15 | os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' 16 | 17 | # Importing input data 18 | import random 19 | import input_data 20 | mnist = input_data.read_data_sets(raw_input(), raw_input(), raw_input()) 21 | 22 | 23 | import tensorflow as tf 24 | ################################ 25 | # Enter your code between here # 26 | ################################ 27 | 28 | x = tf.placeholder(tf.float32, [None, 784]) 29 | W = tf.Variable(tf.zeros([784, 10])) 30 | b = tf.Variable(tf.zeros([10])) 31 | y = tf.nn.softmax(tf.matmul(x, W) + b)#y_ = tf.placeholder(tf.float32, [None, 1) 32 | y_ = tf.placeholder(tf.float32, [None, 10]) 33 | cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1]))#train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropytrain_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy) 34 | train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy) 35 | sess = tf.InteractiveSession() 36 | tf.global_variables_initializer().run() 37 | for _ in range(1000): 38 | batch_xs, batch_ys = mnist.train.next_batch(100) 39 | sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys}) 40 | #print ' '.join(map(str, [random.randint(0,9) for _ in range(len(mnist.validation.images))])) 41 | correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1)) 42 | accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32)) 43 | ######################## 44 | # And here # 45 | ######################## 46 | #print(sess.run(accuracy, feed_dict={x: mnist.test.images, y_: mnist.test.labels})) 47 | 48 | # Uncomment to get a prediction number for each image 49 | 50 | result = sess.run(tf.argmax(y,1), feed_dict={x: mnist.validation.images}) 51 | print ' '.join(map(str, result)) -------------------------------------------------------------------------------- /MEDIUM/BENDER - EPISODE 1/img/bender1-small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/MEDIUM/BENDER - EPISODE 1/img/bender1-small.png -------------------------------------------------------------------------------- /MEDIUM/BENDER - EPISODE 1/img/bender2-small.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/MEDIUM/BENDER - EPISODE 1/img/bender2-small.jpg -------------------------------------------------------------------------------- /MEDIUM/CONWAY SEQUENCE/Readme.md: -------------------------------------------------------------------------------- 1 | # Conway Sequence 2 | 3 | 1 4 | 1 1 5 | 2 1 6 | 1 2 1 1 7 | 1 1 1 2 2 1 8 | 3 1 2 2 1 1 9 | ... 10 | 11 | Warning! This sequence can make you ill. The reasoning is simple but unusual: Read a line aloud whilst looking at the line above and you will notice that each line (except the first) makes ​​an inventory of the previous line. 12 | 13 | Line 3 shows ``2 1`` because the line 2 contains two ``1``, one after the other. 14 | Line 4 displays ``1 2 1 1`` because the line 3 contains a one ``2`` followed by a one ``1``. 15 | Line 5 displays ``1 1 1 2 2 1`` because the line ``4`` contains a one ``1`` followed by a one ``2`` followed by a two ``1``. 16 | 17 | This sequence refers to a technique used to encode ranges in order to compress identical values ​​without losing any information. This type of method is used, amongst others, to compress images. 18 | 19 | Your mission is to write a program that will display the line L of this series on the basis of an original number R (R vaut 1 in our example). 20 | 21 | ## Input 22 | 23 | * **Line 1**: The original number R of the sequence. 24 | * **Line 2**: The line L to display. The index of the first line is 1. 25 | 26 | ## Output 27 | 28 | The line L of the sequence. Each element of the sequence is separated by a blank space. 29 | 30 | ## Constraints 31 | 32 | * 0 < R < 100 33 | * 0 < L ≤ 25 34 | 35 | ## Example 36 | 37 | Input 38 | 39 | 1 40 | 6 41 | 42 | Output 43 | 44 | 3 1 2 2 1 1 45 | 46 | ## Conditions 47 | 48 | * Available RAM: 512MB 49 | * Timeout: 1 seconds 50 | * The program has to read inputs from standard input 51 | * The program has to write the solution to standard output 52 | * The program must run in the test environment -------------------------------------------------------------------------------- /MEDIUM/CONWAY SEQUENCE/php/conway-sequence.php: -------------------------------------------------------------------------------- 1 | abs(floor - cpos): 30 | closest = abs(floor - cpos) 31 | pos = floor 32 | return pos 33 | 34 | def __init__(self): 35 | self.nb_floors, self.width, self.nb_rounds, self.exit_floor, self.exit_pos, self.nb_total_clones, self.nb_additional_elevators, nb_elevators = [ 36 | int(i) for i in input().split()] 37 | for i in range(nb_elevators): 38 | # elevator_floor: floor on which this elevator is found 39 | # elevator_pos: position of the elevator on its floor 40 | elevator_floor, elevator_pos = [int(j) for j in input().split()] 41 | self.elevator_coors.setdefault(elevator_floor, []).append(elevator_pos) 42 | 43 | 44 | class Act: 45 | clone = LeadClone() 46 | area = Area() 47 | wait_need = 0 48 | 49 | def needDirection(self): 50 | need_position = self.area.isExitHere(self.clone.clone_floor) 51 | if need_position != None: 52 | if (need_position < self.clone.clone_pos): 53 | return "LEFT" 54 | elif (need_position > self.clone.clone_pos): 55 | return "RIGHT" 56 | else: 57 | floor_coor = self.area.getClosest(self.clone.clone_floor, self.clone.clone_pos) 58 | if (floor_coor < self.clone.clone_pos): 59 | return "LEFT" 60 | elif (floor_coor > self.clone.clone_pos): 61 | return "RIGHT" 62 | return "STOP" 63 | 64 | def run(self): 65 | self.clone.getParams() 66 | 67 | if self.wait_need > 0: 68 | self.wait_need = self.wait_need - 1 69 | print("WAIT") 70 | else: 71 | need_dir = self.needDirection() 72 | if need_dir == "STOP": 73 | self.wait_need = 1 74 | print("WAIT") 75 | elif self.clone.direction in ['LEFT', 'RIGHT'] and self.clone.direction != need_dir: 76 | print("BLOCK") 77 | self.wait_need = 3 78 | else: 79 | print("WAIT") 80 | 81 | 82 | act = Act() 83 | while True: 84 | act.run() 85 | 86 | -------------------------------------------------------------------------------- /MEDIUM/DWARFS STANDING ON THE SHOULDERS OF GIANTS/Readme.md: -------------------------------------------------------------------------------- 1 | # Dwarfs standing on the shoulders of giants 2 | 3 | The saying "_Dwarfs standing on the shoulders of giants_" refers to the importance of being able to build upon the work of our predecessors. 4 | 5 | When we read texts, we often only get a small glance of this dependence: this person influenced that person. Thereafter, we learn that the second person, in turn influenced a third and so on. In this exercise we’re interested in the chain of influence and more precisely in finding the longest possible chain. 6 | ​ 7 | We choose to represent each person by a distinct integer. If person #1 has influenced persons #2 and #3 and person #3 has influenced #4 then there is a succession of thoughts between #1, #3 and #4. In this case, it’s the longest succession and the expected result will be 3, since it involves 3 people. 8 | 9 | ![DG1](img/dg1.png 'DG1') 10 | 11 | If we were to complete this example when we learn that person #2 also influenced persons #4 and #5, then the longest succession will still have a length of 3, but there will now be several of them. 12 | 13 | ![DG2](img/dg2.png 'DG2') 14 | 15 | If we now add that person #10 influenced person #11, the result remains 3. However, as soon as we learn that #10 also influenced #1 and #3, then the result becomes 4, since there is now a succession involving 4 people, which is #10, #1, #2, #5. 16 | 17 | ![DG3](img/dg3.png 'DG3') 18 | 19 | It takes time for a thought to influence others. So, we will suppose that it is not possible to have a mutual influence between people, i.e. If A influences B (even indirectly through other people), then B will not influence A (even indirectly). Also, you can not influence yourself. 20 | 21 | ## Input 22 | 23 | * **Line 1**: The number N of relationships of influence. 24 | * **N following lines**: a relationship of influence between two people in the form of X (whitespace) Y, which indicates that X influence Y. The relationships of influence are listed in any order. 25 | 26 | ## Output 27 | 28 | * The number of people involved in the longest succession of influences. 29 | 30 | ## Constraints 31 | 32 | * 0 < N < 10000 33 | * 0 < X,Y < 10000 34 | 35 | ## Examples 36 | 37 | #### Example #1 38 | 39 | Input 40 | 41 | 3 42 | 1 2 43 | 1 3 44 | 3 4 45 | 46 | Output 47 | 48 | 3 49 | 50 | ![DG4](img/dg4.png 'DG4') 51 | 52 | #### Example #2 53 | 54 | Input 55 | 56 | 8 57 | 1 2 58 | 1 3 59 | 3 4 60 | 2 4 61 | 2 5 62 | 10 11 63 | 10 1 64 | 10 3 65 | 66 | Output 67 | 68 | 4 69 | 70 | ![DG5](img/dg5.png 'DG5') 71 | 72 | #### Example #3 73 | 74 | Input 75 | 76 | 4 77 | 2 3 78 | 8 9 79 | 1 2 80 | 6 3 81 | 82 | Output 83 | 84 | 3 85 | 86 | ## Conditions 87 | 88 | * Available RAM: 512MB 89 | * Timeout: 1 seconds 90 | * The program has to read inputs from standard input 91 | * The program has to write the solution to standard output 92 | * The program must run in the test environment -------------------------------------------------------------------------------- /MEDIUM/DWARFS STANDING ON THE SHOULDERS OF GIANTS/img/dg1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/MEDIUM/DWARFS STANDING ON THE SHOULDERS OF GIANTS/img/dg1.png -------------------------------------------------------------------------------- /MEDIUM/DWARFS STANDING ON THE SHOULDERS OF GIANTS/img/dg2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/MEDIUM/DWARFS STANDING ON THE SHOULDERS OF GIANTS/img/dg2.png -------------------------------------------------------------------------------- /MEDIUM/DWARFS STANDING ON THE SHOULDERS OF GIANTS/img/dg3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/MEDIUM/DWARFS STANDING ON THE SHOULDERS OF GIANTS/img/dg3.png -------------------------------------------------------------------------------- /MEDIUM/DWARFS STANDING ON THE SHOULDERS OF GIANTS/img/dg4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/MEDIUM/DWARFS STANDING ON THE SHOULDERS OF GIANTS/img/dg4.png -------------------------------------------------------------------------------- /MEDIUM/DWARFS STANDING ON THE SHOULDERS OF GIANTS/img/dg5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/MEDIUM/DWARFS STANDING ON THE SHOULDERS OF GIANTS/img/dg5.png -------------------------------------------------------------------------------- /MEDIUM/DWARFS STANDING ON THE SHOULDERS OF GIANTS/python3/dwarfs-standing-on-the-shoulders-of-giants.py: -------------------------------------------------------------------------------- 1 | # https://www.codingame.com/ide/puzzle/dwarfs-standing-on-the-shoulders-of-giants 2 | connection = {} 3 | 4 | 5 | def letsCount(number): 6 | global connection 7 | max = 0 8 | get_array = connection.get(number, []) 9 | if len(get_array) == 0: 10 | return 0 11 | else: 12 | for item in get_array: 13 | temp = letsCount(item) 14 | if max < temp: 15 | max = temp 16 | return max + 1 17 | 18 | 19 | n = int(input()) # the number of relationships of influence 20 | for i in range(n): 21 | # x: a relationship of influence between two people (x influences y) 22 | x, y = [int(j) for j in input().split()] 23 | connection.setdefault(x, []).append(y) 24 | max = 0 25 | for item in connection: 26 | temp = letsCount(item) 27 | if max < temp: 28 | max = temp 29 | 30 | # The number of people involved in the longest succession of influences 31 | print(max + 1) 32 | -------------------------------------------------------------------------------- /MEDIUM/GAME OF LIFE/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/MEDIUM/GAME OF LIFE/__init__.py -------------------------------------------------------------------------------- /MEDIUM/GAME OF LIFE/python3/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/MEDIUM/GAME OF LIFE/python3/__init__.py -------------------------------------------------------------------------------- /MEDIUM/GAME OF LIFE/python3/game-of-life.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import math 3 | 4 | # Auto-generated code below aims at helping you parse 5 | # the standard input according to the problem statement. 6 | def count(r, c): 7 | global map1 8 | global width 9 | global height 10 | array = [ 11 | [-1, -1], [-1, 0], [-1, 1], 12 | [ 0, -1], [ 0, 1], 13 | [ 1, -1], [ 1, 0], [1, 1]] 14 | count = 0 15 | for item in array: 16 | rn = item[0] + r 17 | cn = item[1] + c 18 | # print(rn, cn, file=sys.stderr) 19 | if rn >= 0 and cn >= 0 and rn < height and cn < width: 20 | print(rn, cn, map1[rn][cn], file=sys.stderr) 21 | if map1[rn][cn] == '1': 22 | count += 1 23 | return count 24 | 25 | 26 | width, height = [int(i) for i in input().split()] 27 | map1 = [] 28 | map2 = [] 29 | for i in range(height): 30 | line = input() 31 | map1.append(list(line)) 32 | # print(map1, file=sys.stderr) 33 | for r in range(height): 34 | map2.append([]) 35 | for c in range(width): 36 | cnt = count(r, c) 37 | # print('cnt: '+ str(cnt), file=sys.stderr) 38 | if map1[r][c] == '1': 39 | if cnt < 2 or cnt > 3: 40 | map2[r].append('0') 41 | else: 42 | map2[r].append('1') 43 | else: 44 | if cnt == 3: 45 | map2[r].append('1') 46 | else: 47 | map2[r].append('0') 48 | print("".join(map2[r])) 49 | print(map2, file=sys.stderr) 50 | # Write an action using print 51 | # To debug: print("Debug messages...", file=sys.stderr) 52 | 53 | # print("answer") 54 | -------------------------------------------------------------------------------- /MEDIUM/MAYAN CALCULATION/python3/mayan-calculation.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import math 3 | import copy 4 | 5 | SYSTEM_SS = 20 6 | 7 | 8 | class CalculateMaya: 9 | numerals = {} 10 | num_1line = {} 11 | num_2line = {} 12 | operation = None 13 | 14 | def __init__(self): 15 | l, h = [int(i) for i in input().split()] 16 | self.numerals = {i: list() for i in range(SYSTEM_SS)} 17 | for i in range(h): 18 | numeral = input() 19 | for j in range(0, len(numeral), l): 20 | self.numerals[int(j / l)].append(numeral[j:j + l]) 21 | 22 | s1 = int(input()) 23 | self.num_1line = {i: list() for i in range(int(s1 / h))} 24 | for i in range(s1): 25 | self.num_1line[math.floor((s1 - i - 1) / h)].append(input()) 26 | s2 = int(input()) 27 | self.num_2line = {i: list() for i in range(int(s2 / h))} 28 | for i in range(s2): 29 | self.num_2line[math.floor((s2 - i - 1) / h)].append(input()) 30 | self.operation = input() 31 | 32 | def calculate(self): 33 | num1 = num2 = 0 34 | for key, value in self.num_1line.items(): 35 | num1 += self.get_numeral(value) * (20 ** key) 36 | for key, value in self.num_2line.items(): 37 | num2 += self.get_numeral(value) * (20 ** key) 38 | result = int(self._make_operation(num1, num2)) 39 | self._out(result) 40 | 41 | def _make_operation(self, num1, num2): 42 | if self.operation == "+": 43 | return num1 + num2 44 | elif self.operation == "*": 45 | return num1 * num2 46 | elif self.operation == "-": 47 | return num1 - num2 48 | elif self.operation == "/": 49 | return math.ceil(num1 / num2) 50 | 51 | def get_numeral(self, value0): 52 | for key, value in self.numerals.items(): 53 | if value == value0: 54 | return key 55 | return Exception('HiThere') 56 | 57 | def get_ASCII(self, key0): 58 | for key, ascii in self.numerals.items(): 59 | if key == key0: 60 | return copy.copy(ascii) 61 | raise Exception('HiThere') 62 | 63 | def _out(self, result): 64 | temp_array = [] 65 | result_20 = [] 66 | if result > 0: 67 | while result > 0: 68 | num = result % 20 69 | result_20.append(num) 70 | result = math.floor(result / 20) 71 | temp = self.get_ASCII(num) 72 | temp.extend(temp_array) 73 | temp_array = temp 74 | else: 75 | temp_array = self.get_ASCII(0) 76 | 77 | i = 0 78 | for item in temp_array: 79 | i += 1 80 | print("{0}".format(item)) 81 | calc = CalculateMaya() 82 | calc.calculate() 83 | 84 | 85 | -------------------------------------------------------------------------------- /MEDIUM/NETWORK CABLING/Readme.md: -------------------------------------------------------------------------------- 1 | # Network Cabling 2 | 3 | An internet operator plans to connect a business park to the optical fiber network. The area to be covered is large and the operator is asking you to write a program that will calculate the minimum length of fiber optic cable required to connect all buildings. 4 | 5 | For the implementation of the works, the operator has technical constraints whereby it is forced to proceed in the following manner: 6 | A main cable will cross through the park from the West to the East (from the position x of the most westerly building to the position x of the most easterly building). 7 | For each building, a dedicated cable will connect from the building to the main cable by a minimal path (North or South), as shown in Fig. 1. 8 | 9 | ![Fig. 1](img/img/fig1.png 'Fig. 1') 10 | 11 | _In this example, the green line represents the cables._ 12 | 13 | The minimum length with therefore depend on the position of the main cable. 14 | 15 | ## Input 16 | 17 | * **Line 1**: The number N de bâtiments à relier à la fibre optique 18 | * **On the N following lines**: The coordinates x and y of the buildings 19 | 20 | ## Output 21 | 22 | The minimum length L of cable required to connect all of the buildings. In other words, the length of the main cable plus the length of the cables dedicated to all the buildings. 23 | The buildings with the same position x should not in any case share the same dedicated cable. 24 | 25 | ## Constraints 26 | 27 | * 0 < N ≤ 100000 28 | * 0 ≤ L ≤ 263 29 | * -230 ≤ x ≤ 230 30 | * -230 ≤ y ≤ 230 31 | 32 | ## Examples 33 | 34 | #### Example #1 35 | 36 | Input 37 | 38 | 3 39 | 0 0 40 | 1 1 41 | 2 2 42 | 43 | Output 44 | 45 | 4 46 | 47 | ![Example #1](img/img/example.png 'Example #1') 48 | 49 | #### Example #2 50 | 51 | Input 52 | 53 | 3 54 | 1 2 55 | 0 0 56 | 2 2 57 | 58 | Output 59 | 60 | 4 61 | 62 | ![Example #2](img/img/example2.png 'Example #2') 63 | 64 | ## Conditions 65 | 66 | * Available RAM: 512MB 67 | * Timeout: 1 seconds 68 | * The program has to read inputs from standard input 69 | * The program has to write the solution to standard output 70 | * The program must run in the test environment -------------------------------------------------------------------------------- /MEDIUM/NETWORK CABLING/img/img/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/MEDIUM/NETWORK CABLING/img/img/example.png -------------------------------------------------------------------------------- /MEDIUM/NETWORK CABLING/img/img/example2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/MEDIUM/NETWORK CABLING/img/img/example2.png -------------------------------------------------------------------------------- /MEDIUM/NETWORK CABLING/img/img/fig1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/MEDIUM/NETWORK CABLING/img/img/fig1.png -------------------------------------------------------------------------------- /MEDIUM/NETWORK CABLING/python3/network-cabling.py: -------------------------------------------------------------------------------- 1 | # FROM HERE https://github.com/kpbochenek/algorithms/blob/master/codingame/medium/network-cabling.py 2 | N = int(input()) 3 | housesX = [] 4 | housesY = [] 5 | for i in range(N): 6 | X, Y = [int(i) for i in input().split()] 7 | housesX.append(X) 8 | housesY.append(Y) 9 | 10 | housesY.sort() 11 | meanlow = housesY[len(housesY)//2] 12 | meanhigh = housesY[len(housesY)//2+1] if len(housesY) > 1 else housesY[0] 13 | 14 | lowest = min(housesX) 15 | highest = max(housesX) 16 | result1 = sum(map(lambda y: abs(meanlow - y), housesY)) 17 | result2 = sum(map(lambda y: abs(meanhigh - y), housesY)) 18 | 19 | print(min(result1, result2) + highest - lowest) -------------------------------------------------------------------------------- /MEDIUM/SCRABBLE/Readme.md: -------------------------------------------------------------------------------- 1 | #Scrabble 2 | 3 | When playing Scrabble©, each player draws 7 letters and must find a word that scores the most points using these letters. 4 | 5 | A player doesn't necessarily have to make a 7-letter word; the word can be shorter. The only constraint is that the word must be made using the 7 letters which the player has drawn. 6 | 7 | _For example, with the letters etaenhs, some possible words are: ethane, hates, sane, ant._ 8 | 9 | ## Letter Scoring 10 | 11 | In Scrabble©, each letter is weighted with a score depending on how difficult it is to place that letter in a word. You will see below a table showing the points corresponding to each letter: 12 | 13 | ### Letters Points 14 | 15 | * **1**: e, a, i, o, n, r, t, l, s, u 16 | * **2**: d, g 17 | * **3**: b, c, m, p 18 | * **4**: f, h, v, w, y 19 | * **5**: k 20 | * **8**: j, x 21 | * **10**: q, z 22 | 23 | _The word banjo earns 3 + 1 + 1 + 8 + 1 = 14 points._ 24 | 25 | A dictionary of authorized words is provided as input for the program. The program must find the word in the dictionary which wins the most points for the seven given letters. If two words win the same number of points, then the word which appears first in the order of the given dictionary should be chosen. 26 | 27 | All words will only be composed of alphabetical characters in lower case. There will always be at least one possible word. 28 | 29 | ## Input 30 | 31 | * **Line 1**: The number N of words in the dictionary 32 | * **N following lines**: The words in the dictionary. One word per line. 33 | * **Last line**: The 7 letters available. 34 | 35 | ## Output 36 | 37 | The word that scores the most points using the available letters (1 to 7 letters). The word must belong to the dictionnary. There is always a solution. 38 | 39 | ## Constraints 40 | 41 | * 0 < N < 100000 42 | * Words in the dictionary have a maximum length of 30 characters. 43 | 44 | ## Example 45 | 46 | Input 47 | 48 | 5 49 | because 50 | first 51 | these 52 | could 53 | which 54 | hicquwh 55 | 56 | Output 57 | 58 | which 59 | 60 | ## Conditions 61 | 62 | * Available RAM : 512MB 63 | * Timeout: 1 seconds 64 | * The program has to read inputs from standard input 65 | * The program has to write the solution to standard output 66 | * The program must run in the test environment 67 | -------------------------------------------------------------------------------- /MEDIUM/SCRABBLE/python/scrabble.py: -------------------------------------------------------------------------------- 1 | # https://www.codingame.com/ide/puzzle/scrabble 2 | values = { 3 | 'e':1, 'a':1, 'i':1, 'o':1, 'n':1, 'r':1, 't':1, 'l':1, 's':1, 'u':1, 4 | 'd':2, 'g':2, 5 | 'b':3, 'c':3, 'm':3, 'p':3, 6 | 'f':4, 'h':4, 'v':4, 'w':4, 'y':4, 7 | 'k':5, 8 | 'j':6, 'x':6, 9 | 'q':7, 'z':7 10 | } 11 | words = [] 12 | n = int(raw_input()) 13 | for i in range(n): 14 | w = raw_input() 15 | words.append(w) 16 | letters = raw_input() 17 | max, winword = 0, '' 18 | for word in words: 19 | temp = 0 20 | temp_letters = list(letters) 21 | for letter in word: 22 | if (letter in temp_letters): 23 | temp+=values[letter] 24 | try: 25 | temp_letters.remove(letter) 26 | except ValueError: 27 | temp = -1 28 | break 29 | else: 30 | temp = -1 31 | break 32 | if temp>max: 33 | max = temp 34 | winword = word 35 | print(winword) -------------------------------------------------------------------------------- /MEDIUM/SCRABBLE/python3/scrabble.py: -------------------------------------------------------------------------------- 1 | # https://www.codingame.com/ide/puzzle/scrabble 2 | values = { 3 | 'e':1, 'a':1, 'i':1, 'o':1, 'n':1, 'r':1, 't':1, 'l':1, 's':1, 'u':1, 4 | 'd':2, 'g':2, 5 | 'b':3, 'c':3, 'm':3, 'p':3, 6 | 'f':4, 'h':4, 'v':4, 'w':4, 'y':4, 7 | 'k':5, 8 | 'j':6, 'x':6, 9 | 'q':7, 'z':7 10 | } 11 | words = [] 12 | n = int(input()) 13 | for i in range(n): 14 | w = input() 15 | words.append(w) 16 | letters = input() 17 | max, winword = 0, '' 18 | for word in words: 19 | temp = 0 20 | temp_letters = list(letters) 21 | for letter in word: 22 | if (letter in temp_letters): 23 | temp+=values[letter] 24 | try: 25 | temp_letters.remove(letter) 26 | except ValueError: 27 | temp = -1 28 | break 29 | else: 30 | temp = -1 31 | break 32 | if temp>max: 33 | max = temp 34 | winword = word 35 | print(winword) 36 | -------------------------------------------------------------------------------- /MEDIUM/SHADOW OF THE KNIGHT - EPISODE 1/php/shadows-of-the-knight-episode-1.php: -------------------------------------------------------------------------------- 1 | -1: 16 | maxy = y0 - 1 17 | elif bomb_dir.find("D")>-1: 18 | miny = y0 + 1 19 | if bomb_dir.find("L")>-1: 20 | maxx = x0 - 1 21 | elif bomb_dir.find("R")>-1: 22 | minx =x0 + 1 23 | x0 = minx + math.ceil((maxx - minx)/2) 24 | y0 = miny + math.ceil((maxy - miny)/2) 25 | # the location of the next window Batman should jump to. 26 | print("{0} {1}".format(int(x0), int(y0))) 27 | -------------------------------------------------------------------------------- /MEDIUM/SHADOW OF THE KNIGHT - EPISODE 1/python3/shadows-of-the-knight-episode-1.py: -------------------------------------------------------------------------------- 1 | # https://www.codingame.com/ide/puzzle/shadows-of-the-knight-episode-1 2 | import sys 3 | import math 4 | # w: width of the building. 5 | # h: height of the building. 6 | w, h = [int(i) for i in input().split()] 7 | n = int(input()) # maximum number of turns before game over. 8 | x0, y0 = [int(i) for i in input().split()] 9 | minx = miny = 0 10 | maxx = w - 1 11 | maxy = h - 1 12 | 13 | while True: 14 | bomb_dir = input() # the direction of the bombs from batman's current location (U, UR, R, DR, D, DL, L or UL) 15 | if bomb_dir.find("U")>-1: 16 | maxy = y0 - 1 17 | elif bomb_dir.find("D")>-1: 18 | miny = y0 + 1 19 | if bomb_dir.find("L")>-1: 20 | maxx = x0 - 1 21 | elif bomb_dir.find("R")>-1: 22 | minx =x0 + 1 23 | x0 = minx + math.ceil((maxx - minx)/2) 24 | y0 = miny + math.ceil((maxy - miny)/2) 25 | # the location of the next window Batman should jump to. 26 | print("{0} {1}".format(x0, y0)) 27 | -------------------------------------------------------------------------------- /MEDIUM/SKYNET REVOLUTION - EPISODE 1/img/Skynet1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/MEDIUM/SKYNET REVOLUTION - EPISODE 1/img/Skynet1.jpg -------------------------------------------------------------------------------- /MEDIUM/SKYNET REVOLUTION - EPISODE 1/img/Skynet1_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/MEDIUM/SKYNET REVOLUTION - EPISODE 1/img/Skynet1_2.jpg -------------------------------------------------------------------------------- /MEDIUM/SKYNET REVOLUTION - EPISODE 1/img/Skynet1_3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/MEDIUM/SKYNET REVOLUTION - EPISODE 1/img/Skynet1_3.jpg -------------------------------------------------------------------------------- /MEDIUM/SKYNET REVOLUTION - EPISODE 1/img/Skynet1_4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/MEDIUM/SKYNET REVOLUTION - EPISODE 1/img/Skynet1_4.jpg -------------------------------------------------------------------------------- /MEDIUM/SKYNET REVOLUTION - EPISODE 1/img/terminator_bike.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/MEDIUM/SKYNET REVOLUTION - EPISODE 1/img/terminator_bike.png -------------------------------------------------------------------------------- /MEDIUM/SKYNET REVOLUTION - EPISODE 1/python/skynet-revolution-episode-1.py: -------------------------------------------------------------------------------- 1 | #https://www.codingame.com/ide/puzzle/skynet-revolution-episode-1 2 | def getBestBloker(si, gat): 3 | global relations 4 | for g in gat: 5 | if g in relations[si]: 6 | return [si, g] 7 | for g in gat: 8 | if len(relations[g]) > 0: 9 | return [g, relations[g][0]] 10 | return [0, 0] 11 | 12 | 13 | def unsetter(c1, c2): 14 | global relations 15 | relations[c1].remove(c2) 16 | relations[c2].remove(c1) 17 | 18 | 19 | n, l, e = [int(i) for i in input().split()] 20 | gat = [] 21 | relations = {} 22 | for i in range(l): 23 | n1, n2 = [int(j) for j in input().split()] 24 | relations.setdefault(n1, []).append(n2) 25 | relations.setdefault(n2, []).append(n1) 26 | for i in range(e): 27 | ei = int(input()) 28 | gat.append(ei) 29 | # game loop 30 | while True: 31 | si = int(input()) 32 | c1, c2 = getBestBloker(si, gat) 33 | unsetter(c1, c2) 34 | print("{0} {1}".format(c1, c2)) 35 | -------------------------------------------------------------------------------- /MEDIUM/SKYNET REVOLUTION - EPISODE 1/python3/skynet-revolution-episode-1.py: -------------------------------------------------------------------------------- 1 | #https://www.codingame.com/ide/puzzle/skynet-revolution-episode-1 2 | # n: the total number of nodes in the level, including the gateways 3 | # l: the number of links 4 | # e: the number of exit gateways 5 | 6 | def getBestBloker(si, gat): 7 | global relations 8 | for g in gat: 9 | if g in relations[si]: 10 | return [si, g] 11 | for g in gat: 12 | if len(relations[g]) > 0: 13 | return [g, relations[g][0]] 14 | return [0, 0] 15 | 16 | 17 | def unsetter(c1, c2): 18 | global relations 19 | relations[c1].remove(c2) 20 | relations[c2].remove(c1) 21 | 22 | 23 | n, l, e = [int(i) for i in input().split()] 24 | gat = [] 25 | relations = {} 26 | for i in range(l): 27 | # n1: N1 and N2 defines a link between these nodes 28 | n1, n2 = [int(j) for j in input().split()] 29 | relations.setdefault(n1, []).append(n2) 30 | relations.setdefault(n2, []).append(n1) 31 | for i in range(e): 32 | ei = int(input()) # the index of a gateway node 33 | gat.append(ei) 34 | # game loop 35 | while True: 36 | si = int(input()) # The index of the node on which the Skynet agent is positioned this turn 37 | c1, c2 = getBestBloker(si, gat) 38 | unsetter(c1, c2) 39 | # Example: 0 1 are the indices of the nodes you wish to sever the link between 40 | print("{0} {1}".format(c1, c2)) 41 | -------------------------------------------------------------------------------- /MEDIUM/STOCK EXCHANGE LOSSES/Readme.md: -------------------------------------------------------------------------------- 1 | # Stock Exchange Losses 2 | 3 | ![Stock Exchange Losses](img/stock_exchange_losses.jpg 'Stock Exchange Losses') 4 | 5 | A finance company is carrying out a study on the worst stock investments and would like to acquire a program to do so. The program must be able to analyze a chronological series of stock values in order to show the largest loss that it is possible to make by buying a share at a given time _t0_ and by selling it at a later date _t1_. The loss will be expressed as the difference in value between _t0_ and _t1_. If there is no loss, the loss will be worth _0_. 6 | 7 | ## Input 8 | 9 | * **Line 1**: the number n of stock values available. 10 | * **Line 2**: the stock values arranged in order, from the date of their introduction on the stock market v1 until the last known value vn. The values are integers. 11 | 12 | ## Output 13 | 14 | The maximal loss _p_, expressed negatively if there is a loss, otherwise _0_. 15 | 16 | ## Constraints 17 | 18 | * 0 < n < 100000 19 | * 0 < v < 231 20 | 21 | ## Examples 22 | 23 | ### Example 1 24 | 25 | Input 26 | 27 | 6 28 | 3 2 4 2 1 5 29 | 30 | Output 31 | 32 | -3 33 | 34 | ![Perte 1](img/perte1.png 'Perte 1') 35 | 36 | ### Example 2 37 | 38 | Input 39 | 40 | 6 41 | 5 3 4 2 3 1 42 | 43 | Output 44 | 45 | -4 46 | 47 | ![Perte 2](img/perte2.png 'Perte 2') 48 | 49 | ### Example 3 50 | 51 | Input 52 | 53 | 5 54 | 1 2 4 4 5 55 | 56 | Output 57 | 58 | 0 59 | 60 | ![Profit](img/profit.png 'Profit') 61 | 62 | ## Conditions 63 | 64 | * Available RAM: 512MB 65 | * Timeout: 1 seconds 66 | * The program has to read inputs from standard input 67 | * The program has to write the solution to standard output 68 | * The program must run in the test environment -------------------------------------------------------------------------------- /MEDIUM/STOCK EXCHANGE LOSSES/img/perte1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/MEDIUM/STOCK EXCHANGE LOSSES/img/perte1.png -------------------------------------------------------------------------------- /MEDIUM/STOCK EXCHANGE LOSSES/img/perte2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/MEDIUM/STOCK EXCHANGE LOSSES/img/perte2.png -------------------------------------------------------------------------------- /MEDIUM/STOCK EXCHANGE LOSSES/img/profit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/MEDIUM/STOCK EXCHANGE LOSSES/img/profit.png -------------------------------------------------------------------------------- /MEDIUM/STOCK EXCHANGE LOSSES/img/stock_exchange_losses.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/MEDIUM/STOCK EXCHANGE LOSSES/img/stock_exchange_losses.jpg -------------------------------------------------------------------------------- /MEDIUM/STOCK EXCHANGE LOSSES/python3/stock-exchange-losses.py: -------------------------------------------------------------------------------- 1 | # https://www.codingame.com/training/medium/stock-exchange-losses 2 | diff = 0 3 | graf = [] 4 | n = int(input()) 5 | for i in input().split(): 6 | graf.append(int(i)) 7 | for i in range(n - 1): 8 | for j in range(i + 1, n): 9 | if graf[i] < graf[j]: 10 | i = j 11 | break 12 | elif diff < graf[i] - graf[j]: 13 | diff = graf[i] - graf[j] 14 | 15 | if diff != 0: 16 | print("-" + str(diff)) 17 | else: 18 | print("0") 19 | -------------------------------------------------------------------------------- /MEDIUM/TEADS SPONSORED CONTEST/python3/teads-sponsored-contest-100-percent.py: -------------------------------------------------------------------------------- 1 | # from here http://codegists.com/snippet/python/teads-sponsored-contestpy_workofartiz_python 2 | from collections import defaultdict 3 | 4 | edges = defaultdict(list) 5 | for i in range(int(input())): 6 | xi, yi = [int(j) for j in input().split()] 7 | edges[xi].append(yi) 8 | edges[yi].append(xi) 9 | 10 | 11 | # calculates the maximum depth (not going back) 12 | def max_depth(came_from, node): 13 | # if leaf node 14 | if len(edges[node]) == 1: 15 | return 0 16 | 17 | depth = 0 18 | 19 | for child in edges[node]: 20 | if came_from == child: 21 | continue 22 | depth = max(depth, 1 + max_depth(node, child)) 23 | 24 | return depth 25 | 26 | 27 | # pick just any node to be the root of the tree 28 | root = xi 29 | 30 | # get max_depths of all children of the root 31 | depths = (1 + max_depth(root, child) for child in edges[root]) 32 | 33 | # sort the depths to easily get the top 1 or 2 34 | depths = sorted(depths, reverse=True) 35 | 36 | # calculate the cost of the longest path 37 | max_chain = depths[0] + depths[1] if len(depths) > 1 else depths[0] 38 | 39 | # print max cost 40 | print("%d" % (max_chain / 2 + max_chain % 2)) -------------------------------------------------------------------------------- /MEDIUM/TEADS SPONSORED CONTEST/python3/teads-sponsored-contest-80-percent.py: -------------------------------------------------------------------------------- 1 | connections = {} 2 | 3 | def calculate(n, nt): 4 | global connections 5 | temp = [-1] 6 | for i in connections.get(n, []): 7 | if i!= nt: 8 | temp.append(calculate(i, n)) 9 | return max(temp) + 1 10 | 11 | n = int(input()) # the number of adjacency relations 12 | keys = {} 13 | for i in range(n): 14 | # xi: the ID of a person which is adjacent to yi 15 | # yi: the ID of a p erson which is adjacent to xi 16 | xi, yi = [int(j) for j in input().split()] 17 | k = keys.get(xi, 0) 18 | keys[xi] = k+1 19 | k = keys.get(yi, 0) 20 | keys[yi] = k+1 21 | connections.setdefault(xi, []).append(yi) 22 | connections.setdefault(yi, []).append(xi) 23 | temp = [] 24 | for i, v in keys.items(): 25 | if v>1: 26 | temp.append(calculate(i, -1)) 27 | # The minimal amount of steps required to completely propagate the advertisement 28 | print(min(temp)) 29 | -------------------------------------------------------------------------------- /MEDIUM/TELEPHONE NUMBERS/Readme.md: -------------------------------------------------------------------------------- 1 | # Telephone Network 2 | 3 | By joining the iDroid smartphone development team, you have been given the responsibility of developing the contact manager. Obviously, what you were not told is that there are strong technical constraints for iDroid: the system doesn’t have much memory and the processor is as fast as a Cyrix from the 90s... 4 | 5 | In the specifications, there are two points in particular that catch your attention: 6 | 7 | 1. **Intelligent Assistance for entering numbers**: The numbers corresponding to the first digits entered will be displayed to the user almost instantly 8 | 1. **Number storage optimization**: First digits which are common to the numbers should not be duplicated in the memory. 9 | 10 | Fortunately, the specifications also have this little chart to guide you in the implementation: 11 | 12 | Your task is to write a program that displays the number of items (which are numbers) required to store a list of telephone numbers with the structure presented above. 13 | 14 | ## Input 15 | 16 | * **Line 1**: The number N of telephone numbers. 17 | * **N Following lines**: Each line contains a phone number, with a maximum length L. Telephone numbers consist of only the digits 0 to 9 included, without any spaces. 18 | 19 | ## Output 20 | 21 | The number of elements (referencing a number) stored in the structure. 22 | 23 | ## Constraints 24 | 25 | * 0 ≤ N ≤ 10000 26 | * 2 ≤ L ≤ 20 27 | 28 | ## Examples 29 | 30 | Input 31 | 32 | 1 33 | 0467123456 34 | 35 | Output 36 | 37 | 10 38 | 39 | Input 40 | 41 | 2 42 | 0123456789 43 | 1123456789 44 | 45 | Output 46 | 47 | 20 48 | 49 | Input 50 | 51 | 2 52 | 0123456789 53 | 0123 54 | 55 | Output 56 | 57 | 10 58 | 59 | Input 60 | 61 | 5 62 | 0412578440 63 | 0412199803 64 | 0468892011 65 | 112 66 | 15 67 | 68 | Output 69 | 70 | 28 71 | 72 | ## Conditions 73 | 74 | * Available RAM: 512MB 75 | * Timeout: 1 seconds 76 | * The program has to read inputs from standard input 77 | * The program has to write the solution to standard output 78 | * The program must run in the test environment 79 | -------------------------------------------------------------------------------- /MEDIUM/TELEPHONE NUMBERS/python3/telephone-numbers.py: -------------------------------------------------------------------------------- 1 | # https://www.codingame.com/ide/puzzle/telephone-numbers 2 | import sys 3 | import math 4 | data = {} 5 | n = int(input()) 6 | cnt = 0 7 | for i in range(n): 8 | telephone = input() 9 | temp = data 10 | for t in telephone: 11 | val = temp.get(t, None) 12 | if val == None: 13 | cnt+=1 14 | temp = temp.setdefault(t, {}) 15 | # The number of elements (referencing a number) stored in the structure. 16 | print(cnt) 17 | -------------------------------------------------------------------------------- /MEDIUM/TEXT ALIGNMENT/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/MEDIUM/TEXT ALIGNMENT/__init__.py -------------------------------------------------------------------------------- /MEDIUM/TEXT ALIGNMENT/python/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/MEDIUM/TEXT ALIGNMENT/python/__init__.py -------------------------------------------------------------------------------- /MEDIUM/TEXT ALIGNMENT/python/text-alignment.py: -------------------------------------------------------------------------------- 1 | # https://www.codingame.com/ide/puzzle/text-alignment 2 | # got from https://github.com/aethersg/codingame-puzzle/blob/master/Python/community%20puzzle/text%20align.py 3 | import sys 4 | import math 5 | 6 | 7 | # Auto-generated code below aims at helping you parse 8 | # the standard input according to the problem statement. 9 | def words_len(array): 10 | return sum([len(x) for x in array]) 11 | 12 | 13 | def justify(sentence, width): 14 | words = sentence.split(" ") 15 | extra_space = width - words_len(words) 16 | while extra_space > 0 and len(words) > 1: 17 | for i in range(len(words) - 1): 18 | words[i] += " " 19 | extra_space -= 1 20 | if extra_space < 1: 21 | break; 22 | return ''.join(words) 23 | 24 | 25 | alignment = raw_input() 26 | n = int(raw_input()) 27 | 28 | map_line = [] 29 | max_size = 0 30 | for i in xrange(n): 31 | text = raw_input() 32 | max_size = max(len(text), max_size) 33 | map_line.append(text) 34 | 35 | # Write an action using print 36 | # To debug: print >> sys.stderr, "Debug messages..." 37 | for t in map_line: 38 | if alignment == "LEFT": 39 | print t.ljust(0) 40 | if alignment == "RIGHT": 41 | print t.rjust(max_size) 42 | if alignment == "CENTER": 43 | print t.center(max_size).rstrip() 44 | if alignment == "JUSTIFY": 45 | print justify(t, max_size) -------------------------------------------------------------------------------- /MEDIUM/TEXT ALIGNMENT/python3/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/MEDIUM/TEXT ALIGNMENT/python3/__init__.py -------------------------------------------------------------------------------- /MEDIUM/TEXT ALIGNMENT/python3/text-alignment.py: -------------------------------------------------------------------------------- 1 | # https://www.codingame.com/ide/puzzle/text-alignment 2 | # got from https://github.com/aethersg/codingame-puzzle/blob/master/Python/community%20puzzle/text%20align.py 3 | import sys 4 | import math 5 | 6 | 7 | # Auto-generated code below aims at helping you parse 8 | # the standard input according to the problem statement. 9 | def words_len(array): 10 | return sum([len(x) for x in array]) 11 | 12 | 13 | def justify(sentence, width): 14 | words = sentence.split(" ") 15 | extra_space = width - words_len(words) 16 | while extra_space > 0 and len(words) > 1: 17 | for i in range(len(words) - 1): 18 | words[i] += " " 19 | extra_space -= 1 20 | if extra_space < 1: 21 | break; 22 | return ''.join(words) 23 | 24 | 25 | alignment = input() 26 | n = int(input()) 27 | 28 | map_line = [] 29 | max_size = 0 30 | for i in range(n): 31 | text = input() 32 | max_size = max(len(text), max_size) 33 | map_line.append(text) 34 | 35 | # Write an action using print 36 | # To debug: print >> sys.stderr, "Debug messages..." 37 | for t in map_line: 38 | if alignment == "LEFT": 39 | print(t.ljust(0)) 40 | if alignment == "RIGHT": 41 | print(t.rjust(max_size)) 42 | if alignment == "CENTER": 43 | print(t.center(max_size).rstrip()) 44 | if alignment == "JUSTIFY": 45 | print(justify(t, max_size)) -------------------------------------------------------------------------------- /MEDIUM/THE GIFT/python3/the-gift.py: -------------------------------------------------------------------------------- 1 | # https://www.codingame.com/ide/puzzle/the-gift 2 | import math 3 | budget_left = [] 4 | budget_calculated=[] 5 | oods_left = n = int(input()) 6 | cost_left = int(input()) 7 | for i in range(n): 8 | budget_left.append(int(input())) 9 | budget_calculated.append(0) 10 | while oods_left>0: 11 | each_pay = math.floor(cost_left/oods_left) 12 | for i in range(n): 13 | if budget_left[i]==0: 14 | continue 15 | if(budget_left[i]<=each_pay): 16 | oods_left-=1 17 | budget_calculated[i] += budget_left[i] 18 | cost_left -= budget_left[i] 19 | budget_left[i] = 0 20 | else: 21 | budget_calculated[i] += each_pay 22 | cost_left -= each_pay 23 | budget_left[i] -= each_pay 24 | if cost_left==0: 25 | break 26 | if cost_left0: 31 | budget_calculated[i] += 1 32 | cost_left -=1 33 | if cost_left==0: 34 | break 35 | if oods_left==0 and cost_left>0: 36 | print("IMPOSSIBLE") 37 | else: 38 | budget_calculated.sort() 39 | for b in budget_calculated: 40 | print(b) 41 | -------------------------------------------------------------------------------- /MEDIUM/THE LAST CRUSADE - EPISODE 1/python3/the-last-crusade-episode-1.py: -------------------------------------------------------------------------------- 1 | # https://www.codingame.com/ide/puzzle/the-last-crusade-episode-1 2 | MAP_RULES = { 3 | '0':{}, 4 | '1':{'LEFT':'BOTTOM', 'TOP':'BOTTOM', 'RIGHT':'BOTTOM'}, 5 | '2':{'LEFT':'RIGHT', 'RIGHT':'LEFT'}, 6 | '3':{'TOP': 'BOTTOM'}, 7 | '4':{'TOP':'LEFT', 'RIGHT': 'BOTTOM'}, 8 | '5':{'TOP':'RIGHT', 'LEFT': 'BOTTOM'}, 9 | '6':{'LEFT':'RIGHT', 'RIGHT':'LEFT'}, 10 | '7':{'TOP':'BOTTOM', 'RIGHT':'BOTTOM'}, 11 | '8':{'LEFT':'BOTTOM', 'RIGHT':'BOTTOM'}, 12 | '9':{'LEFT':'BOTTOM', 'TOP': 'BOTTOM'}, 13 | '10':{'TOP':'LEFT'}, 14 | '11':{'TOP':'RIGHT'}, 15 | '12':{'RIGHT':'BOTTOM'}, 16 | '13':{'LEFT':'BOTTOM'}, 17 | } 18 | DIR_RULES = { 19 | 'LEFT':{'y':0,'x':-1}, 20 | 'RIGHT':{'y': 0, 'x':1}, 21 | 'BOTTOM':{'y': 1, 'x':0} 22 | } 23 | # w: number of columns. 24 | # h: number of rows. 25 | w, h = [int(i) for i in input().split()] 26 | map = [] 27 | for i in range(h): 28 | # represents a line in the grid and contains W integers. Each integer represents one room of a given type. 29 | map.append(input().split()) 30 | ex = int(input()) # the coordinate along the X axis of the exit (not useful for this first mission, but must be read). 31 | 32 | # game loop 33 | while True: 34 | xi, yi, pos = input().split() 35 | xi = int(xi) 36 | yi = int(yi) 37 | rule = DIR_RULES[MAP_RULES[map[yi][xi]][pos]] 38 | x_to, y_to = xi+rule['x'], yi+rule['y'] 39 | # One line containing the X Y coordinates of the room in which you believe Indy will be on the next turn. 40 | print("{0} {1}".format(x_to, y_to)) 41 | -------------------------------------------------------------------------------- /MEDIUM/THERE IS NO SPOON - EPISODE 1/php/there-is-no-spoon-episode-1.php: -------------------------------------------------------------------------------- 1 | p2_kart: 51 | self.player_got_all(1) 52 | self._war = False 53 | elif p1_kart < p2_kart: 54 | self.player_got_all(2) 55 | self._war = False 56 | else: 57 | self._war = True 58 | 59 | def have_enought_karts(self, n): 60 | len1, len2 = len(self._player1deck), len(self._player2deck) 61 | if len1 >= n and len2 >= n: 62 | return True 63 | else: 64 | # set the winner 65 | if self._war: 66 | self._winner = "PAT" 67 | elif len1 - n < 0 and len2 - n < 0: 68 | self._winner = "PAT" 69 | elif (len1 > len2): 70 | self._winner = "1" 71 | else: 72 | self._winner = "2" 73 | 74 | return False 75 | 76 | def play(self): 77 | if self._war: 78 | if self.have_enought_karts(3): 79 | self.drag_karts(3) 80 | else: 81 | return False 82 | if self.have_enought_karts(1): 83 | if not (self._war): 84 | self.round_plus() 85 | self.drag_karts() 86 | self.check_carts() 87 | else: 88 | return False 89 | return True 90 | 91 | def round_plus(self): 92 | self._round = self._round + 1 93 | 94 | def run(self): 95 | while self.play(): 96 | pass 97 | 98 | game = Game() 99 | game.run() 100 | game.print_result() 101 | 102 | -------------------------------------------------------------------------------- /MEDIUM/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/MEDIUM/__init__.py -------------------------------------------------------------------------------- /OPTIMISATION/CODE OF RINGS/code-of-the-rings.py: -------------------------------------------------------------------------------- 1 | class Area: 2 | LETTERS_PLUS = " ABCDEFGHIJKLMNOPQRSTUVWXYZ" 3 | LETTERS_MINUS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ "[::-1] 4 | letters = {} 5 | positio = {} 6 | builded = {} 7 | magic_phrase = "" 8 | path = "" 9 | current_position = 15 10 | 11 | def __init__(self): 12 | self.magic_phrase = input() 13 | 14 | def closest_plus(self, char): 15 | return self.LETTERS_PLUS.find(char) 16 | 17 | def closest_minus(self, char): 18 | return self.LETTERS_MINUS.find(char) 19 | 20 | def get_all_leters(self): 21 | last_position = 15 22 | for char in self.magic_phrase: 23 | letters = self.letters.get(char, None) 24 | if letters is None: 25 | self.letters[char] = last_position 26 | self.positio[last_position] = char 27 | self.builded[char] = False 28 | last_position += 1 29 | 30 | def build_path(self): 31 | for char in self.magic_phrase: 32 | step = (-1, 1)[self.current_position < self.letters[char]] 33 | while self.current_position != self.letters[char]: 34 | if step > 0: 35 | self.path += ">" 36 | self.current_position += 1 37 | else: 38 | self.path += "<" 39 | self.current_position -= 1 40 | if (not (self.builded[char])): 41 | self.builded[char] = True 42 | plus = self.closest_plus(char) 43 | minus = self.closest_minus(char) 44 | sight, count = (["-", minus], ["+", plus])[plus < minus] 45 | self.path += (sight * count) 46 | self.path += "." 47 | print(self.path) 48 | 49 | 50 | act = Area() 51 | act.get_all_leters() 52 | act.build_path() -------------------------------------------------------------------------------- /OPTIMISATION/CODE VS ZOMBIES/python3/code-vs-zombies.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import math 3 | 4 | WIDTH = 16000 5 | HEIGHT = 9000 6 | ASH_SPEED = 1000 7 | ZOMBIE_SPEED = 400 8 | ASH_ATTACK_DISTANCE = 2000 9 | ZOMBIE_ATTACK_DISTANCE = 400 10 | 11 | 12 | def dist(x1, y1, x2, y2): 13 | return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) 14 | 15 | 16 | # TODO: MOVE WITH VECTORS? USE ZOMBIE SPEED 17 | class Action: 18 | x = y = None 19 | humans = {} 20 | zombies = {} 21 | zombie_attack_human = {} 22 | 23 | def read_situation(self): 24 | self.x, self.y = [int(i) for i in input().split()] 25 | human_count = int(input()) 26 | self.humans.clear() 27 | for i in range(human_count): 28 | human_id, human_x, human_y = [int(j) for j in input().split()] 29 | self.humans[human_id] = {'x': human_x, 'y': human_y} 30 | self.zombies.clear() 31 | zombie_count = int(input()) 32 | for i in range(zombie_count): 33 | zombie_id, zombie_x, zombie_y, zombie_xnext, zombie_ynext = [int(j) for j in input().split()] 34 | self.zombies[zombie_id] = {'x': zombie_x, 'y': zombie_y, 'xn': zombie_xnext, 'yn': zombie_ynext} 35 | self.zombie_attack_human.clear() 36 | for hid, human in self.humans.items(): 37 | for zid, zomb in self.zombies.items(): 38 | if (zomb['xn'] > human['x'] - 600 or zomb['xn'] < human['x'] + 600) and ( 39 | zomb['yn'] > human['y'] - 600 or zomb['yn'] < human['y'] + 600): 40 | self.zombie_attack_human[zid] = hid 41 | 42 | def klaatu_barada_nikhe_khe_khe(self): 43 | # get best zombie 44 | zomb = self.get_closest() 45 | if zomb: 46 | print(zomb['x'], zomb['y']) 47 | 48 | def get_closest(self): 49 | distance_to_human = distance_to_hero = WIDTH 50 | closest_to_human = None 51 | closes_to_hero = None 52 | for zid, zomb in self.zombies.items(): 53 | human = self.humans[self.zombie_attack_human[zid]] 54 | dis = dist(zomb['x'], zomb['y'], human['x'], human['y']) 55 | hero_distance = dist(self.x, self.y, human['x'], human['y']) 56 | if distance_to_human > dis and (hero_distance - ASH_ATTACK_DISTANCE) / ASH_SPEED < ( 57 | dis + ZOMBIE_ATTACK_DISTANCE) / ZOMBIE_SPEED: 58 | distance_to_human = dis 59 | closest_to_human = zomb 60 | if distance_to_hero > hero_distance: 61 | distance_to_hero = hero_distance 62 | closes_to_hero = zomb 63 | if closest_to_human: 64 | return closest_to_human 65 | else: 66 | return closes_to_hero 67 | 68 | 69 | act = Action() 70 | while True: 71 | act.read_situation() 72 | act.klaatu_barada_nikhe_khe_khe() 73 | # Your destination coordinates 74 | 75 | -------------------------------------------------------------------------------- /OPTIMISATION/MARS LANDER/php/mars-lander.php: -------------------------------------------------------------------------------- 1 | $LAND_X, 'y' => $LAND_Y); 16 | if ($i > 0 && $coords[$i]['y'] == $coords[$i - 1]['y']) { 17 | $Y_landing = $coords[$i]['y']; 18 | $X1_landing = $coords[$i - 1]['x']; 19 | $X2_landing = $coords[$i]['x']; 20 | error_log(var_export($Y_landing, true)); 21 | error_log(var_export($X1_landing, true)); 22 | error_log(var_export($X2_landing, true)); 23 | } 24 | } 25 | $X_landing = ($X1_landing + $X2_landing) / 2; 26 | $L_length = $X2_landing - $X1_landing; 27 | while (true) { 28 | $i++; 29 | fscanf(STDIN, "%d %d %d %d %d %d %d", 30 | $X, 31 | $Y, 32 | $HS, // the horizontal speed (in m/s), can be negative. 33 | $VS, // the vertical speed (in m/s), can be negative. 34 | $F, // the quantity of remaining fuel in liters. 35 | $R, // the rotation angle in degrees (-90 to 90). 36 | $P // the thrust power (0 to 4). 37 | ); 38 | error_log(var_export($X_landing - $X, true)); 39 | if (abs($X_landing - $X) < ($L_length + 100) / 2) { 40 | if ($HS > 10) { 41 | echo("50 4\n"); 42 | } else if ($HS < -10) { 43 | echo("-50 4\n"); 44 | } else { 45 | if ($VS < -39) { 46 | echo("0 4\n"); 47 | } else { 48 | echo("0 2\n"); 49 | } 50 | } 51 | } else { 52 | if (($X_landing - $X) > 0) { 53 | if ($HS > 55) { 54 | echo("20 4\n"); 55 | } else { 56 | echo("-20 4\n"); 57 | } 58 | } else if (($X_landing - $X) < 0) { 59 | if ($HS < -55) { 60 | echo("-20 4\n"); 61 | } else { 62 | echo("20 4\n"); 63 | } 64 | } 65 | } 66 | //echo("0 3\n"); // R P. R is the desired rotation angle. P is the desired thrust power. 67 | } -------------------------------------------------------------------------------- /OPTIMISATION/NINTENDO SPONSORED CONTEST/c++/contest.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vadim-job-hg/Codingame/4d59bb83b18b91f4a3489b350b7779e12e23ef23/OPTIMISATION/NINTENDO SPONSORED CONTEST/c++/contest.cpp -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Solutions 2 | https://www.codingame.com -------------------------------------------------------------------------------- /VERY HARD/MARS LANDER - EPISODE 3/java/mars-lander-episode-3.java: -------------------------------------------------------------------------------- 1 | //https://www.codingame.com/ide/puzzle/mars-lander-episode-3 2 | import java.util.*; 3 | import java.io.*; 4 | import java.math.*; 5 | import java.awt.*; 6 | 7 | /** 8 | * Auto-generated code below aims at helping you parse 9 | * the standard input according to the problem statement. 10 | **/ 11 | class Player { 12 | 13 | public static void main(String args[]) { 14 | Scanner in = new Scanner(System.in); 15 | int surfaceN = in.nextInt(); // the number of points used to draw the surface of Mars. 16 | Point[] land = new Point[surfaceN]; 17 | int ground = -1; 18 | int high = 0; 19 | for (int i = 0; i < surfaceN; i++) { 20 | int landX = in.nextInt(); // X coordinate of a surface point. (0 to 6999) 21 | int landY = in.nextInt(); // Y coordinate of a surface point. By linking all the points together in a sequential fashion, you form the surface of Mars. 22 | land[i] = new Point(landX,landY); 23 | high = Math.max(high,landY); 24 | if (i == 0) continue; 25 | if (land[i].y == land[i-1].y) ground = i-1; 26 | } 27 | 28 | int testCase = -1; 29 | boolean offTheMark = false; 30 | 31 | // game loop 32 | while (true) { 33 | int X = in.nextInt(); 34 | int Y = in.nextInt(); 35 | int hSpeed = in.nextInt(); // the horizontal speed (in m/s), can be negative. 36 | int vSpeed = in.nextInt(); // the vertical speed (in m/s), can be negative. 37 | int fuel = in.nextInt(); // the quantity of remaining fuel in liters. 38 | int rotate = in.nextInt(); // the rotation angle in degrees (-90 to 90). 39 | int power = in.nextInt(); // the thrust power (0 to 4). 40 | 41 | if (testCase == -1) { 42 | if (hSpeed == 0) testCase = 1; 43 | else testCase = 0; 44 | } 45 | 46 | // RULES FOR TEST 1 47 | if (testCase == 0) { 48 | if (Y - land[ground].y < 800) { 49 | if (vSpeed <= -39) System.out.println("0 4"); 50 | else System.out.println("0 3"); 51 | continue; 52 | } 53 | else if (X <= land[ground+1].x) {System.out.println("-45 4"); continue;} 54 | else if (vSpeed <= -20) {System.out.println("0 4"); continue;} 55 | else if (vSpeed <= -12) {System.out.println("0 2"); continue;} 56 | else {System.out.println("45 4"); continue;} 57 | } 58 | 59 | //RULES FOR TEST 2 60 | if (testCase == 1) { 61 | System.err.println(offTheMark); 62 | if (vSpeed < -45 || Y <= 1135) {System.out.println("0 4"); continue;} 63 | else if (X <= land[ground].x) {System.out.println("-32 3"); continue;} 64 | else if (vSpeed == 0 && Y > high) {System.out.println("0 3"); continue;} 65 | else if (vSpeed < 0 || Y < high) {System.out.println("0 4"); continue;} 66 | else if (vSpeed >= 12 || offTheMark) { 67 | offTheMark = true; 68 | System.out.println("45 4"); 69 | continue; 70 | } 71 | else {System.out.println("0 4"); continue;} 72 | } 73 | } 74 | } 75 | } -------------------------------------------------------------------------------- /VERY HARD/THE RESISTANCE/c++/the-resistance.cpp: -------------------------------------------------------------------------------- 1 | /*~~~~~~~~~~~~~~~~~~* 2 | * * 3 | * $Dollar Akshay$ * 4 | * * 5 | *~~~~~~~~~~~~~~~~~~*/ 6 | 7 | //https://www.codingame.com/ide/28851516be94dd1da9c26c054ed61ccdfcde661 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | using namespace std; 27 | 28 | #define sp system("pause") 29 | #define FOR(i,a,b) for(int i=a;i<=b;++i) 30 | #define FORD(i,a,b) for(int i=a;i>=b;--i) 31 | #define REP(i,n) FOR(i,0,(int)n-1) 32 | #define pb(x) push_back(x) 33 | #define mp(a,b) make_pair(a,b) 34 | #define DB(s,x) fprintf(stderr,s,x); 35 | #define MS(x,n) memset(x,n,sizeof(x)) 36 | #define SORT(a,n) sort(begin(a),begin(a)+n) 37 | #define REV(a,n) reverse(begin(a),begin(a)+n) 38 | #define ll long long 39 | #define pii pair 40 | #define MOD 1000000007 41 | 42 | 43 | int len, n; 44 | 45 | char code[100000]; 46 | bool calc[10001]; 47 | ll int DP[10001]; 48 | vector words; 49 | 50 | char alphabet[26][10] = { 51 | ".-","-...","-.-.","-..",".","..-.", // a-f 52 | "--.","....","..",".---","-.-",".-..", // g-l 53 | "--","-.","---",".--.","--.-",".-.", // m-r 54 | "...","-","..-","...-",".--","-..-", // s-x 55 | "-.--","--.." }; // y-z 56 | 57 | char original[10000][100],dict[10000][100]; 58 | 59 | void wordToMorse(char original[100], char dict[100]) { 60 | 61 | char morse[100] = ""; 62 | int len = strlen(original); 63 | REP(i, len) 64 | strcat(morse, alphabet[original[i] - 'A']); 65 | strcpy(dict, morse); 66 | 67 | } 68 | 69 | ll int DFS(int k) { 70 | 71 | if (k==len) { 72 | return 1; 73 | } 74 | 75 | if (calc[k]) 76 | return DP[k]; 77 | 78 | REP(i, n) { 79 | if (strncmp(code+k, dict[i], strlen(dict[i]))==0) { 80 | words.push_back(i); 81 | DP[k] += DFS(k+strlen(dict[i])); 82 | words.pop_back(); 83 | } 84 | } 85 | calc[k] = true; 86 | return DP[k]; 87 | } 88 | 89 | int main() { 90 | 91 | scanf("%s", code); 92 | len = strlen(code); 93 | scanf("%d", &n); 94 | REP(i, n) { 95 | scanf("%s", original[i]); 96 | wordToMorse(original[i], dict[i]); 97 | } 98 | printf("%lld\n", DFS(0)); 99 | sp; 100 | return 0; 101 | } 102 | 103 | //Solved -------------------------------------------------------------------------------- /VERY HARD/THE RESISTANCE/java/the-resistance.java: -------------------------------------------------------------------------------- 1 | //https://github.com/CyberLemonade/Codingame/blob/master/Very%20Hard/The%20Resistance.java 2 | import java.util.*; 3 | class Solution { 4 | 5 | static String morse[] = {".-","-...","-.-.","-..",".", 6 | "..-.","--.","....","..",".---", 7 | "-.-",".-..","--","-.","---", 8 | ".--.","--.-",".-.","...","-", 9 | "..-","...-",".--","-..-","-.--","--..",}; 10 | 11 | static String sequence = ""; 12 | static Map occur = new HashMap(); 13 | static long[] combos; 14 | static int max = 0; 15 | 16 | public static void main(String[] args) { 17 | Scanner in = new Scanner(System.in); 18 | sequence = in.nextLine(); 19 | int N = in.nextInt(); 20 | combos = new long[sequence.length()]; 21 | in.nextLine(); 22 | for (int i = 0; i < N; i++) { 23 | morph(in.nextLine()); 24 | } 25 | System.out.println(tryCombos(0)); 26 | } 27 | 28 | public static void morph(String word) { 29 | String morphed = ""; 30 | for (int i = 0; i < word.length(); i++) { 31 | morphed += morse[word.charAt(i)-65]; 32 | if (sequence.indexOf(morphed)==-1) {return;} 33 | } 34 | int freq = 1; 35 | try {freq+=occur.get(morphed);} 36 | catch (Exception e) {max=Math.max(max,morphed.length());} 37 | occur.put(morphed,freq); 38 | } 39 | 40 | public static long tryCombos(int start) { 41 | if (start==sequence.length()) return 1L; 42 | if (combos[start]!=0) return combos[start]-1L; 43 | long result = 0; 44 | for (int i = 1; i<=max && start+i<=sequence.length(); i++) { 45 | try { 46 | result += (long)occur.get(sequence.substring(start,start+i))*tryCombos(start+i); 47 | } 48 | catch (Exception e) {} 49 | } 50 | combos[start] = result+1L; 51 | return result; 52 | } 53 | } --------------------------------------------------------------------------------