# 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!

# Collectables, Inc king-of-the-hill

You're an aspiring collector. You want to be the top collector for as many collections as possible.

Here's how you play (with P players):

• The game consists of multiple Auctions, and 2P collections. Some collections are bigger than others. Smaller collections are more valuable and rare, bigger collections are cheaper.

• Each Auction puts 2P random items up for sale

• You place a bid on each item, grouped by collection. (e.g. If doll was a collection, you place a single bid for all of the dolls in the current Auction)

• You win by having the most pieces for the most collections. (Each collection is worth 1 point. If you have the plurality of that collection, you gain that point).

### Fine Details:

• Each collection contains a different number of items, from 2 to 2P+1.

• There are 2P+3 auctions (until all items are sold)

• Players can bid on multiple items, and their total bid can exceed their current gold.

• Resolution of bids happens as follows:

1. All invalid bids are removed. (Players without enough gold, or bids on items already sold).
2. Find the top bid (by gold). Tiebreaker is the collection size (smallest first).
3. If there is still a tie, then that item group is removed.
4. Otherwise, the top bidder wins the item group. His money is added to the pot.
• After an Auction is finished, the pot is evenly distributed among all players. Any remainder is put back into the pot.

I think that my rules are pretty complete.

• Is it clear?
• Is it interesting?
• How many reads did it take you to understand the post?
• 1. It took me until the third read-through to understand that the collections are split into items and then recombined, possibly because I'm unconsciously applying real-world knowledge about how these things normally work. Explicitly saying that there are P*2+3 auctions would be a useful hint. 2. I was going to say that point 3 was missing a tie-breaker until I realised that the second sort criterion is collection size and not group size. 3. I think there's some interesting game theory here: things like weighting bids towards odd sized collections vs even sized collections. Sep 11, 2017 at 7:37
• @PeterTaylor thanks for the feedback! I added an overview, does that help? Sep 11, 2017 at 15:32
• Best to ask someone who hadn't previously read the question. BTW I presume you're planning to add something later about the I/O? Sep 11, 2017 at 16:01
• Yep. There isn't any hidden information (unless you count simultaneous as hidden), so the API should be pretty straightforward. Sep 11, 2017 at 16:21

## Unicode reversible programs

The goal is to make a program that includes unicode formatting characters that when executed as-is generates a OEIS sequence, and when copied as its rendered* and executed, returns a different sequence.

• The renderer is one that properly reacts to unicode formatting. For example with RLO the text should be reverted. (Its stored as "\u202etest" but renders as "tset"

This is will be so the answer with less bytes wins.

• What do you mean by "copied as its rendered and executed"? Feb 1, 2018 at 11:18
• @PeterTaylor I mean that for example the text "\u202e hello" is rendered as "olleh " because U+202E is a unicode control character that reverses text (when rendered) Feb 1, 2018 at 19:28
• Define it objectively. How browsers/text editors handle copy-paste are implementation-defined. (which browsers/text editors, which exact ways to copy-paste, put the pointer on which pixel of the screen, etc.) Feb 2, 2018 at 5:35
• U+202E is not a Unicode control character: the Unicode control characters are the ranges U+0000 to U+001F and U+007F to U+009F. Feb 2, 2018 at 12:19
• Also: this question talks about characters and bytes but it doesn't address the relationship between them, which is a minefield. What about languages which don't use UTF-8 or UTF-16 for their source? What about languages which use either according to a command-line flag: can the transformed program change the state of that flag? Feb 2, 2018 at 12:26
• @PeterTaylor languages that dont use utf-8 it in their source can use a escaped form such as (0xe2 0x80 0xae). Also thanks for pointing that its actually a formatting character (not control) Feb 2, 2018 at 18:20
• So basically split on the unicode char and reverse all that's after it? Possibly multiple times? Doesn't sound too interesting. Feb 2, 2018 at 21:29
• "for example"? Questions (challenges) need to be self-included. List all of them please. Feb 3, 2018 at 5:29

# Non-true, non-false JS boolean

Array prototype isn't redefined, input hasn't getters

function magic(input){
let result = [];
if(input.boolean != true){result.push("non-true");}
if(input.boolean != false){result.push("non-false");}
result.push(input);
return result.join("\n");
}


returns

non-true
non-false
{"boolean": true}


What is passed to magic function?

Based on real problem :) I spent 30 minutes on this puzzle

• This site is for programming contests, not pure programming puzzles. Thanks for using the sandbox, anyway. Feb 1, 2018 at 12:11
• Contrary to what user202729 states, Programming Puzzles are on-topic on this site. This challenge could use a little cleanup to make it a better fit here (for example, what language is this?), but this challenge is indeed allowed here. Feb 1, 2018 at 14:02
• ... someone said that I'm wrong. Anyway people definitely doesn't like this. Feb 1, 2018 at 14:02
• @AdmBorkBork this is JS Feb 1, 2018 at 14:41
• @ЕвгенийНовиков what JS version is this? in is a keyword, and can't be a variable name. Feb 1, 2018 at 14:47
• @dzaima Good point. Last time I check on TIO the object {boolean: true} doesn't have " around and it caused a syntax error. I forgot about in so just try to rename it and it worked... Feb 1, 2018 at 14:51
• "Programming Puzzle" is in the name of the site @user202729 Feb 1, 2018 at 15:46
• @dylnan But... Feb 1, 2018 at 15:55
• @AdmBorkBork is correct. We do allow programming puzzles. Feb 1, 2018 at 16:25
• @NathanMerrill Then just upvote the comment. Feb 2, 2018 at 5:34
• Many many things in the past, including but not limited to, code-trolling, underhanded, non-observable behavior, etc. are off-topic or heavily-discouraged nowadays. Be careful. Feb 2, 2018 at 5:34
• @user202729 I did upvote. I just wanted to make sure it was extra clear to the OP. Furthermore, this challenge doesn't fit any of those tags, because its not asking for trolling/underhanded/non-observable code. You could argue that the code in the challenge fits those tags, but that's not what we care about. Feb 2, 2018 at 5:51
• I don't believe that console is part of any JS spec. This presumably only works in certain contexts, and the question should specify what they are. Otherwise the task devolves into code-trolling by defining a suitable console. It's already borderline IMO. Feb 2, 2018 at 12:04
• @dzaima sorry, fixed this. Now input variable is input Feb 3, 2018 at 7:40
• OK, so, in that case you may want to work on the wording of the challenge before posting it to Main because, right now, it reads as though you've come across this challenge elsewhere, spent half an hour trying to solve and are now looking for help doing so. Also, just so you know, restricted language challenges rarely go down well here. Feb 3, 2018 at 19:20

Tags: Codegolf

Title: evil detection

When given any (you may choose the format and you should assume integer input) input, the output should be true if the input is a palindrome and false if not (or 1/0 or any equivalent).

To make it (a lot) harder, your code must work with a result that fulfills the challenge inverted if read backwards. So for a palindrome input, forward gives true, backwards false.

Example:

If your code is "abc12" and the input is 1221, your code should produce true-ish and "21cba" (your code read backwards) should produce false-ish.

Bonus if you think that's to easy: produce false if and only if the input is 666 forward and true backwards.

• Duplicate Feb 5, 2018 at 16:58
• First, I want to say thanks for using the sandbox! Also, I do think you could go somewhere with this idea that doesn't make it a duplicate. Your idea is marginally different, in that it only requires the code to behave the same forward and backwards, rather than actually be a palindrome. While I think for palindromes it will almost always be best to have a palindrome, perhaps you can think of a different pattern that makes it more interesting? I'll let you know if I think of anything. Feb 5, 2018 at 22:23
• @FryAmTheEggman, I don't think the fact that the code need not be palindromic is enough to make this not be a dupe; many of the solutions to the challenge above would also be the optimal solution here. Maybe if this one required that the code not be a palindrome and also required that it output a different pair of consistent and distinct values when run in reverse, it might be enough to differentiate it? Feb 6, 2018 at 9:25
• Thanks to both of you, I'll have a look at the other answers, but I agree that allowing the code to be semi-palindromic is not enough (unless the other answers are all extremely long, I haven't looked yet). I'm thinking about making the code required to not be symmetric, but haven't figured out what to do with the input to make it fit Feb 6, 2018 at 9:28
• @Shaggy That seems like a good start for changing it. For the record, I definitely think that as it was when I posted it was a duplicate, I just thought there was something good in this challenge and I didn't want it to just be discarded! The unfortunate thing about just requiring non symmetry is that comments/newlines could often just be added at the end without much cost, but I do think there is a good challenge here, somewhere. Feb 6, 2018 at 18:39
• I think the problem with this is that while some of the answers to the other question will no longer work, some are still usable here with only a slight modification, so I don't think this will cut it. Feb 6, 2018 at 19:31
• @Fryamtheeggman and if I make the bonus question mandatory? But I'll think some more Feb 6, 2018 at 19:42

