# What is the Sandbox?

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

See the Sandbox FAQ for more information on how to use the Sandbox.

## Get the Sandbox Viewer to view the sandbox more easily

To add an inline tag to a proposal use shortcut link syntax with a prefix: [tag:king-of-the-hill]

# First 100 Twin Primes

### What Are Twin Primes?

Twin primes are two prime numbers that has a gap of 2 between them; i.e. 3-5, 5-7, 11-13...

### Goal

• Take no input and print first 100 twin primes to STDOUT.
• Shortest code in bytes wins.

### Rules

• Your submission should be an executable complete program.
• Every prime couple should be on a new line.
• Printed twins should have a space between them.
• All standard rules are applied.

### Restrictions

• No usage of built-in or external methods or functions that returns a prime number.
• No hardcoded prime numbers except 2 (as number, not count).

Any suggestions? I looked to similar questions but i couldn't see an identical one.

• Unfortunately, we consider questions for which most solutions can be easily transferred duplicates, so without the restriction on builtins (and probably even with) your question would be closed as a duplicate of codegolf.stackexchange.com/questions/31822/… – lirtosiast Nov 10 '15 at 1:14

# Rounding Fractions

Back in the old days of game programming, before FPUs were the norm, games predominantly used fixed-point math to represent non-integer values. Typically, the lower 8 or 12 bits of a 32-bit word are used as fractional parts, and the rest are treated as the integral part. Sometimes when looking at fixed-point constants in old game code, I get confused trying to figure out what they were actually trying to approximate, particularly if it's not a number between 0 and 1 (0x4C = 0.3, 0x119 = 1.1?, 0x73 = ???).

Since just rounding 1/256ths and 1/4096ths has a limited range of applications, the challenge here is to take any integer ratio a/b, and output the simplest fraction that rounds down to it. More specifically, output the ratio p/q with lowest denominator such that a/b ≤ p/q < (a+1)/b.

This code should support any non-negative a and positive b up to at least 10,000, and should run in a reasonable time for anything in that range (nothing on the order of minutes, at least). Answers should be correct, i.e., no rounding errors due to floating-point. Answers can be in the form of a full program or function, and use any convenient input / output (a string '1/2', an ordered pair (1, 2), a list of two integers {1, 2}, etc).

This challenge is code-golf, lowest score in bytes wins.

Some test cases:

1/3 -> 1/3
4/10 -> 2/5
33/100 -> 1/3
66/100 -> 2/3
67/100 -> 19/28
115/256 -> 9/20  (who knew?)
0/417 -> 0/1
653/654 -> 653/654
1404/702 -> 2/1


## Sandbox Questions

Hey! I'm a long-time lurker, first-time-question-asker; I'm pretty sure this hasn't been asked before (more general than "Un-round fractions", not quite "Closest fraction"). Not sure what to set for a deadline before accepting an answer, since this is my first time actually participating. Anything else obvious I missed?

• Don't set a deadline before accepting an answer, at least in the sense of putting a date in the question. As a rule of thumb, wait a week, accept the winning answer, and if someone later posts an improved answer then change the accepted answer. – Peter Taylor Nov 14 '15 at 18:19
• Sort of duplicate? The differences seem to be normal rounding vs rounding down and the odd restriction to a single loop in the existing challenge. – Martin Ender Nov 14 '15 at 23:46
• That challenge is only about decimals, whereas this starts with an arbitrary rational number. Not sure if that's enough of a differentiation, but this one's broader, I guess. – Jonathan Aldrich Nov 15 '15 at 0:02
• @MartinBüttner, I agree it's borderline, but some of the answers to the older question couldn't easily be adapted because they rely on converting float to string, and that only works in base 10. – Peter Taylor Nov 15 '15 at 8:47
• @PeterTaylor It is a duplicate. floor(x)=round(x-0.5) – Xwtek Nov 17 '15 at 12:04
• @ChristianIrwan, why is that relevant? – Peter Taylor Nov 17 '15 at 14:32
• @PeterTaylor Oh, sorry, misread. – Xwtek Nov 18 '15 at 9:45

# Nondeterministic Turing Machine

## Introduction

We all know the concept of Turing machines, if not let's reiterate the concept. We have the following things that define a Turing machine:

• A tape that is divided into cells and is (potentially) infinite to the right.

• A transition function that defines state changes and the direction in which the head shall move, based on the current state and the input read.

We can now have to supply some input, and the definition of the transition function (the set of states is implicit, and contains all states defined in the function). Additionally we assume that the alphabet is [0-9a-zA-Z!?()^+-] and space is the blank symbol. The tape head is then postioned over the leftmost character on the tape, which in our case is the first character of the input tape. The machine then starts applying the transition function. The computation continues until one of the following happens:

• The machine reaches the HALT state
• There is no transition defined in the transition function for the current state with the given input.

If the first case occurs, we say that the machine "accepts" the word. If the second case occurs we say that the machine "rejects" the word.

We can now extend this definition, to obtain a nondeterministic Turing Machine. To do this we allow the transition function to define more than one "next" state for each state/input combination. The machine can then choose which "execution path" to take. We then say that the machine accepts the word if it reaches the "HALT" state in any execution path, and it rejects it if it does not reach this state in all exection pats.

## Problem definition

You must supply a program or function that accepts a string and returns a truth-ish value (either true/false, or 0/1, or anything else, at long as the meaning is clear) indicating wheter the word is accepted for at least one computation path or not. The input has the following for:

(<current_state>,<input_read>,<output>,<follow_up_state>,<move_direction>)


All the parts of the tuple are provided as strings where

• <input read> is a string of length 1, which can contain any character except ","
• <output> is also a string of length 1
• <move_direction> is either "l" (move left) or "r" (move right)

You may assume the following:

• The machine will always halt (i.e. no infite loops)
• There is only one state on which the machine halts which is HALT
• The alphabet is [0-9a-zA-Z!?()^+-] plus space as the blank symbol
• The leftmost character is always a blank, to indicate the ending of the tape on the left side.
• States are defined implicitly by the tranistion function. So the only states the machine knows are the one that occure during the definition of the transition function and there is no explicit definition of the states.
• The initial state is always s_i

The input has the following form

<nr_of_tuples_for_definition_of_transition_function>
<tuple_1>
<tuple_2>
...
<tuple_n>
<input_string>


All lines end with a newline character (\n) and the input string is not under double quotes.

Standard loopholes are disallowed! Shortest answer in byte wins.

# Notes

Working example is still missing, I'll update that in the following days

• "The machine then starts the computation at the beginning of the input": I suggest adding "i.e. with the first character under the tape head, and the others to the right". I'm not sure what you mean by "States are defined implicitly by the tranistion function". – Peter Taylor Nov 13 '15 at 13:59
• Followup questions: 1. What characters can appear in the name of a state? 2. What delimiters occur between the tuples in the input? 3. What delimits the end of the initial tape contents and the start of the tuples? – Peter Taylor Nov 13 '15 at 18:20
• Thank you very much for your feedback. I just realized that I didnt think the input part through, I'll need some time to rethink that. – wastl Nov 13 '15 at 18:54
• I realised today that there's another thing which needs specifying in the input: what is the starting state? This could done implicitly by saying that it's the <current_state> of the first tuple. – Peter Taylor Nov 14 '15 at 18:20
• I added input specification. Do you think this is an adequate method to provide the input? – wastl Nov 16 '15 at 11:39
• Yes, that works. – Peter Taylor Nov 16 '15 at 12:16

# DND Level Tables

In 3rd edition DND, there a lot of stats that you have to keep track for when you level up. Let's fix that by making some nice tables for them.

## Crash Course on 3rd edition DND

3rd edition DND is very complex since it does not have "classes" in the traditional sense of most RPG games. Instead of picking a class when you create a character and more or less sticking to it, in 3rd edition you can actually "opt in" into any class you want at any time. Essentially, when you level up, you can choose to put that level in any class you want. This means that you can potentially have three levels in Rogue, two levels in Fighter, etc.

In addition to this, 3rd edition has special things called skills, which are unique to each class. When you level up you get some skill points that you can spend on skills. You can spend one skill point to get one "rank" in a skill. However, if that skill does not belong to your class you only get one-half of a "rank" in that skill. There are also feats, which are essentially general skills that don't belong to any class and have their own "skill points", and stat increases, which are little stat bonuses you get on level up.

All together, this is probably enough to make your head swim. Luckily, this challenge doesn't require you to get too much into the nitty gritty of this.

## Challenge

Given an number representing a level as input, print out a table starting from level 1 up to and including the specified level of the following stats:

• The total amount of XP you've gained to reach this level

• Maximum class skill rank you've gained

• Maximum cross-class skill rank you've gained

• Whether you've gained a feat or stat increase (they are not gained every level) and the number of it.

The stats should be in this exact order. The table should be formatted with columns for each stat, with at least 4 spaces between each column. The level, feat and status increase numbers should have their appropriate suffixes (like 3rd). If you do not get a status increase or feat at a level, write -- where the feat or status increase number would go.

Now, without further ado, the math for all of this. Assume x is the level.

Total XP:

Class Rank:

Cross-Class Rank:

Feats: If

(x divisible by 3), then you have gained your

feat. You also automatically gain a feat at 1st level.

Stat Increases: If

then you have gained your

stat increase. Unlike feats, you do not get one of these at 1st level.

## Examples

Sample input: 40

Sample output:

1st    0    4    2.0    1st    --
2nd    1000    5    2.5    --    --
3rd    3000    6    3.0    2nd    --
4th    6000    7    3.5    --    1st
5th    10000    8    4.0    --    --
6th    15000    9    4.5    3rd    --
7th    21000    10    5.0    --    --
8th    28000    11    5.5    --    2nd
9th    36000    12    6.0    4th    --
10th    45000    13    6.5    --    --
11th    55000    14    7.0    --    --
12th    66000    15    7.5    5th    3rd
13th    78000    16    8.0    --    --
14th    91000    17    8.5    --    --
15th    105000    18    9.0    6th    --
16th    120000    19    9.5    --    4th
17th    136000    20    10.0    --    --
18th    153000    21    10.5    7th    --
19th    171000    22    11.0    --    --
20th    190000    23    11.5    --    5th
21st    210000    24    12.0    8th    --
22nd    231000    25    12.5    --    --
23rd    253000    26    13.0    --    --
24th    276000    27    13.5    9th    6th
25th    300000    28    14.0    --    --
26th    325000    29    14.5    --    --
27th    351000    30    15.0    10th    --
28th    378000    31    15.5    --    7th
29th    406000    32    16.0    --    --
30th    435000    33    16.5    11th    --
31st    465000    34    17.0    --    --
32nd    496000    35    17.5    --    8th
33rd    528000    36    18.0    12th    --
34th    561000    37    18.5    --    --
35th    595000    38    19.0    --    --
36th    630000    39    19.5    13th    9th
37th    666000    40    20.0    --    --
38th    703000    41    20.5    --    --
39th    741000    42    21.0    14th    --
40th    780000    43    21.5    --    10th


## Reference Implementation

Perl:

