From ab8a5e7079755622e9254c96977b3baec49a2f75 Mon Sep 17 00:00:00 2001 From: vaz-rodrigo Date: Tue, 22 Mar 2016 14:26:59 -0300 Subject: [PATCH 01/11] Typed the challenge from the subreddit. Can someone check the formatting? --- .../challenge_text.md | 52 ++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/Extra-Bonus Challenges/Challenge #207 [Bonus] Erdos Number Calculator/challenge_text.md b/Extra-Bonus Challenges/Challenge #207 [Bonus] Erdos Number Calculator/challenge_text.md index c5c3c75..46d8e9d 100644 --- a/Extra-Bonus Challenges/Challenge #207 [Bonus] Erdos Number Calculator/challenge_text.md +++ b/Extra-Bonus Challenges/Challenge #207 [Bonus] Erdos Number Calculator/challenge_text.md @@ -1 +1,51 @@ -trash \ No newline at end of file +# [](#BonusIcon) _(Bonus)_: Erdos Number Calculator + +In honor of the 102nd birthday of the famous mathematician, a problem named after him. + +## Description + +Paul Erdős (1913–1996) was an influential mathematician who spent a large portion of his later life writing papers with a large number of colleagues, working on solutions to outstanding mathematical problems. The idea of the Erdős number was originally created by the mathematician's friends as a tribute to his enormous output. However, in later years it gained prominence as a tool to study how mathematicians cooperate to find answers to unsolved problems. +The Erdös number describes the "collaborative distance" between mathematician Paul Erdős and another person, as measured by authorship of mathematical papers. Erdös himself has a number of 0, anyone he co-authored a paper with has a number of 1, anyone they co-authored a paper with (without Erdös) has a number of 2, and so forth. +Several studies have shown that leading mathematicians tend to have particularly low Erdős numbers. For example, only 134,007 mathematicians have an Erdős number, with a median value of 5. In contrast, the median Erdős number of Fields Medalists is 3. Only 7,097 (about 5%) of mathematicians with a collaboration path have an Erdős number of 2 or less. +For this challenge you'll be working with a small, toy database of Erdős and related publications and be asked to calculate the Erdős number for several authors. + +## Input Description + +You'll be given 2 integers on the first line, N and M. N is the number of of papers in APA format showing authors, titles, journals, and the like; think of it as a mini database. M is the number of authors to identify the Erdős number for. Note that all of the names should be in the same format of last name, then first and middle initials. + +## Output Description + +Your program should emit the name of the mathematician and their Erdős number. + +# Sample Inputs and Outputs + +## Sample Input + + 7 4 + Thomassen, C., Erdös, P., Alavi, Y., Malde, P. J., & Schwenk, A. J. (1989). Tight bounds on the chromatic sum of a connected graph. Journal of Graph Theory, 13(3), 353-357. + Burr, S., Erdös, P., Faudree, R. J., Rousseau, C. C., & Schelp, R. H. (1988). Some complete bipartite graph—tree Ramsey numbers. Annals of Discrete Mathematics, 41, 79-89. + Burris, A. C., & Schelp, R. H. (1997). Vertex-distinguishing proper edge-colorings. Journal of graph theory, 26(2), 73-82. + Balister, P. N., Gyo˝ ri, E., Lehel, J., & Schelp, R. H. (2007). Adjacent vertex distinguishing edge-colorings. SIAM Journal on Discrete Mathematics, 21(1), 237-250. + Erdös, P., & Tenenbaum, G. (1989). Sur les fonctions arithmétiques liées aux diviseurs consécutifs. Journal of Number Theory, 31(3), 285-311. + Hildebrand, A., & Tenenbaum, G. (1993). Integers without large prime factors. Journal de théorie des nombres de Bordeaux, 5(2), 411-484. + Balister, P. N., Riordan, O. M., & Schelp, R. H. (2003). Vertex‐distinguishing edge colorings of graphs. Journal of graph theory, 42(2), 95-109. + Schelp, R. H. + Burris, A. C. + Riordan, O. M. + Balister, P. N. + +## Sample Output + + Schelp, R. H. 1 + Burris, A. C. 2 + Riordan, O. M. 2 + Balister, P. N. 2 + +# Notes + +This challenge is a shameless rip off of [*this*](http://www.programming-challenges.com/pg.php?page=downloadproblem&format=html&probid=110206). It was too good to pass up; I did, however, compile my own challenge inputs and outputs. +A full list of Erdös publications is up [*here*](http://www.renyi.hu/~p_erdos/Erdos.html). + +# Finally + +Got any cool challenge ideas? Submit them to /r/DailyProgrammer_Ideas! From e403aebb960ccfe71396d293092268ea1f53871c Mon Sep 17 00:00:00 2001 From: vaz-rodrigo Date: Tue, 22 Mar 2016 14:50:38 -0300 Subject: [PATCH 02/11] Update challenge_text.md --- .../challenge_text.md | 105 +++++++++++++++++- 1 file changed, 104 insertions(+), 1 deletion(-) diff --git a/Easy Challenges/Challenge #0166b [Easy] Planetary Gravity Calculator/challenge_text.md b/Easy Challenges/Challenge #0166b [Easy] Planetary Gravity Calculator/challenge_text.md index c5c3c75..2dd5fd5 100644 --- a/Easy Challenges/Challenge #0166b [Easy] Planetary Gravity Calculator/challenge_text.md +++ b/Easy Challenges/Challenge #0166b [Easy] Planetary Gravity Calculator/challenge_text.md @@ -1 +1,104 @@ -trash \ No newline at end of file +# Description + +Welcome to this week's rebooted challenges. While this challenge is very simple at its core (which I think gives it an Easy rating), it gives me a chance to teach a bit of physics while I'm at it, so I may as well! +Newton's Law of Universal Gravitation says that: +Any two objects in the universe attract **each other** gravitationally... +With a force that's proportional to the product of their masses, and... +Inversely proportional to the square of the distance between them. (distance is measured from the center of the object - so if you're standing on Earth, you are about 6353 km away from it. +Because this is only a proportionality (not an equality), you will need a constant multiplier - this is called G, the gravitational constant. +This gives us the remarkably simple formula: +``` + mass of first object × mass of second object + force = G × -------------------------------------------- + (distance between objects)² +``` +This force is applied on both objects equally and in opposite directions, toward each other. The value of G is currently known to be about **6.67e-11** which is why gravity is so weak - you can overcome the force of the entire planet just by jumping! +These 4 simple rules were used to describe gravity in nearly its entirety before Albert Einstein found out it was incomplete and discovered Special and General relativity - which you won't need today! Anyway, this is the only bit of physics you'll need for today's challenge - the rest is basic maths. + +We're going to assume all planets are perfect spheres. This means you can find the volume of a planet, given its radius, with the fomula `V = 4/3 × π × radius³` like a normal sphere. We'll also assume they are made of a material which has the exact same density everywhere - so a handful of material from one bit of the planet weighs the same as any other. This means, given a density (in kilograms per cubic metre), and using the volume you worked out, you can compute the mass of the planet with the formula `mass = volume × density`. Assume the units you are using are kilograms and metres. Sorry, imperial folk! + +Now, in case you are new to physics, you may need to know a little bit about forces. Forces are measured in Newtons (N) and measure, essentially, how hard an object is pushing another object. The object could be pushing physically - eg. pushing a lawn mower - or via an elementary force, such as Earth's gravity pushing you toward it. They can all be measured in Newtons. The force of a planet on something due to gravity is called weight - which is not to be confused with [mass](https://en.wikipedia.org/wiki/Mass), which is measured in kilograms and is a measure of how much matter something contains. As we saw before, the more mass two objects have, the greater the force they exert on each other. As gravitational force is dependent on the product of the masses of both objects, an object will weigh more if either the object itself, or the planet, is heavier - which is why you weigh less on the Moon! + +Anyway, after that lengthy backstory, the challenge for you today is, given the dimensions of several planets and an object's mass, calculate how much force is applied on the object at the surface of the planet. Pretend the object is quite small for simplicity of your caluclations. + +This is certainly a lot of physics to get your teeth into, so if you need any help, leave a comment and either I or someone else should be happy to help you out. + +## Input Description + +You will be given a number M which is the mass of an object in kilograms, on its own line, for example: +``` +100 +``` + +Followed by a number N: +``` +4 +``` + +You will then, on separate lines, be given a list of N planets. This will be given as its name, its radius (in metres), and its average density (in kilograms per cubic metre), like so: +``` +Mercury, 2439700, 5427 +``` + +## Output Description + +Print the weight (in Newtons) of the object if it were at the surface of each planet, like so: +``` +Mercury: 314.623 +``` + +#Example Inputs and Outputs + +## Example Input +``` +100 +4 +Tantalus, 3104500, 5009 +Reach, 7636500, 4966 +Circumstance, 4127000, 4132 +Tribute, 2818000, 4358 +``` +## Example output +``` +Tantalus: 434.467 +Reach: 1059.536 +Circumstance: 476.441 +Tribute: 343.117 +``` +# Challenge + +## Challenge Input + +``` +75 +9 +Mercury, 2439700, 5427 +Venus, 6051900, 5243 +Earth, 6367445, 5515 +Mars, 3386000, 3934 +Jupiter, 69173000, 1326 +Saturn, 57316000, 687 +Uranus, 25266000, 1270 +Neptune, 24553000, 1638 +Pluto, 1173000, 2050 +``` + +## Expected Challenge Output + +``` +Mercury: 277.442 +Venus: 664.886 +Earth: 735.845 +Mars: 279.124 +Jupiter: 1922.011 +Saturn: 825.103 +Uranus: 672.382 +Neptune: 842.741 +Pluto: 50.388 +``` + +(These values are all very nearly exact!) + +# Notes + +You have a chance to utilise some OOP here. If your programming language supports it, you may want to create a *Planet* object. From 240f2c8b0452348accf310dff83127625adcac81 Mon Sep 17 00:00:00 2001 From: vaz-rodrigo Date: Tue, 22 Mar 2016 15:17:50 -0300 Subject: [PATCH 03/11] Update challenge_text.md --- .../challenge_text.md | 60 ++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/Easy Challenges/Challenge #0214 [Easy] Calculating the standard deviation/challenge_text.md b/Easy Challenges/Challenge #0214 [Easy] Calculating the standard deviation/challenge_text.md index c5c3c75..6024103 100644 --- a/Easy Challenges/Challenge #0214 [Easy] Calculating the standard deviation/challenge_text.md +++ b/Easy Challenges/Challenge #0214 [Easy] Calculating the standard deviation/challenge_text.md @@ -1 +1,59 @@ -trash \ No newline at end of file +#Description + +**Standard deviation** is one of the most basic measurments in statistics. For some collection of values (known as a "population" in statistics), it measures how dispersed those values are. If the standard deviation is high, it means that the values in the population are very spread out; if it's low, it means that the values are tightly clustered around the mean value. +For today's challenge, you will get a list of numbers as input which will serve as your statistical population, and you are then going to calculate the standard deviation of that population. There are statistical packages for many programming languages that can do this for you, but you are highly encouraged not to use them: the spirit of today's challenge is to implement the standard deviation function yourself. +The following steps describe how to calculate standard deviation for a collection of numbers. For this example, we will use the following values: +``` +5 6 11 13 19 20 25 26 28 37 +``` + +1. First, calculate the average (or **mean**) of all your values, which is defined as the sum of all the values divided by the total number of values in the population. For our example, the sum of the values is 190 and since there are 10 different values, the mean value is 190/10 = 19 +2. Next, for each value in the population, calculate the difference between it and the mean value, and square that difference. So, in our example, the first value is 5 and the mean 19, so you calculate (5 - 19)2 which is equal to 196. For the second value (which is 6), you calculate (6 - 19)2 which is equal to 169, and so on. +3. Calculate the sum of all the values from the previous step. For our example, it will be equal to 196 + 169 + 64 + ... = 956. +4. Divide that sum by the number of values in your population. The result is known as the variance of the population, and is equal to the square of the standard deviation. For our example, the number of values in the population is 10, so the **variance** is equal to 956/10 = 95.6. +5. Finally, to get standard deviation, take the square root of the variance. For our example, sqrt(95.6) ≈ 9.7775. + +# Formal inputs & outputs + +## Input +The input will consist of a single line of numbers separated by spaces. The numbers will all be positive integers. + +## Output +Your output should consist of a single line with the standard deviation rounded off to at most 4 digits after the decimal point. + +# Sample inputs & outputs + +## Sample 1 +### Input +``` +5 6 11 13 19 20 25 26 28 37 +``` +### Output +``` +9.7775 +``` + +## Sample 2 +### Input +``` +37 81 86 91 97 108 109 112 112 114 115 117 121 123 141 +``` +### Output +``` +23.2908 +``` + +# Challenge Inputs +## Input 1 +``` +266 344 375 399 409 433 436 440 449 476 502 504 530 584 587 +``` +## Input 2 +``` +809 816 833 849 851 961 976 1009 1069 1125 1161 1172 1178 1187 1208 1215 1229 1241 1260 1373 +``` + +# Notes + +For you statistics nerds out there, note that this is the population standard deviation, not the sample standard deviation. We are, after all, given the entire population and not just a sample. +If you have a suggestion for a future problem, head on over to [/r/dailyprogrammer_ideas](https://www.reddit.com/r/dailyprogrammer_ideas) and let us know about it! From fdb246472eaa12d9733b373d7e86e1d915ab8531 Mon Sep 17 00:00:00 2001 From: vaz-rodrigo Date: Tue, 22 Mar 2016 15:39:44 -0300 Subject: [PATCH 04/11] Update challenge_text.md --- .../challenge_text.md | 115 +++++++++++++++++- 1 file changed, 114 insertions(+), 1 deletion(-) diff --git a/Hard Challenges/Challenge #0248 [Hard] NotClick game/challenge_text.md b/Hard Challenges/Challenge #0248 [Hard] NotClick game/challenge_text.md index c5c3c75..caa4916 100644 --- a/Hard Challenges/Challenge #0248 [Hard] NotClick game/challenge_text.md +++ b/Hard Challenges/Challenge #0248 [Hard] NotClick game/challenge_text.md @@ -1 +1,114 @@ -trash \ No newline at end of file +# Description + +Click games such as [Cookie Clicker](http://orteil.dashnet.org/cookieclicker/) are resource games where, part of the game, is obtaining free resources limited by how fast you can repeatedly click for them. +Today's challenge simulates these games with a constant 1 click per second, and a build order queue. Allowing the game to be played in a console, and finish "instantly". +For our game, cookies is the name of the generated resources. + +# Setup +For each line in this input, each word is: +1. Name of building (can be discarded or split into its own array for formatting use) +2. Cost for first building purchase. +3. Number of Cookies each building generates. +4. Number of extra cookies the building generates on first upgrade. (all subsequent upgrades double production) +5. Cost of first upgrade. + +## Setup Input +``` +cursor 12 0.1 0.1 100 +grandma 100 0.8 0.3 1000 +farm 500 4 1 10000 +mine 1000 10 3 50000 +factory 5000 40 10 200000 +bank 100000 100 40 5000000 +temple 1000000 400 100 100000000 +city 300000000 5000 2000 1000000000 +``` +Not in input are 2 constants for each line. +1. The cost growth rate of each new building. Fixed at 1.2 (20% cost growth per purchase of the same building) +2. The cost growth rate of each upgrade. Fixed at 3 (200% cost increase for each upgrade of the same building) +``` +┌────────┬─────────┬────┬──────┬────────────┬────────────┬────────────┐ +│BUILDING│COST1 │PROD│BOOST1│UPGRADE_cOST│BCOST_GROWTH│UCOST_GROWTH│ +├────────┼─────────┼────┼──────┼────────────┼────────────┼────────────┤ +│cursor │12 │0.1 │0.1 │100 │1.2 │3 │ +├────────┼─────────┼────┼──────┼────────────┼────────────┼────────────┤ +│grandma │100 │0.8 │0.3 │1000 │1.2 │3 │ +├────────┼─────────┼────┼──────┼────────────┼────────────┼────────────┤ +│farm │500 │4 │1 │10000 │1.2 │3 │ +├────────┼─────────┼────┼──────┼────────────┼────────────┼────────────┤ +│mine │1000 │10 │3 │50000 │1.2 │3 │ +├────────┼─────────┼────┼──────┼────────────┼────────────┼────────────┤ +│factory │5000 │40 │10 │200000 │1.2 │3 │ +├────────┼─────────┼────┼──────┼────────────┼────────────┼────────────┤ +│bank │100000 │100 │40 │5000000 │1.2 │3 │ +├────────┼─────────┼────┼──────┼────────────┼────────────┼────────────┤ +│temple │1000000 │400 │100 │100000000 │1.2 │3 │ +├────────┼─────────┼────┼──────┼────────────┼────────────┼────────────┤ +│city │300000000│5000│2000 │1000000000 │1.2 │3 │ +└────────┴─────────┴────┴──────┴────────────┴────────────┴────────────┘ +``` +# Simulation +Your challenge is to create a function that models resources after each turn. It has 2 inputs: +1. the number of iterations (turns) to run the simulation. +2. A queue of building and upgrade orders coded as 0-7, for a building order (0 = cursor, 1 = grandma etc...) and 100-107 for an upgrade (100 = upgrade cursor, 101 = upgrade grandma ...) + +The simulation order is: +1. Add resources created from buildings. +2. Add automatic resources from turn: These are from the 1 click per turn. **turn resources = 1 + resources from "cursors building"** +3. If there is enough resources to buy the first building or upgrade in queue, then it is bought, and the total number of owned buildings or upgrades of that type is increased by one, and the cost of the building or upgrade reduced from cash/cookie balance. **this can be done on same turn resources above came in**. Can only build one building per turn. +Its recommended that you track `turns passed` `total resources collected` + +To play the game, you probably need to track the current costs of each purchase option as well as production rates of each option. To choose which option has the highest ROI. +``` + 1000 G 0 0 0 1 0 0 0 100 0 0 0 2 0 100 0 0 1 0 0 100 0 0 100 0 0 0 3 3 0 3 1 1 4 3 2 3 4 2 4 3 2 4 0 1 +┌───────┬───────┬───────┬──────┬───────┬───────┬──────┬──────┬────┬──────┬───────┬─────┬─────┬───────┬────┬──────┬────┐ +│CPS │cursor │grandma│farm │mine │factory│bank │temple│city│cursor│grandma│farm │mine │factory│bank│temple│city│ +├───────┼───────┼───────┼──────┼───────┼───────┼──────┼──────┼────┼──────┼───────┼─────┼─────┼───────┼────┼──────┼────┤ +│308.2 │552.061│248.832│1036.8│2985.98│10368 │100000│1e6 │3e8 │8100 │1000 │10000│50000│200000 │5e6 │1e8 │1e9 │ +├───────┼───────┼───────┼──────┼───────┼───────┼──────┼──────┼────┼──────┼───────┼─────┼─────┼───────┼────┼──────┼────┤ +│1024.05│33.6 │4 │16 │60 │160 │0 │0 │0 │1.6 │0.8 │4 │10 │40 │100 │400 │5000│ +└───────┴───────┴───────┴──────┴───────┴───────┴──────┴──────┴────┴──────┴───────┴─────┴─────┴───────┴────┴──────┴────┘ +┌─────┬──────┬───────┬─┬────────────────┬───────────────┬─────┐ +│turns│gen │CASH │M│Builds │Upgrades │Queue│ +├─────┼──────┼───────┼─┼────────────────┼───────────────┼─────┤ +│1000 │118484│71585.4│1│21 5 4 6 4 0 0 0│4 0 0 0 0 0 0 0│ │ +└─────┴──────┴───────┴─┴────────────────┴───────────────┴─────┘ +``` +The 2nd table output is the same as sample input #1. +After 1000 turns, $71585 cash balance is generated, from 21 cursors, 5 grandmas 4 farms, 6 mines, and 4 factories, with cursors upgraded 4 times. The queue has been emptied of all orders. +The first table, ommitting the first column, has buidling then upgrade info. The first row is the cost of the next building or upgrade. The 2nd row has the total production for each building type in the left half, and the per building production (by type) in the right half. +The first column CPS has in first row, total production rate per turn including special rules for cursors, and in 2nd row, an indicator formula I thought might be useful CPS + CASH / 100 + +# Challenge 0 (sample with output) + +What is the earliest turn you can build a farm (building 2)? +**output** The output is the function inputs, followed by the simulation results to show that the simulation results in the farm being built. There is a better solution (ie fewer turns than 300) than this (`300` iterations with queue `0 0 0 1 0 2`)that appears in a spoiler in the comments. +``` + 300 G 0 0 0 1 0 2 +┌───────┬───────┬───────┬────┬────┬───────┬──────┬──────┬────┬──────┬───────┬─────┬─────┬───────┬────┬──────┬────┐ +│CPS │cursor │grandma│farm│mine│factory│bank │temple│city│cursor│grandma│farm │mine │factory│bank│temple│city│ +├───────┼───────┼───────┼────┼────┼───────┼──────┼──────┼────┼──────┼───────┼─────┼─────┼───────┼────┼──────┼────┤ +│6.6 │24.8832│120 │600 │1000│5000 │100000│1e6 │3e8 │100 │1000 │10000│50000│200000 │5e6 │1e8 │1e9 │ +├───────┼───────┼───────┼────┼────┼───────┼──────┼──────┼────┼──────┼───────┼─────┼─────┼───────┼────┼──────┼────┤ +│6.60184│0.4 │0.8 │4 │0 │0 │0 │0 │0 │0.1 │0.8 │4 │10 │40 │100 │400 │5000│ +└───────┴───────┴───────┴────┴────┴───────┴──────┴──────┴────┴──────┴───────┴─────┴─────┴───────┴────┴──────┴────┘ +┌─────┬─────┬─────┬─┬───────────────┬───────────────┬─────┐ +│turns│gen │CASH │M│Builds │Upgrades │Queue│ +├─────┼─────┼─────┼─┼───────────────┼───────────────┼─────┤ +│300 │664.6│0.184│1│4 1 1 0 0 0 0 0│0 0 0 0 0 0 0 0│ │ +└─────┴─────┴─────┴─┴───────────────┴───────────────┴─────┘ +``` + +# Challenge 1 + +Find a build queue that generates over 100000 cash in 1000 turns. +# Challenge 2 + +Get enough cash to buy a city ($300M) in under 6300 turns. (or close to it if you can't make it) +Its ok to use tools such as the above to handcraft solutions. Solving this type of challenge automatically will be a later part 2 challenge. + +#Bonus, TBD + +~~A bonus for this challenge will be added later today. It involves adding special upgrades that interact with buildings/state in more comprehensive and intertwined manners.~~ + +Medals awarded: Gold to [u/fibonaci](https://www.reddit.com/u/fibonaci) and [u/godspiral](https://www.reddit.com/u/godspiral). Silvers to other solutions. From 28000c5708caa53f883626a3fbfde306629888bf Mon Sep 17 00:00:00 2001 From: vaz-rodrigo Date: Tue, 22 Mar 2016 15:54:20 -0300 Subject: [PATCH 05/11] Update challenge_text.md --- .../challenge_text.md | 143 +++++++++++++++++- 1 file changed, 142 insertions(+), 1 deletion(-) diff --git a/Hard Challenges/Challenge #0241 [Hard] Chess Puzzle solver/challenge_text.md b/Hard Challenges/Challenge #0241 [Hard] Chess Puzzle solver/challenge_text.md index c5c3c75..560ab65 100644 --- a/Hard Challenges/Challenge #0241 [Hard] Chess Puzzle solver/challenge_text.md +++ b/Hard Challenges/Challenge #0241 [Hard] Chess Puzzle solver/challenge_text.md @@ -1 +1,142 @@ -trash \ No newline at end of file +# Getting out of check + +Wednesday's challenge 2 (listing pieces that have black king in check) was pretty hard, but getting that one will get you through 2/3rds of this challenge. +A good source of puzzles is this [site](https://www.sparkchess.com/chess-puzzles.html), and the first one is this first challenge: +``` + toascii'1r3rkR/1pnnq1b1/p1pp2B1/P2P1p2/1PP1pP2/2B3P1/5PK1/2Q4R' +.r...rkR +.pnnq.b. +p.pp..B. +P..P.p.. +.PP.pP.. +..B...P. +.....PK. +..Q....R +``` +In this position the black king is in check by the rook at *h8*. There is only one legal move to get out of this one. But in general, the algorithm to get out of check is: + +1. If 2 pieces are "checking" the king, then the king must move. +2. If 1 piece is checking, then capturing that piece also removes the check. +3. if 1 piece is checking and it is a queen, rook or bishop, then putting a piece in between the king and checker gets out of check. + +It is perfectly reasonable also to try all possible moves filtered by those that result in not being in check anymore. If there is no legal move to get out of check then the condition is called mate, and that side has lost. + +For the purpose of these challenges, you do not need to consider castling, 2 space pawn moves, en-passant capture, or pawn promotion. All positions are white to move first, and white is the one looking to check and mate, and black the one running away. + +\** what move gets black out of check \** + +#Finding a move that causes check + +This position is one move prior to last one. +``` + toascii'1r3rk1/1pnnq1bR/p1pp2B1/P2P1p2/1PP1pP2/2B3P1/5PK1/2Q4R' +.r...rk. +.pnnq.bR +p.pp..B. +P..P.p.. +.PP.pP.. +..B...P. +.....PK. +..Q....R +┌─┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐ +│8│ │@...@│ │.....│ │@...@│ @ │.....│ +│ │ │@@@@@│ │.....│ │@@@@@│@@@@@│.....│ +│ │ │.@@@.│ │.....│ │.@@@.│ @@@ │.....│ +│ │ │.@@@.│ │.....│ │.@@@.│@@@@@│.....│ +├─┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤ +│7│.....│ │.@@@.│ @@@ │@.@.@│ │..@..│O O│ +│ │.....│ @ │@@@@.│@@@@ │@@@@@│ │.@@@.│OOOOO│ +│ │.....│ @ │..@..│ @ │.@@@.│ │..@..│ OOO │ +│ │.....│ @@@ │@@@@.│@@@@ │@...@│ │..@..│ OOO │ +├─┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤ +│6│ │.....│ │.....│ │.....│ O │.....│ +│ │ @ │.....│ @ │..@..│ │.....│ OOO │.....│ +│ │ @ │.....│ @ │..@..│ │.....│ O │.....│ +│ │ @@@ │.....│ @@@ │.@@@.│ │.....│ O │.....│ +├─┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤ +│5│.....│ │.....│ │.....│ │.....│ │ +│ │..O..│ │.....│ O │.....│ @ │.....│ │ +│ │..O..│ │.....│ O │.....│ @ │.....│ │ +│ │.OOO.│ │.....│ OOO │.....│ @@@ │.....│ │ +├─┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤ +│4│ │.....│ │.....│ │.....│ │.....│ +│ │ │..O..│ O │.....│ @ │..O..│ │.....│ +│ │ │..O..│ O │.....│ @ │..O..│ │.....│ +│ │ │.OOO.│ OOO │.....│ @@@ │.OOO.│ │.....│ +├─┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤ +│3│.....│ │..O..│ │.....│ │.....│ │ +│ │.....│ │.OOO.│ │.....│ │..O..│ │ +│ │.....│ │..O..│ │.....│ │..O..│ │ +│ │.....│ │..O..│ │.....│ │.OOO.│ │ +├─┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤ +│2│ │.....│ │.....│ │.....│ O │.....│ +│ │ │.....│ │.....│ │..O..│OOOOO│.....│ +│ │ │.....│ │.....│ │..O..│ OOO │.....│ +│ │ │.....│ │.....│ │.OOO.│OOOOO│.....│ +├─┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤ +│1│.....│ │O.O.O│ │.....│ │.....│O O│ +│ │.....│ │OOOOO│ │.....│ │.....│OOOOO│ +│ │.....│ │.OOO.│ │.....│ │.....│ OOO │ +│ │.....│ │O...O│ │.....│ │.....│ OOO │ +├─┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤ +│ │a │b │c │d │e │f │g │h │ +└─┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘ +``` +here it is white's turn to play, and there are 3 moves that will result in check. + +The most general recommended strategy is to try all possible moves, but for complete possibilities. + +1. The positions that a king would be in check by a specific type of piece that a such a piece can move to. Intersection of those 2 sets for each piece type. +2. In the case of a Queen, Bishop or Rook, if the piece is already in the same row, column or diagonal as the king, and there is only 1 piece between the 2, and that piece is white (attacker's colour) then moving that piece out of the way will result in check. This is the only case that can result in double check on the king. + +\** what 3 (white) moves gets black into check \** + +#Chess puzzle solver + +By repeatedly playing white and black sides in a breadth first search until a mate is forced, the shortest move sequence until mate can be found. + +All of these solutions have check moves by white. + +**Sample input** + +`1r3rk1/1pnnq1bR/p1pp2B1/P2P1p2/1PP1pP2/2B3P1/5PK1/2Q4R` + +3 check options, 1 black reply line. mate in 2. + +**Sample output** +``` +h7-h8 g7-h8 h1-h8 +``` + +**challenge inputs** +``` +1r3k2/2n1p1b1/3p2QR/p1pq1pN1/bp6/7P/2P2PP1/4RBK1 +``` +solution has 5 check options, 2 reply lines + +``` +r2q1k1r/ppp1bB1p/2np4/6N1/3PP1bP/8/PPP5/RNB2RK1 +``` +solution has 10 check options, 1 reply line + +``` +1k1r4/3b1p2/QP1b3p/1p1p4/3P2pN/1R4P1/KPPq1PP1/4r2R +``` +solution has 4 check options 1 reply line + +``` +r2r1n2/pp2bk2/2p1p2p/3q4/3PN1QP/2P3R1/P4PP1/5RK1 +``` +solution has 9 check options, 1 reply line + +#Bonus: Forcing moves that are not check. + +As long as the opponent cannot place you in check, and you would be able to check opposing king on next move, then your side (white) still has the initiative. +For these problems all legal moves for white can be considered. But a good filtering criteria would be moves where if white could play again (without Black's response turn) that a mate could be forced in a short time (with consecutive checks). + +**inputs** +``` +r2qrb2/p1pn1Qp1/1p4Nk/4PR2/3n4/7N/P5PP/R6K +``` + +Thanks to [/u/szerlok](https://www.reddit.com/u/szerlok) for this Challenge idea. If you have ideas for challenges, visit [/r/dailyprogrammer_ideas](https://www.reddit.com/r/dailyprogrammer_ideas) From 3f85e7f4a13368772e9692c7af84af9ca05b9af5 Mon Sep 17 00:00:00 2001 From: vaz-rodrigo Date: Tue, 22 Mar 2016 18:29:52 -0300 Subject: [PATCH 06/11] Update challenge_text.md --- .../challenge_text.md | 77 ++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/Hard Challenges/Challenge #0208 [Hard] The Universal Machine/challenge_text.md b/Hard Challenges/Challenge #0208 [Hard] The Universal Machine/challenge_text.md index c5c3c75..2e14b93 100644 --- a/Hard Challenges/Challenge #0208 [Hard] The Universal Machine/challenge_text.md +++ b/Hard Challenges/Challenge #0208 [Hard] The Universal Machine/challenge_text.md @@ -1 +1,76 @@ -trash \ No newline at end of file +# Description +Imagine an infinitely long, one-dimensional list of symbols. The list is infinite in both directions, and each symbol is indexed by a number, where the middle of the list is zero. This is called a **tape**. The symbols on the tape can be any symbol from an **alphabet**, which is just a set of possible symbols. If our example alphabet consists of the symbols `0`, `1` and `#`, then a valid tape would look like: +``` +#0110#10101#111#01## +| +``` +(The `|` marks the location of the middle of the tape, position zero.) Of course, we can't represent an infinite tape at once. Therefore, we add another possible symbol to our alphabet, `_` (underscore), to denote the lack of a symbol. This `_` symbol fills the rest of the tape, all the way out to infinity, like so (ellipsis denotes repeat): +``` +. . . _________________#0110#10101#111#01##_________________ . . . + | +``` +Now, imagine we have a **machine** that can look at this tape, but it can only see one symbol on the tape at once. To look at this tape, it has a **read head**. In our tape diagrams, the read head is marked with a caret (`^`). For example, here's the read head at position 7: +``` +#0110#10101#111#01## +| ^ +``` + +This read head can move one symbol to the left or right, but it can't skip ahead arbitrarily or jump to a specific location. Besides the read head, the machine also has a **state**. This is just an alphanumeric string, with no spaces, like a variable of the machine. It could be `Red`, it could be `Clockwise`, it could be `Catch22`, it could be `Tgnqovjaxbg`, as long as it's alphanumeric. + +Now, this machine is capable of performing a **step**. A step will change the symbol under the read head to another symbol from the alphabet, and then either move the read head left or right. The type of step that happens depends on the current state, and the current symbol under the read head. We can define a rule for our machine which says something like this: + + If the current symbol under the read head is **p**, and the current state is **A**, then change the state to **B**, change the symbol under the read head to **q** and move the read head in direction **d**. + +**p** and **q** can be the same symbol, and **A** and **B** can be the same state. For example: + + If the current symbol under the read head is `0`, and the current state is `State1`, then change the state to `State1`, change the symbol under the read head to `1` and move the read head left. + +This rule is called a **transition function**, and the typical notation is: +``` +𝛿(A, p) = (B, q, d) +``` + +So our example rule is: +``` +𝛿(State1, 0) = (State1, 1, <) +``` + +So, if our machine is in the state State1 and our tape looks like this: +``` +#0110#10101#111#01## +| ^ +``` +Then, after applying our transition function above, we're now in State1 (again) and the tape now looks like this: +``` +#0110#11101#111#01## +| ^ +``` + +You'll typically have quite a few transition functions to cover every possible state/symbol combination. After each step, the machine compares the new state to a special state known as the accepting state. If the current state is the accepting state, then the machine stops, as the computation is complete. + +Whew, that's a lot of information! Here's the synopsis of what you need to describe one of these machines: + +- The **alphabet**: all possible symbols (along with `_`, which is implicitly part of the alphabet.) +- The **tape** at the start of the computation. +- The **starting position** of the read head on the tape; this is assumed to be zero. +- The **list of possible** states that our machine can be in. +- The **starting state**, and the **accepting state**. +- A list of **transition functions**, that cover every possible symbol/state combination on the given tape. + +This type of machine is known as a [Turing machine](https://en.wikipedia.org/wiki/Turing_machine), named after the famous groundbreaking computer scientist and mathematician [Alan Turing](https://en.wikipedia.org/wiki/Alan_Turing). It sounds hopelessly verbose in practice, but a Turing machine is insanely useful as a theoretical model for computation. To gloss over quite a few details: if a machine can simulate any such Turing machine as described above, then it's described as **Turing-complete**. Today, you'll be writing a program to simulate a turing machine given the above required parameters; therefore, you'll need to use a Turing-complete language to solve this challenge. :) + +# Input Description + +First, you will be given the alphabet of a Turing machine (excluding _, which is always part of the alphabet) as a sequence of non-whitespace characters, like so: +``` +01 +``` +Next, you will be given a space-separated list of possible states for the machine, like this: +``` +Mov B Bi OK +``` +You will then be given the initial state, and the accepting state, on two lines: +Mov +OK +After this, you will be given the initial tape to use. The first character is assumed to be at position 0, with following characters at successive locations (1, 2, 3, etc.), like so: +01100100 From 3cfa324f18373802f197c45bb55688d53db04671 Mon Sep 17 00:00:00 2001 From: vaz-rodrigo Date: Tue, 22 Mar 2016 18:42:48 -0300 Subject: [PATCH 07/11] Update challenge_text.md --- .../challenge_text.md | 138 +++++++++++++++++- 1 file changed, 136 insertions(+), 2 deletions(-) diff --git a/Hard Challenges/Challenge #0208 [Hard] The Universal Machine/challenge_text.md b/Hard Challenges/Challenge #0208 [Hard] The Universal Machine/challenge_text.md index 2e14b93..349c6bb 100644 --- a/Hard Challenges/Challenge #0208 [Hard] The Universal Machine/challenge_text.md +++ b/Hard Challenges/Challenge #0208 [Hard] The Universal Machine/challenge_text.md @@ -59,9 +59,11 @@ Whew, that's a lot of information! Here's the synopsis of what you need to descr This type of machine is known as a [Turing machine](https://en.wikipedia.org/wiki/Turing_machine), named after the famous groundbreaking computer scientist and mathematician [Alan Turing](https://en.wikipedia.org/wiki/Alan_Turing). It sounds hopelessly verbose in practice, but a Turing machine is insanely useful as a theoretical model for computation. To gloss over quite a few details: if a machine can simulate any such Turing machine as described above, then it's described as **Turing-complete**. Today, you'll be writing a program to simulate a turing machine given the above required parameters; therefore, you'll need to use a Turing-complete language to solve this challenge. :) -# Input Description +# Formal Inputs and Outputs -First, you will be given the alphabet of a Turing machine (excluding _, which is always part of the alphabet) as a sequence of non-whitespace characters, like so: +## Input Description + +First, you will be given the alphabet of a Turing machine (excluding `_`, which is always part of the alphabet) as a sequence of non-whitespace characters, like so: ``` 01 ``` @@ -70,7 +72,139 @@ Next, you will be given a space-separated list of possible states for the machin Mov B Bi OK ``` You will then be given the initial state, and the accepting state, on two lines: +``` Mov OK +``` After this, you will be given the initial tape to use. The first character is assumed to be at position 0, with following characters at successive locations (1, 2, 3, etc.), like so: +``` +01100100 +``` +Finally, you're given a list of transition rules. These are in the format `StateBefore SymbolBefore = StateAfter SymbolAfter DirectionToMove`, like this list: +``` +Mov 0 = Mov 0 > +Mov 1 = Mov 1 > +Mov _ = B _ < +B 0 = B 0 < +B 1 = Bi 1 < +B _ = OK _ > +Bi 0 = Bi 1 < +Bi 1 = Bi 0 < +Bi _ = OK _ > +``` +The direction is either `<` for left, or `>` for right. + +## Output Description + +You are to output the tape after the computation has finished. You are also to output the symbol `|` (pipe) under the middle of the tape (position zero), and output the symbol `^` (caret) under the position of the read head after the computation has finished. If the `^` and `|` would be in the same place (ie. the read head finishes at the middle of the tape), just print only the `|`. +``` +10011100 +| +``` + +# Sample Turing Machines + +##Machine 1: Two's Complement + +This machine computes the two's complement of the binary number in the input. Notice how the transition functions can use the `_` symbol, even though it's not explicitly part of the alphabet. + +### Input +``` +01 +Mov B Bi OK +Mov +OK 01100100 +Mov 0 = Mov 0 > +Mov 1 = Mov 1 > +Mov _ = B _ < +B 0 = B 0 < +B 1 = Bi 1 < +B _ = OK _ > +Bi 0 = Bi 1 < +Bi 1 = Bi 0 < +Bi _ = OK _ > +``` + +### Output +``` +10011100 +| +``` + +## Machine 2: Moving Morse Code + +This machine takes input as dots (`.`) and dashes (`/`), including a delimiter symbol, `k`. The dots and dashes are moved to after the `k`. + +### Input +``` +./k +Init Mdot MDash Ret OK +Init +OK +/././../.../..../k +Init _ = Init _ > +Init . = Mdot _ > +Init / = MDash _ > +Init k = OK k > +Mdot . = Mdot . > +Mdot / = Mdot / > +Mdot k = Mdot k > +Mdot _ = Ret . < +MDash . = MDash . > +MDash / = MDash / > +MDash k = MDash k > +MDash _ = Ret / < +Ret . = Ret . < +Ret / = Ret / < +Ret k = Ret k < +Ret _ = Init _ > +``` + +###Output +``` +_________________k/././../.../..../ +| ^ +``` + +Notice all the spaces in the output, as the dots and dashes are now not centered on the middle of the tape. + +##Machine 3: Copying + +This machine takes a binary input string, including a delimiter symbol at the end. The binary string is copied to after the delimiter symbol. + +###Input +``` +01xy# +C0 C1 Ret Search OK +Search +OK +0110100# +Search 0 = C0 x > +Search 1 = C1 y > +Search # = OK # > +C0 0 = C0 0 > +C0 1 = C0 1 > +C0 # = C0 # > +C0 _ = Ret 0 < +C1 0 = C1 0 > +C1 1 = C1 1 > +C1 # = C1 # > +C1 _ = Ret 1 < +Ret 0 = Ret 0 < +Ret 1 = Ret 1 < +Ret # = Ret # < +Ret x = Search 0 > +Ret y = Search 1 > +``` + +###Output +``` +0110100#0110100 +| ^ +``` + +#Notes and Further Reading + +The Wolfram MathWorld [page on Turing Machines](http://mathworld.wolfram.com/TuringMachine.html) has some more description of the concept of turing machines. Sometimes cell 'colours' are used rather than 'symbols', but the over-arching concept is always the same. +Got any cool challenge ideas? Submit them to [/r/DailyProgrammer_Ideas](https://www.reddit.com/r/DailyProgrammer_Ideas)! From b333b45a6a4b3a1d1274f8ecdcc81f4aea556651 Mon Sep 17 00:00:00 2001 From: vaz-rodrigo Date: Tue, 22 Mar 2016 18:58:03 -0300 Subject: [PATCH 08/11] Update challenge_text.md --- .../challenge_text.md | 48 ++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/Hard Challenges/Challenge #0129 [Hard] Baking Pi/challenge_text.md b/Hard Challenges/Challenge #0129 [Hard] Baking Pi/challenge_text.md index c5c3c75..c51ff11 100644 --- a/Hard Challenges/Challenge #0129 [Hard] Baking Pi/challenge_text.md +++ b/Hard Challenges/Challenge #0129 [Hard] Baking Pi/challenge_text.md @@ -1 +1,47 @@ -trash \ No newline at end of file +# Description + +[Pi (π)](http://en.wikipedia.org/wiki/Pi), the super-cool irrational number, can be computed through a variety of ways. One way is using [continued fractions](http://en.wikipedia.org/wiki/Continued_fraction), which computes a more and more precise value of Pi over each iteration. The problem with this approach is you cannot distribute the work across several machines, because the computation itself cannot be split into smaller independent computations. + +This is where [Spigot Algorithms](http://en.wikipedia.org/wiki/Spigot_algorithm) shine: you can compute the subset of base-16 digits for some constants (like Pi) independently across many machines. More specifically, the [Bailey–Borwein–Plouffe](http://en.wikipedia.org/wiki/Bailey%E2%80%93Borwein%E2%80%93Plouffe_formula) formula allows you to compute digits of Pi without having to compute any preceding digits. + +Your goal is to write an application that computes base-16 digits of Pi across multiple machines over the Internet. You will have to implement a master dispatcher service, that sends out work commands and receives results, to networked machines that implement the BBP formula. The implementation details are up to you, including the network protocol and platform you want to write for. You must support at minimum four (4) machines computing in parallel, though for demonstration purposes you may run the processes locally on one machine. + +**Bonus:** As an extra bonus challenge, implement a verification feature (e.g. machine 1 computes a digit, then machines 2 & 3 verify it is valid). + +**Reddit Gold:** To thank Reddit for hosting such an awesome community, the first two valid solutions posted will win one-month of [Reddit Gold](http://www.reddit.com/gold/about). + +**Special Thanks:** Special thanks to Daily Programmer's Elite6809 for clarifying why this challenge must compute in base-16 (or in a base that's a power of two), and not in the original description's base-10. The challenge text has been updated to reflect the fix. + +# Formal Inputs & Outputs + +## Input Description + +There is no formal input description, though this is the desired behavior: +You launch your main dispatcher-application on Computer A. You then launch the computing-applications on Computer W, X, Y and Z. Computer A wants to compute the first four digits of Pi, and sends the appropriate network commands, one to each computer. Computer Y returns a result first, so the dispatcher receives the data, saves in your output file the line "0:2", and then gives the command to compute the 5th digit of Pi. Computers X, Z, W finish in that order, returning the results to the dispatcher, which in turn saves in the same format. They are then asked to compute digits 6, 7, and 8. This repeats until your dispatcher application sends a "stop" or "kill" command to the computing processes. It is up to you how many hexadecimal digits each process computes. + +## Output Description + +For each computed base-16 (hexadecimal) digit of Pi, write to a file a line of text in the format of \:\. The order does not matter, and you may skip digits. An example of the file, after eight computed digits, would be as follows: +``` +0:2 +1:4 +2:3 +3:F +4:6 +5:A +6:8 +7:8 +``` + +# Notes + +There are a few sites that already have large numbers of hexadecimal digits of Pi pre-computed; make sure to use them as a resource to validate your work! [Here's a great example on CalcCrypto](http://calccrypto.wikidot.com/math:pi-hex). Remember that these digits are in the Mantissa, so you compute the decimal values with negative exponent. As an example, the first 8 binary digits of Pi's Significand is "00100100". What would the decimal value be? Use the algebraic conversion formula: +``` +0 * 2^-1 + 0 * 2^-2 + 1 * 2^-3 + 0 * 2^-4 + 0 * 2^-5 + 1 * 2^-6 + 0 * 2^-7 + 0 * 2^-8 +``` + +The result here is "0.140625" (decimal), where the first two digits in the Significant are correct! We can apply the same for the above computed hex digits: (note how F was changed to 15 and A changed to 10, as appropriate) +``` +2 * 16^-1 + 4 * 16^-2 + 3 * 16^-3 + 15 * 16^-4 + 6 * 16^-5 + 10 * 16^-6 + 8 * 16^-7 + 8 * 16^-8 +``` +The result is "0.14159265346" (decimal), 9 decimal digits matching with Pi! From 453ab22aedecfd2d85e8dca2d8f1369378f1330c Mon Sep 17 00:00:00 2001 From: vaz-rodrigo Date: Tue, 22 Mar 2016 19:05:26 -0300 Subject: [PATCH 09/11] Update challenge_text.md --- .../challenge_text.md | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/Hard Challenges/Challenge #0121 [Hard] Medal Management/challenge_text.md b/Hard Challenges/Challenge #0121 [Hard] Medal Management/challenge_text.md index c5c3c75..51d4daf 100644 --- a/Hard Challenges/Challenge #0121 [Hard] Medal Management/challenge_text.md +++ b/Hard Challenges/Challenge #0121 [Hard] Medal Management/challenge_text.md @@ -1 +1,26 @@ -trash \ No newline at end of file +#Description + +The moderators of [/r/DailyProgrammer](https://www.reddit.com/r/DailyProgrammer) give out medals (either gold or silver) as community rewards / community achievements. Though everyone has the two medal icons next to their names, the actual amount you have are reflected as two integers (gold first, then silver). The side-bar to the right has a section titled "Achievements System", which describes how medals are earned. + +The problem though is that mods have to use the sub-Reddit's administration page to add the basic flair to a user and to change the medal count in any way. Though not hard, it certainly isn't a simple process, so we would like your help in building a better solution! + +Your goal is to write a single web-page in JavasScript that "wraps" these admin features together in a nice single form. Essentially it should be a page with **minimal server-side code** or **you can ditch the idea of a page and just make a browser add-on (Chrome or FireFox please)**, when given Reddit login credentials, allows: + +- Loading a user's flair string and type +- Saving a user's flair string and type +- Allowing a one-click +1 Gold and +1 Silver for any given Reddit username +- Load a user's [/r/DailyProgrammer](https://www.reddit.com/r/DailyProgrammer) post history for any given Reddit username + +Reddit provides an external API interface for these purposes: [learn more about the web-based API here](http://www.reddit.com/dev/api). + +**Though this will be a typical [hard] level challenge, we will be giving out a gold medal and Reddit gold (3 months) for the person who gives a fully-featured solution. Note that solutions must be open-source (hey, we want to use your system!) and you will be given full credits to it in our sub-Reddit's side-bar. Starting from today (Friday), all solutions are due in exactly 7 days: the competition ends at 11:55pm, American pacific time, UTC−8. It'll take about day to confirm who wins.** + +To help get started, check out these Reddit JavaScript APIs: (note that none are a "perfect" solution, and some heavy work will be required) + +- [Official Reddit API](http://www.reddit.com/dev/api) +- [Handson Reddit](https://github.com/timisbusy/handson-reddit) +- [Reddit JS Client](https://github.com/tommyvyo/reddit-js-client) + +This is quite a big challenge to take on, so I'll be much more involved with responding to questions and comments. Good luck, and have fun! + +**Edit 1**: Our awesome user [Skeeto](http://www.reddit.com/r/dailyprogrammer/comments/1dk7c7/05213_challenge_121_hard_medal_management/c9r4obj) has pointed out that a pure client-side implementation is not possible for security reasons; my bad! I've updated the rules to allow minimal server-side code or the choice of just making all of this a browser add-on. From b589e5bfe3163d74e12a8db3a3573fd1c1e19c46 Mon Sep 17 00:00:00 2001 From: vaz-rodrigo Date: Tue, 22 Mar 2016 19:07:55 -0300 Subject: [PATCH 10/11] Update challenge_text.md --- Hard Challenges/Challenge #0050 [Hard]/challenge_text.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Hard Challenges/Challenge #0050 [Hard]/challenge_text.md b/Hard Challenges/Challenge #0050 [Hard]/challenge_text.md index c5c3c75..74ae354 100644 --- a/Hard Challenges/Challenge #0050 [Hard]/challenge_text.md +++ b/Hard Challenges/Challenge #0050 [Hard]/challenge_text.md @@ -1 +1,5 @@ -trash \ No newline at end of file +# Description + +T9 Spelling: The Latin alphabet contains 26 characters and telephones only have ten digits on the keypad. We would like to make it easier to write a message to your friend using a sequence of keypresses to indicate the desired characters. The letters are mapped onto the digits as 2=ABC, 3=DEF, 4=GHI, 5=JKL, 6=MNO, 7=PQRS, 8=TUV, 9=WXYZ. To insert the character B for instance, the program would press 22. In order to insert two characters in sequence from the same key, the user must pause before pressing the key a second time. The space character should be printed to indicate a pause. For example “2 2″ indicates AA whereas “22″ indicates B. Each message will consist of only lowercase characters a-z and space characters. Pressing zero emits a space. For instance, the message “hi” is encoded as “44 444″, “yes” is encoded as “999337777″, “foo bar” (note two spaces) is encoded as “333666 6660022 2777″, and “hello world” is encoded as “4433555 555666096667775553″. + +This challenge has been taken from [Google Code Jam Qualification Round Africa 2010](http://code.google.com/codejam/contest/dashboard?c=351101#s=p2) ... Please use the link for clarifications. Thank You From f5758c8a941add22c565e589de7e7a39594acebc Mon Sep 17 00:00:00 2001 From: vaz-rodrigo Date: Tue, 22 Mar 2016 19:14:05 -0300 Subject: [PATCH 11/11] Update challenge_text.md --- .../challenge_text.md | 126 +++++++++++++++++- 1 file changed, 125 insertions(+), 1 deletion(-) diff --git a/Intermediate Challenges/Challenge #0241 [Intermediate] ascii Bitmap Chess/challenge_text.md b/Intermediate Challenges/Challenge #0241 [Intermediate] ascii Bitmap Chess/challenge_text.md index c5c3c75..6060f8a 100644 --- a/Intermediate Challenges/Challenge #0241 [Intermediate] ascii Bitmap Chess/challenge_text.md +++ b/Intermediate Challenges/Challenge #0241 [Intermediate] ascii Bitmap Chess/challenge_text.md @@ -1 +1,125 @@ -trash \ No newline at end of file +# Unicode Sucks + +From Monday's challenge, +``` + toascii '1r3rk1/1pnnq1bR/p1pp2B1/P2P1p2/1PP1pP2/2B3P1/5PK1/2Q4R' +.r...rk. +.pnnq.bR +p.pp..B. +P..P.p.. +.PP.pP.. +..B...P. +.....PK. +..Q....R +``` +make something like this: +``` +┌─┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐ +│8│ │X...X│ │.....│ │X...X│ X │.....│ +│ │ │XXXXX│ │.....│ │XXXXX│XXXXX│.....│ +│ │ │.XXX.│ │.....│ │.XXX.│ XXX │.....│ +│ │ │.XXX.│ │.....│ │.XXX.│XXXXX│.....│ +├─┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤ +│7│.....│ │.XXX.│ XXX │X.X.X│ │..X..│O O│ +│ │.....│ X │XXXX.│XXXX │XXXXX│ │.XXX.│OOOOO│ +│ │.....│ X │..X..│ X │.XXX.│ │..X..│ OOO │ +│ │.....│ XXX │XXXX.│XXXX │X...X│ │..X..│ OOO │ +├─┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤ +│6│ │.....│ │.....│ │.....│ O │.....│ +│ │ X │.....│ X │..X..│ │.....│ OOO │.....│ +│ │ X │.....│ X │..X..│ │.....│ O │.....│ +│ │ XXX │.....│ XXX │.XXX.│ │.....│ O │.....│ +├─┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤ +│5│.....│ │.....│ │.....│ │.....│ │ +│ │..O..│ │.....│ O │.....│ X │.....│ │ +│ │..O..│ │.....│ O │.....│ X │.....│ │ +│ │.OOO.│ │.....│ OOO │.....│ XXX │.....│ │ +├─┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤ +│4│ │.....│ │.....│ │.....│ │.....│ +│ │ │..O..│ O │.....│ X │..O..│ │.....│ +│ │ │..O..│ O │.....│ X │..O..│ │.....│ +│ │ │.OOO.│ OOO │.....│ XXX │.OOO.│ │.....│ +├─┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤ +│3│.....│ │..O..│ │.....│ │.....│ │ +│ │.....│ │.OOO.│ │.....│ │..O..│ │ +│ │.....│ │..O..│ │.....│ │..O..│ │ +│ │.....│ │..O..│ │.....│ │.OOO.│ │ +├─┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤ +│2│ │.....│ │.....│ │.....│ O │.....│ +│ │ │.....│ │.....│ │..O..│OOOOO│.....│ +│ │ │.....│ │.....│ │..O..│ OOO │.....│ +│ │ │.....│ │.....│ │.OOO.│OOOOO│.....│ +├─┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤ +│1│.....│ │O.O.O│ │.....│ │.....│O O│ +│ │.....│ │OOOOO│ │.....│ │.....│OOOOO│ +│ │.....│ │.OOO.│ │.....│ │.....│ OOO │ +│ │.....│ │O...O│ │.....│ │.....│ OOO │ +├─┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤ +│ │a │b │c │d │e │f │g │h │ +└─┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘ +``` +Here are some 4x5 crappy bitmaps to get started +``` +O...O +OOOOO +.OOO. +.OOO. +; +.OOO. +OOOO. +..O.. +OOOO. +; +..O.. +.OOO. +..O.. +..O.. +; +O.O.O +OOOOO +.OOO. +O...O +; +..O.. +OOOOO +.OOO. +OOOOO +; +..... +..O.. +..O.. +.OOO. +; +..... +..O.. +.O.O. +..... +``` +the last one is that ghost square from Monday's challenge. Bitmaps differences for Starting, Regular, and Ghost Rooks is encouraged, as is code generating as much as possible of the variations. + +# Is the black king in check + +[how chess pieces can move](https://en.wikipedia.org/wiki/Chess#Movement) + +The black king (k) is in a check position if +- He pretends he is a bishop(b), and can capture a B or Q(ueen) +- He pretends he is a rook(r), and can capture a R or Q(ueen) +- He pretends he is a knight(n), and can capture a N +- He pretends he is a pawn(p), and can capture a P + +(note that pieces are blocked by other friend and foe pieces from "checking" the king) + +For output, list all squares that have a piece that is holding the black king in check. + +\** sample input \** +``` +1r3rk1/1pnnq1bR/p1pp2B1/P2P1p2/1PP1pP2/2B3P1/5PK1/2Q4R +``` + +\** sample output \** +empty - no checks. + +\** challenge input \** +``` +'1r3kR1/4P3/6NB/8/8/Q7/8/4KR2' +```