532
\$\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 needs more feedback, but it's been ignored, you can ask for feedback in The Nineteenth Byte. It's not only allowed, but highly recommended!

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

Other

Search the sandbox / Browse your pending proposals

The sandbox works best if you sort posts by active.

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

Get the Sandbox Viewer to view the sandbox more easily!

\$\endgroup\$
0

3471 Answers 3471

1
14 15
16
17 18
116
3
\$\begingroup\$

Jelly's Untruth

\$\endgroup\$
3
\$\begingroup\$

Generalised Taxicab Numbers

\$\endgroup\$
3
\$\begingroup\$

posted

\$\endgroup\$
3
\$\begingroup\$

Is my triangle on the lattice?

Posted on the main site.

\$\endgroup\$
3
\$\begingroup\$

Is it a Lobster Number?

Posted

\$\endgroup\$
6
  • \$\begingroup\$ I like the idea, but the fact that prime numbers don’t count seems a bit arbitrary. \$\endgroup\$
    – user
    Jan 23 at 21:11
  • 2
    \$\begingroup\$ It definitely is a bit arbitrary, but I felt that it made sense as an edge case, since while it is a prime factor, it is already the number itself, and there are no other factors. The related (but not identical) OEIS sequence also seems to have made this distinction, so it seemed reasonable. It also has the simple explanation that lobsters are not needed to get the result for the prime numbers, and shouldn't be overly difficult to work around in golfing, as all you need is a single comparison (is there only one factor, or is the first factor equal to the number). \$\endgroup\$
    – IronEagle
    Jan 23 at 21:35
  • \$\begingroup\$ Yeah, that makes sense, and it's not a deal-breaker for me, it would just make writing an answer slightly more annoying :) \$\endgroup\$
    – user
    Jan 23 at 21:36
  • \$\begingroup\$ @user - Posted since there seems to be no general problems with the question. \$\endgroup\$
    – IronEagle
    Jan 24 at 15:04
  • \$\begingroup\$ Well, I don't see any problems with it myself, but it would have been good to let it sit a few more days to get more feedback \$\endgroup\$
    – user
    Jan 24 at 15:07
  • 1
    \$\begingroup\$ @user - I'll keep that in mind, this is my first question here, this site is quite a bit different from the other StackExchange sites. \$\endgroup\$
    – IronEagle
    Jan 24 at 15:13
3
\$\begingroup\$

BF memory layout optimizer (posted).

See the notes in the revision history.

[please review other sandbox posts]

\$\endgroup\$
3
  • 1
    \$\begingroup\$ (upvote this comment if you want a variant with [fastest-code] instead.) \$\endgroup\$
    – DELETE_ME
    Jan 31 at 2:11
  • 2
    \$\begingroup\$ (upvote this comment if you want both a [code-golf] version and a [fastest-code] version.) \$\endgroup\$
    – DELETE_ME
    Jan 31 at 2:11
  • 1
    \$\begingroup\$ (upvote this comment if you want only a [code-golf] version.) \$\endgroup\$
    – DELETE_ME
    Jan 31 at 2:11
3
\$\begingroup\$

Note:

  • as you can probably tell, this is a simpler variation; however the poster of the other sandbox post has not been visiting the site for a while.
  • because of the current situation, I recently (after the 2 upvotes is made) changed the winning criteria. Is there any problem with the description?
  • What info should be included in the header?...

Efficient table-lookup computation

Posted: Efficient table-lookup computation

\$\endgroup\$
20
  • \$\begingroup\$ (ah, right. The sandbox is still as inactive as usual.) \$\endgroup\$
    – DELETE_ME
    Jan 30 at 17:16
  • \$\begingroup\$ Or it could be that the challenge is simply a little hard to read.) \$\endgroup\$
    – DELETE_ME
    Jan 31 at 14:45
  • \$\begingroup\$ If two answers have the same A+B, is the one with lower A or lower B considered better, or is there no tie-breaker? \$\endgroup\$
    – Dingus
    Feb 2 at 8:43
  • \$\begingroup\$ @Dingus No, see the meta post about challenge having multiple winning conditions. codegolf.meta.stackexchange.com/questions/19041/… \$\endgroup\$
    – DELETE_ME
    Feb 2 at 10:19
  • \$\begingroup\$ There's no consensus on that meta question. I think you should state that if two answers have the same A+B then they score the same. \$\endgroup\$
    – Dingus
    Feb 2 at 10:37
  • \$\begingroup\$ @Dingus +1 is not a consensus? \$\endgroup\$
    – DELETE_ME
    Feb 2 at 10:42
  • 1
    \$\begingroup\$ A post is considered as a consensus only if it's at >= +10 and upvotes >= 2*downvotes. So +5/-4 (at the time of writing) is closer to a controversy than a consensus. I guess many people have just feelings without enough justification about whether it's fine or not. I personally view it as a good challenge, so I upvoted it. \$\endgroup\$
    – Bubbler
    Feb 8 at 23:20
  • \$\begingroup\$ A minor nitpick: In your Python code, adding string to a number is invalid. I guess you meant to take the inputs as strings, e.g. m1 = "0" etc. \$\endgroup\$
    – Bubbler
    Feb 8 at 23:21
  • \$\begingroup\$ For the lack of sandbox feedback, I usually leave my challenges for at least a week, regularly asking for feedback in the chat (at least 2 or 3 times before moving to main). \$\endgroup\$
    – Bubbler
    Feb 8 at 23:24
  • \$\begingroup\$ @Bubbler Fixed. \$\endgroup\$
    – DELETE_ME
    Feb 9 at 1:41
  • \$\begingroup\$ to me it looks like the given method to generate a single score from A and B only adds confusion, especially the "combined score" part... what's the advantage compared to a simpler formula like A^2+B^2? (I would be in favour of just using A and B and letting all pareto-optimal solutions win, but I understand that at the moment there's not enough consensus for this) \$\endgroup\$
    – Leo
    Feb 12 at 8:57
  • \$\begingroup\$ @Leo Because it doesn't encourage these solutions, obviously? -- (I think that the solution with minimum A is pretty interesting, but I'd like to see a solution that generates reasonably-good parametrized solutions too.) \$\endgroup\$
    – DELETE_ME
    Feb 12 at 9:53
  • \$\begingroup\$ @Leo as explained in the linked meta post -- (did I explain it clearly enough?) that method would allow essentially the same "every solutions win" situation by letting every such "winning" solution improves the "combined" score. (and is the only one that I can come up with with that condition) \$\endgroup\$
    – DELETE_ME
    Feb 12 at 9:54
  • \$\begingroup\$ The problem with the combined score is that you have two scores again, the "normal" one and the "combined" one... Does only one or the other count for "victory"? \$\endgroup\$
    – Leo
    Feb 12 at 10:29
  • \$\begingroup\$ @Leo Obviously the combined one. Note that the criteria is chosen so that the combined score is always better than or equal to the normal score, and the combined score is always better than the previous combined score. \$\endgroup\$
    – DELETE_ME
    Feb 12 at 10:32
