{"id":268,"date":"2021-12-07T21:20:36","date_gmt":"2021-12-07T20:20:36","guid":{"rendered":"https:\/\/www.davidestebanmunoz.com\/?p=268"},"modified":"2022-01-26T22:42:58","modified_gmt":"2022-01-26T21:42:58","slug":"telefonica-code-challenge-2021-participation-3","status":"publish","type":"post","link":"https:\/\/www.davidestebanmunoz.com\/?p=268&lang=es","title":{"rendered":"Participaci\u00f3n en el Telefonica Code Challenge 2021"},"content":{"rendered":"\n<p><a href=\"https:\/\/www.davidestebanmunoz.com\/?p=256\">This article can be read in English here.<\/a><\/p>\n\n\n\n<p>Del 13 al 20 de diciembre de 2021, el Telefonica Code Challenge <a href=\"https:\/\/codechallenge.0x14.net\">https:\/\/codechallenge.0x14.net<\/a> (evoluci\u00f3n del Tuenti Challenge) ocup\u00f3 mis pocas horas libres.<\/p>\n\n\n\n<p>Hab\u00eda intentado participar en los Tuenti Challenges en el pasado, pero siempre se me pasaba la fecha, o me pillaba en \u00e9poca de examenes, o de vacaciones en el extranjero. Esta vez, en cuanto me enter\u00e9 me apunt\u00e9 por lo que esta es mi primera experiencia en un evento de este tipo.<\/p>\n\n\n\n<p>El Challenge tuvo 20 retos de programaci\u00f3n, algoritmia, reversing, hacking \u2026 Fui capaz de resolver los primeros 13. Fue una semana de alta carga en el trabajo y solo pude disponer de unas pocas horas a las tardes y noches por lo que estoy orgulloso de haber sido capaz de solventar esos 13 retos.<\/p>\n\n\n\n<p>Qued\u00e9 en la posici\u00f3n 49 tal y como se puede comprobar en <a href=\"https:\/\/codechallenge.0x14.net\/Stats\">https:\/\/codechallenge.0x14.net\/Stats<\/a><\/p>\n\n\n\n<p>Decid\u00ed participar en este Challenge utilizando Python. Echando un ojo a los resultados creo que fue una gran idea, la grand\u00edsima cantidad de librer\u00edas existentes para python y los tipos de dato (listas, diccionarios y tuplas) de este lenguaje fueron realmente muy \u00fatiles y me facilitaron el trabajo.<\/p>\n\n\n\n<p>Para todo aquel que quiera probarse en este tipo de eventos, le recomiendo la web<a href=\"https:\/\/www.codingame.com\/multiplayer\/clashofcode\"> https:\/\/www.codingame.com\/multiplayer\/clashofcode<\/a><\/p>\n\n\n\n<p>Todos los programas codificados por mi para este concurso est\u00e1n disponibles en <a href=\"https:\/\/github.com\/botmakerdvd\/code_challenge_2021\">https:\/\/github.com\/botmakerdvd\/code_challenge_2021<\/a><\/p>\n\n\n\n<p>Dado que el concurso fue \u00edntegro en ingl\u00e9s no voy a traducir los enunciados<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"challenge-1-roll-the-dice\">Challenge 1: Roll the dice<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Let\u2019s play a very simple dice game. In the game, two players throw two dice and the score is the sum of the dice throws. The player with the highest score wins the game. If both players get the same score the game is a draw.<br>Input<\/p><p>The first line will have an integer N, which is the number of cases for the problem. Each case has the result of the dice roll of the first player represented by two numbers (between 1 and 6) separated by \u2018:\u2019.<br>Output<\/p><p>For each case, there should be a line starting with \u201cCase #x: \u201d followed by the minimum score the second player needs to win the game, or \u2018-\u2018 when it\u2019s impossible to win (there can only be a draw after scoring all 6 dice).<\/p><\/blockquote>\n\n\n\n<p>Resolution code: <a href=\"https:\/\/github.com\/botmakerdvd\/code_challenge_2021\/blob\/master\/1\/1.py\">https:\/\/github.com\/botmakerdvd\/code_challenge_2021\/blob\/master\/1\/1.py<\/a><\/p>\n\n\n\n<p>Este fue realmente sencillo, asi que vayamos al siguiente.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"challenge-2-catch-them-all\">Challenge 2 \u2013 Catch them all<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Something strange has happened. All your pokemons have escaped. Can you catch them all?<\/p><p>You\u2019ve been given a map (shown with rows and columns) so you can find all the Pok\u00e9mon. The Pok\u00e9mon\u2019s name can only be found horizontally. But it can be written from left to right or right to left and it can be on more than one line. Once you catch a Pok\u00e9mon make sure to remove it from the map. Because each Pok\u00e9mon only appears once and some Pok\u00e9mon can be hidden within other Pok\u00e9mon.<br>Input<\/p><p>The first line will have an Integer N, which is the number of cases for the problem. It is followed by a description of T cases. Every case has an Integer P, which is the number of Pok\u00e9mon to find, an Integer R, which is the number of rows, and an Integer C, which is the number of columns. Then it has P lines with the names of each Pok\u00e9mon N. And finally R lines with C characters split by an empty space.<br>Output<\/p><p>For each case, there should be a line starting with \u201cCase #x: \u201d followed by the result of the map without the Pok\u00e9mon.<br>Limits<\/p><p>1 \u2264 T \u2264 20<br>1 \u2264 P \u2264 50<br>1 \u2264 C, R \u2264 100<br>1 \u2264 N \u2264 100<\/p><\/blockquote>\n\n\n\n<p>Resolution code: <a href=\"https:\/\/github.com\/botmakerdvd\/code_challenge_2021\/blob\/master\/2\/2.py\">https:\/\/github.com\/botmakerdvd\/code_challenge_2021\/blob\/master\/2\/2.py<\/a><\/p>\n\n\n\n<p>Este segundo, utilizando las listas de Python tambi\u00e9n resulto realmente sencillo.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"challenge-3-the-night-of-the-hunter\"><strong>Challenge 3<\/strong> \u2013 The night of the hunter<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Love or Hate? True or False? Create or Destroy? Which word would win in a hypothetical fight between antonyms? It depends on the values of the letters, of course.<\/p><p>Input<\/p><p>The first line has an integer N, which is the number of cases for the problem. Each case is a fight between two antonyms. Each line has:<\/p><p>Two opposite words separated by \u2018-\u2018<br>The character \u2018|\u2019<br>The value of each letter, which can be an integer or a fraction. The list of letters with its values can be in many formats:<br>As a dictionary:<\/p><p>{\u2018a\u2019: 2\/3, \u2018e\u2019: 4, \u2018h\u2019: 3, \u2018l\u2019: 5, \u2018o\u2019: 1, \u2018t\u2019: 6, \u2018v\u2019: 0}<\/p><p>As a list of tuples:<\/p><p>[(\u2018a\u2019, 2\/3), (\u2018e\u2019, 4), (\u2018h\u2019, 3), (\u2018l\u2019, 5), (\u2018o\u2019, 1), (\u2018t\u2019, 6), (\u2018v\u2019, 0)]<\/p><p>As a list of assignments:<\/p><p>a=2\/3,e=4,h=3,l=5,o=1,t=6,v=0<\/p><p>Output<\/p><p>For each case, there should be a line starting with \u201cCase #x: \u201d followed by the winning word or \u2018-\u2018 when the result is a draw.<\/p><\/blockquote>\n\n\n\n<p>Resolution code: <a href=\"https:\/\/github.com\/botmakerdvd\/code_challenge_2021\/blob\/master\/3\/3.py\">https:\/\/github.com\/botmakerdvd\/code_challenge_2021\/blob\/master\/3\/3.py<\/a><\/p>\n\n\n\n<p>En este caso, inicialmente se ha trasladado toda la informaci\u00f3n que se da sobre el valor de las letras a diccionarios.<\/p>\n\n\n\n<p>Esto facilita mucho la segunda parte del programa ya que lo simplifica al extremo.<\/p>\n\n\n\n<p>Se ha utilizado la librer\u00eda Fraction, para evitar problemas de precisi\u00f3n realizando operaciones con floats.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"challenge-4-let-s-build-musical-scales\"><strong>Challenge 4<\/strong> \u2013 Let\u2019s build musical scales<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Did you know there are really 12 notes and not 7? Don\u2019t forget the sharps and flats. Those are the black keys on a piano or keyboard. A musical scale is just a series of 7 of the 12 notes. Now, we\u2019re going to build some musical scales with different roots.<\/p><p>If we use the English notation notes are represented from A to G (A=La, B=Si, C=Do, etc.). You should also know that the note following most notes, except B and E, is the sharp, for example A and A#. But every sharp note can also be flat for the note after it. So A# can also be called Bb. So, the sequence of notes from A to B can be A-A#-B or A-Bb-B. There is one special rule. Some version of every note must be included in the scale , either natural, flat or sharp. So in some circumstances a modified version of B and E could also be included in the scale.<\/p><p>The root of a musical scale is the first note of the scale. So, if you have a C scale the first note will be C, and so will the 8th one. A sequence of semitone and tone jumps is defined when creating a scale. A semitone jump is just the next note in the sequence of all notes. A full tone jump means 2 semitones. So, you jump 2 notes to find the next note in the scale. For instance, the major scale is built with the sequence tone-tone-semitone-tone-tone-tone-semitone (TTsTTTs). So, the C major scale has the notes CDEFGABC. There are no sharps or flats.<\/p><\/blockquote>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/codechallenge.0x14.net\/resources\/img\/04-c-major-scale.png\" alt=\"C Major scale\"\/><\/figure>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>But what happens when a sharp or flat is included in the scale? Should we use the sharp or the flat? It\u2019s easy. Note names can only appear once in any given scale. So, if you already have A, for example, you cannot also have A#, so Bb is used.<br>Input<\/p><p>The first line will have an integer T, which is the number of cases for the problem. It\u2019s followed by a description of T cases. Every case has two lines. The first line of each case has the root of the scale to generate. It can be a simple note or a modified note (sharp or flat). The second line of each case has a string of 7 characters describing the scale steps. \u201cT\u201d means a tone and \u201cs\u201d means a semitone.<br>Output<\/p><p>For each case, there should be a line starting with \u201cCase #x: y\u201d, where x is the test case number (starting with 1) and y is a string with the notes of the scale.<\/p><\/blockquote>\n\n\n\n<p>Resolution Code: <a href=\"https:\/\/github.com\/botmakerdvd\/code_challenge_2021\/blob\/master\/4\/4.py\">https:\/\/github.com\/botmakerdvd\/code_challenge_2021\/blob\/master\/4\/4.py<\/a><\/p>\n\n\n\n<p>Resolv\u00ed este desaf\u00edo generando 2 diccionarios, uno para el siguiente tono de cada tono y otro para el siguiente semitono de cada tono.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"challenge-5-invictus\"><strong>Challenge 5<\/strong> \u2013 Invictus<\/h2>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/codechallenge.0x14.net\/resources\/img\/05-nelson-mandela.jpg\" alt=\"Nelson Mandela\"\/><\/figure>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>INVICTUS<\/p><p>Out of the night that covers me,<br>Black as the pit from pole to pole,<br>I thank whatever gods may be<br>For my unconquerable soul.<\/p><p>In the fell clutch of circumstance<br>I have not winced nor cried aloud.<br>Under the bludgeonings of chance<br>My head is bloody, but unbowed.<\/p><p>Beyond this place of wrath and tears<br>Looms but the Horror of the shade,<br>And yet the menace of the years<br>Finds and shall find me unafraid.<\/p><p>It matters not how strait the gate,<br>How charged with punishments the scroll,<br>I am the master of my fate,<br>I am the captain of my soul.<\/p><p>William Ernest Henley<\/p><p>Input<br>Find the PASSWORD hidden in the following file: Invictus.txt<br>Output<br>Find the PASSWORD. It contains the SURNAME in UPPERCASE of the famous person in the picture.<\/p><\/blockquote>\n\n\n\n<p>Resolution code: <a href=\"https:\/\/github.com\/botmakerdvd\/code_challenge_2021\/blob\/master\/5\/5.py\">https:\/\/github.com\/botmakerdvd\/code_challenge_2021\/blob\/master\/5\/5.py<\/a><\/p>\n\n\n\n<p>Este fue el primer reto de reversing\/hacking . Utiliz\u00e9 un visor hexadecimal y descubr\u00ed que habia algo oculto en el Invictus.txt<\/p>\n\n\n\n<p>Descubr\u00ed que utilizando caracteres ascii no imprimibles, se estaba ocultando informaci\u00f3n.<\/p>\n\n\n\n<p>Por lo que parecia cada dato era una tupla de 4 bytes, con la informaci\u00f3n en el 3\u00ba y 4\u00ba byte.<\/p>\n\n\n\n<p>Una vez que tuve dichos valores, descubr\u00ed que habia 2 tipos, unos con el valor 0x81 en el primer byte y otras que no.<\/p>\n\n\n\n<p>Como sab\u00eda que la soluci\u00f3n tenia que contener el nombre completo de NELSON ROLIHLAHLA MANDELA, descubr\u00ed que un cifrado por sustituci\u00f3n se hab\u00eda usado.<\/p>\n\n\n\n<p>Fue facil de resolver buscando 3 valores que se repitiesen estando separados 2 elementos entre si, ya que eso ser\u00edan las L de ROLIHLAHLA.<\/p>\n\n\n\n<p>A continuaci\u00f3n calcul\u00e9 la diferencia entre el valor ASCII de la letra L y el valor que yo ten\u00eda y aplicando esa diferencia resolv\u00ed el problema.<\/p>\n\n\n\n<p>O no\u2026 Finalmente descubr\u00ed que habia 2 tipos diferentes de sustituci\u00f3n, dependiendo del primer byte de cada valor, si el primer byte era 0x81 hab\u00eda que restar 110 al segundo, si no, 302.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"challenge-6-what-day-is-it\"><strong>Challenge 6<\/strong> \u2013 What day is it?<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Have you ever wondered what day of the week a date is? I\u2019m sure you have. In this challenge, you have to code a program to figure out how to tell anybody the day of the week (from a list of languages) for a given date.<\/p><p>Input<\/p><p>The first line has an integer N, which is the number of cases for the problem. Each case has a date, the character \u2018:\u2019 and a two-letter language code.<\/p><p>The date format can be: YYYY-MM-DD or DD-MM-YYYY<br>All dates are after 1970-01-01<br>Input cases may have invalid dates, like an invalid month (MM&gt;13) or an invalid day of a month<br>The weekday of a date can be given in any of these twenty languages:<\/p><p>CA: catalan CZ: czech DE: german DK: danish EN: english<br>ES: spanish FI: finnish FR: french IS: icelandic GR: greek<br>HU: hungarian IT: italian NL: dutch VI: vietnamese PL: polish<br>RO: romanian RU: russian SE: swedish SI: slovenian SK: slovak<\/p><p>Output<\/p><p>For each case, there should be a line starting with \u201cCase #x: \u201d followed by the weekday IN LOWERCASE of the day in the indicated language, or \u2018INVALID_DATE\u2019 if given date is invalid, or \u2018INVALID_LANGUAGE\u2019 for an unknown language code.<\/p><\/blockquote>\n\n\n\n<p>Resolution code: <a href=\"https:\/\/github.com\/botmakerdvd\/code_challenge_2021\/blob\/master\/6\/6.py\">https:\/\/github.com\/botmakerdvd\/code_challenge_2021\/blob\/master\/6\/6.py<\/a><\/p>\n\n\n\n<p>Utilizando locales y la libreria locale para Python, este reto fue muy sencillo.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"challenge-7-escape-or-die\">Challenge 7 \u2013 Escape or Die<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Hello, dear friend. Do you feel like you\u2019re in some kind of jail? Did you wake up this morning with the feeling that everything was dark?<\/p><p>Well, it isn\u2019t a dream. You\u2019re really here, in a long dark dungeon.<\/p><p>What do you have to do? It\u2019s simple. Try to escape from the dungeon. But, hurry up or something bad will happen to you.<\/p><p>You have to find the shortest path to the exit to escape the maze.<\/p><p>Good luck, my friend. Your dungeon is waiting for you at codechallenge-daemons.0x14.net:4321<br>Input<\/p><p>No input needed<br>Output<\/p><p>A list of coordinates with the shortest path to the exit. The list must have the following syntax:<\/p><p>(x0, y0), (x1, y1), (x2, y2), (x3, y3)\u2026 (xn, yn)<\/p><p>Where (x0, y0) is the starting position in the maze and (xn, yn) is the final position (the exit).<\/p><p>For example, if your initial position is (3, 4) and the exit is at (5, 6), the following could be a good solution:<\/p><p>(3, 4), (3, 5), (3,6), (4, 6), (5, 6)<\/p><p>Assuming the path is clear, of course.<\/p><\/blockquote>\n\n\n\n<p>Resolution code: <a href=\"https:\/\/github.com\/botmakerdvd\/code_challenge_2021\/blob\/master\/7\/7.py\">https:\/\/github.com\/botmakerdvd\/code_challenge_2021\/blob\/master\/7\/7.py<\/a><\/p>\n\n\n\n<p>En este caso despu\u00e9s de mucho leer, utilic\u00e9 el algoritmo Dijkstra\u2019s para resolverlo, integrando una librer\u00eda telnet en mi c\u00f3digo python. La explicaci\u00f3n de este algoritmo se puede ver en <a href=\"https:\/\/en.wikipedia.org\/wiki\/Dijkstra%27s_algorithm\">https:\/\/en.wikipedia.org\/wiki\/Dijkstra%27s_algorithm<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"challenge-8-awesome-sales-inc\"><strong>Challenge 8<\/strong> \u2013 Awesome Sales Inc.!<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>You\u2019ve been contacted by a company called Awesome Sales Inc. They recently bought some new ultra-modern AI based software for creating travel plans for their sales force. But, it seems to have a huge problem and the developers have gone MIA. So they need you to figure out how to fix it.<\/p><p>The \u201cawesome\u201d software works with two modules. The first module (AICityPicker) picks the best cities to be visited by each employee based on a number of the employee\u2019s records and traits. It also takes another important factor into account, which is that employees can move between cities on an ASCB (Awesome Sales Connection Bus).<\/p><p>Once the cities have been picked by the AI, a plan is generated in the form of bus tickets that can be used multiple times to move between cities. For example, t1: [A, B] is a ticket that can be used to go from city A to city B and vice versa. In the plans, employees can always reach one city from another using their tickets. For example, if an employee has to visit cities A, B and C, there will always be a way to go from A to C, even if they have to go from A to B and then from B to C.<\/p><p>The other module (AICityRemover) is the one with the problems. Once a plan is generated, this module evaluates budgets, costs and other things and picks cities from the initial plan to remove. It cancels the bus tickets for them and everything else \u2013 all automatically.<\/p><p>The biggest problem is that this module doesn\u2019t take the ASCB into account. Cities are removed and employees can no longer reach all their destinations. For example, if an employee has to visit A, B and C, the module may remove B, even if none of the ASCB can go from A to C directly. So, when an employee finds themselves in that situation they have to find a way to reach their destination. Sometimes they pay for a regular bus ticket or taxi out of their own pocket or they might even ask a stranger for a ride. Not good.<\/p><p>Of course, you don\u2019t have access to the source code. But, you manage to reverse engineer the AICityRemover module and find the root cause of the problem. A function called currentPlan.getCriticalCitiesThatCannotBeRemoved() wasn\u2019t implemented and always returns an empty list! Luckily, the documentation has some examples so you can work out your own implementation.<\/p><p>You need to write the getCriticalCitiesThatCannotBeRemoved() function so that for each plan it returns a list of cities that can\u2019t be removed. In other words, the list of cities where if any city is removed the initial plan breaks and the employee can\u2019t reach the rest of the cities using their ASCB tickets.<\/p><p>Cities are removed one by one, so when a city is removed from the initial plan, other cities might become critical now but that would be a whole new case. You need to provide the list of cities that are critical from the initial plan.<\/p><p>Input<\/p><p>The first line will have an integer C, which is the number of cases for the problem. The description of the C cases follows. For each case, the first line is an integer T showing the number of tickets. Then T lines follow, each describing a ticket. Each ticket is described in the form \u201cCity A,City B\u201d, which means the ticket can be used to go from City A to City B and vice versa.<br>Output<\/p><p>For each case, there should be a line starting with \u201cCase #x: y\u201d, where x is the test case number (starting from 1) and y is the list of the critical cities, in the form \u201cCity A,City B\u201d. The list should be ordered alphabetically. If none of the cities are critical a dash (-) should be printed instead.<\/p><\/blockquote>\n\n\n\n<p>Resolution code: <a href=\"https:\/\/github.com\/botmakerdvd\/code_challenge_2021\/blob\/master\/8\/8.py\">https:\/\/github.com\/botmakerdvd\/code_challenge_2021\/blob\/master\/8\/8.py<\/a><\/p>\n\n\n\n<p>Este reto fue muy sencillo de resolver utilizando Teoria de Grafos y la librer\u00eda networkx. En la Teor\u00eda de Grafos las ciudades cr\u00edticas se les llama puntos de articulaci\u00f3n, y la librer\u00eda networkx los encuentra facilmente.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"challenge-9-collisions\"><strong>Challenge 9<\/strong> \u2013 Collisions<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>We\u2019re building the collision detection module for our 2D game engine. We want to be able to process a lot of sprites at the same time and detect all the collisions. We\u2019ll provide the bitmask for each sprite, where 0 indicates transparency and 1 indicates a solid part of the sprite. If two solid parts of different sprites share the same location then it\u2019s counted as a collision. If two sprites collide at different points a single collision is counted. A sprite can collide with multiple other sprites.<\/p><p>Given a set of sprites, return how many collisions are detected.<\/p><p>Limits<\/p><p>T \u2264 10<br>D \u2264 10<br>W, H \u2264 512<br>P \u2264 50000<br>X, Y \u2264 100000<\/p><p>Input<\/p><p>The first line will have an integer T, which is the number of cases for the problem. The next line has an integer D, which is the number of sprite definitions. D sprite bitmask definitions follow. Each sprite bitmask definition starts with a line with two integers W, H, which are the width and height of the sprite followed by H lines of length W of 0\u2019s or 1\u2019s. T test cases follow. Each case starts with an integer P, which is the number of sprite positions in the test. P lines follow and each line has 3 integers: I, X, Y, where I is the sprite identifier (from 0 to D-1), and X, Y are the coordinates of the sprite.<\/p><p>The (0,0) coordinate is the top-left corner of the display and sprites.<br>Output<\/p><p>For each case, there should be a line starting with \u201cCase #x: \u201d followed by the number of collisions for that test case.<\/p><\/blockquote>\n\n\n\n<p>Resolution code:<a href=\"https:\/\/github.com\/botmakerdvd\/code_challenge_2021\/blob\/master\/9\/9.py\"> https:\/\/github.com\/botmakerdvd\/code_challenge_2021\/blob\/master\/9\/9.py<\/a><\/p>\n\n\n\n<p>IEn este caso lo complicado no fue desarrollar el algoritmo de detecci\u00f3n de colisiones, sino optimizarlo para que fuera m\u00e1s veloz sabiendo cuando podia parar de buscar colisiones.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"challenge-10-packets-delivery\"><strong>Challenge 10<\/strong> \u2013 Packets delivery<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>We\u2019ve discovered a security hole in the enemy communication system and we need your help to move forward.<\/p><p>Thanks to our secret agent, we found out the enemy was using a quite exotic physical transport layer described in the experimental RFC 1149. However, you don\u2019t need to be an expert in that RFC, since we\u2019ve already been able to do a MITM attack on the communication system (with a shotgun) and extract the packets.<\/p><p>What do we need from you? Because we\u2019ve heard you\u2019re a forensics expert, we need you to extract the information from the intercepted packets. You can download them from this URL: ICMPs pcap.<\/p><p>The test and submission passwords are the same.<br>Input<br>No input needed<br>Output<\/p><p>The password hidden on the pcap file<\/p><\/blockquote>\n\n\n\n<p>Resolution code: <a href=\"https:\/\/github.com\/botmakerdvd\/code_challenge_2021\/blob\/master\/10\/10.py\">https:\/\/github.com\/botmakerdvd\/code_challenge_2021\/blob\/master\/10\/10.py<\/a><\/p>\n\n\n\n<p>Este es el 2\u00ba reto que involucra hacking\/reversing.<\/p>\n\n\n\n<p>Inicialmente al abrir la captura en whireshark observ\u00e9 que el campo ID se repetia bastante, por lo que cog\u00ed sus valores , los traduje a ASCII y obtuve una frase indicandome que reordenase los paquetes.<\/p>\n\n\n\n<p>A continuaci\u00f3n obtuve la carga de la capa ICMP y la orden\u00e9 basandome en el numero de secuencia ICMP.<\/p>\n\n\n\n<p>Detect\u00e9 que era una imagen PNG ya que descubr\u00ed su cabecera por lo que al abrirlo con un visor de im\u00e1genes\u2026 apareci\u00f3 un QR.<\/p>\n\n\n\n<p>Por \u00faltimo decodifiqu\u00e9 el QR code en<a href=\"https:\/\/online-barcode-reader.inliteresearch.com\"> https:\/\/online-barcode-reader.inliteresearch.com<\/a> y obtuve la soluci\u00f3n.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"challenge-11-alot-another-library-of-tools\"><strong>Challenge 11<\/strong> \u2013 ALOT Another library of tools<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Our team is writing a new JS utils library. The project has N functions. We want to split and distribute the functions in different files so every file exposes the same K number of functions. But we want to do it in a very specific way.<\/p><p>We have a linting tool that gives a score to our project and we want to maximize our score.<\/p><p>How is the score computed? The score of the project is the sum of the scores of its files.<\/p><p>How is the score for a file computed? The score for a file is the length of the longest common prefix of all the function names the file exposes. Let\u2019s see an example. A file that exposes the following three functions \u2013 getHeight, getWidth and getDepth \u2013 will score 3 points, because their longest common prefix is \u201cget\u201d, which has three characters<\/p><p>However, a file that exposes the following functions \u2013 pairs, invert and invoke \u2013 will score no points because the names have no common prefix.<\/p><p>So given a set of function names and K, the number of functions a file should contain, what would be the maximum score possible by spreading the functions into N\/K files, with K functions in each file?<\/p><p>Note that you don\u2019t need to say which functions go into which files. You just need to know the score they would have.<br>Input<\/p><p>The first line will have an integer T, which is the number of cases for the problem. It is followed by a description of T cases. Every case has a line with two integers N and K. There are N lines following that each have a function name as a string.<br>Output<\/p><p>For each case, there should be a line starting with \u201cCase #x: y\u201d, where x is the test case number (starting with 1) and y is the maximum score that can be achieved.<br>Limits<\/p><p>T = 100<br>1 \u2264 K \u2264 N \u2264 1000<br>N mod K == 0<br>function names length \u2264 50<\/p><\/blockquote>\n\n\n\n<p>Resolution code: <a href=\"https:\/\/github.com\/botmakerdvd\/code_challenge_2021\/blob\/master\/11\/11.py\">https:\/\/github.com\/botmakerdvd\/code_challenge_2021\/blob\/master\/11\/11.py<\/a><\/p>\n\n\n\n<p>Este algoritmo es bastante simple, y utilizando listas ordenadas en python, este reto es bastante asequible.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"challenge-12-the-crypto-bubble\"><strong>Challenge 12<\/strong> \u2013 The crypto bubble<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>We all know that cryptocurrencies is a market that is growing exponentially. That\u2019s why your friend Jonathan got the idea of trying to scrape several crypto trading websites to find a bug he can profit from.<\/p><p>His idea is to find out whether you can increase the amount of the coins you initially invested by exchanging different cryptocurrencies between different websites. Your friend Jonathan is a very good programmer, but algorithms aren\u2019t his strong suit. That\u2019s why he\u2019s asking for your help.<\/p><p>He agrees to create a file with all the cryptocurrency exchange information from the different websites. And he\u2019s asking you to develop an algorithm to figure out whether it\u2019s possible to get rich by exchanging coins.<\/p><p>Jonathan only has one BTC and he wants to get more. Exchanges must start and end in BTC, but any other cryptocurrency can be used in the intermediate steps. Exchanging a cryptocurrency can take a very long time, so you should try to do as few exchanges as possible. If there are multiple paths with the same number of exchanges, you should choose the most profitable one. In other words, you need to find the shortest exchange loop that gives you more bitcoin than when you started even if another longer loop may be more profitable.<br>Input<\/p><p>After some tough negotiating you reach an agreement on what the file format will be like.<\/p><p>The first line has the number N of different cases<br>The N cases start after that line:<br>Each case starts with a number M, which is the number of websites in the case.<br>Then the websites datai starts:<br>Each website data block starts with a line that has the website name (a string of characters without white space) and K (the number of available trades).<br>The K available trades are described after the name.<br>Each trade is declared on one line with the crypto acronym followed by a dash then an integer D, another dash and finally the other crypto acronym.<br>An example trade line would be: BTC-2-ETH<br>What does a trade line mean? In the example above one BTC is exchanged for two ETH. But it doesn\u2019t mean two ETH can be exchanged for one BTC.<\/p><p>Output<\/p><p>For each case, there should be a line starting with \u201cCase #N: Z\u201d, where N is the case number and Z is a number. Z must be the final amount of BTC you end up with after doing one iteration on the chosen path. If there are no paths that generate a profit the final amount must be the starting amount, in this case \u201c1\u201d.<\/p><\/blockquote>\n\n\n\n<p>Resolution code: <a href=\"https:\/\/github.com\/botmakerdvd\/code_challenge_2021\/blob\/master\/12\/12.py\">https:\/\/github.com\/botmakerdvd\/code_challenge_2021\/blob\/master\/12\/12.py<\/a><\/p>\n\n\n\n<p>De nuevo la Teoria de Grafos aparece por aqu\u00ed, y de nuevo utilizo la librer\u00eda networkx para resolver este problema.<\/p>\n\n\n\n<p>Inicialmente todas las conversiones se a\u00f1aden como vertices al grafo, siempre que tengan un tipo de cambio diferente de 0 claro.<\/p>\n\n\n\n<p>A continuaci\u00f3n se obtienen todos los caminos desde BTC a BTC y se incluyen en una lista. Lista que ordenamos basandonos en lo largo de cada camino.<\/p>\n\n\n\n<p>Por \u00faltimo se calcula la ganancia en cada uno de esos caminos ordenados y una vez que obtienes una ganancia &gt; 1, el programa termina.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"challenge-13-find-the-new-earth\"><strong>Challenge 13<\/strong> \u2013 Find the New Earth<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u2014 So, where are we going now, Captain? \u2014 asked the young soldier.<br>\u2014 You know where, answered Adama. Let\u2019s go to our New Earth.<br>\u2014 Yes, Sir. But what are the coordinates?<\/p><p>After a long fight, Battlestar Galactica and its crew deserve to reach New Earth, the new home they\u2019ve chosen for themselves. And to get there, all they need is the position. The coordinates (15 numbers in a row) are somehow hidden here. But the only hint they have is this:<\/p><p>plyba:xvyy_nyy_uhznaf<\/p><p>Will you help the young soldiers find the coordinates so they can reach New Earth?<br>Input<br>No input needed<br>Output<\/p><p>A 15 digit string of numbers<\/p><p>Example:<\/p><p>123456789012345<\/p><\/blockquote>\n\n\n\n<p>Resolution code: <a href=\"https:\/\/github.com\/botmakerdvd\/code_challenge_2021\/blob\/master\/13\/13.py\">https:\/\/github.com\/botmakerdvd\/code_challenge_2021\/blob\/master\/13\/13.py<\/a><\/p>\n\n\n\n<p>Otro reto de Hacking<\/p>\n\n\n\n<p>Met\u00ed \u201cuhznaf to text\u201d en google y el segundo resultado hablaba sobre ROT13, por lo que introduje plyba:xvyy_nyy_uhznaf en https:\/\/codebeautify.org\/rot13-to-text-converter y obtuve:<\/p>\n\n\n\n<p>cylon:kill_all_humans<\/p>\n\n\n\n<p>con este usuario y contrase\u00f1a pude entrar al sitio web de donde descargu\u00e9 un fichero que descomprim\u00ed.<\/p>\n\n\n\n<p>Finalmente un peque\u00f1o c\u00f3digo convirti\u00f3 ese fichero en el string de 15 n\u00fameros.<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/www.davidestebanmunoz.com\/?p=268&#038;lang=es\">Read More<span class=\"screen-reader-text\">Participaci\u00f3n en el Telefonica Code Challenge 2021<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[116,107,114,67,112],"class_list":["post-268","post","type-post","status-publish","format-standard","hentry","category-proyectos-personales","tag-analisis-de-red","tag-code-challenge-es","tag-hacking-es","tag-python-es","tag-reversing-es","excerpt"],"_links":{"self":[{"href":"https:\/\/www.davidestebanmunoz.com\/index.php?rest_route=\/wp\/v2\/posts\/268","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.davidestebanmunoz.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.davidestebanmunoz.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.davidestebanmunoz.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.davidestebanmunoz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=268"}],"version-history":[{"count":4,"href":"https:\/\/www.davidestebanmunoz.com\/index.php?rest_route=\/wp\/v2\/posts\/268\/revisions"}],"predecessor-version":[{"id":275,"href":"https:\/\/www.davidestebanmunoz.com\/index.php?rest_route=\/wp\/v2\/posts\/268\/revisions\/275"}],"wp:attachment":[{"href":"https:\/\/www.davidestebanmunoz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=268"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.davidestebanmunoz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=268"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.davidestebanmunoz.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}