sub formatNum {
$_=pop;$first = substr $_,-2,-1; if($first == "1" and length $_ > 1) { return$_."th"; }
$digit = substr$_,-1;
if($digit == "1") { return$_."st"; }
if($digit == "2") { return$_."nd"; }
if($digit == "3") { return$_."rd"; }
else { return $_."th" }; } sub space { print " "x4; } while(<>) {$limit = $_; for(my$c = 1; $c <=$limit; $c++) { print formatNum$c;
space;
print ($c*($c-1)*500);
space;
print ($c + 3); space; printf ("%.1f", ($c - 1)/2 + 2);
space;
if($c % 3 == 0) { print formatNum$c/3+1; }
elsif($c == 1) { print "1st"; } else { print "--"; } space; if($c % 4 == 0) { print formatNum c/4; } else { print "--"; } print "\n"; } }  Try it online. ## coreutils default behavior stdin/stdout We have a lot of challenges to implement just one of these operations, but a lot more are missing. Instead of adding a challenge for each of them, I thought I'd see if I could make a multiple-holes challenge that's complex enough to inspire some code re-use. This challenge is to reproduce a small subset of what Busybox does, namely to implement the default behavior of [almost] all of the GNU coreutils that (usually) read input from stdin or a file and send output to stdout or a file. The utilities to reproduce are as follows: 1. cat copy stdin to stdout 2. tac copy stdin to stdout, reversing the order of the input lines (last line first) 3. nl copy stdin to stdout, adding a line number to the start of each line. Start at 1, use spaces to pad each number to a width of 6, and add two spaces between the line number and the original line 4. od I can't come up with a concise unambiguous way to describe the default output from od. I might skip it. 5. base64 for every 3 bytes of stdin, split into groups of 6 bits, look those 6-bit values up in the base64 alphabet, and output 4 such bytes to stdout. wrap output lines at 76 characters. pad missing bits with 0s, and output an all-padding 0b000000 as "=" I'll finish filling out descriptions for some subset of the following if this idea proves popular enough to proceed with. fmt, pr, fold, head, tail, split, csplit, wc, sum, sort, shuf, uniq, ptx, tsort, cut, tr, expand, unexpand, yes The format of an entry would be either one program or one function, which can perform all of these tasks, just like busybox can. As a program, it might read its own process name to decide which tool to run. As a program or a function, the first parameter might be which tool to run. As a program, input should come from stdin and go to stdout. As a function, input should be a single string parameter, and return a single string. • I think it would be better to say "These ones have already been implemented" with links to the appropriate questions, and to then ask for a multi-tool which implements the non-dupes. That keeps things clear and, frankly, the ones which have already been done are probably mainly the less interesting ones. – Peter Taylor Nov 21 '15 at 23:07 • @PeterTaylor fewer holes means less likelihood of code reuse. I'm annoyed at other challenges where code reuse is possible but it's not useful. I hope to see it in winning entries here. – Sparr Nov 22 '15 at 2:06 # Find the nested source codes A cops and robbers challenge where the cops write between 2 and 8 programs that produce output in the same language and interweave the programs together. WLOG, let's discuss this action being performed on two programs. By interweaving, I mean adding the characters of the second program to the first program so that when the characters of either the (WLOG) first program are removed, the second program can be seen. Obviously, commenting in any program is not allowed. The cops will post their combined codes, the number of different programs in what they post, and the language the codes are written in, and what the programs print as output. To get credit for cracking the submission, the robbers must post the split codes and what each one outputs. As a general rule, cops cannot use a language more than once. Scoring A cop will receive points if their submission is safe for one week from the time of posting. Their score will be the sum of the two following. • The first value is 256 divided by 2 to the power of the number of different programs used. • Round the number of bytes in the combined codes up to the nearest power of 2 and call this number x. The second value is 1024 divided by x. A cop will lose 10 points for every code that is cracked before the one-week period is up. Robbers will receive a number of points equal to the sum of the following for each cracked submission. • The first value is 2 to the power of the number of different programs used in the cop's answer. • Round the number of bytes in the combined codes up to the nearest power of 2 and call this number y. The second value is 1024 divided by y. Example Python, 2 codes prpriintn("t"(hlellamlao")"[0]) Prints llama and h Codes: print("llama") and print("hello"[0]) • Can I see an example? – Conor O'Brien Nov 22 '15 at 1:46 • @CᴏɴᴏʀO'Bʀɪᴇɴ Updated. – Arcturus Nov 22 '15 at 1:54 • On interweaving: does one have to say which method they used to interweave? – Conor O'Brien Nov 22 '15 at 1:57 • Interweaving is done in order. The example given would be prPRiIntN("T**"(HlElLamLaO")"[0]**, where bold and capitalization represent the second code. – Arcturus Nov 22 '15 at 2:03 • @CᴏɴᴏʀO'Bʀɪᴇɴ Think this is good enough to post officially? – Arcturus Nov 22 '15 at 2:36 • I'd wait a day or two, and ask some other people in chat. – Conor O'Brien Nov 22 '15 at 3:03 # Complete the Digit Sequence We have a string of digits with some elements missing and marked with .s. 74..7.1..1.3...8.781256  We want to fill the missing parts in a way that they would form an arithmetic sequence with the previous on next elements. E.g. 8...2 becomes 8642. If this kind of filling is not possible with single digits, mark the positions with ?. E.g. 7..3 would become 7??3. With this rules our original example becomes 745674111123???8?781256  You should write a program or function which receives a digit string as input and outputs or returns the filled sequence. Input: TODO  Output: TODO  Examples: TODO  This is code golf so the shortest entry wins. Sandbox note: this seems boring so ideas are welcomed. • Idea: turn the entire string into an arithmetic sequence of as many integers as possible (after inserting spaces). e.g. 7....2 would become 765432, i.e. 7 6 5 4 3 2, but 7....3 would have to become 791113, i.e. 7 9 11 13, whereas 7....4 would have to become 727374 (72 73 74) or 767574 (76 75 74) – Martin Ender Nov 23 '15 at 11:38 • @MartinBüttner I like it although I would like to avoid the extensive brute-force approaches. – randomra Nov 23 '15 at 12:37 • I just noticed there are a lot more possibilities for my last test case, like 72 53 44. But yeah, I'm not sure how much one could optimise solutions for this. (Also, I'd still keep the possibility of given digits within the sequence, I just used the x....y format for simplicity.) – Martin Ender Nov 23 '15 at 12:40 # The Language Relay! A typical relay race only has four competitors per team, but where's the fun in that? Instead, let's see how many teammates you can cram onto the bus to the stadium and still finish the race. (This analogy is starting to break down, so I'll cut to the chase.) Your task is to write a program or function in 256 bytes or less. It will take no input, and its output will be a program or function in another language. That program or function will also take no input, and its output will be a program or function in another language... and so on and so forth, until the last program, which will output the following: . \O/ . |===== |_ =====| | _/ | |  The winner is whoever manages to use the most languages. If there is a tie, the winner is the one with the shortest code in bytes. You cannot use the same language twice, and different versions of the same language do not count as different languages. The output must also be different every time (no using languages that leave the program or function untouched.) Here's a small example: #include<stdio.h> int main(){printf("print(\". \\O/ .\\n|===== |_ =====|\\n| _/ | |\")");}  This C code produces this Python code: print(". \O/ .\n|===== |_ =====|\n| _/ | |")  And the Python produces the final output. I've used two languages, so my score is 2, and I'm going to lose terribly. • I'd implement some way to incorporate byte counts into the score because otherwise I'm sure there will be plenty of ties. – Downgoat Nov 25 '15 at 17:45 • Good idea, thanks. – Luke Nov 25 '15 at 17:46 This might already exist, but through my search I couldn't find anything like it, so here it goes. ## Find My Number code-golf My friends and I have made are playing a game where we have a variable N that represents a number from 0 to 10. Using an expression they give us containing + - * / for addition subtraction multiplication and division, > < = for greater than, less than, and equal to, and the integers 0-10, we must find there number or what their number can possibly be. I’m lazy, so I want you to write a Program that takes an input from STDIN or an acceptable alternative and return the possible numbers to STDOUT or an acceptable alternative. Examples: Input: N+3>N*2-2 Output 1, 2, 3, 4 Input N+2=N*2 Output 2 Input N*4/6=N*2 Output 0 Because I might be caught, I want the program to be a small as possible in characters to avoid me friends seeing it, so the shortest solution wins! • What it is impossible such as N<N or the result is all real numbers such as N=N? – Downgoat Nov 26 '15 at 16:18 • Well in the first one is impossible, so nothing works, so it doesn't output anything. The second one since anything works it prints all numbers 0-10 – Generic User Nov 26 '15 at 20:12 • I assume that the n in one of the examples is a typo for N. This is not really an interesting question. The addition of < and > makes it marginally different to existing "evaluate this expression" questions, but it's still trivial to handle with eval in languages which use infix operators. – Peter Taylor Nov 26 '15 at 21:14 • Thanks for pointing out the typo, I think expression still works since I explained what I mean, but I will try to find a way to reword the question. Anyone have suggestions? – Generic User Nov 26 '15 at 21:43 I'm thinking I want to make a KOTH challenge that has bots play the classic game of Mafia. Bots will be placed in groups of seven, roles randomly assigned, and they play the game! Explanation of Game Mechanics The game proceeds in multiple turns, each turn consisting of Night followed by Day. At night, each person completes his role as will be described below. During the daytime, players (in real life) discuss the events of the night (communicated by God, a separate person who does not participate in the game besides prompting people to their roles.) Just before night, the players have the option of voting to lynch another player, the objective being to lynch a mafia member to help the town win. Choosing not to lynch is always an option if you think it is too risky to lynch someone who might be innocent. In real life, God would tell everyone to sleep, then ask mafia to wake up and silently agree on who to kill, tell them to sleep, and continue with the other roles in a similar manner. Town wins if all the mafia are dead; mafia wins if they at least outnumber the town. There are four roles in this game, but I have played many games with more than seven people with more ridiculous roles that are very fun to play. Each player bot is assigned an ID number indicating his role. • Mafia - There will be 2 mafia in this game. The two mafia will come to a consensus on who to kill. If one is dead the other decides on his own. The two mafia can not choose one of them to be killed. Mafia has a role of either 1 or 2, which are identical in function. • Inspector - There will be 1 in this game. At night he visits a person, and receives a report on that person's innocence. Both Mafia members will appear as guilty and the rest will appear as innocent. He can not inspect himself nor dead people. His number is 3. • Doctor - There will be 1 in this game. At night he visits a person, and that person will not die that night. Doctor can not save himself nor dead people. His number is 4. • Townsperson - Does nothing at night. Numbers 5, 6, 7. The Challenge You will write a Java player class who will have (at least) three important methods: night, claim, and vote. All of these three methods will return the player to 'act' on (of course, depending on your role), given an ArrayList of information that the other players have claimed in public. I am not very clear on how to run a KOTH challenge and what github is supposed to do and how to use it so it would be very helpful if someone could point me in the right direction. As of now I'm still working out the exact details of a Java class to run the game, as well as making a generic Player class that the answers will have to extend and use methods from. Right now, I have a generic Player class that each answer will extend, and each Player object has two Identity objects: a public, claimed Identity and a private Identity. The private Identity will hold the players actual role (kept secret, of course), as well as a doctor arraylist of Integers and a cop arraylist of Strings. If the player happens to be a cop, the controller program will add an entry to the private cop arraylist which will serve as his way of receiving a verdict. I'll make a method called verdict() which returns the last element to make the programming easier. An example string is "4G" which means that player 4 is guilty. This player 4 may be mafia 1; player numbers are just given for discussion purposes and to identify a player based on his claims and is independent on role. Doctor is the same except integers because you only need to store who was saved that night. The public, claimed Identity works in much the same way except that the controller will never modify it, only the player can. An identity object contains a role (an integer representing the role number), an ArrayList of strings called 'visits' (to be used if you are a cop or doctor, to store a list of people visited and any outcomes), and an ArrayList of suspicions to indicate that your bot suspects or is guessing that another player has a given role. It will also have a lynch value which can be changed during the day, and this is where a player decides on who to lynch (if at all). Finally, it will have a boolean for if the player is dead or alive. You had better not mess with this. The idea of having two is that you can claim whatever you want; so a Mafia can claim to be Cop or a townsperson and the doctor can claim to be a cop. Initially your public claim ID is 0, indicating that you have not claimed. The program will give you your private ID, which will contain your actual role and and is not necessarily meant to be made public just yet. The program controller will only modify your private ID object, and only then if your are Doctor or Cop. It will append to the visits ArrayList in the private identity object the result of the visit; the doctor will have access to everyone he has visited, and the cop will have access to everyone he has inspected and their alignment. The controller, each night, will ask Mafia 1 for his choice then Mafia 2 for his choice, then repeat, say, 25 times. If at any point the two mafia agree, then it stops because the Mafia have just made their choice. The number of times attempted thus far will be given to the Mafia's night method, so the code will look like M1.night(<other players info>, 1) then M1.night(<other players info>, 2), etc. is that arraylist of public identities previously mentioned. If no consensus, no kill. Similarly prompt cop and doctor once for their choice on who to visit. In the day time, every player's lynch value will be 0, indicating that they do not vote yet; each player will be given 25 chances to act. An action can consist of adding to the list of suspected values, claiming a role, changing a role, changing the list of suspected values, voting to lynch someone, changing a lynch vote, etc., or more. Some actions are smarter than others, and your goal is to have a good action strategy. Upon each call of a players act() method, he will be given an arraylist of everyone else's public identity objects, as well as how many times before he has been prompted. This gives him access to what other players claim to be, who other players claim to have visited and outcomes, who they suspect as who, and who others are voting to lynch. If at any point there is a majority (more than half but not exactly half) of people wanting to lynch a person (No lynch, indicated by the value -1, counts too), then day time ends, that person is lynched and his role revealed. If majority voted -1 (no lynch) then nobody dies and day time ends. Again, please guide me on how I should design my classes, controller, and what files I should put up and how people are going to test their bot at home. I would be glad to show you what I have so far, which includes a controller program and a dummy player class. • Note that we already have a Mafia KOTH here in the sandbox. – Alex A. Dec 5 '15 at 1:45 • @AlexA. Note also that he allowed me to take over. – Faraz Masroor Dec 5 '15 at 2:17 • Some important notes: The messages from the past post were a really good idea. Use them. Also, I think that its a good idea to have people submit a bot that plays a single role. Then, from round to round, simply switch in/out the bots for that role. – Nathan Merrill Dec 7 '15 at 4:40 • I am not very clear on how to run a KOTH challenge and what github is supposed to do and how to use it so it would be very helpful if someone could point me in the right direction I like this KoTH, and I've got quite a few of them under my belt. If you pop into chat I'd be happy to chat about it with you (and help with the code, if you'd like) – Nathan Merrill Dec 7 '15 at 4:49 • @FarazMasroor are you still planning on doing this? – Nathan Merrill Dec 27 '15 at 13:12 # Generate a graphical representation of a Stern–Brocot tree of depth n I am aware of this challenge. Would this be considered as a dupe? # Gilbert-Shannon-Reeds Shuffle ### Background The Gilbert-Shannon-Reeds (GSR) shuffle is a simple model of riffle shuffling close to how real humans shuffle a deck of cards. The well-known rule of thumb to riffle-shuffle a deck of 52 cards seven times for sufficient randomness is based on the GSR shuffle. ### Algorithm • Cut the deck at a position k, 0≤k≤n. If there are n cards, the probability that any given k is chosen is (n nCr k)/(2^n). • Put the first k cards into one pile, and the other n-k in a second pile. • Until all the cards are gone: • Where the sizes of the two piles are x and y, choose the first pile with probability x/(x+y) and the second pile with probability y/(x+y). • Move the first card in that pile to the new array. ### Challenge Input: An array of positive integers, of length n<1000. Output: The array shuffled once. ### Rules You may use any algorithm that gives equivalent results to the GSR shuffle. • Just to clarify: We have to shuffle once, yes? – Dennis Dec 4 '15 at 19:45 • Closely related. This is one of the rare cases where I would actually favour closing an older question as a duplicate of a newer one. – Peter Taylor Dec 4 '15 at 20:27 # Play Chess with a One-Move Lookahead "I see only one move ahead, but it is always the correct one." – Jose R. Capablanca, World Chess Champion 1921-1927 This is a chess tournament with a twist: your chess engine is only allowed to look 1 move (2 ply) ahead. In order to succeed, you must create the best board evaluation algorithm. ## Additional Rules • En passant, castling, and under-promotion will be allowed. Of course, it is up to you if you want to bother adding those capabilities to your AI. I personally find these to be some of the best rules of chess. I am considering making a "template" bot which implements alpha-beta pruning, and requiring users to just fill in the method for board evaluation. Otherwise, there may be ways to stretch what it means to "look ahead." The benefit for users would be that they don't have to write their own getLegalMoves() method. • How is the algorithm scored? – Doorknob Dec 7 '15 at 2:24 • I don't think there's any way to specify "look ahead" which isn't vulnerable to stretching. Even if you just ask for the board evaluation. – Peter Taylor Dec 7 '15 at 9:44 • Why would you need pruning for a bot that only looks 1 move ahead?? – feersum Dec 7 '15 at 11:50 # Rearrangement Inequality: The Sequel code-challengegrid Read the previous version here. Your mathematics teacher looked at your test results on inequalities. Not good. Hence he decided to give you some homework on inequalities. Since this is about inequalities (how unfair), he decided to give each student a differing amount of homework. The exact amounts do not matter to him. After allocating the homework, he had a bunch of complaints. Apparently, some students have some neighbouring students who have less homework than them. Hence, he has decided to rearrange the students such that there will be fewer complaints. As long as each student sees that at most one adjacent student has less homework than them, they will not complain. (The students are quite reasonable.) Note that he can swap the position of two students, but he cannot move a student into an empty spot as the empty spot has no chairs and the chairs in this classroom cannot be moved around due to safety concerns. ## Input Here are different forms of input you can consider: Optional: You can include integers in your input for the size of the classroom for convenience. This is , so input and output does not matter too much. Function input: Container with truthy and falsy values representing if a student is there or not. All truthy values must be the same, similarly, all falsy values must be the same. Standard Input: A grid of 2 different characters, which can be separated by spaces. Possible input: 0 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1  or _@@_@ @@@@@ @_@@@ @@@@@  ## Output The teacher wants to know how to arrange the students. Each student can be represented as an integer from 1 to n from the least amount of homework to the most amount of homework. For the input: 0 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1  where 1 means there is a student and 0 means there isn't any students, a possible output is: 0 12 13 0 4 10 11 16 15 3 9 0 14 17 2 8 7 6 5 1  where the students labelled 16 and 17 are not satisfied. Your score for every test case will be the number of students which are satisfied over the total number of students in that test case. It is guaranteed that there is at least one student in each test case. Your final score will the average of your scores over all test cases. If you want to use another form of input and output, please clearly state it in your answers. ## The teacher has some concerns: Please ensure that your code is deterministic, as the teacher may test it several times. You are allowed to code your own psuedorandom number generator if you need random numbers. Please ensure that your code terminates within a minute for each test case, as the teacher is impatient. The teacher has been to PPCG for a long time, so he knows all the standard loopholes. The teacher has a very large classroom (100 by 100), and would be worried if your program fails to give an answer for such a large classroom. ## Finally: This is , and the winner will be the person with the largest score. # Sandbox Meta: I still need to generate some large test cases, so I'm leaving this in the Sandbox until I have large test cases. How should I show people large test cases? • Is it acceptable to use a built in pseudorandom number generator provided it is always run with the same seed? – trichoplax Dec 29 '15 at 15:37 • @trichoplax I may need to be able to test the code multiple times, so that may require all compilers/interpreters to implement the same pseudorandom number generator, which I am not sure if that is the case. – Element118 Dec 29 '15 at 15:41 • Ah, I see. That is definitely guaranteed for some languages, and definitely not for others... Banning all built in RNGs does at least seem fair to all languages. – trichoplax Dec 29 '15 at 15:58 # Approximate an image using all colours I know that this is basically a subset of the then very popular American Gothic in the palette of Mona Lisa: Rearrange the pixels but I think it is worth making it a new challenge. As @MartinBüttner pointed out, there has also been the Images with all colors challenge, but in my opinion it has very little in common with the proposed challenge. # Challenge Given a image of 2^12 x 2^12 pixels as input, your program should recreate this image, but you have to use each of 8-bit RGB colour exactly once. # Meta These are roughyl 12MP images, quite large. So one could just restrict it to 7-bit RGB then the pictures would only have to be 2^18 pixels, that means e.g. 512 x 512 pixels which would be way more suitable for the challenges here. Or does anyone know a convenient other colour representation? • There's also this. I'm really not sure you'll get any better approaches than those used for CH's palette challenge. – Martin Ender Dec 22 '15 at 19:11 • I was wondering that too on the other hand you have the advantage of exactly knowing the pallete and at the same time the disadvantage of having to use all the colours, even those that do not follow a "natural distribution" (a palette that is similar to "natural" images.) – flawr Dec 22 '15 at 19:15 • I lean towards thinking this is too much of a duplicate of "in the palette of", but if it turns out to be accepted I'd recommend changing the title to "Approximate an image using all colours" to make it clear it's not "Images with all colors" again. – trichoplax Dec 29 '15 at 15:52 • As noted in my answer to "in the palette of", it was directly adapted from a program which does this, so as far as I'm concerned it's a dupe. – Peter Taylor Dec 30 '15 at 10:54 ## Make a New Year countdown Editor's note: This challenge is cancelled because it is the year 2016, and I'm too late. XP It is kept here for posterity. It is New Year coming soon. As such, it would be a great idea to make a New Year countdown. That is your challenge today! Happy New Year! ### The full rules • Create a program taking from STDIN the current time and outputting a countdown until New Year into STDOUT. • The program should be flexible - after Year 2015 has concluded, the program should count down until New Year 2017, and so on. See examples for more information. • The program should count down until it is taken down by external means (using Ctrl-C, the Task Manager, the reset button, et cetera). • The countdown may be formatted however you like. • At the null second in the new year (YYYY-01-01 00:00:00), it should output 0 days, 0 hours, 0 minutes 0 seconds in your chosen format. • This is , so shortest answer wins. • The last rule: Have fun! ### Examples Given the input after from: the following countdown should be given, in any format you like (after to:). from: 2015-12-31 06:00:00 to: 0 days 18:00:00 from: 2015-12-31 23:59:57 to: 0 days 00:00:03 from: 2016-01-01 00:00:00 to: 0 days 00:00:00 from: 2016-01-01 00:00:01 to: 364 days 23:59:59  • Three things: 1. IMO this is close enough to this question that it's a borderline dupe. 2. 2016 is a leap year, so from 2016-01-01 00:00:01 to 2017-01-01 00:00:00 is 365 days 23:59:59 (assuming no leap seconds are added, but that can't be predicted in advance). 3. Because of points such as the previous one, for testing date questions it's usually better to take the current time on stdin rather than read it from the clock. – Peter Taylor Dec 31 '15 at 10:59 • For 3; changed the rules to get the time from STDIN – user48538 Dec 31 '15 at 16:40 ## Sig-fig calculator As a scientist, sig-figs are definitely one of the most important parts of measurements and calculatations (unless you are a theoretical scientist, where everything must be exact!). Sig-figs is an important way of measuring uncertainty and accuracy of a value. To calculate the number of sig-figs for a value, use the following to help you (from here): 1. ALL non-zero numbers (1,2,3,4,5,6,7,8,9) are ALWAYS significant. 2. ALL zeroes between non-zero numbers are ALWAYS significant. 3. ALL zeroes which are SIMULTANEOUSLY to the right of the decimal point AND at the end of the number are ALWAYS significant. 4. ALL zeroes which are to the left of a written decimal point and are in a number >= 10 are ALWAYS significant. 5. Exact numbers in an equation have infinite sig-figs. For example, in the equationA=pi*r^2$,$pi\$ has infinite sig-figs and the exponent of 2 also has infinite sig-figs. (not included in the above link)