3
\$\begingroup\$

Generalise perfect numbers

\$\endgroup\$
3
  • \$\begingroup\$ Better having a statement "in this challenge \$\sigma^n(k) \$ denotes...". It can be interpreted as \$(\sigma(k))^n \$ too. \$\endgroup\$
    – DELETE_ME
    Feb 24 at 4:15
  • \$\begingroup\$ Can answers assume that "the sequence is infinite"? \$\endgroup\$
    – DELETE_ME
    Feb 24 at 4:16
  • \$\begingroup\$ @user202729 Addressed both questions \$\endgroup\$ Feb 28 at 1:18
3
\$\begingroup\$

Byte-sized Huffman Coding (WIP)

Huffman codings are a method to compress data with certain frequency properties, usually text. Normally, these operate on bits rather than bytes, but this challenge will instead operate on whole bytes instead. Since you wouldn't get any benefit otherwise, you can represent multiple consecutive characters with a sequence of one or more bytes, for instance '. ' (a period followed by a space) could be represented by byte 1, 'The' could be represented with byte 2, and 'Ishmael' could be represented by a 255 then a 7 (among many other sequence codings).

Challenge

Create a program that compresses a plain-text version of a work of literature by returning a byte-wise Huffman coding table and a sequence of bytes that represents the text with that table.

Rules and Assumptions

  • You may assume that the text is written in English and uses only printable ASCII characters plus space, newline, and tab.
  • It must be a proper Huffman coding; no mapping may be the prefix of another.
  • Not all Huffman sequences need to be mapped to a particular character sequence; you could, for instance, not have 7 mapped to anything or not have 255, 39 mapped to something, but have every other 1 and 2 byte sequence mapped to something.
  • The returned coding table must be able to encode every possible sequence of valid characters (as per the first assumption above). The simplest way to do this is to make sure that every individual character is mapped to a Huffman byte sequence.
  • It can be possible to encode a body of text multiple ways using the returned encoding table. If both ca and at are mapped to byte sequences, cat could be encoded two ways. This is totally fine.
  • Case must be preserved.
  • Runs do not need to be deterministic, i.e. two runs of the same program with the same input could produce different Huffman tables and compressed output.
  • Your program must return a result within a reasonable amount of time to be considered a valid solution. (If you want a hard limit, I'll say 5 minutes on a 2GHz Intel dual-core i5 with 16 GB RAM running Windows 10)

Scoring

Your results will be run against a corpus of (TBD) 12 publicly available literary (and non-fiction) works. For each work of literature, your score will be the size, in bytes, of the compressed text, plus the total length of all text strings mapped to a byte sequence in the Huffman-coding table. Your overall score is the total score across all 12 works.

Lowest score wins.

Literature list

  • The King James Bible
  • Hamlet by William Shakespeare
  • Dracula by Bram Stoker
  • Frankenstein by Mary Shelley
  • On the Origin of Species by Charles Darwin
  • Moby-Dick by Herman Melville
  • Little Women by Louisa May Alcott
  • Tom Sawyer by Mark Twain
  • Pride and Prejudice by Jane Austen
  • The Hound of the Baskervilles by Arthur Conan Doyle
  • < Something that entered the public domain in 2019 because it was published in 1923 >
  • < Something written in the last 20 years willingly released into the public domain or with a Creative Commons license that allows derivative works >

Sandbox

At least one of the last two literary works should preferably be written by a female and/or non-white author to hopefully make writing styles diverse enough to make hard-coded Huffman tables ineffective. Each work should be comparable in length to the other works.

Links to these books (in plain text) would be appreciated. Substitution suggestions are welcome.

\$\endgroup\$
8
  • \$\begingroup\$ If you want to vary writing styles, is there a non-fiction work that only contains the allowed characters? \$\endgroup\$
    – trichoplax
    Sep 24 '19 at 23:21
  • \$\begingroup\$ @trichoplax The most notable non-fiction book I can think of for that would be "On the Origin of Species" by Charles Darwin. I've also thought about throwing in the King James bible. Maybe I could bump up the total to 12 works. I also probably will drop War and Peace because the plain text version I found was machine converted and has issues. \$\endgroup\$
    – Beefster
    Sep 25 '19 at 15:21
  • \$\begingroup\$ Regarding plain text books, have you checked Project Gutenberg? They have plaintext versions of many of their books. \$\endgroup\$ Sep 25 '19 at 18:35
  • \$\begingroup\$ I have no idea how much sample text is a good amount for this challenge (number of books, length of books) but it's probably worth doing some kind of rough check that there is enough text to give variation between answers (no optimal solution) while still being little enough text that running in a reasonable time is realistic (doesn't require weeks of work before an answer is efficient enough to meet the time restriction). Maybe others can suggest good ways of approximating this? \$\endgroup\$
    – trichoplax
    Sep 25 '19 at 20:16
  • \$\begingroup\$ @trichoplax so basically you suggest sampling out, say, a few chapters instead of the whole book and then reducing the required runtime? I'm open to that, especially since the word count difference between Hamlet and the Bible is so big. The interesting thing about the Bible is that it has a ton of different authors, so it would almost be better to have the first chapter of each book instead of inserting, say, the entirety of Genesis. \$\endgroup\$
    – Beefster
    Sep 26 '19 at 4:41
  • \$\begingroup\$ I couldn't guess at this point whether more text or less text would be better, and I don't have a way of estimating, just wondering if anyone else does. \$\endgroup\$
    – trichoplax
    Sep 26 '19 at 7:32
  • \$\begingroup\$ I see no problem with 5 minutes as a rough time limit. I'd lean towards a time limit that allows someone to write a quick answer and then improve on it gradually, to encourage more participants. How long that needs to be for the text you settle on I don't know. As long as you're confident an optimal solution can't be found, you could just time a naive approach and then choose a time that doesn't exclude that. Then you can get lots of early answers to get the competition going, but still have open ended improvement over the long term \$\endgroup\$
    – trichoplax
    Sep 26 '19 at 7:38
  • \$\begingroup\$ Not to say that this isn't an interesting challenge as it is but I do wonder if it wouldn't be more interesting without requiring that we use Huffman Encoding? \$\endgroup\$
    – Shaggy
    Sep 27 '19 at 22:21
3
\$\begingroup\$

What's the odd one out?

\$\endgroup\$
2
  • \$\begingroup\$ Looks like this but a bit more interesting \$\endgroup\$
    – Razetime
    Mar 9 at 13:35
  • \$\begingroup\$ Great challenge! Seems ready to be posted \$\endgroup\$
    – user100690
    Mar 9 at 16:03
3
\$\begingroup\$

Sociable sequences

\$\endgroup\$
8
  • \$\begingroup\$ You probably need to describe what a proper divisor is. Separately, I'm not sure how great requiring infinite output is. I'd probably consider allowing another optional argument that limits how many sequences to output? \$\endgroup\$ Nov 12 '20 at 19:47
  • \$\begingroup\$ @FryAmTheEggman I've updated the challenge to be closer to the normal [sequence] I/O rules \$\endgroup\$ Nov 26 '20 at 15:23
  • \$\begingroup\$ So is 25 a 1-sociable number, since its divisors sum to 6, and then there's a cycle? \$\endgroup\$
    – user
    Jan 6 at 21:04
  • 1
    \$\begingroup\$ @user No, \$25\$ is not a \$1\$-sociable number. "They are numbers whose proper divisor sums form cycles beginning and ending at the same number". \$25\$'s "cycle" is \$25 \to 6 \to 6 \to \cdots\$, which does not begin and end with the same numbers. I'll edit that in though \$\endgroup\$ Feb 22 at 17:50
  • \$\begingroup\$ That "begin and end at the same number" is unclear. (it's a cycle, it neither begins nor ends) Perhaps "the initial number is inside the cycle". \$\endgroup\$
    – DELETE_ME
    Feb 24 at 4:30
  • \$\begingroup\$ Should that "given value" be interpreted as "value that will be given as input"? \$\endgroup\$
    – DELETE_ME
    Feb 24 at 4:31
  • \$\begingroup\$ That "does not diverge" sounds like a terribly hard conjecture... EDIT indeed it is. en.wikipedia.org/wiki/Catalan%E2%80%93Dickson_conjecture ("likely false"), and looks like that the sequence you came up with already have a name. \$\endgroup\$
    – DELETE_ME
    Feb 24 at 4:32
  • \$\begingroup\$ with that, it's problematic, you'd better specify that "If there are \$ n \$ such numbers, the answer must provably finish printing them all without assuming the conjecture" -- although for most approaches it isn't that hard. \$\endgroup\$
    – DELETE_ME
    Feb 24 at 4:38
3
\$\begingroup\$

Write an interpreter generator

\$\endgroup\$
14
  • \$\begingroup\$ Can an input contain one or more operations? like a + 1 - 4 * 8? Is input guaranteed to be valid? \$\endgroup\$
    – wasif
    Mar 22 at 17:11
  • \$\begingroup\$ @Wasif editing the answer \$\endgroup\$
    – user100690
    Mar 22 at 17:12
  • \$\begingroup\$ Another suggestion, you might make it a code-challenge, where the objective will be to generate as short output as possible (Which means to golf the generated interpreter as much as possible), where the original source code length will not matter, so people can work for their code more peacefully, But code-golf (original challenge) one is good too. \$\endgroup\$
    – wasif
    Mar 22 at 17:14
  • \$\begingroup\$ @Wasif hmm... not a bad idea at all. This challenge does seem more effective with the code-challenge tag, I will edit that into the answer. \$\endgroup\$
    – user100690
    Mar 22 at 17:17
  • \$\begingroup\$ @Wasif on second thought, I'm not really sure how you would actually test the length of the output... it would not be fair for one answerer to test with a 100-command language while another tests with a simple 1-command language. Thanks for the suggestion, but code-golf seems like the better option for now. \$\endgroup\$
    – user100690
    Mar 22 at 17:19
  • \$\begingroup\$ OK, also how would handle destructive input like a / 0, which attempts to divide the accumulator by 0, which would result into crashing the interpreter? \$\endgroup\$
    – wasif
    Mar 22 at 17:22
  • \$\begingroup\$ the input is valid doesn't seem like a good enough description, let me change that \$\endgroup\$
    – user100690
    Mar 22 at 17:22
  • \$\begingroup\$ "each command is one letter long." so, highest number of inputs are 26? \$\endgroup\$
    – wasif
    Mar 22 at 17:33
  • \$\begingroup\$ Can we pre-define the input array in the header section of Try It Online? \$\endgroup\$
    – wasif
    Mar 22 at 17:35
  • \$\begingroup\$ @Wasif yes, that can be inferred from that fact. Not sure what the header is, because I don't really use tio \$\endgroup\$
    – user100690
    Mar 23 at 6:23
  • \$\begingroup\$ Header section means the part where you write code, is not added to the byte count. \$\endgroup\$
    – wasif
    Mar 23 at 6:52
  • \$\begingroup\$ Let us continue this discussion in chat. (Automatically comments were moved there because lengthy conversations cannot be run in comments) \$\endgroup\$
    – wasif
    Mar 23 at 6:52
  • \$\begingroup\$ I've edited this to a stub now that it's been posted \$\endgroup\$ Mar 23 at 15:40
  • \$\begingroup\$ @ChartZBelatedly thank you, forgot to do that \$\endgroup\$
    – user100690
    Mar 23 at 16:05
3
\$\begingroup\$

Keep PPCG running in Game of Life

\$\endgroup\$
5
  • \$\begingroup\$ "Minimally destroying CGCC", "Keep PPCG running". Hmm, someone doesn't like the name change :). May I ask why you have this proposal too, though? \$\endgroup\$
    – user
    Mar 22 at 19:24
  • 2
    \$\begingroup\$ @OriginalOriginalOriginalVI Because the two tasks are different, and I very much doubt answers to the two will be trivially similar \$\endgroup\$ Mar 22 at 19:38
  • \$\begingroup\$ Right now you could just place a glider in the box and it would run forever. Maybe redefine 'fixed position'? \$\endgroup\$
    – emanresu A
    Mar 23 at 8:16
  • \$\begingroup\$ @Ausername "If any spaceships or patterns of infinite growth are generated, the board will never reach a "fixed state" and such cases are invalid submissions." A glider is a spaceship \$\endgroup\$ Mar 23 at 13:13
  • \$\begingroup\$ Oh ok, didn't see that bit. \$\endgroup\$
    – emanresu A
    Mar 23 at 19:37
3
\$\begingroup\$

Limit of lists

You're given a never-ending sequences of lists, each of which appends some number of values to the end of the previous one. That is, each list is a prefix of the next.

3
3,1,4
3,1,4,1
3,1,4,1
3,1,4,1
3,1,4,1,5,9,2,6
...

While some steps may leave the list unchanged, its length grows unboundedly, giving an infinite list in the limit. Your goal is to output this infinite list.

Note that you can't know a-priori how many lists you must read to get, say, the 5th value in the infinite list, just that you'll eventually hit a list with 5 or more elements.

Input and output:

The list elements are digits 0-9. You may treat them as characters if you wish.

The input and output are both infinite lists. These can be represented in various ways, and may be different for the input and output.

  • An infinite list or stream
  • A stateful method or black-box function that produces a new value with each call
  • Repeatedly reading from STDIN or writing to STDOUT, or file buffers or the like

A mapping from index to value isn't allowed for input or output. The output must be uniform, without chunks of digits grouped together.


Sandbox: Infinite list I/O is hard. Any suggestions?

\$\endgroup\$
3
  • \$\begingroup\$ "Your goal is to output this infinite list" - can you clarify that it's by taking later elements from the lists that get later and later in the input list - I had to read this several times to understand that. Also, while I don't think there's any getting around the infinite input requirement, perhaps you could change the output to standard sequence rules to make it more flexible? \$\endgroup\$
    – pxeger
    Mar 27 at 18:04
  • \$\begingroup\$ Is the first list guaranteed to be one element long? Or can it be any length? Can it (and any subsequent lists) be empty? \$\endgroup\$
    – pxeger
    Mar 27 at 18:09
  • \$\begingroup\$ You should probably specify the intermediate output/s needs to be as soon as it's available from the input infinite lists, or at least in finite time, so noone can submit tail -1 \$\endgroup\$
    – pxeger
    Mar 27 at 18:21
3
\$\begingroup\$

cadaddadadaddddaddddddr - linked list accessing

\$\endgroup\$
8
  • \$\begingroup\$ Yay, a lisp challenge! Does each 'a' mean a car and each 'd' a cdr? \$\endgroup\$
    – user
    Mar 24 at 21:56
  • 1
    \$\begingroup\$ @OriginalOriginalOriginalVI yeah, but I'm to lazy to have written a description in english so far. I guess I'll get to it eventually :P \$\endgroup\$
    – Wezl
    Mar 24 at 21:58
  • \$\begingroup\$ Fortunately the common lisp hyperspec already describes the bulk of it well. \$\endgroup\$
    – Wezl
    Mar 24 at 22:22
  • \$\begingroup\$ You might want to make the reference implementation a link to TIO (unless it doesn't work on TIO, of course) \$\endgroup\$
    – user
    Mar 24 at 22:23
  • \$\begingroup\$ @OriginalOriginalOriginalVI Why? (I can't access TIO anyway) \$\endgroup\$
    – Wezl
    Mar 24 at 22:25
  • \$\begingroup\$ Meh, I just don't like those code snippets, and it makes it easier to pull out of the question, modify the input, and stuff. These code snippets sometimes break for me. If you can't access TIO, though, it doesn't matter, of course. \$\endgroup\$
    – user
    Mar 24 at 22:26
  • \$\begingroup\$ posted \$\endgroup\$
    – Wezl
    Mar 25 at 15:04
  • \$\begingroup\$ I've edited this down to a stub now that it's been posted \$\endgroup\$ Mar 28 at 14:01
3
\$\begingroup\$

Un-pipe an Elixir expression

\$\endgroup\$
5
  • \$\begingroup\$ It's unclear what kind of expressions we have to deal with, but it looks good, and interesting . E.g. do we have to handle expr |> function(with_one_parameter)? \$\endgroup\$
    – Wezl
    Mar 25 at 15:27
  • \$\begingroup\$ @Wezl I was thinking the expression could be anything with printable non-whitespace ASCII but I realize now that could be problematic. I'll change it to be more restrictive. \$\endgroup\$
    – 79037662
    Mar 25 at 15:30
  • \$\begingroup\$ @Wezl I specified that you may assume all functions will take only one parameter, so you do not have to handle expr |> function(with_one_parameter). \$\endgroup\$
    – 79037662
    Mar 25 at 15:39
  • 1
    \$\begingroup\$ Why do some piped expressions have () and some do not? Are we meant to support both of these? \$\endgroup\$
    – emanresu A
    Mar 26 at 4:45
  • \$\begingroup\$ @Ausername It's to demonstrate that both are valid, but as I state in the rules you need only support one convention. \$\endgroup\$
    – 79037662
    Mar 26 at 13:17
3
\$\begingroup\$

What's my TIO uniqueness?

\$\endgroup\$
9
  • \$\begingroup\$ Oops, didn't read that \$\endgroup\$
    – user
    Mar 23 at 20:59
  • \$\begingroup\$ Maybe you could say "undefined" instead of 0 in the sentence "The TIO uniqueness of a language for which this is impossible is 0". Also, do you want submissions to store all 680 language names in the code? \$\endgroup\$
    – Bubbler
    Mar 24 at 23:58
  • 1
    \$\begingroup\$ @Bubbler Changed to undefined, it fits better. Yes, submissions should have some way of storing the names, be it in an external file or in the program itself etc. \$\endgroup\$ Mar 25 at 0:02
  • \$\begingroup\$ @FryAmTheEggman Given that there are 680, I think it may be impractical to include the full list in the question, which is why I linked to this gist with all languages and their outputs \$\endgroup\$ Mar 25 at 0:20
  • \$\begingroup\$ Ah, sorry, I missed the link. \$\endgroup\$ Mar 25 at 3:44
  • \$\begingroup\$ "subsequence" tag? Why? \$\endgroup\$
    – tsh
    Mar 29 at 8:58
  • 1
    \$\begingroup\$ @tsh Because the TIO uniqueness depends on the shortest substring that isn't common with any other language \$\endgroup\$ Mar 29 at 18:49
  • \$\begingroup\$ but substring is not subsequence \$\endgroup\$
    – tsh
    Mar 30 at 0:32
  • \$\begingroup\$ @tsh No, but [substring] isn't a tag, and [subsequence] is the best alternative \$\endgroup\$ Mar 30 at 21:37
3
\$\begingroup\$

Rejecting invalid IPv4 addresses

\$\endgroup\$
4
  • \$\begingroup\$ You should generally include the definition of things like this directly in the challenge rather than just linking to a Wikipedia article on it, so people don't have to go to an external site \$\endgroup\$
    – pxeger
    Apr 8 at 8:42
  • \$\begingroup\$ I think it would be clearer if you used boolean true/false for "is this valid", rather than "invalid" vs "valid". You might also want to change classification to decision-problem \$\endgroup\$
    – pxeger
    Apr 8 at 8:46
  • \$\begingroup\$ @pxeger Thanks. Included both suggestions. \$\endgroup\$
    – rsjaffe
    Apr 8 at 15:55
  • \$\begingroup\$ Is this means the input should always be a string / list of characters? May I take input as an array of 4 integers / a 32 bit unsigned integer / a built-in type for IP address (if there is one)? \$\endgroup\$
    – tsh
    Apr 13 at 3:57
3
\$\begingroup\$

Remove first encountered elements from a second list

\$\endgroup\$
8
  • 1
    \$\begingroup\$ While this comes from an SE question, having two arrays seems a bit odd. A more standard task is simply to remove the first occurrence from the single array. (Though, it may be a duplicate then) \$\endgroup\$ Aug 17 '16 at 18:33
  • \$\begingroup\$ @NathanMerrill I thought of limiting it to just one array, but in my opinion this way is more challenging. \$\endgroup\$
    – pajonk
    Aug 17 '16 at 19:01
  • \$\begingroup\$ I agree, it does increase the difficulty of the challenge. \$\endgroup\$ Aug 17 '16 at 19:04
  • 1
    \$\begingroup\$ The separator between the elements of the list needs to be distinct from the separator between lists -- it just means that the two output lists should be distinguishable (and not clumped into a single list, for example), right? The current wording doesn't make much sense if we can return two lists from a function. \$\endgroup\$
    – Bubbler
    Apr 12 at 23:07
  • \$\begingroup\$ @Bubbler, yes, that's right - I'll change it. Thanks. \$\endgroup\$
    – pajonk
    Apr 13 at 5:06
  • 1
    \$\begingroup\$ I suggest using standard JSON in your examples, e.g. [2,3,3,5,5,4,3,7,1] \$\endgroup\$
    – Adám
    Apr 13 at 6:58
  • 2
    \$\begingroup\$ I think removing elements from L2 is unnecessary. The essence of the challenge is to remove elements from L1 based on the first occurrence of each unique element in L2. \$\endgroup\$
    – Adám
    Apr 13 at 7:00
  • \$\begingroup\$ Thanks @Adám for the comments. You're right - I edited accordingly. \$\endgroup\$
    – pajonk
    Apr 13 at 19:41
3
\$\begingroup\$

Interpret control characters like a terminal

\$\endgroup\$
4
  • \$\begingroup\$ As "your program does not need to interpret backslash escape sequences - the input will contain the literal control codes themselves.", I'd suggest actually including the characters in the test cases, or at least including a TIO link (or pastebin etc.) with the literal characters \$\endgroup\$ Apr 12 at 13:14
  • 1
    \$\begingroup\$ @cairdcoinheringaahing \r isn't really usable on the web because it will be converted to a newline, and most languages have their own literal syntax for entering those characters anyway, so I think it wouldn't really help \$\endgroup\$
    – pxeger
    Apr 12 at 13:18
  • 1
    \$\begingroup\$ Suggest a aaaaaaa\b\b\b\t case, do TAB fill them space? \$\endgroup\$
    – l4m2
    Apr 15 at 4:17
  • \$\begingroup\$ @l4m2 thanks - that helped me discover some subtle bugs in my reference implementation too \$\endgroup\$
    – pxeger
    Apr 15 at 9:01
3
\$\begingroup\$

You are kinda Replacable to Me

\$\endgroup\$
3
\$\begingroup\$

A Self-Referential Sentence

The Story


One day, you decide that you want a sentence that tells you where in the sentence the letter T occurs (excluding whitespace and punctuation). Out of curiosity, you try to make one. Messing around a little you get

T is the first, fourth, eleventh, sixteenth, twenty-fourth, ....

Oh dear, this sentence appears to run forever. But you now think you have an interesting number sequence, so you slap it into the OEIS search bar and lo and behold you find sequence A005224, Aronson's sequence. And better yet, an interesting code-golf problem that no appears to have posed before!


The Task

Your task is to write a program that takes in a single positive integer, n, as input and gives the position of the n-th "t" in the above sentence (indexing begins at 1 for the sake of this problem). For example, an input of 1 should return 1, while 2 should return 4. The input number will not exceed 4 decimal digits in length (i.e. the maximum input is 9999)

As always, the shortest code in bytes wins, and standard loopholes apply.


Tags:


The Meta

Ok, so I have a couple of questions, since this my first sandbox post.

  1. What can I do to flesh out this problem? This seems short, especially for a CGSE prompt. Should I somehow flesh out the heading fluff? Or should I add something more to the task itself?
  2. I was pretty thorough in my search of the sandbox and main site for similar problems, but I could always have missed something, so please let me know if this is a duplicate.
  3. Is the 4 digit input limit reasonable? Should I raise it or lower it? Remove it entirely? Since I'm not providing a file with ordinal strings, it seems like having a restriction on the size of the input is quite important.
  4. Finally, please let me know if there's any other glaring problems in this prompt, this is both a first draft, and my first attempt at a code-golf prompt (since high-school).
\$\endgroup\$
3
  • \$\begingroup\$ Nice first challenge! I'd suggest following the standard sequence I/O rules and allowing programs to output either the first \$n\$, the \$n\$th term or all terms. Additionally, forcing 1-indexing (for the sequence) doesn't improve the challenge any more than allowing either 0 or 1 indexing. I cannot find any challenge that could be a dupe through some searching, so this looks to be 100% original. Finally, I'd recommend including either test cases or the first 10 or so terms in the challenge body \$\endgroup\$ Apr 24 at 16:21
  • 1
    \$\begingroup\$ @cairdcoinheringaahing 1-indexing is fundamental to the recursive definition of this sequence, as “T is the zeroth, third, tenth, twelfth, seventeenth, twentieth, …” is quite a different sequence (not just off by one). \$\endgroup\$ Apr 25 at 18:25
  • \$\begingroup\$ @AndersKaseorg I meant 0 indexing in the input, not in the position of the T (e.g. n = 0 would output 1, n = 1 would output 4, etc.) \$\endgroup\$ Apr 25 at 18:27
3
\$\begingroup\$

diddly darn posted

\$\endgroup\$
10
  • \$\begingroup\$ Tag chess? \$\endgroup\$
    – pxeger
    Apr 12 at 6:43
  • 1
    \$\begingroup\$ My god, this is amazing. I can't wait to see the full version! \$\endgroup\$ Apr 12 at 9:48
  • 1
    \$\begingroup\$ It's not clear to me what should be output in the non-deterministic cases. Do we have to output all possibilites? \$\endgroup\$
    – kops
    Apr 22 at 23:35
  • \$\begingroup\$ Addtionally, what do you want the result of this to be: ,v, \n >,A \n ^<B (pastebin; is multline code possible in a comment?) Rules as written I think it's a tie since the center cell is reached twice but it's not clear this is desirable. \$\endgroup\$
    – kops
    Apr 22 at 23:37
  • \$\begingroup\$ @kops it's okay for the board to result in a tie. \$\endgroup\$
    – lyxal
    Apr 22 at 23:43
  • \$\begingroup\$ And the point is to output the result of the board, which may not be deterministic \$\endgroup\$
    – lyxal
    Apr 22 at 23:43
  • \$\begingroup\$ So each possibility has to be output with the correct probability in the non-deterministic cases? And for the specific board in my second comment, it's very much morally an A victory, not a tie, but the technicality of passing through the same cell going in different directions makes it a tie in these rules which I find a bit weird. \$\endgroup\$
    – kops
    Apr 22 at 23:46
  • \$\begingroup\$ @kops no it is not the probability but the result of running it once. That result may vary. And even though that may seem like it should be a win for A, it could be the result of some clever play from B to trick A into thinking they've won \$\endgroup\$
    – lyxal
    Apr 22 at 23:50
  • \$\begingroup\$ @Lyxal I didn't mean to say the probability itself should be output, but that for each possibility, the probability of that possibility being output has to be correct? \$\endgroup\$
    – kops
    Apr 22 at 23:56
  • \$\begingroup\$ @kops you only ever output one result - the winner of the game when evaluated. Because there are commands that change the direction, it can be impossible to 100% tell who wins. I was simply pointing out that there is more than one possible output for such boards. \$\endgroup\$
    – lyxal
    Apr 22 at 23:59
3
\$\begingroup\$

Interpret Gelatin

\$\endgroup\$
3
\$\begingroup\$

CDGLF:TMN2APL


Meta questions:

  • Is this a duplicate? (I've looked and there are several challenges with operator precedence, but there are large differences such as floor/ceiling and the output format)
  • How can I objectively define "equivalent expressions"? Should I write a reference interpreter or answer?
  • Would it be more interesting going the other way?
  • Should answers be required to reject invalid input? Seems not
  • Should I I've replaced the unicode operators ×÷⌈⌉⌊⌋ with ascii symbols */{}[].
  • Is the exponentiation operator necessary? (It might just make the challenge more cumbersome because of its different associativity)
\$\endgroup\$
6
  • \$\begingroup\$ It was previously APL2TMN. I'm changing it to TMN2APL to make it more interesting. \$\endgroup\$
    – Wezl
    Apr 22 at 14:42
  • 1
    \$\begingroup\$ TMN's +-×÷ are left-associative, but in APL everything is right-associative. The equivalent of TMN 3-5÷2+1 in APL is (3-5÷2)+1; APL 3-(5÷2)+1 is 3-((5÷2)+1). \$\endgroup\$
    – Bubbler
    Apr 22 at 23:41
  • 1
    \$\begingroup\$ Thanks, I completely forgot about associativity. I don't think my grammar handles it, however, so I'm not sure exactly how to resolve this. \$\endgroup\$
    – Wezl
    Apr 22 at 23:44
  • 1
    \$\begingroup\$ Also, I suggest to state the output format (APL) in the same way as you did for the input format (TMN), and state the precedence and associativity (for both TMN and APL) separately in plain English for those who are not familiar with parser grammars. And I think input validation is unnecessary here. \$\endgroup\$
    – Bubbler
    Apr 22 at 23:52
  • \$\begingroup\$ I think the Unicode operators definitely should be replaced with ASCII, because otherwise it's 10 bytes used on every answer. This would require you to remove or change the output syntax of exponentiation, but I don't really feel like it adds much tbh. \$\endgroup\$
    – pxeger
    Apr 24 at 15:57
  • 1
    \$\begingroup\$ @pxeger I've changed it, and I agree. \$\endgroup\$
    – Wezl
    Apr 25 at 0:53
3
\$\begingroup\$

Distance between vowels

Objective

Given two vowels represented in single IPA characters, calculate the distance between them.

Vowels

Vowels are characterized by three factors: Height, backness, and roundedness. Here, all vowels have the three characteristics as integers.

Unrounded vowels (z = 0)

    x=0       x=1       x=2       x=3       x=4
y=6 i(U+0069)           ɨ(U+0268)           ɯ(U+026F)
y=5           ɪ(U+026A)           ʊ(U+028A)
y=4 e(U+0065)           ɘ(U+0258)           ɤ(U+0264)
y=3                     ə(U+0259)
y=2 ɛ(U+025B)           ɜ(U+025C)           ʌ(U+028C) 
y=1 æ(U+00E6)           ɐ(U+0250)
y=0 a(U+0061)                               ɑ(U+0251)

(I know, Wikipedia states ʊ as rounded, but official IPA doesn't specify the roundedness of ʊ. It will be considered unrounded for this challenge.)

Rounded vowels (z = 1)

    x=0       x=1       x=2       x=3       x=4
y=6 y(U+0079)           ʉ(U+0289)           u(U+0075)
y=5           ʏ(U+028F)
y=4 ø(U+00F8)           ɵ(U+0275)           o(U+006F)
y=3
y=2 œ(U+0153)           ɞ(U+025E)           ɔ(U+0254) 
y=1
y=0 ɶ(U+0276)                               ɒ(U+0252)

Metric

Your metric \$d\$ shall fit the usual definition of metric:

  • \$d(v,w)=0\$ if and only if \$v=w\$

  • For all \$v\$ and \$w\$, \$d(v,w)=d(w,v)\$

  • For all \$v\$, \$w\$ and \$x\$, \$d(v,x)≤d(v,w)+d(w,x)\$

As an additional constraint, the norm \$\Vert\cdot\Vert\$ induced by \$d\$ shall satisfy:

  • For all \$x≠0\$, \$y\$ and \$z\$, \$\Vert(0,y,z)\Vert<\Vert(x,y,z)\Vert\$

  • For all \$x≠0\$, \$y\$, \$z\$ and \$k>1\$, \$\Vert(x,y,z)\Vert<\Vert(kx,y,z)\Vert\$

  • Analogous rules for the y-axis and z-axis

All of these apply only to the vowels above. All other inputs fall in don't care situation.

Rules

  • Input format is flexible. It may be two chararacters, or a single string containing two charcters. In any case, every input that doesn't fit in your format falls in don't care situation.

  • Output format is also flexible.

\$\endgroup\$
3
\$\begingroup\$

Generate a UK number plate

\$\endgroup\$
5
  • \$\begingroup\$ I'd suggest saying AANNXXX or something like that instead of AA12XXX so it's clear the age identifier isn't always 12 (that's clarified later, but still). \$\endgroup\$
    – user
    Apr 28 at 18:12
  • \$\begingroup\$ Just a note: the last 3 characters can't be either Q or I \$\endgroup\$ May 1 at 18:13
  • \$\begingroup\$ @cairdcoinheringaahing I thought that too, but I found no mention of it in the government document so I kept it as the whole alphabet. shrug \$\endgroup\$
    – pxeger
    May 1 at 19:37
  • \$\begingroup\$ There's a Q in the alphabet for the first letter, but then you say the alphabet, minus IJQTUXZ. \$\endgroup\$
    – Arnauld
    May 5 at 18:13
  • 1
    \$\begingroup\$ @Arnauld yep, that shouldn't be there. Too much muscle memory from typing the alphabet correctly I guess :þ \$\endgroup\$
    – pxeger
    May 5 at 19:15
3
\$\begingroup\$

Worst time complexity for an irreducible program

Time complexity, typically represented in Big O notation, represents how long a program will typically take to run given some input(s), ignoring constants.

Your task is to do one of the following things, with the worst time complexity possible:

  • Sort an array of integers
  • Find duplicates in an array
  • Find longest strictly increasing slice of an array of integers

Tasks:

All of the tasks involve taking one input, an array of items, in any reasonable format, and returning an array. If your language supports mutable array data types, this is an allowed output format. Assume all items in the arrays will be (not necessarily positive) integers.

If you choose sorting: You may choose to sort the array by minimum or maximum.

If you choose listing duplicates: You may include a duplicate item any number of times in the output; [1, 2, 2, 3, 4] could result in [2, 4], [2, 2, 4], or even [2, 4, 4, 4].

If you choose longest strictly increasing slice: Duplicate items do not count as increasing, so [1, 2, 2, 4] is not strictly increasing. The items do not have to increase by a steady amount; [-1, 4, 14, 16, 17] is strictly increasing.

Rules:

Your program must be irreducible. This means removing any slice of the program, other than the whole thing (or nothing), will cause it to no longer perform the required task. Your program should terminate in a finite amount of time. You can assume your program will never run out of memory, and it does not have to terminate before the heat death of the universe.

This is a . The winner will be based on the average time complexity, with slower being better, followed by the minimum and then maximum for ties.

\$\endgroup\$
2
  • \$\begingroup\$ Unfortunately, this answer broke all "irreducible" challenges. You can execute (almost) arbitrary code unrelated to the task without breaking the "irreducible" requirement. \$\endgroup\$
    – Bubbler
    Apr 22 at 0:16
  • \$\begingroup\$ @Bubbler Hmm, and I don't think irreducible is a sensible requirement for this either. It definitely makes more sense with bytes than time, along with pristine. I'll have to think about some creative limitations. Maybe unique bytes only? \$\endgroup\$ Apr 22 at 0:22
3
\$\begingroup\$

I'm Lazy: Close my Parens

\$\endgroup\$
10
  • 1
    \$\begingroup\$ It's clear what to do with ], but what does [ represent? Is it the same as just (? \$\endgroup\$
    – DJMcMayhem
    Jun 1 at 22:00
  • \$\begingroup\$ Why is ([(] invalid but [(] is not? Will there ever be multiple ] in a row? \$\endgroup\$
    – DJMcMayhem
    Jun 1 at 22:05
  • \$\begingroup\$ @DJMcMayhem ([(] is invalid because it is the same as [(] but with an unmatched ( at the beginning since the ] only closes the [. There may be multiple ] in a row. \$\endgroup\$
    – Wezl
    Jun 1 at 22:08
  • 3
    \$\begingroup\$ So basically ] matches as many open parens as possible until it hits a [ at which point it has to stop? \$\endgroup\$
    – DJMcMayhem
    Jun 1 at 22:10
  • \$\begingroup\$ @DJMcMayhem yes. Should I add that to the question for clarity? \$\endgroup\$
    – Wezl
    Jun 1 at 22:12
  • \$\begingroup\$ Yes, I think that would help. \$\endgroup\$
    – DJMcMayhem
    Jun 1 at 22:17
  • 1
    \$\begingroup\$ Not sure if lisp tag is appropriate, because the challenge itself doesn't have to do with lisp. \$\endgroup\$
    – qwr
    Jun 2 at 14:43
  • 2
    \$\begingroup\$ Tag: balanced-string? \$\endgroup\$
    – pxeger
    Jun 3 at 10:47
  • \$\begingroup\$ @pxeger nice tag-finding skills :) I'll add that. \$\endgroup\$
    – Wezl
    Jun 3 at 13:04
  • \$\begingroup\$ @qwr How else do I get the tag badge :P \$\endgroup\$
    – Wezl
    Jun 3 at 13:07
3
\$\begingroup\$

But, Is It Art?

\$\endgroup\$
1
  • \$\begingroup\$ I think it is clear, but the second example of "is not equivalent to" is a little unnecessary in my opinion. \$\endgroup\$
    – Alex bries
    Jun 2 at 10:03
1
14 15
16
17 18
116

You must log in to answer this question.

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