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.

To post to the Sandbox, scroll to the bottom of this page or click on the "Add Proposal" link below, and click "Answer This Question". Click "OK" when it asks if you really want to add another answer. Write your challenge just as you would when actually posting it. 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, replace the post here with a link to the challenge and delete it.

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]

Proper Kerning

Kerning is the adjustment of spacing between pairs of letters in order to obtain an aesthetic result. When kerning is applied automatically by a program (typically whatever editor you're using), it is said to be automatic. There are two types of automatic kerning. The one used in this challenge is metric kerning. With metric kerning, the amount of space between pairs of letters is dictated by the kerning tables found in the font file.

Given a TrueType font file, output the kerning values for each mapping in the kerning table for ASCII characters 48 - 122 inclusive.

Example

calibri.ttf

l="A" r="C" v="-15"
l="A" r="G" v="-15"
l="A" r="J" v="23"
l="A" r="O" v="-23"
l="A" r="Q" v="-23"
l="A" r="T" v="-160"
l="A" r="U" v="-32"
l="A" r="V" v="-89"
l="A" r="W" v="-80"
l="A" r="Y" v="-150"
l="A" r="t" v="-52"
l="A" r="v" v="-38"
l="A" r="y" v="-41"
l="A" r="?" v="-68"
l="B" r="A" v="-20"
l="B" r="T" v="-48"
l="B" r="V" v="-25"
l="B" r="W" v="-24"
l="B" r="X" v="-44"
l="B" r="Y" v="-57"
l="B" r="Z" v="-20"
l="B" r="f" v="-20"
l="B" r="t" v="-20"
l="B" r="v" v="-20"
l="B" r="x" v="-15"
l="B" r="y" v="-20"
l="C" r="G" v="-18"
l="C" r="J" v="12"
l="C" r="O" v="-18"
l="C" r="Q" v="-18"
l="C" r="T" v="10"
l="D" r="A" v="-30"
l="D" r="J" v="-22"
l="D" r="T" v="-23"
l="D" r="V" v="-24"
l="D" r="W" v="-14"
l="D" r="X" v="-31"
l="D" r="Y" v="-39"
l="D" r="Z" v="-22"
l="E" r="A" v="-22"
l="E" r="C" v="-24"
l="E" r="G" v="-24"
l="E" r="O" v="-32"
l="E" r="Q" v="-32"
l="E" r="S" v="-20"
l="E" r="Z" v="-10"
l="E" r="a" v="-34"
l="E" r="c" v="-28"
l="E" r="d" v="-30"
l="E" r="e" v="-37"
l="E" r="f" v="-64"
l="E" r="o" v="-37"
l="E" r="q" v="-30"
l="E" r="t" v="-24"
l="E" r="v" v="-48"
l="E" r="w" v="-34"
l="E" r="y" v="-48"
l="F" r="A" v="-115"
l="F" r="C" v="-18"
l="F" r="G" v="-18"
l="F" r="J" v="-109"
l="F" r="O" v="-18"
l="F" r="Q" v="-18"
l="F" r="S" v="-29"
l="F" r="X" v="-22"
l="F" r="Z" v="-11"
l="F" r="a" v="-55"
l="F" r="c" v="-28"
l="F" r="d" v="-20"
l="F" r="e" v="-30"
l="F" r="o" v="-28"
l="F" r="q" v="-20"
l="F" r="s" v="-35"
l="G" r="T" v="-10"
l="G" r="V" v="-10"
l="G" r="W" v="-9"
l="G" r="Y" v="-30"
l="G" r="v" v="-29"
l="G" r="w" v="-22"
l="G" r="x" v="-14"
l="G" r="y" v="-30"
l="J" r="A" v="-35"
l="J" r="X" v="-20"
l="K" r="C" v="-78"
l="K" r="G" v="-80"
l="K" r="O" v="-97"
l="K" r="Q" v="-97"
l="K" r="S" v="-18"
l="K" r="U" v="-29"
l="K" r="W" v="-34"
l="K" r="a" v="-34"
l="K" r="c" v="-40"
l="K" r="d" v="-33"
l="K" r="e" v="-37"
l="K" r="f" v="-25"
l="K" r="m" v="-32"
l="K" r="n" v="-32"
l="K" r="o" v="-37"
l="K" r="p" v="-32"
l="K" r="q" v="-33"
l="K" r="r" v="-32"
l="K" r="s" v="-18"
l="K" r="t" v="-38"
l="K" r="u" v="-32"
l="K" r="v" v="-101"
l="K" r="w" v="-95"
l="K" r="y" v="-85"
l="L" r="C" v="-22"
l="L" r="G" v="-47"
l="L" r="J" v="25"
l="L" r="O" v="-45"
l="L" r="Q" v="-45"
l="L" r="T" v="-150"
l="L" r="U" v="-44"
l="L" r="V" v="-147"
l="L" r="W" v="-118"
l="L" r="Y" v="-167"
l="L" r="f" v="-23"
l="L" r="t" v="-38"
l="L" r="v" v="-78"
l="L" r="w" v="-72"
l="L" r="y" v="-79"
l="O" r="A" v="-23"
l="O" r="J" v="-27"
l="O" r="T" v="-55"
l="O" r="V" v="-25"
l="O" r="W" v="-22"
l="O" r="X" v="-64"
l="O" r="Y" v="-55"
l="O" r="Z" v="-38"
l="O" r="x" v="-12"
l="O" r="z" v="-10"
l="P" r="A" v="-151"
l="P" r="J" v="-140"
l="P" r="T" v="-9"
l="P" r="V" v="-10"
l="P" r="X" v="-35"
l="P" r="Y" v="-11"
l="P" r="Z" v="-29"
l="P" r="a" v="-44"
l="P" r="c" v="-43"
l="P" r="d" v="-34"
l="P" r="e" v="-41"
l="P" r="f" v="12"
l="P" r="o" v="-41"
l="P" r="q" v="-34"
l="P" r="s" v="-32"
l="P" r="t" v="12"
l="P" r="y" v="12"
l="Q" r="J" v="41"
l="Q" r="T" v="-47"
l="Q" r="V" v="-25"
l="Q" r="W" v="-12"
l="Q" r="X" v="12"
l="Q" r="Y" v="-46"
l="Q" r="g" v="59"
l="Q" r="j" v="79"
l="Q" r="x" v="31"
l="Q" r=";" v="60"
l="Q" r="]" v="32"
l="R" r="C" v="-18"
l="R" r="G" v="-19"
l="R" r="O" v="-20"
l="R" r="Q" v="-20"
l="R" r="S" v="-27"
l="R" r="T" v="-20"
l="R" r="V" v="-28"
l="R" r="W" v="-18"
l="R" r="Y" v="-30"
l="R" r="e" v="-36"
l="R" r="o" v="-42"
l="R" r="v" v="-26"
l="R" r="w" v="-33"
l="R" r="y" v="-33"
l="S" r="A" v="-15"
l="S" r="J" v="-9"
l="S" r="T" v="-14"
l="S" r="V" v="-14"
l="S" r="W" v="-15"
l="S" r="X" v="-13"
l="S" r="Y" v="-20"
l="S" r="v" v="-23"
l="S" r="w" v="-17"
l="S" r="y" v="-25"
l="T" r="A" v="-160"
l="T" r="C" v="-42"
l="T" r="G" v="-59"
l="T" r="J" v="-65"
l="T" r="O" v="-58"
l="T" r="Q" v="-58"
l="T" r="S" v="-10"
l="T" r="T" v="28"
l="T" r="a" v="-160"
l="T" r="c" v="-177"
l="T" r="d" v="-147"
l="T" r="e" v="-182"
l="T" r="g" v="-151"
l="T" r="m" v="-127"
l="T" r="n" v="-127"
l="T" r="o" v="-182"
l="T" r="p" v="-127"
l="T" r="q" v="-147"
l="T" r="r" v="-127"
l="T" r="s" v="-153"
l="T" r="u" v="-127"
l="T" r="v" v="-92"
l="T" r="w" v="-86"
l="T" r="x" v="-90"
l="T" r="y" v="-93"
l="T" r="z" v="-142"
l="T" r=";" v="-114"
l="T" r=":" v="-134"
l="U" r="A" v="-45"
l="U" r="J" v="-40"
l="V" r="A" v="-96"
l="V" r="C" v="-18"
l="V" r="G" v="-25"
l="V" r="J" v="-80"
l="V" r="O" v="-27"
l="V" r="Q" v="-27"
l="V" r="S" v="-12"
l="V" r="V" v="9"
l="V" r="a" v="-114"
l="V" r="c" v="-103"
l="V" r="d" v="-87"
l="V" r="e" v="-102"
l="V" r="g" v="-100"
l="V" r="m" v="-50"
l="V" r="n" v="-50"
l="V" r="o" v="-86"
l="V" r="p" v="-50"
l="V" r="q" v="-87"
l="V" r="r" v="-50"
l="V" r="s" v="-90"
l="V" r="u" v="-50"
l="V" r="y" v="-35"
l="V" r="z" v="-82"
l="V" r=";" v="-108"
l="V" r=":" v="-73"
l="W" r="A" v="-93"
l="W" r="C" v="-22"
l="W" r="G" v="-22"
l="W" r="J" v="-88"
l="W" r="O" v="-22"
l="W" r="Q" v="-22"
l="W" r="S" v="-10"
l="W" r="X" v="-13"
l="W" r="a" v="-71"
l="W" r="c" v="-78"
l="W" r="d" v="-72"
l="W" r="e" v="-75"
l="W" r="g" v="-54"
l="W" r="m" v="-60"
l="W" r="n" v="-60"
l="W" r="o" v="-86"
l="W" r="p" v="-60"
l="W" r="q" v="-72"
l="W" r="r" v="-60"
l="W" r="s" v="-73"
l="W" r="u" v="-60"
l="W" r="v" v="-34"
l="W" r="y" v="-53"
l="W" r=";" v="-156"
l="X" r="C" v="-57"
l="X" r="G" v="-65"
l="X" r="O" v="-57"
l="X" r="Q" v="-57"
l="X" r="S" v="-20"
l="X" r="d" v="-44"
l="X" r="e" v="-39"
l="X" r="g" v="-9"
l="X" r="o" v="-38"
l="X" r="q" v="-44"
l="X" r="t" v="-31"
l="X" r="u" v="-38"
l="X" r="v" v="-55"
l="X" r="w" v="-49"
l="X" r="y" v="-43"
l="Y" r="A" v="-152"
l="Y" r="C" v="-67"
l="Y" r="G" v="-67"
l="Y" r="J" v="-112"
l="Y" r="O" v="-66"
l="Y" r="Q" v="-66"
l="Y" r="S" v="-17"
l="Y" r="Z" v="-10"
l="Y" r="a" v="-134"
l="Y" r="c" v="-159"
l="Y" r="d" v="-131"
l="Y" r="e" v="-147"
l="Y" r="f" v="-62"
l="Y" r="g" v="-142"
l="Y" r="i" v="-32"
l="Y" r="j" v="-49"
l="Y" r="m" v="-94"
l="Y" r="n" v="-94"
l="Y" r="o" v="-153"
l="Y" r="p" v="-94"
l="Y" r="q" v="-131"
l="Y" r="r" v="-94"
l="Y" r="s" v="-115"
l="Y" r="t" v="-44"
l="Y" r="u" v="-94"
l="Y" r="v" v="-69"
l="Y" r="w" v="-62"
l="Y" r="x" v="-70"
l="Y" r="y" v="-65"
l="Y" r="z" v="-100"
l="Y" r=";" v="-138"
l="Y" r=":" v="-154"
l="Z" r="A" v="-11"
l="Z" r="C" v="-25"
l="Z" r="G" v="-24"
l="Z" r="O" v="-24"
l="Z" r="Q" v="-24"
l="Z" r="W" v="-7"
l="Z" r="Y" v="-7"
l="Z" r="a" v="-10"
l="Z" r="c" v="-12"
l="Z" r="d" v="-18"
l="Z" r="e" v="-31"
l="Z" r="o" v="-29"
l="Z" r="q" v="-18"
l="Z" r="v" v="-45"
l="Z" r="w" v="-38"
l="Z" r="y" v="-37"
l="a" r="f" v="-12"
l="a" r="t" v="-19"
l="a" r="v" v="-34"
l="a" r="w" v="-14"
l="a" r="x" v="-19"
l="a" r="y" v="-38"
l="b" r="f" v="-17"
l="b" r="s" v="-10"
l="b" r="t" v="-9"
l="b" r="v" v="-10"
l="b" r="w" v="-10"
l="b" r="x" v="-41"
l="b" r="y" v="-10"
l="b" r="z" v="-28"
l="c" r="a" v="-17"
l="c" r="o" v="-17"
l="e" r="f" v="-18"
l="e" r="t" v="-11"
l="e" r="v" v="-10"
l="e" r="w" v="-10"
l="e" r="x" v="-31"
l="e" r="y" v="-13"
l="e" r="z" v="-20"
l="f" r="a" v="-40"
l="f" r="c" v="-45"
l="f" r="d" v="-53"
l="f" r="e" v="-51"
l="f" r="f" v="-20"
l="f" r="g" v="-60"
l="f" r="o" v="-43"
l="f" r="q" v="-53"
l="f" r="s" v="-27"
l="f" r="v" v="13"
l="f" r="w" v="6"
l="f" r="y" v="10"
l="f" r="z" v="-20"
l="g" r="a" v="-38"
l="g" r="c" v="-12"
l="g" r="d" v="-19"
l="g" r="e" v="-17"
l="g" r="g" v="19"
l="g" r="o" v="-14"
l="g" r="q" v="-19"
l="g" r="t" v="-31"
l="h" r="f" v="-12"
l="h" r="t" v="-19"
l="h" r="v" v="-34"
l="h" r="w" v="-14"
l="h" r="x" v="-19"
l="h" r="y" v="-38"
l="k" r="a" v="-35"
l="k" r="c" v="-48"
l="k" r="d" v="-56"
l="k" r="e" v="-66"
l="k" r="o" v="-69"
l="k" r="q" v="-56"
l="k" r="s" v="-19"
l="k" r="t" v="-10"
l="k" r="u" v="-26"
l="m" r="f" v="-12"
l="m" r="t" v="-19"
l="m" r="v" v="-34"
l="m" r="w" v="-14"
l="m" r="x" v="-19"
l="m" r="y" v="-38"
l="n" r="f" v="-12"
l="n" r="t" v="-19"
l="n" r="v" v="-34"
l="n" r="w" v="-14"
l="n" r="x" v="-19"
l="n" r="y" v="-38"
l="o" r="v" v="-9"
l="o" r="w" v="-8"
l="o" r="x" v="-40"
l="o" r="y" v="-11"
l="o" r="z" v="-27"
l="p" r="f" v="-17"
l="p" r="s" v="-10"
l="p" r="t" v="-9"
l="p" r="v" v="-10"
l="p" r="w" v="-10"
l="p" r="x" v="-41"
l="p" r="y" v="-10"
l="p" r="z" v="-28"
l="q" r="g" v="10"
l="r" r="a" v="-42"
l="r" r="c" v="-30"
l="r" r="d" v="-28"
l="r" r="e" v="-27"
l="r" r="g" v="-28"
l="r" r="o" v="-33"
l="r" r="q" v="-28"
l="r" r="s" v="-35"
l="r" r="v" v="19"
l="r" r="w" v="11"
l="r" r="y" v="10"
l="s" r="f" v="-19"
l="s" r="t" v="-23"
l="s" r="v" v="-31"
l="s" r="w" v="-10"
l="s" r="x" v="-22"
l="s" r="y" v="-37"
l="s" r="z" v="-18"
l="t" r="a" v="-25"
l="t" r="c" v="-25"
l="t" r="d" v="-23"
l="t" r="e" v="-22"
l="t" r="o" v="-20"
l="t" r="q" v="-23"
l="t" r="t" v="-29"
l="v" r="a" v="-30"
l="v" r="c" v="-25"
l="v" r="d" v="-20"
l="v" r="e" v="-20"
l="v" r="f" v="11"
l="v" r="g" v="-28"
l="v" r="o" v="-19"
l="v" r="q" v="-20"
l="v" r="s" v="-9"
l="v" r="t" v="10"
l="v" r="v" v="12"
l="v" r="w" v="12"
l="v" r="y" v="12"
l="v" r="z" v="-26"
l="w" r="a" v="-23"
l="w" r="c" v="-20"
l="w" r="d" v="-18"
l="w" r="e" v="-18"
l="w" r="f" v="6"
l="w" r="g" v="-18"
l="w" r="o" v="-19"
l="w" r="q" v="-18"
l="w" r="s" v="-18"
l="w" r="t" v="4"
l="w" r="v" v="12"
l="w" r="w" v="8"
l="w" r="y" v="12"
l="w" r="z" v="-17"
l="x" r="a" v="-37"
l="x" r="c" v="-46"
l="x" r="d" v="-44"
l="x" r="e" v="-54"
l="x" r="o" v="-55"
l="x" r="q" v="-44"
l="x" r="s" v="-12"
l="x" r="t" v="6"
l="x" r="u" v="-20"
l="y" r="a" v="-31"
l="y" r="c" v="-26"
l="y" r="d" v="-24"
l="y" r="e" v="-25"
l="y" r="f" v="10"
l="y" r="g" v="-26"
l="y" r="o" v="-24"
l="y" r="q" v="-24"
l="y" r="s" v="-19"
l="y" r="t" v="10"
l="y" r="v" v="12"
l="y" r="w" v="8"
l="y" r="y" v="10"
l="y" r="z" v="-17"
l="z" r="a" v="-34"
l="z" r="c" v="-45"
l="z" r="d" v="-46"
l="z" r="e" v="-46"
l="z" r="f" v="-10"
l="z" r="g" v="-17"
l="z" r="o" v="-45"
l="z" r="q" v="-46"
l="z" r="s" v="-22"
l="z" r="u" v="-10"
l="z" r="v" v="-18"
l="z" r="w" v="-22"
l="z" r="y" v="-18"


Scoring

This is , so the shortest answer (in bytes) wins.

Meta

I know this challenge is going to need a lot of work before it's ready for main. Please hold criticisms for now. Helpful ideas and thoughts are welcome.

• I'm not sure that the problem is well defined. There's a reason it's called font hinting: the rendering application is free to take it into account or not, or even to apply more complex logic. E.g. some fonts have multiple sets of font hints for different contexts. There are other complex issues. A font can have Latin and Cyrillic letters and define hints for kerning between pairs of Latin and pairs of Cyrillic but not between Latin and Cyrillic; however, some letters may have identical glyphs, so a judgement on whether the kerning is "correct" might be ambiguous. Then there's antialiasing. – Peter Taylor May 24 '17 at 6:15
• @PeterTaylor Good notes. I will likely restrict the character set. I just wanted to start getting ideas down in the sandbox. – Poke May 24 '17 at 6:51
• Very ambiguous. – anna328p May 25 '17 at 17:48
• @Mendeleev It's not done yet. I'm aware it's ambiguous. – Poke May 26 '17 at 16:10
• Looking at developer.apple.com/fonts/TrueType-Reference-Manual/RM06/… I can see a number of issues to address. 16- vs 32-bit entries? Should multiple tables be combined or printed separately? All tables or only tables with certain coverage values? Which of the four defined formats need to be supported? Do you have a test case which covers glyph index differing from codepoint? – Peter Taylor Sep 16 '17 at 17:28
• @PeterTaylor I have a proof of concept that I wrote (it's the reason I have taken so long to update this) and I'm planning to address all of your questions. Thanks for doing a bit of research to help me out, though :] – Poke Sep 16 '17 at 18:57
• Downvoter, why? – Poke Oct 4 '17 at 21:03

Six Flags over HTTP

Let's say you need to transmit six boolean flags in a URL string. Obviously you could do it with six ones or zeroes, but you want better compression. With a little math you can pack them into two characters using 0-7 octal.

How about mapping all six to a single ASCII character? Here we have a problem: you are not allowed to use , / ? : @ & = + $# or space. Now the range of printable ASCII no longer has 64 valid characters in a row. In Javascript (or another language that can run from a web page, if any), what is the shortest code for a pair of functions to encode and decode this data, between an array of six booleans and a single character? • -1 language restriction, most languages have HTTP libraries so I think any language should be allowed – ASCII-only Sep 24 '17 at 13:11 • This challenge could be improved by rephrasing it to: "Write a bijective function between an array of six booleans and a single printable character excluding the characters ,/?:@&=+$# ". Mentioning that the encoder and decoder should be separate programs/functions would be helpful. Also, may the encoder and decoder share code? – fireflame241 Sep 24 '17 at 22:08

Count letter frequency

Inspired by question Tweetable hash function challenge, you should take the English dictionary used there and produce a program or function that outputs the the absolute and relative frequency of each character. It is CASE SENSITIVE and the APOSTROPHE is also accountable as a real letter.

Example of a valid output format (but with stupid guessing values):

A      5566    20%
...
Z        60     0.2%
a     27000    30%
...
z       120     0.01%
'       450     3.5%


It is , but no answer will be accepted. Wanna know shortest script for each language.

• -1 (01) Don't rely on another challenge to define yours; include all the information we need in your write-up. (02) Make an effort to come up with some actual test cases - do you honestly expect us to verify our solutions against "stupid guessing values"? – Shaggy Sep 30 '17 at 0:55

Is it a perfect loop? test-batterydecision-problem

Your task is to take a GIF or an animated image in any reasonable format as input (including taking the file name of a GIF in the current directory), and output whether it is a "perfect loop" - that is, the frames transition seamlessly from the end to the start, and a human cannot notice where it starts and ends at first glance. Return or print a truthy value if it is a perfect loop, otherwise print or return a falsy value.

Scoring

Winners will be determined from the percentage of test cases they get correct. In the event of a tie, highest votes wins. You can view test cases at https://ghostbin.com/paste/m3yaw. Show your score against the test cases when you post.

Input

If you are not taking input in a GIF, please provide a program that will convert a GIF to your desired format.

Images corresponding to a truthy value have been taken from /r/perfectloops and for falsy test cases, /r/almostperfectloops and /r/gifs.

Restrictions

• Hard coding is not allowed (violates standard loophole 1 and 2).
• You must provide consistent results for the same GIF (no randomness)
• Remember, this is not , so byte count is not needed in your solution. Just post the language name and add the percentage correct when I comment.
• I'm not sure it's as simple as comparing the first to the last frame, if it is we'd have duplicate frames. is this challenge allowing HTTP requests? – tuskiomi Oct 17 '17 at 21:15
• If hashing the inputs is not allowed, then you should clearly define what constitutes a “perfect loop”. It's not good to extrapolate from a handful of test cases where the pass/fail cases are very similar. – japh Oct 18 '17 at 14:31

Highest code size∕output ratio to generate a large executable section inside an elf file.

Your challenge is to create the shortest code in your language of choice or the tools of your choice (like objcopy) that will create an elf file with a the executable section as large as possible.
I mean that if I extract the.text section of the elf binary, the resulting extracted file should be at least 90% of the elf binary.

Requirements

• The program should takes the desired section size as input.
• The .text section name needs to corresponds to the executable section.
• The type of the .text section should bePROGBITSand it should contains instructions.
• The elf file should have a .shstrtab section.
• The .text section should be readable and writable.
• The target architecture should be Pnacl or armelv7 or x86_64.
• The elf file should be valid and pass Google nacl’s validation whitelist in order to be loaded (but I don´t care if the sandbox segfault).
If you have no idea about what Google native client is, just create a script that call the patched version of binutils from the nacl_sdk, or make sure the elf file is valid and can be executed on Linux.

Of course, you normally can’t use a compiler because it would takes too much computational years in order to finish.

Winner

The answer with the highest code size∕program output ratio.

• Why not make scoring output size / code size? – anna328p Apr 4 '17 at 3:49
• Make it a code-challenge – anna328p Apr 4 '17 at 3:49
• This is essentially the same challenge as this one, and would be closed as a duplicate. Although it's not exactly the same, some answers to the previous question would require very little modification and answers to this question would also require very little modification to be answers to the other one. – Peter Taylor Apr 4 '17 at 8:37
• @Alt-F4 : it was a code challenge. – user2284570 Apr 4 '17 at 21:52
• @PeterTaylor : they were no answer to the previous question. In order to be closed as a duplicate the target needs to be already answered. You known it was closed an unclear, so please suggest change to make this answer clearer. – user2284570 Apr 4 '17 at 21:54
• Huh? It's open and has 15 answers. – Peter Taylor Apr 4 '17 at 22:09
• @PeterTaylor sorry, I thought to an another question that was closed as unclear and didn’t take time to read your link. In that case NO, the aim is to not use the compiler in order to actually build the file. This normally can’t be done with a compiler or an assembler. – user2284570 Apr 4 '17 at 22:16
• Can't it? Why not? – wizzwizz4 Dec 16 '17 at 19:55
• Wait... shortest code that generate any program? Or what? Don't think this is a good idea... – user202729 Jan 6 '18 at 12:10

Removing a Letter adds a Letter

Your program should output nothing when unaltered, however, when any single character is removed it should have an output length of 1. This extends to any number of characters being removed from the program, as long as there is, at minimum, a single character remaining.

For example, if my program were abcdefg, it should output nothing if unaltered.

However, if I were to remove a and d from this program to get bcefg, it should output any two printable characters that represent 16 bytes of information (2 characters for 2 characters removed).

• So if bcefg outputs (00,AA,etc...) this is valid.

Taking this further, if we were to remove all but the letter g we'd need an output of 6 characters.

• So if g outputs ('000000','@$^%@(',etc...) this is valid. Your program must function for all possible combinations of removals that are possible, that is to say each single letter in your program should be a valid program. Rules • You may "lock" pieces of the code, each locked byte counts for 2-bytes instead of 1-byte. • Locked bytes will never be removed. • For instance, if my program was abcdefg and bcd is locked, the shortest program we'll get is abcd,bcde,bcdf and bcdg. • If bcd was locked in abcdefg it'd be 10 bytes, not 7. • The program may output any byte to represent 1 removed character, N-bytes for N removed chars in the code itself. • The rule only leads to totally locked code – l4m2 Mar 13 '18 at 0:13 • @l4m2 hah. I disagree. – Magic Octopus Urn Mar 13 '18 at 0:58 • But more constructively, increase the penalty? Limit locked chars? – Magic Octopus Urn Mar 13 '18 at 1:04 • Maybe require an unlocked percent? – l4m2 Apr 6 '18 at 10:52 Sandbox: Is this question already available (duplicate)? Are things too vague? Does providing the example help or hinder? Tidy the Pantry (easy) I hate grocery shopping, particularly the part where I put groceries away--so I'm calling upon the collective hive-mind to handle that. Challenge Your challenge is to take a 1D-list of groceries and a 2D pantry as input; and output an newly assorted pantry. The two variables can be of your type choice, and in any order, but please specify what item types your program requires (e.g. string, array, etc.). Rules & Additional info. Scoring • This is code golf, so the shortest answer in bytes wins Rules • The pantry should be ordered alphabetically (A - Z, left to right, top to bottom) • For simplicity, the pantry is case-insensitive • The pantry must retain its horizontal size (but trailing newlines are optional) • "Pockets" (empty spaces) should be filled between items (i.e. only the last item is allowed to have a trailing pocket) • If the pantry is too small for the incoming groceries, then the pantry must replace older items (Z being the oldest, A the youngest) • Z from groceries is younger than A in pantry • Standard loopholes are forbidden Examples ([ and ] are used for readability) Input (4x4 pantry): [A][A][ ][ ] [ ][ ][B][ ] [C][ ][ ][ ] [ ][ ][ ][D] AAD  Output: [A][A][A][A] [B][C][D][D] [ ][ ][ ][ ] [ ][ ][ ][ ]  Input (2x2 pantry): [A][B] [C][D] XYZ  Output: [A][X] [Y][Z]  Example solution JavaScript ES6 (989 bytes) // (String, String) -> String let organise = (pantry, groceries) => { let n = pantry.split("\n").sort((a, b) => b.length - a.length); // used at the end of the function for horizontal sizing n = n[0].length; pantry = pantry .replace(/\W/g, "") // get rid of all non-alphanumeric characters .split(""); // turn the string into an array // we need the properties of the new array // so the extra pantry = pantry is needed pantry = pantry .slice(0, pantry.length - groceries.length) // go ahead and remove the last overlapping elements .concat(groceries) // add the groceries to the pantry .join("") // turn into a string .split("") // turn into an array .sort() // sort the array .join(""); // turn into a string return pantry.replace(RegExp((.{${n}}), 'g'), "\$1\n");
};

/** Testing below **/

console.log("Test #2:\n" + organise(
AJCHDJE
JJ   JA
ASD
OOQ I U
Q     W
R,

'AHJBCJHDHHATTGEH'
))

Test Cases:

Test #1, 4x4 pantry

TVCX <- pantry
ABCD
ATDJ
UAIK

XYXY <- groceries
----
AAAB <- expected output
CCDD
IJKT
XYXY


Test #2, 7x6 pantry

AJCHDJE
JJ   JA
ASD
OOQ I U
Q     W
R

AHJBCJHDHHATTGEH
-------
AAAAABC
CDDDEGH
HHHHJJT
T


Test #3, 10x10 pantry

AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA

ZZZZZZZZZZZZZZZZZZZZ
----------
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
ZZZZZZZZZZ
ZZZZZZZZZZ


Test #4, 16x16 pantry pantry

ASDFGHJKLZXCVBNM
QJKAJ  KAKSJD  J
KJASDKFHI YOIER
W   OSDOFJ    DK
E PPPASP     AS
R
TASD
YAAAAAAAAAAAA
U          JHOLK
IIAUSHODUYOAISUO
OASD  AUSODI
PIASND JUASJNOIJ
A ASJDH PPOIO
QHIAIUSOIUOOO
WYYAIUSNNAJSDASD
EAISDUUIOPJPIJPJ
ROQPEWIHRNXCAISD

QWERTYUIOP
----------------
AAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAA
ABCCDDDDDDDDDDDD
DDDEEEEEFFFGHHHH
HHHIIIIIIIIIIIII
IIIIIIJJJJJJJJJJ
JJJJJJKKKKKKKKLL
MNNNNNNOOOOOOOOO
OOOOOOOOOOPPPPPP
PPPPPPQQQQRRRRRS
SSSSSSSSSSSSSSSS
SSSTTUUUUUUUUUUU
UVWWY


Test #5, 2x2 pantry

HE
LO

[no groceries]
--
HE
LO

• why divide the program score? – RedClover Feb 26 '18 at 19:03
• I recommend you do count by bytes otherwise someone is just going to encode their entire program in Chinese characters and win. – HyperNeutrino Feb 26 '18 at 19:09
• @labela--gotoa To get a golfed score (smaller programs get a smaller score), should I change it? – Ephellon Dantzler Feb 26 '18 at 19:13
• @EphellonDantzler I don't understand why not just normal scoring...? – RedClover Feb 26 '18 at 19:14
• LOL, that's why I set in in Sandbox first @labela--gotoa – Ephellon Dantzler Feb 26 '18 at 19:16
• Some notes on your reference implementation: 1 It appears far too soon in the challenge. 2 It's not 1768 bytes. 3 You need to ungolf it and make it readable or it's not much use. 4 As it's JS, create a Snippet for it. 5 Is it necessary? It seems to be thrown in there to try to patch over any holes in the challenge spec. – Shaggy Feb 26 '18 at 23:17

Interpret pseudocode

Wikipedia says pseudocode

is intended for human reading rather than machine reading.

and

A program in pseudocode is not an executable program.

I don't care.

Make a pseudocode interpreter that can run pseudocode that fits the rules described below*. This is based on the IB pseudocode guide, but it is simplified quite a bit to make it fit for the challenge.

Pseudocode specifications

This is a simplified pseudocode to make the challenge less tedious. The pseudocode language has no strings, no arrays, no classes, no methods, and no variables other than integers.

Basic syntax

Comments that start at // and end at a newline (like java one-line comments). // is not necessarily followed by a space, and the comment may be empty. Example:

A = 2 + 3 // I can't write five because my keyboard is broken


Statements are separated by newlines. Lines may be empty (without statements). The exact number of spaces doesn't matter, and spaces are not required. The language is case sensitive.

Variables

All variables are global, and can be accessed anywhere. They do not need to be declared. To keep things simple, all variables can be assumed to be integers. All variable names are UPPERCASE, and consist only of letters. Your program should at least handle integers from -256 to 256. A wider range is not a requirement.

Variables are assigned values using this syntax:

VARIABLE = Expression


Where VARIABLE can be any uppercase name and expression can be any integer expression, as discussed below.

Examples:

A = 5
B = A + 3
NUMBER = A * B


Expressions

An expression can be:

• An integer, like 42
• A variable, like NUMBER
• A binary operation on two other expressions, like NUMBER + 5. There are only four operations: +, -, *, /. Division rounds integers down.

Expressions can be surrounded by parentheses to indicate that they need to be evaluated first. To keep things simple, all expressions are evaluated from left to right no matter what the operations are (unless there are parentheses that specify otherwise), so

A = 2 - RM * 9 + 3 / NUMBER
B = 1 + 2 * (3 - 4) / 6


is equivalent to

A = (((2 - RM) * 9) + 3) / NUMBER
B = ((1 + 2) * (3 - 4)) / 6


Boolean expressions

Boolean expressions can compare two expressions using == (equality), != (not equal to), < (less than), and > (greater than). They are only used for control flow, as discussed below (there are no boolean variables).

Control flow

There are four types of control flow. They can be infinitely nested in all combinations.

If

if (booleanExpression) then
// statements (discussed below)
endif


If-else

if (booleanExpression) then
// statements (discussed below)
else
// other statements
endif


Loop while

loop while (booleanExpression)
// do stuff
endloop


Where booleanExpressions are boolean expressions. The ifs work the same as in normal programming languages. The while loop is a simple while loop.

The booleanExpressions will always be surrounded by (). The pseudocode is very flexible with spaces, and any number of spaces is valid.

Loop for

loop VARIABLE from Expression1 to Expression2
// things to do over and over again
end loop


Where Expression1 and Expression2 are expressions that are evaluated before the loop begins and their values are stored until the loop finishes. The content of the loop is executed for every integer from the result of Expression1 to that of Expression1, inclusive. At every iteration, the index variable (VARIABLE in this case) is updated.

Example:

loop I from 3 to 5
output(I)
endloop


Outputs:

3
4
5


Statements

Output

output(Expression) outputs the evaluated expression. It's like println in programming languages. So:

output(1+1)


prints 2, followed by a newline.

output() with no arguments should print a newline.

Other statements

If the interpreter encounters any other statement that looks like a method call with no arguments, it should pretend it's executing it. For example,

lightsoff()
gohome()


should print (together with a newline):

executing lightsoff
executing gohome


In other words, executing [Method name] should be printed. All statements will be lowercase and will consist entirely of letters.

Keywords cannot be statements. You do not have to deal with the following (it will not appear in the pseudocode): - if() - endif() - loop() - while() - etc.

However, statements that start with keywords are valid. For example, loophole() should print executing loophole, even though loop() itself is not valid.

Challenge rules

• Your program should take a string as input. It can also take something equivalent, like an array of characters. But you can't take an array of strings; your program must itself separate the lines and tokens. You can also take a file as input.
• Your program should print the output of the pseudocode in any reasonable form.
• No standard loopholes.
• There are no restrictions on what your program should do when given invalid pseudocode.
• This is code golf. The shortest code in bytes wins.

1

A = 3
output(A) // prints 3
B = 4 + A * 2
output(B)
helloworld()
output(A + B + 1 * 3)


Should give:

3
14
executing helloworld
54


2

loop NUM from 2 to 20 // cycle through possible prime numbers
COUNT = 0
loop DIV from 2 to NUM // cycle through possible divisors
if(NUM/DIV*DIV == NUM) then // if the number is exactly divisible
COUNT = COUNT + 1
endif
endloop
if (COUNT == 2) then // if number is prime
output(NUM)
endif
endloop


Should give:

2
3
5
7
11
13
17
19


3

Tricky cases that your interpreter should handle:

// empty comment:
//
// empty line:

// more comment testing // ///
////

if     (3<4) then
endoftheworld() // a statement
ifff()
endifnot()
// endif in a comment doesn't count
endif
// loops can be empty:
loop I from 0 to 10
endloop
output(I) // variables are global
if(1<2)
if(3<4) // nesting is ok
ok()
endif
endif
// spacing doesn't matter:
output   (2+   8   - 1   )
loop             while(2<1)
neverhappened()
endloop


Should output:

executing endoftheworld
executing ifff
executing endifnot
10
excecuting ok
9


*Technically, once pseudocode follows rules as strict as those described here, it is arguably not pseudocode anymore. Wikipedia says it's called skeleton code.

Any suggestions?

I double-checked all the specifications, but if anything seems reasonably unclear, please let me know.

• Actually that's because the challenge is uninteresting. – Xwtek May 3 '18 at 2:11
• @Akangka thanks for the feedback. How do you think it could be made more interesting? – Reinis Mazeiks May 3 '18 at 16:47
• Unfortunately, there is nothing to improve. You have to find other challenge. Also, it is not pseudo-code. – Xwtek May 4 '18 at 3:03
• @Ok, thanks. I'll try to think of something. Also, read the *note. :) – Reinis Mazeiks May 5 '18 at 19:39

Common Logic Gates

Given positive integer n, make a common n-to-1 gate with fewest input, i.e. make a function f: {0,1}k ↦ {0,1} with smallest k that, for each function g: {0,1}n ↦ {0,1}, there exists {ak}, such that each element ai in the sequence map to one of 0, 1, x1, x2, x3, ..., xn, satisfying that, for each {xn}, g(x1, x2, x3, ..., xn) = f(a1, a2, a3, ..., an).

Samples:

To make a common 1-to-1 gate, your circuit must take at least 2 input:

f(A,B) = A XOR B


For a buffer gate (g = x1 ↦ x1), let A=0 and B=Input (a1 = 0, a2 = x1); for a not gate (g = x1 ↦ ¬x1) , let A=1 and B=Input (a1 = 1, a2 = x1).

Alternatively, you can use f(A,B) = A AND NOT B. For a buffer gate, let B=0 and A=Input; for a not gate, let A=1 and B=Input.

To make a common 2-to-1 gate, the circuit must take at least 4 input bits: (The two inputs are represented as a and b)

f(A,B,C,D) = ((A AND B) OR (C AND NOT B)) XOR D

(ab)
00 01 10 11 A B C D
0  0  0  1  a b 0 0
0  0  1  0  0 b a 0
0  1  1  0  a a a b
0  1  1  1  1 b a 0
1  0  0  0  1 b a 1
1  0  0  1  0 a 1 b
1  1  0  1  0 b a 1
1  1  1  0  a b 0 1


Output can be an boolean expression with reasonable logic gates, or just the output corresponding to all possible input of the n-to-1 function f (the truth table of f). If there are more than one possible functions, you can output any of them.

Shortest code in bytes win.

Code that matches the requirement:

function solve(n) { // n positive int
var res = [], tmp=[], inmap=[], need=[];
for (var i=1; ; i++) {
for (var _res=0; _res<2**(2**i); _res++) {
var valid = 1;
for (var j=0; j<2**i; j++)
tmp[j] = Math.floor(_res/2**j)%2;
for (var _need=0; _need<2**(2**n); _need++) {
for (var j=0; j<2**n; j++)
need[j] = Math.floor(_need/2**j)%2;
var valid2 = 0;
for (var _inmap=0; _inmap<(n+2)**i; _inmap++) {
var valid3 = 1;
for (var j=0; j<i; j++)
inmap[j] = Math.floor(_inmap/(n+2)**j)%(n+2) - 1;
for (var j=0; j<2**n; j++) {
var bits = 0;
for (var k=0; k<i; k++) {
if (inmap[k]==-1 || (inmap[k] && (j>>(inmap[k]-1))%2))
bits |= 1 << k;
}
if (tmp[bits] != need[j])
valid3 = 0;
}
valid2 |= valid3;
}
if (!valid2) valid = 0;
}
if (valid)
res.push (tmp.slice());
}
if (res.length)
return res[AnyNonNegativeIntegerLessThan(res.length)];
// binary index input
}
}

function AnyNonNegativeIntegerLessThan(x) { if(R>=x) throw ("end"); return R;}
for (R=0; ; R++) { console.log (solve(1)); }

• You don't define what an n-to-1 gate is anywhere in your question. – Wheat Wizard Mar 27 '18 at 1:00
• @user202729 @user56656 n-to-1 gate means a gate with n input and 1 output. common n-to-1 logic gate mean a logic gate that can be used to replace any n-to-1 gate with some proper wiring. You can treat a logic gate as a ROM(so you can decide for each input what the output is) – l4m2 Mar 27 '18 at 1:15
• Output gates or ROM – l4m2 Mar 27 '18 at 1:25
• You should put the definitions in the challenge. "that can be used to replace any n-to-1 gate with some proper wiring" is still not very clear, you should define more carefully what you mean by proper wiring. – Wheat Wizard Mar 27 '18 at 3:22
• I assume you mean functions g: {0,1}^n -> {0,1}, right? Why do you specify x_0 and x_-1? Shouldn't x just be a vector with indices 1,2,3,...,n? – flawr Mar 27 '18 at 14:07
• Is {a_k} just a subset of {1,2,3,...,n}? Or can we have a_1=a_2=a_3=1 for example? – flawr Mar 27 '18 at 14:09
• {a_k} seems not a multiset. It should be an array or say a sequence of numbers – l4m2 Mar 27 '18 at 14:43
• So you're asking for something which outputs answers to codegolf.stackexchange.com/q/24983/194 ? – Peter Taylor Mar 28 '18 at 11:33
• @PeterTaylor No. it requires to use NAND gate to make up one circult that do the thing. Also 24983 is a 1-of-4 (74LS153), not a 4-to-1 gate common 2-to-1 – l4m2 Mar 28 '18 at 12:41
• (+) Any reason for downvoting? Downvoting in the sandbox indicates that the challenge is incomplete, if you don't leave a comment the OP can't know what is wrong. – user202729 Mar 29 '18 at 4:48
• @user202729, there are already comments indicating that this question is going to attract close votes as unclear if it's posted to main in the current state. – Peter Taylor Mar 29 '18 at 10:59
• @user56656 Are the issues fixed now? – user202729 Mar 31 '18 at 15:16
• @flawr Are the issues fixed now? – user202729 Mar 31 '18 at 15:16
• No I still think the explanation is quite bad and the notation is not very clear – flawr Mar 31 '18 at 16:15
• A reference implementation is no substitute for a clear specification. The first paragraph is where you need to focus your efforts. – Peter Taylor Mar 31 '18 at 19:32

Is the program 32 or 64 bits?

Assignment is simple to explain: write the shortest code you need to determine whether an executable binary program supplied as parameter is 32 or 64 bits.

If there is a different kind of bitness, you can also do for it, but is not mandatory.

What I really don't want is telling me you support other bitnesses and after I get 32 or 64 as a result.

Valid outputs for 32:

32
32bit
32bits
32 bit
32 bits


The same pattern for 64.

No accepted answer.

• I think you're missing a word somewhere in the region of "determine supplied" – Kamil Drakari Apr 4 '18 at 19:43
• @KamilDrakari thanks. – sergiol Apr 4 '18 at 19:53
• Executable on Windows or Linux machine? What if (... maybe ...) the program is a valid executable for both "bitness" but do different things? – user202729 Apr 5 '18 at 1:30
• Of the output formats you allow, I think the first one will result in the shortest code in every single language. Because of this, you might as well just specify that the output should be the number 32 or the number 64. – Nathaniel Apr 5 '18 at 8:03
• This made me wonder what to do about shell scripts, which are executable programs, but require another file to interpret them and as such aren't 32-bit or 64-bit per se. Maybe it would be best to specify "executable binary file" to not have to deal with that mess. – Angs Apr 5 '18 at 11:22
• @Angs: Thanks. Changed. – sergiol Apr 5 '18 at 11:27
• @user202729: I don't care. Windows, Linux, Mac, whatever, ... – sergiol Apr 5 '18 at 11:28
• @Nathaniel: It is intentional. If you have a language feature called bitness(program) returning 32bits you do not need to waste more bytes removing the bits part! – sergiol Apr 5 '18 at 11:30
• The word "challenge" is not really true, at least for ELF. It's absolutely trivial. – Peter Taylor Apr 6 '18 at 20:20
• @PeterTaylor : Changed, thanks. – sergiol Apr 6 '18 at 21:20
• The real "challenge" is to know the executable file format, so this becomes more of a puzzle than a challenge. And for puzzles, people can just copy others' solution and port to other languages. // Consider having some popular file format in the challenge itself so people don't have to look up them? – user202729 Apr 7 '18 at 11:19
• @user202729: My initial idea was to ask only for Windows .exe files but I changed my mind because it was too limiting. Without such restrictions the question becomes multi-platform. – sergiol Apr 7 '18 at 11:38

The challenge

• Write a Discord bot with a single command, !oldest, that gives the oldest user in the server that the command that was run in.

• Gracefully failing in DM channels is not required.

• Assume the bot's token is this invalid token: MjM4NDk0NzU2NTIxMzc3Nzky.CunGFQ.wUILz7z6HoJzVeq6pyHPmVgQgV4.
If the token is compressed in the program, provide instructions on how to change it so I can test it.

Sample discord.py implementation

import discord
client = discord.Client()
@client.event
async def on_message(M):
if(M.content=="!oldest"):
N=sorted([x.id for x in M.server.members])[1]
await client.send_message(M.channel, str(M.server.get_member(N)))
client.run("MjM4NDk0NzU2NTIxMzc3Nzky.CunGFQ.wUILz7z6HoJzVeq6pyHPmVgQgV4")

1. Get a list of every user in the server
2. Sort their snowflake IDs
3. Print the username and discriminator of the member with the smallest ID.

No API for your language? Have fun.

Standard loopholes forbidden, etc, etc.

Shortest code in bytes wins.

Sandbox

I originally posted this question on the main site, but I deleted it, as it turns out I'm bad at writing these. Please forgive me.

• I'm sure I've seen this already, but with comments saying that it needed a lot more information to be self-contained. It still needs a lot more information to be self-contained. – Peter Taylor May 5 '18 at 11:11
• Yep. I've edited the question to clarify. – SIGSTACKFAULT May 5 '18 at 12:35
• Are you talking about discord servers? Other than form the example this is not clear at all. What is a DM channel? What is a token in this context? – flawr May 5 '18 at 13:02
• A: Clarify that you're talking about Discord B: When you make a challenge that requires a library does that mean I can use a library that conveniently has the command you're asking of? – IQuick 143 May 6 '18 at 2:12

Divide two strings

One day, I saw the challenge to multiply two strings and I thought I might be able to do one better.

That challenge was fake. It was elementwise maximum. It was not real multiplication. So I set out to make something real. Real division between two strings.

I quickly realized that this would make an amazing challenge, as the algorithm was surprisingly complex and interesting to implement.

I then realized that it was actually easily reduced into a mere few operations. I'm still doing the challenge, though.

Enough with the backstory. Let's go.

Method

To divide two strings, do the following, where x is the first string and y the second:

• If x does not contain y, return a space and a period concatenated to x.
• For example, testx and blah would become .textx, with a space at the beginning.
• Otherwise, return every occurrence of y in x, a period, then y divided by x with every occurrence of y removed, with all the periods removed.
• For example, eestestst and est would become estest.est.

Challenge

Write a program or function that, given two strings via standard input, returns the first string divided by the second.

You may assume that neither input string contains a space, newline or period, and that the operation does not require more than 10 layers of recursion.

Test cases

test, es => es. es
test, blah =>  .test
okayye, y => yy. y
testes, es => eses. es
battat, at => atat. at
see, es =>  .see
see, e => ee. e
same, same => same.
aabb, ab => ab.ab
eestestst, est => estest.est
aheahahe, aheah => aheah.aheah ah


Scoring

As this is , the submission with the least amount of bytes wins.

Sandbox questions

• Is this a duplicate?
• Have I missed anything?
• Does anything need further explaining?
• Is there an issue with the concept of the challenge?
• What for aabb / ab? – l4m2 Jun 1 '18 at 12:42
• okayye, y => yy. okay typo? – l4m2 Jun 1 '18 at 12:42
• The test case battat, at => atat. by seems like it should be battat, at => atat. bt instead. – Kamil Drakari Jun 1 '18 at 13:47
• It seems odd to me that when no characters are matched the output format is {matched characters (empty)}<space>.{unmatched characters} while the format when there are matches becomes {matched characters}.<space>{unmatched characters}. I would much rather see consistent ordering of the . and <space> – Kamil Drakari Jun 1 '18 at 13:50
• @KamilDrakari 2 / 4 is 0.5, not .05, when 4 is not contained within 2 at all. Thus it makes no sense for test / blah to be . test when blah is not contained within test. We treat a space essentially like a zero would be with normal numbers. – LyricLy Jun 1 '18 at 22:15
• @LyricLy 6/4 is 1.5 not 1.05. If you're treating space as 0 then there shouldn't be any space after the dot in any of the test cases. – Kamil Drakari Jun 1 '18 at 22:58
• @KamilDrakari Actually, you're right. I was entirely mistaken because you get a fraction from 1 / remainder, not original number / remainder. Meaning this entire thing is wrong and I need to figure out a good replacement for 1 in string form. – LyricLy Jun 2 '18 at 3:32
• Fixed the issues. – LyricLy Jun 2 '18 at 3:50
• I accept downvotes, but I'd appreciate suggestions on how to improve the idea, or at least an explanation of what's wrong with it, so I know why I shouldn't post it. – LyricLy Jun 2 '18 at 8:18

Introduction

I recently came across an oral exam where the candidates were asked to find a logical circuit than can negate 3 inputs A,B,C using only two NOT gates.

The question also specified that such a circuit is unique up to removal of useless gates and reordering inputs/outputs. The candidates were asked to prove this assertion by writing a piece of code that generates all such circuits.

Challenge

No inputs whatsoever are given.

The program must output all logical circuits using unlimited AND and OR gates but only two NOT gates which take in three inputs which map to three outputs. The outputs should be the negation of each input.

The outputted circuits should not have any redundant/trivial gates (gates that always output the same thing) or unused gates (whose output doesn't influence the outcome).

The program should use as little precalculated data as possible.

Output format is left up to the coders.

The winner will be determined by overall simplicity -- low run time and code elegance. It is not an objective criterion.

Example Input and Output

Input:

N/A

Output:

R    = (A & B) | (A & C) | (B & C)
notR = !R
S    = (notR & (A | B | C)) | (A & B & C)
notS = !S

notA = (notR & notS) | (notR & S & (B | C)) | (R & notS & (B & C))
notB = (notR & notS) | (notR & S & (A | C)) | (R & notS & (A & C))
notC = (notR & notS) | (notR & S & (A | B)) | (R & notS & (A & B))

• Example output and proof of existence are provided here – John Do Jun 17 '18 at 9:22
• "It is not an objective criterion." Then it is not an on-topic question. – Peter Taylor Jun 19 '18 at 8:49

Two functions with same input/output, with largest difference in bytes.

This challenge is a terrible idea. Don't try submitting it or anything similar!

Provide two functions with the largest difference in bytes. (These two functions will be referred to in bold italics to distinguish them from built-in functions available in your language in the rules below.)

Rules:

1. Both functions must take an input and must produce an output. The input to and output from both functions must be identical.

2. Both functions must be explicitly named. The function names must have the same byte count.

3. You may not define any other functions.

4. If you use a built-in function your language provides, it must be used with the same number of parameters in each of the functions.

5. You may use string/numeric literals or any built-in constants, but you must use exactly the same ones in both functions.

6. You can define variables, must you must use the same variable names in both functions.

7. You can use comments, no-ops, and the equivalent, but they must be the same in both functions.

8. Both functions must contain the same amount of whitespace (or equivalently, don't count whitespace at all.)

9. You can import libraries/packages and the equivalent, as long as you import the same ones for both functions.

10. You can use pre-processor directives as long as they are the same for both functions.

If any of these rules mean your language cannot compete, so be it.

Not really sure how to tag this. A little bit of and .

• I don't think this is a good idea. {Main downvote} – user202729 Jul 12 '18 at 16:26
• Give up. E.g. in APL, ⊢ and ⊢⊢⊢⊢⊢⊢⊢⊢⊢ do the same. – Adám Jul 12 '18 at 16:26
• @Adám, with those rules, it'd be something like f←⊢ and g←⊢(⊢(⊢(⊢(...)))) due to rules #2 and #3. The same thing still applies to OP: give up! – Zacharý Jul 12 '18 at 16:36
• Thank you. I am happy to give up! – ngm Jul 12 '18 at 16:56
• @Zacharý I intended them to be dyadic, but whatever… – Adám Jul 12 '18 at 17:18
• "Both functions must take an input", which I assume would restrict the functions to monadic. – Zacharý Jul 12 '18 at 17:39

Quiet QR

Your mission, should you choose to accept it is to infiltrate the top secret HQ of the Big Bad Evil Guy (TM) and extract information on their latest evil scheme saved in the file Plan.txt.

The target PC is isolated from any and all network connections, and you can't physically connect anything to it. The server room is equipped with sound sensors that will detect key presses.

Your tools are restricted to a mobile phone equipped with a QR code reader. Your recommended course of action is to write a code on the target machine that will display the file content as QR code.

You are to complete the mission with the least number of keystrokes as to minimise the sound generated by the mechanical keyboard.
It is advisable not to use languages that require unicode characters as entering one character will require multiple key presses (Eg:þ = Alt+0254) is considered 5 keystrokes.

You are to assume that the machine will have its terminal open and ready for input at the root directory of the system (C:\> or /).

All programming languages can be accessed directly from root folder. The target file is on the root folder.

Javascript is available as command line executable named js usable as (js filename) and prints output.

Image viewer is called view and usable as (view imagefile) [Extension is not needed]

Possible ways of output:

1. An image containing the QR code

2. ASCII art depicting the QR code using characters like █ ▄▀

3. Or any form readable by any standard-issue QR code reader

4. Other formats of 2D barcodes are accepted on the condition of being readable by a standard reader.

Example Solution for batch file:

copy con a.bat
open file Plan.txt
echo █ ▄▀
^Z
a


=59 keystrokes.

The symbols are 4 keystrokes each:

• ▀ Alt+991

• █ Alt+987

• ▄ Alt+988

^Z as Ctrl+z and is considered 2 ketstrokes (F6 is considered one).
New lines and spaces are one keystroke each.
Capital letters are 2 strokes (Shift+c).
CAPITAL words are one keystroke added to the length of the word (Shift+capital).
No need to clean the screen at the end because the evidence will be erased by a Micro-EMP device that will disable the machine.

• Why not just have a question to turn text into a QR code? The keystroke golfing just seems to complicate things – Jo King Jul 18 '18 at 11:54
• @JoKing The premise of the challenge is to extract information from a pc with the least keystrokes. – workoverflow Jul 22 '18 at 9:06
• In that case, what operating system is the PC? What type of QR code do you want (alphanumeric or byte?)? Can you add a link or explain an algorithm to generate you type of QR code (questions should be self-contained)? How big can the input be (100 bytes? 1kb?), and what characters can it contain? – Jo King Jul 22 '18 at 9:15
• You may assume that the PC have an open terminal window ready for input in whatever OS you'd want (Bash, PowerShell, Command prompt,.....) The QR code must be able to encode alphanumeric+punctuation text in the file Plan.txt – workoverflow Jul 24 '18 at 10:29

Projective related points

Points A, B, C, D and A′, B′, C′, D′ are related by a projective transformation if their cross ratios are equal.

Given A, B, C, D four ordered points on a line, their cross ratio is defined as:

$\displaystyle\frac{distance(A,C)\times distance(B,D)}{distance(A,D)\times distance(B,C)}$,

where $distance(A,C)$ is the Euclidean distance between points A and C.

Challenge

Given a set of eight points, say if yes or no the set can be splited into two subgroups (each subgroup with four points) where the two subgroups are related by a projective transformation.

Input

A set of 8 points, each point defined by its Cartesian coordinates (integer coordinates).

Output

Either a specific true output (true, 1, yes, ...) or a specific false output (false, 0, no, ...).

Example

{(10,100),(25,100),(2,63),(2,33),(31,100),(2,13),(2,3),(17,100)} --> true
with subgroups:
{(10,100),(25,100),(31,100),(17,100)}
and
{(2,63),(2,33),(2,13),(2,3)}

{(45,54),(8,23),(8,8),(8,29),(27,30),(15,14),(9,6),(8,15)} --> true
with subgroups:
{(8,23),(8,8),(8,29),(8,15)}
and
{(45,54),(27,30),(15,14),(9,6)}


Hint (no need to use division or square root)

In order to avoid floating points, you can use the fact that points A, B, C, D and A′, B′, C′, D′ are related by a projective transformation implies:

$distance^2(A,C)\times distance^2(B,D)\times distance^2(A',D')\times distance^2(B',C')$

equals

$distance^2(A',C')\times distance^2(B',D')\times distance^2(A,D)\times distance^2(B,C)$

Rules

• The input and output can be given in any convenient format.
• No need to output the two subgroups.
• No need to handle the case when at least two points in the set are the same.
• No need to check the fact that the four points in each subgroup are aligned.
• In your submission, please state the true and the false values.
• Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
• If possible, please include a link to an on-line testing environment so other people can try out your code!
• Standard loopholes are forbidden.
• This is so all usual golfing rules apply, and the shortest code (in bytes) wins.
• As with most problems involving floating point comparisons, I think you should include a large-ish number of test cases and require that submissions pass all of those cases. That way people can be sure their submissions are sufficiently accurate. – FryAmTheEggman Jul 13 '18 at 20:40
• @FryAmTheEggman In fact there is a way to work only with integers, I'll add a hint. – mdahmoune Jul 16 '18 at 10:53
• I had totally missed that the input would always be integers. Cary on, but I still recommend including at least several test cases to make users more able to be sure their submission works without having to find edge cases on their own. – FryAmTheEggman Jul 16 '18 at 14:35
• @FryAmTheEggman Ok I'll add more examples. – mdahmoune Jul 16 '18 at 15:55
• Is the cross ratio $\overline{AC}\times\frac{\overline{BD}}{\overline{AD}}\times\overline{BC}$ or $\frac{\overline{AC}\times\overline{BD}}{\overline{AD}\times\overline{BC}}$? – wastl Jul 18 '18 at 11:31
• @wastl it's the second one, thanks for the remark, I just updated the formula. – mdahmoune Jul 18 '18 at 11:39

A function to traverse an array and re-generate the same array

We take an array, then write a function that will traverse the array and generate the array in a format given in the example below.

For example, given the array:

Array

(

[0] => Array
( [name] => Tom
[age] => 32
[key] => Array
( [0] => abc
[1] => def
[2] => efg
)
)
[1] => Array
( [name] => Jim
[age] => 30
[key] => Array
( [0] => abc
[1] => def
[2] => efg
)
[address] => Array
( [0] => Array
( [state] => CA
[country] => US
)
[1] => Array
( [state] => NY
[country] => US
)
)
)
)


Output should be:

User: 0
name: Tom
age: 32
key:
0: abc
1: def
2: efg
User: 1
name: Jim
age: 30
key:
0: abc
1: def
2: efg
address:
0:
state: CA
country: US
1:
state: NY
country: US


Challenge rules:

• You can assume array can be multidimensional
• The array can also be array of cars, schools, districts etc.
• The preferred output is in json format
• Indentation for the output is a simple json format

code-golf

The function will be tested with any sort of multidimensional arrays for speed of execution

• Can you give a quick explanation of how you generated the array? For example, where does Name come from, and what are the rules behind indentation? – Jo King Aug 9 '18 at 6:17
• The array just contains User details which will include the Name, Age, Address etc. – Mochesane Aug 9 '18 at 6:45
• Hi! Welcome to PPCG. We usually require challenges to be a bit more precisely defined, to avoid ambiguity. For eg., you mention " generate the array in a format given in the example below", and the rules say "the preferred output is in json format" - but the format in the example is not JSON (and has some possible issues, for eg. address not being indented). Also, the post says "array" throughout, but what you're actually working with looks like a nested hashmap/dictionary structure. – sundar - Reinstate Monica Aug 12 '18 at 11:46
• Finally, you've mentioned code-golf, but also that the answers will be tested for speed of execution - do you intend code-golf (number of bytes) to be the primary winning criterion and the speed of execution the tie-breaker? Or do you mean all answers have to transform a particular large input within a certain time (say 1 minute) to be valid? In the latter case, it would be useful to specify what the large, multidimensional input will be, and what the maximum time of execution allowed is. – sundar - Reinstate Monica Aug 12 '18 at 11:46

Pyramid of Bots

In this game, your bot is trying to get as high off the ground as possible. However, it can only stand on top of other bots, which are trying to get higher, too!

Overview

Your bot should be a Javascript function. It's return value should tell the program if the bot should move left, move right, or jump. Every bot starts out on a 2 dimensional grid, with a width and height set by (botCount * 2) + 1. Bots are placed on either side of the center space, and every other bot is spaced 1 apart from any other bot. They all start at y=0, and far left is x=0.

Gravity

If there is no bot on top of your bot, it can return the value jump. When a bot jumps, it moves 1 square up. If at any point in time there is nothing under the bot, it moves down 1. A bot cannot return jump if nothing is under it. If your bot is on top of another bot which moves left, your bot will fall.

Function params

Your function has 3 parameters: dirs, height, and map. The array dirs contains four boolean values, representing if there is a bot or arena border: below, to left, to right, above. The parameter height is an array with 2 elements: your height, current winner's height. The map array contains the height/width of the array, and then the amount of turns left in the game.

Running the game

In one game, the bot function will be run 800 times. Each of these is a turn. Your bot should return jump, or a direction. The bot can only move in a direction if there is no bot currently there. The two directions are left and right. Standard loopholes are not allowed (when are they ever allowed??), and the bot who wins the most out of 1000 games is the winner.

• I don't see the strategy in this. There's no way for a bot to reliably move up. No bot will stand still, so you literally have to guess whether or not an adjacent bot will move under you, and then hope that they move up while other adjacent bots move under. – Nathan Merrill Aug 27 '18 at 16:21

My Ribosomes Got a Firmware Upgrade

So all of the Apple iBosomes in my body have been updated to RibOS 4.0 now… while I appreciate the additional optimizations that were added, unfortunately for me they've dropped support for the legacy mRNA API.

So since my RNA Polymerase library still needs to return strings in the format AUUCGGUCAAAGU for the code still using it, I'll need to add some code to the getBasePairs() method to translate it from the new API.

Challenge

• Your input will be a string in base64 (because codons are exactly 6 bits) representing the genome.
• You should output a string with the equivalent RNA base pair sequence:
• 00 becomes A.
• 01 becomes G.
• 10 becomes C.
• 11 becomes U.
• All languages are allowed.
• Your I/O must be in these exact string formats, even if they're small enough to encode as integers.
• The shortest answer in bytes wins.
• Are you asking for a method that does a base64 to base4 conversion and pretty-prints the result? – Jonathan Frech Sep 18 '18 at 21:15
• @JonathanFrech Kinda, I guess. – Nissa Sep 18 '18 at 21:17
• So using lax I/O I can take the input as an integer and output four unique values like this? – Jonathan Frech Sep 18 '18 at 21:21
• @JonathanFrech wasn't what I had in mind; I'll edit the proposal once I finish the essay I'm working on right now. – Nissa Sep 18 '18 at 21:26

Trilateration

Intro:

Similar to Trilaterate your position with a small twist.

In a n x m array,

Original Problem:

You will be given a list of (x,y,d) as input, where d is the distance of your position from the point (x,y). Using this we can find our position.

................

In the above problem, d is the exact distance from the respective point.

In this problem, due to some error, we know that the distance is actually the maximum distance from the respective point. Because of that, instead of a single point, we will get a small area of our position. Objective is to get that area.

It should be in the format(a function):

f(list,n,m):
#your code here
return #list of all indices where you may be.


What's returning should be a list of points (x,y) with 0<=x<=n,0<=y<=m.

In case there is no solution return an empty list. The winner will be the fastest code. In case of a tie shorter code wins. The time taken will most likely depend on n,m and list of points.

• On which test(s) will the code be measured? – user202729 Sep 26 '18 at 15:14
• Edited it.. Also, what are the tags I should add other then fastest-algorithm – Vedant Kandoi Sep 27 '18 at 10:54

The goal of this challenge is to make an interpreted language that can print anything! The format of the language needs to be

[command eg: print] [args];


You have to use regex, even though it is not the typical way to write a language, to avoid people finding loopholes. Your interpreter also needs to ask for a file to open to interpret; example input file prompt:"File to interpret: "

Some tests to try:

print Hello World;

print This is a very very very very very long test;

ktrgjkfgjk;

print hi


If your interpreter runs these tests correctly, you can submit your interpreter.

Notes:

Do not just cut off the print!

If the command given does not exist, or if semicolon not present, print "Error"

This is so the lowest byte count + working code wins!

• I recommend some more explanation of the "File: " part – trichoplax Oct 7 '18 at 19:06
• @trichoplax Thats the input file prompt – Menotdan Oct 7 '18 at 19:09
• @trichoplax, well then i wont accept those answers, hold on let me edit – Menotdan Oct 7 '18 at 19:11
• Read it again: it says: The format of the language needs to be [command eg: print] [args]; <--- note semicolon It was just a typo (I didnt type the ;) – Menotdan Oct 7 '18 at 19:14
• The problem with saying "do not just cut off the print" is that there may be other ways of achieving the same thing, then the challenge just becomes a long list of things which are banned. You can avoid this by trying to set the requirements and inputs in a way that doesn't have these loopholes. – trichoplax Oct 7 '18 at 19:16
• @trichoplax Ok i only want the print though – Menotdan Oct 7 '18 at 19:20
• Writing challenges can be tricky, and people have posted advice on meta that can help: things to avoid when writing challenges and things to consider when creating a challenge – trichoplax Oct 7 '18 at 19:21
• If you only want print, then is there a difference between this challenge and "remove the first 6 characters and the last character from this string"? If you don't want people to solve it that way, you could consider what they need to do when the input is not a valid print command, and specify that in that case it should do something different (like not output anything). – trichoplax Oct 7 '18 at 19:24
• @trichoplax Yes, i didnt think of that – Menotdan Oct 7 '18 at 19:25
• "do not just cut off the print" is an example of a non-observable requirement. Here's a good explanation of why that can be a problem – trichoplax Oct 7 '18 at 19:26
• Here, new update – Menotdan Oct 7 '18 at 19:31
• I hope all the comments don't put you off - writing challenges is difficult, but we get much more answers than challenges so more challenges are needed. I had lots of useful feedback from this community when I started out. – trichoplax Oct 7 '18 at 19:32
• Is this better @trichoplax and where else can i improve – Menotdan Oct 7 '18 at 19:36
• – Menotdan Oct 7 '18 at 19:37
• you have to use regex ... , to avoid people finding loopholes This seems very arbitrairly restricting. What about languages without regexes? You haven't actually said what the outputs of the test are. And what exactly is the program meant to have as input? I recommend a string input instead of messing around with files – Jo King Oct 8 '18 at 12:35

Cops:

The cops must design a programming language that takes in the contents of the program from a default I/O method, and do something.

Rules:

• The program must not print anything to STDERR
• The program must be able to output to STDOUT with certain program contents of your choice
• The program must be able to calculate any function up to $$\f_{\omega}(n)\$$ where f is the fast-growing hierarchy. In other words, it needs to be able to evaluate any primitive-recursive statement.
• There cannot be a way to execute commands in other languages (for example, if there is a command in your programming language that can execute Python code based on the argument, that would be cheating)

Since there are tons of loopholes, whether or not the answer is valid is up to me (and also, standard loopholes are also not allowed).

Robbers:

Your job is to make the same compiler (which does the same thing with the same commands given as the equivalent cop answer), with more characters. The programming language may be different.

Standard loopholes aren't allowed, and whether an answer is valid or not will be judged by me.

As always, since this is code-bowling, aim for the most bytes!

• "whether or not the answer is valid is up to me" unfortunately, this is going to make the challenge unclear. – Erik the Outgolfer Nov 6 '18 at 20:35
• I'm afraid I don't really understand the core of this challenge. The robbers have to make the compiler larger without affecting its functionality? That seems trivial to do; just add a comment or some whitespace. – Dennis Nov 6 '18 at 21:26
• Your job is to make the same compiler ... with more characters Should this be less characters? also, shouldn't it be bytes? – Jo King Jan 29 '19 at 5:06
• @JoKing Yeah, I realized that. – MilkyWay90 Jan 29 '19 at 12:24

Win 2048

Win 2048. You can decide where to summon block of 2(no 4), and how you move. The output would be [place, place, move, place, move, ..., place, move](finally you reach 2048).

Shortest code win.

SN: Similar to Play a perfect game of 2048 ?

• (in case somebody don't understand the challenge: the program should take no input, and output any sequence of moves in 2048 game such that the tile 2048 is generated. As said in the challenge, the new block must be [2] (not [4]) and the program can determine where the block appears) – user202729 Nov 15 '18 at 14:31

Coprimes upto N (Performance Edition)

There is this question: Coprimes up to N

Most of the answers there take way to long for larger numbers.

So, your task is to find all the coprimes of a number n (gcd(n,coprime)==1) up to nas fast as possible.

Scoring

Score=Largest n for which your code will output in less than 10 seconds on my laptop. Provide instructions to run it on my machine.

Highest score wins.

I will put the specs of my pc, anything else needed?

• I think this is not interesting. The output (φ(n) numbers) is too large in comparison with the time complexity of a reasonably-competitive algorithm (I'd expect algorithms to take n log n time at worst), so printing output is going to be the bottleneck. – user202729 Nov 23 '18 at 11:54
• What if I make it to print the number of coprimes instead? @user202729 – Vedant Kandoi Nov 23 '18 at 12:08
• That is number of primes @user202729. This is co-primes of n. – Vedant Kandoi Nov 23 '18 at 12:24
• Still, very similar to codegolf.stackexchange.com/questions/26739/… . – user202729 Nov 23 '18 at 13:03

A Quine that Grows!

Challenge

Create a quine that, when run, outputs itself but copied larger in the next one. The output should be able to be run, and get larger each time the output is run. The output must consist only of characters from the original quine!

EX:

abc //original
abcabc //output


or

abc //original
aabcc //output


What not to do

abc //original
abcgef //output

abc //original
abcoooooooooooo //output


An example I created

Try it Online! It replicates pretty fast if I do say so myself!

Points

This challenge is meant to be a codegolf, but also emphasize on how fast it replicates. So perhaps something like the speed at which it gets bigger divided by the number of bytes.

I really don't want loopholes like just repetitively adding characters to a section of the code, making infinite loops, and things of the like.

Any input on how to make this a good challenge? I'm open to suggestions!!!

• Related, related (probably a dupe) – Jo King Feb 10 '19 at 10:25
• @JoKing What about a polyglot that gets bigger? It runs, making another program that runs and outputs a bigger version of the original, and vice versa. – KrystosTheOverlord Feb 10 '19 at 16:02
• where's the polyglot part come from? otherwise that sounds like the second one – Jo King Feb 10 '19 at 22:04
• @JoKing The output has to be in a different programming language, and then create a larger version of the original, then this larger original makes a larger of second program etc... Also to prevent easy loopholes, no using program languages that are derivatives of eachother – KrystosTheOverlord Feb 10 '19 at 22:32

Just idea. Not sure what to do exactly.

Evolutionary Golf

Make simple (not golfed at all at first) code for (some program) with language (something).

Now, change a little bit (maximum 3 byte) of code to make it shorter.

Altered code must work properly (this is how evolution work).

(Maybe here will be starting code).

Sandbox

First. What program would be best? For example, 'Hello World' program is not proper, because it is too short, and can't golf that much.

Second. What language would be best? Esolang like BF? Or something like C?

• If I understand the challenge idea correctly you will post an ungolfed answer that does something in some (probably verbose) language (i.e. FizzBuzz in C#). And then answers after that should have a Levensteihn distance change $c$ where $1\leq c\leq3$ (at least 1 delete) that does the same thing (in any language). And the shortest answer that's at the end of the answer chain wins if no other answers are posted within 2-3 weeks (which is usually the case with answer-chaining challenges)? Or do you mean that anyone can post an ungolfed program, and others using the same language chain it? – Kevin Cruijssen Jun 26 '19 at 9:04
• @KevinCruijssen I'm thinking of both. This is just brief outline, so everything can be changed. – LegenDUST Jun 26 '19 at 12:10
• this is just game of nim with extra steps – Kenzie Aug 2 '19 at 17:51

Print all the commands

META Just a rought idea, needs to be worked out.

Write a program that prints all the keywords and commands that are available in your langauge when you do not import/add anything

Details

• require full program or standard code-golf?
• Understanding that this is a rough idea, what happens in languages without commands corresponding to single tokens e.g. ///? – lirtosiast Jul 18 '19 at 15:49
• It is my opinion that this sort of challenge will likely never be clear. – Wheat Wizard Jul 18 '19 at 16:08
• I'd imagine for /// you'd output all valid non-text characters, so \ /. – bigyihsuan Jul 18 '19 at 17:08
• Another thing is that language version would be specified. For example, Python 2 has print as a keyword, while Python 3 has print() instead. – bigyihsuan Jul 18 '19 at 17:10
• Pretty sure this (or something similar enough to be a dupe) has been done before. Lemme see if I can find it .... – Shaggy Jul 21 '19 at 21:11
• – Shaggy Jul 21 '19 at 21:13
• One way to do this might be to make it language specific? While that isn't usually popular, outputting all of, say, Python's commands in most languages besides python is a dupe of the Rickroll challenge. However, in python itself that isn't the best approach. I can't say how well reveived it'd be, but you could try "output these MATLAB commands in MATLAB" and see what people think. – FryAmTheEggman Jul 23 '19 at 19:45

Here's a challenge I'd like post because I'm curious to see what people will come up with. It's a bit of an anti-code-golf question because the code should look normal.

Is it clear what the constraints? Did I miss anything?

Introduction

Write a piece of unsuspicious code that does the following:

Let's say you've written a parser that parses it's input line by line and somewhere in your code is

find_string(line, "[start]", "[end]") // returns string between [start] and [end]


This program, when given it's own source code plain text as input, will match that line (twice actually); but we don't want that. It should still parse what it was designed for but not match any line of it's own source code.

Rules

• It's preferred that your code makes it obvious that one of it's intended uses is to parse (and not match) itself. This is so anyone 'refactoring' the code will not accidentally undo the trick that made it work.
• Your source code as input will be reduced to a single line.
• Your program should be able to handle large input (~10mb) and perform reasonably (for your chosen language).
• Your program does not need to parse the input line by line but that just seems like something reasonable code would do.
• Points are awarded for code that looks like a normal parser and contains as little assumptions about the input as possible. Bonus points for solutions that contain the start and end delimiters in that order.

Easy solutions are to swap the start and end token arguments or to pre-treat the tokens in some way but that would look suspicious. Someone will come along and refactor your code and break the 'trick'.

I'm interested in reasonable solutions because this is a reduction of a real life problem.

Example Input and Output

• Input lines may or may not contain [start] or [end], only return it in the output when it occurs in a pair.
• Input lines will never contain more than one pair of [start] and [end] tokens.
• Input lines may contain additional content before [start] or after [end]
• Your source code plain text will be inserted at a random line in the input.

Input #1:

[start]hello[end]
<<your source code plain text>>
dont output this[start]world[end]


Output #1:

hello world


Input #2:

lorem[start]i solemnly[end]
[start]false start
[start]swear[end]
ope, sorry just passing through
this is not the[end]
[start]that i'm up to[end]ipsum
[start]no[end]dolor
<<your source code plain text>>
[start]good[end]


Output #2:

i solemnly swear that i'm up to no good

• What is the objective winning criterion? – Unrelated String Aug 9 '19 at 5:16
• This could be a good challenge if it was just 'Write a program that takes a line of input and returns the concatenation of anything between [start] and [end] on each line, otherwise an empty string', with the restriction that if it was fed itself, it wouldn't return anything – Jo King Aug 9 '19 at 6:05
• I'm a little confused about what Bonus points for solutions that contain the start and end delimiters in that order. means, since I thought the point was that we're not allowed to have that? – Jo King Aug 9 '19 at 6:07
• "unsuspicious code" will raise red flags in the minds of a number of old-timers, for historical reasons which I won't explain in detail. What I will say is that unsuspicious is subjective, and we insist on objective criteria. In terms of actual reasonable solutions to the real world problem: don't use magic strings. If "[start]" and "[end]" are both constants and defined on separate lines, the problem is averted, and anyone who refactors to inline them deserves all the bugs that causes. – Peter Taylor Aug 9 '19 at 10:45

Title: Transposition

** The challenge **

Given a set of notes (as a string, or a list, or any other reasonable input - but as letters and accidentals, not a numerical equivalent), the key those notes are in, and a target key; output the notes transposed into the new key. Some of the notes may not exist in the scale for the given key (e.g Eb in the key of C).

** Inputs **

The complete set of input notes for this challenge will use the English naming convention, and so are as follows:

Ab,G##,A,A#,Bb,B,C,C#,Db,C##,D,D#,Eb,E,F,F#,Gb,F##,G,G#

where "b" represents a flattened note (down one semitone per b), and # represents a sharpened note (up one semitone per #). Theoretically all notes can be extended further with more #s and bs; but for the purposes of this program that won't happen beyond what is already given.

** What is transposing? **

Transposing a song involves "moving" the song into a different key, by finding the equivalent note of the scale in that key.

We will assume Major scales for the purposes of this challenge.

** Scales **

The scales for this challenge are officially as follows:

• C: C, D, E, F, G, A, B, C
• C#: C#, D#, E#, F#, G#, A#, B#, C#
• Db: Db, Eb, F, Gb, Ab, Bb, C, Db
• D: D, E, F#, G, A, B, C#, D
• D#: D#, E#, F##, G#, A#, B#, C##, D#
• Eb:Eb, F, G, Ab, Bb, C, D, Eb
• E: E, F#, G#, A, B, C#, D#, E
• F: F, G, A, Bb, C, D, E, F
• F#: F#, G#, A#, B, C#, D#, E#, F#
• Gb: Gb, Ab, Bb, Cb, Db, Eb, F, Gb
• G: G, A, B, C, D, E, F#, G
• G#: G#, A#, B#, C#, D#, E#, F##, G#
• Ab: Ab, Bb, C, Db, Eb, F, G, Ab
• A: A, B, C#, D, E, F#, G#, A
• A#: A#, B#, C##, D#, E#, F##, G##, A#
• Bb: Bb, C, D, Eb, F, G, A, Bb
• B: B, C#, D#, E, F#, G#, A#, B

For simplicity, we can assume that both notes in the pairs A#/Bb, C#/Db, D#/Eb, F#/Gb, G#/Ab, C##/D, F##/G, G##/A are enharmonically equivalent (i.e. interchangeable - although they're not, always).

For scales with double-sharps, I will accept the enharmonic equivalents as an alternative implementation:

• D#: D#, E#, G, G#, A#, B#, D, D#
• G#: G#, A#, B#, C#, D#, E#, G, G#
• A#: A#, B#, D, D#, E#, G, A, A#

but for all other notes in the scale, they must match. If the note isn't in the scale, either can be used.

e.g.

• F in the key of C should transpose to F# in the key of C#, and not to Gb, because that option in the pair is explicitly in the scale
• but D in the key of C# could transpose to either C# or Db in the key of C, because it's an incidental anyway and so there's no easy rule to determine which it should be.

BONUS feel-good points *: normally it's # if you're going up, and a b if you're going down - feel free to implement this if you want!

For double-sharps (e.g F##) in all cases, It's OK if the program "resolves" these (e.g.to G in that case) even if they are in the scale; but again, some BONUS feel-good points * if you keep the double-sharps in.

Examples

• CDEFGABC in C to A -> ABC#DEF#G#A
• C# in C to A -> A# OR Bb
• ABCDEFGBAF#Bb in Bb to Gb -> FGAbBbCDbEbGFDGb
• CCGGAAAAGFFEEDDCGGGFFEEEDCGGGFFFFEEED in C to G# -> G#G#D#D#E#E#E#E#D#C#C#B#B#A#A#G#D#D#D#C#C#B#B#B#A#G#D#D#D#C#C#C#C#B#B#B#A#

Websites like http://www.logue.net/xp/ can be used to test your answers to other inputs

* Bonus feel-good points don't get you anything extra, unless someone can come up with a quantifiable difference that it should make to the score?

• This is kind of similar but doesn't use scales and has a different set of chords, so I think this is effectively different? – FryAmTheEggman Sep 24 '19 at 18:47
• Yes, I agree it's similar but doing a different thing to me (they're using chords, and so have the extra text to worry about; but I'm doing notes, like sheet music; and so you have accidentals to worry about) – simonalexander2005 Sep 25 '19 at 8:48

Interpret Unneccesary (Not quite)

Unneccesary is a joke language created by Keymaker. The source is unneccesary, and if given, it will error out.

Your task here is similar. If there is input, your program should error out. If the input is empty, your program should do nothing and terminate.

• What does it mean to error out? – Beefster Oct 24 '19 at 19:14
• @Beefster throw a runtime error... Or? – null Dec 1 '19 at 10:15
• What if I'm using a language that does not have terminal errors such as Bash? – Beefster Dec 2 '19 at 19:34
• @Beefster Are there any specifications for, something like error quine? – null Dec 21 '19 at 10:54