## Build a Brainfuck transpiler

Your job is to build a program that transpiles valid brainfuck to a language (not brainfuck!) of your choice.

You are not required to handle cases where the program is invalid (mismatched [ ]s), or contains characters that are not +-<>[],. but all other cases must be handled.

Size limits on your input or output are fine as long as they are imposed by computer restrictions, like RAM.

The programming language you transpile to is covered under the "What defines a programming language" rules, and must have been created before this challange.

In extension to not transpiling to brainfuck (cheater!) you can't use a brainfuck derivative or trival brainfuck substitution as the transpiled to language either.

### Scoring

Programs will be scored with the average ratio of bytes in the input brainfuck program to the output transpiled result, as based on the examples.

## Meta questions

This is a rough draft!
What tags should be associated with this?
How can I improve the scoring system?
What examples should I use to keep the scoring fair, but prevent obvious tricks?
What loopholes are there in this rough draft that I need to patch?

This entire thing will be reorganized when I get enough info to make a better writeup.

• I'd tag it with code-challenge and brainfuck. Once you post the examples the scoring system seems to be fine, the major problem would be hardcoding but this is a standard loophole, so this should be fine. Also you should probably consider adding a non-terminating example. About preventing brainfuck derivatives: I'm not sure if this is well-defined enough, maybe others have some ideas? Feb 10, 2018 at 14:22
• @BMO About hardcoding: Just hide the official test cases. You don't need to prevent BF derivative, they would just be boring (and downvoted most likely). Also it's very hard to define them (What about 2D BF? What about Unary? What about Random BF / self-modifying BF?) Feb 10, 2018 at 15:39
• Also, BF is too unclear as a language specification. (is memory wrapping or infinite to one end or infinity to both ends? Are values positive/negative/modulo 256? etc.) Feb 10, 2018 at 15:41

# Chiasmus Indenter

Chiasmus is a literary form that is similar to palindromes. Some ideas are presented and then presented again in reverse order, often phrased differently.

Natural language processing is hard, so I'll be using a more computer-friendly definition. A chiasmic string is made up of a series of substrings that are repeated in reverse order in the second half of a string. Formally:

• If a is some non-empty string, then aa is chiasmic.
• If C is chiasmic and a is some string, then aCa is also chiasmic. Note that this applies recursively, thus abCba is chiasmic if C is also chiasmic and a and b are non-empty strings.

For example, batbat is chiasmic, as are glassbottlebottleglass and AliceBobCharlieCharlieBobAlice. All even-length palindromes are chiasmic, being made up of many length-1 strings.

Note that the empty string is not a chiasmus.

# The Challenge

We're programmers, so we like nice indentation. Your goal is to take chiasmic strings and indent them so that each matching substring is at the same level of indentation. For example, cheesepizzawithanchoviesanchovieswithpizzacheese would be indented like so:

cheese
pizza
with
anchovies
anchovies
with
pizza
cheese


For base case chiasms (i.e. 2 repetitions of a string), no indentation is necessary, but the substrings should still be on separate lines. Thus, gumgum would be indented:

gum
gum


In order for there to be only one canonical output for each chiasmus, if it is possible to indent at more than one place, indent in a way such that the a substrings for the form aCa are as long as possible (applied recursively for each C until the aa base case is reached). For example, catdogcatdogdogcatdogcat should be indented like this:

catdogcat
dog
dog
catdogcat


Not like this:

cat
dog
cat
dog
dog
cat
dog
cat


Also not like this:

cat
dogcatdog
dogcatdog
cat


The behavior of indenting a non-chiasmus is undefined.

# Rules

• Indentation can use any amount of whitespace of any kind, so long as it is consistent (e.g. do not mix tabs and spaces). Lines may either be output as a list/array/whatever or a newline-separated string.
• You may assume that the input is a chiasmus that contains only alphanumeric characters.
• As this is , the shortest submission wins.
• May indentation be done with a \t character? Feb 9, 2018 at 22:25
• I probably should do that since it saves 2 characters and is purely cosmetic. Feb 9, 2018 at 22:43
• "Longest possible substrings" still leaves some room for ambiguity. What's the canonical output for ababbaba? Feb 10, 2018 at 4:40
• aba b b aba. I see how it can be indented as a bab bab a, though. Feb 10, 2018 at 6:44
• I kept waiting for a glassbottlebottleglass test case! Feb 11, 2018 at 9:27
• @Shaggy Wish granted. Feb 11, 2018 at 16:52
• I don't understand the catdogcatdogdogcatdogcat example. It seems to me to directly contradict the rule it's supposed to be illustrating. Feb 12, 2018 at 8:54
• @PeterTaylor how so? Feb 12, 2018 at 20:15
• On review, I agree that "directly contradict" is overstating it. But the minimalist indentation still doesn't fit the rest of the question. The stated grammar is pointless: the derivation aCa is only permitted for extremely limited values of C (strings of the form bb such that there aren't c and d satisfying ab = cd and |c| > |a|). The statement "indent in such a way that the lowest levels of indentation have the longest strings possible" (my emphasis) makes no sense, because there is at most one level of indentation (or two if you count "unindented" as the first). Feb 12, 2018 at 21:49
• And the statement "All even-length palindromes are chiasmic, being made up of many length-1 strings" is not true, because the canonicalisation forces it to be made up of one repeated length-1 string and an outer layer of a repeated length-(n-2)/2 string. Feb 12, 2018 at 21:50
• The aCa form is recursive. Maybe I should make that clearer with the examples. Feb 13, 2018 at 1:53
• I would suggest dropping the requirement to produce an error on non-chiasmal(?) input, and instead just guarantee that the input will be a chiasmus. This changes it from two challenges (detect whether the input is a chiasmus, and then indent it if it is) to one (indent a chiasmus). Just my opinion though. Feb 13, 2018 at 7:56
• Slightly related Feb 13, 2018 at 10:16
• @Shaggy Well yeah it's related. I created that challenge and it was a direct inspiration for this one. Feb 13, 2018 at 19:30

## Self-removing executable (retracted: dupe)

• I don't like the restriction, it makes it easier for you to test (I guess that's the point of it?), but it prevents me (and many others) from competing. Saying it must handle "long and unusual characters" is underspecified. You can say that the program must be able to handle any valid filename, in the chosen operating system. The example code is already very short, so it doesn't leave much room for golfing, with all the restrictions in place. Feb 14, 2018 at 11:03
• Which restriction? Shall it be centered around per-language leaderboard then?
– Vi.
Feb 14, 2018 at 11:13
• Always per-language. I guess t's not all restrictions, but all the Linux-specific stuff. Keep in mind that these are only my opinions though, others might disagree. Feb 14, 2018 at 11:22
• It could be a good idea to have it Linux specific, but the example code is already so short that it leaves very little room for creativity. Feb 14, 2018 at 11:23
• Feb 14, 2018 at 12:52

# Convert a number to (Name-To-Be-Specified)

(Name-To-Be-Specified) is a completely made up language. It uses a Senary (base 6) system of numbers with words for those numbers structured in a similar way to English.

0 to 6
Single digit numbers use a single word for each digit.

0 = "zeeroo"
1 = "nimbo"
2 = "feta"
3 = "tarumba"
4 = "ntamno"
5 = "waramaka"
(Any similarity to Kómnzo numbers are coincidental.)

6 to 11
The first set of two-digits numbers have special rules.

6 = "wi"
7 = "seeveen"
8 = "ayte"
9 = "tarumbawin"
10 = "ntamnowin"
11 = "waramakawin"

12 to 35
Multiples of 6 have the single digit word with a "wee" suffix.

12 = "fetawee"
18 = "tarambawee"
24 = "ntamnowee"
30 = "waramakawee"

Other numbers in this range are made by joining the word for the multiple of 6 with the word for single digit number, separated by a space. For example:
13 = "fetawee nimbo"
20 = "tarambawee feta"
27 = "ntamnowee taramba"
34 = "waramakawee ntamno"

36 to 1295
1296 to 46655
46656 to 1679615
1679616 to 60466175
(Since this is a sandbox, I'll leave these to-be-specified for now. Suffice to say I'll come up with words for each and consistent rules for joining them together and when you need the word "and".)

# Challenge

Write a program that takes an integer as input and outputs that number in (Name-To-Be-Specified) words as described above. Shortest code wins.

• A language called Golfish already exists >_< Feb 23, 2018 at 13:50
• @Mr.Xcoder I believe you mean Gol><>
– user45941
Feb 23, 2018 at 13:52
• That's a programming language, not a spoken language. But fair point, if I graduate this to an actual question I'll pick a new name. Feb 23, 2018 at 13:52
• @Mego Well yeah but the repository name is Golfish... Feb 23, 2018 at 13:53
• Anyway, I'd advise referencing that you're not referring to Gol><> in any way. :) Feb 23, 2018 at 13:54

# Paintball Tournament

Inspired by The Rock, Paper, Scissors, Lizard, Spock Tournament of Epicness as well as other King-of-the-hill challenges, I would like to propose a Paintball Tournament.

There is a game on my phone, called Game Pigeon that contains a paintball game. This paintball game is played by two players. The object of the game is to shoot your opponent x times before they shoot you x times.

### Gameplay

The game is played in two sets of rounds. A moving round and a shooting round.

Both players, without their opponents knowledge, pick from three objects in front of them to hide behind.

                                (P1) X           X
X           X (P2)
X           X


Both players, without their opponents knowledge, choose which target across from them they would like to shoot at. After players decide which target to shoot at, players shoot at the targets chosen in unison, during which expose themselves from behind their target and are vulnerable to be hit.

Let's go through a small example. In the movement round, P1 has chosen to hide behind their left-most target. P2 has chosen to hide behind their middle target. In the shooting round, P1 chooses their leftmost target (Spot 1). P2 chooses their rightmost target (Spot 3). (See Below for diagram)

                                (P1) 3 <- Hit   1
2          2 (P2)
1  Miss -> 3


For the above example, P1 would miss their shot and P2 would hit their shot, resulting in P1 losing one of their lives. During the shooting phase, players must choose a barrier to shoot behind, they cannot stay hidden.

After the shooting phase both players go back into the moving phase and, without their opponents knowledge, can move behind either of the other two objects or stay in place. They then continue to the shooting phase. They loop through these two phases until one of the players run out of lives, both players run out of lives, or a set number of rounds is completed.

### Inputs

In the first game of the match, no arguments will be supplied to your bot. In each subsequent game of the match, you will be supplied 2 Args. -Arg1 will contain the location of the player([1, 2, or 3]) as well as the players move history. -Arg2 will contain the location of the players shot([1, 2, or 3]) as well as the players shot history. Both of these locations are referenced as if you are looking in the face of your opponent.

Example:

• Round 1: PaintballBot.exe
• Round 2: PaintballBot.exe 1 1
• Round 3: PaintballBot.exe 12 11
• Round 4: PaintballBot.exe 121 113

### Output

Each round, your bot must output the location in which it is hiding, and the location it is going to shoot, to STDOUT, with two characters. All example outputs are shown below:

11 12 13 21 22 23 31 32 33

### Match Format

Each submitted bot will play one match against each other bot in the tournament

Each match will last until one of the players loses their x amount of lives, or the match executes 50 rounds.

Matches will be played anonymously, you will not have an advanced knowledge of the specific bot you are playing against, however you may use any and all information you can garner from his decision making during the history of the current match to alter your strategy against your opponent. You may also track history of your previous games to build up patterns/heuristics etc... (See rules below)

### Submission

• A command to
• execute your bot from the shell e.g.
• ruby myBot.rb
• python3 myBot.py
• OR
• first compile your both and then execute it. e.g.
• csc.exe MyBot.cs
• MyBot.exe

## Sidenotes

• Need to describe that the location is relative to the shooter(from left to right) and the targets are relative to the shooter(from left to right)

• I am still working on the control program for this event, and any help from other is greatly appreciated

If someone with more experience than me wants to take this over, please let me know. I would rather help with this challenge since it is my first and then have the knowledge and skills to run my own in the future.

Please let me know what still needs more clarification so we can have a fun tournament!

## Sandbox Notes

• Is this inflammatory, mean, and liable to draw unwanted and unnecessary attention to low-voted questions in the Network?
• Better tags?
• I should probably write a snippet to find all angry Metas.

# Angry Meta

A site on the Stack Exchange network is considered to have an angry Meta if the lowest-voted Meta question (possibly closed, but not deleted) on the site is voted lower than the lowest-voted Main question.

For example, at the moment, the lowest-voted question on PPCG.SE is at -32, while the lowest-voted question on Meta.PPCG.SE is at -24. This means that codegolf does not have an angry Meta.

On the other hand, the lowest voted question on SoftwareEngineering.SE is at -13, while the lowest-voted question on Meta.SoftwareEngineering.SE is at -17. This means that softwareengineering does have an angry Meta.

## Challenge

You will be given the name of a Stack Exchange site, which you can assume will not be Area 51, Stack Apps, Stack Overflow, a subdomain of Stack Overflow (such as the Spanish Stack Overflow), Ask Ubuntu, Super User, Meta.SE, or any other site that whose domain is not of the form *.stackexchange.com.

The name will be given as the name of the subdomain (e.g. codegolf for PPCG, puzzling for Puzzling, gaming for Arqade, etc.). You should return one of two distinct, consistent values depending on whether the site has an angry Meta or not.

Since this is liable to change over time, I will not provide a list of test cases here, but you can use this Stack Snippet which is the reference implementation:

TODO

• I suppose you mean to say lowest voted questions in your PPCG.SE example. Mar 1, 2018 at 13:12
• @WeijunZhou Fixed. Mar 1, 2018 at 16:38

# Comment or not comment?

Write a function which given an all lowercase string, return the same string but with characters that are comments turned uppercase.

# Input

Input is a null terminated ASCII string which may contain any of these characters abcdefghijklmnopqrstuvwxyz /*\ space newline
Last and only last character is null
You will not need to test for invalid input, such as "stringliterals" etc

# Rules for what is comment

/* causes everything until */ (or end of string) to be comment
// causes everything until newline (or end of string) to be comment
'\' at end of line in a comment causes next line to be a comment aswell

# Output

A copy of the input but with letters which are comments according to the rules above in uppercase, other characters shall remain unchanged

# Examples

/comment -> /comment
//comment -> //COMMENT
/*comment -> /*COMMENT
no /*yes*/ no // yes -> no /*YES*/ no // YES

/*          ->              /*
comment                     COMMENT
*/                          */

//\          ->             //\
/*                          /*
not comment                 not comment
//\                         //\
*/                          */


ungolfed

• Which characters can be in the input? Printable ASCII? Mar 4, 2018 at 5:48
• printable ascii yes and you can also assume input will not contain uppercase letters, function shall change a-z -> A-Z if they would be comment according to C-syntax Mar 4, 2018 at 16:52
• I edited the proposal, clarified and simplified a little bit Mar 4, 2018 at 20:59
• Potential dupe. This challenge is about removing comments instead of changing their capitalization, but the main part is the same. Mar 6, 2018 at 21:00
• @Laikoni, thanks I had not seen that one, looks almost the same Mar 6, 2018 at 21:21

# There, I fixed it (with recycled parts)

### Challenge

Given a string containing only letters a-z (either upper- or lowercase), fix it by adding characters to it so that the difference between two adjacent characters is no more than one, or if you can't, remove offending characters (in order) until the string satisfies the requirement.

For example, abcdfge must be fixed either by adding an e, resulting in abcdefge, or by removing f and g, resulting in abcde. Removing must be done only if adding can't be done.

You can add characters only from a recycle bin, which your program or function must store between calls. Characters removed from the string are placed in the recycle bin, and added characters are removed from the bin. The bin can store multiple instances of the same character. In the beginning, the bin is empty.

If you can't fix the whole string by adding characters, don't add any characters. That is, only ever either add or cut a string, not a bit of both.

### Example

First call:
Recycle bin: "" (empty)
Input:       "abcdfge"
Output:      "abcde"          // 'f' and 'g' are removed and placed in the recycle bin

Second call:
Recycle bin: "fg"
Input:       "defhiabcdeg"
Output:      "defghiabcdefg"  // 'f' and 'g' are taken from the recycle bin and placed
// where they are needed.

Third call:
Recycle bin: ""
Input:       "codegolf"
Output:      "cdef"           // The two 'o's and the 'g' and the 'l' are removed and
// placed in the recycle bin.

Fourth call:
Recycle bin: "oogl"
Input:       "mnpqrt"
Output:      "mn"             // 'o' could be added, but it isn't, because an 's' is
// also missing and we don't have one. "pqrt" are added
// to the recycle bin.

Fifth call:
Recycle bin: "ooglpqrt"
Input:       "kmnrsu"
Output:      "klmnopqrstu"    // Characters "lopqt" are added from the bin to fill all
// the gaps. Unused characters are left in the bin.

Sixth call:
Recycle bin: "ogr"
Input:       "qwerty"
Output:      "qe"             // The gap between 'q' and 'w' can't be fixed so 'q' is
// removed. 'e'-'q' < 0 and therefore not more than 1,
// so 'e' stays. The rest of the characters are removed.
// The recycly bin will contain "ogrwrty".


This is , so the goal is to make your code as short as possible in whatever language you choose to participate with.

• "You can add characters only from a recycle bin, which your program or function must store between calls." Many languages don't have the capability to store information between program runs or function calls, or at least not easily. Perhaps having two inputs (recycle bin, 'input'), and two outputs (recycle bin, 'output') would be more inclusive? Mar 9, 2018 at 9:32

I wrote the following question then found this question. Is it similar enough to mine that mine would be considered a duplicate?

# Recursive Prime Multiplicative Base

I've been thinking about this idea for months now, and, as far as I have been able to find, nobody else has thought of it. Please let me know if I wasn't the first!

Most number systems are additive positional. These take the form of ∑bi*di, where di is the sequence of digits and bi is the base sequence. For example, for the number 1234 in base ten, di={4,3,2,1,0,0,0...} and bi=10i.

I propose the idea of a multiplicative positional system.1 This instead takes a general form of ∏bidi. The most obvious useful multiplicative base is that of bi=Pi, where Pi is the i-th prime number. For example, one could write 3960 as 3,2,1,0,12, as 23*32*51*70*111=3960. This is mathematically interesting (e.g. multiplication gets reduced to addition, but addition is way harder) but we're still using an additive system underneath. This obviously cannot do. Thankfully, we can use recursion! This is probably best illustrated with an example:

3960=
3    2   1  0 1
(0 1) (1)  () 0 ()
(0()) (()) () 0 ()
=(0())(())()0()


As you can see, each nonzero digit gets replaced with that digit's representation. 1 gets replaced with (), as a blank sequence is equivalent to an infinite series of zeros, and anything to the power of zero is one. If one were to include a symbol representing negation, one could write any rational number and even any expression obtainable from the integers using a finite number of multiplications and exponentiations in a finite sequence of four characters.

To give this number system a name, I term it the recursive prime multiplicative base or RPMB (unless you have any better ideas for it).

1Extending this, one can conceive of an infinite number of hyperoperational positional systems, but that's for another code challenge. ;)

# The Challenge

You are to write a program that, when given an integer as input outputs the RPMB form of that integer. The output may be either as a string or a list. If the output is a string, you may substitute any characters for ()0. If the output is a list, the output should be a list of 0's and other lists matching this description. For example, for 3960, the program might output [[0,[]],[[]],[],0,[]].

(todo)

## Scoring

This is , so the smallest program in bytes wins.

• Mar 11, 2018 at 10:07
• But 9 isn't a prime... Mar 11, 2018 at 10:08
• @user202729 whoops, typo! Thanks for catching that Mar 11, 2018 at 17:30

• Output the largest prime number possible in as few bytes as possible using no number but pi.
• This code will be the sole judge of whether your output is actually a prime number.
• Your score will be the prime number produced divided by the number of bytes used for your code.
• If your language has a built-in variable for pi, use that. Otherwise, let pi equal 3.1415926535898. Any occurrance of pi itself or something referring directly to pi counts as one byte.
• Your number must be generated solely by applying various operations and functions to pi. Those functions cannot offset pi by anything other than another number derived from pi. The sole exceptions to this rule are floor and ceiling functions. For example, if you want to find the square root of something, you must do something to the effect of raising it to the (pi/pi/(pi/pi+pi/pi))th power.
• You may not modify pi in any way that uses a reference to or directly uses non-pi number.
• The entirety of the number must be outputted in base 10 and without scientific notation. All digits of the number must be included in the output.
• You must provide a
• The largest score wins.

Here's an example in Lua:

print(math.floor(math.pi))


That's 14 bytes (counting math.pi as one byte) for the prime number 3, so my score is 3/14 or ~0.21428571428. Here's another example:

m=math print(m.floor(m.pi^m.pi)+m.pi/m.pi)


That's 31 bytes (each m.pi is one byte) for the prime number 37, so my score is 37/31 or ~1.1935483871.

# Sandbox

Are there any other ways to clear up ambiguities I may be missing?

• some loopholes are forbidden by default and are sometimes referred to as "standard loopholes". Mar 12, 2018 at 21:31
• You should include a winning criterion, i.e., "largest score wins" if I'm reading this correctly. Mar 12, 2018 at 21:31
• @Giuseppe Thanks. I've edited the post Mar 12, 2018 at 21:33
• At some point (and judging by the kind of stuff that happens here) the values being produced will be beyond guaranteed bounds of even strong tests like Baillie-PSW (2^64=18446744073709551616). Are such values banned or is it up to others to show that the number produced is composite? For example I might post Ç*ÇµḞ+Ḟ×Ḟ+Ċ*$ in Jelly since it produces 10555134955777783414078330085995832946127396083370199445109 which Baillie-PSW says is a probable prime. Mar 12, 2018 at 21:55 • Welcome to PPCG! Nice challenge! Mar 12, 2018 at 22:19 • Oh, by the way, that is floor(π^π)×(floor(π^π)+floor(π^π))+ceil(π^π)^ceil(π^π) and WolframAlpha also says it is prime Mar 12, 2018 at 22:24 • ...Mathematica to the rescue, it has a "PrimalityProving" package which we can plug numbers into to check Try It Online! Might be worth including this link. Mar 12, 2018 at 23:36 • Note that requiring unobservable behavior is discouraged. I suggest making the challenge a mathematical challenge and the score is calculated based on (the size of the formula) and (the output). (yes, non-code challenges are allowed) Mar 13, 2018 at 1:43 • Quoting from that answer: "Non-observable requirements tend to be vague, subjective, or based on false assumptions about the properties of programming languages." -- Yes, you're assuming that every language have floating point support, or that every language have the functions you mentioned. Mar 13, 2018 at 1:48 • (1) It's very hard to write prohibitions unambiguously, and I don't think you've succeeded. I don't know what exactly "Your number must be generated solely by applying various operations and functions to pi. Those functions cannot offset pi by anything other than another number derived from pi." allows and forbids. Can I convert pi to a string and take its length? Convert pi to a string, remove the decimal point, and convert back to an integer? Note: answering those two examples would not address the real problem. (2) "You must provide a" what? Mar 13, 2018 at 8:55 • I fell it's a busy-beaver – l4m2 Mar 15, 2018 at 15:14 # Relay Adder Make a 32-bit full adder with relays. A relay is here a gate with four inputs A, B, C and D, and output if A==B then C else D. You'll be given two 32-bit numbers (totally 64 inputs), a carry flag, constant 0 and 1, sum up to 67 inputs; output 33 bits as the result Smallest Gate count * gate depth win TODO: add tags • Do you foresee any possible gains by making this a 32-bit adder? It feels to me like an 8-bit adder would be sufficiently complicated to allow golfing, without becoming as tedious. What do you mean by: "sup up to 67 inputs?" You also don't define what gate depth is. You also probably want to come up with a way for answers to post readable solutions. Mar 16, 2018 at 20:20 # Split the wagons! code-golfparsing In some variants of APL, a tacit function, or a train, consists of several functions next to each other. Your task is, given a train, to separate the different functions it consists of. The symbols you will be given and their meanings are: • F: Function • O: Dyadic operator Here is how functions are separated in extended Backus-Naur form: function ::= {F O} F  Namely, a dyadic operator O accepts one function to its left and one F to its right, and the result is one function, for example F O F, F O F O F O F and F O F O F O F O F O F are all considered single functions for the purposes of this challenge. F F F O F O F F F O F, however, isn't a single function, and is split as (F, F, F O F O F, F, F O F). You can get the symbols in any reasonable form, including a string, an array of integers, and any other kind of ordered collection able to hold at least 2 different elements. You can assume the input doesn't start or end with O, or contain two Os in a row. However, you must always use the same symbols, and you must only use two unique symbols. The output can be one of: • List of indices (0- or 1-based) which are the locations of the first symbol of each function. The index representing the first symbol of the input can be optionally omitted, as it's implied. The list doesn't have to be ordered. • List of indices (0- or 1-based) which are the locations of the last symbol of each function. The index representing the last symbol of the input can be optionally omitted, as it's implied. The list doesn't have to be ordered. • List of the individual functions. Every element of this list is a list subject to the same restrictions as the input, but not necessarily in the same format as the input. However, all elements must have the same format. The list has to be ordered. Do not include empty partitions or duplicate, out-of-bounds or negative indices in the output. Below are some test cases. F and O are used for F and O respectively, and the output is a list of the separated parts. (empty) -> (empty) F -> F FOF -> FOF FOFOFOF -> FOFOFOF FOFOFOFOFOF -> FOFOFOFOFOF FFFOFOFFFOF -> F F FOFOF F FOF FFOFOFFOF -> F FOFOF FOF FFFFF -> F F F F F FOFF -> FOF F FFFF -> F F F F  # Euler's Formula for the Quaternions Euler's famous formula, e^iθ = cosθ + isinθ, can be used to calculate the exponential of arbitrary complex numbers: e^(a+ib) = e^a(cosb + isinb). That's cool and all, but what if we want to go even further? The quaternions are an expansion of the complex numbers, where instead of just having i*i = -1, you have i*i = j*j = k*k = i*j*k = -1. Quaternions can be represented as a + bi + cj + dk or (s, v) where s is a scalar and v is a 3-Dimensional vector. Euler's formula can be extended to the quaternions; for an arbitrary quaternion q = (s, v), e^q = e^s (cos|v|, (v/|v|)sin|v|), or, if q = a + bi + cj + dk and r = sqrt(b^2 + c^2 + d^2), e^q = e^a (cosr + (bi + cj + dk)(sinr)/r). ### The task: Write a program or function to exponentiate arbitrary quaternions. Built-ins are allowed. You may represent a quaternion in any sane manner. ### Examples Here, quaternions are represented as a four element array. Input Output (approximately) 0 3.14159 0 0 -1 0 1 1 1 -0.160557 0.56986 0.56986 0.56986 1 2 3 4 1.69392 -0.78956 -1.18434 -1.57912 0.095767 0.601479 0.285658 0.926716 0.458433 0.527339 0.250447 0.812487 -0.654682 -0.925557 -0.409382 0.619391 0.194782 -0.37576 -0.166202 0.251462  • There's a missing ) in e^q = e^a (cosr + (bi + cj + dk)(sinr)/r Mar 23, 2018 at 21:53 # Brainfuck Compiler! Your goal is simple: Compile brainfuck to x86 assembly (NASM style), and do it with as small of a program as possible. You will be able to choose your compiler's input and output model, as long as the input is brainfuck code and the output is NASM style x86 assembly. The brainfuck code should read from STDIN and output to STDOUT Your compiler must be fully compliant with no extensions, and must support a infinite (to the max the computer's memory can sustain, running out of space on either end can be treated as a crash.) number of unsigned 8 bit cells both forward and back, with the tape Your output assembly should provide the exact same outputs for the corresponding inputs as the brainfuck code. Your program's output must be compilable to a ELF binary that runs on Linux using the NASM compiler. Your program will be linked with libc, so you can use any function in the C library. ### What is Brainfuck? Brainfuck is a language with 8 instructions, and a tape memory model composed of an infinite amount of unsigned 8 bit (1 byte) cells. The pointer always points to one of those cells, executing its operations on the current cell. Each instruction is executed one at a time, and are as follows: • + Increment the current value under the pointer • - Decrement the current value under the pointer • . Output the value under the pointer as an ASCII character • , Get a character from input, and wait until one is received. • > Move the pointer to the right • < Move the pointer to the left • [ Jump to the matching ] if the value under the pointer is 0 • ] Jump to the matching [ if the value under the pointer is not 0 If a [ doesn't have a matching ] (or vice versa), you can consider that undefined behavior. Anything not listed here should be considered a NOP, or in the case of a empty program (EOF), simply a blank, noncrashing program. ### Test cases. To allow competition, and varying compilation results, my test cases will show what each test program should output. Program: "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>."  Outputs (no input): "Hello, World!"  Program: +[,.]  Outputs: "I am a test string" -> "I am a test string" "Golfing is fun!" -> "Golfing is fun!"  Program: +[]  Outputs: Nothing. This program loops forever. Program: +[<+]  Outputs: This program can be considered undefined behavior, because it will eventually run out of memory. ### TODO More test cases? • is the tape left bounded? also you should specify input behaviour on EOF Mar 26, 2018 at 22:05 • "to the max the computer's memory can sustain" -- I feel that requirement quite problematic. For example, a submission using 16-bit cell (and only use the lower 8-bit, for whatever reason) will only be able to handle half as many cells as one using 8-bit cell. Mar 27, 2018 at 0:55 • @user202729 I'd say a submission like that would be rare enough it's a non issue. Mar 27, 2018 at 1:40 • @DestructibleLemon The tape is unbounded, both left and right. Mar 27, 2018 at 1:40 • For a doubly infinite tape, to the max the computer's memory can sustain definitely needs more clarification. For example, if I "run out of space" on the right end, but still have space on the left one, do I need to shift things around? Mar 27, 2018 at 1:42 • Alright. I'll fix that now. Mar 27, 2018 at 1:43 • I think it's better to use 1 side unbounded, as that's usually the convention i think Mar 27, 2018 at 2:02 # Fill a virtual World Cup Sticker Album As the World Cup is due to kick off (pun intended), the inevitable sticker book comes along as well. According to this BBC article , at a cost of £0.80 for a pack of 5 and with a total of 682 stickers needed to complete the book it could cost up to £700 or more to fill, taking duplicates into account. Write the shortest program possible to • Buy a virtual pack of stickers (at 0.80 per pack), which will be 5 random numbers between 1 and 682 (or 0 and 681) • Repeat until all numbers have been picked at least once • Output how many packs were bought and a final cost. Output should be in the format "Bought number packets at cost of number" Sample un-golfed Python 2 code import random total = 682 remain = total cost = 0.8 spend = 0.0 packs = 0 got = [0 for i in range(total)] while remain > 0: # buy a packet of stickers for i in range(5): got[random.randint(0,total-1)] += 1 spend += cost remain = got.count(0) packs += 1 print 'Bought %d packs at cost of %.2f' % (packs,spend)  Sample output Bought 865 packs at cost of 692.00  ## QUESTION • Writing the Python script for myself is what made me think of this question - does it help to include it, or clutter the page? (This is my first attempt at a question here) • You need to flesh out what we're doing? Your code isn't super greatly commented and I'm not sure how much a pack costs, how many packs are needed. etc. should it always output the same amount? Mar 29, 2018 at 20:57 • What does "simulate" mean here? Beware the curse of the non-observable requirement. Mar 29, 2018 at 22:28 # Navigate my Taxi ## Introduction Taxi is an esoteric programming language simulating a taxi. You can pick up passengers (values) and drop them at special places to modify them. For example, this program squares the input. The places are all in Townsburg: To travel from one place to another, you have to tell your taxi where to go: Go to the Post Office: west 1st left, 1st right, 1st left.  And you need gas to drive, your car gets 18 miles per gallon. So it's best to find the shortest possible way between two places. That leads me to ... ## The Challenge ### Input You get an incomplete Taxi program, consisting of the following statements: • Pickup a[nother] passenger going to [the] <place>.: Pickup a passenger, you may ignore it for this challenge • "<string>" is waiting at [the] Writer's Depot. / <number> is waiting at [the] Starchild Numerology.: Create passengers, you may ignore this, too • Go to [the] <place>.: Go to a place, you have to add directions (see below) • [<label>]: A label for jumping, you have to parse those to know where the taxi is. They don't do anything if passed. You can assume that you are in the same location, regardless of where you reach the label from. • Switch to plan "<label>".: Unconditional jump, follow these to know where the taxi is • Switch to plan "<label>" if no one is waiting.: Conditional jump, you have to support both ways If the input program contains anything else, you may do anything you want (undefined behaviour). ### Conversion Following all jumping instructions, you have to add directions to the Go to commands. It has to be the shortest possible way (I want to save gas!) Directions consist of a cardinal direction (north, east, south, west or NESW) and a comma-separated list of turns, consisting of a number (1st 2nd 3rd or 1 2 3) and left/L or right/R. Examples: Go to the Post Office: west 1st left, 1st right, 1st left. Go to Post Office: W 1 L, 1 R, 1 L. Go to Tom's Trims: N.  The cardinal directions do have the following meanings (xstart means x pos of the starting point, yend means y pos of the next corner/intersection/place): • north: ystart > yend • south: ystart < yend • west: xstart > xend • east: xstart < xend (Coordinates from the top left corner) Here is a list of all intersections/corners/places/streets, extracted from the interpreter. Some additional info: • The taxi starts at the Taxi Garage. • If the taxi reaches the Taxi Garage, the program ends. • If the program reaches its end and the taxi is not in the Taxi Garage, that's an error, so you'll have to add 'Go to the Taxi Garage: ...' at the end if it's missing. ### Output • Your program or function has to output a valid Taxi program (online interpreter) or a list of instructions (which, when concatenated, form a valid Taxi program) • You may use the long (north 1st left) or short (N 1 L) syntax. • The ways chosen have to be the shortest possible (droven distance, i.e. sum of Euclidian distances between any two consecutive points on your way) • If there are multiple equally long ways, you can use any of them ### Additional Rules • Standard loopholes are forbidden • Your score is the number of bytes in your program • Lowest score wins ### Test Cases TODO • Is any part of the specs confusing? • Should I not input a full program, but just start and destination? • Should I add the map in some format as an additional input? • Thanks for using the sandbox, but I'm sorry that it's not very active. We decided that "typical desktop computer" is not clear enough, so you should change it. Feb 24, 2018 at 14:54 • What is "shortest" measured in? Euclidean distance? What if there are multiple equally long paths? Feb 24, 2018 at 15:09 • @user202729 Edit: time is now on TIO, distance is sum of Euclidian distances between any two consecutive points on the way. I'm thinking about writing a program that calculates the distance Feb 24, 2018 at 16:37 • TIO is still not usable for time-related things. See codegolf.meta.stackexchange.com/questions/12707/… . Feb 24, 2018 at 16:39 • Is it guaranteed that the taxi will be in the same location regardless of how we reach a label? Feb 24, 2018 at 17:08 • @user202729 Ok, removed time limit Feb 24, 2018 at 17:09 • @Nitrodon finally, I got what you meant. Sure. Although theoretically, if both points lie on one street, one could do that ... (I would not recommend it) Mar 16, 2018 at 23:02 # Left Turn at Euqreuqebla Write a quine, according to the standard definition of a quine, that outputs itself when executed. However, when your code is reversed it should output each character of your source code separated by a newline instead. # Example If your program was: ABCDEFGH IJKLMNOP  The unedited program should output: ABCDEFGH IJKLMNOP  However the reverse of the program should output: A B C D E F G H I J K L M N O P  # Rules: • Outputting a single trailing or preceding newline is acceptable. • If your code contains newlines, they do not require rotation, treat them regularly. • Standard loopholes are disallowed. • Ensure that your "quine" is actually a quine. • This is , ; lowest byte-count wins. • an example with code with newlines would be useful (as those I'd naturally rotate 90 degrees :p) Mar 29, 2018 at 21:04 • @dzaima which way do you think is better, not requiring "natural rotation" to support Java and the like better? Or supporting natural rotation for the esolangs? Mar 29, 2018 at 21:07 • a thing to consider is that if natural rotation would be required, everyone would just try to keep everything in a single line to make the challenge way easier Mar 29, 2018 at 21:10 • @dzaima I could make it optional? I don't see that hurting the challenge too much either way to be honest, it just lets languages to what they do best. Mar 29, 2018 at 21:11 • that'd be a good compromise if there's no better solution Mar 29, 2018 at 21:12 • @dzaima ehhh? decent? Mar 29, 2018 at 21:17 • usually it's bad to have multiple ways to solve the challenge, though here it's pretty easy to tell which method's gonna be the easiest Mar 29, 2018 at 21:18 • @dzaima exactly, that's why I want to allow it to see if SOGL or some other language with crazy flipping commands can do this the "harder" way. Mar 29, 2018 at 21:19 • If you're going for Albuquerque spelled backwards, that's not how it's spelled. Mar 30, 2018 at 13:25 • Shouldn't the example have a gap of three newlines between the H and the I, not two? Apr 1, 2018 at 0:00 • @AidanF.Pierce great catch. Apr 2, 2018 at 11:50 # Radioactive Quine Sums Related: Radioactive Quines ## Challenge Write a program that takes an integer as input and.... 1. When the program is run it outputs the input. 2. When you split the program in half, each sub-program should take as input the output of the original program, and output a number. The sum of the two numbers should equal the output of the original program. 3. Repeat the procedure with each valid sub-program. Your score is byte count/[valid programs]2 (lowest score wins). ## Specs 1. When you split an odd-length program in half, the program on the left gets the extra character. 2. For a sub-program to be valid, the sum of its output and its pair's output must be the input, for every possible input n, -100≤n≤100. 3. A sub-program that doesn't compile/doesn't output a number is invalid (along with its pair). 4. If a program is invalid, it can't be split further. 5. A program that outputs "0" for more than one input can't be split further. ## Testcases Pseudo-langauge: A adds a 0 to the stack, Q adds the input to the stack. - negates the element to the right of it.The output is the sum of the stack elements. 1. Q Score: 1/1 = 1 2. AQ Score: 2/3² = .222 (AQ -> input, A + Q -> 0 + input) 3. AAQ Score: 3/3² = .333 (AAQ -> input, AA + Q -> 0 + input) [Since the output of AA is 0, you can't split it any further] 4. QAA Score: 3/5² = .12 (QAA-> input, QA + A -> input + 0, Q+A -> input +0) [Since QA -> input, Q and A are valid sub-programs, since the sum of their outputs equals the output of QA.] 5. QAQ Score: Infinity [Since QAQ outputs 2*input, it is invalid and can't be split further.] 6. QQ-Q Score: 4/5² = .16 (QQ-Q -> input+input-input,QQ+-Q -> (input+input)+(-input), Q+Q->input+input, -+Q->error) [Q and Q are valid subprograms of QQ because the sum of their outputs is 2*input, which is the output of QQ.] Feedback Appreciated • 0=0+0=(-1)+1, why can't it be splitted further? Apr 2, 2018 at 6:38 • @user202729 because someone would just leave it always zero – l4m2 Apr 2, 2018 at 15:30 • However I still think score->0 solution exist, so – l4m2 Apr 2, 2018 at 15:31 • For 0=(-1)+1: Language W=output the input 0=output zero Q=quit WQ0Q0Q0Q0Q0Q0Q0Q has low score – l4m2 Apr 2, 2018 at 15:33 • @l4m2 and user202729 look at rule 5 in Specs. Apr 2, 2018 at 17:01 • @geokavel we know the rule, just analysing whether they are good here – l4m2 Apr 2, 2018 at 17:03 • @l4m2 yeah, i see your point about WQ0Q0.... scaling infinitely. Apr 2, 2018 at 17:04 # Heroes of Might and Magic 0: A Numerical Boxing Match It's time to program a game! Well not a game, precisely. More of a stripped-down version of a game, without graphics or real-time input... or really much of anything. But it'll modify numbers on screen, and isn't that why we play games in the first place? ## To elaborate: If you're unfamiliar with the Heroes of Might and Magic franchise, here's the very most basic workings of the combat system: A stack of creatures of a single type (say, 2 green dragons or 1000 marksmen) will simultaneously attack another stack of creatures of a single type. Each creature does a specific amount of damage, and that's reflected in how many troops in the opposing stack die. For example, let's have 5 angels vs. 100 skeletons, and let's have the angels go first. If they hit 50 damage each, then 5*50 = 250 damage will be done to the skeletons. If the skeletons each have 10 health, then 250/10 = 25 skeletons will perish, leaving 75. Next, the skeletons attack. If the skeletons deal 2 damage each and angels have 100 health each, the skeletons will do 2*75 = 150 damage to the angels. But how can we kill 150/100 = 1.5 angels? What happens is that one angel will die, and then the remaining 150-100 = 50 damage is dealt to the top angel in the stack. This angel will be the first to receive damage on the next round and will only require 100-50 = 50 damage to die, but can still deal damage like normal in the meanwhile. Then angels attack skeletons, skeletons attack angels, angels attack skeletons... repeat until only one stack of creatures remains! There are loads of other mechanics involved in actual combat, but the fundamental one is attacking, and that's what you'll be programming today. ## Technical Specification Two stacks of monsters will be attacking each other. Each of these stacks has three properties: 1. Size, positive integer. This is how many total monsters are in the stack. 2. Health, positive integer. This is how much damage is needed to kill ONE. 3. Damage, positive integer. This is how much damage EACH monster in the stack will deal. When a stack of monsters A attacks a stack of monsters B, all of the monsters attack, dealing A_size * A_damage  total damage. This kills a total of floor(A_size * A_damage / B_health)  monsters in B. If the damage dealt isn't an even multiple of B_health, then the remaining (A_size * A_damage) - (B_health * floor(A_size * A_damage / B_health)) = (A_size * A_damage) % B_health  damage is dealt to the top monster in B, which will persist into the next round. ## Input You'll receive two groups of three numbers, each of which contains information about one stack of monsters: The total number, the health of each individual, and the damage dealt by each individual. [(A_size, A_health, A_damage), (B_size, B_health, B_damage)]  You can receive this as two lists/tuples/arrays of three, six separated values in a single line, or six newline-separated values. The first group of numbers represents the monster that attacks first. ## Output After the fight is finished, you must output the number of remaining troops in the winning stack. ## Examples Input: [(1000, 10, 2), (500, 15, 3)] Output: 763 Input [(1, 2, 3), (4, 5, 6)] Output: 4 Input [(100, 100, 1), (100, 100, 1)] Output: 10  Lowest byte count wins! # Feedback • Is the challenge clear? I feel like it's simple and maybe I'm being too verbose in explaining it, but maybe it isn't. • Are there any other good ways to accept input? • Does it seem like it'd make a fun challenge? If not, are there any changes I could make to make the challenge more interesting? • Anything else? Thanks everyone!! See all the blocks In a 3D coordinates, a block (a,b,c) takes the place of x<a<x+1, b<y<b+1, c<z<c+1. 1. Is there a point that can see every block? (Exist point P, For each block K exist point Q, segment PQ don't go across any block but K) 2. Is there a way that can see every block? (Exist non-zero vector w, For each block K exist point Q, for each positive number t, Q+wt is not in other blocks than K) Output four values to represent the four possibles. Shortest code in bytes win. • Although the challenge idea is good, we generally expect people to make the challenge reasonably-complete in the sandbox ("write your challenge just as you would when actually posting it"), and not just the ideas. (for example: what is the winning criteria?) Apr 4, 2018 at 6:55 • Also, it appears that there are 2 different challenges here that needs to be solved in very different ways. Consider having 2 different posts. Apr 4, 2018 at 6:56 Write a program that, in different languages, output a different permutation(the exact source is counted as one permutation) of the code. Proper quine rule apply. Largest (Language count)^6/(Code length) win. Sample: If your code is AAB and running in several languages return ABA, AAB, AAB, then its score is 2^6/3. • "Shuffle" implies randomness. I'm assuming that this isn't what you want: "Ordering" is a better term: You want a set of programs that output the same bytes, but in different orders. Apr 7, 2018 at 5:31 • Or "permutation". Apr 7, 2018 at 6:08 • Do the output need to be valid (executable) source code or it may be mess of reordered characters? – tsh Apr 8, 2018 at 6:46 # The 3n+1 problem The legendary problem in UVa Online Judge, with over 775k submissions and over 85k people who solved it. I, personally, have solved it in many ways, even reaching the best time below 0.01 sec. Even though the problem is interesting from the algorithmic point of view, insofar as reasonable time constraints would be easily able to force people to think about some sane approach to caching and use data structures like the segment tree, it is actually not the case here: the time constraints, on UVa, are so lax that even a purely naive algorithm is accepted by the judge. Since we are on CodeGolf and not on a programming contest, we aim here to write shortest code, and not necessarily fastest one, so for most part you don't need to care about performance - that is, as long as it is not horrible even beyond the lax allowances of the online judge; more on that below. # The input The input will consist of several lines, each containing a pair of integers i and j, such that 0<i,j<1,000,000. # The output For each line of input, you are to print one line of output that will consist of integers i and j, in that order, followed by one number that will denote the maximum length of the Collatz sequence (also known as the 3n+1 sequence), over all numbers between and including i and j. Note that while in mathematics the terminal number 1 usually doesn't count to the length of the sequence, in this problem it does. The Collatz sequence is defined as follows: If an is odd, then an+1:=3*an+1; or, if an is even, then an+1:=an/2. The sequence ends when it reaches number 1. # Sample input (taken from UVa): 1 10 100 200 201 210 900 1000  # Sample output (taken from UVa): 1 10 20 100 200 125 201 210 89 900 1000 174  # Additional notes: • There is no guarantee that i<=j. The input may contain lines with i>j. However, even in these cases, you are supposed to print out i and j in the output in the correct order (that is, i comes before j, not min(i, j) before max(i, j). • There is a guarantee that, while computing the Collatz sequence terms, no term will overflow a 32bit integer. • As of now, the problem specification gives incorrect input boundaries, claiming that all numbers will be less than 10,000. The correct bound seems to be 1,000,000 instead, which is present in the archived version of the problem specification. Since last time I checked the judge required accepted programs to be able to process numbers up to 1,000,000, we retain that requirement in our problem. • Your program must perform actual computations. Hardcoding all sequence lengths for numbers between 1 and 1,000,000 is unacceptable. So is fetching them from external sources. • Your program must read from standard input and write to standard output. Your program must format its output as required by UVa Online Judge for this program. • Of course, we do not retain the original harsh requirements on acceptable programming languages. Any programming language is OK as long as it doesn't violate the standard loopholes. • Your program must correctly process all lines until EOF and then exit gracefully. Your program must not wait endlessly on EOF, enter an infinite loop on EOF, crash on EOF, exit with an error, etc. • Performance restrictions: • Basically, the intention is to allow everything but most horribly underperforming programs. • To be more specific, the naive algorithm that, for each line of input, computes once the whole sequence for each number in the required range is allowed (example of an allowed program). It is also allowed to keep an array caching lengths of all sequences starting with numbers from 1 to 1,000,000 (example of an allowed program), or to keep a dictionary caching lengths of all sequences starting with any encoutered numbers so far (example of an allowed program); however, it is not allowed to keep an array caching all encountered lengths, since that array would be unreasonably sparce and thus unreasonably large (example of a disallowed program); it is also not allowed to precompute a 1,000,000x1,000,000 array that would keep all maximums of lengths in all valid ranges (example of a disallowed program). Your program may precompute lengths even for numbers that would otherwise be disallowed by the guarantee of not overflowing a 32bit integer (example of an allowed program), if you wish. Shortest code wins. • From a golfing perspective, this looks like basically the usual Collatz challenge, taking the max over an interval but with Cumbersome I/O and non-observable performance requirements. – xnor Apr 8, 2018 at 7:03 • @xnor , I don't think these requirements are non-observable, my intention was to disallow everything the judge disallows without imposing the programming language restrictions; anyway; a 1,000,000x1,000,000 array of integers is around 3.5TB!! - I think disallowing this makes sense? Basically my intention was to prevent saying that "In a computer with unlimited resources this program would complete and is therefore valid". If I want to disallow this, am I supposed to rather prepare my own test case and run the program on my computer to see if it fits in reasonable time/space requirements? Apr 8, 2018 at 12:56 • I think I'm not understanding the restrictions then -- is what you intend is just a hard bound on run-time and memory, and the types of programs that work are just examples? Regardless though, I expect it not to matter as golfed programs will just compute the whole sequence for each number in the range, which you allow. All the optimizations seem like they'd take more characters. – xnor Apr 8, 2018 at 23:45 • ... yes, to have such requirements you have to run it yourself (or ask someone to do this for you) Although, if as you said (almost every algorithm) are allowed, what's the point in having another challenge? I would call this a dupe. Apr 9, 2018 at 15:13 • One more point: If there exists a programming language where hardcoding 10⁶ terms is shorter than computing them, you should reconsider the challenge. Apr 9, 2018 at 15:14 # ___ encrypting Given two text a and b, both contain only lowercase letters 1. Write each charactor in a into 5 digits of binary (a => 00001, z => 11010) 2. Write each charactor in b where such place of the binary list is 1 is written into a different style (uppercase, bold, etc., but should be consistant) 3. If some char remain in b, either keep them all in the 0 style or remove them. You can assume b has enough chars. Sample: a = cat, b = programmingpuzzlescodegolf 1. Write a into binary 000110000110100 2. So the output can be proGRammiNGpUzz, proGRammiNGpUzzlescodegolf, programmingpuzzlescodegolf, etc. • You should probably mention a specific win condition. Apr 10, 2018 at 13:07 # A Magic Ritual Given an input string N perform a sequence of steps. 1. Delete all spaces from the string. 2. Delete all other occurrences that come after the first one of the same letter from the string. 3. If the string contains the letters needed for zero, delete these letters and add the corresponding digit 0 to the end of the string. Repeat this for 0 to 9. 4. Order the characters left in the string by the alphabet, then by their numeric values. ## Input May be received as a string, an array of characters or any other reasonable input for text. You may assume that the input will only consist of characters including a-z (lowercase) and spaces. ## Output Same as input, or may be directly written to stdout. ## Rules • This is , the shortest code in terms of bytecount wins. • Standard loopholes are forbidden. ## Test Cases a magic ritual -> acgilmrtu sixone -> 16 codegolf -> cdefglo the quick brown fox jumps over the lazy dog -> abcdfghjklmnpqtuvwy06 qwertyuiopasdfghjklzxcvbnm -> abcdfghjklmnpqtuvwy06  • Do second occurrences include 3rd 4th etc? – l4m2 Apr 10, 2018 at 8:14 • @l4m2 Yes, I'll clarify. Apr 10, 2018 at 8:15 # Count the Matches Given a stripped-down regular expression, estimate (rules below) the number of lower-ASCII-only strings that it matches fully (meaning it matches the whole string). You should handle the following: • Literals/sequencing • Vertical bars ...|... • Groups (...) or (?:...) • Special characters escaped with a preceding \ • Character classes [...] • Complemented classes [^...] • The standard classes ., \d, \w, \s, \D, \W, and \S • The escape sequences \f, \n, \r, \t, and \xhh • The quantifiers ?, {x}, and {a,b} # Estimation Rules ## Literals Literals, obviously, match only one string. aaaaa --> 1  ## Classes The estimate for a class is the number of characters that it can match. If multiple are seen, then their individual counts can be multiplied. There are also the standard classes: \d is [0-9], \w is [_A-Za-z\d], and \s is [ \n\t\r]. \D, \W, and \S are the complements of their lowercase versions. a.b --> 127 \D --> 118 [a-gd-k] --> 11 [^\w$A] --> 64
[abc][xyz] --> 9
\d\d\d --> 1000


## Switches

Switches (vertical bars) should be estimated as the sum of the component expressions.

a|a --> 2
a|b --> 2
(0|1)[01] --> 4
0|1[01] --> 3
optional| --> 2


## Quantifiers

With a static quantifier, you can treat it as a power function. With a variable quantifier, you can use the geometric sequence formula to get the estimate:

a1 is the first term, in this case the estimate at the lower bound. r is the common ratio, for which you should use the estimate for the group quantified. n is the number of terms, which is the upper bound minus lower bound plus one for the quantifier.

[01]{10} --> 1024
.? --> 128
[01]{3,10} --> 2040
0|[12]{3} --> 9
(0|[12]){3} --> 27
\d{30,40} --> 99999999999000000000000000000000000000000
(?:a{2,3}){2,3} --> 12


Shortest code in bytes wins.

• The examples require support for sequencing, which is not listed as something which must be supported. The standard classes with upper case are not explained. (?:...) is mis-labelled: it's a non-capturing group. Apr 12, 2018 at 10:49
• Also what's the charset? 0-127?
– l4m2
Apr 12, 2018 at 14:49
• @l4m2 it's lower ASCII, so yes. Apr 12, 2018 at 15:54
• ASCII sometimes onlt mean 32-126 though
– l4m2
Apr 12, 2018 at 17:19
• @l4m2 that's printable ascii. Apr 12, 2018 at 17:27

# Tell SMILES from FROWNS

The Simplified Molecular-Input Line-Entry System file format is used to store structures of organic molecules. For information on why there is an actual file format called "smiles", consult this comic from PhD Comics. As a summary of the format:

• Start the file with a root chain of atoms.
• Put each branch group in parentheses after the atom it connects to.
• Use = for a double bond and # for a triple bond.
• Break aromatic rings and number the bonds broken; add those numbers after the atoms bordering them.
• Put metal atoms and any ions in square brackets.
• Omit hydrogens attached to carbons. Their presence is assumed.

For example, 1-chloro-3-ethylbenzene could be C=1(CC)C=CC(Cl)=CC=1.

# Challenge

Let's make a new acronym, FROWNS: Fraudulent, Ridiculous, Overbonded, Wacked, or Nonexistent SMILES. Basically, a SMILES string is a FROWNS string if any of the following apply:

• A loop is unclosed or closed twice.
• An atom from period 2 (Li, Be, B, C, N, O, F, Ne) has more than 4 total bonds.
• A neutral nitrogen atom has 4 total bonds.
• An oxygen atom has more than 2 difference of bonds - charge.
• A fluorine atom has anything other than exactly 1 bond.
• Noble gasses other than xenon are bonded.

Your program should determine whether a given SMILES string is a FROWNS string.

Here are some examples of FROWNS:

C1=CC=CC=C
CC(C)(C)(C)C
C1=CC=CC=C1C=CN1
C#C#C
C=N=C
CC#O
OFO
FKr(F)(F)(F)(F)F
FXeF(F)(F)


These, however, are not FROWNS:

C1=CC=CC=C1
CC(C)(C)C
C12=CC=CC=C1C=CN2
C#C
C[N-]C
CC=O
OClO
FXe(F)(F)(F)(F)F
Xe(F)(F)(F)(F)


May the shortest code win.

• SMILES is a relatively complicated format, so it might be a good idea to define your own subset of it and set it out in the question, so that people don't have to worry about whether they have to implement aromatic bonds or stereochemistry or what have you Apr 13, 2018 at 15:53
• @Nathaniel my subset called FROWNS is somewhat strictly defined, so that shouldn't be a problem. Apr 13, 2018 at 17:50
• I don't think it's well defined enough. Is F/N=N/F` a FROWNS string, for example? Technically yes, because it is a SMILES string containing an N with 4 bonds. But do you really need people to support stereochemistry for this challenge? I don't think you do, which is why I suggest you define your own subset of SMILES instead of relying on the relatively complex standard. This will also have the advantage that people won't need to understand organic chemistry to compete in the challenge. Apr 15, 2018 at 4:29