# Sandbox for Proposed Challenges

This "sandbox" is a place where Code Golf users can get feedback on prospective challenges they wish to post to main. This is useful because writing a clear and fully specified challenge on your first try can be difficult, and there is a much better chance of your challenge being well received if you post it in the sandbox first.

Sandbox FAQ

## Posting

Write your challenge just as you would when actually posting it, though you can optionally add a title at the top. You may also add some notes about specific things you would like to clarify before posting it. Other users will help you improve your challenge by rating and discussing it.

When you think your challenge is ready for the public, go ahead and post it, and replace the post here with a link to the challenge and delete the sandbox post.

## Discussion

The purpose of the sandbox is to give and receive feedback on posts. If you want to, feel free to give feedback to any posts you see here. Important things to comment about can include:

• Parts of the challenge you found unclear
• Problems that could make the challenge uninteresting or unfit for the site

You don't need any qualifications to review sandbox posts. The target audience of most of these challenges is code golfers like you, so anything you find unclear will probably be unclear to others.

If you think one of your posts requires more feedback, but it's been ignored, you can ask for feedback in The Nineteenth Byte. It's not only allowed, but highly recommended! Be patient and try not to nag people though, you might have to ask multiple times.

It is recommended to leave your posts in the sandbox for at least several days, and until it receives upvotes and any feedback has been addressed.

## Other

Search the sandbox / Browse your pending proposals

The sandbox works best if you sort posts by active.

To add an inline tag to a proposal, use shortcut link syntax with a prefix: [tag:king-of-the-hill]. To search for posts with a certain tag, include the name in quotes: "king-of-the-hill".

Get the Sandbox Viewer to view the sandbox more easily!

# ro1000an nu1000era50 en100o501ng

• I suggest adding a worked out example - the test cases were still confusing for me after reading the challenge body. Jun 25 at 13:48

• (from the test cases) How is 110015, ICIV, 94? IC is 99 + IV which is 4 should be 103. I'd suggest removing that test case though, because ICIV is not technically a valid roman numeral. Jun 26 at 3:06
• The second-to-last test case is also wrong apparently: the second number is MMCCCXL which is 2340, not 2345, so the result is 3574 Jun 26 at 3:17
• @Steffan fixed and fixed Jun 26 at 6:53
• this is basically roman numeral addition right? with translating before and after to numeric symbols
– qwr
Jun 26 at 21:12

# Word stays a word after taking away a letter

## Posted here

• Is it guaranteed that the input will contain a solution? Jul 1 at 12:36
• @pajonk I think it's better to say no, thanks Jul 1 at 18:10

# Next digit of rational numbercodegolfstring

• A good test case might be 1.221122, which I believe should result in an output of 2 Jul 15 at 5:52
– Jiří
Jul 15 at 10:08
• Is the decimal separator important to the challenge? I feel like it might be better to just have no decimal separator Jul 16 at 4:19
• @CommandMaster It isn't really that important, but I wanted the challenge make sense so this is why I kept it there. I expect that for most languages it will just be single replace, tr or something.
– Jiří
Jul 16 at 14:36

# Rearrange to a palindrome

Given a string, shuffle it so that it becomes a palindrome.

For example, adadbcc can be arranged into dacbcad, or dcabacd, acdbdca and more. Any of these (or all) is acceptable, and duplicates are allowed if outputting all. Something like abc cannot be shuffled into a palindrome, and you can assume it won't be inputted.

(if it helps) input will only contain lowercase letters.

## Testcases

These show one possible solution.

nanas -> nasan
coconutnut -> conuttunoc
apotato -> atopota
manplancanalpanamaaaa -> amanaplanacanalpanama


# Halve a string

Posted

• If this was a decision problem, it would be easier to give test cases (because it would true/false instead of many different possible outputs) Jul 19 at 12:46
• I guess another possible task is to output the list of all halves of a given string. Jul 19 at 14:20

# Every $$\ n $/extract_tex]th repeat code-golfarray Given a list of positive integers, and another integer $$\ n \$$, output every $$\ n \$$th instance of each distinct item in the list, starting with the first, in the order they appear in the original list. For example, with $$\ n = 2 \$$, we will output the first instance of each item, but not the second, but we will output the third, and so on. If $$\ n = 2 \$$ and the list is 4 1 3 2 3 1 6 3 4 1 1, then: • 1 occurs four times, so only the first and third will be kept • 4 occurs twice, and only the first will be kept • 3 occurs three times; the first and third will be kept • 2 and 6 only occur once each, so their first and only occurrences will be kept Therefore, the output is 4 1 3 2 6 3 1. This is , so the shortest code in bytes wins. ## Test cases todo # Meta • Related ($$\ n = 2 \$$, and more open ended) • Is this a duplicate? • Is this clear enough? # Swap every two elements in the list every possible way Posted • Welcome to the Code Golf SE! I have a few questions about your problem: 1) Should the output include the original order? Examples 2 and 3 do, but example 1 doesn't. 2) I might be mistaken, but isn't this equivalent to finding all permutations of the array? Jul 23 at 20:13 • @Adam 1) The output should include the original order only if the original order can be reached by applying every possible pair swap in some order. For example 1, the only possible swap just swaps two elements, and so only one permutation can be reached. For example 3, there is no possible swap, so the array stays the same, and for example 2, there are a lot of different possible results that happen to include the original order. 2) You are mistaken in that case. It isn't all permutations, it's slightly more complicated than that. It's a little bit of a research problem. Jul 25 at 12:33 # IE's Extra Robust Color Parsing® • So #FFF (white in today's browsers) became #0F0F0F (very dark grey)‽ – Adám Jul 25 at 15:02 • When you say output as an "a RGB color", you should clarify whether you mean the text formatted as an RGB color string, or to graphically output the color itself Jul 25 at 15:48 • @Adám So it would seem, I noticed that as well. Jul 26 at 20:39 • @thejonymyster right, poor wording on my part. Fixed. Jul 26 at 20:39 • Could you please add comments to less obvious steps in the worked out examples? (I don't get the AD0, AC0, 0E0 --> AD, AC, 0E, as the algorithm says to remove characters always from the front.) Also, I suggest adding some more test-cases (not necessarily worked out, but in a copy-friendly format). Jul 27 at 5:27 • @pajonk I added some comments, planning to add some test cases later whan I find the time. Jul 27 at 9:57 • Will IE recognize some special words like red, white? Or red is processed into #000e0d? – tsh Jul 29 at 3:17 • @tsh Good point, thanks! IE probably did respect them, but for the challenge, we'll process them. Updated the rules. Jul 29 at 7:05 • I assume we just have to output the six resulting characters, and the leading # in the output is optional? Jul 29 at 7:44 • Yes, I just used that to mark the results. Jul 29 at 9:29 # Cryptic Multiplications # Anti-divisors of a number # An algorithm to find even sublime numbers # Convert integer to IEEE 754 float The task is simple, given a 32 bit integer, convert it to its floating point value as defined by the IEEE 754 (32-bit) standard. ## IEEE 754 Here is a converter for your reference. Here is how the format looks: The standard is similar to scientific notation. The sign bit determines whether the output is negative or positive. If the bit is set, the number is negative otherwise it is positive. The exponent bit determines the exponent (base 2), it's value is offset by 128. Therefore the exponent is $$\2^{n-128}\$$ where n is the integer representation of the exponent bits. The mantissa defines a floating point number in the range $$\[1,2)\$$. The way it represents the number is like binary, the most significant bit is $$\\frac 1 2\$$, the one to the right is $$\\frac 1 4\$$, the next one is $$\\frac 1 8\$$ and so on... A one by default is added to the value. Now the final number is: $$\text{sign}\cdot 2^{\text{exponent}-128}\cdot \text{mantissa}$$ ## Test cases 1078523331 -> 3.1400001049041748046875 1076719780 -> 2.71000003814697265625 1036831949 -> 0.100000001490116119384765625 3264511895 -> -74.24919891357421875 1056964608 -> 0.5 3205496832 -> -0.5625  For this challenge assume that cases like NaN and inf are not going to be the inputs, and subnormals need not be handled. This is code-golf, so the shortest answer in bytes wins. • Do subnormals need to be handled? Sep 21 at 17:25 • Closely related. Kinda opposite task, but I think there are certainly overlapping techniques around reinterpreting a bit pattern from one type to another. Sep 22 at 0:22 • The exponent bias is \2^{8-1}-1=127\, not \128\. Sep 23 at 14:01 # Metagolf: Catlike Piet The goal of this is to write a catlike program, which would be executed (in a Unix environment, though you needn't stick to that) by the following: yourprogram < file > output piet output  where piet output writes the contents of file to stdout. That is, you're to generate a Piet program which prints the input to yourprogram. One-liners Straight line programs can be written in Piet... in straight lines. If you're willing to take a hit to your score, your output can take the form of a string of commands: = none (continue color block) | push ^ pop + add - subtract * multiply / divide % mod ~ not > greater . pointer \ switch : duplicate @ roll  input number ? input character # output number ! output character  which is trivial to convert to a Piet program with the following (partially golfed) Python code: def P(s): h=v=0;l=len(s)+1;R="P3 %i 2 255 192 0 0 "%(l+2) C=[1,3,2,6,4,5];V=[0,192,192,255,0,255] for x in map("=|^+-*/%~>.,:@?#!".find,s): C=C[x//3:]+C[:x//3];V=V[x%3*2:]+V[:x%3*2] for i in [1,2,4]:R+="%i "%V[(C[0]//i)%2] return R+"255 "*4+"0 0 "+"255 "*l*3+"255 0 0 "*2  The dimension of said program is (n+3) x 2 if there are n characters in the string. Scoring Your code will be judged on the maximum dimension of the images that it outputs. • Part 1: Take the maximum score taken over all ascii codes (that is, single-character inputs), discounting EOF. • Part 2: Take the score for the input "Hello. My name is Inigo Montoya. You killed my father. Prepare to die." Your score is the product of the scores in part 1 and part 2. Punishment: Double your score if you write one-liners as above (that is, if you don't output an image). Bonus: If your program is written in Piet, take the square root of your score above. • It took me a while to understand the task as "Write a program taking INPUT which produces as output a piet program that takes no input but produces INPUT." I think it is a interesting and challenging, but it's reception will depend entirely on how many people are willing to learn/futz-around-in/deal-with piet. And I have no feel for how many that is. Jul 7, 2011 at 3:12 • @dmckee; would it be better if I just used a reduced instruction set, and only ask for the instruction stream? I think this is still challenging with {push 1,duplicate,add,subtract,multiply,output}. Come to think of it, if I restrict to {push 1,duplicate,add,output}, there's a reduction to some awesome algorithms. Jul 7, 2011 at 4:48 • I did this in piet some time ago: craigoclock.blogspot.com/2011/05/metaprogramming-in-piet.html May 21, 2012 at 18:31 • Hello! This looks like a good but abandoned meta post, would you be willing to offer it for adoption? (If you want to, you can still post to main.) – user58826 Jun 9, 2017 at 15:22 # Count Syllables The goal of this challenge is to write a program that can count the syllables in a word as accurately as possible. ## Input On STDIN, your program will receive a number X followed by X lines, each containing a single word. Simple enough. (Should there be a limit on the size of X?) The words will come from this list. 4 challenge to count syllables  ## Output Your output should be to STDOUT and have X lines. On each line should be the number of syllables counted in that word. 2 1 1 3  # Scoring To score you program, it will receive a long secret list of words to test. All programs will receive the same list of words. For each word, the number of syllables that your program got wrong will be added to the score of the program. If it output a 4 or a 2 when the word had 3 syllables, then one point will be added. If it said a 15 instead of a 3, then 12 points will be added to the score. The lower the score, the better. For example, if for the above input your program output 3 2 2 2 (which would be produced by a program that counts strings of vowels), then the program would receive a score of 2. # Rules Your program should not access any external files (such as the word list). Also, your program should be no more than 5,000 bytes long (is this a reasonable limit?). The winner will be the person whose program has the lowest score, therefor the most accurate syllable counter. The deadline for submissions is [some time at least a month away]. # Suggestions I am open to all constructive criticism. Is 5,000 bytes a reasonable limit for the program size? How long should the official scoring test be? How long should the deadline be? • This has one major flaw: the output is subjective. How many syllables do these words have? Every; victory; hierarchy; desire; oil; hour; poem. The only real way I see to work around this is for you to produce a marked-up version of the word list. May 29, 2012 at 20:40 • I was really worried about that, and I don't see a way around it. May 29, 2012 at 20:42 • I personally would love to see more language processing challenges. I agree with @PeterTaylor on the difficulty of some words. Perhaps taking a specific text(s) and identifying explicitly in the challenge which words will have how many syllables? Jun 8, 2012 at 3:34 • @PeterTaylor ...Or maybe you could filter ambiguous words out of the reference list? – user16991 Feb 8, 2015 at 1:19 • What's the point of the first line of input? Apr 27, 2016 at 20:05 • If you provide a reference list, A hyphenated reference list, and hide a secret list which may or may not include members of the reference list, this would be a reasonable challenge Sep 17, 2016 at 0:05 • Do you plan to post this? If not, I'd be happy to adopt it. (If you don't respond within two weeks, by community standards, I'm allowed to do so.) Aug 18, 2017 at 3:20 • The example of inaccurate program that would score 2 - did you mean to output 3 1 1 2 rather than 3 2 2 2? Nov 9, 2017 at 18:31 • A reference list could be dynamic: potential contestants can ask for words of their choice to be added to the list. They won't know what's on the secret list but will try to make their programs as accurate as possible (according to your syllable count) so they should always be able to ask for specific words they are not sure about. Of course, you could make it in different language. In my language, Slovene, it's much clearer how many syllables words have. How about Solresol, haha! Nov 9, 2017 at 18:38 • I am going to adopt this if you don''t respond Dec 20, 2017 at 16:48 ## Play Simple 2-Dimensional Minecraft Recently I found this video of "HansLemurson" showing a computer that was built in minecraft, which runs minecraft. He is playing minecraft on a computer that was built in minecraft that is running on his computer. To be specific, it is a two dimensional version with an 8x8 grid of cells. There is gravity, block placement, and even jumping. It is worth noting that the computer is single purpose. The same person has built programmable computers, but making them single purpose allows the computer to be much smaller. ## Details The minecraft world is an 8x8 grid (one horizontal and one vertical dimension). The grid is comprised of either Xs (representing blocks) or empty spaces. The player is an X that is blinking on and off about once every second. There are two modes in the game, controlled by a toggle switch. The first mode is movement. This is controlled by a WASD-like button arrangement. If the player chooses to move left/right/down, the computer checks to see if the space immediately in that direction is empty. If so, then the player moves into that space. If the player chooses to move up, then the computer checks that the block underneath the player is solid. If so, then the player moves upward two units. Notice that this can propel the player into a solid block. If this happens, the player is obscured by the solid block, but can still move to an empty block next to him. When the player is inside on a solid block, the game continues as if the block isn't there, although the block is still there once the player leaves it. After each move, the player falls down one unit if there is empty space there. This simulates gravity. This is also why moving up moves up two units, so that the gravity makes a net movement of up one unit. Gravity does not cause the player to fall all of the way to the ground, just one unit. The second mode is block placement. In this mode, the same exact WASD buttons are used. Instead of moving the player, they toggle the state of the block in that direction. If the player presses "left" and there is a block there, then the block is destroyed. If there is not a block there, then a block is placed. Again after this move, the player is again subject to gravity. The blocks are not subject to falling. Toggling the toggle switch does not count as a move, and does not invoke gravity. The game board is a torus, so all actions (movement, block creation) can wrap around the board. The board does not scroll with the player. The player moves, and the blocks stay in the same place. ## The challenge You challenge is to write the shortest program that simulates this game. Your program should display and update the map correctly (with Xs as blocks, and with the blinking player). It should accept input from a button that toggles the state and four buttons for movement and actions. This is code golf. There are imaginary bonus points for adding more features (block types, game size, etc) to your game. ## Suggestions? • With more complicated challenges I find that it helps to do a reference implementation so that you have a very concrete idea of how much work is involved. Aside from that, I like it. Jun 3, 2012 at 20:11 • Is the blink rate selected to fit with the ANSI escape sequence? Either way I would explicitly allow that, because it's the obvious way to do it on compatible terminals. Jun 5, 2012 at 7:14 • The blink rate wasn't selected to be anything specific. I think that I will broaden the restriction. Maybe any blink rate between 3 blinks per second to 1 blink every 2 seconds. Jun 5, 2012 at 20:21 • @programmer5000 No, for two main reasons: First, challenges can go extended periods of time in the sandbox before they are posted and/or adopted. In the past I've posted challenges after not touching them for 4 years. Second, deleting this answer will not reduce lag, as deleted answers are still present, simply not visible. Users with sufficient rep will see all 4040 answers in the sandbox, and you will too once you earn the "view deleted answers" privilege. Apr 13, 2017 at 18:15 ## Bad Voice Recognition Calculator Overview: Let's say you've decided to operate your computer using voice recognition software, but unfortunately you did a horrible job researching the various products out there and chose a package that does not recognize numbers as numerals, only words. (i.e. "one" (spoken) == "one" (typed), not "1".) Rather than spend more money to get another option, you decide to make do. Now you want to use the computer's calculator, but this poses a problem, since your machine doesn't know how to add "one plus one". Objective: Implement a basic calculator that will read in a string of the written-out equation, perform the correct calculations, then return the result in its text form. Your code should be as short as possible; this is code golf. Rules/Constraints: • Input/output will be using your preferred method (STDIN, ARGV, etc.). • Your calculator must be able to handle input and output within the billions (non-inclusive) -1,000,000,000 < i < 1,000,000,000, but you may expand to more if you wish. • Decimal values and/or parts must be accepted (0 < i < 1) up to 3 places/digits. • When calculating answers, proper rounding must be used, so "three point one four one five nine two six" must be returned as "three point one four two". • Basic calculator functions required: • "Add"/"Plus"/"Sum"/"And" (+) • "Subtract"/"Minus"/"Remove" (-) • "Multiply"/"Times" (*) • "Divide"/"Divided"/"Divide by"/"Divided by" (/) • "Raise"/"Exponent"/"Power"/"To the power of" (^) • "<Base>Root"/"<Base>Radical" (√) • "Point"/"Decimal" (.) • "Pi" (π) • All strings in the list above must be accounted for in your code, capitalization does not matter. • Numbers may be presented as their full value ("one thousand") or by digit (one zero zero zero). • Negative numbers may be assigned using "Minus" or "Negative". • The string "Minus" bust be accounted for as an operator and identifier. (see example) • "And" is only acceptable as an operator, not as part of a named number. • "one hundred and one" • "one hundred one" • "a" or the absence of a number does not equate to any number; all numbers will be explicitly accounted for in the program input. • "a hundred" does not equate to "one hundred" and is not a valid input. • No more than 2 terms will be used. • "one plus one minus one" will not be implemented. • If an invalid input is supplied, your function/program should handle the error and exit gracefully with an error description. Example I/O: • "one add one" --> "two" • "five thousand thirty four subtract ten thousand six hundred" --> "negative five thousand five hundred sixty six" • Alternatively: "five zero three four subtract one zero six zero zero" • "three root twenty seven" --> "three" • "ten minus minus ten" --> "twenty" • Alternatively: "ten subtract negative ten" ## Sandbox Questions: 1. Is this too basic/complicated? (I'm assuming some languages will handle this much more simply than the method I have in my head...) 2. Does the title fit? 3. Are there any constraints that should be added/lifted? 4. Are any more examples needed for clarification? Thanks for your input, guys! • Not everyone says numbers the same way. Does the parser have to treat the following as equivalent? "negative one hundred five", "minus one hundred five", "negative one hundred and five", "minus one hundred and five", "negative a hundred five", "negative a hundred and five", ...? Jun 15, 2012 at 15:12 • @PeterTaylor I had had a similar thought re: operators. ("plus" versus "add", etc.) I think it would be more interesting to account for all, but given the wide variety of possible inputs, it may generally be better to limit the options to a specifically defined set (which I have yet to define). Jun 15, 2012 at 15:18 • @PeterTaylor I've added some of these details. Please let me know if there's anything unclear about them. Jun 15, 2012 at 16:10 • I don't spot any ambiguities in the parser. There is still an ambiguity relating to decimals, though. What precision should be used? Also, I notice now that there's no winning condition. Is this intended to be code-golf? (Ugh - tons of strings which will have to be hard-coded in most languages. I expect Perl has a suitable parser already in CPAN, though...) Jun 19, 2012 at 9:03 • @PeterTaylor I don't know where I went... I've updated the spec. re: decimal places and objective. Jun 29, 2012 at 13:24 • @PeterTaylor metacpan.org/pod/Lingua::EN::Words2Nums Apr 27, 2016 at 20:37 # Count unique characters in text. Given a string for input, output the unique non-whitespace characters in that string along with a count of their occurrences. The list should be sorted in ascending order of ASCII code. Examples Input: Hello, World!  Output: Character Count ! 1 , 1 H 1 W 1 d 1 e 1 l 3 o 2 r 1  Input: The quick brown fox jumps over the lazy dog.  Output: Character Count . 1 T 1 a 1 b 1 c 1 d 1 e 3 f 1 g 1 h 2 i 1 j 1 k 1 l 1 m 1 n 1 o 4 p 1 q 1 r 1 s 1 t 1 u 1 v 1 w 1 x 1 y 1 z 1  The actual formatting (headers, spacing, etc) of the on-screen output is up to you. The only conditions are that it must be sorted in ascending order by ASCII code, and it must be easy to tell what represents a character from the string and what represents a count of a given character. (For example, given a string of 99999999, the output should be explicit so that it is not confused as saying I have 9 8s.) Ultimate challenge (taken from here): JKqdJg+oJgiowgyIJgkS+gyxJdeS+gyxJ4yoJdybJdioJdqIJ4kS+KwFJ4QS+gzYJg+ow4vIJ4yxvd+IJgy=+dv=JdQx+gzbJrzx24zYJgkxJ4qLJKQxJ4yxJKqx+KqdJKqdJg+oJgiowgyIJgkS+gyxJdeo24yxJm+xJdybJdioJdqIJKi=J4wF+dvS+gzYJg+ow4zYJ4yxvdy=J4i=+Kv=JdQo+KqxJrzdJKzYJgkxJ4qLJgkxJ4yxJKvSJ4qbJKqdJg+oJgiowgyIJgkdJgyxJdeo24yxJm+xJdybJd+oJd+S+dz=J4wF+dvS+g+SJg+ow4vIJ4yxJ4voJgy=+dv=+dzdJgqxJrzdJKzYJgkS+dweJKQxJ4yxJKvSJ4qbJKq=24yYJgiowgyIJgkdJgzdJryo24yxJm+d24zxJd+oJdqIJ4kS+KwFJ4QS+gzYJ4y=2gzYJ4yxJ4voJgy=+dv=+dzdJgqxJrzx24zYJgkS+dweJKQxJ4fK+dQSJ4qbJKq=24yYJgiowgyIJgkS+gzdJryS+gyxJ4yoJdybJd+oJd+S+dz=J4wF+dvS+gzYJ4y=2gvIJ4yxJ4voJgy=+dv=JdQo+KqxJrzx24zY+dzS+dweJKQxJ4yxJKqx+KqbJKq=24vbJdyowgyIJgkdJgzdJryS+gyxJm+d24zxJdioJd+S+dz=J4wF+dvS+gzYJg+ow4vIJ4yxJ4voJgy=+Kv=JdQx+gzbJrzx24zYJgkS+dweJgkxJ4yxJKvSJ4qdJKq=24yYJgiowgyIJgkdJgzdJryS+gyxJ4yoJdybJd+oJdqIJKi=J4wF+dvS+gzYJg+ow4vIJ4yxJ4v=J4i=+Kv=+dzdJgqxJrzx24zYJgkS+dweJgkxJ4fKJ4qx+KqdJKqdJg+SJdyowg+oJgkS+gyxJdeS+gyxJ4yoJdybJd+oJdqIJ4kS+KwFJ4QS+g+SJ4y=2gzYJ4yxJ4v=J4i=+Kv=JdQo+KqxJrzx24zY+dzS+dweJKQxJ4yxJKvSJ4qbJKqdJg+oJgiowg+oJgkS+gzdJryo24yxJ4yoJdybJdioJdqIJ4kS+KwFJ4QS+g+SJg+ow4vIJ4yxvd+IJgy=+dv=JdQo+KqxJrzdJKzY+dzxJ4qLJKQxJ4yxJKqx+KqdJKq=24vbJdyowg+oJgkS+gzdJryo24yxJ4yoJdybJdioJd+S+dz=J4wFJ4QS+gzYJg+ow4zYJ4yxvd+IJgy=+Kv=+dzdJgqxJrzdJKzYJgkxJ4qLJgkxJ4yxJKvSJ4qbJKq=24vbJdyowgyIJgkdJgyxJdeo24yxJm+xJdybJd+oJdqIJKi=J4wF+dvS+g+SJ4y=2gvIJ4yxvd+IJgy=+dv=+dzdJKzbJrzdJKzY+dzS+dweJgkxJ4yxJKvSJ4qbJKq=24yYJgiowg+oJgkS+gyxJdeo24yxJ4yoJKzxJd+oJdqIJKi=J4wF+dvS+gzYJg+ow4vIJ4yxJ4v=J4i=+dv=+dzdJgqxJrzx24zYJgkxJ4qLJKQxJ4fKJ4qx+KqdJKqdJg+oJgiowgyIJgkS+gzdJryS+gyxJm+d24zxJd+oJdqIJKi=J4wFJ4QS+gzYJ4y=2gzYJ4yxvdy=J4i=+Kv=+dzdJKzbJrzx24zY+dzxJ4qLJKQxJ4yxJKqx+KqdJKqdJg+SJdyowg+oJgkdJgzdJryo24yxJm+d24zxJd+5  • This isn't really an interesting problem. The shortest answer is almost certainly going to be fewer than 10 characters. Dec 11, 2013 at 12:19 • @PeterTaylor While I mostly agree with your comment - already the header line may contain more than 10 characters. Dec 12, 2013 at 6:15 • "The quick brown fox jumps over the lazy dog." contains "e" three times. Dec 12, 2013 at 6:16 • @Howard Thanks. I must be blind - it took me about five times of reading your comment to find it. Also, do remember that the header is optional to a certain degree - you just need to make sure the output is unambiguous as to which items are characters from the string, and which are character counts. – Iszi Dec 12, 2013 at 7:02 • My brain instantly went into bash mode. wc and uniq practically solve half of this, but not in any particularly short manner. – Rob Dec 17, 2013 at 20:31 ## Chess move The Challenge Write a program that gets a string containing a chessmove and a chessboard as input, and then outputs the chessboard. Requirements The chess move will have this format: <from square><to square>[<promoted to>]  Examples: d2d4 f8g7 a7a8R  The chessboard format is not fixed, but there must be a 1 to 1 relation between the board and the string to represent the board. Also the format of the input must bet the same as the format of the output. Two suggestions of what it could look like: rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR rnbqkbnr pppppppp 00000000 00000000 00000000 00000000 PPPPPPPP RNBQKBNR  It is not required to store anything except the location of the pieces, and validity of moves can be assumed. Scoring Base score is character count (assuming your program can move pieces for all moves) Bonus multipliers: • If the program updates the promoted piece, divide by 2 • If the program also moves the rook when castling, divide by 2 • If the program also removes the pawn when capturing en passent, divide by 2 The moves, and castling & en passent in particular are explaned on Wikipedia. So basically writing a 100 character solution for the base problem gives the same score as an 800 character solution with all bonus multipliers. Examples If you would choose to use one of the board formats above, your input would look like one of these strings: e2e4 rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR e2e4 rnbqkbnr pppppppp 00000000 00000000 00000000 00000000 PPPPPPPP RNBQKBNR  Your corresponding output string would then be one of these: rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR rnbqkbnr pppppppp 00000000 00000000 0000P000 00000000 PPPP0PPP RNBQKBNR  • Before I get on to more specific criticisms: as presented, without the bonus this is too trivial to be interesting. I suggest removing some flexibility: require Fen notation for the board position and algebraic notation for the move, and making the current bonus options mandatory. On specifics: it's not clear why you talk about storage; and the board position notations you suggest don't include enough information to know whether en passant is possible. Dec 22, 2013 at 23:56 • @PeterTaylor I agree that compared to chess programs this may be trivial, but I would like to make it a golf challenge. Compared to the hot code golf questions this is quite elaborate already in its basic form. (For a good solution the board design may need to be changed drastically). It is true that there is no attention to the legality of moves (whether it is possible to capture en passent) but for a mere viewer this is not required so I am not too worried about this. So far the chess questions seem to get very few answers as they tend to be complex and I hope to offer relatively easy entry. Dec 30, 2013 at 11:02 • Your point about en passant is valid - you had said in the spec to not worry about legality. I'll try to convince you of my first point: without the bonus, this reduces to: a) parse first four characters into (col 1, row 1, col 2, row 2); b) take board as a 64-char string; c) board[8*row_2+col_2] := board[8*row_1+col_1]; board[8*row_1+col_1] := ' '; print board. This is trivial compared to any good golf question. (Note that the hot questions at the moment are neither golf questions nor good questions). Dec 30, 2013 at 12:14 • This sandbox post has had little activity in a while. Please improve / edit it or delete it to help us clean up the sandbox. Due to community guidelines, if you don't respond to this comment in 7 days I have permission to vote to delete this. – user58826 Jun 9, 2017 at 15:40 # Black Box Your task is to analyze a given situation for the game Black Box. Given a sequence of guesses and answers, your program is to either print the solution or suggest the next move. ## The game The board consists of 8×8 cells, with edges labeled like this: I'll probably create nice images here, particularly to make sure that the squares of the board are really square.  abcdefgh i I j J k K l L m M n N o O p P ABCDEFGH  The player shoots rays into the interior of the box, where they might get deflected, reflected or absorbed. He is told the position where the ray leaves the black box again, and from that has to deduce the positions of 4 atoms inside the black box. I'll have to include more of the game rules here, but for now see Wikipedia. # Input and output Input is a sequence of line, each consisting of two characters. The first denotes the point where the ray of light enters the black box, the second the place where it comes out again. In the case of a reflection, both characters will be equal. In the case of a hit, the second character will be -. If the input is enough to fully determine the locations of the atoms, then output should be four lines giving the coordinates of each atom. The lines should be two lower case characters each, the first giving the row and the second giving the column of the found solution. The atom positions must be printed in lexicographical order. If the input is consistent with more than one set of atom positions, then the output should consist of a single line containing a single character, which is the location where the next ray should be shot. That location has to be chosen in such a way that it can help find the solution. This is the case unless all of the atom positions consistent with the input so far would produce the same output for this next ray as well. Your output has to be terminated by a newline character. # Examples Let's take the atom configuration the Wikipedia article uses as an example as well:  abcdefgh i I j J k O O K l L m M n O N o O p O P ABCDEFGH  If the input were cf D- Em HH Co  then the output should be kb kg nd pg  but if the input were only Em HH  then the output might be for example K  ## Scoring This is code golf, so shortest answer wins. However, I'll only accept answers which are practical in so far as they compute their result in reasonable time. I'd say no more than five minutes on my system where I'll evaluate the answers, and I'll simply hope that correct solutions will be much faster and incorrect ones much slower, so that the speed of my system doesn't make a difference. A submission which gives a wrong answer for one of my test cases will be disqualified until it gets fixed. I will probably point out the problem in a comment to that post. # Create a program with "exact repetition" in its source code The task is to create a program, with the following restrictions placed on the printable ASCII characters in the source code: choose some k > 0. • Every non-alphabetic character has to appear exactly k times. • Every alphabetic character has to appear at most k times. • This rule differs from the former in order to avoid boring dummy identifiers while still making it a challenge to choose good library functions to call. Character set definitions used: • Non-alphabetic characters are !"#%&'()*+,-./0123456789:;<=>?@[$^_{|}~ and '' (backtick).
• Alphabetic characters are ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.

Note that no restriction is placed on characters outside of the range of printable ASCII characters (including control codes, tabs, newlines, higher unicode codepoints, etc).

What the program does is up to you; be creative. Some general guidelines:

• Programs that do something interesting might have better chances, although more impressive code structure (i.e. fewer comments) is also beneficial.
• Stuffing excess characters in comments is boring, and should be avoided/is discouraged.
• Dead/no-op code isn't terribly interesting either, but is probably unavoidable and at least has to conform to the language's grammar.

This is : whatever has the most upvotes at Feb 1, 2014 gets accepted as the winner.

#
#
/*@*/_[]={9.};main() {printf("He%clo \
world!%c\
",2^7&!8.&~1|~-1?4|5?0x6C:48:6<3>2>=3<++_[0],'@'^79-5);}


Prints "Hello world!" (adapted from an answer to another question). Probably wouldn't score a lot (since what it does isn't terribly interesting). Each of the non-alphabetic characters appear exactly twice, and no alphabetic character appears more than twice.

For meta: I want to post this, but I'm worrying that "do something interesting" might give too little guidance and the question won't receive many answers.. thoughts? Is it good as-is, or should I come up with some task that one should be required to implement (and possibly change the ruling to code-challenge, with length + 2^(characters-in-comments) as the score)?

