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.

The Sandbox works best if you sort posts by "active".

Add Proposal

Search the Sandbox

Browse your pending proposals

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]

| |

2867 Answers 2867

84 85
87 88

Golf me a Bookmarklet Quine

Given a javascript program (or any utf-8 text) of arbitrary length, output it in my simplified version of URI form, like a bookmarklet. You can use https://mrcoles.com/bookmarklet/ as reference. Output should be in the form

javascript:[input with percent-encoding for special characters]

Special characters are any character that is not

  • Alphabetic (upper or lower)
  • a digit
  • the characters .,-,_, or ~ (period, hyphen, underscore, tilde)

Your program "should convert all other characters to bytes according to UTF-8, and then percent-encode those values"w

A percent-encoding mechanism is used to represent a data octet in a component when that octet's corresponding character is outside the allowed set or is being used as a delimiter of, or within, the component. A percent-encoded octet is encoded as a character triplet, consisting of the percent character "%" followed by the two hexadecimal digits representing that octet's numeric value. For example, "%20" is the percent-encoding for the binary octet "00100000" (ABNF: %x20), which in US-ASCII corresponds to the space character (SP). source

Lowercase hex is okay, but uppercase is preferred.

This is code golf, standard loopholes are prohibited, programs should handle input up to 20 lines and output in a single line.

The Twist (so it's not a duplicate)

If run with no input or just a newline (your choice), the program should output itself in the same format as if the program's source was inputted normally.


In                                              Out

[blank]                                         javascript:[the%20program%27s%20source]
g/re/p                                          javascript:g%2Fre%2Fp
https://www.youtube.com/watch?v=dQw4w9WgXcQ     javascript:https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DdQw4w9WgXcQ
alert("test!")                                  javascript:%7Balert(%22test!%22)

sandbox questions

  • What should I add?
  • What tags does this need?
  • Are my examples inconsistent?
  • What parts of the challenge are redundant?
| |

Comment: might be too similar to previous mutual quine challenge?

Collaboration/quasi-quine challenge

Write a valid submission (A) which prints the code for another competitor's valid submission (B). The languages used in A and B must be different.

Clarifying rules

If B prints the code for a third submission, C, it is not required that A and C be different languages. Similarly, the authors of A and B must be different, but A and C need not be. (More different languages/authors score higher, however.)

The shortest chain is for A to print B and B to print A.

Note that if A prints B, and B prints C, but C is not valid for some reason, then neither A nor B are valid either.

It is acknowledged that the validity of your submission may change over time, due to factors beyond your control. Try not to let this worry you too much. :)




Just the code described above. Nothing extraneous.


Scoring is (A + L) * 100 + C where:

  • A is the number of distinct authors that directly or indirect print your solution. So if you are Q, and Z=>X=>Q=>X, your "A" is 2. (Each submission only has one author, the "answerer".)
  • L is the number of distinct languages in your quine circle, along the same lines as for authors. (Each submission only has one language. "Distinct" means really different, not just different versions or implementations of the same languages.)
  • C is the length of your solution in bytes.

(So, for a given circle of quines, all the submissions will have similar scores, with the length of the submission as tie-break.)

Standard loopholes are forbidden.

| |
  • \$\begingroup\$ I like it when your score improves if you use more languages. Any reason why you didn't include that? \$\endgroup\$ – Wezl Apr 30 at 21:51
  • \$\begingroup\$ Oh, what would an example of that be? I did consider something like having your score improve, the longer the chain is. Like, your score is the sum of the length of all the submissions divideded by the square of the number of participants or something. \$\endgroup\$ – Steve Bennett May 1 at 2:09
  • \$\begingroup\$ That would be nice, but I wouldn't know how to balance it well. Just a thought. \$\endgroup\$ – Wezl May 1 at 17:46
  • 2
    \$\begingroup\$ This seems to me like a chicken-and-egg situation. How could the first posted answer be valid if there are no B answers to print the code for? \$\endgroup\$ – math junkie May 25 at 15:35
  • 1
    \$\begingroup\$ This is another similar challenge. It had several problems that I think might occur again with your current setup. I'd recommend giving the criticism and answers there a read over. \$\endgroup\$ – FryAmTheEggman May 25 at 20:45
  • \$\begingroup\$ @mathjunkie It wouldn't. I don't think that's inherently problematic, it's just an interesting bootstrapping challenge. \$\endgroup\$ – Steve Bennett May 26 at 1:00

Price this word

So, I'm going shopping in the Word Market™. There are shelves of words which I can buy around me, but I only have one dollar bills and the change machines at the market are broken. To add to the problem, there are words with... non-word characters in them. That's no good, I can't buy those... can you help me figure out which words I can buy and which I can't?


So, I can only buy words that consist of only alphabetical characters and are worth a dollar. To determine a word's value, you have to sum the letters in the word where A = 1¢, B = 2¢... to Z = 26¢. I'm too lazy to look at the output and judge whether it is equal to one dollar (100 cents), so you'll need to return a specific value for words equal to a dollar (...or 100 cents) and a specific value for not equal to a dollar (I'm going to stop including this).

I'll also offer a bonus byte reduction: if your code returns whether the word is less than a dollar, equal to a dollar, greater than a dollar, or invalid (e.g. <, =, >, x), your score will be multiplied by 3/4.

SANDBOX NOTE: Is this a balanced bonus value?


Word          Non-bonus value     Bonus value

a                  false               <
b                  false               <
printera           false               >
$word              false               x
printer            true                =

And here's a JavaScript snippet you can use if you want to check for non-bonus validity:

(it's also 52 bytes; you can use it by calling f())


Anyways, standard loopholes apply, shortest answer in bytes wins (but I'll add shortest answers for esoteric and functional languages)... you get the idea.

| |
  • 1
    \$\begingroup\$ In general, bonuses in code golf are seen as something to avoid \$\endgroup\$ – math junkie May 28 at 2:45
  • \$\begingroup\$ Standard Loopholes \$\endgroup\$ – math junkie May 28 at 2:46
  • 2
    \$\begingroup\$ This challenge doesn't seem interesting to me. We've already have plenty of challenges about summing up characters in a string, and having to determine whether a string contains non-word characters just seem like tacked on challenge that makes the whole thing more cumbersome. \$\endgroup\$ – Surculose Sputum May 28 at 15:40
  • 2
    \$\begingroup\$ What's a bit ironic about this is that after you posted this you went on to write a program that went through words in the English language and summed up their values depending on what character they were, sharpness of a word \$\endgroup\$ – Ethan Slota May 28 at 20:53
  • \$\begingroup\$ Never say I like the sharpness challenge either. :P But I do think that that challenge is a bit more interesting, due to the somewhat arbitrary mapping of letter to values. Yours just straight up uses the vanilla alphabetical order. \$\endgroup\$ – Surculose Sputum May 29 at 14:53
  • \$\begingroup\$ You do have a point; in Jelly or 05AB1E there's probably a builtin that would sum up a string based on values like I want people to do. \$\endgroup\$ – Ethan Slota May 29 at 21:50

Magic card trick: Hide information by flipping cards

(This is inspired by a series of questions on puzzles.stackexchange.com: 10, 8, 7)

Fix two integers m and u. Your task is to perform the following magic trick:

  • A Magician brings a pack of m distinct cards, and leaves the room.

  • In their absence, a volunteer from the audience shuffles the deck and arranges all cards in a line, in any order they want.

  • Still in the absence of the magician, their assistant flips u cards. On the table are the n cards, still in the order chosen by the volunteers, but u are face down, leaving only mu cards face up.

  • The magician returns, and from the order of the cards alone, knows each card.


m - number of cards.

u - number of cards to flip face down.

  • You may assume 0 < u < m.

Output, if the trick is possible for m and u:

f - an mapping assigning to each sequence the order the assistant will create by flipping cards.

  • If the trick is to work, this mapping must be bijective.
  • Use the integers 1...m (or 0...m−1), or single letters as card values.
  • Use any meaningful way to express f: a hash maps, a table, a function.
  • Use a fixed placeholder for any face-down cards.

Output, if the trick is impossible for given values of m and u

This case should be indicated in a meaningful way.

Example output (m=3, u=1):

Using the digits 0, 1, and 2 as cards, and _ for their flipside:

012 01_
021 0_1
102 _02
120 12_
201 2_1
210 _10

(For these values of m and u, this isn't very impressive as a magic trick, of course.)

Example output (m=4, u=2):

Using 1, 2, 3, and 4 for the cards and 0 for their flipside, and a JSON representation:


This is correct because as required, the keys are all permutations of 1234, each value has two cards face-down and the other cards match the original sequence, and each value appears only once.


This is code-golf. Shortest solution wins.

| |
  • \$\begingroup\$ I think I should not allow all that input/output flexibility and require some fixed format. For example: input is u and a string whose (unique) characters are the decks. Require _ as placeholder. Require a fixed table format. \$\endgroup\$ – retzler May 29 at 4:27
  • 1
    \$\begingroup\$ There were some clarity issues I had while reading this, but as is I think this has a much bigger problem. It seems very likely to me that outputs for large m will be prohibitively difficult to verify, given the complexity of the proofs from the related puzzling challenges. There are many ways you could approach this, like upper bounding m, making this a test-battery, or making a code-challenge where the goal is to find the maximum u for the highest m. There are probably other ways to handle this, so these are just some starting ideas. Thanks for using the sandbox! \$\endgroup\$ – FryAmTheEggman May 29 at 19:23
  • \$\begingroup\$ Thank you for the valuable feedback @FryAmTheEggman. The proofs from the linked puzzles are long because they're reasoning & looking for insight. To just verify the list, two steps are sufficient: verify that f*(*x) is obtained from x by replacing u symbols with _, and that f is a bijection and defined for all permutations. Non-golfed solution including full tests . The output will still be huge, no chance of cursory manual verification. I didn't know about alternatives to code-golf, actually! I'll be looking into these. \$\endgroup\$ – retzler May 29 at 21:44
  • \$\begingroup\$ No problem! I do want to clarify though - I was aware of the ability to prove by exhaustion when I posted my first comment. However, I did base my assessment of it being a true problem around you not wanting a completely naive brute force search through each strategy, which I see now wasn't correct, so if you are fine with that then there isn't really a problem. But of course, if you want anything besides those solutions I'd recommend looking into what I suggested, or asking in our chat room for other people's points of view. \$\endgroup\$ – FryAmTheEggman May 29 at 22:43


| |
  • \$\begingroup\$ What kind of numbers can be in the sequence? \$\endgroup\$ – xnor May 22 at 10:30
  • \$\begingroup\$ @xnor Integers, basically. \$\endgroup\$ – Member for 3 months May 22 at 10:35
  • \$\begingroup\$ Would the test cases that time out, 1,2 and 7,4, be excluded by "the input will always be provided in a way such that it won't take forever to zero the accumulator"? No product of exclusively odd numbers can end up being divisible by a power of 2. \$\endgroup\$ – Unrelated String May 23 at 9:35
  • 1
    \$\begingroup\$ @UnrelatedString Thanks for nothing that; I've removed these test cases. \$\endgroup\$ – Member for 3 months May 23 at 9:46
  • 2
    \$\begingroup\$ Now this post is zeroed eventually \$\endgroup\$ – l4m2 Jun 5 at 1:36

Mobile games money representation

In many mobile clicker games where the player is usually required to tap on the screen to make money (in order to buy upgrades for you to generate money faster), it gets to a point in the game that the money made per second is so big that if represented in its "normal" form, it would clutter the mobile screen. Imagine showing the user that they are making \$1,000,000,000,000,000,000,000,000\$ per second in a small mobile phone screen!

From my experience as a regular player of these type of games, I have noticed that most of them represent bigger numbers by using letters. If the number of money per second is a number less than \$10,000,000\$ then print the number as is. Otherwise, if the number is in the millions (but \$ \geq 10,000,000\$), for example \$ 102,000,000\$ it should print \$102M\$. If it is in the billions, it should print \$102B\$. You should use \$T\$ for trillion and \$Q\$ for quadrillion.

As you can notice, the next would be quintillion which would also use the letter \$Q\$ if followed the pattern. Instead of following this pattern which can be confusing at one point, game developers usually start a new pattern: Quintillion is used with the suffix \$AA\$, sextillion is \$AB\$, septillion is \$AC\$ and so on.

Notice that this pattern would go until \$AZ\$ and if the player is making more money than that, it would start from \$BA\$, \$BB\$, ..., \$BZ\$, ...,\$ZA\$, \$ZB\$, ... , \$ZZ\$ which for our problem we will assume is the limit one player can make per second.


Given an integer \$x\$ where \$0 \lt x \leq 999\$ and a natural number \$y\$ where \$y \gt 0\$ representing the number of zeroes the number has, output the number in a "mobile game money representation" as described above.


  • The number of zeroes that \$y\$ represent does not include the possible zeroes \$x\$ might have! Example: if \$x = 100\$ and \$y = 6\$, you should output \$100M\$ and not \$1,000,000\$

Test Cases (x, y --> game money representation)

100,  6 --> 100M
100,  5 --> 10M 
100,  4 --> 1000000
1,   12 --> 1T
10,  12 --> 10T
100, 12 --> 100T
1,   18 --> 1AA
10,  18 --> 10AA
100, 18 --> 100AA
# To be added...

Meta questions

  1. Is this a duplicate? I have looked around but didn't find anything similar.
  2. Is the wording confusing? I'm open to recommendations!
  3. I haven't written a program yet so the test cases might be wrong (I'll add more later).
  4. Pretty much any feedback is appreciated!
| |
  • 2
    \$\begingroup\$ Looks like it needs some test cases with decimal points, e.g. 123, 17 -> 12.3AA. \$\endgroup\$ – Bubbler Jun 1 at 0:20
  • \$\begingroup\$ Shouldn't 100, 4 become 1M? \$\endgroup\$ – Surculose Sputum Jun 1 at 13:03
  • \$\begingroup\$ @SurculoseSputum In these games, when the number is small enough (as I said in the second paragraph), if the number is less than 10 million, then it is printed in its "normal" form. The abreviations starts after 10 million. \$\endgroup\$ – ihavenoidea Jun 1 at 19:33
  • \$\begingroup\$ Suggest cases where \$y\$ don't just go the AA \$\endgroup\$ – l4m2 Jun 19 at 4:24
  • \$\begingroup\$ Thanks all, I'm pretty busy lately unfortunately. Whenever I get the time I'll try to update the challenge \$\endgroup\$ – ihavenoidea Jun 19 at 21:59

Shift the letters, soldier !

posted, finally

| |
  • \$\begingroup\$ Thank you for sandboxing this. I usually recommend doing so for at least a week, and periodically ask for review in TNB. \$\endgroup\$ – Adám Feb 28 at 9:09
  • \$\begingroup\$ I think people would be forced to do the bonus in this case because of the -30% margin. I got a 42 without bonus but a 57*0.7=39.9 with bonus in JS. \$\endgroup\$ – Shieru Asakoto Feb 29 at 3:16
  • \$\begingroup\$ Bonuses are discouraged for a variety of reasons. I would strongly recommend either making it mandatory or completely leaving it out. \$\endgroup\$ – FryAmTheEggman Mar 1 at 18:58
  • \$\begingroup\$ The main challenge is add by position, the bonus challenge is minus by position. So it's a good idea to completely leave the bonus out. \$\endgroup\$ – Member for 3 months Mar 2 at 0:29
  • \$\begingroup\$ Thanks for the comments, I'll remove the bonus as it will never be balanced enouth to be interesting. I'll add some example as soon as I can. \$\endgroup\$ – The random guy Mar 3 at 20:02
  • \$\begingroup\$ I would say that allowing the usage of the ascii range 1 to 255 or a language's code page could allow for some interesting golfs :) \$\endgroup\$ – RGS Mar 3 at 20:39
  • \$\begingroup\$ Use asciii values from 0 to 255 was my original plan, but I'm afraid some interestings languages would be disadvantaged. Also, wouldn't the usage of language's code page be too permissive ? \$\endgroup\$ – The random guy Mar 4 at 15:51
  • \$\begingroup\$ @Therandomguy it depends on what you mean by "too permissive". Sometimes it is done, as it may allow some languages to do some funny things. As to the range being from 0 to 255, I don't see it hurting any language at all, but of course I may be missing something :) \$\endgroup\$ – RGS Mar 4 at 21:36
  • \$\begingroup\$ Are you interested in re-posting it? \$\endgroup\$ – Member for 3 months Mar 6 at 7:38
  • \$\begingroup\$ This weekend I'll post it, I just need some time creating the examples \$\endgroup\$ – The random guy Mar 6 at 8:25
  • \$\begingroup\$ I'd be glad to see it posted in Main! \$\endgroup\$ – Member for 3 months Mar 25 at 12:19
  • \$\begingroup\$ Finally posted it in main \$\endgroup\$ – The random guy Jun 3 at 7:45

Compute the pointiness, sharpness and smoothness of a letter

Inspired by Determine the sharpness of a word.
You are given an uppercase letter of the English alphabet as input. You have to compute (and output) its pointiness, sharpness and smoothness. Since it is difficult to define these objectively, here's a table of the outputs:

            A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
pointiness: 2 0 2 0 3 3 2 4 4 2 4 2 2 2 0 1 1 2 2 3 2 2 2 4 3 2
sharpness:  1 2 0 2 2 1 1 0 0 1 0 1 3 2 0 1 0 1 0 0 0 1 3 0 0 2
smoothness: 0 2 1 1 0 0 1 0 0 1 0 0 0 0 1 1 1 1 2 0 1 0 0 0 0 0

Transposed version (first lists the letter, then the pointiness, then the sharpness and then the smoothness) (like a true CGCC user, I transposed it with Jelly and added spacing with Retina):

A 2 1 0
B 0 2 2
C 2 0 1
D 0 2 1
E 3 2 0
F 3 1 0
G 2 1 1
H 4 0 0
I 4 0 0
J 2 1 1
K 4 0 0
L 2 1 0
M 2 3 0
N 2 2 0
O 0 0 1
P 1 1 1
Q 1 0 1
R 2 1 1
S 2 0 2
T 3 0 0
U 2 0 1
V 2 1 0
W 2 3 0
X 4 0 0
Y 3 0 0
Z 2 2 0

Bonus imaginary internet points if you find a language where this is built-in.

This is tagged , so the shortest answer wins.

Sandbox stuff

  • Is this not a duplicate?
  • Is the table computed correctly? (the only ones that don't seem certain with the current font are I's pointiness, G's sharpness and S's smoothness)
| |
  • \$\begingroup\$ After fiddling about a bit, I think this should probably have enough patterns that mindlessly compressing the numbers won't be the best strategy. Still, I could be wrong, but here is what I used to see roughly how long such an approach would be (I encoded each set of values to a base 5 number, then in turn encoded that list of numbers into a base 61 number). Separately, you probably want to include the data in a more copy-pastable way. \$\endgroup\$ – FryAmTheEggman Jun 3 at 20:34

Is this a simple cutting template?

A simple cutting template is a rectangle that can be recursively cut into smaller rectangles using only full-width cuts.

If you prefer a bottom-up description, then:

  • A single rectangle is a simple cutting template with 0 cuts.
  • Two simple cutting templates of the same width (or length) can be joined along their common side into a larger simple cutting template.

Input: A diagram of a rectangle subdivided into smaller rectangles, or a list of rectangles in some standard format, e.g. position and size.

Output: A truthy value if the diagram is a simple cutting template.

Note that if you take input as a diagram then all of the rectangle edges will use the same character, whearas in the truthy examples below, some of the edges have been replaced with digits to show a possible ordering of cuts while the falsy examples have the smallest portion of the input that is not a simple cutting template marked on them.

#   2               #
#                   #
#                   #
#                   #
#     2   2   2 4 4 #
3333332   2   2 4 4 #
# 4   2   2   2 4 4 #
# 45552   2   2 454 #
# 4 6 2   2   2 4 4 #
# 4 6 2   2   2 4 4 #
# 4 6 2   2   2 4 4 #
33333323332   2 4 4 #
#     2   2   2 4 4 #
#     23332   2 4 4 #
#     2   2   2 4 4 #
#     2   2   233333#
#     2   2   2     #

-> Truthy

# 2     4           #
# 2333333333333333333
# 2         6     4 #
# 25555555555555554 #
# 2 6   6     8   4 #
# 2 6   67777777774 #
# 2 6   6         4 #
# 2 6   6         4 #
# 2 6   6         4 #
#               2   #
#               2333#
#               2   #
#   2             2 #
#   233333333333332 #
#   2 4 4     4   2 #
#   2 4 4555554   2 #
#   2 4 4     4   2 #

-> Truthy

#                   #
#                   #
#                   #
# 2   4           2 #
# 2   4           2 #
# 2   4           2 #
# 23333333333333332 #
# 2     4   4 6 4 2 #
# 2     45554 6 4 2 #
# 2     4 6 4 6 4 2 #
# 2     4 6 4 6 4 2 #
# 2     4 6 4 6 4 2 #
# 2     4 6 45554 2 #
# 2     4 6 4   4 2 #
# 2     4 6 4   4 2 #
# 2     4 6 4   4 2 #
# 2     4 6 4   4 2 #
# 2     4 6 4   4 2 #

-> Truthy

#               # # #
################# # #
#               # # #
#               # # #
#               # # #
?     # ?     #     #
?     # ?     #     #
?     # ?     #     #
?     ##?     #     #
?     # ?     #     #
?###### ?############
?     # ? #       # #
?     # ? #       # #
?     # ? #       # #
?###### ?##       ###
? #   # ? #       # #
? ######? #       # #
? #     ? #       # #

-> Falsy

?     # # # # #     ?
?###### # # # #     ?
?     # # # # #     ?
?     # # # # ######?
?     # # # # #     ?
?###### # ##########?
? #   # # #         ?
? ##### # #         ?
? # # # # #         ?
? # # # # #         ?
? # # # # #         ?
? ####### #         ?
? #     # #         ?
? #     ############?
? #     #     #     ?
? #############     ?
? #     #     #     ?
? ##################?
? #         #       ?

-> Falsy

#       #   #     # #
################### #
#                 # #
# #                 #
# ###################
# #   #             #
# ###################
# #   #     #       #
# ###################
# #                 #
# ???????????????????
# ?   #             ?
# ?   #             ?
# ?   #             ?
# ?   ##############?
# ?   #   #         ?
# ?########         ?
# ?       #         ?

-> Falsy

This is , so the shortest program or function that breaks no standard loopholes wins.

| |
  • \$\begingroup\$ I think you should include an explicit definition: 'A simple cutting template is a rectangle that can be recursively cut into smaller rectangles using only full-width cuts.' \$\endgroup\$ – Dingus Jun 6 at 4:06
  • 1
    \$\begingroup\$ @Dingus Thanks for pointing that out, I think I must have accidentally edited it out by mistake when writing the sentence for the output. \$\endgroup\$ – Neil Jun 6 at 10:29
  • 1
    \$\begingroup\$ I'd prefer one or two small examples with extra markings and then a list of copy-pasteable test cases. \$\endgroup\$ – Zgarb Jun 6 at 11:13

ax + by, a & b are coprime


A doctor in Berlin, after analyzing his medical history, has realized that all of the results of his integral measurement results can be represented in the form of \$23x+28y\$, where \$x\$ and \$y\$ are integers.

However, he could have extended his theory. \$23\$ and \$28\$ can be replaced by any two coprime numbers, and this theory would still hold. (He didn't have time to write his theory in a paper, that's quite awful.)


Without examples, I'll never be convinced that this nonsensical theory holds!

Given \$the\ output\ of\ (ax+by)\$ (let's call it \$z\$), \$x\$, and \$y\$, find the smallest pair of \$(a,\ b)\$ that makes \$ax + by = z\$ true.

Example cases

| |

Duplicate of Find the minimum edit distance between two strings

| |

Partition distance

Quoting Anush:

I am very glad to provide a service to fill in the terrible gap in edit distance questions which codegolf.se has had. When there are as many edit distance questions as quine questions my job will be done.



Given a binary string consisting only of 0's and 1's, partition the binary string (divide the string into consecutive substrings), and determine the minimal edit distance in order to transform one piece into another, left to right. You need to output the sum of the edit distances between consecutive blocks.


I'm going to make a reference implementation to find the optimal partitions. But that's after I dump all my ideas, though.


We partition the string like this:

And then find the cumultative edit distance between each 2 pairs of partitioned strings:
[1 1 1]

Then, we sum the list of partitions.

So 3 is a possible output for this binary string. However, you need to find the minimum edit distance, so this might not be the correct answer.

Another example


We partition this string:

And then find the mimimal edit distance between each piece.
[0 1]

Therefore, our (non-optimal?) output for 001001010 is 1 ([0 1] summed).


  • The edit distance between two strings is the minimum number of single character insertions, deletions and substitutions needed to transform one string into the other.
  • The input is guaranteed to have at least length 3.
  • The pieces of your partition don't have to be the same length.
| |
  • \$\begingroup\$ What do you mean by "partition the input string"? Can I choose any partition I want as long as it's not all singletons or the entire thing? Or do I have to find one that's optimal in some sense? Why is the all-singletons case disallowed? Is the output the sum of the edit distances between consecutive blocks? From the examples I guess it is but you should say it explicitly. \$\endgroup\$ – Zgarb May 31 at 18:50
  • \$\begingroup\$ @Zgarb "partition the input string" means divide the input string into (not necessarily equal) consecutive substrings. You need to find one that's optimal, I've emphasized that. I allowed the all-singleton case; I specified that the output is the edit distance sum between consecutive blocks explicitly. \$\endgroup\$ – Member for 3 months Jun 7 at 4:36
  • \$\begingroup\$ It should still be made clearer that the output is the minimum over all partitions. \$\endgroup\$ – Zgarb Jun 7 at 20:21

Pristine Polyglot Quines

As the title says, you are to create a pristine program which outputs its own source code in as many languages as possible. A pristine program, taken from here, is:

Let's define a pristine program as a program that does not have any errors itself but will error if you modify it by removing any contiguous substring of N characters, where 1 <= N < program length.

For example, the three character Python 2 program

8 is a pristine program (thanks, Sp) because all the programs resulting from removing substrings of length 1 cause errors (syntax errors in fact, but any type of error will do):


and also all the programs resulting from removing substrings of length 2 cause errors:


If, for example, `8 had been a non-erroring program then `8` would not be pristine because all the results of substring removal must error.

A pristine quine is a pristine program that outputs its own source code, according to our standard quine rules (so no empty or literal only programs).

You are to write, in as many languages as possible, a pristine quine.

  • Your code must work in a minimum of two distinct languages
  • Different versions of a language do not count as different languages. Therefore, Python 2 and Python 3 are considered the same language.
  • Your program must be pristine in all languages used
  • This is , so the answer with the most languages wins
    • In case of a tie breaker, the longest solution, in bytes, wins


| |
  • \$\begingroup\$ Wow, pristine quines are already hard enough, and now you want it to be a polyglot too? Especially since polyglots often rely on one language ignoring the executing part of the other. Also, does it need to pristine in both languages, or both combined (i.e. removing a section can work in language A, as long as it errors in language B)? \$\endgroup\$ – Jo King Nov 13 '19 at 5:58

Default Lightning Strike


Inspired by this reddit question: ELI5: Why does lightning travel in a zig-zag manner rather than a straight line?

Although it's more complex than this, in general multiple lightning paths will randomly check its immediate surrounding for the direction with least resistance (based on air pressure, temperature, composure, humility, etc.) and travel in that direction. As soon as one of the paths reaches the ground, that entire path has the least resistance and most (although not all) of the ions will accumulate in that path, causing the lightning flash and thunder.
Here a slow-mo video of a lightning strike to get an idea.


Input: An integer \$h\geq3\$ and an integer \$1\leq p\leq\left\lfloor\frac{h}{2}\right\rfloor\$

Output: Each step of the ASCII animation of a lightning strike, with a cloud to earth height of \$h\$ and up to \$p\$ paths

We start with a lightning ion at the cloud, with a lowercase letter of your own choosing (i.e. b). This ion will travel in a random direction (horizontally, vertically, or (anti-)diagonally), except where this path itself comes from. Every 'tick' it also has a 20% chance of branching out into two paths, as long as we haven't reached \$p\$ paths yet. Each of these paths will behave the same.
As soon as any path hits the ground based on the height \$h\$, all letters of that particular path will become uppercase, and in the final 'tick' after that, only this uppercase path will remain.

Challenge rules:

  • Paths can intersect with other paths
  • Paths can travel upwards beyond the height of our starting point
  • Output can be in any reasonable format. Could be a list of multi-line strings for each 'tick'. Could be a list of character-matrices for each 'tick'. Could be pretty-printed to STDOUT (with clear non-whitespace separation between each 'tick' - i.e. a single character like a comma or semi-colon, or a line of --- or ___)
  • Trailing spaces for each line of a tick are optional (leading as well, as long as the lightning bolts are still correct)
  • If multiple paths strike the ground in the same 'tick', only the first one of those two (or more) paths will become the lightning strike. The order in which paths are created are therefore important, so keep that in mind.


This may all sound pretty vague, so here a couple of examples:
(I've added trailing spaces for each step with spaces, but you don't necessarily have to do so as mentioned in the challenge rules.)

Example 1: \$h=3, p=1\$

Tick 1:
" "
" "
Tick 2 (random direction: right):
"  "
"  "
Tick 3 (random direction: up-left):
"b "
"  "
"  "
Tick 4 (random direction: down-left):
" b "
"   "
"   "
Tick 5 (random direction: down):
" b "
"b  "
"   "
Tick 6 (random direction: up-right):
Note that this overlaps with a previous step in this path, which is fine.
" b "
"b  "
"   "
Tick 7 (random direction: down-right):
" b "
"b b"
"   "
Tick 8 (random direction: down):
" b "
"b b"
"  b"
Tick 9 (lightning strike):
" B "
"B B"
"  B"
Tick 10 (extra tick to remove all other paths, although there are none right now):
" B "
"B B"
"  B"

Example 2: \$h=5, p=2\$

Tick 1:
" "
" "
" "
" "
Tick 2 (random direction: down-left):
" b"
"b "
"  "
"  "
"  "
Tick 3 (random direction: down-left):
"  b"
" b "
"b  "
"   "
"   "
Tick 4 (random direction: right):
"  b"
" b "
"bb "
"   "
"   "
Tick 5 (random 20% path split; random direction 1: top-right, random direction 2: right):
"  b"
" bb"
"   "
"   "
Tick 6 (random direction 1: top-left, random direction 2: down):
" bb"
" bb"
"  b"
"   "
Tick 7 (random direction 1: left, random direction 2: down-right):
"bbb "
" bb "
"bbb "
"  b "
"   b"
Tick 8 (lightning strike of path 2):
"bbB "
" Bb "
"BBB "
"  B "
"   B"
Tick 9 (extra tick to remove all the other paths, which is path 1 in this case):
"  B "
" B  "
"BBB "
"  B "
"   B"

General rules:

  • This is , so shortest answer in bytes wins.
    Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
  • Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
  • Default Loopholes are forbidden.
  • If possible, please add a link with a test for your code (i.e. TIO).
  • Also, adding an explanation for your answer is highly recommended.

Sandbox Questions:

  • Should I perhaps use a different letter of the alphabet per path?
    • If yes: what would happen when different letter-paths overlap? I assume the top one will be visible per 'tick', but if lightning is struck it should still change it to the underlying letter as uppercase. In either case, you'll have to keep track of each individual path and uppercase only the one that struck the ground (first).
  • Any additional rules or things that are unclear?
  • An additional relevant tag?
  • More examples with more paths and/or larger height?
  • A different path percentage instead of hard-coded \$\frac{1}{5}\$ / 20%.
| |

Sort numbers using as few distinct bytes as possible


Write an algorithm that takes as input an ordered list (array, linked list, etc...) of numbers and outputs an ordered list containing the same numbers sorted by their value (ascending or descending).

The numbers may be represented using the most convenient format to you, with the only restriction that there must be a way to encode 256 distinct numbers. You are not allowed to use built-in sorting functions/algorithms.

Scoring criteria

Let \$c\$ be the number of distinct bytes in your code* and let \$s\$ be the number of bytes in your code*.
*Or its UTF-8 representation

The score is equal to \$c^2 + s\$. The answer with the lowest score wins!

Examples (imagine these are sorting algorithms):

  • ababccbaacbabcba\$c=3, s=16, score=25\$
  • aAbcd€f\$c=9, s=9, score=90\$
  • bytes 16 ee 3c 79 ee\$c=4, s=5, score=21\$

I'm open to suggestions, especially about the score formula.

| |
  • \$\begingroup\$ I see that this is your first attempt at writing a challenge. Thank you so much for using the sandbox! \$\endgroup\$ – Adám Jun 25 at 22:16
  • \$\begingroup\$ Please note that it is very hard to write good challenges that restrict solutions from certain things. This is because it is hard to define exactly what is prohibited in every language, and it is also hard to determine if any prohibited feature was used. \$\endgroup\$ – Adám Jun 25 at 22:19
  • 1
    \$\begingroup\$ @Adám So how should I prevent trivial answers? Maybe "built-in sorting functions/algorithms" is a bit vague. \$\endgroup\$ – D. Pardal Jun 25 at 23:04
  • \$\begingroup\$ We don't prevent trivial answers in most cases. Btw, if I accept plain numbers as input, may I assume the input is a list of integers between 0 and 255 inclusive? \$\endgroup\$ – Bubbler Jun 25 at 23:46
  • \$\begingroup\$ How about this: "You are not allowed to use any built-in function/command that can take an ordered container and output the sorted result. Anything else is OK." \$\endgroup\$ – Bubbler Jun 25 at 23:54
  • \$\begingroup\$ I think a good solution would be to allow built-in solutions, but to compile (in advance, so that it can be posted very quickly, probably via the "answer your own question" feature) a community wiki answer listing trivial 1-byte solutions. \$\endgroup\$ – my pronoun is monicareinstate Jun 26 at 4:17
  • \$\begingroup\$ @Bubbler Would still be unclear if J's /:~ or /:] were allowed or not. \$\endgroup\$ – Adám Jun 26 at 6:15
  • \$\begingroup\$ @D.Pardal Why do you want to prevent trivial answers? \$\endgroup\$ – Adám Jun 26 at 6:20
  • \$\begingroup\$ I wanted to prevent built-in functions because otherwise most answers would be exactly the same as the ones from this question. Maybe the easiest way to solve this would be to replace the task of sorting an array with another. \$\endgroup\$ – D. Pardal Jun 26 at 7:15
  • 1
    \$\begingroup\$ Yes. Banning built-in has long been considered a bad idea. \$\endgroup\$ – user202729 Jun 26 at 11:57

Distributive on myself


We all know about distributivity, i.e. \$a(b+c) = ab + ac\$. This is a property on 2 different operations, namely addition and multiplication. But indeed, nothing can stop us from studying distributivity of 1 operation. In this challenge, you will be studying a kind of left-distributive operation.


Given a positive integer \$N\$. Consider an operation \$p \star q\$ where \$p, q\in\{0, 1,\dots, N-1\}\$, such that \$ p \star 1 \equiv p + 1 \pmod N\$ and \$p \star (q \star r) = (p \star q) \star (p \star r)\$. In essence, you are making an \$N\times N\$ table. For instance, if \$N = 4\$, a possible \$\star\$ is:

⋆ q 0 1 2 3
0 | 0 1 2 3
1 | 0 2 0 2 ←
2 | 0 3 0 3
3 | 0 0 0 0

Note that the marked column satisfies \$ p \star 1 \equiv p + 1 \pmod N\$. In this challenge, we are interested in the marked row. It seems to be periodic.

Task: given a positive integer N, compute all the possible smallest positive periods of 1 ⋆ q.

Details and clarifications

By "all the possible periods", I mean that, there may be many, or one, or no such operation \$\star\$. And each of them will have a smallest positive period. Your challenge is to compute all such periods, given N. In the case N = 4, the given table turns out to be the only possible one, so you should output a list (or a set, etc.) consisting only of the number 2. But for N = 3, no operation satisfies all the requirements, so you can output an empty list, or 0, or some falsy value.

The smallest positive period will always be between 1 and \$N\$, if the sequence 1 ⋆ q (0 <= q < N) doesn't repeat at all, it is of period \$N\$.

N will range from 1 to \$2^{32}-1\$. So you can just encode the finite sequence of answers in some ways. But note that a formula or recurrence relation of this is unknown.

Test cases

In : N = 1
Out: [1]

In : N = 2
Out: [2]

In : N = 3
Out: []

In : N = 4
Out: [2]


  • Is the specification clear enough?
  • Should I provide more properties of \$\star\$, or should I just leave the golfers to figure them out?
| |

Fix mispellings

Wikipedia has a list of common misspellings, and there is also a machine-readable version!

Your challenge is to input a string and fix the mispellings in it.

The parituclar list we'll be using is https://en.wikipedia.org/w/index.php?title=Wikipedia:Lists_of_common_misspellings/For_machines&oldid=962756669#The_Machine-Readable_List. Note that even if the list changes, you must use this version. Here's a pastebin link: https://pastebin.com/j03aL98d.

Each line in the list is in the format INPUT->OUTPUT1, OUTPUT2, OUTPUT3, ... (of course, there may be more or less possible outputs, or even just one). That means that for input INPUT you must output exactly one of the possible outputs OUTPUT....

This is tagged , so the shortest answer wins.

Sandbox stuff

Should I add more misspellings to the post, or should I remove them?

| |
  • \$\begingroup\$ Related \$\endgroup\$ – pppery 20 hours ago
  • \$\begingroup\$ @pppery While the idea is probably related, I don't think the solutions would be related at all. \$\endgroup\$ – my pronoun is monicareinstate 20 hours ago
  • \$\begingroup\$ What is the input format? A plain English sentence (so we need to handle spaces, punctuation, capitalization), or is a list of words acceptable? How should capitalization be handled (some entries look like Tolkein->Tolkien and UnitesStates->UnitedStates; given unkown->unknown, what is the expected output of unkown, Unkown, UNKown, Tolkein, tolkein, TOLKEIN)? \$\endgroup\$ – Bubbler 11 hours ago
  • \$\begingroup\$ @Bubbler The input is a single entry in the list (the part before ->, of course). You do not need to handle capitalization ("tOLKEIN" is not "Tolkein"). (will clarify later). \$\endgroup\$ – my pronoun is monicareinstate 8 hours ago

Polyglot: Convert Case

Your task is to complete the conversions below in the same program in different languages. For example, running your code in Python 2 might transform input to snake case, but running it in JavaScript might transform input to kebab case.


The following case conversions must be completed:


This is a test         thisIsATest
camelCaseTest          camelCaseTest
PascalCaseTest         pascalCaseTest
snake_case_test        snakeCaseTest
kebab-case-test        kebabCaseTest
Testing!!one!!!1!!!    testingOne1
aBCDef                 aBCDef
ABCDef                 aBCDef
a_b_c_def              aBCDef
a-b-c-def              aBCDef

Try it online!


This is a test         ThisIsATest
camelCaseTest          CamelCaseTest
PascalCaseTest         PascalCaseTest
snake_case_test        SnakeCaseTest
kebab-case-test        KebabCaseTest
Testing!!one!!!1!!!    TestingOne1
aBCDef                 ABCDef
ABCDef                 ABCDef
a_b_c_def              ABCDef
a-b-c-def              ABCDef

Try it online!


This is a test         this_is_a_test
camelCaseTest          camel_case_test
PascalCaseTest         pascal_case_test
snake_case_test        snake_case_test
kebab-case-test        kebab_case_test
Testing!!one!!!1!!!    testing_one_1
aBCDef                 a_b_c_def
ABCDef                 a_b_c_def
a_b_c_def              a_b_c_def
a-b-c-def              a_b_c_def

Try it online!


This is a test         this-is-a-test
camelCaseTest          camel-case-test
PascalCaseTest         pascal-case-test
snake_case_test        snake-case-test
kebab-case-test        kebab-case-test
Testing!!one!!!1!!!    testing-one-1
aBCDef                 a-b-c-def
ABCDef                 a-b-c-def
a_b_c_def              a-b-c-def
a-b-c-def              a-b-c-def

Try it online!


  • Your code should produce the same output as the linked examples.
  • This is the shortest solution, in each set of languages, wins.

Questions for sandbox

  • I feel like maybe this should be just a minimum of two languages and answerers can decide which conversions to perform with number of conversions winning and as the tie-break.
  • I wondered about adding UPPER_SNAKE_CASE but feel like that would overcomplicate the conversion process so have omitted it for now.
  • Have I missed any other major naming schemes?
| |
  • \$\begingroup\$ in the example, at the start, you said python 2 and javascript, while below there are 4 conversions. Must you do all of them in a different language each? Also, do language versions (python 2 / python 3) count as different languages? \$\endgroup\$ – Command Master 7 hours ago
  • \$\begingroup\$ @CommandMaster It was just a cut down example to explain the concept of a polyglot. I'm still unsure whether it makes sense to allow two or more languages or require all four. I feel like allowing two or more would enable more elegant solutions as snake Vs kebab is the same bar the delimiter and Pascal Vs camel is the same bar leading capitalisation. What're your thoughts? \$\endgroup\$ – Dom Hastings 4 hours ago
  • \$\begingroup\$ Different language versions count as different languages (not sure of there's a relevant meta post. I'll try and look for it when I'm not on mobile.) \$\endgroup\$ – Dom Hastings 4 hours ago

Create a Boolean Calculator

Our boolean operators are AND, OR, XOR, NAND, NOR, XNOR and NOT.

Our numbers are 1 and 0.

The challenge is to write a program or function that calculates the results of the input.


A string, array or other input; containing alternating numbers and operators, e.g. 1 NOR 1 or 1 OR 0 AND 1. It must contain the strings for the operators, and not .+^¬||&& etc. As an exception, NOT must come directly after another operator (e.g. 0 AND NOT 1). You won't ever get a chain of multiple NOTs (so 1 AND NOT NOT 0 is invalid).


Return or print a single number (1 or 0), derived using the calculation below. Invalid input can lead to any output you choose, or none.


We're ignoring any precedence rules here - just calculate them in the order they come in - as if someone was typing it into a calculator and pressing Enter after each number. NOT is the only one that might cause some difficulties with that logic, as you need to figure out what it's NOT-ing before you can apply the other operator.

Truth Tables

0   0    0   1   0   1   0   1
0   1    0   1   1   0   1   0
1   0    0   1   1   0   1   0
1   1    1   0   1   0   0   1

0    1
1    0


  • 1 NOR 1 = 0
  • 1 NOR NOT 0 = 0 (equivalent to 1 NOR 1)
  • 1 NOR NOT 0 AND 1 = 0 (equivalent to 0 (from above) AND 1)
  • 1 NOR NOT 0 AND 1 OR 1 = 1 (equivalent to 0 (from above) OR 1)
  • 1 NOR NOT 0 AND 1 OR 1 XNOR 1 = 1 (equivalent to 1 (from above) XNOR 1)
  • 1 NOR NOT 0 AND 1 OR 1 XNOR 1 NAND 0 = 1 (equivalent to 1 (from above) NAND 1)
  • 1 NOR NOT 0 AND 1 OR 1 XNOR 1 NAND 0 XOR NOT 0 = 0 (equivalent to 1 (from above) XNOR NOT 0 = 1 XNOR 1 = 0)


This is code-golf, but with a twist.

Your score is the number of bytes in your code, divided by the number of operators your code implements. Smallest score wins.

For example, if you only implement AND, your score is the number of bytes of your code.

If you implement AND, OR, XOR, NAND, NOR, XNOR, NOT (the full list of operators); then you get to divide the number of bytes by 7.

| |

Something Else - ASCII Art maker:

A text to ASCII art generator maker, the program must input a string and return ASCII art from it. Something like patorjk.com/software/taag/. It has to use the Graffiti font. The winning criteria is the whoever gets the most likes.

| |
  • \$\begingroup\$ Hello! Just a few things to point out: 1) The current spec is very broad. For example, what fonts, how does spacing look, what characters need to be supported... there's a lot more details that need to be included than just "return ASCII art of this text" \$\endgroup\$ – Sp3000 Feb 24 '15 at 4:07
  • 1
    \$\begingroup\$ 2) What's the winning criterion? Popularity contest? Code golf? \$\endgroup\$ – Sp3000 Feb 24 '15 at 4:08

Identifying a Sonnet

This challenge is about determining if a given file (read-in from stdin) meets the criteria to be a sonnet. You may use any language for this challenge. If your language supports an API to use an online dictionary you may use that API, if your language doesn't then too bad.

Additionally, it is preferred if your language is one that can be ran directly from the command line and is a language that has a compiler or interpreter available directly from my distro's repos(Fedora), as I would rather just use a bash script to test the various programs, then test each program manually.

Definition of a Sonnet

  • Has 14 Lines (lines are denoted as the standard newline on your operating system).
  • Has a definite rhyme scheme, it will have one of the following rhyme schemes
  • Iambic Pentameter - consists of alternating stressed, unstressed syllables. This doesn't have to be perfect 100% of the time, just at least 50% of the time.

In order for your program to declare a given string a sonnet, it must meet all of the above criteria.

Additional Notes

You do not have to identify the following:

  • Thought Structure - too intense for a code golf challenge, and too subjective.
  • Topic - computer lacks context to determine this


Input will be read from stdin. This is the string that you will be declaring to be or not to be a sonnet.


Your program will output either yes or no for the question:

Does this string meet the given requirements to be a sonnet?

As this is code golf yes or no can be abbreviated to Y/N.


The solution with fewest number of bytes win that has the highest accuracy ratio for the correct identification of a sonnet. The preference is for higher accuracy rather than brevity of the program.

Test Data and Resources

What is not a sonnet

The following are examples that you program should return false on:

  • Beowulf
  • Haiku
  • Input that doesn't have exactly 14 Lines in it
  • The text of this question.
  • The text of just about any other question on StackExchange.
  • Things that don't have a rhyme scheme. See Below

Not A Sonnet

A man got on a boat
The boat was leaky
and had poor construction
For it was made by a one-eyed blind man
and his dumb intern
As soon as he got out of port
at the fort
it started to sink
eventually, it tanked.
And it capsized
If only that shipwright
wasn't so blind deaf and dumb
as microsoft tech support
That's not much support at all.
| |
  • 2
    \$\begingroup\$ I think without dictionaries for rhymes and stresses this is probably not a good idea. Of course you can use some sort of accuracy ratio, but then you also need false positives, and you need a lot more examples than the few on the pages you've linked. But if you do this there's no requirement to actually recognise the sonnets by their rhymes and stresses - instead, I'm pretty sure, people will just regex golf the test sets. \$\endgroup\$ – Martin Ender Mar 24 '15 at 19:36
  • \$\begingroup\$ @MartinBüttner I updated the requirements with an accuracy percentage, and added the option to use an API to look up terms from a dictionary. \$\endgroup\$ – HSchmale Mar 24 '15 at 19:57
  • 1
    \$\begingroup\$ 1. Test data which only covers one possible output isn't test data. I can write a program which always outputs Y in as little as one byte and it will pass all of the linked "test data", but it comes nowhere near to meeting spec. 2. Unless you specify which rhyme/stress dictionary to use, you can't guarantee that the test data is "correct". \$\endgroup\$ – Peter Taylor Mar 24 '15 at 20:20
  • \$\begingroup\$ @PeterTaylor I added examples of what is not a Sonnet. \$\endgroup\$ – HSchmale Mar 24 '15 at 20:32
  • 1
    \$\begingroup\$ I'm not sure how to say this, but it feels as though this task has a lot of individual parts, each of which could be quite tricky. Especiallly detecting rhymes/syllables/stresses, since words can be pronounced/stressed differently based on context. Also if you're using Shakespeare's sonnets I have no idea where to get rhyming and stress dictionaries for Elizabethan English... \$\endgroup\$ – Sp3000 Mar 25 '15 at 14:18
  • \$\begingroup\$ To make this interesting, you'll need some interesting near-misses: non-sonnets that can't be detected by something simple like counting lines or words per line. \$\endgroup\$ – xnor Mar 25 '15 at 20:59
  • \$\begingroup\$ @xnor You mean a file with a that looks like a sonnet but has no rhyme. \$\endgroup\$ – HSchmale Mar 25 '15 at 21:04
  • \$\begingroup\$ Yes, for example. Or, one with rhyme by wrong rhythm. Or, one with nonsense characters that seem to "rhyme". \$\endgroup\$ – xnor Mar 25 '15 at 21:06
  • \$\begingroup\$ @Sp3000 You can just use modern english, or just base it on words that have similar endings. \$\endgroup\$ – HSchmale Mar 25 '15 at 21:11

Complicating Simple Maths

We do know what 1 + 1 is, or 2 - 1. How about we turn those and other really simple operations into complex numbers?


As stated in the intro, taking an operation that can be done within the range of the following operators ( +, -, /, *, ^ and () ), print out a complex number operation that is pretty much a transformed version, and when done using the order of operations, results in the same answer as the inputted operation.


Input: 5 - 1
Output: 5 + 2i

Input: 4 * (7 ^ 2)
Output: (4 * 4i) * (7 ^ 2) 


  • It is recommended you print out the sector(s) that holds your complex number(s) as a + bi, e.g. (a + bi) - (ci * (di ^ f)). (NOTE: If you are doing non-communicative operations, such as ^, /, or -, the recommendation doesn't apply to the sub-operation).

  • No standard loopholes.

  • If you want to, feel free to use operations/functions other than the set mentioned in the Goal, but your input operation must have at least one of them.

  • You can format your operators in any way, e.g. x or • instead of *, ÷ instead of /, etc.

  • Input and output is allowed in any format as long as it fits within the standard I/O rules.

  • Input must also be flexible (as in to return any input from a simple operation to a complex number operation.

  • This is , so shortest answer wins.

Sandbox use only:

Is there any way I can improve this challenge? Are there any other loopholes to be covered in the rules?

| |
  • \$\begingroup\$ Can you relax output to standard IO too? At the moment it seems you can only print the result. Also isn't this essentially calculate the result of the inputted expression then work out a complex expression that gives the same answer seeing as you don't need to keep anything in the input the same. \$\endgroup\$ – TheLethalCoder Aug 7 '17 at 10:32
  • 3
    \$\begingroup\$ And if that is the case isn't this challenge just return input + (1 + i^2)? \$\endgroup\$ – TheLethalCoder Aug 7 '17 at 10:33
  • \$\begingroup\$ No, the challenge is to transform parts of the input into complex numbers and output that. \$\endgroup\$ – S.G. Harmonia Aug 7 '17 at 13:13
  • 1
    \$\begingroup\$ But 5 - 1 becomes 5 + 2i You are removing two stages - and 1 and adding 2 + and 2i. It's not entirely clear how much you can remove and how much you can add. \$\endgroup\$ – TheLethalCoder Aug 7 '17 at 13:15
  • \$\begingroup\$ At least one sub-operation should be transformed from simple to complex (which could take two steps). \$\endgroup\$ – S.G. Harmonia Aug 7 '17 at 13:16

Golf Cubically code

Your task is to optimize Cubically source code using one or more optimizations in this post.

How this challenge works:

  • You will choose one or more optimizations below and write a program (in the language of your choice) that performs those optimizations on a Cubically program.
  • Your program will take a Cubically program as input using any allowed input methods, and output a Cubically program using any allowed output methods.
  • The first answer to successfully perform all optimizations wins!


1. Face turn arguments

Before a face turn is performed, the interpreter calculates turns = turns mod 4. So R5 would be equivalent to R1 which is equivalent to R, R7 is equivalent to R3 which is equivalent to R', etc. Also note that R11111 is equivalent to R5, and R22 is equivalent to nothing at all.

Performing this optimization will mean evaluating all arguments to an R, L, U, D, M, E, or S command and shortening them as much as possible.

Test cases:

Relevant code -> Optimization
R11           -> R2
R1            -> R
L33           -> L2
U22           ->
D222          -> D2
M11111        -> M
E00001        -> E
S9            -> S

2. Repeated face turn

When multiple calls to the same face turn command are present right next to each other, they can clearly be golfed. For example, R2R1 is equivalent to R3. UUU is equivalent to U3. F2F2F2F2 is equivalent F8.

Test cases:

Relevant code -> optimization
R2R2R2        -> R6            (R2 if you also choose optimization 1)
LLL           -> L3
UU            -> UU or U2
D3D2D1        -> D6            (D2 if you also choose optimization 1)

3. "Set notepad to" commands

There are some commands that, instead of adding to/subtracting from/multiplying by/dividing by the notepad, just assign to it. Here are all such commands:


When called with multiple arguments, since each argument calls the command separately, only the final argument is relevant. So =123 is equivalent to =3, _00000 is equivalent to _0, and :12345678987654321 is equivalent to 1.

Test cases:

Relevant code -> Optimization
_333          -> _3
=12321        -> =1
+54321        -> +54321
:55           -> :5
/55           -> /55

4. Repeated non-face-turn commands

When multiple face turn commands are present right by each other, their arguments can simply be added together. Commands do not act this way. While R2 calls R with 2, =2 calls = with the face sum of the front face (face index 2).

To perform this optimization, when multiple commands outside of RLUDFBMES appear next to each other, simply remove the duplicated commands without removing the arguments.

Relevant code -> Optimization
_1_1_1_1      -> _1111         (_1 if you also choose optimization 3)
%11%22%33     -> %112233       (%3 if you also choose optimization 3)
+12345+67+8   -> +12345678

5. Nonexistent commands

Go check out the Cubically commands page and you'll see that there are plenty of characters that are not commands. For example, there are no commands that are lowercase letters.

To perform this optimization, remove all nonexistent commands and their arguments from the Cubically source. If the commands also have arguments, you must remove the arguments so that they are not passed to the previous command.

Test cases:

Relevant code -> Optimization
moo cow moo   -> 
moo2cow2moo   -> 
misteR2 FOO   -> R2F
FEAR ME.      -> ERME
u1U2u3U4u5U6  -> U2U4U6   (nothing if you also choose optimization 1, U12 if you also choose optimization 2)

6. Non-implicit commands

There are lots of implicit commands in Cubically (RLUDFBMES()$~&E!), but there are plenty that need to be called with arguments. So %%%% is equivalent to nothing at all while %%2%% is equivalent to %2.

Test cases:

Relevant code -> Optimization
%%%%          -> 
$$$$          -> $$$$
++2++2++2     -> +2+2+2                 (+222 if you also choose optimization 4)
+++>--<-      -> Not Brainf**k, sorry!  (:P)


I'll add more optimizations later.

| |
  • \$\begingroup\$ Clarification on R123: That's the same as R6 and R2, not R3, right? Digits are summed, there are multidigit numbers? That would be better to specify \$\endgroup\$ – isaacg Aug 17 '17 at 20:13
  • \$\begingroup\$ A few things: first, I can't find the tag "fgitw", is there a typo? Second, does optimization 1 require handling F and B as well, or just the currently listed ones? Third, in optimization 3 most of the listed commands seem invalid because the notepad is used in calculation and then overwritten with the output; for example =11 is not the same as =1 in most circumstances. In fact, I think only _: are valid. Fourth, is the winning answer one which performs all optimizations in a single program, or one which contains a separate program for each optimization? \$\endgroup\$ – Kamil Drakari Aug 18 '17 at 18:03

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.



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"


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


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.

| |
  • \$\begingroup\$ 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. \$\endgroup\$ – Peter Taylor May 24 '17 at 6:15
  • \$\begingroup\$ @PeterTaylor Good notes. I will likely restrict the character set. I just wanted to start getting ideas down in the sandbox. \$\endgroup\$ – Poke May 24 '17 at 6:51
  • \$\begingroup\$ Very ambiguous. \$\endgroup\$ – dkudriavtsev May 25 '17 at 17:48
  • \$\begingroup\$ @Mendeleev It's not done yet. I'm aware it's ambiguous. \$\endgroup\$ – Poke May 26 '17 at 16:10
  • \$\begingroup\$ 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? \$\endgroup\$ – Peter Taylor Sep 16 '17 at 17:28
  • \$\begingroup\$ @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 :] \$\endgroup\$ – Poke Sep 16 '17 at 18:57
  • \$\begingroup\$ Downvoter, why? \$\endgroup\$ – Poke Oct 4 '17 at 21:03

Shift-left golfer

Sometimes when doing code-golf, a person needs to understand which format is shorter:

  • 2147483648
  • 0x80000000
  • 1<<31

The task:

You will receive a number in one of the three formats above: decimal, hexadecimal, or shift-left operation. If there is no advantage in converting it to another format, just leave the number the way it is; otherwise I want the shortest format. Of course there are numbers you can't convert to shift-left format!


  • Hexadecimal0x#######.... where there are no leading zeros after the x. When accounting for evaluating the golfiness, the 0x part is also taken into consideration. For example 0x80000000 has a length of 10.

  • Decimal#######.... where there are no leading zeros.

  • Shift-left#...<<#.... no leading zeros both sides of <<. The << operator is also considered for length, e.g 1<<31 has a length of 5. You must also handle multiple digits before the << signal.

# represents a digit and ... represent possible repetition of digits

I don't care if you handle leading zeros at the input or not; but if you handle them, you must do the comparison operations without them and output also without them — You're a golfer, come on! You will understand!

There will be no accepted answer.

, so I want to know shortest answer by language.


In spite of @dzaima 's comment, now it also needs to handle multiple digits before << signal.

| |
  • 1
    \$\begingroup\$ How about just take an integer as input and return the shortest form as output? \$\endgroup\$ – HyperNeutrino Sep 15 '17 at 19:20
  • \$\begingroup\$ 1<<31 has a length of 4 not 5? \$\endgroup\$ – Rɪᴋᴇʀ Sep 15 '17 at 22:38
  • \$\begingroup\$ @Riker: Sorry, my mistake. Now fixed. \$\endgroup\$ – sergiol Sep 15 '17 at 22:59
  • \$\begingroup\$ @dzaima: Updated. Yes, it will need to handle multiple digits before << \$\endgroup\$ – sergiol Sep 16 '17 at 11:07
  • \$\begingroup\$ If you allow non-ones in front of the byte shift as input, but not as output, an input like 99<<99 would result in the output having more bytes than the input. \$\endgroup\$ – Jonathan Frech Sep 18 '17 at 5:23
  • \$\begingroup\$ What about something like 0x45<<0x378? i.e., why not hex numbers in left-shifts? \$\endgroup\$ – wastl Jul 7 '18 at 20:38

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?

| |
  • \$\begingroup\$ -1 language restriction, most languages have HTTP libraries so I think any language should be allowed \$\endgroup\$ – ASCII-only Sep 24 '17 at 13:11
  • \$\begingroup\$ 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? \$\endgroup\$ – 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
    \$\begingroup\$ -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"? \$\endgroup\$ – Shaggy Sep 30 '17 at 0:55

Is it a perfect loop?

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.


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.


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.


  • 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.
| |
  • \$\begingroup\$ 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? \$\endgroup\$ – tuskiomi Oct 17 '17 at 21:15
  • \$\begingroup\$ 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. \$\endgroup\$ – japh Oct 18 '17 at 14:31

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.


  • 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.
| |
  • \$\begingroup\$ The rule only leads to totally locked code \$\endgroup\$ – l4m2 Mar 13 '18 at 0:13
  • \$\begingroup\$ @l4m2 hah. I disagree. \$\endgroup\$ – Magic Octopus Urn Mar 13 '18 at 0:58
  • \$\begingroup\$ But more constructively, increase the penalty? Limit locked chars? \$\endgroup\$ – Magic Octopus Urn Mar 13 '18 at 1:04
  • \$\begingroup\$ Maybe require an unlocked percent? \$\endgroup\$ – l4m2 Apr 6 '18 at 10:52

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");}
  return result.join("\n");


{"boolean": true}

What is passed to magic function?

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

| |
  • 5
    \$\begingroup\$ This site is for programming contests, not pure programming puzzles. Thanks for using the sandbox, anyway. \$\endgroup\$ – user202729 Feb 1 '18 at 12:11
  • 7
    \$\begingroup\$ 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. \$\endgroup\$ – AdmBorkBork Feb 1 '18 at 14:02
  • \$\begingroup\$ ... someone said that I'm wrong. Anyway people definitely doesn't like this. \$\endgroup\$ – user202729 Feb 1 '18 at 14:02
  • \$\begingroup\$ @AdmBorkBork this is JS \$\endgroup\$ – Евгений Новиков Feb 1 '18 at 14:41
  • 3
    \$\begingroup\$ @ЕвгенийНовиков what JS version is this? in is a keyword, and can't be a variable name. \$\endgroup\$ – dzaima Feb 1 '18 at 14:47
  • \$\begingroup\$ @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... \$\endgroup\$ – user202729 Feb 1 '18 at 14:51
  • \$\begingroup\$ "Programming Puzzle" is in the name of the site @user202729 \$\endgroup\$ – dylnan Feb 1 '18 at 15:46
  • \$\begingroup\$ @dylnan But... \$\endgroup\$ – user202729 Feb 1 '18 at 15:55
  • \$\begingroup\$ @AdmBorkBork is correct. We do allow programming puzzles. \$\endgroup\$ – Nathan Merrill Feb 1 '18 at 16:25
  • \$\begingroup\$ @NathanMerrill Then just upvote the comment. \$\endgroup\$ – user202729 Feb 2 '18 at 5:34
  • \$\begingroup\$ 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. \$\endgroup\$ – user202729 Feb 2 '18 at 5:34
  • \$\begingroup\$ @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. \$\endgroup\$ – Nathan Merrill Feb 2 '18 at 5:51
  • 2
    \$\begingroup\$ 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. \$\endgroup\$ – Peter Taylor Feb 2 '18 at 12:04
  • \$\begingroup\$ @dzaima sorry, fixed this. Now input variable is input \$\endgroup\$ – Евгений Новиков Feb 3 '18 at 7:40
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – Shaggy Feb 3 '18 at 19:20
84 85
87 88

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .