572
\$\begingroup\$

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

Sandbox FAQ

Posting

To post to the sandbox, scroll to the bottom of this page 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, though you can optionally add a title at the top. You may also add some notes about specific things you would like to clarify before posting it. Other users will help you improve your challenge by rating and discussing it.

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

Discussion

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

  • Parts of the challenge you found unclear
  • Comments addressing specific points mentioned in the proposal
  • Problems that could make the challenge uninteresting or unfit for the site

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

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

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

Other

Search the sandbox / Browse your pending proposals

The sandbox works best if you sort posts by active.

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

\$\endgroup\$
0

4667 Answers 4667

6
\$\begingroup\$

PPCG Handwriting OCR

(insert logo here once I make it)

Given an image consisting of handwritten text, output the text that is written. The image of the handwritten text will be generated by taking characters from one or more handwriting samples given by PPCG users.

Rules

  • You may not hardcode your program to only recognize the samples in the corpus.
  • There will be sufficient spacing between characters to avoid ambiguity.
  • Only ASCII alphanumeric characters (those matching the regex [A-Za-z0-9], i.e. uppercase and lowercase English letters and digits) will be present in the input.
  • Inputs will be formed by concatenating individual characters from the handwriting samples.
  • The test cases used for scoring may be modified at any point if I feel it is necessary to do so. Reasons may include but are not limited to: needing more test cases to have a single winner, removing problematic test cases, and fixing errors in test cases.

Aside from the above considerations, there are no guarantees on the appearance of the handwriting, as these are actual handwriting samples and thus can have drastic variances.

Score

Your score will be the number of test cases that are correctly recognized, divided by the total number of test cases. The highest score wins. In the event of a tie, the first submission to reach the high score wins. Additional test cases may be added to break ties.

Handwriting Samples

This Imgur album contains the handwriting samples, as well as the names of the users who contributed them.


I've made a chat room for submitting handwriting samples. The more samples I get, the better this challenge will be, so please take a few minutes and submit a sample!

\$\endgroup\$
14
  • \$\begingroup\$ You may not hardcode your program to only recognize the samples in the corpus.: Can we tailor our code to be better for the samples than other inputs though? \$\endgroup\$ Aug 2, 2017 at 16:08
  • \$\begingroup\$ The test cases used for scoring may be modified at any point: Will current answers be modified? \$\endgroup\$ Aug 2, 2017 at 16:09
  • 1
    \$\begingroup\$ @TheLethalCoder 1) No. 2) Answers will be run on the test cases any time the answer or the test cases change, and the scores will be updated accordingly. \$\endgroup\$
    – user45941
    Aug 2, 2017 at 16:11
  • \$\begingroup\$ Hadn't seen that loophole before :) \$\endgroup\$ Aug 2, 2017 at 16:13
  • \$\begingroup\$ Can I nitpick again and say handwriting OCR is called ICR? :P \$\endgroup\$ Aug 3, 2017 at 9:06
  • \$\begingroup\$ Can you add an example input as well? \$\endgroup\$ Aug 3, 2017 at 9:07
  • 2
    \$\begingroup\$ @TheLethalCoder 1) ICR is when a program tries to learn what handwriting looks like via machine learning. OCR is just parsing written/text input into data. This is OCR, not ICR. 2) I'll add some examples once I get more samples and finish writing my generator. \$\endgroup\$
    – user45941
    Aug 3, 2017 at 9:08
  • \$\begingroup\$ Can you assume a minimum height for the characters? \$\endgroup\$ Aug 3, 2017 at 9:28
  • \$\begingroup\$ @TheLethalCoder Aside from the above considerations, there are no guarantees on the appearance of the handwriting, as these are actual handwriting samples and thus can have drastic variances. \$\endgroup\$
    – user45941
    Aug 3, 2017 at 9:29
  • \$\begingroup\$ To be honest with no restrictions this is going to be very hard, Do you lose points for returning extra information? Assume the input Hello if I return H.e.l.l.o. is that 100% for that test case or do I lose and get something like 50%? \$\endgroup\$ Aug 3, 2017 at 9:31
  • \$\begingroup\$ And does the output have to be in the correct order? \$\endgroup\$ Aug 3, 2017 at 9:58
  • \$\begingroup\$ @TheLethalCoder It's all or nothing. Getting 100% on a test battery challenge should be hard. \$\endgroup\$
    – user45941
    Aug 3, 2017 at 9:58
  • \$\begingroup\$ Please update imgur album \$\endgroup\$
    – Pavel
    Sep 18, 2017 at 4:28
  • \$\begingroup\$ @Pavel I will once I finish cutting up the images. My free time has been limited these past few weeks. \$\endgroup\$
    – user45941
    Sep 18, 2017 at 4:29
6
\$\begingroup\$

2 Spooky 4 Me

In terms of halloween, some things are just too spooky for me... Feel like we need some serious doots from skeletons to fuel our hallowed weens. So, in the spirit of that end, print the following, exactly as it is shown, if and only if the input does not equal "DOOT" (in all caps ONLY):

               _.---._
             .'       '.
             :)       (:
             \ (@) (@) /
              \   A   /
               )     (
               \"""""/
                '._.'
                 .=.
         .---._.-.=.-._.---.
        / ':-(_.-: :-._)-:' \
       / /' (__.-: :-.__) '\ \
      / /  (___.-' '-.___)  \ \
     / /   (___.-'^'-.___)   \ \
    / /    (___.-'='-.___)    \ \
   / /     (____.'='.____)     \ \
  / /       (___.'='.___)       \ \
 (_.:       '---'.=.'---'       :._)
 :||        __  _.=._  __        ||:
 :||       (  '.-.=.-.'  )       ||:
 :||       \    '.=.'    /       ||:
 :||        \    .=.    /        ||:
 :||       .-'.'-._.-'.'-.       ||:
.:::\      ( ,): O O :(, )      /:::.
|||| '     / /''--'--''\ \     ' ||||
''''      / /           \ \      ''''
         / /             \ \
        / /               \ \
       / /                 \ \
      / /                   \ \
     / /                     \ \
    /.'                       '.\
   (_)'                       '(_)
    \\.                       .//
     \\.                     .//
      \\.                   .//
       \\.                 .//
        \\.               .//
         \\.             .//
          \\.           .//
          ///)         (\\\
        ,///'           '\\\,
       ///'               '\\\
      ""'                   '""

However, if the input DOES equal "DOOT", in all caps only, print this instead:

               _.---._
             .'       '.
             :)       (:
             \ (@) (@) /
              \   A   /
               )     (
               \"""""/
                '._.'          ' ''''    _''|
                 .=.       @=====***===::_  |
         .---._.-.=.-._.---. (( \-@|_) )) `.|
        / ':-(_.-: :-._)-:' \ ]--------'"
       / /' (__.-: :-.__) '\ \   ||:
      / /  (___.-' '-.___)  \ \  ||:
     / /   (___.-'^'-.___)   \ \ ||:
    / /    (___.-'='-.___)    \ \||:
   / /     (____.'='.____)     \ ||:
  / /       (___.'='.___)       \||:
 (_.:       '---'.=.'---'       :._)
 :||        __  _.=._  __       
 :||       (  '.-.=.-.'  )      
 :||       \    '.=.'    /       
 :||        \    .=.    /      
 :||       .-'.'-._.-'.'-.       
.:::\      ( ,): O O :(, )   
|||| '     / /''--'--''\ \    
''''      / /           \ \
         / /             \ \
        / /               \ \
       / /                 \ \
      / /                   \ \
     / /                     \ \
    /.'                       '.\
   (_)'                       '(_)
    \\.                       .//
     \\.                     .//
      \\.                   .//
       \\.                 .//
        \\.               .//
         \\.             .//
          \\.           .//
          ///)         (\\\
        ,///'           '\\\,
       ///'               '\\\
      ""'                   '""

Rules

  • Trailing newlines and spaces are allowed.
  • The design is horizontally symmetric, if you find inconsistencies let me know.

Doot it up, and enjoy!


(Yes, I'm going to make it more official when posting on the actual SE)

\$\endgroup\$
2
  • 4
    \$\begingroup\$ What about this challenge ensures that the same old techniques won't be the best ones (i.e. that it adds value to the site)? \$\endgroup\$ Oct 13, 2017 at 23:01
  • 2
    \$\begingroup\$ @PeterTaylor worse? Better? 10x worse? 10x better? I don't really know what makes the challenge unique beyond a formal proof that it is, but if the users enjoy it; why not allow it... current event challenges attract new users. \$\endgroup\$ Oct 16, 2017 at 23:03
6
\$\begingroup\$

Check equation proofs in a ring

The recent to prove that (-a)×(-a) = a×a attracted a number of faulty submissions, because there wasn't an easy way to verify the proofs. So, let's write some proof checkers.

Input

Your program should take a sequence of strings representing expressions in a ring. Valid expressions consist of:

  • Single-lowercase-letter variables (a to z)
  • Two constants: the additive identity 0 and multiplicative identity 1
  • Compound expressions: (X+Y), (X*Y) and (-X), where X and Y stand for subexpressions. (The parentheses must always be present, and there must be no whitespace.)

Task

Your program should check whether:

  • All strings except the first and last represent valid expressions.
  • Each expression (after the first) can be obtained from the preceding expression, by substituting one of the ring axioms in the expression exactly once.

Output truthy if these conditions are met. Otherwise, output falsey.

You may assume that the first and last strings in the input are valid expressions. But your program must check the intermediate strings.

The ring axioms

For this challenge, use the following substitution rules (and do not use any others). Substitutions can go both left-to-right and right-to-left.

  1. (X+(Y+Z)) = ((X+Y)+Z)

  2. (X+0) = X

  3. (X+(-X)) = 0

  4. (X+Y) = (Y+X)

  5. (X*(Y*Z)) = ((X*Y)*Z)

  6. (X*1) = X

  7. (1*X) = X

  8. (X*(Y+Z)) = ((X*Y)+(X*Z))

  9. ((X+Y)*Z) = ((X*Z)+(Y*Z))

Scoring

Proof checkers are traditionally small, so that people can review them easily. Therefore, your program should be written in as few bytes as possible.

Meta comments

Is the input format fair for most languages and approaches?

Usually, code-golf problems should not require input validation. However, I thought it would be appropriate behaviour for a proof checker. I think the current spec still accommodates regex-based solutions.

The format for the original challenge also listed which axiom was used for each step. I could include this but I doubt that it improves the challenge much.

Test cases

Valid proofs

(0+a)
(a+0)
a

(a*(-1))
((a*(-1))+0)
((a*(-1))+(a+(-a)))
(((a*(-1))+a)+(-a))
(((a*(-1))+(a*1))+(-a))
((a*((-1)+1))+(-a))
((a*(1+(-1)))+(-a))
((a*0)+(-a))

Invalid proofs

These proofs are missing intermediate steps.

(0+a)
a

(-0)
((-0)+0)
0

((a*0)+(-a))
(0+(-a))

This is simply untrue, so no proof should ever be accepted.

(a*b)
(b*a)

Invalid expressions

Your proof checker should reject if these appear partway through a proof.

a+b

(a+-b)

(a + b)

1+

42
\$\endgroup\$
1
  • 1
    \$\begingroup\$ You should include the ring axioms to make the post self-contained. \$\endgroup\$
    – Laikoni
    Oct 18, 2017 at 16:23
6
\$\begingroup\$

ASCII Stock Exchange

At the ASCII Stock Exchange, each character has a price. If a character is used more often, its price rises, otherwise the price decreases over time.

Initially, each character has price 10. [Meta: Is this too low/high?] After each answer, the prices change as follows:

  • Each character that is not used in the answer's code has its price decreased by one, except when the price is already one, in which case it stays one.
  • If a character is used n-times, then its price increases by n.

We define the score of a piece of code as the sum of the prices of its characters.

Example

For the sake of simplicity, we only consider characters A, B and C for this example. The challenge itself works with all bytes from \0 to \255. Initially, we have the following prices:

A -> 10, B -> 10, C -> 10

If the code of the first answer is BAAA, then is has a score of 40 (computed by taking the previous character prices into account) and the prices change to

A -> 13, B -> 11, C -> 9

If the next answer is CC, it has a score of 18 and the prices are updated to

A -> 12, B -> 10, C -> 11

The Task

Your objective is to write a program or function which calculates the score of a given piece of code in dependence of a list of previous answers which all influence the initial prices in the way described above.

The goal is to do so while minimizing the submission's score itself in the context of this challenge, that is your submission should be able to calculate its own score by taking a list of all previous submissions and its own source code as input.

The answer with the lowest score in each language wins.

Rules

  • You may take a list of strings and a string as input, or require that the string to be scored is the first/last element of the list, or any other reasonable input format.
  • You may not answer twice in a row.
  • If an answer in language X has already been posted, you may only post another answer in language X if your submission achieves a lower score than the previous answer and the code is not identical.
  • For this challenge only major releases of languages are considered their own language (e.g. Java 7 vs. Java 8). If there already is an answer in version A of a language and you have an answer in version B of the language and are in doubt whether version B is different enough from version A to be treated as different language, make sure that your code is not valid in version A.

Answer Format

To avoid having to copy all previous answers in order to calculate your submission's score, the chain will maintain a score calculator on TIO. Click on the link to the calculator in the previous answer and enter your code into the input field to calculate its score. Then add your code as a command-line argument, generate a new link and include it in your answer for the next submission.

If you wrote answer number 42 in Haskell with a score of 100, please format it as

42. Haskell, score 100

 <code>

TIO-Link, explanation, ...

Score calculator for next answer

Test Cases

These test cases are in the format list of strings, string to score -> result.

[], "BAAA" -> 40
["BAAA"], "CC" -> 18
["abc"], "abc" -> 33
["ab12", "aa22", "31a"], "ac23" -> 42
["a","b","c","d","e","f","g","h","i","j"], "123" -> 3

Meta

  • Any idea what could be a good initial price? I picked the number 10 rather arbitrarily.
  • Letting the cost of unused characters decrease until 0 might lead to score 0 answers. Do you think this is a problem and the minimum cost should be 1? Minimum changed to 1.
  • I'm unsure what range of characters is a sensible choice. Limiting answers to printable ASCII plus white space would make things easier but also exclude a lot of languages. Another possibility would be to allow the whole byte range from \0 to \255. Then also golfing languages could participate, albeit to score them they would need to be converted to their byte form which usually contains a lot of unprintable characters. The score calculator is able to handle unprintables, but I don't know how to insert them into the text fields on TIO. All bytes from \0 to '\255' are allowed.
  • Is the winning criterion suitable for answer chaining?
  • A leader board snippet would be nice, but I don't know how to modify the existing ones. If someone could provide such a snippet, I would be very grateful.
  • Relevant tags?
\$\endgroup\$
4
  • 1
    \$\begingroup\$ I think decreasing the scores to 1 is more sensible, because otherwise I could write a submission using all (or even just one of) the zero-score characters a billion times (say, in a comment), keeping a "minimum" score, but then subsequent submissions would have completely absurd scores, and it'd be easy to outgolf later, leading to a boring answer chain. \$\endgroup\$
    – Giuseppe
    Oct 2, 2017 at 18:08
  • \$\begingroup\$ You may want to correct "enter your code into the input field to calculate its score. Then add your code as a command-line argument," \$\endgroup\$ Oct 2, 2017 at 19:55
  • 2
    \$\begingroup\$ I think allowing all 256 bytes is a good idea because languages like Jelly, 05AB1E, etc. will more than likely use more than the printable ASCII chars. \$\endgroup\$ Oct 2, 2017 at 20:30
  • 3
    \$\begingroup\$ "While in principal Python 2.7.14 and Python 2.7.13 are different languages according to the site rules, I recommend to avoid using the fact that it is technically allowed as an excuse to post boring answers." Recommendations do not work, especially when they're as imprecise as this. (Are you "recommending" not treating Python 2 and Python 3 as separate languages? I have no idea). If you want to ban boring exploitation of the convention on different interpreters, ban it outright, but give a clear definition of how lines should be drawn. \$\endgroup\$ Oct 2, 2017 at 21:21
6
\$\begingroup\$

Tower Builder

The king is coming to visit! Your city is competing with another neighboring city to attract his attention.

Each player owns their own tower within a city full of other players. Each turn you place 1 blocks on your tower or another tower in your city.

After 100 turns, the king will only visit the city with the highest tower. If he visits your city, then you will gain points equal to the number of blocks in your personal tower. In the case of a tie, neither city is visited.

Games include all players, and each game will randomly arrange players into cities. Your score is the total score across all games.

  • Player identifiers are randomly generated at the start of the tournament, but are consistent from game to game.
  • In addition, contrary to past KoTHs: I allow saving state from game to game (but not between tournaments)
  • You will always have complete information, including:
    • The size of everybody's towers (including the other city)
    • The actions players have taken
    • The current score of all players
\$\endgroup\$
13
  • \$\begingroup\$ How is always playing on the tallest tower in your city a bad strategy? Maybe the other city will do the same, but you won't lose. \$\endgroup\$
    – aschepler
    Jul 22, 2017 at 22:47
  • \$\begingroup\$ @aschepler because the number of points you get is height of your personal tower. If you only build on another's tower, and never your own, you'll never get any points. \$\endgroup\$ Jul 23, 2017 at 1:55
  • \$\begingroup\$ @NathanMerrill it took me a few minutes to understand what you even meant by that. you probably need to make this more clear \$\endgroup\$ Aug 7, 2017 at 0:24
  • \$\begingroup\$ If the points are only awarded to the player who is visited by the king, it would seem that putting 99 blocks on the city tower and 1 block on your personal tower guarantees victory, no? \$\endgroup\$ Jan 30, 2018 at 17:22
  • \$\begingroup\$ @AdmBorkBork there's no singular "city tower". Furthermore, you are still competing against the players in your city. Your score is your total score across many games. \$\endgroup\$ Jan 30, 2018 at 17:40
  • \$\begingroup\$ Oh, the part that I missed was that multiple players share a city. I think that should be made more clear because that will drastically change strategy. I read it as you have a personal tower and everyone also gets their own city with a separate tower, and it's only the city's tower that matters for the king. \$\endgroup\$ Jan 30, 2018 at 17:45
  • \$\begingroup\$ This needs some clarification about arrangement. The game will randomly arrange players into one of () cities, or a city with () others in it \$\endgroup\$
    – pfg
    Jan 30, 2018 at 19:10
  • \$\begingroup\$ @pfg It'll definitely be one of () cities, but I'm not sure how many. My intuition says "2", but I can't give a solid reason. Any suggestions? \$\endgroup\$ Jan 30, 2018 at 19:21
  • \$\begingroup\$ 2 or 3 per city or total cities? 3 seems good per city because with just two the strategy is much easier @Nathan Merrill \$\endgroup\$
    – pfg
    Jan 30, 2018 at 19:23
  • \$\begingroup\$ Hmmm...I'm thinking 100 players in 2 cities, and allow for duplicate entries. \$\endgroup\$ Jan 30, 2018 at 19:28
  • \$\begingroup\$ It seems to me that if you allow saving state you can simplify the last point to "You will be notified of the actions of every player" and let those who want to analyse it calculate the sizes of the towers, scores, etc. Normally I would favour supplying calculated information to save the players from re-implementing the game logic, but here the logic is simpler than the serialisation would be. \$\endgroup\$ Jan 31, 2018 at 8:43
  • \$\begingroup\$ @PeterTaylor I already provide complete information about the current game (including its history). The difference here is that you are allowed to persist information from game to game, meaning you can remember players who are antagonistic. \$\endgroup\$ Jan 31, 2018 at 15:04
  • \$\begingroup\$ My point is that the communication between the server and the bots would be simpler if you didn't provide that information, and you don't need to provide it because it can be calculated easily. \$\endgroup\$ Jan 31, 2018 at 15:07
6
\$\begingroup\$

Chess ASCII Art, Knight

In honor of the world chess championship, in the shortest possible program, output the following ASCII art piece

      ,....,
   ,::::::<
  ,::/^\"``.
 ,::/, `   e`.
,::; |        '.
,::|  \___,-.  c)
;::|     \   '-'
;::|      \
;::|   _.=`\
`;:|.=` _.=`\
  '|_.=`   __\
   `\_..==`` /
    .'.___.-'.
   /          \
  ('--......--')
  /'--......--'\
   "--......--"

This is a code-golf challenge

\$\endgroup\$
9
  • \$\begingroup\$ You might want to make sure all the lines are aligned properly (they could be fine, since I'm on mobile and I know it can display differently, but it looks bent to me). \$\endgroup\$
    – Οurous
    Nov 23, 2018 at 19:59
  • \$\begingroup\$ you're right, it was a little bent, I've reformatted it \$\endgroup\$
    – Thaufeki
    Nov 23, 2018 at 20:17
  • 2
    \$\begingroup\$ Seems straightforward enough \$\endgroup\$
    – Quintec
    Nov 24, 2018 at 1:23
  • \$\begingroup\$ lol, akin to image compression of pixel art in a very specific case :) I like the idea. \$\endgroup\$
    – alan2here
    Nov 24, 2018 at 22:22
  • \$\begingroup\$ The very worst is approx 145 bytes + "verbatim output this". Be fun to see much better ones :) \$\endgroup\$
    – alan2here
    Nov 24, 2018 at 22:33
  • 1
    \$\begingroup\$ Isn't the World Chess Championship already over? According to google it ended nov. 28th. ;) Did you forgot to post it? \$\endgroup\$ Dec 3, 2018 at 9:08
  • \$\begingroup\$ Yeah, I made this post on November 23rd, cross-posting from sandbox eventually slipped my mind \$\endgroup\$
    – Thaufeki
    Dec 3, 2018 at 14:42
  • \$\begingroup\$ @Thaufeki You could still post it, or are you going to wait a year? ;) \$\endgroup\$ Dec 4, 2018 at 10:22
  • \$\begingroup\$ I would have to wait two, next one isn't until 2020! I'll post it now \$\endgroup\$
    – Thaufeki
    Dec 4, 2018 at 14:43
6
\$\begingroup\$

Is this checkmate?

Input

A chess position in FEN format. You can assume the input is a valid chess position.

Output

Two distinct consistent outputs for checkmate or not.

Examples

enter image description here

8/8/8/8/8/5BKN/8/7k b - - 93 47
Mate

\$\endgroup\$
6
  • \$\begingroup\$ I suggest wording similar to “two distinct consistent outputs for checkmate or not” \$\endgroup\$
    – Quintec
    Mar 12, 2019 at 11:52
  • \$\begingroup\$ @Quintec Thanks. \$\endgroup\$
    – user9207
    Mar 12, 2019 at 11:58
  • 4
    \$\begingroup\$ I'd recommend keeping it all self-contained and having a description for the FFN format, as well as a few more test cases \$\endgroup\$
    – Jo King Mod
    Mar 12, 2019 at 21:41
  • 2
    \$\begingroup\$ Is restricted to the FFN format a part of the challenge? Why not allow it in any reasonable format? \$\endgroup\$
    – tsh
    Mar 13, 2019 at 5:47
  • \$\begingroup\$ @Quintec why not just say truthy or falsey? \$\endgroup\$
    – qwr
    Jun 20, 2019 at 14:48
  • \$\begingroup\$ I suggest removing the restriction to FEN format, as it doesn't really add anything to the challenge, and specifying that the output be a truthy or falsey value as that is the usual spec for these types of challenges. \$\endgroup\$ Aug 26, 2019 at 13:28
6
\$\begingroup\$

Lexicographically earliest valid UTF-8 byte sequence permutation

There are currently 1,114,112 possible Unicode characters (code points). Each character has a unique valid byte sequence in the UTF-8 encoding. Different characters have different length encodings:

  • ASCII characters have a 1-byte encoding 00-7F.
  • The next 1920 characters have a 2-byte encoding C2 80-DF BF.
  • The rest of the BMP has a 3-byte encoding E0 A0 80-ED 9F BF and EE 80 80-EF BF BF.
  • The other planes have a 4-byte encoding F0 90 80 80-F4 8F BF BF.

It's possible for two strings (specific non-normalised sequences of Unicode code points) of Unicode to have byte sequences that are permutations of each other in a number of ways:

  • One string could simply be a permutation of the other at the Unicode level, e.g. ab (61 62) and ba (62 61).
  • UTF-8 continuation bytes could be switched between two characters, e.g. ¡â (C2 A1 C3 A2) and ¢á (C2 A2 C3 A1).
  • UTF-8 continuation bytes could be switched within a character, e.g. (E1 B4 B5) and (E1 B5 B4).

For this challenge I would like you to write a program or function that finds the string whose UTF-8 byte sequence is lexicographically earliest of all such sequences that are permutations of the UTF-8 byte sequence of a given Unicode string.

For example, if your input is ᵴ¢ába (E1 B5 B4 C2 A2 C3 A1 62 61) your output would be ab¡âᴵ (61 62 C2 A1 C3 A2 E1 B4 B5).

Note however that some byte sequences are not valid UTF-8 (e.g. E0 80 A0 which is an overlong encoding for a space) so you need to take care to avoid these.

It would be helpful if your "Try It Online" or similar link includes a footer that helps demonstrate the correctness of your output, where this is not obvious from the I/O format or code.

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

\$\endgroup\$
20
  • 3
    \$\begingroup\$ For test cases, it will probably be a good idea to provide both strings and hex since I'd guess many languages will have to try both. Also this probably needs at least a link to an explanation of UTF8 continuation bytes. \$\endgroup\$ Jun 29, 2019 at 16:57
  • 1
    \$\begingroup\$ "permutation of its canonical" should be "permutation of the input's canonical". \$\endgroup\$ Jun 29, 2019 at 17:00
  • 1
    \$\begingroup\$ @FryAmTheEggman ... but I provided the hex? I'm not sure what I'm missing... \$\endgroup\$
    – Neil
    Jun 29, 2019 at 23:24
  • 1
    \$\begingroup\$ @EriktheOutgolfer How about "I would like you to write a program or function that returns the Unicode string whose canonical UTF-8 byte sequence is the lexicographically earliest of all such sequences that are permutations of the canonical UTF-8 byte sequence of a given Unicode string"? \$\endgroup\$
    – Neil
    Jun 29, 2019 at 23:27
  • 1
    \$\begingroup\$ I meant in the example that you actually had, and presumably some number of test cases. I only mentioned it because I thought it was odd that you did it in the explanation but not the example. \$\endgroup\$ Jun 29, 2019 at 23:54
  • \$\begingroup\$ @Neil Looks good. :) \$\endgroup\$ Jun 30, 2019 at 16:34
  • \$\begingroup\$ I'm wary of the use of the word "canonical" in this question, because it raises issues in my mind about normalisation of Unicode strings. I think that the intended challenge is really about byte arrays with constraints on the most significant bits, and I think it would be better to make that explicit (and to make the constraints explicit). \$\endgroup\$ Jul 2, 2019 at 11:16
  • \$\begingroup\$ @PeterTaylor There is that, but I wanted to exclude sequences such as E0 80 A0. \$\endgroup\$
    – Neil
    Jul 2, 2019 at 13:23
  • \$\begingroup\$ @Neil, I think there's a miscommunication here. I'm saying that instead of talking about Unicode strings the question should explicitly state the FSS-UTF constraints on byte sequences, and maybe rule out encoding UTF-16 surrogate codepoints and codepoints greater than 0x10FFFF. \$\endgroup\$ Jul 2, 2019 at 13:48
  • \$\begingroup\$ @PeterTaylor OK but I really wanted this to be a string question rather than a byte sequence question... \$\endgroup\$
    – Neil
    Jul 2, 2019 at 16:20
  • \$\begingroup\$ The problem then is dealing with the lexicographically first rearrangement of C3 A9 (é in normal form C) being 65 CC 81 (é in normal form D). \$\endgroup\$ Jul 2, 2019 at 16:29
  • \$\begingroup\$ @PeterTaylor Is that possible to do just by permuting the byte sequence? \$\endgroup\$
    – Neil
    Jul 2, 2019 at 16:34
  • \$\begingroup\$ No, and that's why I'm arguing that the question should be phrased in terms of byte sequences rather than strings. \$\endgroup\$ Jul 2, 2019 at 17:40
  • \$\begingroup\$ There’s a mistake in the example: á is C3A1 and ¡ is C2A1. Good challenge. From the sound of it I/O will be flexible; this seems sensible since it keeps it open to more languages. \$\endgroup\$ Jul 2, 2019 at 17:54
  • \$\begingroup\$ @PeterTaylor I wanted it to be clear that these byte sequences must be a valid UTF-8 encoding of a Unicode string. I've tried rewriting the question a bit... \$\endgroup\$
    – Neil
    Jul 2, 2019 at 23:55
6
\$\begingroup\$

Compose Fill In The Blanks

\$\endgroup\$
4
  • \$\begingroup\$ Can you add some test cases? \$\endgroup\$
    – MilkyWay90
    Jul 27, 2019 at 14:35
  • \$\begingroup\$ @MilkyWay90 Ok I added some \$\endgroup\$
    – Wheat Wizard Mod
    Jul 27, 2019 at 14:47
  • \$\begingroup\$ Okay, I give /support (also, you may want to add disallowing standard loopholes and using any default io method to finish it up) \$\endgroup\$
    – MilkyWay90
    Jul 27, 2019 at 14:48
  • 3
    \$\begingroup\$ @MilkyWay90 Those are already standard I am not going to be making my post any more cluttered with stuff that adds nothing. \$\endgroup\$
    – Wheat Wizard Mod
    Jul 27, 2019 at 14:53
6
\$\begingroup\$

Move arrows along a contour

Posted here

\$\endgroup\$
18
  • \$\begingroup\$ I've edited in a question since it needs 2D for clarity. \$\endgroup\$
    – Adám
    Jul 26, 2019 at 8:48
  • \$\begingroup\$ @Adám Only the arrows move. "+-|" always stay in place, or are "hidden" behind an arrow. So, you second example is correct (I deleted the first one) \$\endgroup\$ Jul 26, 2019 at 9:02
  • \$\begingroup\$ Continuing @Adám's question: Are shapes always separated by at least one space, or can they be next to each other like ++++\n++++, and we have to determine if it's a ++++\n++++ or +--+\n+--+ based on the directions the arrows are facing? I.e. is this a possible/valid input, and are those outputs correct? \$\endgroup\$ Jul 26, 2019 at 11:26
  • \$\begingroup\$ @GalenIvanov I didn't have anything but arrows move, and not it doesn't follow, because you couldn't tell what was behind the arrows, -s or +s which is what would make the two possible answers. \$\endgroup\$
    – Adám
    Jul 26, 2019 at 11:28
  • 1
    \$\begingroup\$ @KevinCruijssen Example 2 has two adjacent shapes with no (vertical) spacing. \$\endgroup\$
    – Adám
    Jul 26, 2019 at 11:29
  • \$\begingroup\$ @Adám Ah, you're right. As for your question however, you'd still know +<<+\n+>>+ is +--+\n+--+ due to the directions of the arrows in combination with the rule "when an arrow is on a corner, it keeps its current direction and changes it only after the turn is taken". See the pastebin in my previous comment for some test cases where you do know it's ++++\n++++ instead, because of the arrow directions. +^<+\n+>v+ will be two ++++\n++++ boxes, but +<<+\n+>>+ will be one +--+\n+--+ box. \$\endgroup\$ Jul 26, 2019 at 11:37
  • \$\begingroup\$ @KevinCruijssen Good point, but OP actually never says that the input is an obtainable state, though it does make sense. I still have a feeling that there could be ambiguous cases. \$\endgroup\$
    – Adám
    Jul 26, 2019 at 11:41
  • 1
    \$\begingroup\$ @KevinCruijssen The shapes will always be separated by at least one space, I'll add it to the description. \$\endgroup\$ Jul 26, 2019 at 11:44
  • \$\begingroup\$ @GalenIvanov Probably better indeed to not have to deal with confusing ambiguous cases. In that case I would also have at least a newline separation, so test case 2 should be slightly modified. :) \$\endgroup\$ Jul 26, 2019 at 11:45
  • \$\begingroup\$ @Adám Oh, I see - indeed I need to correct the second case to have a vertical space between the shapes. \$\endgroup\$ Jul 26, 2019 at 11:51
  • 2
    \$\begingroup\$ Even single tracks can be incredibly difficult: [" ++ ","++++","++^+"," ++ "] only has one possible output: [" ++ ","++++","+++>"," ++ "] \$\endgroup\$
    – Adám
    Jul 26, 2019 at 11:55
  • 2
    \$\begingroup\$ @AdámYes, this is the only output. Do you think a condition that sharp turns are forbidden will help? (this means no two + can be adjacent) \$\endgroup\$ Jul 26, 2019 at 12:21
  • 1
    \$\begingroup\$ @GalenIvanov Maybe that's indeed better to reduce confusion and make the challenge someone more manageable. Although you can still deduct the solution in Adam's comment above, having no spaces inside the space makes it rather difficult to parse correct. Always having at least one |/- between two + will always give the shapes always spaces, making it easier to parse individual shapes. In which case Adam's one would become [" +-+ "," | | ","+-+ +-+","| |","+-+ ^-+"," | | "," +-+ "] -> [" +-+ "," | | ","+-+ +-+","| |","+-+ +>+"," | | "," +-+ "] \$\endgroup\$ Jul 26, 2019 at 13:55
  • \$\begingroup\$ @KevinCruijssen Thanks, I added clarification. \$\endgroup\$ Jul 26, 2019 at 14:09
  • 1
    \$\begingroup\$ @GalenIvanov Maybe also change the one Adam edited in, since it's still with ++ below one-another. :) \$\endgroup\$ Jul 26, 2019 at 15:08
6
\$\begingroup\$

Posted here

\$\endgroup\$
12
  • \$\begingroup\$ I found a lot of similar questions, but not quite the same. Would it be considered a duplicate? \$\endgroup\$
    – Jitse
    Aug 1, 2019 at 8:17
  • \$\begingroup\$ we've had double factorial closed before as a dupe of the vanilla factorial question \$\endgroup\$
    – Giuseppe
    Aug 1, 2019 at 12:03
  • 1
    \$\begingroup\$ @Giuseppe Thanks! I found that post, but I thought the variable factorial range might make it considerably different from the original challenge. \$\endgroup\$
    – Jitse
    Aug 1, 2019 at 12:12
  • \$\begingroup\$ Can we take input as two integers? \$\endgroup\$
    – Adám
    Aug 1, 2019 at 12:49
  • \$\begingroup\$ Can you give a definition for the multi-factorials above 2? \$\endgroup\$
    – MilkyWay90
    Aug 2, 2019 at 4:55
  • \$\begingroup\$ @Adám That makes the challenge somewhat easier, but I suppose it is fair. I added the other input option. \$\endgroup\$
    – Jitse
    Aug 2, 2019 at 7:04
  • \$\begingroup\$ @MilkyWay90 Yes! Totally skipped that part, oops. Is it clear enough like this? \$\endgroup\$
    – Jitse
    Aug 2, 2019 at 7:05
  • 1
    \$\begingroup\$ @KevinCruijssen Input numbers can be in any format, of course. I thought this was included in the default I/O rules, buy I will specify this in the challenge. \$\endgroup\$
    – Jitse
    Aug 2, 2019 at 12:39
  • \$\begingroup\$ @KevinCruijssen In the input, at least one factorial sign is expected, i.e. a positive integer. I suppose the correct return value for a factorial number of zero would just be the base, but as the challenge is to calculate a factorial, this seems like an unreasonable restriction. The same goes for a factorial number lager than the base. If the factorial number is equal to the base, the base should be returned as per the generalized formula. I will add additional examples to clear this up. Thanks for the feedback! \$\endgroup\$
    – Jitse
    Aug 2, 2019 at 12:39
  • \$\begingroup\$ @KevinCruijssen The range(start,stop,step) function in Python 3 returns a generator with an initial value of start (or 0 if not specified) and a final value of stop-1. For example, the list representation of range(1,4) is [1,2,3]. If this list is sliced as [1,2,3][::-1], the returned list is [3,2,1], which can also be achieved with range(3,0,-1). When the slicing operator is applied to the generator directly, a new generator is returned which generates the sliced list instead. Does that answer your question? Also, range(420,0,-30) would be a cleaner approach in this case. \$\endgroup\$
    – Jitse
    Aug 2, 2019 at 13:08
  • \$\begingroup\$ @Jitse Ah ok, now it makes more sense. I indeed knew range(1,4) is [1,2,3]. And I also knew [::-1] reverses the order, since I see it used in answers every now and then. Seeing the range(1,4)[::-1] == range(3,0,-1) now I'm not sure why I didn't see it myself when I asked you the question. And yes, range(value,0,-n) would indeed be clearer than range(1,value+1)[::-n]. ;) \$\endgroup\$ Aug 2, 2019 at 13:24
  • \$\begingroup\$ Seems good except maybe you should specify that \$n!^{(k)} = n\underbrace{!\ldots!}{k}\$ (n!^{(k)} = n\underbrace{!\ldots!}{k}) \$\endgroup\$
    – MilkyWay90
    Aug 2, 2019 at 16:47
6
\$\begingroup\$

Cliquish Program

Challenge: Write a program that accepts a character (or byte, see additional information) as input. Then:

  1. If the character is contained within the source code, output a different character also in your source code.
  2. If the character is not contained within the source code, output a different character also not in your source code.

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

Additional Information

  • Your program must consist of at least 2 distinct characters.
  • Your program must have at least 2 possible outputs.
  • Your program does not have to be deterministic; it may output a character at random (with any distribution), so long as it conforms to the above criteria.
  • Your program may optionally take a byte as input instead of characters. If you do, the code page the input is written in must contain at least each distinct byte in the source code, as well as at least two different bytes not in the source code.
  • You may take input and give output in any reasonable way. For example, you may take input as a function parameter, a command-line argument, a line from STDIN, a triple-nested array containing a single character, etc. You could output via return value, STDOUT, exit code (if applicable), fax output, etc. The input and output formats must be consistent, however.
  • Your output can only consist of the required character, optionally followed by one trailing newline. Prompt information (such as ans =) is exempt from this rule; such unpreventable output is acceptable.
\$\endgroup\$
5
  • 2
    \$\begingroup\$ Slightly more interesting than most generalised quines. Have you checked quine for dupes? \$\endgroup\$ Aug 2, 2019 at 7:32
  • 1
    \$\begingroup\$ @PeterTaylor related related related. I couldn't find any exact dupes. \$\endgroup\$ Aug 2, 2019 at 19:39
  • \$\begingroup\$ What if your program contains all but one possible character? What encoding are the characters in? UTF-8? latin-1? ASCII? \$\endgroup\$
    – Beefster
    Aug 2, 2019 at 20:18
  • \$\begingroup\$ @Beefster Hopefully I've addressed your first question. As per your second, I believe we have a standard consensus on what a character is \$\endgroup\$ Aug 11, 2019 at 18:13
  • \$\begingroup\$ By induction the program must have 4 possible outputs. Inside/outside of the source × two included in each (if choose one, output the other). Btw I don't understand the title \$\endgroup\$ Aug 22, 2019 at 7:05
6
\$\begingroup\$

Implement Brainfuck Algorithms

In order to make algorithms written in brainfuck more understandable, you can write them in a more abstract notation, where you give a given cell a name, and instead of lots of unreadable < and > instructions to move the pointer to a specific, you just write down the name of the cell. Let us see an example:

This algorithm doubles the value in cell x, and saves the result again in x. It needs an additional temporary cells t

t[-]          clear temporary variable
x[t+x-]       move the value from x to t
t[x++t-]      move twice as many units from t back to x

Now lets see what this would look like, if x was the cell with index 0, and t was the cell with index 2, assuming the poninter is in position 0 when the algorithm starts:

>>[-] 
<<[>>+<<-]  
>>[<<++>>-]

Challenge

Given a string with a valid (see below) brainfuck algorithm, a list of strings containing the cell names and a list of integers containing the indices of each of the cell of the previous list, your program/function has to return an implementation of this algorithm in brainfuck.

Details

  • The pointer is assumed to be on a cell with index 0 when the implementation is executed.
  • The two given lists can also be in a different reasonable format e.g. [cell1,index1,cell2,index2,...] or [[cell1,index1],[cell2,index2],... or as arguments of a function with a variable number of arguments etc.
  • You can assume that in the given string representing the algorithm, there are only brainfuck instructions as well as cell names, but no other symbols (no line breaks, no spaces)
  • The cell names consist of lower- and uppercase characters A-Z and a-z as well as digits 0-9
  • The cell names in the string are always separated by at least one BF instruction symbol.
  • You can assume that the pointer is the same index whenever it enters a loop as it exits the same loop.

Examples

x=y:

String (remove line breaks):
  temp0[-]
  x[-]
  y[x+temp0+y-]
  temp0[y+temp0-]
List of variable names: [temp0,x,y]
List of indices:        [    2,0,1]
Output (remove line breaks):
  >>[-]
  <<[-]
  >[<+>>+<-]
  >>[<+>-]

x=x*x

String (
  temp0[-]
  temp1[-]
  temp2[-]
  x[temp2+temp1+x-]
  temp1[
    temp2[x+temp0+temp2-]
    temp0[temp2+temp0-]
    temp1-
  ]
List of variable names: [x,temp0,temp1,temp2]
List of indices:        [0,    1,    2,    3]
Output (remove line breaks):
  >[-]
  >[-]
  >[-]
  <<<[>>>+<+<<-]
   >>[
    >[<<+>+>>-]
    <<[>>+<<-]
    >-
  ]

(More to be added)

\$\endgroup\$
3
  • \$\begingroup\$ Aah, I just noticed something when writeing that line (see meta section) but I do not have time right now to think through that. That's why this part was unfinished. \$\endgroup\$
    – flawr
    Jun 20, 2016 at 15:14
  • \$\begingroup\$ I think that this is undecidable. Consider a line of the form x[algorithm] where algorithm doesn't guarantee to leave the pointer where it started. For the subsequent line to move the pointer to the desired cell it needs to know whether x was zero going into that line or not. \$\endgroup\$ Jun 20, 2016 at 16:03
  • \$\begingroup\$ I think the problem can be solved by requiring that there are no <> in the input. Although that would make the resulting language not Turing-complete (can only access finite amount of memory) \$\endgroup\$
    – DELETE_ME
    May 2, 2018 at 9:51
6
\$\begingroup\$

ASCII Maze Unrendering 3000

Posted

\$\endgroup\$
5
  • \$\begingroup\$ Part of the wall for the current only test case seems a bit too narrow. \$\endgroup\$ Aug 28, 2019 at 2:37
  • \$\begingroup\$ I think this could be considered a special case of this challenge, with slight differences in the voxel style. \$\endgroup\$
    – flawr
    Aug 29, 2019 at 6:56
  • \$\begingroup\$ @flawr You're right. As written, this is a duplicate. Do you know if the reverse has been done, taking the 3d version and returning the original? \$\endgroup\$
    – Hiatsu
    Aug 29, 2019 at 17:52
  • \$\begingroup\$ I don't think the reverse has been done, but I'm not sure this would make a good challenge. I'm still thinking about how one could make this. I mean the 2d version you propose would make it a bit simpler. \$\endgroup\$
    – flawr
    Aug 29, 2019 at 19:10
  • 1
    \$\begingroup\$ Yes. The full 3d version would almost certainly be impossible, because most voxels would be completely blocked. Here, every block is visible, and a human can figure out where the walls are, so a computer should be able to do it too. \$\endgroup\$
    – Hiatsu
    Aug 29, 2019 at 19:17
6
\$\begingroup\$

Question link

\$\endgroup\$
8
  • \$\begingroup\$ @Night2 Indeed, didn't notice that point, I fixed the samples in the rules to include AA-000-AA \$\endgroup\$
    – Elcan
    Sep 20, 2019 at 6:25
  • \$\begingroup\$ Are the letters mandatory to be uppercased, or could we output in lowercase as well? \$\endgroup\$ Sep 20, 2019 at 9:51
  • 1
    \$\begingroup\$ @KevinCruijssen Yes, letters are mandatory to be uppercase, also I feel like you ask that because of a builtin somewhere :P \$\endgroup\$
    – Elcan
    Sep 20, 2019 at 12:36
  • \$\begingroup\$ Fine by me. I was mainly asking because it isn't a core-part of the challenge, and in some challenges lowercase/uppercase/mixed case is all allowed. But you're indeed right that lowercase would save a byte in my language of choice 05AB1E, where A is the lowercase alphabet builtin, and I'd need an additional u to uppercase it. ;p But since number plates are always uppercase, I can understand to keep the uppercase mandatory here as well. I had prepared a 24-byter, but will throw it away for now since I feel this can be done shorter.. Will try again later when it's posted to main. :) \$\endgroup\$ Sep 20, 2019 at 12:41
  • \$\begingroup\$ Another question, or more recommendation: allowed both 0-based and 1-based indexing for answers. I see your test cases are 0-based, but some languages use 1-based indexing instead. \$\endgroup\$ Sep 20, 2019 at 12:44
  • 1
    \$\begingroup\$ @KevinCruijssen Sure, no problem with 1-based indexing, going to fix the rules to add that. As I've never used such languages, I often forget about them \$\endgroup\$
    – Elcan
    Sep 20, 2019 at 13:19
  • \$\begingroup\$ I would say if the format irl has to be in uppercase then following that would be better. I've got myself an 85-byte JS answer that conforms to the irl format though. \$\endgroup\$ Sep 21, 2019 at 1:06
  • \$\begingroup\$ @ShieruAsakoto That's what I also advocate for, minus all the dumb real life rules that would just make it unfun to do. Anyway, going to post this \$\endgroup\$
    – Elcan
    Sep 23, 2019 at 18:41
6
\$\begingroup\$

Almost Illegal Strings

Posted.

\$\endgroup\$
11
  • \$\begingroup\$ Does the challenge need to have the robber code output "Well done!"? What if they could just submit any code with the substring that runs? \$\endgroup\$
    – xnor
    Oct 24, 2020 at 10:24
  • \$\begingroup\$ @xnor That's fair enough - I just struggle to define 'program that runs'. Would you consider zero exit code and no stderr output reasonable? Or are there some languages that output to stderr even in a valid program? \$\endgroup\$
    – Sisyphus
    Oct 24, 2020 at 12:00
  • \$\begingroup\$ I think this is too similar to the original "illegal strings" question which basically turned into a cops-and-robbers anyway \$\endgroup\$
    – pxeger
    Oct 24, 2020 at 18:26
  • \$\begingroup\$ @Sisyphus I was thinking you could just copy whatever condition Find an Illegal String uses. But it doesn't seem to be that rigorous, saying "The compiler/interpreter/runtime must give an error when given any source code that contains your string as a substring." I think requiring no output to STDERR is probably fine. Maybe though some languages give warnings to STDERR that golfers typically ignore? Note that defaults allow programs that print then crash, so just requiring output doesn't preclude a fatal error after. \$\endgroup\$
    – xnor
    Oct 24, 2020 at 21:12
  • \$\begingroup\$ Rule suggestion: commenting out the almost illegal string is not allowed \$\endgroup\$
    – Beefster
    Oct 28, 2020 at 15:33
  • \$\begingroup\$ I think it's too thorny to define what comments are in a way that works across languages. One objective way to handle it would be to let cops specify a set of characters that are not in their code, where they might include their language's comment character(s) or quote literals. \$\endgroup\$
    – xnor
    Oct 29, 2020 at 0:40
  • \$\begingroup\$ @xnor Ok, I've rewritten the challenge to just require that the program does not error, and feel the rules are fairly straightforward and watertight. \$\endgroup\$
    – Sisyphus
    Nov 1, 2020 at 5:50
  • \$\begingroup\$ @Beefster I considered this, and something like xnor's suggestion of banning characters. However, I think it ruins the purity of the challenge a bit, and for most languages it's very easy to avoid being in a comment (newline + end of comment block will do it). There are some languages which have 'inescapable comments', such as raw strings with specific delimiters, or something like Perl's __END__, but they're sacrifices I'm willing to make. \$\endgroup\$
    – Sisyphus
    Nov 1, 2020 at 5:52
  • \$\begingroup\$ The problem with not banning comments (or including things within strings, for that matter) is that it's quite easy to cop out and write a hello world with the almost illegal string appended in a comment. That takes out all the challenge. xnor's suggestion solves that mostly, but that does end up limiting cops a little bit to make the robbers' job an actual challenge. \$\endgroup\$
    – Beefster
    Nov 2, 2020 at 16:25
  • 1
    \$\begingroup\$ @Beefster Apologies, I have not been clear about my reasoning. My logic is that for the vast majority of languages, a cop can 'comment proof' their string trivially by adding a newline (to escape a single line comment) and an end of comment block (to end a multiline comment). For example, the string \nx"""x''' (with a literial newline) escapes all Python comments. You can do this in most languages - or am I missing something? \$\endgroup\$
    – Sisyphus
    Nov 3, 2020 at 3:12
  • 2
    \$\begingroup\$ @Beefster It looks like you were right - it is too hard without allowing Cops to ban characters. I'd like to apologise for not taking your feedback more seriously while the question was in the sandbox. \$\endgroup\$
    – Sisyphus
    Nov 6, 2020 at 1:10
6
\$\begingroup\$

Speed of Lobsters

\$\endgroup\$
0
6
\$\begingroup\$

Print random integers until 0

\$\endgroup\$
10
  • \$\begingroup\$ Presumably, if the first number is zero, we just output zero and exit? \$\endgroup\$
    – pxeger
    Jan 16, 2021 at 18:57
  • \$\begingroup\$ "integers may be separated by any non-digit, non-empty separator" can we output in zero-padded form (00 01 .. 98 99) so that a separator isn't necessary? What about codepoints/byte values (NULL - c)? Can it be a list-like object rather than a separated string? I think this would be better with more sequence-like IO rules \$\endgroup\$
    – pxeger
    Jan 16, 2021 at 18:59
  • 1
    \$\begingroup\$ @pxeger Yes, if the first number is zero, you just output zero and exit. I don't think the standard is to output with zero-padding, so I'll say no on that. Byte values and list objects are both standard forms of outputting a bunch of numbers, so of course, those are allowed \$\endgroup\$ Jan 16, 2021 at 19:07
  • \$\begingroup\$ Also, I assume it is not necessary that the program follows the indicated procedure (which would be unobservable anyway), as long as the output has the same statistical properties. So if a different procedure is used, perhaps the answer writer should justify it. (For example: generate a number K geometrically distributed with parameter 1/99, then output K nonzero numbers, then output a 0) \$\endgroup\$
    – Luis Mendo
    Jan 16, 2021 at 19:07
  • \$\begingroup\$ @LuisMendo Yeah, I'm pretty sure that "you don't have to follow the letter of the challenge so long as the behaviour is the same" is a standard rule, but in case not, I've edited in a sentence along with your example \$\endgroup\$ Jan 16, 2021 at 19:10
  • \$\begingroup\$ I didn't fully define my example, sorry. You may want to change it to "then output K independent numbers with a uniform distribution on the set {1, 2, ..., 99}". That corresponds to the procedure you specify with a uniform distribution on {0, 1, ..., 99}. \$\endgroup\$
    – Luis Mendo
    Jan 16, 2021 at 19:21
  • \$\begingroup\$ @cairdCoinheringaahing are built-in functions for generating pseudo-random numbers forbidden? If not, is the challenge a very trivial one or am I missing something? \$\endgroup\$
    – anotherOne
    Jan 27, 2021 at 23:17
  • 1
    \$\begingroup\$ @Davide Trivial challenges are not necessarily bad, since it encourages participation in relatively hard-to-use or minimal esolangs. And I think this one is actually good because I smell many unexpected approaches to golf the problem. (Also, banning built-ins are considered bad.) \$\endgroup\$
    – Bubbler
    Jan 28, 2021 at 0:26
  • \$\begingroup\$ @Bubbler thank you so much for this train of information \$\endgroup\$
    – anotherOne
    Jan 28, 2021 at 0:35
  • 1
    \$\begingroup\$ @Davide Nope, all builtins are allowed. As Bubbler said, trivial challenges are only really bad if there’s no room for interesting solutions, which I don’t think is the case here \$\endgroup\$ Jan 28, 2021 at 10:06
6
\$\begingroup\$

Remove Nth occurrences

\$\endgroup\$
4
  • 2
    \$\begingroup\$ There is this but it got closed, Everything is clear, but can you replace, "the n" with "the integer n" in the last point of your assumptions list. For some reason that made me read the sentence multiple times. \$\endgroup\$
    – Alex bries
    Feb 23, 2021 at 12:08
  • \$\begingroup\$ Is there a reason for limiting the array values to 1-9? \$\endgroup\$
    – pxeger
    Feb 23, 2021 at 19:49
  • 1
    \$\begingroup\$ @pxeger Because the values don't matter, so there's no reason to complicate it more. Plus, it can allow for some interesting string based approaches by taking \$A\$ as a single string \$\endgroup\$ Feb 23, 2021 at 19:52
  • \$\begingroup\$ @pxeger It certainly helps that 0 cannot be part of the array, because then I can use it to erase values in APL. I'm sure other languages can take advantage of that too \$\endgroup\$
    – user
    Feb 24, 2021 at 1:48
6
\$\begingroup\$

To raise \$ e \$ to the power of a matrix

Posted


Meta

  • Is this clear enough?
  • Is this a duplicate?
  • Any other feedback?
\$\endgroup\$
8
  • \$\begingroup\$ why not require exact calculation, it makes for a harder challenge but a more interesting one \$\endgroup\$
    – rak1507
    Apr 1, 2021 at 19:54
  • \$\begingroup\$ @rak1507 it's irrational so an exact value can't be calculated \$\endgroup\$
    – pxeger
    Apr 1, 2021 at 19:55
  • \$\begingroup\$ looked like there were methods on wikipedia but I could be wrong \$\endgroup\$
    – rak1507
    Apr 1, 2021 at 21:45
  • \$\begingroup\$ Note that the exponential of a 9x9 matrix of 100's exceeds what floats can represent. You might want to lower the 100 bound or make allowances for that. \$\endgroup\$
    – xnor
    Apr 2, 2021 at 6:30
  • \$\begingroup\$ I think the precision convergence rule is too restrictive and too tied to that specific power series method, and some loose accuracy bound would allow more varied methods. For instance, one can approximate \$e^M \approx (I+M/n)^n\$ for large \$n\$. \$\endgroup\$
    – xnor
    Apr 2, 2021 at 6:38
  • \$\begingroup\$ @xnor I didn't read much into the matrix exponential (because I couldn't find the article on Wikipedia and was too busy watching the rest of the 3b1b video :P), so I hadn't not really realised there were other ways to compute it. What would you recommend? I still like the idea of requiring it to be observed to converge within floating point limits, because it adds an extra layer of challenge rather than just "repeat this step 100 times", but maybe that just isn't practical \$\endgroup\$
    – pxeger
    Apr 2, 2021 at 6:50
  • 5
    \$\begingroup\$ I think convergence within floating point limits would unfortunately be hard and finicky here because of the nature of exponentials. The same way that \$e^{100}\$ and \$e^{100.001}\$ differ a lot, small errors in the computation can accumulate into huge ones. Also, the values in the output might be extremely small and become represented as zero. I'd have to think more about bounds, but maybe something like every entry within either 1% or 1e-4 of the true one should work. \$\endgroup\$
    – xnor
    Apr 2, 2021 at 7:03
  • 2
    \$\begingroup\$ My solution to floating-point errors is "the result should be within [insert error bound here] relative error for the given test cases". (The bolded part is VERY important. FP computation methods often have errors dependent on the magnitude of the input, so it is very hard to judge if an implementation is valid, even if the possible input range is specified. Explicitly giving the test cases makes it much easier to test submissions. Also, you need to craft the test cases carefully so that you don't accidentally ban a valid method or allow invalid methods.) \$\endgroup\$
    – Bubbler
    Apr 4, 2021 at 23:28
6
\$\begingroup\$

Non-quining infinite printer

Seems like the title could be better but I'm not sure what to do instead

I have heard that a monkey typing random keys on a typewriter, given infinite time, will eventually type out the entire works of Shakespeare, and in fact type out every possible string of characters of any length. This sounds to me like the basis for a profitable business venture in publishing. Unfortunately, however, as a result of previous failed business ventures, I am legally barred from possessing either monkeys or typewriters, so I'll instead need a program. I want this program to provably generate every possible string of characters, assuming infinite time and memory. Repetition is fine, as is overlap, as long as every possible string appears somewhere in the output. There's a catch, though. I imagine once my business gets off the ground and people realize the potential profits, they might want to get their hands on my program. The trouble is that since I'm outputting every possible string of text, in theory I'll eventually end up outputting the program itself, leaving it open to be stolen. To prevent this, I want the program never to output its own source code. It should still output every other possible string, just not itself (or, obviously, any strings which it is a substring of). Because my funds are currently very tight, I can't afford to pay for more bytes than are necessary, so I'm seeking the shortest possible program that does the job (This is a code-golf challenge, shortest answer in bytes wins). Is it communicated well enough what this challenge is asking for? Should I add a TL;DR and/or a more technical explanation of what's being looked for?

Additional notes:

  • I've had enough run-ins with the law in previous ventures, I'd like this one to go smoothly. So no abusing loopholes in the program, please.
  • Given that this program is my financial plan for the next infinity years, I'd like some reassurance that it actually does what it's supposed to. Please provide at least a brief explanation of why your code works, since it can't exactly be tested.
  • Any character encoding is fine, please specify though. The exception is that your source code must be printable in the encoding you use. Is this a reasonable way to handle this that is fair to all languages?
  • No reading your own source, because that makes quine-related holes uncool, and uncoolness does not fit with my businesses' brand persona.
\$\endgroup\$
7
  • \$\begingroup\$ How are the strings in the output separated? Some previous challenges about "print all possible strings" were closed as unclear because of this. \$\endgroup\$
    – Bubbler
    Jun 7, 2021 at 1:06
  • \$\begingroup\$ @Bubbler The strings don't have to be separated. What I mean is that every string should be a substring of the "main" output if that makes sense. Put another way, running a regex match on the output for any string of characters (other than the source) should return at least one result. Would adding something to that effect clear up that confusion? \$\endgroup\$
    – je je
    Jun 7, 2021 at 1:13
  • \$\begingroup\$ It should still output every other possible string, just not itself (or, obviously, any strings which it is a substring of) Okay, the task makes sense now. I think you'll need to add that information somewhere before the sentence I quoted. Now I wonder if the task is actually possible... \$\endgroup\$
    – Bubbler
    Jun 7, 2021 at 1:39
  • \$\begingroup\$ @Bubbler Sure, it's possible. One approach is to store the program's source in a string, and then run some sort of code that generates every possible string, checking after each generation whether the generated string contains the source string, and only printing if it doesn't. There might be some trouble in making sure the source isn't present in a combination of two consecutively generated strings (i.e. if the source code is AB, then outputting XA and BX consecutively is an issue), but a simple solution to that is to insert a character not present in the source between each pair. \$\endgroup\$
    – je je
    Jun 7, 2021 at 8:02
  • \$\begingroup\$ Here's an implementation in Python tio.run/… \$\endgroup\$
    – je je
    Jun 7, 2021 at 8:03
  • \$\begingroup\$ @jeje An easily thought solution is just use an unused char as split, but that likely be longer \$\endgroup\$
    – l4m2
    Jul 1, 2021 at 16:40
  • \$\begingroup\$ What do mean by "all possible strings"? Is this restricted to all strings consisting of printable ASCII? The entire Unicode table? \$\endgroup\$ Jul 8, 2021 at 1:14
6
\$\begingroup\$

Who Is Kevin Bacon?

\$\endgroup\$
2
  • \$\begingroup\$ > I'm worried it will just be "string a load of combinatorial builtins together" and brute-force it That's a solution to pretty much anything \$\endgroup\$
    – emanresu A
    Dec 30, 2021 at 5:12
  • \$\begingroup\$ it looks interesting enough, I can't find anything similar with searches like "Erdos number" and such. It will inevitably get a trivial golflang answer, especially with felxible input methods. To control quality, maybe adding a restricted-time would help. \$\endgroup\$
    – Razetime
    Jan 2, 2022 at 7:49
6
\$\begingroup\$

Sort every dimension

\$\endgroup\$
6
\$\begingroup\$

Output a random unary string

\$\endgroup\$
9
  • \$\begingroup\$ Would printing an infinite stream of separators or xs be valid? It's an infinitesimally small chance that just, e.g., one x is ever printed for the rest of time, but does that count (I'd be inclined to say no)? \$\endgroup\$ Feb 22, 2022 at 20:43
  • \$\begingroup\$ i have no idea what this challenge is about but +1 \$\endgroup\$
    – DialFrost
    Feb 23, 2022 at 3:43
  • \$\begingroup\$ Since most languages random number generator (RNG) only have finite state, The program won't output infinity number of different outputs. You may argue that we may consider (assume) RNG have infinity digits (precision). But then, someone would argue that repeat("x", floor(1/random_between_0_and_1())) is a valid submission as we can consider the output of random_between_0_and_1 have infinity precision. It is not very clear which is valid and which is not to me. \$\endgroup\$
    – tsh
    Feb 23, 2022 at 10:32
  • \$\begingroup\$ Looks like "the RNG in use has perfect random distribution" is a necessary assumption, but allowing the return value of RNG to be of infinite precision sounds a bit weird, as tsh pointed out. You may want to clarify these points in the challenge rules. (I'm not entirely against it though; in some langs the only source of randomness is a random real number in [0,1), which makes some compromises like "you can only use RNGs that return a finite number of integers" unsuitable) \$\endgroup\$
    – Bubbler
    Feb 23, 2022 at 23:56
  • \$\begingroup\$ @tsh @Bubbler Do you think the rule I just added is adequate? (I think tsh's suggested repeat("x", floor(1/random_between_0_and_1())) should be considered valid as long as it never causes a division by zero.) \$\endgroup\$
    – pxeger
    Feb 24, 2022 at 16:20
  • \$\begingroup\$ @pxeger I cannot understand how random_between_0_and_1 output a "infinite precision" number in finite time (so program will halt with with probability 1). But regardless this, the rule seems clear to me. \$\endgroup\$
    – tsh
    Feb 25, 2022 at 7:20
  • \$\begingroup\$ @tsh Well obviously nothing can output an infinite precision number of any kind, but I'm allowing it as an assumption because I think it should be considered a valid possible solution. \$\endgroup\$
    – pxeger
    Feb 25, 2022 at 7:44
  • \$\begingroup\$ Does "Every possible length of xs" includes 0 (empty output)? \$\endgroup\$
    – tsh
    Feb 25, 2022 at 9:08
  • \$\begingroup\$ @tsh "You may choose whether to include the empty string as a possible output" \$\endgroup\$
    – pxeger
    Feb 25, 2022 at 9:50
6
\$\begingroup\$

Building spikes

\$\endgroup\$
4
  • 3
    \$\begingroup\$ Interesting idea. I think the challenge could be interesting if solutions were required to take in a size and output a spiked building of that size. \$\endgroup\$
    – ophact
    Mar 9, 2022 at 8:20
  • \$\begingroup\$ @ophact is it better now? \$\endgroup\$
    – DialFrost
    Mar 9, 2022 at 23:37
  • \$\begingroup\$ Why input 7 is one line taller than input 2? \$\endgroup\$
    – tsh
    Mar 10, 2022 at 3:02
  • \$\begingroup\$ @tsh its same height \$\endgroup\$
    – DialFrost
    Mar 10, 2022 at 3:04
6
\$\begingroup\$

Sort numbers in a ragged list

\$\endgroup\$
3
  • \$\begingroup\$ Can the output be flattened? \$\endgroup\$ Mar 11, 2022 at 22:55
  • \$\begingroup\$ @BgilMidol No, that defeats the point of it. \$\endgroup\$
    – emanresu A
    Mar 11, 2022 at 22:56
  • 2
    \$\begingroup\$ I think to avoid ambiguity it should be said something like "The shape of the output must be the same as the shape of the input". The spec is currently pretty sparse, relying mostly on an example. \$\endgroup\$
    – Wheat Wizard Mod
    Mar 11, 2022 at 22:57
6
\$\begingroup\$

King of the Holster (EXITING SANDBOX TOMORRROW)

I realized there hadn't been a King of the Hill in forever, so I wanted to create one.

Before the Game

You will be given 10 points to distribute between HP, Dexterity, Armor, and Speed. You may distribute up to 10 points between these categories (integer amounts only). You do not have to put a point in each category.

  • Your HP will equal 10 plus the number of points you put in HP.
  • Your Dexterity (chance of dodging a hit) is equal to 0.04 times the number of points you put in Dexterity. For example, if you put 8 points in Dex, you would have a .32 chance of dodging a hit.
  • Your Armor (chance of taking 1 less damage from a hit) is equal to .1 times the number of points you put into Armor.
  • Your Speed is simply equal to the number of points you put in Speed.
  • You always start with 2 ammo.

Gameplay

Agents will be ordered based on their speed, with ties being broken at random before the game begins. On their turn, each agent will be given their HP, all of their stats (max HP, Dexterity, Armor, and Speed), how much ammo they have, who they attacked most recently, and who attacked them most recently.

On each agent's turn, there are three possible moves:

  • Heal: If not at maximum HP, gain 1 HP.
  • Reload: Gain 2 ammo.
  • Shoot: Choose another agent. They get a random real from 0 to 1. If that number is less than their dexterity, they dodge and take 0 damage. Otherwise, they take a random integer amount of damage from 1 to 4, then they generate another random real from 0 to 1. If that number is less than their armor, they take 1 less damage.

TLDR: Shooting does 0 damage if they dodge, 0 to 3 if they get armor but no dodge, 1 to 4 if none.

Once an agent's HP is less than 0, it is out and can no longer take actions. Last agent surviving wins the round.

Scoring

Each round, if there were X agents, your agent receives X points for each agent below it. Therefore, in a 10 player game, the top agent would get 9 points, the second would get 8, and so on. I can currently run 5000 3-player modes in 10 or so seconds (probably much faster if I removed some of the printing for debugging), so as long as nobody's agent takes too long to run, I should be able to run thousands of score tests.

I/O

Currently, submissions will create a class which extends PlayerClass. It will create a new class constructor that takes no inputs, which will call super() with the points it wants in each category. Additionally, you will redefine the makeMove function, which takes no inputs and calls move() with whatever arguments are required.

Rules

Submissions in Java only. As long as the submission is simple enough, I might be able to translate from pseudocode/some other language to Java though.

No calling any methods of other entities using shenanigans. The biggest problem here is takeDamage(), which has to be public so it can be called when someone is shot. Other than that, there shouldn't be any public functions other than turn-order functions, which are probably fine to access.

No redefining any functions/variables of PlayerClass besides makeMove().

The subclass constructor must be of the form super(x,y,z,a); and cannot overwrite the requirements in the PlayerClass constructor.

You may define other methods within your class IF they are only called as part of generating your stats or deciding who to shoot and they follow the rules outlined above.

Don't make your code take forever. This KOTH is pretty lightweight, so there shouldn't be a need for complex algorithms.


The controller and four basic test agents can be found here: https://github.com/romanpwolfram/GunfightKoTH/tree/main

Challenge name by tjjfvi.

\$\endgroup\$
8
  • \$\begingroup\$ What programming language? \$\endgroup\$
    – ophact
    Apr 18, 2022 at 16:18
  • \$\begingroup\$ Java right now, but it's simple enough that I can probably convert it to another language with a bit of work. \$\endgroup\$
    – Romanp
    Apr 18, 2022 at 16:31
  • \$\begingroup\$ How much damage does getting shot do? \$\endgroup\$ Apr 18, 2022 at 16:33
  • \$\begingroup\$ Random from 1 to 4, but random from 0 to 3 if they "win" their armor roll. \$\endgroup\$
    – Romanp
    Apr 18, 2022 at 16:34
  • 1
    \$\begingroup\$ > I realized there hadn't been a King of the Hill in forever sad noises \$\endgroup\$
    – Seggan
    Apr 18, 2022 at 18:34
  • 1
    \$\begingroup\$ That one looked like a good KoTH, and I have no idea why it failed. Reasonably complex strategy, but easy enough to code. \$\endgroup\$
    – Romanp
    Apr 18, 2022 at 18:36
  • 1
    \$\begingroup\$ Watch out, a player can just do ammo = 10000 and get away with it. Might want to make em private and instead put getters. \$\endgroup\$
    – Seggan
    Apr 19, 2022 at 0:18
  • 1
    \$\begingroup\$ Ok. I think I can change all of them since all the info you need should come from getInfo and getAlivenemies \$\endgroup\$
    – Romanp
    Apr 19, 2022 at 13:11
6
\$\begingroup\$

Convert Alpha-3 to Alpha-2

\$\endgroup\$
3
  • 2
    \$\begingroup\$ If that link goes down, or if the list changes for any reason (such as by adding a new country), it would invalidate existing answers. The usual way around this is to declare one unchanging list of every country/territory code that needs to be handled, even if the external resource changes. Since the full list looks too large to comfortably fit in a post, you could copy the list into a Pastebin or something. \$\endgroup\$
    – Nitrodon
    Apr 28, 2022 at 14:12
  • \$\begingroup\$ Yep! I was planning on posting one to my website later today! \$\endgroup\$
    – Komali
    Apr 28, 2022 at 14:13
  • \$\begingroup\$ @Nitrodon done! \$\endgroup\$
    – Komali
    Apr 28, 2022 at 16:22
6
\$\begingroup\$

Shortest restricted superstring

\$\endgroup\$
1
  • 1
    \$\begingroup\$ please don't enforce answers having to handle the empty set as either input but especially the first. It's just an annoying edge case. \$\endgroup\$
    – emanresu A
    May 4, 2022 at 5:48
6
\$\begingroup\$

ITEXTIN - Is This an EXTended Initialism?

Please write a program or function that, when given a list of words and proposed extended initialism, outputs whether it is valid.

Rules:

  • The list will contain at least two words.
  • The extended initialism will contain at least three letters.
  • Each word in the phrase contributes a prefix to the extended initialism.
  • This prefix must not be the whole word.
  • In the case of the first and last words, the prefix must not be empty.
  • The extended initialism is the concatenation of these prefixes.
  • Inputs are alphabetic only, your choice of upper or lower case.
  • Separators, if you want them, are any symbol or white space.

Examples (truthy):

laser=light amplification by the stimulated emission of radiation
radar=radio detection and ranging

Examples (falsy):

labyser=light amplification by the stimulated emission of radiation
radar=light amplification by the stimulated emission of radiation
dear=radio detection and ranging

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

\$\endgroup\$
8
  • \$\begingroup\$ How should a function determine whether to exclude words such as by, the, of or and? \$\endgroup\$
    – jezza_99
    May 26, 2022 at 1:21
  • \$\begingroup\$ @jezza_99 By looking at which letters it needs. \$\endgroup\$
    – Neil
    May 26, 2022 at 6:18
  • \$\begingroup\$ Surely then labtseor is correct, not laser, by "Each word in the phrase contributes a prefix to the extended initialism." \$\endgroup\$
    – jezza_99
    May 26, 2022 at 23:27
  • \$\begingroup\$ @jezza_99 Empty prefixes are allowed except for the first and last words. \$\endgroup\$
    – Neil
    May 26, 2022 at 23:27
  • \$\begingroup\$ Can we assume the input initialism is always at least 2 characters long? If not, can we at least assume it's non-empty? \$\endgroup\$
    – pxeger
    May 28, 2022 at 11:41
  • \$\begingroup\$ @pxeger Hmm, 2 characters is still a bit of an edge case, since it can only ever be the first character of the first and last words... maybe I should make it at least 3? What do you think? \$\endgroup\$
    – Neil
    May 28, 2022 at 14:17
  • \$\begingroup\$ @Neil I don't exactly see anything wrong with just >=2, but to completely minimise any problem you could go with >=3 to be safe. \$\endgroup\$
    – pxeger
    May 28, 2022 at 15:11
  • 1
    \$\begingroup\$ @pxeger How about the list of words? I've gone with >=2 there for now. \$\endgroup\$
    – Neil
    May 28, 2022 at 16:17

You must log in to answer this question.

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