This is my first try at writing a challenge. Please let me know how I can improve it.

# Roman Calculator

Create a basic calculator for Roman numerals.

### Requirements

• Supports +,-,*,/
• Input and output should expect only one prefix per symbol (i.e. 3 can't be IIV because there is two I's before V)
• Input and output should be left to right in order of value, starting with the largest (i.e. 19 = XIX not IXX, 10 is larger than 9)
• Left to right, no operator precedence, as if you were using a hand calculator.
• Supports whole positive numbers input/output between 1-4999 (no need for V̅)
• No libraries that do roman numeral conversion for you

### For you to decide

• Case sensitivity
• Spaces or no spaces on input
• What happens if you get a decimal output. Truncate, no answer, error, etc..
• What to do for output that you can't handle. Negatives or numbers to large to be printed.

### Extra Credit

• -20 - Handle up to 99999 or larger (numbers with a vinculum)

Sample input/output

XIX + LXXX                 (19+80)
XCIX

XCIX + I / L * D + IV      (99+1/50*500+7)
MIV


The shortest code wins.

• You might want to be explicit about which variants of Roman numerals need to be supported. For example, do I have to understand IV as 4, or can I require that it be written as IIII? And what about, say, writing 8 as IIX instead of VIII, 19 as IXX or XVIV instead of XIX, or 99 as IC instead of XCIX? (All these variants have, AFAIK, been used classically.) Feb 9, 2014 at 22:36
• @IlmariKaronen thanks. I modified the question to be slightly more specific about that. Feb 10, 2014 at 14:09
• I think that using IV, IX, IC, XC, etc. should be alright, but only allow one prefix. Also, 19 should be written XIX, not IXX. One other thing, can we assume that the operators will be separated by a space, or no?
– user10766
Feb 12, 2014 at 0:32
• Hello! This looks like a good but abandoned meta post, would you be willing to offer it for adoption? (If you want to, you can still post to main.)
– user58826
Jun 9, 2017 at 16:06
• 1. I don't need to handle I/III but need to handle I/III+II/III? 2. For the extra can I output maybe [V] for 5000?
– l4m2
Apr 12, 2018 at 15:05
• @programmer5000 it was posted to main awhile ago. codegolf.stackexchange.com/questions/20670/… Apr 26, 2018 at 11:58

# Create a calendar

We all know HDD-space is precious and bandwidth is expensive, therefore it is best to reduce the size of your executables. Let's start with your calendar:

Your task is to build a calendar app in at most 512 bytes. The calendar must at least support the following features, but additional features may gain you additional upvotes:

• It must be able to show the current month with the current day highlighted
• The user must be able to find out the week day of each day

Rules:

• Maximum code length is 512 bytes (counted as UTF-8 without BOM)
• You may subtract the bootstrapping code (i.e. int main(int argc, char **argv) in C or <?php in PHP) and imports from the final size to allow for more verbose languages to be in
• You may use standard time / date functions of your programming language, as long as they don't allow you to output a ready to use calendar
• No network access (I said bandwidth is expensive!)
• Voters decide on the amount of features / look and feel / creativity

This needs a tag for the size restriction, any suggestions?

• "bandwidth is expensive" <sup>[citation needed]</sup> Mar 22, 2014 at 5:27
• Seems rather close to Output: Calendar Month Mar 22, 2014 at 5:33
• Who decides what counts as bootstrapping code? It seems odd to arbitrarily exclude code like that, and the examples you gave can be golfed a lot: they're more or less equivalent to main(){ and <?  respectively. Mar 24, 2014 at 20:49
• @WanderNauta Bootstrapping code is the code that's essentiell to get a working noop program. Mar 24, 2014 at 21:00
• @TimWolla That definition won't fly. A zero-byte file is a working noop PHP script, for example. Mar 24, 2014 at 21:01
• @WanderNauta A zero byte file is a working noop in every language. Mar 24, 2014 at 22:12
• So what's bootstrapping code then? :) Mar 24, 2014 at 22:53
• for the limit I'd say code-shuffleboard or restricted-source Mar 26, 2014 at 15:57
• This sandbox post has had little activity in a while. Please improve / edit it or delete it to help us clean up the sandbox. Due to community guidelines, if you don't respond to this comment in 7 days I have permission to vote to delete this.
– user58826
Jun 9, 2017 at 16:28

Hi, first time golf questioner, hopefully I'm doing it right!

A maths trade (or "math" trade if you prefer) is a way of calculating complex trades of arbitrary items in a circle of participants where not all participants want all items.

X participants have an item they would like to trade. Each participant is assigned a unique number, and provides a list of (numbers identifying) the items they would willingly trade their item for. They may provide an empty list (i.e. they would rather not trade).

## Input

X lines, one for each participant, comprising a unique number identifying them, followed by a colon, then a comma-separated-list of numbers identifying other items that they would trade for. e.g.:

1:2,3,4
2:
3:1,4
4:2


The numbers identifying the participants will not necessary be in order, nor will they necessarily be 1 to X. You may assume that they will be numeric.

This string can be in STDIN, or an argument to a function, or similar and can be followed by a new-line or not, whatever the coder prefers.

## Output

One or more trade loops in which all participants are making trades they're happy with. Each loop should be on a new line and comprise a participant number, followed by "->", followed by the participant they should give their item to, then another "->", and another participant number etc, until the loop is closed and the last participant number matches the first one. Another line is added with the number of completed trades. e.g.:

1->3->1
2


Participants for which no valid trade is possible are omitted.

Output can be via STDOUT, or returned as a string, or something else, with an optional final new-line.

1. A participant may not be involved in more than one trade
2. A participant may not receive an item that they didn't want
3. All loops must be closed
4. Maximum number of possible trades should be completed (i.e. no submitting a zero-trade output and claiming it's valid). If there are multiple permutations, pick whichever you prefer.

This is a code golf challenge, so shortest working code wins.

### 1

1:2,3,4,5
2:3,5,7,9
3:1,2,5,6,10
4:
5:1,2,3,4,10
6:5,7,9
7:3,6,9,10
8:1,2,4,10
9:1
10:9

1->9->10->3->1
7->2->5->6->7
8


For instance, in this trade: 9 stated that he would accept 1's item in a trade, 10 stated that he would accept 9's item, 3 would accept 10's and 1 would accept 3's. In the second loop, 2 receives 7's item, 5 receives 2's, 6 receives 5 and 7 receives 6's. (Other outputs are possible from this input.)

### 2

1:2
4:
2:3
5:1
3:4

0


### 3

1:5,9
5:1
9:1

1->5->1
2


1->9->1 is also valid in this case, but both cannot be completed. Either is acceptable.

Thanks for reading guys! Let me know if there are any improvements I can make.

• "can be followed by a new-line or not, whatever the coder prefers." How flexible is this? For instance, can I use trailing commas, like 1:2,4,7, if it makes my code shorter? May 2, 2014 at 17:28
• Will the participants always be numbered 1 to n and their input lines provided in order? If so, state it. If not, include a test case which fails if an implementation decides to ignore everything before the : in each input line. May 5, 2014 at 10:02
• @m.buettner I would say a trailing comma is not acceptable, on the end of any line, or the end of the input/output. May 6, 2014 at 8:55
• @PeterTaylor Good tip. I'll correct the question to state that you can't assume that the numbers will be 1 to n, in order. May 6, 2014 at 8:57
• Hello! This looks like a good but abandoned meta post, would you be willing to offer it for adoption? (If you want to, you can still post to main.) Due to community guidelines, if you don't respond to this comment in 7 days I have permission to adopt this.
– user58826
Jun 9, 2017 at 16:39

## Design and Solve a Maze

(this question on hold while the details are ironed out)

Your task is to play the roles of both characters in this scene from Inception. In it, Cobb gives Ariadne a challenge:

You have two minutes to design a maze that takes one minute to solve.

Some liberties will be taken on that description. Most importantly, this challenge is not time-based, rather scores are based on the effectiveness of your mazes and maze-solvers.

I apologize for the many edits to this challenge as we iterate towards an easy and fair format..

### Part I: Maze format

All mazes are square. A cell in the maze is represented as a zero-indexed tuple row column.

Walls are represented by two binary strings: one for horizontal walls (which block movement between rows) and vertical walls (vice versa). On an NxN maze, there are Nx(N-1) possible walls of each type. Let's take a 3x3 example where the cells are labelled:

A   B | C
---
D | E   F
---
G   H | I


all possible vertical walls are: AB BC DE EF GH HI. Translated into a string, the walls shown are 011001 for vertical walls and 010010 for horizontal walls. Also, by "binary string" I mean "the characters '0' and '1'".

The full maze format is a string which contains, in this order:

• width
• start cell tuple
• end cell tuple
• horizontal walls
• vertical walls

For example, this maze:

   0 1 2 3 4
_________
0 | |  E|  _|
1 |  _|_|_  |
2 |_ _ _  | |
3 |  _ _  | |
4 |____S|___|
start:(4,2)
end:(0,2)


is formatted to this:

5
4 2
0 2
00001011101110001100
10100110000100010010


### Part II: The Architect

The Architect program creates the maze. It must play by the rules and provide a valid maze (one where a solution exists, and the end is not on top of the start).

input via stdin: Two positive integers:

size [random seed]


Where size will be in [15, 50]. You are encouraged to make use of the random seed so that matches can be replayed, although it is not required.

output to stdout: A valid size x size (square) maze using the format described in Part I. "valid" means that a solution exists, and the start cell is not equal to the end cell.

The score of an Architect on a given maze is

   # steps taken to solve
------------------------------
max(dist(start,end),(# walls))


So architects are rewarded for complex mazes, but penalized for each wall built (this is a substitute for Ariadne's time restriction). The dist() function ensures that a maze with no walls does not get an infinite score. The outside borders of the maze do not contribute to the wall count.

### Part III: The Solver

The Solver attempts to solve mazes generated by others' architects. There is a sort of fog-of-war: only walls adjacent to visited cells are included (all others are replaced with '?')

input via stdin: the same maze format, but with '?' where walls are unknown, an extra line for the current location, and a comma-separated list of valid choices from this location. (This is a big edit that is meant to make it simpler to write a maze-parsing function)

example (same as the above 5x5 maze after taking one step left)

5
4 2
0 2
???????????????011??
????????????????001?
4 1
4 0,4 2


Which corresponds something like this, where ? is fog:

   0 1 2 3 4
_________
0 |????E????|
1 |?????????|
2 |?????????|
3 | ?_?_????|
4 |__C_S|_?_|


output to stdout: One of the tuples from the list of valid choices

Each Solver's score is the inverse of the Architect's score.

### Part IV: King of the Hill

Architects and Solvers are given separate scores, so there could potentially be two winners.

Each pair of architects and solvers will have many chances to outwit each other. Scores will be averaged over all tests and opponents. Contrary to code golf conventions, highest average score wins!

I intend for this to be ongoing, but I can't guarantee continued testing forever! Let's say for now that a winner will be declared in one week.

### Part V: Testing

I have written a Python testing kit which includes a Maze class for parsing and writing in the proper formats, as well as an example architect/solver pair: Daedalus and the Minotaur

Available on both Dropbox and GitHub

### Part VI: Submitting

• I maintain veto power over all submissions - cleverness is encouraged, but not if it breaks the competition or my computer! (If I can't tell what your code does, I will probably veto it)
• Come up with a name for your Architect/Solver pair. Post your code along with instructions on how to run it.
• I suppose input is via STDIN? You might want to mention that explicitly, because at least the architect could just as well take the input via command-line arguments. May 15, 2014 at 15:34
• updated. I have a driver/referee program which will handle I/O; I'll update it to use stdin/stdout since that will no doubt be the easiest standard. May 15, 2014 at 16:04
• @m.buettner before de-sandboxing this, would you be willing to try the test kit? May 15, 2014 at 18:20
• I'd love to, but I'm afraid I'm too busy this week. Try ask for help in the chatroom. May 15, 2014 at 18:35
• Possible architect issue: With this scoring method (steps/walls), you can get a minimum score of 3 by simply putting the start/finish right next to each other with a single wall between. It takes three steps to go around. Most actual mazes I've seen have too many walls to make a score of 3 likely, much less guaranteed. May 16, 2014 at 13:51
• Thats a problem. What if the dist function was shortest path? Then only mazes which cause detours could get a score > 1 May 16, 2014 at 15:09
• That would probably be better. That way it's scored on best vs actual. It would take away the incentive to figure out how to build hard mazes with few walls, though, which was interesting itself. May 17, 2014 at 3:01
• Hey rangu... not sure if you're still planning to do this thing, but overactor just said something in chat which reminded me of your challenge and might be a neat way to avoid the combined score: split this up into two code-challenges, one for maze generation and one for maze solving. Each code-challenge's benchmark set (to determine the scores) would be the outputs of the other challenge's participants. Then you could just pick a best solver and a best generator independently. Aug 1, 2014 at 11:18

Author note: I was thinking about new genres today, and I had an idea. What if there could be a challenge that encourages people to write good code, instead of the code-golf gibberish we all know? Here's a challenge that attempts to do that. (This could even possibly be a , which would be great because it would bring in a greater high quality question volume to the site, but I'm terrible at coming up with names. Feel free to suggest something in the comments.)

# Build your own image editor

For this challenge, you will create the best GUI image editor that can perform the most tasks that you possibly can... from scratch.

Here are the features / tasks used to score your program. Each task is worth a certain amount of points, which is specified in brackets before the task description. For convenience, each task will also be prefixed by an ID string so that you can refer to them when describing your program.

• [1 A] Brush tool: Simple, click and drag the mouse to draw freestyle doodles. Must draw a contiguous path.
• [1 A1] Ability to change the brush size.

## Requirements

Your editor must conform to the following requirements:

• Must accept input via the mouse. Tools (brush, flood fill, etc.) can be switched and configured with keyboard shortcuts, by clicking icons with the mouse, through a menu, or however you would like.
• You may not use a single built-in function to accomplish one or more of the tasks. For example, if your language has a built-in image flood fill function, you may not use it and must build your flood fill from scratch.

## Final score and voting

# {language}, {your score} score
<sup>(features implemented: {A, A1, ...})</sup>

{description, comments, other notes, etc. here}


• elegance and readability of the source code
• ease of use of the image editor and how powerful it is
• remember to sort by "active" so that you're voting for new answers too, and not just the top voted ones!
• Your questions should be reasonably scoped. If you can imagine an entire book that answers your question, you’re asking too much. A really good answer to this would run into millions of lines of code. Jun 4, 2014 at 15:52
• @PeterTaylor Yes, I was a little worried about that, but if it's not broad enough, it will be easy to just implement all the features. Any suggestions for fixing this? I was thinking of adding a "brevity" criterion in the voting section, but that doesn't seem like an ideal solution. Jun 4, 2014 at 16:00
• To be honest, the site for good code is Code Review. They already have a monthly challenge, for which they post snippets for review. I don't see a need to copy them. Jun 4, 2014 at 16:12
• @PeterTaylor Wait, isn't Code Review for questions and answers, not challenges and contests? In any case, is there any reason for that to prevent us from posting challenges like we always have? Jun 4, 2014 at 16:17
• meta.codereview.stackexchange.com/questions/tagged/… . Surprised you don't know about it, given how dedicated you are to spying on them ;) In general, if a question is on topic for multiple stacks then there's no obligation to do the sensible thing and post it on the one which it best fits, but you should expect people to ask why you're not doing the sensible thing. I think you're going to have to work hard to turn this into a question which fits this site, whereas it's already a good fit for CR's challenge programme. Jun 4, 2014 at 16:31
• @PeterTaylor Hmm, that's strange. Wouldn't that be more on-topic here? (And I only occasionally pop in to their chat/meta to see what they're up to. :-P) Jun 4, 2014 at 16:32

# Help Joe Bloggs with his password hash

Joe was confidently using "password1" as his main password to all his accounts until one day he received an e-mail from fBay. His account has been compromised and he must change his password immediately. Yet worse, the attacker had access to all Joe's accounts. Being an engineer, Joe thought: What if I could hash somehow my password using a keyword? I wouldn't need to remember any passwords and I would have a different one for each account.

Joe then creates an algorithm - he takes the domain name as a key and creates the password for each of his account consisting of:

1. (<consonants><vowels>)(alternating case: lower, capital, lower...)
2. <number of consonants><number of vowels>
3. <sum of consonants and vowels numbers converted to a character on US Qwerty Keyboard>


Joe then opens an account on SO to create a new code golf challenge. He uses stackoverflow as a key to generate password:

1. sTcKvRfLwAoEo - consonants and vowels in alternating case
2. 94 - 9 consonants, 4 vowels
3. 9+4=13, 1+3=4, Shift+4=$ Therefore, Joe's password for stackoverflow is: sTcKvRfLwAoEo94$

### Challenge

Create a shortest function to generate a password given the rules above. The code should accept a string type parameter d and return/display the generated password.

### Rules

1. Only Latin letters from the input should be used. Any other characters should be ignored.
2. Minimum input length is 1 letter. (guys at q.com need passwords as well!)
3. Assume Y is a vowel
4. If vowels or consonants are missing, use 0 accordingly. E.g. input a would result in a01!
5. Shortest code wins

List of vowels and consonants

US qwerty keyboard

• Thanks for the feedback @m.buettner. I meant to say, without using any libraries. The problem is, that people become lazy to think sometimes and just dive straight away to use Linq where a bit of thought will do
– mai
May 28, 2014 at 13:14
• Well actually you can, I'm just checking now. You can do a lot of manipulations on strings without libraries.
– mai
May 28, 2014 at 13:18
• Looping over string characters, concatenation work perfectly. Nevertheless, I've updated the challenge. If a function to depend on a library, it must be included in the character count.
– mai
May 28, 2014 at 13:21
• 1. Strictly speaking, in .Net you don't have strings without libraries. The string keyword is syntactic sugar for a class in mscorlib. 2. As things currently stand, your rule 1 strictly prohibits something and then says what to do if you ignore that prohibition. This is illogical. It's also unclear what "that" in "please inlcude that in characters count" means. Does it mean that each submission should be a program as opposed to a code snippet? If so, state it explicitly. May 28, 2014 at 13:32
• Hmm.. I don't know how to write it the best way. mscorlib is included by default so that is permissible. I don't want the code to use other libraries as Linq as it's less fun.
– mai
May 28, 2014 at 13:47
• @m.buettner I agree with you. Nevertheless, there will solutions provided in other languages as well (there always are). And I would like the authors of those solutions to think about the best approach in their language of choice without depending on libraries like Linq.
– mai
May 28, 2014 at 14:00
• Does Rule 2 mean ONLY vowels/consonants to be used from input? What about symbols *@#\$ etc. Depending on that answer, potentially clarify Rule 5 regarding symbol input. As for Step 3 in the hash, should that progress further, similar to my Appended Numbers game so 103 consonants and 5 vowels would follow as 103+5 = 108, 1+0+8/10+8, etc.?
– Matt
Jun 4, 2014 at 2:35
• @Matt, clarified - only Latin letters are used from the input. If consonants or vowels are missing, use 0 instead. The sum should progress, until it's <=9. E.g. 103 consonants, 5 vowels: 103+5=108, 1+0+8=9. Then, Shift+9='('
– mai
Jun 18, 2014 at 10:36

# Diplomacy

Note for Sandbox: I have not finished (or really started) the control program for this game, because I wanted to see if there was interest in it before I dedicated too much time to the project. that means that the rule are still up to be tweaked, so please leave a comment if you have a suggestion, and comment or vote if you are interested in seeing this happen.

Diplomacy is a complex strategy game, with a very entertaining combat system. This challenge will be to write a bot to compete in a simplified version of diplomacy combat.

## Rules

### Rounds

Countries (bots) will begin the game with 10 health, representing their remaining will to fight. The goal is to eliminate all other Nations by attacking them until they have 0 health.

The game will consist of several rounds. On the first round, all bots will receive 2 numbers as command line arguments: The first will be the total number of countries fighting, and the second will be their number in the list. Each following round, bots will receive a command line arguments containing the actions taken by each player last round and a list of all bots and their remaining health separated by commas, like so

 1:A2,2:S3,3:A4,4:A3 1:10,2:7,3:7,4:1


Each bot must then output a desired action, which is one two commands

1. Attack a player. This is done by printing the letter A followed by the number of the player you with to attack. For instance, A3
2. Support a player. This will give the player you support a boosted attack.

### Resolving combat

After player have sent in their moves, attack scores will be calculated thus:

1. All players start with a strength of 1, and one point is added for every player supporting them. For instance, if the moves are 1:A3,2:S1,3:A2,4:S2 then bot 1 has strength 2, bot 2 has strength 2, bot three has strength 1, and bot 4 has strength 1.
2. After strength has been calculated, bots will deal damage based on their strength. The formula for damage is (Attacker's strength + 1) - (Defender's Strength)` In the above situation, player 3 would take 2 damage and player 2 would take 0 damage. Note that, unlike regular diplomacy, attacking a supporter does not cut support.
3. All attack take place simultaneously and independently. This means that if player 1 and 2 both attack player 4, then they each deal 1 damage. If player 3 were to support player 4, then player 4 would take no damage.

### Round Ends

After combat has been resolved, countries that have 0 health will no longer be able to attack or support. However, they still will be listed in the input with an health of 0. When a bot is eliminated, all remaining bots will receive a single point.

### Ending the game

The game ends when either 100 turns have elapsed or only 2 or less players remain. At this point, the player with the highest remaining health is the winner and receives 1 point. In case of ties, all tied bots will revive 1 point. If all bots die on the same turn, this is not a tied victory, but mutually assured destruction, and all bots will receive 0 points.

### Scoring

The control program will run 100 rounds of the game. The winner will be the country with the most points at the end of 100 rounds.

## Code

You may write in any language I can reasonably compile. I will make an effort to compile odd languages, but make no promises as to my ability to do so. Please provide your source code, an explanation, and a command line command to run your program.

Notes
• You are allowed to write to a file. In fact, you are encouraged to do so.

• Because this is a game where cooperation is paramount, you are allowed to write bots that work together, with the following restriction:

• Only two bots can be written by a single player to work together at a time.
• Standard Loopholes apply. You are not allowed to change the way the control program runs. If you provide invalid input to the control program, the program will just skip your turn. However, you are allowed to spy on other countries files, and all bot programs will be in the same folder at runtime. This is war, after all!

• I reserve the right to disqualify any country that takes more than about a second to run, or that tries a loophole not mention within. That being said, if it is sufficiently clever I will probably let it go.

I will have source code up soon for a sample country that will be competing, and will post the control program when I finish it.

• "In case of ties, all tied bots will revive 1 point". Is that supposed to say "receive"? "If all bots die on the same turn, ... all bots will receive 0 points." If there are two bots left, each of which has received 1 point from the earlier death of a third bot, and the two bots destroy each other on the same turn, what's the final score for the round? I'm not sure whether it's 0-0-0 or 1-1-0. "You are allowed to write bots that work together": but how can they identify each other? Do they have to use their moves as a covert channel? Aug 29, 2014 at 14:28
• "Support a player. This will give the player you support a boosted attack." Or defence. Might be clearer to say "boost that player's strength for the turn". Should also state whether or not it's possible to support yourself. Aug 29, 2014 at 14:29