To calculate the number of sig-figs from a calculation, use the following rules:

1. For multiplication and division, the number of sig-figs for the result is equal to the number of sig-figs for the least accurate value (i.e. the value with the least number of sig-figs). For example, 2.000*5.00 = 10.0 and 4.5*6.00 = 27

2. For addition and subtraction, the result has as many decimal places as the one with the least decimal places. For example, 5.00-2 = 3 while 6.0-3.000 = 3.0

3. logs (including natural logs) have as many decimal places as the number of sig-figs of the value of whose log is being taken (I am not sure if this sentence of English is correct!). For example, log(2.45) = 0.389.

4. Other functions, such as square roots, exponents, sines, cosines, etc. can be assumed to have the same number of sig-figs as its argument. So the sin(3.14) = 0.00159

Challenge

The challenge is to write a sig-fig calculator with the following functions:

2. sine, cosine, tan, and their inverses
3. sinh, cosh, tanh, and their inverses
4. Exponents, including shortcuts for e^x and 10^x, along with sqrt. The exponents are assumed to be exact and has infinite sig-figs
5. log of base 10 and natural log.

The result of each calculation should give you the correct result, but insert a "\" before the last sig fig. If there is infinite sig figs, there should be no "\" at all. Also, undefined and infinite values should give an error or NaN or print "infinity" or "undefined". For example,

sin(3.14) = 0.0015\9265292
log(1.01) = 0.00\432137378
5.00*2 =\10
2.00^5=32.\0


This is a so the shortest code wins!

• The positioning of the backslash in the output spec is rather confusing, but I think that one of the examples disagree with the spec. 5.00 * 2 is 10 with one sig fig according to the rule for multiplication that you take the number of sig figs of the least accurate value. Of course, this runs into the problem that your (unconventional, I believe) rule 4 does not provide any way to represent the number 10 with only 1sf, but even so I think the correct output should be \10. – Peter Taylor Nov 24 '15 at 22:06
• @PeterTaylor thanks! It is now fixed – TanMath Nov 24 '15 at 22:59

# Clean numbers

We call a positive integer a clean number if it is expressible by using only a positive digit once or more and no other sign. For example 88 is expressible with 2's as 2222.

A more complex example is

$$141289730531295606313143345858933 = 3^{33}3^{3^3}3333$$

## Details

The possible operations are

• exponentiation
• multiplication (only if the first part contains exponentiation as otherwise it is just digit concatenation)
• digit concatenation

Precedence is as normal. Power towers are computed from right to left (top to bottom).

sandbox note: which one should it be? I'm thinking d) now

• a) given a number return if it is clean
• b) given a number return the digit with which it is clean
• c) given a number and a digit return if the number is clean with that digit
• d) given a number and a digit return digit-clean numbers up to the given number
• e) given a number find the smallest digit or digit-sequence which makes it clean (eg. 63504 = 2522)

## Test cases

TODO
(11^1)*11
2^(2^2*22)


Your program should solve every test case in a couple of minutes.

This is code golf.

• Unfortunately, this site doesn't have latex support. It should though. – SuperJedi224 Jan 2 '16 at 14:55
• @SuperJedi224 I know and I will add image for the final version. I'm just lazy to do it already. – randomra Jan 2 '16 at 15:00
• Unfortunately, Meta does have LaTeX support. You just have to double up on the dollar signs. – Dennis Jan 2 '16 at 16:06
• Not anymore... i guess – user46167 Jan 3 '16 at 17:47
• If combinations are allowed, then 2016=C(2^C(2^2,2),2) ;) – user46167 Jan 3 '16 at 17:49
• @BlockCoder1392 seeing that in the chat gave the idea for the challenge – randomra Jan 3 '16 at 18:05
• Yes, I know. I was just suggesting combinations (which probably wouldn't be accepted anyways) – user46167 Jan 3 '16 at 18:21

I wasn't able to find a challenge like this before, but it wouldn't surprise me if it already exists.

A strand of DNA is made up of bases notated by the letters A, T, C, and G. A always pairs with T, C always pairs with G, and vice versa.

Therefore, you can find the opposite side of a DNA strand by swapping all occurrences of a base with its complement.

Here's the catch: your program cannot contain the characters A, T, C, or G at all – in string literals or in the body of the program.

The input is a string of continuous uppercase characters (you can assume that this string only contains the above bases). The input can be any length. The output should be the complementary strand of DNA.

Examples

Input:   AC
Output:  TG

Input:   ACCTAGTAT
Output:  TGGATCATA

Input:   GCATC
Output:  CGTAG

Input:   TCTGAAACTAGGGGC
Output:  AGACTTTGATCCCCG


This is code golf, so the shortest program wins.

• I think this is the closest existing question. Note that it's a more complicated question, and the winner is still only 24 bytes. I have a 16 char solution to this question in CJam. – Peter Taylor Jan 5 '16 at 23:18
• It seems like this is basic character table translation in languages that support that, in pyth and cjam these answers seem near optimal, they're also kind of boring, idk if people will think it's too boring... – FryAmTheEggman Jan 6 '16 at 15:28
• @FryAmTheEggman that's why I added the requirement the character restriction. I don't think it will be as easy to do a character replacement without using the actual characters. – erdekhayser Jan 6 '16 at 18:20
• @erdekhayser in many languages you can just use base encoding of some kind to avoid that. – FryAmTheEggman Jan 6 '16 at 18:35
• @FryAmTheEggman simple thing would be to prohibit the use of base encoding... – TanMath Jan 6 '16 at 19:05
• @FryAmTheEggman I have a 17 byte Pyth answer using only simple ASCII characters. It is possible to solve this challenge without base encoding – TanMath Jan 6 '16 at 19:06
• @TanMath without base encoding I think most languages would just add to character codes... – FryAmTheEggman Jan 6 '16 at 19:17
• @FryAmTheEggman I think that is the only route to go, which is what I used. Any problem with that? – TanMath Jan 6 '16 at 19:20
• @TanMath not necessarily, but a challenge where the only challenge is working around an obvious solution by restricting workarounds isn't one I would personally find interesting. – FryAmTheEggman Jan 6 '16 at 21:43
• @TanMath or just specify ranges around the desired characters in the translate command. Like this 15 char Retina solution TB-H@-UH-BU-@ – Rainer P. Jan 6 '16 at 22:18
• 20 bytes in Seriously using only arithmetic on character codes (no base encoding or translate): ,O6╙(-7P/≈u6╙+cMεj – quintopia Jan 7 '16 at 16:55
• Should I add a restriction on base encoding, or should I not post this challenge? – erdekhayser Jan 7 '16 at 19:48

# Format a list of words

Your challenge is to format a list of words across multiple lines that are no longer than a given number of characters, so that each line contains as many words as possible and no words are unnecessarily cut off.

## Input

The input will be a space-separated list of words and then a number that is at least 4.

## Output

The output should be the input words grouped into lines so that none of the lines contains more characters than the input number. The lines should be output in the order they were input. The words should be comma-separated, and each line except the last should end with a comma. If a word is too long to fit on a line, it should be cut off as little as possible while following the other rules, and "..." should be added to the end.

## Test cases

Input:
foo bar baz qux 12

Output:
foo, bar,
baz, qux

Input:
foo bar baz qux 5

Output:
foo,
bar,
baz,
qux

Input:
strength dexterity constitution intelligence wisdom charisma 10

Output:
strength,
dexterity,
consti...,
intell...,
wisdom,
charisma

Input:
quas wex exort 4
...,
wex,
e...


## Sandbox questions

• Has this been done before?

# "Compress" text into Zalgo

Zalgo, the Nezperdian hivemind of chaos, is a type of text that uses combining characters to make very tall and noisy text. If you don't know what I'm talking about, maybe this will jog your memory:

<zalgo>

H̡̢̢̡̡̧̢̡͎̟͚̮͓͇̦̮̙̗̜̱̱͔̲̹̣̱̠̀̀͐̑̾̓̃́̃̍̀͆̇͆̽̔̒̚̕͘̚͜͝͠͠ͅE̢̧͓̺͉̟͙͇̳̰͉͖̺̻͕̰̱̝̳̙̰̟̠̯̘̰̲̎̑͋͂͑́͛̎͋̇̍̾̊̈́̂̽̿͆͛͑̽̒̊́͠͝͠͝͝ͅ ̨̢̟̳̥̖̺̼͎̩̘̰̣̼͇̰̫̞̜̲̰͔̗̠͔̩̻̳͇̾͌̆̑̍̄̊͗̓̃̆̊̄̽̐̂͛̏͑̒̓̆͝͝͝Ç̛̬̩͙̱̥̦̪̮̖͚͚͔̼̱̺̳̳̬̭͍̣͍̙̹̜̫̟̳͌̓͗͊̐̈̄́̏̀͂̎̃̈́̈́̎͋̀̒̊̀̈́͒̽͘̕͝Ȏ̡̡̨̡̝̬̠͚̠̯͖̹̟͓̮̻̲͙̖̪̯͇̍̅̂̌̌̒͗̈́̉͆̇̑͒̉̂̾̃̌̽͛͘͝͝ͅM̡̢̢̘͉̤͍̫̺̻͕̱̤̤̞̟̞̹͉͓̥̳͖̹̤̆̋̓͂̂͑̃̌͛͂̋̂̓̏́̀̾̋̈́̅̐̅̎̇̐̽͜͝Ȩ̨̛̭̥̹̳̫͎͖͈̳̠͍͙͉̻̼͍̞̜̺̝̻̝̗̳̏̈̓͋̐́̋͆͋̓̿͐͆̾̾̃͌͌̾̊́̚͘͘͜S̡̢̡̡̛̯̪̬̹̲̙̮̲̲̤͖͖̞̲̞̼̪͓͇̤̼͇͆͋̊̈̑̆̿̐̎͑̾̅̀̒̓̎̐̍̽̈́̋̽̓̔̍͜͝

</zalgo>


As a new twist on the age-old Zalgo generation problem, your goal is to take a string and "compress" it into a single Zalgo character. You will write two programs, one which takes in a string of printable ASCII and outputs a single Zalgo character, and a second which takes in a single Zalgo character and outputs the original ASCII string.

• I think the most golfable solution will be to encode the input in unary and use a single combining mark. Is that what you're looking for? – Martin Ender Jan 9 '16 at 22:11
• Maybe require the zalgo output to be shorter in some sense? – xnor Jan 9 '16 at 22:38

# Sorting trains

This problem is based off of a solitaire card game called Calculation. You can play it here (highly recommended).

You are in charge of designing a train yard. At your junction, you have an In/Out track (queues) and Storage (stack). Train cars come in a random order; your job is to arrange them into 4 different ordered trains. Land is expensive, so we need you to minimize the amount of storage tracks we need.

Your rail car mover can only handle 1 train at a time, and move a car:

1. In track -> Out track
2. In track -> Storage track
3. Storage track -> Out track.

Each Out Track needs the same 25 cars, each in a different order:

Track 1: 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,0
Track 2: 2,4,6,8,10,12,14,16,18,20,22,24,1,3,5,7,9,11,13,15,17,19,21,23,0
Track 3: 3,6,9,12,15,18,21,24,2,5,8,11,14,17,20,23,1,4,7,10,13,16,19,22,0
Track 4: 4,8,12,16,20,24,3,7,11,15,19,23,2,6,10,14,18,22,1,5,9,13,17,21,0


We can use (nx+n) mod 25 to calculate ID of the xth car of the nth track.

### Important notes:

• Storage tracks can store as many cars as you want, but you can only remove the most recently placed car
• Cars cannot be moved from one storage track to another
• Your algorithm must be deterministic (it must do the same thing given the same input queue and the same number of storage stacks)
• You may get into an impossible situation, where you end up not being able to order the trains. If that happens, try again with additional storage tracks.

### Input:

Your input is a list of integers, where each integer is the ID of the train car.

### Output:

You need to return a list of moves that sorts the cars into the Out tracks. A move looks like I->S1 or S1->O2, where I is the input track, S# is a storage track, and O# is an output track.

### Scoring:

Your score is the total number of tracks you need for of all test cases (you can use a different number of tracks for each test case). Lowest score wins.

### Test cases:

4,13,20,23,22,21,0,18,8,17,16,6,18,22,15,19,21,8,6,24,7,21,9,4,24,19,0,20,12,1,3,10,5,6,19,23,17,9,14,24,13,5,10,15,2,14,7,8,6,10,3,18,22,16,2,4,10,14,1,21,11,9,22,18,20,16,1,4,12,0,12,11,20,11,19,12,0,13,9,11,23,24,15,3,14,5,2,5,8,7,7,3,16,13,15,23,17,1,2,17
1,8,7,5,6,7,21,9,15,5,7,6,21,13,13,18,16,12,22,10,18,14,13,14,10,0,8,24,13,23,2,9,3,4,19,11,24,16,15,10,8,22,3,2,16,17,1,2,12,18,19,2,19,22,0,23,12,24,11,23,23,3,21,15,0,16,14,5,17,10,20,20,0,15,6,7,20,11,17,22,6,17,5,9,1,8,14,21,4,4,3,11,12,4,20,19,1,18,9,24
21,2,14,11,12,21,15,21,16,23,2,19,8,14,23,0,16,4,7,9,24,10,0,11,17,5,4,8,10,0,20,6,5,18,18,6,9,10,22,10,9,1,16,22,1,22,6,17,19,7,2,1,7,18,3,18,11,2,11,7,23,17,6,3,19,13,21,4,20,14,24,20,15,15,15,13,13,12,22,5,13,20,24,3,24,23,4,0,9,8,5,17,16,8,14,12,3,19,1,12
2,7,10,22,15,3,16,7,3,6,4,17,2,20,6,21,13,5,1,7,16,18,24,17,8,14,5,23,17,18,13,0,9,14,24,21,19,23,0,20,15,1,12,24,3,18,11,5,15,7,4,4,9,8,17,12,0,23,6,8,14,12,1,22,9,11,14,20,19,3,12,23,11,19,16,11,22,16,9,4,13,19,1,22,15,2,8,10,0,13,10,18,24,10,21,6,5,2,21,20
14,20,18,21,19,10,7,16,2,22,14,15,17,24,8,10,13,0,11,5,11,11,7,13,19,9,22,10,7,0,3,16,2,8,21,8,4,14,2,19,24,16,12,1,0,0,17,15,1,21,6,5,4,6,12,23,3,15,21,2,12,23,14,23,5,1,10,1,17,13,7,22,4,5,18,6,18,12,16,11,9,13,6,19,23,15,17,22,4,20,8,3,18,20,24,20,9,24,3,9
0,23,4,4,14,17,14,0,8,21,8,9,8,5,16,20,15,9,24,23,12,11,24,2,14,17,3,21,1,19,5,17,15,16,7,2,22,20,6,1,24,16,7,22,21,19,6,13,23,11,4,11,15,19,20,19,18,5,1,18,10,22,16,6,18,20,10,9,6,2,12,23,7,12,3,9,10,7,5,10,13,3,17,12,13,2,1,0,15,4,22,18,11,14,3,24,21,8,0,13
8,19,19,0,23,7,10,21,2,22,13,20,2,10,16,21,3,17,20,18,5,9,14,19,22,0,7,6,3,10,18,6,6,5,24,2,11,24,7,1,11,17,8,9,24,5,15,18,16,24,11,5,14,1,0,13,16,0,13,17,8,12,4,1,21,20,11,10,14,16,8,21,4,7,17,9,13,4,1,3,15,6,22,23,9,23,15,12,15,19,3,20,2,23,12,12,4,18,22,14
17,3,8,24,18,5,7,2,13,2,9,19,21,6,8,8,21,16,17,3,11,20,24,24,12,11,18,11,16,15,24,9,14,10,18,4,22,20,0,10,7,14,6,1,15,6,13,7,3,12,7,23,4,21,0,23,2,10,12,22,9,17,0,4,4,3,22,16,23,20,15,18,10,8,23,1,14,11,5,19,16,1,2,22,9,12,1,5,13,19,14,20,19,5,13,0,15,6,21,17


# Risk dice battle

Risk is a board game in which you attempt to conquer the world by attacking your opponents' countries. As the game progresses the number of armies involved in attack gets higher and higher, which can lead to a lot of dice rolling. I want you to make this easier for me. It's possible that my favourite answer will actually get used when playing Risk.

Rules of Risk battles

Each country in Risk must have at least one army on it. Therefore a battle can only take place if the attacker has more than one army (in case he loses.) The defender obviously has at least one army.

The attacker rolls 3 dice (only 2 if he has only 2 armies) while the defender rolls 2 dice (only 1 if he has only 1 army.) Once the dice are rolled, the highest dice of each player are compared, then the next highest. (If one player rolled more dice than the other, his lowest dice are discarded.)

For each dice comparison, the player with the lower score loses an army. If the dice are the same, the defender wins and the attacker loses an army. Note that this does not necessarily put the attacker at the disadvantage, as he frequently has more dice to roll than the defender.

Example:

               Attacker 6 3 2
Defender 5 4
^ ^
| |
Defender loses 1 army -+ +-Attacker loses 1 army


For interest the probabilities are as follows:

                        Defender rolls 2 dice       Defender rolls 1 die
---------------------------------------------------
Attacker rolls 3 dice   Attacker loses 2 29.26%     Attacker loses 1 34.03%
Both lose 1      33.58%     Defender loses 1 65.97%
Defender loses 2 37.17%

Attacker rolls 2 dice   Attacker loses 2 44.83%     Attacker loses 1 42.13%
Both lose 1      32.41%     Defender loses 1 57.87%
Defender loses 2 22.76%


A full program is required which will accept from stdin or commandline, a number of attacking armies and a number of defending armies. There will be at least 1 army of each. Your code will display the number of armies as follows

1.If there is only 1 attacking army, your program shall immediately terminate with the message Insufficient force.

2.The code shall now accept a user input from stdin. If the user now enters anything other than an empty string, the code shall terminate. If the user enters an empty string, you must simulate the roll of the appropriate number of dice, sort each player's dice in descending order, and report the result and the updated number of armies per example below. 2 trailing newlines are required after the output.

Attacker dice: 5 3 1
Defender dice: 5 4

Attacker: p armies (where p is the number of attacking armies)
Defender: q armies (where q is the number of defending armies)
(2 trailing newlines)


3.If either player now has 0 armies, display the message Defender defeated! or Attacker defeated! as appropriate and terminate the program. Similarly, if the attacker now has only 1 army, terminate with the message Insufficient force.

The program shall now loop back to step 2 and continue until either one player's armies are depleted or the user enters a non-empty string.

Rules

The distribution of the dice throws shall be exactly as with real dice (up to the limits of uniformity both the dice and the random number generator used.) It is expected that most submissions will generate the numbers for each die and then sort them. Clever submissions that generate the output in other ways avoiding the sorting step are acceptable, but the theoretical probability distribution of the output must be identical to the real dice throws. (For example it is permissible to precalculate and presort all 216 possible throws of 3 dice and select one of these at random.)

Due to the real time nature of the application a full program is required, with input from stdin (enabling the user to run quick fire battles by reviewing the output and pressing the return key.)

Formatting of output strings and newlines shall be exactly as described above. Up to 2 additional symbols (but not alphanumerics) are acceptable between and around numbers. For example [3,2,1] is an acceptable way of displaying the roll of 3 dice.

Scoring

This is code golf. Shortest code in bytes wins.

• I don't see the point of requiring termination on a nonempty string. – lirtosiast Jan 18 '16 at 3:18
• @ThomasKwa An attacker doesn't always want to fight to the death, especially if he has a run of bad luck with the dice. The user experience is designed to make attacking as easy as possible but there has to be a way to terminate. The alternative would be ctrl z or ctrl c which is ugly. If you mean you don't see the point of termination on the first iteration, well that is partly to enable implementation with a while loop but mainly to enable the attacker to change his mind right up to the last minute. – Level River St Jan 18 '16 at 8:21
• Oh, okay. I wasn't used to seeing practical concerns on code golf questions. – lirtosiast Jan 18 '16 at 17:51
• Your description of the number of dice rolled by the attacker doesn't seem to match the official rules. You say "The attacker rolls 3 dice (only 2 if he has only 2 armies)", but the rules say "You, the attacker, will roll 1,2 or 3 red dice: You must have at least one more army in your territory than the number of dice you roll". (There's also the subtle issue of choosing to roll fewer dice than the maximum because you want to keep more than one army behind). – Peter Taylor Jan 23 '16 at 19:16

## Help find Mersenne primes! code-golfrestricted-sourcemathsequence

There has recently been a discovery of a new prime number: 2^74207281-1. This is the biggest prime number to date and broke the previous 3-year record holder by over 4 million digits!

Your job will be to help mathematicians find some prime numbers (not really). You must take in an integer N and output the Nth Mersenne prime (OEIS A000668). You may assume that the Nth Mersenne prime is under your languages maximum integer number and/or will not cause an overflow (but your code should work for higher numbers if your language allowed it. You may not use any built ins for primality testing and cannot hard-code any values.

You can find a list of most of these numbers over here.

### Test Cases

2 -> 7
5 -> 8191
8 -> 2147483647


This is , shotest code in bytes wins.

• Please don't call it GIMPS XD. – Conor O'Brien Jan 21 '16 at 4:51
• 1. Yes, that's the wrong sequence. It's actually A000668. 2. The current wording of the overflow assumption seems to allow hard-coding 4 values if your language operates purely on bytes. I also see no restriction on built-in primality testing. – Peter Taylor Jan 21 '16 at 9:15
• I've been thinking about "code-golf or fastest-code". As code-golf it's a loop with multiplication by two and a primality test, and primality testing has been done to death. As fastest-code, it would pretty much be a case of simplifying the GIMPS client to something which could be posted. I suggest that you make it a compromise: code-golf, but with a speed constraint which rules out naïve primality testing. Maybe write a Lucas-Lehmer test in a slow language, take the highest value it can do in 6 seconds, and require answers to reach that value in 1 minute. – Peter Taylor Jan 21 '16 at 21:15
• Somehow failed to find it when I searched before, but this question is related. – Peter Taylor Jan 24 '16 at 23:08

# Parse an "Efficient" Encoding

Let us define a fictitious encoding "ENCWID", that follows this general form: there are three bits that denote the length of the following character, for each character. This looks something like this:

WWWN..N
^^^^--- the actual character
^^^------- width bits; from 000 to 111


Perhaps this is a little vague. To understand this better, let us encode the string "Hello!" into ENCWID. Observe:

H   72   1001000
e   101  1100101
l   108  1101100
o   111  1101111
!   33   100001


This diagrams the binary ASCII codes of each character in the string. Let us put these values into an array that represents "Hello!": [1001000,1100101,1100101,1100101,1101111,100001]. The widths for each of these strings are 7, 7, 7, 7, 7, and 6 respectively. To binary, this makes 7 111 and 6 110. Now, we put the binary length of each binary ASCII code before the actual ASCII code, and combine them all into a single string, as such:

111-1001000 111-1100101 111-1101100 111-1101100 111-1101111 110-100001
(7)-(  H  ) (7)-(  e  ) (7)-(  l  ) (7)-(  l  ) (7)-(  ᴏ  ) (6)-(  !  )


(Spaces, hyphens, and parentheses added for visual clarity.)

And thus, the encoding of "Hello!" is 11110010001111100101111110110011111011001111101111110100001.

Decoding the string form is perhaps rather easy, using the following steps:

1. Read three characters; call this N.
2. Set N to the decimal number represented by N, from binary.
3. Read the next N charcters; call this S.
4. Parse S as a binary number, and append this character to the result.
5. If there are still unread characters, go to step 1. Otherwise, continue.
6. Return the result.

Objective Your objective is to write two programs; one that encodes and one the decodes the described encoding. Your score is the sum of the program's byte count.

## Implications

Suppose that we can actually implement this in mainstream use; then, an encoding can be used that utilizes the lower-width codepoints for the most common letters in a given language. This would allow for a lesser amount of bits to convey the same message.

Say we did this for English, and that this

earniol1t.9h0s,dC()u2Scmy8gBJDW7HvM6RbkA435wfLPGpTKEFNYO
zI'Vq/Ux-[]jZ"  ;:QX&!


is the approximate frequency at which english letters occur, this could be our (partial) encoding:

   0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
0     e  a  r  n  i  o  l  1  t  .  9  h  0  s  ,
1  d  C  (  )  u  2  S  c  m  y  8  g  B  J  D  W
2  7  H  v  M  6  R  b  k  A  4  3  5  w  f  L  P
3  G  p  T  K  E  F  N  Y  O  \n z  I  '  V  q  /
4  U  x  -  [  ]  j  Z  "  \t ;  :  Q  X  &  !  \


Thus, "Hello!" would be encoded as:

H   12   18   10010     (5 => 101)
e   01   01   1         (1 => 001)
l   07   07   111       (3 => 011)
o   06   06   110       (3 => 011)
!   4E   78   1001110   (7 => 111)

101-10010 001-1  011-111 011-111 011-110 111-1001110
(5)-( H ) (1)(e) (3)-(l) (3)-(l) (3)-(o) (7)-(  !  )

=> 1011001000110111110111110111101111001110
(²7ß{Î, under ISO-8859-7 encoding)


And, "Hello!" fits into a clean 5 bytes under this encoding, as opposed to 6-byte standard encoding. This would equate to a lot more bytes saved for a higher sample size.

# Meta

Suggestions?

• 1. The introduction talks in terms of bits, but the description of decoding talks in terms of characters. Which is it? 2. If it's bits, how is padding to an exact multiple of 8 bits handled? (Or to an exact multiple of some other word size, if the storage/transmission model isn't based on octets). 3. With respect to the implications, see Huffman encoding and arithmetic encoding, which do the same thing better. – Peter Taylor Jan 23 '16 at 18:56
• @PeterTaylor 1. Bits, I will revise. 2. I don't know much about this stuff; this really isn't an implementation as it is an interpretation. 3. I didn't claim that this was the best way. >_<. I know of both mentioned. – Conor O'Brien Jan 23 '16 at 19:02

# Language Guessing

(Inspired by What's the Language?)

According to the first Google result, the most popular programming languages are:

1. Java
2. C++
3. C#
4. Python
5. PHP

(For our purposes, C and C++ will both be treated as C++, though the test cases may include C source code and header files)

Write a function that accepts a String, determines what programming language the String is, and returns its result.

## Rules

• The input String will be in one of the five languages listed above.
• Your method should return a String with the name of the programming language exactly as written above.
• Your code must be under 150 bytes.
• No compiling, running, or otherwise evaluating the test cases to determine their language.
• No standard loopholes.

## Scoring

• The code with the highest match percentage wins
• For every 15 bytes under the 150 byte limit, you get an extra percentage point (a 61-75 byte program would get 5% extra on top of the match percentage.
• The method or function header does not count toward the total byte count. Return statements do count, however.
• The code used to load the test cases and feed them into your method does not count either.
• You get one import for "free". Any other imports count toward the byte limit.

## Test Cases and Testing Code

Here is sample java code used for testing submissions. If you write in a language besides java, your tester must only accept one parameter, and cannot access any variables that are stored between iterations of the function. The entire code, including the tester, must be included in your answer.

import java.util.*;
import java.io.*;

public class Tester{

static int right = 0;//How many are right
static int total = 0;//How many tested in all

public static void main(String[] args){

//Opens up test cases
File rootFolder = new File("./Test Cases");
File[] subFolders = rootFolder.listFiles();

HashMap<File, String> fileList = new HashMap<>();

//Add all files in a subfolder to a HashMap and associate them with the language
for(File currentFolder : subFolders){
if(currentFolder.isDirectory()){
for(File currentFile : currentFolder.listFiles()){
fileList.put(currentFile, currentFolder.getName());
}
}
}

//Iterate through files
fileList.forEach((File f,String lang)->{
System.out.print("Testing " + f.getName()+"\t");

try{
//Get contents of file
BufferedInputStream input = new BufferedInputStream( new FileInputStream(f));
Scanner sc = new Scanner(input);
sc.useDelimiter("\\Z");
String contents = sc.next();

//Call compute method and store result
String result = compute(contents);

//Increment counters
if(result.equals(lang))
right++;
total++;

System.out.println("Guess: " + result +"\tActual: " + lang);
} catch(IOException e){
System.out.println("There was an error when reading the file");
}
});

//Print out final results
System.out.println("Right: " + right);
System.out.println("Total: " + total);
System.out.println("Percent: " + (double)right * 100.0 / total + "%");
}

public static String compute(String c){
}
}


The test cases consist of 500 code samples (100 from each language) from around the internet (mostly github). Specific locations can be found in Credit.txt in the Test Cases folder.

• If you don't want to limit it to Java, don't enforce the submission tester. Most languages aren't too hard to test, with the exception of TinyMUSH. – Rɪᴋᴇʀ Jan 24 '16 at 1:16
• @RikerW I made the wording a bit more language neutral. – Daniel M. Jan 24 '16 at 1:27
• Why do we need a tester at all? Can't we just test it manually? – Rɪᴋᴇʀ Jan 24 '16 at 1:30
• How else would you run through a few hundred test cases – Daniel M. Jan 24 '16 at 1:32
• @Downgoat's was a special case, normally there aren't that many test cases. There should only be like 10 different cases, and that should cover most of it. – Rɪᴋᴇʀ Jan 24 '16 at 1:33
• The number of test cases will vary widely with the challenge. Depending on the length of the code samples in this challenge, I can imagine a fairly large number of test cases being used to give a demanding challenge. – trichoplax Jan 28 '16 at 18:52
• If the test cases are provided as a list of inputs and a list of outputs, would that allow for easy testing in any language? Simply automate the running of the candidate answer against every input, giving a list of outputs, and then compare that with the target list of outputs. – trichoplax Jan 28 '16 at 18:54
• The test cases are a bunch of files of each programming language. They are sorted into subfolders with the name of the language the example is written in. The tester loads each file, gets the language based on the subfolder's name, puts the whole file into a string, and feeds it to the method. It compares the returned value to the subfolder's name. This way, to add or change test cases, it's a matter of dropping additional files into a folder, or dropping in a folder to add a new language. – Daniel M. Jan 28 '16 at 19:03

# Pixel "Density"

In this challenge, we will be viewing each pixel in an image as a particle with two properties:

(1) vertical density (vd)

(2) horizontal density (hd)

These two properties are determined by the RGB values of the pixel in the following manner:

vd = Red - Blue

hd = 128 - Green

We call a sorted image an image that satisfies the following conditions:

For each pixel:

1. no pixel to the right has a lower hd

2. no pixel to the left has a higher hd

3. no pixel above has a higher vd

4. no pixel below has a lower hd

The challenge is to produce such sorted images.

Input

An image in any "common, recognizable" format, via file or stdin.

Output

A sorted image in a "common, recognizable" format (not necessarily the same format as input) containing exactly the pixels of the original , via file or stdout.

Relevant Details:

• This is .

• alpha values (if they exist) are ignored.

• Libraries may be used, but size must be added to your score

• "common, recognizable" formats will be determined by the community. I don't expect this to be an issue, but if you feel the the loose wording is being exploited, downvote the answer (or even better, help me fix it before the challenge goes live. I don't really want to enumerate the allowed formats, but maybe that is a better option?).

If there is interest in the question, I will create a reference implementation as well as test cases.

• I don't think this specific task is a dupe - the closest that comes to mind involves doing the same transformation but on colours represented as hex strings rather than on the actual bytes. However, this is pretty much "Look up one value i in an array; then loop applying A[i++]^=255 until the end of the array. Adding alpha makes it slightly less boring, but not much. – Peter Taylor Jan 23 '16 at 13:29
• @PeterTaylor You were right about it being extremely boring, I've reworked the challenge considerably. I hope this is more interesting. – Liam Jan 23 '16 at 23:28
• There seem to be 2 separate tasks here: 1. the pixel sorting. 2. processing bmp files. Do you want the file processing to be part of the same challenge? Otherwise you could allow any recognised freely available image format. For example, I would expect code to process a ppm file to be considerably shorter than code to process a bmp file. – trichoplax Jan 28 '16 at 18:35
• Relevant meta answer – trichoplax Jan 28 '16 at 18:45
• @trichoplax good point. My original thinking was to discourage the use of libraries so I wanted to use the simplest format I could think of, which is bmp. I'll make changes. – Liam Jan 28 '16 at 18:48

Windows batch polyglot/hybrids challenge with any language possible /* I need some help to refine my challenge */

As the batch scripts are pretty limited, hybrid files that embed a code from another language into a batch file are used a lot lately.

Though usually there are some requirements for a good hybrid script:

1. The embedded code should be usable as-it-is - without any ugly batch escaping sequences.
2. There should not be redundant output. E.g. a lot of languages use /* */ for multi-line comments. If the batch script executes a line that starts with / * it will print an error message an will continue to the next line .Though it will allow you to hybridize C/C++/C#/Java/... with a batch file the error message cannot be surpassed so this will not count as a good hybrid.
3. No temp files.It's easy to output a lot of code into a temp file that will be later executed , the IO operations will slow the script and on of the main advantages of batch scripting (the speed) will be lost. And more over is a challenging constraint. But this will be not possible for compiling languages and for extension sensitive languages.

Some examples will follow:

JScript (good for example as it comes with every windows installation) technique invented somewhere in the link by Tom Lavedas :

@if (true == false) @end /*
@echo off
cscript //nologo //e:javascript "%~dpnx0" %*
echo Output from the batch.
goto :EOF */

WScript.Echo('Output from the jscript.');


The output will be:

Output from the jscript.

Output from the batch.

The technique uses the JScript (javascript has no such thing) specific @ directives to make the code valid (or silent) both for both languages.

Another example (again with JScript) invented by Ryan Biesemeyer:

0</* :
@echo off
echo Output from the batch.
cscript /nologo /E:jscript %~f0 %*
exit /b %errorlevel%
*/0;

WScript.Echo('Output from the jscript.');


This time is used the redirection priority in batch scripts and 0</* : will be parsed as 0:</* .

• every line that starts with @ will be silent - even the invalid commands.
• every line that starts with : will be taken as label in batch and will be not executed
• every line that starts with something like <someWord : someWord will be silent because of redirection priority
• every line that starts with something like digit<someWord : someWord will be silent because of redirection priority (this time the output will be redirected to a stream).In this case will be best to use 0
• you can use <space><tab> ; , = at the beginning of every line - these will be ignored as standard delimiters in batch.Can be useful if some language use some of these as comment.
• if you start a line with %not_existing_variable% it will be replaced with nothing.Could be useful if in some language comments start with percent.
• If you finish a line with a caret ^ the next line will be appended at the end.With the caret in batch you can escape the new line.

here's a little bit more inspiration

And here's the challenge. Your script should be with .bat or .cmd extension . It should contain a code from another language - the code should be used by the second language as it is (no escapes symbols) .REPL tools are accepted with the condition of no escape symbols - except in the line where the REPL tool is invoked. There should not be redundant output. There should be not temp files (with the exception of compiling languages , and file extension sensitive languages - then the file should copy itself in the %TEMP% folder).

Each script should accept one command line argument which will be printed 5 (five) times . Both from the batch part of the code and from the second language prefixed by the language name (for the batch case it should be BATCH: for example.If the second language is Ruby it should be RUBY:)

For sure this will be not possible with every language , but for many it is achievable.

The winner should propose the most solutions with different languages (or if the language is the same a different kind of techniques should be used like in the two examples above).In case of equal number of solutions the first one wins.

# Weekly Physics Golf #{TBD}: Wavelength of a Sound Wave code-golfmath

META NOTE: I believe, and others in the comments, that this challenge is quite trivial. So, I will be working on making this challenge harder in the next few days.

## Introduction to the Series

Every week I will be posting a physics challenge. My goal here is to design challenges that in the end, teach some people some physics. Overall, the challenges will be very basic with little information. All of these challenges will have the minimal information necessary to solve them, and the goal is for users like you to do some research, watch some videos, and understand how these concepts work to teach you how to approach these types of physics problems and explain how they work. Of course, I will also give two optional hints per challenge, which are there if you do not have the time or determination to do the research, or you cannot figure out how to do the problem after researching. The two hints will be "necessary equations for this challenge" and "process to solve the problem". The hints are completely optional to use and it is encourages to not use them, but as stated above to learn the information for yourself. The series will have one main leaderboard. Whoever has the least combined byte count for all of the challenges gets a to be determined prize. Each challenge will range in difficulty, with an upwards trend of difficulty. I wish you all luck and I hope you learn a thing or two!

## Challenge #{TBD}: Wavelength of a Sound Wave (Difficulty: EASY)

Many people may not know that sound is actually a wave, which would explain why it can go through objects and bend around corners. But it has some really interesting properties. For example, the speed of the sound wave changes from a few factors, all relating to the medium it travels through. In this challenge, you will have to figure out the wavelength of a sound wave through a given medium.

But first, lets define a medium. A medium is any liquid, solid, or gas that a wave can travel through. Mediums can affect the speed of a sound wave in two ways: the density of the medium, and the bulk modulus elasticity of the medium. But what are these two things? Well lets first consider the density of an object. Density is defined to be the mass divided volume of the object, or in simple terms, amount of mass in a given space. This is important, as waves travel differently through mediums of different densities. The reason behind this is that a medium with a higher density has more inertia (the resistance to change in motion). An object with a higher inertia will be more difficult to move with a wave (which displaces particles to move). Therefore, INCREASED DENSITY corresponds to DECREASED WAVE SPEED.

Now lets define bulk modulus elasticity. This is really just a fancy name for stiffness of an object. But what does this have to do with anything? Well, when an object is stiffer, each molecule is more interconnected to other molecules. And because a wave displaces particles to "move", it will move through a stiff medium faster because it can move larger molecules, hence moving more distance in a shorter time, a.k.a. moving faster. Therefore, INCREASED BULK MODULUS ELASTICITY corresponds to INCREASED WAVE SPEED.

So in this challenge, I will give you the density and the BME (bulk modulus elasticity) of the medium, and also the frequency of the sound wave. Your job is to use this information and output the wavelength. Here are the full specs:

• Input will be three numbers (not necessarily integers). They correspond to density in kg/m^3, bulk modulus elasticity in Pascals, and sound wave frequency in hertz.
• Input can be in any order, in any convenient format (so 12.3 45.6 78.9, [12.3 45.6 78.9], and 78.9,[12.3,45.6] are all acceptable).
• You may assume that input will never cause any sort of error during execution.
• Output will be the calculated frequency of the sound wave in meters, precise to three decimal places, omitting leading and trailing zeros. For example, inputs of 6, 27, and 3 would given an output of 0.707 after rounding from 0.70710678118654752440084436210485.
• Shortest code in bytes wins!

## Test cases

META NOTE: Test cases to come, I am working on them right now.

## Hints

These hints are for those who do not want to put in the time and effort of research, or those who could not find a solution. So, here are the two hints:

### Hint 1: Equations

You need the following equations for this challenge:

### Hint 2: Sample Solution Process:

Using the two equations above, we can set them equal to each other to get:

Solving for wavelength gets us this equation:

From here you can just plug in values.

This is , so shortest code in bytes wins. Good luck!

Meta note: blah blah blah, working leaderboard will eventually go here! This leaderboard will contain and combine scores for all of the weekly challenges. It will only be visible on this question, though.

• Please tell me of any suggestions, I'll be happy to hear them. More importantly, please alert me of any mathematical inaccuracies and/or inaccurate explanations. – GamrCorps Feb 2 '16 at 2:25
• +1 for the idea. I love learning new things! – user81655 Feb 2 '16 at 12:20
• But my concern with this challenge is that it's too simple and straight-forward. The shortest answer in every language would be something like (a,b,c)=>(b/a)**.5/c (except for Mathematica, it proabably has a built-in :P ). – user81655 Feb 2 '16 at 12:20
• I concur with @user81655, but I'm excited to see what you can come up with. – lirtosiast Feb 2 '16 at 18:05
• @user81655 Yes, after further analysis I have realized how simple the problem is. I am currently working on an alternative challenge while I make this one more difficult. – GamrCorps Feb 2 '16 at 21:55

I've posted two well-received (by my standards: 10+ no downvotes) questions in the past; however, I've always missed a bit of information, so I welcome all feedback to this challenge!

### Introduction

A palindrome is a word or string of words that is the same forwards as it is backwards, e.g. taco cat, kayak, madam im adam. I'm sure by now you're all familiar with .

An anagram is a word or group of words that when the letters are rearranged, forms a different word or string of words. If you haven't already, Google for anagram or define anagram (not part of the puzzle, obviously).

Your task is to write a program which will take a string of lowercase characters and blank space, and return truthy/falsey if the string can be anagrammed into (or is) a palindrome (even if it doesn't form a legit word). This is so shortest answer wins. Standard loopholes apply.

### Input

• A string of at least 1 character containing a mixture of lowercase alphanumeric characters and blank space
• Whitespace can be ignored when determining whether a word or phrase can be anagrammed.

### Examples:

Truthy
kayak = kayak / akyka
maam = maam / amma
her taco cat hero = hertacoocatreh
boob = obbo
boobs = bosob
ooh = oho
lol = lol (already a palindrome)
zzz = zzz (already a palindrome)
i = i
00010001 = 10000001
0xd00000d = 0d00x00d0
sevens 7even = seven7neves
Falsey
glum glow worm