555
\$\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".

Get the Sandbox Viewer to view the sandbox more easily!

\$\endgroup\$
0

3920 Answers 3920

1
10 11
12
13 14
131
4
\$\begingroup\$

Crate art stacking

\$\endgroup\$
4
  • \$\begingroup\$ Is trailing whitespace allowed? \$\endgroup\$
    – pajonk
    Mar 2 at 7:11
  • 1
    \$\begingroup\$ This one is much better than the Stack Em one. \$\endgroup\$
    – ophact
    Mar 2 at 8:40
  • \$\begingroup\$ @pajonk do you think its better to allow or not allow? \$\endgroup\$
    – DialFrost
    Mar 3 at 2:57
  • 1
    \$\begingroup\$ I think I usually see allowing trailing whitespace in such challenges. Also, I'm always on the side of loosening I/O requirements. \$\endgroup\$
    – pajonk
    Mar 3 at 7:28
4
\$\begingroup\$

Sorted strings filter

Input a list of strings a and a string s for search keyword. Find out all strings in a which contains s as subsequence. And sort them in the following order:

  1. Exact equals to s
  2. Starts with s
  3. Contains s as substring (continuous subsequence)
  4. Contains s as subsequence

Detail

  • When two strings belongs to the same group, you may sort them in any order you prefer.
  • String matching is case sensitive. "A" and "a" are different characters.
  • All strings will only contain printable ASCII (#32~#126).
  • All strings will not have leading or trailing whitespaces.
  • All strings will be non-empty.
  • List a does not contain duplicate strings.

Example

When the list is ["center","encounter","enter","enterprise","event"], and the search target is "enter", output should be ["enter","enterprise","center","encounter"]. "event" is not included in the output as it doesn't contain "enter" as subsequence.

Test cases

["center","encounter","enter","enterprise","event"]
"enter"
-> ["enter","enterprise","center","encounter"]

["celebration","cooperation","generation","operation","ratio"]
"ratio"
-> ["ratio","celebration","cooperation","generation","operation"]

["combination","explanation","international","nation","national","nomination"]
"nation"
-> ["nation","national","combination","explanation","international","nomination"]

["ever","every","here","very","where"]
"everywhere"
-> []

["interaction","traditional","train","training","transformation"]
"train"
-> ["train","training","interaction","traditional","transformation"]

["condition","confusion","construction","contribution","information","organization","recommendation","transportation"]
"onion"
-> ["condition","confusion","construction","contribution","organization","recommendation"]

["...","---",".-.-.-","..--","-..-"]
"--"
-> ["---","..--",".-.-.-","-..-"]

["#","##","###","####","#####"]
"####"
-> ["####","#####"]

Output from your program may be different from above test cases, as the order of words in same group is not required.

Rules

Input / Output

Input / Output are flexible. For example, you may use any reasonable ways including but not limited to:

  • You may I/O string as
    • Your languages built-in string in ASCII or any ASCII compatible encoding (e.g. UTF-8);
    • Your languages built-in string in any codepage that supports all printable ASCII characters (e.g. UTF-16);
    • NUL terminated array of characters;
    • array of integers, each integer is the ASCII value of character
    • 0 terminated integer array;
  • You may I/O the array of string as
    • A collection (OrderedSet, LinkedList, Array, ...; or HashSet only for input) of strings
    • A character (or ASCII value) matrix with 0 padding at the ending to each short ones;
      • Output matrix may have unnecessarily extra 0 padding;
    • Line break (CR / LF / CRLF) separated single string;
    • JSON encoded array of string

Meta: Is this clear enough? Any duplicate? Will it be interesting enough to post?

\$\endgroup\$
6
  • \$\begingroup\$ IMHO this would benefit from explicitly allowing or disallowing I/O as a list of char codes. \$\endgroup\$
    – pajonk
    Mar 9 at 13:10
  • \$\begingroup\$ @pajonk Included. Will it be helpful? \$\endgroup\$
    – tsh
    Mar 10 at 2:36
  • \$\begingroup\$ this challenge is quite interesting imo, but the bolding of words in the description might be abit hard to see (idk if you want to change it or leave it uty) but otherwise gd job on the challenge details! \$\endgroup\$
    – DialFrost
    Mar 10 at 2:44
  • 1
    \$\begingroup\$ @DialFrost Do you mean the example section? IMO, the bolding may be ignored and readers may still understand the question without them. So I think leave it as is should be enough. \$\endgroup\$
    – tsh
    Mar 10 at 2:55
  • \$\begingroup\$ ah ok @tsh sry my bad \$\endgroup\$
    – DialFrost
    Mar 10 at 2:59
  • \$\begingroup\$ @tsh Yes, thank you. \$\endgroup\$
    – pajonk
    Mar 10 at 5:27
4
\$\begingroup\$

Repeat List Until Longer

\$\endgroup\$
4
  • \$\begingroup\$ I think the output for the last example should be [2,3,5,2,3,5,2,3,5]? \$\endgroup\$
    – Dingus
    Mar 9 at 0:26
  • \$\begingroup\$ Ah yes, that was my muscle memory being a little off. Thanks. \$\endgroup\$
    – Seggan
    Mar 9 at 0:27
  • \$\begingroup\$ Suggestion: instead of second list as input take only its length. \$\endgroup\$
    – pajonk
    Mar 9 at 13:13
  • \$\begingroup\$ This problem is component of a solution for another problem. I prefer it like this. \$\endgroup\$
    – Seggan
    Mar 9 at 15:26
4
\$\begingroup\$

The Missing Match

\$\endgroup\$
5
  • \$\begingroup\$ The task becomes clear by the end but I think some reorganisation of the text would help. In the second sentence you say 'The braces are all balanced', but further down we find out that this isn't actually true: 'inside the string there is a single unbalanced brace'. I'd suggest these two bits of information should be closer together. \$\endgroup\$
    – Dingus
    Mar 13 at 2:26
  • \$\begingroup\$ @Dingus thanks for the feedback. I updated the answer; would you care to take a look? \$\endgroup\$
    – code
    Mar 13 at 3:25
  • \$\begingroup\$ Looks good to me, but one other thing - I'd suggest brackets is a more appropriate word than braces here. \$\endgroup\$
    – Dingus
    Mar 13 at 6:29
  • \$\begingroup\$ @Dingus sure, thanks! Do you suggest I post it anytime soon or wait another day or so? \$\endgroup\$
    – code
    Mar 13 at 6:54
  • \$\begingroup\$ The general recommendation is to leave it in the Sandbox a few days at least, just to maximise the number of eyes that see it before it goes on main. \$\endgroup\$
    – Dingus
    Mar 13 at 9:25
4
\$\begingroup\$

Can you decrypt me?

Cops

Cops, post obfuscated code that hides a number \$n\$ inside its code. If \$n\$ condchars are changed, the program outputs \$n\$. Otherwise, it outputs a different number. Both programs may not error.

Robbers

Find the chars to change and what they should change into.

Example

print(2)

N is 1.


Robbers' post:

print(1)

Scoring

Cops, the user with the most uncracked posts wins. Robbers, the user with the most cracks wins.

\$\endgroup\$
7
  • \$\begingroup\$ How could you stop robbers writes a code that try to apply cops code on every possible inputs until find out one matching output? \$\endgroup\$
    – tsh
    Mar 16 at 11:22
  • \$\begingroup\$ @tsh uh, can you clarify? \$\endgroup\$
    – Bgil Midol
    Mar 16 at 11:51
  • \$\begingroup\$ Does this mean robber just need to write a program that for (i in AllPossibleInputs) if (CopsCode(i) == CopsOutput) return i? \$\endgroup\$
    – tsh
    Mar 16 at 12:28
  • 1
    \$\begingroup\$ @tsh, is it possible to enforce "don't do that?" \$\endgroup\$
    – Bgil Midol
    Mar 16 at 13:11
  • \$\begingroup\$ This is a good format for a CnR, but you need to specify scoring criteria. For the cops, "shortest code" (code-golf) is probably good enough. For robbers, something like "most cracked answer". You should probably add a rule to allow uncracked cops' answers to become "safe" after a certain amount of time (probably around 1-2 weeks) \$\endgroup\$
    – pxeger
    Apr 12 at 9:01
  • \$\begingroup\$ @pxeger does it need more clarifying and details? (other then scoring criteria) \$\endgroup\$
    – Bgil Midol
    Apr 12 at 14:10
  • \$\begingroup\$ No, if you add those things, it will be ok \$\endgroup\$
    – pxeger
    Apr 12 at 14:47
4
\$\begingroup\$

What does the text talk about?

note that the machine-learning tag will be new

META: this is far from being done. I also understand that this challenge depends heavily on manual opinion about the "type" of a piece of text. Hence, if you take issue with that, I would appreciate your giving a comment that suggests ways to fix that issue, rather than an unjustified downvote related to that issue.

Additionally, this might be a duplicate. I would appreciate your pointing this out before I compile the list of texts, if possible. However, if you identify a duplicate after I start compiling the list of texts, that is also fine.

Some parts use the future tense to talk about what I will do. Obviously I will have done them by the time I post the challenge.

The sections in italic could be taken as being ambiguous.

The links to the training, validation and test sets are not available yet. And of course, I don't yet have labels on my side.


This is a project that I once attempted to do, having learned machine learning. I run a forum app, and I was thinking of incorporating my new machine learning knowledge into that app by creating a model that could detect topics related to a given topic. After having worked on it for a few days, I hadn't made much progress, so I abandoned it. I hereby challenge you to make a similar model, ideally with machine learning, but that is not required. Your model will classify the topic of a piece of text. Such a model could then be used to find text related to a given piece of text by finding texts with a similar topic. You can choose to write your model without machine learning.

This is thus essentially a machine learning challenge. (or ideally, it will be. You may choose to write your solution without machine learning, but I am mainly looking forward to seeing machine learning solutions.) I will provide a large set of "articles", divided into a training set, a validation set, and a test set, with a 60-30-10 split. I expect there to be about 500 articles in all.

The articles in the training and validation sets are labeled with their topics: for instance, history, geography, mathematics, programming, etc. The test set, importantly, does not have public-facing labels, but I have labels on my side.

The training set is available here.

The validation set is available here.

The test set is available here.

Challenge

Write a classifier that attempts to classify the topic of a piece of text. The possible topics are:

(coming soon)

You can choose any of (coming soon) distinct values to represent the topic.

It should be able to produce an output that is one, and only one, of the chosen distinct values given any input string.

You have access to the train set to teach your classifier to recognize the topics (if you are using machine learning). The validation set can be used to compare different approaches.

Your submission will be scored based on how well it does on the test set. I will write the test set articles in such a way that they are not ambiguous (500 years ago, a mathematician discovered a method to calculate integrals is ambiguous as the sentence could be about mathematics or history, but Learn about the way people lived 1000 years ago is only about history). Your score is the number of articles it can correctly classify out of the test set. The higher the number of articles your submission can correctly classify, the better the score is. Thus the winner of this challenge is the submission that classifies the most articles correctly.

Importantly, this is not . I expect this to be a challenge that demands significant time and effort to produce a solution that scores highly, so you may post a link to a GitHub repository hosting the solution if required.

You are encouraged to either provide a way to easily run your solution, or provide the list of outputs that your code produces when given the test set articles. Even better, you could post a Jupyter notebook (if you are answering with a supported language) containing your solution, complete with test set outputs.

Important: please do not post a solution that is optimized only for the test set. It should work reasonably well in general.

Just so that you can get an idea of the topics:

Article: The dinosaurs went extinct 66 million years ago due to an asteroid impact.
Topic: history

Article: Time complexity is a measure of the complexity of an algorithm. For instance, the operation of adding two integers is usually taken to have a complexity of O(1). The operation of summing a list given as input has a complexity of O(n) where n is the size of the input.
Topic: programming

Article: Partial derivatives are derivatives taken with respect to one variable.
Topic: mathematics

Article: Planes are for going on holiday, especially island getaways.
Topic: holiday

Article: Carrot Cake Potato Mushroom
Topic: food
\$\endgroup\$
1
  • \$\begingroup\$ [joke] mathematica probably has a builtin for this \$\endgroup\$
    – des54321
    May 2 at 18:54
4
\$\begingroup\$

Matrix Meets ASCII Art

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Is the input guaranteed to contain at least one 1? How should we handle all-0 rows? (will it ever be a case?) Are the 1s going to be always neighbours? I suggest adding some more examples/test-cases. \$\endgroup\$
    – pajonk
    May 9 at 11:05
4
\$\begingroup\$

Haplololololololology!

\$\endgroup\$
7
  • 1
    \$\begingroup\$ Suggested test case: aaaabaaaab -> aaaab, as a simple example of matching the longest sequences not producing the shortest result (which would be abab) \$\endgroup\$ May 4 at 1:22
  • 2
    \$\begingroup\$ Thanks, added... \$\endgroup\$ May 4 at 1:27
  • 2
    \$\begingroup\$ What about something like filed edit? \$\endgroup\$
    – emanresu A
    May 4 at 5:45
  • 2
    \$\begingroup\$ It would yield filedit - or were you suggesting I add it to the test cases? \$\endgroup\$ May 4 at 5:51
  • 1
    \$\begingroup\$ Isn't mississippi -> missippi? \$\endgroup\$
    – pajonk
    May 4 at 12:55
  • \$\begingroup\$ Awesome, thank you! \$\endgroup\$ May 5 at 1:40
  • \$\begingroup\$ Edited down to a stub now that it's been posted to save space. \$\endgroup\$
    – Steffan
    May 13 at 4:04
4
\$\begingroup\$

Straighten my corners... diagonally

\$\endgroup\$
5
  • 1
    \$\begingroup\$ This is OEIS A060736. Sample Python copied from OEIS. \$\endgroup\$
    – Steffan
    May 22 at 23:14
  • \$\begingroup\$ Cheesy title suggestion: straighten my corners... diagonally \$\endgroup\$
    – chunes
    May 24 at 14:42
  • \$\begingroup\$ @chunes That sounds great, thanks! \$\endgroup\$
    – emanresu A
    May 24 at 19:33
  • \$\begingroup\$ Also, you probably realize this, but the question doesn't currently have a score criterion. \$\endgroup\$
    – chunes
    May 25 at 13:39
  • \$\begingroup\$ @chunes Nice catch, thanks :) \$\endgroup\$
    – emanresu A
    May 25 at 19:20
4
\$\begingroup\$

Make the list Fibonacci-like

\$\endgroup\$
4
\$\begingroup\$

Count /[^a-z]/gi with /[a-z]/gi

\$\endgroup\$
1
  • 4
    \$\begingroup\$ Suggested tag: self-scoring. Maybe solve ASCII-only dilemma with a rule that you must support ascii and characters in your source code (if outside ascii)? Requiring handling characters outside ASCII may exclude some languages and complicate things in others. Also, I suggest code-golf as tie-breaker, as I suppose many languages will end up with the same score. \$\endgroup\$
    – pajonk
    Jun 6 at 7:59
4
\$\begingroup\$

Generate a Baudot punched tape segment

What is Baudot?

From Wikipedia

The Baudot code [boˈdo] is an early character encoding for telegraphy invented by Émile Baudot in the 1870s. It was the predecessor to the International Telegraph Alphabet No. 2 (ITA2), the most common teleprinter code in use until the advent of ASCII. Each character in the alphabet is represented by a series of five bits, sent over a communication channel such as a telegraph wire or a radio signal. The symbol rate measurement is known as baud, and is derived from the same name.

Task:

For this challenge, your task is to write a program or a function that takes a string as its input and generates ASCII art that looks like a roll of punched tape. For the purposes of this challenge, you should specifically use the following variant, as it just happened to be the first image I found :P

International Telegraph Alphabet 2 brightened

For example where input is "HELLO WORLD\r\n" (note that carriage return is optional)

 *    *      
  **  * **  *
.............
*    *  *    
    *  *   * 
* ***  *  *  
hello worldcl
           rf

Program Description:

  • The program/function takes the input and turns it into a sequence of Baudot words (sequences of five bits)
  • For each word, it makes a column of the first two bits, then a . then the remaining three bits
  • Optional trailing space / newline

Criteria:

  • Output may not be output as an array unless there is no other valid option in the language. Trailing spaces and newlines allowed.
  • Any acceptable input
  • Assume all input characters are valid Baudot characters
\$\endgroup\$
2
  • 2
    \$\begingroup\$ No need to specify standard loopholes and I/O, they apply by default. You also override standard I/O with your third rule, so not much of a point to linking to it. \$\endgroup\$ Jun 7 at 21:12
  • \$\begingroup\$ The Baudot code comes with the ability to switch between two modes (one for letters and one for figures). You'll have to clarify if we need to support that and how. \$\endgroup\$
    – Arnauld
    Jun 12 at 20:41
4
\$\begingroup\$

The Magic Money Machine

This KOTH is based on a game of Tom Scott's series Money, so make sure to check out his video


Challenge

There are three rounds per game. Each bot will get 100$.
They'll have to decide how much money they'll keep for themselves, and how much they're going to put in the Magic Money Machine.
The money in the Machine will get a 20% boost in the first round, a 50% boost in the second round, and a 100% boost in the third round.
Each bot will equally get the money left in the Machine.

Example:

  • Bot A decides to put 60$ in the Money Machine and keep 40$ for themselves
  • Bot B decides to put 30$ in the Money Machine and keep 70$ for themselves
  • In total there are 90$ in the Money Machine, so with a boost of eg. 20% that's 108$, so each bot will get an additional 54$
  • Bot A has 94$ in the end
  • Bot B has 124$ in the end

You have to try to get as much money as possible.

Rules:

  • Standard Loopholes apply
  • No interaction with the controller other than by returning values.
  • No interaction with other bots

API Template

def plan(round_num, others_money):
    # Tell the other bots how much money you're going to put in the Machine
    # You are allowed to lie
    return money_insert_pub

def main(round_num, others_money, others_plan):
    # Do stuff here
    return money_insert
  • round_num: an integer ranging from 1 to 3, it depicts the current round
  • others_money: a list of 0, 1, or 2 tuples. Each tuple will contain the money_kept var of the other bots of the last rounds (yours incl.).
  • money_insert_pub: the money_insert value you're telling others
  • money_insert: an integer between 0 to 100, the amount of money you put in the Magic Money Machine
  • others_plan: the money_insert_pub value of the other bots (yours incl.)

Controller code is on Github

Example bots

Beep Boopy Random

import random
def plan(round_num, others_money):
    global money_insert
    money_insert = random.randint(0, 100)
    return money_insert

def main(round_num, others_money, others_plans):
    return money_insert

Random copycat

import random
def plan(round_num, others_money):
    return 100

def main(round_num, others_money, others_plan):
    if round_num == 1:
        money_insert = random.randint(0, 100)
    else:
        money_insert = (
            random.choice(others_money[-1]) if others_money else random.randint(0, 100)
        )
    return money_insert

Meta

  • This is my first (well sort of) KOTH, is there anything I've missed?
\$\endgroup\$
5
  • \$\begingroup\$ Is the controller function written yet? You might want to link to it on Github. \$\endgroup\$
    – Steffan
    Jun 9 at 22:15
  • \$\begingroup\$ @Steffan not yet :P \$\endgroup\$
    – mathcat
    Jun 10 at 8:19
  • \$\begingroup\$ but now I'm done \$\endgroup\$
    – mathcat
    Jun 10 at 12:42
  • 1
    \$\begingroup\$ It looks like the bot that never donates will always win because "Each bot will equally get the money left in the Machine?" Am I missing something? \$\endgroup\$
    – Wezl oOvOo
    Jun 10 at 15:28
  • \$\begingroup\$ @WezloOvOo damn maybe one sec \$\endgroup\$
    – mathcat
    Jun 10 at 15:34
4
\$\begingroup\$

Give f and g that sometimes commute

\$\endgroup\$
8
  • \$\begingroup\$ @WheatWizard, how's this? \$\endgroup\$
    – cjquines
    Jun 11 at 19:15
  • \$\begingroup\$ Seems good. A little odd that when anonymous functions are only allowed for the separate submissions, but understandable. \$\endgroup\$
    – Wheat Wizard Mod
    Jun 11 at 19:36
  • \$\begingroup\$ What restrictions are there on the codomains of the functions? E.g. are \$f(x)=\frac32 x\$, \$f(x)=i^x\$, \$f(x)=\frac1{x^2}\$ valid? \$\endgroup\$
    – att
    Jun 11 at 22:05
  • \$\begingroup\$ @att by "over the integers", i mean that the domain and codomain are integers. i'll clarify. \$\endgroup\$
    – cjquines
    Jun 12 at 5:57
  • \$\begingroup\$ You've specified these functions to act on all integers, but it may be annoying for answers to handle negative numbers and/or zero. Is there a reason you don't restrict the input to positive integers, or allow answers to decide which of \$ \{ \mathbb Z, \mathbb Z^+, \mathbb Z^* \} \$ they handle? \$\endgroup\$
    – pxeger
    Jun 12 at 9:30
  • 1
    \$\begingroup\$ @pxeger no reason! i think the extra flexibility is okay. i'll edit the question so that people can choose, but i think it's still reasonable to require the domain and codomain to be equal (because these functions should be composed). \$\endgroup\$
    – cjquines
    Jun 12 at 17:56
  • \$\begingroup\$ Can I use builtins without explicitly declaring them? for instance, using \$f(x)=\text{abs}(x)\$, 0 bytes? Plus, why do I have to enter \$ here...? \$\endgroup\$ Jun 13 at 0:42
  • \$\begingroup\$ @NobodyNeedsNames at minimum you need to submit abs (like how other builtin submissions are) \$\endgroup\$
    – cjquines
    Jun 13 at 4:37
4
\$\begingroup\$

Iteratively delete a list

\$\endgroup\$
4
\$\begingroup\$

Universal Unicode Clock

\$\endgroup\$
4
  • \$\begingroup\$ How does this have to do with polyglot? \$\endgroup\$
    – Steffan
    Jun 11 at 20:09
  • \$\begingroup\$ @Steffan It's a program which runs on different versions of a library. So it's a sort of library polyglot. \$\endgroup\$
    – Wheat Wizard Mod
    Jun 11 at 20:10
  • \$\begingroup\$ If the Unicode handling library has an interface to determine which version of the Unicode database it uses, are we allowed to use that? \$\endgroup\$
    – pxeger
    Jun 12 at 15:21
  • \$\begingroup\$ @pxeger I'm not sure if there is really any point in disallowing it since it seems unlikely that it would get you many votes. \$\endgroup\$
    – Wheat Wizard Mod
    Jun 12 at 17:20
4
\$\begingroup\$

Extend a matrix in all directions

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Why is the second input another array, and not just the dimensions of the output array? \$\endgroup\$
    – pxeger
    Jun 14 at 16:00
  • \$\begingroup\$ @pxeger Good point \$\endgroup\$
    – emanresu A
    Jun 14 at 19:20
4
\$\begingroup\$

Enumerate the Microwave Timer

Related

Sometimes when I use my microwave, I do a little trolling and enter times such as 2:90 instead of 3:30 because they end up being the same time anyway. The microwave happily accepts this and starts counting down from 2:90, displaying times like 2:86 and 2:69 until it gets back to a stage where it can count down like a normal timer. Y'all's task today is to simulate this behaviour by returning a list of all times displayed by the microwave when given a starting time.

An Example

Say I input 2:90 into the microwave. It starts at 2:90 and then shows 2:89, 2:88, 2:87, 2:86, ..., 2:60, 2:59, 2:58, 2:57, ..., 2:00, 1:59, 1:58, 1:57, ..., 0:05, 0:04, 0:03, 0:02, 0:01, 0:00. As you can see, where the seconds are less than 60, it acts as normal. But where the seconds are greater than 60, it decrements the seconds without impacting the minute count.

Rules

  • Input can be taken in any convienient and reasonable format, including, but not limited to:

    • [minutes, seconds]
    • [seconds, minutes]
    • minutes on one line, seconds on the next
    • seconds on one line, minutes on the next
  • Output can be given in any convienient and reasonable format, including, but not limited to:

    • [[minute, second], [minute, second], [minute, second], ...]
    • ["minute second", "minute second", "minute second", ...]
    • minute second\n minute second\n ...
  • The outputted times can be returned in any order - they don't need to be sorted.

  • The seconds will never be greater than 99.

Make sure to include how you're outputting the times in your answer.

Sample IO

Input here is given as [minutes, seconds]. Output is given as a list of [minute, seconds]

[0, 90] => [[0, 90], [0, 89], [0, 88], [0, 87], [0, 86], [0, 85], [0, 84], [0, 83], [0, 82], [0, 81], [0, 80], [0, 79], [0, 78], [0, 77], [0, 76], [0, 75], [0, 74], [0, 73], [0, 72], [0, 71], [0, 70], [0, 69], [0, 68], [0, 67], [0, 66], [0, 65], [0, 64], [0, 63], [0, 62], [0, 61], [0, 60], [0, 59], [0, 58], [0, 57], [0, 56], [0, 55], [0, 54], [0, 53], [0, 52], [0, 51], [0, 50], [0, 49], [0, 48], [0, 47], [0, 46], [0, 45], [0, 44], [0, 43], [0, 42], [0, 41], [0, 40], [0, 39], [0, 38], [0, 37], [0, 36], [0, 35], [0, 34], [0, 33], [0, 32], [0, 31], [0, 30], [0, 29], [0, 28], [0, 27], [0, 26], [0, 25], [0, 24], [0, 23], [0, 22], [0, 21], [0, 20], [0, 19], [0, 18], [0, 17], [0, 16], [0, 15], [0, 14], [0, 13], [0, 12], [0, 11], [0, 10], [0, 9], [0, 8], [0, 7], [0, 6], [0, 5], [0, 4], [0, 3], [0, 2], [0, 1], [0, 0]]
[1, 20] => [[1, 20], [1, 19], [1, 18], [1, 17], [1, 16], [1, 15], [1, 14], [1, 13], [1, 12], [1, 11], [1, 10], [1, 9], [1, 8], [1, 7], [1, 6], [1, 5], [1, 4], [1, 3], [1, 2], [1, 1], [1, 0], [0, 59], [0, 58], [0, 57], [0, 56], [0, 55], [0, 54], [0, 53], [0, 52], [0, 51], [0, 50], [0, 49], [0, 48], [0, 47], [0, 46], [0, 45], [0, 44], [0, 43], [0, 42], [0, 41], [0, 40], [0, 39], [0, 38], [0, 37], [0, 36], [0, 35], [0, 34], [0, 33], [0, 32], [0, 31], [0, 30], [0, 29], [0, 28], [0, 27], [0, 26], [0, 25], [0, 24], [0, 23], [0, 22], [0, 21], [0, 20], [0, 19], [0, 18], [0, 17], [0, 16], [0, 15], [0, 14], [0, 13], [0, 12], [0, 11], [0, 10], [0, 9], [0, 8], [0, 7], [0, 6], [0, 5], [0, 4], [0, 3], [0, 2], [0, 1], [0, 0]]
[2, 90] => [[2, 90], [2, 89], [2, 88], [2, 87], [2, 86], [2, 85], [2, 84], [2, 83], [2, 82], [2, 81], [2, 80], [2, 79], [2, 78], [2, 77], [2, 76], [2, 75], [2, 74], [2, 73], [2, 72], [2, 71], [2, 70], [2, 69], [2, 68], [2, 67], [2, 66], [2, 65], [2, 64], [2, 63], [2, 62], [2, 61], [2, 60], [2, 59], [2, 58], [2, 57], [2, 56], [2, 55], [2, 54], [2, 53], [2, 52], [2, 51], [2, 50], [2, 49], [2, 48], [2, 47], [2, 46], [2, 45], [2, 44], [2, 43], [2, 42], [2, 41], [2, 40], [2, 39], [2, 38], [2, 37], [2, 36], [2, 35], [2, 34], [2, 33], [2, 32], [2, 31], [2, 30], [2, 29], [2, 28], [2, 27], [2, 26], [2, 25], [2, 24], [2, 23], [2, 22], [2, 21], [2, 20], [2, 19], [2, 18], [2, 17], [2, 16], [2, 15], [2, 14], [2, 13], [2, 12], [2, 11], [2, 10], [2, 9], [2, 8], [2, 7], [2, 6], [2, 5], [2, 4], [2, 3], [2, 2], [2, 1], [2, 0], [1, 59], [1, 58], [1, 57], [1, 56], [1, 55], [1, 54], [1, 53], [1, 52], [1, 51], [1, 50], [1, 49], [1, 48], [1, 47], [1, 46], [1, 45], [1, 44], [1, 43], [1, 42], [1, 41], [1, 40], [1, 39], [1, 38], [1, 37], [1, 36], [1, 35], [1, 34], [1, 33], [1, 32], [1, 31], [1, 30], [1, 29], [1, 28], [1, 27], [1, 26], [1, 25], [1, 24], [1, 23], [1, 22], [1, 21], [1, 20], [1, 19], [1, 18], [1, 17], [1, 16], [1, 15], [1, 14], [1, 13], [1, 12], [1, 11], [1, 10], [1, 9], [1, 8], [1, 7], [1, 6], [1, 5], [1, 4], [1, 3], [1, 2], [1, 1], [1, 0], [0, 59], [0, 58], [0, 57], [0, 56], [0, 55], [0, 54], [0, 53], [0, 52], [0, 51], [0, 50], [0, 49], [0, 48], [0, 47], [0, 46], [0, 45], [0, 44], [0, 43], [0, 42], [0, 41], [0, 40], [0, 39], [0, 38], [0, 37], [0, 36], [0, 35], [0, 34], [0, 33], [0, 32], [0, 31], [0, 30], [0, 29], [0, 28], [0, 27], [0, 26], [0, 25], [0, 24], [0, 23], [0, 22], [0, 21], [0, 20], [0, 19], [0, 18], [0, 17], [0, 16], [0, 15], [0, 14], [0, 13], [0, 12], [0, 11], [0, 10], [0, 9], [0, 8], [0, 7], [0, 6], [0, 5], [0, 4], [0, 3], [0, 2], [0, 1], [0, 0]]

As this is , the aim of the game is to get your byte count as low as possible.

Sandbox Meta

  • Should there be a requirement to sort outputted times?
  • Should there be a limit on the maximum value of the seconds?
  • Any other recommended tags?
\$\endgroup\$
3
  • \$\begingroup\$ Now I wanna try this on my microwave :P \$\endgroup\$
    – Seggan
    Jun 19 at 1:25
  • \$\begingroup\$ Can the output times be [second, minute]? \$\endgroup\$
    – Steffan
    Jun 20 at 15:54
  • \$\begingroup\$ @steffan that's covered under the reasonable format rule \$\endgroup\$
    – lyxal
    Jun 21 at 0:56
4
\$\begingroup\$

Compress Jelly's code page


In this challenge, you'll print out the SBCS of Jelly, a popular golfing language. Its code page looks like this:

_0 _1 _2 _3 _4 _5 _6 _7 _8 _9 _A _B _C _D _E _F
0_ ¡ ¢ £ ¤ ¥ ¦ © ¬ ® µ ½ ¿ Æ Ç Ð
1_ Ñ × Ø Œ Þ ß æ ç ð ı ȷ ñ ÷ ø œ þ
2_   ! " # $ % & ' ( ) * + , - . /
3_ 0 1 2 3 4 5 6 7 8 9 : ; < = > ?
4_ @ A B C D E F G H I J K L M N O
5_ P Q R S T U V W X Y Z [ \ ] ^ _
6_ ` a b c d e f g h i j k l m n o
7_ p q r s t u v w x y z { | } ~
8_ ° ¹ ² ³ Ɓ
9_ Ƈ Ɗ Ƒ Ɠ Ƙ Ɲ Ƥ Ƭ Ʋ Ȥ ɓ ƈ ɗ ƒ ɠ
A_ ɦ ƙ ɱ ɲ ƥ ʠ ɼ ʂ ƭ ʋ ȥ
B_ Ȧ
C_ Ċ Ė Ġ İ Ŀ Ȯ
D_ Ż
E_ § Ä ȧ ċ ė ġ ŀ
F_ ȯ ż « »

Or, in a code block:

¡¢£¤¥¦©¬®µ½¿€ÆÇÐ
Ñ×ØŒÞßæçðıȷñ÷øœþ
!\"#$%&'()*+,-./
0123456789:;<=>?
@ABCDEFGHIJKLMNO
PQRSTUVWXYZ[\]^_
`abcdefghijklmno
pqrstuvwxyz{|}~¶
°¹²³⁴⁵⁶⁷⁸⁹⁺⁻⁼⁽⁾
ƁƇƊƑƓƘⱮƝƤƬƲȤɓƈɗƒɠ
ɦƙɱɲƥʠɼʂƭʋȥẠḄḌẸḤ
ỊḲḶṂṆỌṚṢṬỤṾẈỴẒȦḂ
ĊḊĖḞĠḢİĿṀṄȮṖṘṠṪẆ
ẊẎŻạḅḍẹḥịḳḷṃṇọṛṣ
ṭ§Äẉỵẓȧḃċḋėḟġḣŀṁ
ṅȯṗṙṡṫẇẋẏż«»‘’“”

Rules:

  1. You can substitute with \n (0x10), § with , or Ä with ṿ if you wish
  2. You may use combining diacritics if these can be normalized to the correct character
  3. You may represent characters with their Unicode code points or UTF-8/16/32 representations
  4. You may output the characters with any reasonable formatting, as long as they are in order (e.g., a 256 character string, an array of characters, a 2d array representing a table with any dimensions, a string with newlines delimiting each character, etc.)

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

\$\endgroup\$
3
  • \$\begingroup\$ Argh Fig cannot compress Unicode... \$\endgroup\$
    – Seggan
    2 hours ago
  • \$\begingroup\$ Code block is incorrect: !\"#$%&'()*+,-./ should be ` !"#$%&'()*+,-./` (even though that didn't format right here in comment MD). Fun fact, this is 2 bytes in Jelly \$\endgroup\$
    – Steffan
    2 hours ago
  • \$\begingroup\$ Also Ɓ goes on the previous line \$\endgroup\$
    – Steffan
    2 hours ago
4
\$\begingroup\$

xkcd's roman numeral encoding

In the hovertext of this xkcd:

100he100k out th1s 1nno5at4e str1ng en100o501ng 15e been 500e5e50op1ng! 1t's 6rtua100y perfe100t! ...hang on, what's a "virtuacy"?

There's an "encoding" based on replacing runs of roman numerals with their sums. To do this:

  • Find all runs of at least 1 roman numeral (IVXLCDM)
  • Replace them with their sums, as numbers

The Roman Numerals are IVXLCDM, corresponding respectively to 1, 5, 10, 50, 100, 500, 1000. You should match them in either case.

For example, if we take encoding, c is the roman numeral 100, so it gets replaced with 100, leaving en100oding. Then, di are both roman numerals, respectively 500 and 1, so it gets replaced with their sum, 501, leaving en100o501ng.

Your challenge is to implement this, given a string. This is , shortest wins!

Note: the xkcd implements some more complex rules regarding consecutive characters like iv. This can create some ambiguities so I'm going with this simpler version.

Testcases

xkcd -> 10k600
encodingish -> en100o501ng1sh
Hello, World! -> He100o, Wor550!
Potatoes are green -> Potatoes are green
Divide -> 1007e
bacillicidic -> ba904
\$\endgroup\$
2
  • 2
    \$\begingroup\$ I suggest adding a worked out example - the test cases were still confusing for me after reading the challenge body. \$\endgroup\$
    – pajonk
    9 hours ago
  • \$\begingroup\$ Your hello world test case doesn't capitalize the H in the result. Also, can we take input in only one case? \$\endgroup\$
    – Steffan
    2 hours ago
3
\$\begingroup\$

Metagolf: Catlike Piet

The goal of this is to write a catlike program, which would be executed (in a Unix environment, though you needn't stick to that) by the following:

yourprogram < file > output
piet output

where piet output writes the contents of file to stdout. That is, you're to generate a Piet program which prints the input to yourprogram.

One-liners

Straight line programs can be written in Piet... in straight lines. If you're willing to take a hit to your score, your output can take the form of a string of commands:

=  none (continue color block)
|  push
^  pop
+  add
-  subtract
*  multiply
/  divide
%  mod
~  not
>  greater
.  pointer
\  switch
:  duplicate
@  roll
$  input number
?  input character
#  output number
!  output character

which is trivial to convert to a Piet program with the following (partially golfed) Python code:

def P(s):
 h=v=0;l=len(s)+1;R="P3 %i 2 255 192 0 0 "%(l+2)
 C=[1,3,2,6,4,5];V=[0,192,192,255,0,255]
 for x in map("=|^+-*/%~>.,:@$?#!".find,s):
  C=C[x//3:]+C[:x//3];V=V[x%3*2:]+V[:x%3*2]
  for i in [1,2,4]:R+="%i "%V[(C[0]//i)%2]
 return R+"255 "*4+"0 0 "+"255 "*l*3+"255 0 0 "*2

The dimension of said program is (n+3) x 2 if there are n characters in the string.

Scoring

Your code will be judged on the maximum dimension of the images that it outputs.

  • Part 1: Take the maximum score taken over all ascii codes (that is, single-character inputs), discounting EOF.

  • Part 2: Take the score for the input "Hello. My name is Inigo Montoya. You killed my father. Prepare to die."

Your score is the product of the scores in part 1 and part 2.

Punishment: Double your score if you write one-liners as above (that is, if you don't output an image).

Bonus: If your program is written in Piet, take the square root of your score above.

\$\endgroup\$
4
  • 2
    \$\begingroup\$ It took me a while to understand the task as "Write a program taking INPUT which produces as output a piet program that takes no input but produces INPUT." I think it is a interesting and challenging, but it's reception will depend entirely on how many people are willing to learn/futz-around-in/deal-with piet. And I have no feel for how many that is. \$\endgroup\$ Jul 7, 2011 at 3:12
  • \$\begingroup\$ @dmckee; would it be better if I just used a reduced instruction set, and only ask for the instruction stream? I think this is still challenging with {push 1,duplicate,add,subtract,multiply,output}. Come to think of it, if I restrict to {push 1,duplicate,add,output}, there's a reduction to some awesome algorithms. \$\endgroup\$
    – boothby
    Jul 7, 2011 at 4:48
  • \$\begingroup\$ I did this in piet some time ago: craigoclock.blogspot.com/2011/05/metaprogramming-in-piet.html \$\endgroup\$
    – captncraig
    May 21, 2012 at 18:31
  • \$\begingroup\$ Hello! This looks like a good but abandoned meta post, would you be willing to offer it for adoption? (If you want to, you can still post to main.) \$\endgroup\$
    – user58826
    Jun 9, 2017 at 15:22
3
\$\begingroup\$

Count Syllables

The goal of this challenge is to write a program that can count the syllables in a word as accurately as possible.

Input

On STDIN, your program will receive a number X followed by X lines, each containing a single word. Simple enough. (Should there be a limit on the size of X?) The words will come from this list.

4
challenge
to
count
syllables

Output

Your output should be to STDOUT and have X lines. On each line should be the number of syllables counted in that word.

2
1
1
3

Scoring

To score you program, it will receive a long secret list of words to test. All programs will receive the same list of words. For each word, the number of syllables that your program got wrong will be added to the score of the program. If it output a 4 or a 2 when the word had 3 syllables, then one point will be added. If it said a 15 instead of a 3, then 12 points will be added to the score. The lower the score, the better.

For example, if for the above input your program output 3 2 2 2 (which would be produced by a program that counts strings of vowels), then the program would receive a score of 2.

Rules

Your program should not access any external files (such as the word list). Also, your program should be no more than 5,000 bytes long (is this a reasonable limit?).

The winner will be the person whose program has the lowest score, therefor the most accurate syllable counter. The deadline for submissions is [some time at least a month away].

Suggestions

I am open to all constructive criticism. Is 5,000 bytes a reasonable limit for the program size? How long should the official scoring test be? How long should the deadline be?

\$\endgroup\$
10
  • 12
    \$\begingroup\$ This has one major flaw: the output is subjective. How many syllables do these words have? Every; victory; hierarchy; desire; oil; hour; poem. The only real way I see to work around this is for you to produce a marked-up version of the word list. \$\endgroup\$ May 29, 2012 at 20:40
  • \$\begingroup\$ I was really worried about that, and I don't see a way around it. \$\endgroup\$
    – PhiNotPi
    May 29, 2012 at 20:42
  • 1
    \$\begingroup\$ I personally would love to see more language processing challenges. I agree with @PeterTaylor on the difficulty of some words. Perhaps taking a specific text(s) and identifying explicitly in the challenge which words will have how many syllables? \$\endgroup\$
    – Gaffi
    Jun 8, 2012 at 3:34
  • 2
    \$\begingroup\$ @PeterTaylor ...Or maybe you could filter ambiguous words out of the reference list? \$\endgroup\$
    – user16991
    Feb 8, 2015 at 1:19
  • 1
    \$\begingroup\$ What's the point of the first line of input? \$\endgroup\$
    – msh210
    Apr 27, 2016 at 20:05
  • 3
    \$\begingroup\$ If you provide a reference list, A hyphenated reference list, and hide a secret list which may or may not include members of the reference list, this would be a reasonable challenge \$\endgroup\$ Sep 17, 2016 at 0:05
  • \$\begingroup\$ Do you plan to post this? If not, I'd be happy to adopt it. (If you don't respond within two weeks, by community standards, I'm allowed to do so.) \$\endgroup\$
    – MD XF
    Aug 18, 2017 at 3:20
  • \$\begingroup\$ The example of inaccurate program that would score 2 - did you mean to output 3 1 1 2 rather than 3 2 2 2? \$\endgroup\$
    – Heimdall
    Nov 9, 2017 at 18:31
  • \$\begingroup\$ A reference list could be dynamic: potential contestants can ask for words of their choice to be added to the list. They won't know what's on the secret list but will try to make their programs as accurate as possible (according to your syllable count) so they should always be able to ask for specific words they are not sure about. Of course, you could make it in different language. In my language, Slovene, it's much clearer how many syllables words have. How about Solresol, haha! \$\endgroup\$
    – Heimdall
    Nov 9, 2017 at 18:38
  • \$\begingroup\$ I am going to adopt this if you don''t respond \$\endgroup\$ Dec 20, 2017 at 16:48
3
\$\begingroup\$

Play Simple 2-Dimensional Minecraft

Recently I found this video of "HansLemurson" showing a computer that was built in minecraft, which runs minecraft. He is playing minecraft on a computer that was built in minecraft that is running on his computer. To be specific, it is a two dimensional version with an 8x8 grid of cells. There is gravity, block placement, and even jumping. It is worth noting that the computer is single purpose. The same person has built programmable computers, but making them single purpose allows the computer to be much smaller.

Details

The minecraft world is an 8x8 grid (one horizontal and one vertical dimension). The grid is comprised of either Xs (representing blocks) or empty spaces. The player is an X that is blinking on and off about once every second.

There are two modes in the game, controlled by a toggle switch. The first mode is movement. This is controlled by a WASD-like button arrangement. If the player chooses to move left/right/down, the computer checks to see if the space immediately in that direction is empty. If so, then the player moves into that space.

If the player chooses to move up, then the computer checks that the block underneath the player is solid. If so, then the player moves upward two units. Notice that this can propel the player into a solid block. If this happens, the player is obscured by the solid block, but can still move to an empty block next to him. When the player is inside on a solid block, the game continues as if the block isn't there, although the block is still there once the player leaves it.

After each move, the player falls down one unit if there is empty space there. This simulates gravity. This is also why moving up moves up two units, so that the gravity makes a net movement of up one unit. Gravity does not cause the player to fall all of the way to the ground, just one unit.

The second mode is block placement. In this mode, the same exact WASD buttons are used. Instead of moving the player, they toggle the state of the block in that direction. If the player presses "left" and there is a block there, then the block is destroyed. If there is not a block there, then a block is placed. Again after this move, the player is again subject to gravity. The blocks are not subject to falling.

Toggling the toggle switch does not count as a move, and does not invoke gravity.

The game board is a torus, so all actions (movement, block creation) can wrap around the board. The board does not scroll with the player. The player moves, and the blocks stay in the same place.

The challenge

You challenge is to write the shortest program that simulates this game. Your program should display and update the map correctly (with Xs as blocks, and with the blinking player). It should accept input from a button that toggles the state and four buttons for movement and actions. This is code golf.

There are imaginary bonus points for adding more features (block types, game size, etc) to your game.

Suggestions?

\$\endgroup\$
4
  • 4
    \$\begingroup\$ With more complicated challenges I find that it helps to do a reference implementation so that you have a very concrete idea of how much work is involved. Aside from that, I like it. \$\endgroup\$ Jun 3, 2012 at 20:11
  • \$\begingroup\$ Is the blink rate selected to fit with the ANSI escape sequence? Either way I would explicitly allow that, because it's the obvious way to do it on compatible terminals. \$\endgroup\$ Jun 5, 2012 at 7:14
  • \$\begingroup\$ The blink rate wasn't selected to be anything specific. I think that I will broaden the restriction. Maybe any blink rate between 3 blinks per second to 1 blink every 2 seconds. \$\endgroup\$
    – PhiNotPi
    Jun 5, 2012 at 20:21
  • \$\begingroup\$ @programmer5000 No, for two main reasons: First, challenges can go extended periods of time in the sandbox before they are posted and/or adopted. In the past I've posted challenges after not touching them for 4 years. Second, deleting this answer will not reduce lag, as deleted answers are still present, simply not visible. Users with sufficient rep will see all 4040 answers in the sandbox, and you will too once you earn the "view deleted answers" privilege. \$\endgroup\$
    – PhiNotPi
    Apr 13, 2017 at 18:15
3
\$\begingroup\$

Bad Voice Recognition Calculator

Overview:

Let's say you've decided to operate your computer using voice recognition software, but unfortunately you did a horrible job researching the various products out there and chose a package that does not recognize numbers as numerals, only words. (i.e. "one" (spoken) == "one" (typed), not "1".) Rather than spend more money to get another option, you decide to make do. Now you want to use the computer's calculator, but this poses a problem, since your machine doesn't know how to add "one plus one".

Objective:

Implement a basic calculator that will read in a string of the written-out equation, perform the correct calculations, then return the result in its text form. Your code should be as short as possible; this is code golf.

Rules/Constraints:

  • Input/output will be using your preferred method (STDIN, ARGV, etc.).
  • Your calculator must be able to handle input and output within the billions (non-inclusive) -1,000,000,000 < i < 1,000,000,000, but you may expand to more if you wish.
  • Decimal values and/or parts must be accepted (0 < i < 1) up to 3 places/digits.
    • When calculating answers, proper rounding must be used, so "three point one four one five nine two six" must be returned as "three point one four two".
  • Basic calculator functions required:
    • "Add"/"Plus"/"Sum"/"And" (+)
    • "Subtract"/"Minus"/"Remove" (-)
    • "Multiply"/"Times" (*)
    • "Divide"/"Divided"/"Divide by"/"Divided by" (/)
    • "Raise"/"Exponent"/"Power"/"To the power of" (^)
    • "<Base>Root"/"<Base>Radical" (√)
    • "Point"/"Decimal" (.)
    • "Pi" (π)
  • All strings in the list above must be accounted for in your code, capitalization does not matter.
  • Numbers may be presented as their full value ("one thousand") or by digit (one zero zero zero).
  • Negative numbers may be assigned using "Minus" or "Negative".
    • The string "Minus" bust be accounted for as an operator and identifier. (see example)
  • "And" is only acceptable as an operator, not as part of a named number.
    • "one hundred and one"
    • "one hundred one"
  • "a" or the absence of a number does not equate to any number; all numbers will be explicitly accounted for in the program input.
    • "a hundred" does not equate to "one hundred" and is not a valid input.
  • No more than 2 terms will be used.
    • "one plus one minus one" will not be implemented.
  • If an invalid input is supplied, your function/program should handle the error and exit gracefully with an error description.

Example I/O:

  • "one add one" --> "two"
  • "five thousand thirty four subtract ten thousand six hundred" --> "negative five thousand five hundred sixty six"
    • Alternatively: "five zero three four subtract one zero six zero zero"
  • "three root twenty seven" --> "three"
  • "ten minus minus ten" --> "twenty"
    • Alternatively: "ten subtract negative ten"

Sandbox Questions:

  1. Is this too basic/complicated? (I'm assuming some languages will handle this much more simply than the method I have in my head...)
  2. Does the title fit?
  3. Are there any constraints that should be added/lifted?
  4. Are any more examples needed for clarification?

Thanks for your input, guys!

\$\endgroup\$
6
  • \$\begingroup\$ Not everyone says numbers the same way. Does the parser have to treat the following as equivalent? "negative one hundred five", "minus one hundred five", "negative one hundred and five", "minus one hundred and five", "negative a hundred five", "negative a hundred and five", ...? \$\endgroup\$ Jun 15, 2012 at 15:12
  • \$\begingroup\$ @PeterTaylor I had had a similar thought re: operators. ("plus" versus "add", etc.) I think it would be more interesting to account for all, but given the wide variety of possible inputs, it may generally be better to limit the options to a specifically defined set (which I have yet to define). \$\endgroup\$
    – Gaffi
    Jun 15, 2012 at 15:18
  • \$\begingroup\$ @PeterTaylor I've added some of these details. Please let me know if there's anything unclear about them. \$\endgroup\$
    – Gaffi
    Jun 15, 2012 at 16:10
  • \$\begingroup\$ I don't spot any ambiguities in the parser. There is still an ambiguity relating to decimals, though. What precision should be used? Also, I notice now that there's no winning condition. Is this intended to be code-golf? (Ugh - tons of strings which will have to be hard-coded in most languages. I expect Perl has a suitable parser already in CPAN, though...) \$\endgroup\$ Jun 19, 2012 at 9:03
  • \$\begingroup\$ @PeterTaylor I don't know where I went... I've updated the spec. re: decimal places and objective. \$\endgroup\$
    – Gaffi
    Jun 29, 2012 at 13:24
  • 1
    \$\begingroup\$ @PeterTaylor metacpan.org/pod/Lingua::EN::Words2Nums \$\endgroup\$
    – msh210
    Apr 27, 2016 at 20:37
3
\$\begingroup\$

Count unique characters in text.

Given a string for input, output the unique non-whitespace characters in that string along with a count of their occurrences. The list should be sorted in ascending order of ASCII code.

Examples

Input:

Hello, World!

Output:

Character    Count
!            1
,            1
H            1
W            1
d            1
e            1
l            3
o            2
r            1

Input:

The quick brown fox jumps over the lazy dog.

Output:

Character    Count
.            1
T            1
a            1
b            1
c            1
d            1
e            3
f            1
g            1
h            2
i            1
j            1
k            1
l            1
m            1
n            1
o            4
p            1
q            1
r            1
s            1
t            1
u            1
v            1
w            1
x            1
y            1
z            1

The actual formatting (headers, spacing, etc) of the on-screen output is up to you. The only conditions are that it must be sorted in ascending order by ASCII code, and it must be easy to tell what represents a character from the string and what represents a count of a given character. (For example, given a string of 99999999, the output should be explicit so that it is not confused as saying I have 9 8s.)

Ultimate challenge (taken from here):

JKqdJg+oJgiowgyIJgkS+gyxJdeS+gyxJ4yoJdybJdioJdqIJ4kS+KwFJ4QS+gzYJg+ow4vIJ4yxvd+IJgy=+dv=JdQx+gzbJrzx24zYJgkxJ4qLJKQxJ4yxJKqx+KqdJKqdJg+oJgiowgyIJgkS+gyxJdeo24yxJm+xJdybJdioJdqIJKi=J4wF+dvS+gzYJg+ow4zYJ4yxvdy=J4i=+Kv=JdQo+KqxJrzdJKzYJgkxJ4qLJgkxJ4yxJKvSJ4qbJKqdJg+oJgiowgyIJgkdJgyxJdeo24yxJm+xJdybJd+oJd+S+dz=J4wF+dvS+g+SJg+ow4vIJ4yxJ4voJgy=+dv=+dzdJgqxJrzdJKzYJgkS+dweJKQxJ4yxJKvSJ4qbJKq=24yYJgiowgyIJgkdJgzdJryo24yxJm+d24zxJd+oJdqIJ4kS+KwFJ4QS+gzYJ4y=2gzYJ4yxJ4voJgy=+dv=+dzdJgqxJrzx24zYJgkS+dweJKQxJ4fK+dQSJ4qbJKq=24yYJgiowgyIJgkS+gzdJryS+gyxJ4yoJdybJd+oJd+S+dz=J4wF+dvS+gzYJ4y=2gvIJ4yxJ4voJgy=+dv=JdQo+KqxJrzx24zY+dzS+dweJKQxJ4yxJKqx+KqbJKq=24vbJdyowgyIJgkdJgzdJryS+gyxJm+d24zxJdioJd+S+dz=J4wF+dvS+gzYJg+ow4vIJ4yxJ4voJgy=+Kv=JdQx+gzbJrzx24zYJgkS+dweJgkxJ4yxJKvSJ4qdJKq=24yYJgiowgyIJgkdJgzdJryS+gyxJ4yoJdybJd+oJdqIJKi=J4wF+dvS+gzYJg+ow4vIJ4yxJ4v=J4i=+Kv=+dzdJgqxJrzx24zYJgkS+dweJgkxJ4fKJ4qx+KqdJKqdJg+SJdyowg+oJgkS+gyxJdeS+gyxJ4yoJdybJd+oJdqIJ4kS+KwFJ4QS+g+SJ4y=2gzYJ4yxJ4v=J4i=+Kv=JdQo+KqxJrzx24zY+dzS+dweJKQxJ4yxJKvSJ4qbJKqdJg+oJgiowg+oJgkS+gzdJryo24yxJ4yoJdybJdioJdqIJ4kS+KwFJ4QS+g+SJg+ow4vIJ4yxvd+IJgy=+dv=JdQo+KqxJrzdJKzY+dzxJ4qLJKQxJ4yxJKqx+KqdJKq=24vbJdyowg+oJgkS+gzdJryo24yxJ4yoJdybJdioJd+S+dz=J4wFJ4QS+gzYJg+ow4zYJ4yxvd+IJgy=+Kv=+dzdJgqxJrzdJKzYJgkxJ4qLJgkxJ4yxJKvSJ4qbJKq=24vbJdyowgyIJgkdJgyxJdeo24yxJm+xJdybJd+oJdqIJKi=J4wF+dvS+g+SJ4y=2gvIJ4yxvd+IJgy=+dv=+dzdJKzbJrzdJKzY+dzS+dweJgkxJ4yxJKvSJ4qbJKq=24yYJgiowg+oJgkS+gyxJdeo24yxJ4yoJKzxJd+oJdqIJKi=J4wF+dvS+gzYJg+ow4vIJ4yxJ4v=J4i=+dv=+dzdJgqxJrzx24zYJgkxJ4qLJKQxJ4fKJ4qx+KqdJKqdJg+oJgiowgyIJgkS+gzdJryS+gyxJm+d24zxJd+oJdqIJKi=J4wFJ4QS+gzYJ4y=2gzYJ4yxvdy=J4i=+Kv=+dzdJKzbJrzx24zY+dzxJ4qLJKQxJ4yxJKqx+KqdJKqdJg+SJdyowg+oJgkdJgzdJryo24yxJm+d24zxJd+5

\$\endgroup\$
5
  • \$\begingroup\$ This isn't really an interesting problem. The shortest answer is almost certainly going to be fewer than 10 characters. \$\endgroup\$ Dec 11, 2013 at 12:19
  • \$\begingroup\$ @PeterTaylor While I mostly agree with your comment - already the header line may contain more than 10 characters. \$\endgroup\$
    – Howard
    Dec 12, 2013 at 6:15
  • \$\begingroup\$ "The quick brown fox jumps over the lazy dog." contains "e" three times. \$\endgroup\$
    – Howard
    Dec 12, 2013 at 6:16
  • \$\begingroup\$ @Howard Thanks. I must be blind - it took me about five times of reading your comment to find it. Also, do remember that the header is optional to a certain degree - you just need to make sure the output is unambiguous as to which items are characters from the string, and which are character counts. \$\endgroup\$
    – Iszi
    Dec 12, 2013 at 7:02
  • \$\begingroup\$ My brain instantly went into bash mode. wc and uniq practically solve half of this, but not in any particularly short manner. \$\endgroup\$
    – Rob
    Dec 17, 2013 at 20:31
3
\$\begingroup\$

Chess move

The Challenge

Write a program that gets a string containing a chessmove and a chessboard as input, and then outputs the chessboard.

Requirements

The chess move will have this format:

<from square><to square>[<promoted to>]

Examples:

d2d4
f8g7
a7a8R

The chessboard format is not fixed, but there must be a 1 to 1 relation between the board and the string to represent the board. Also the format of the input must bet the same as the format of the output. Two suggestions of what it could look like:

rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR

rnbqkbnr pppppppp 00000000 00000000  00000000  00000000 PPPPPPPP RNBQKBNR

It is not required to store anything except the location of the pieces, and validity of moves can be assumed.

Scoring

Base score is character count (assuming your program can move pieces for all moves)

Bonus multipliers:

  • If the program updates the promoted piece, divide by 2
  • If the program also moves the rook when castling, divide by 2
  • If the program also removes the pawn when capturing en passent, divide by 2

The moves, and castling & en passent in particular are explaned on Wikipedia.

So basically writing a 100 character solution for the base problem gives the same score as an 800 character solution with all bonus multipliers.

Examples

If you would choose to use one of the board formats above, your input would look like one of these strings:

e2e4 rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR

e2e4 rnbqkbnr pppppppp 00000000 00000000  00000000  00000000 PPPPPPPP RNBQKBNR

Your corresponding output string would then be one of these:

rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR

rnbqkbnr pppppppp 00000000 00000000  0000P000  00000000 PPPP0PPP RNBQKBNR
\$\endgroup\$
4
  • 1
    \$\begingroup\$ Before I get on to more specific criticisms: as presented, without the bonus this is too trivial to be interesting. I suggest removing some flexibility: require Fen notation for the board position and algebraic notation for the move, and making the current bonus options mandatory. On specifics: it's not clear why you talk about storage; and the board position notations you suggest don't include enough information to know whether en passant is possible. \$\endgroup\$ Dec 22, 2013 at 23:56
  • \$\begingroup\$ @PeterTaylor I agree that compared to chess programs this may be trivial, but I would like to make it a golf challenge. Compared to the hot code golf questions this is quite elaborate already in its basic form. (For a good solution the board design may need to be changed drastically). It is true that there is no attention to the legality of moves (whether it is possible to capture en passent) but for a mere viewer this is not required so I am not too worried about this. So far the chess questions seem to get very few answers as they tend to be complex and I hope to offer relatively easy entry. \$\endgroup\$ Dec 30, 2013 at 11:02
  • 2
    \$\begingroup\$ Your point about en passant is valid - you had said in the spec to not worry about legality. I'll try to convince you of my first point: without the bonus, this reduces to: a) parse first four characters into (col 1, row 1, col 2, row 2); b) take board as a 64-char string; c) board[8*row_2+col_2] := board[8*row_1+col_1]; board[8*row_1+col_1] := ' '; print board. This is trivial compared to any good golf question. (Note that the hot questions at the moment are neither golf questions nor good questions). \$\endgroup\$ Dec 30, 2013 at 12:14
  • \$\begingroup\$ This sandbox post has had little activity in a while. Please improve / edit it or delete it to help us clean up the sandbox. Due to community guidelines, if you don't respond to this comment in 7 days I have permission to vote to delete this. \$\endgroup\$
    – user58826
    Jun 9, 2017 at 15:40
3
\$\begingroup\$

Black Box

Your task is to analyze a given situation for the game Black Box. Given a sequence of guesses and answers, your program is to either print the solution or suggest the next move.

The game

The board consists of 8×8 cells, with edges labeled like this:

I'll probably create nice images here, particularly to make sure that the squares of the board are really square.

 abcdefgh
i        I
j        J
k        K
l        L
m        M
n        N
o        O
p        P
 ABCDEFGH

The player shoots rays into the interior of the box, where they might get deflected, reflected or absorbed. He is told the position where the ray leaves the black box again, and from that has to deduce the positions of 4 atoms inside the black box.

I'll have to include more of the game rules here, but for now see Wikipedia.

Input and output

Input is a sequence of line, each consisting of two characters. The first denotes the point where the ray of light enters the black box, the second the place where it comes out again. In the case of a reflection, both characters will be equal. In the case of a hit, the second character will be -.

If the input is enough to fully determine the locations of the atoms, then output should be four lines giving the coordinates of each atom. The lines should be two lower case characters each, the first giving the row and the second giving the column of the found solution. The atom positions must be printed in lexicographical order.

If the input is consistent with more than one set of atom positions, then the output should consist of a single line containing a single character, which is the location where the next ray should be shot. That location has to be chosen in such a way that it can help find the solution. This is the case unless all of the atom positions consistent with the input so far would produce the same output for this next ray as well.

Your output has to be terminated by a newline character.

Examples

Let's take the atom configuration the Wikipedia article uses as an example as well:

 abcdefgh
i        I
j        J
k O    O K
l        L
m        M
n   O    N
o        O
p      O P
 ABCDEFGH

If the input were

cf
D-
Em
HH
Co

then the output should be

kb
kg
nd
pg

but if the input were only

Em
HH

then the output might be for example

K

Scoring

This is code golf, so shortest answer wins. However, I'll only accept answers which are practical in so far as they compute their result in reasonable time. I'd say no more than five minutes on my system where I'll evaluate the answers, and I'll simply hope that correct solutions will be much faster and incorrect ones much slower, so that the speed of my system doesn't make a difference. A submission which gives a wrong answer for one of my test cases will be disqualified until it gets fixed. I will probably point out the problem in a comment to that post.

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

Create a program with "exact repetition" in its source code

The task is to create a program, with the following restrictions placed on the printable ASCII characters in the source code: choose some k > 0.

  • Every non-alphabetic character has to appear exactly k times.
  • Every alphabetic character has to appear at most k times.
    • This rule differs from the former in order to avoid boring dummy identifiers while still making it a challenge to choose good library functions to call.

Character set definitions used:

  • Non-alphabetic characters are !"#$%&'()*+,-./0123456789:;<=>?@[\]^_{|}~ and '`' (backtick).
  • Alphabetic characters are ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.

Note that no restriction is placed on characters outside of the range of printable ASCII characters (including control codes, tabs, newlines, higher unicode codepoints, etc).

What the program does is up to you; be creative. Some general guidelines:

  • Programs that do something interesting might have better chances, although more impressive code structure (i.e. fewer comments) is also beneficial.
  • Stuffing excess characters in comments is boring, and should be avoided/is discouraged.
  • Dead/no-op code isn't terribly interesting either, but is probably unavoidable and at least has to conform to the language's grammar.

This is : whatever has the most upvotes at Feb 1, 2014 gets accepted as the winner.


Example answer (C)

#
#
/*$$@``*/_[]={9.};main() {printf("He%clo \
world!%c\
",2^7&!8.&~1|~-1?4|5?0x6C:48:6<3>2>=3<++_[0],'@'^79-5);}

Prints "Hello world!" (adapted from an answer to another question). Probably wouldn't score a lot (since what it does isn't terribly interesting). Each of the non-alphabetic characters appear exactly twice, and no alphabetic character appears more than twice.


For meta: I want to post this, but I'm worrying that "do something interesting" might give too little guidance and the question won't receive many answers.. thoughts? Is it good as-is, or should I come up with some task that one should be required to implement (and possibly change the ruling to code-challenge, with length + 2^(characters-in-comments) as the score)?

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

This is my first try at writing a challenge. Please let me know how I can improve it.

Roman Calculator

Create a basic calculator for Roman numerals.

Requirements

  • Supports +,-,*,/
  • Input and output should expect only one prefix per symbol (i.e. 3 can't be IIV because there is two I's before V)
  • Input and output should be left to right in order of value, starting with the largest (i.e. 19 = XIX not IXX, 10 is larger than 9)
  • Left to right, no operator precedence, as if you were using a hand calculator.
  • Supports whole positive numbers input/output between 1-4999 (no need for V̅)
  • No libraries that do roman numeral conversion for you

For you to decide

  • Case sensitivity
  • Spaces or no spaces on input
  • What happens if you get a decimal output. Truncate, no answer, error, etc..
  • What to do for output that you can't handle. Negatives or numbers to large to be printed.

Extra Credit

  • -20 - Handle up to 99999 or larger (numbers with a vinculum)

Sample input/output

XIX + LXXX                 (19+80)
XCIX

XCIX + I / L * D + IV      (99+1/50*500+7)
MIV

The shortest code wins.

\$\endgroup\$
6
  • 1
    \$\begingroup\$ You might want to be explicit about which variants of Roman numerals need to be supported. For example, do I have to understand IV as 4, or can I require that it be written as IIII? And what about, say, writing 8 as IIX instead of VIII, 19 as IXX or XVIV instead of XIX, or 99 as IC instead of XCIX? (All these variants have, AFAIK, been used classically.) \$\endgroup\$ Feb 9, 2014 at 22:36
  • \$\begingroup\$ @IlmariKaronen thanks. I modified the question to be slightly more specific about that. \$\endgroup\$
    – Danny
    Feb 10, 2014 at 14:09
  • 1
    \$\begingroup\$ I think that using IV, IX, IC, XC, etc. should be alright, but only allow one prefix. Also, 19 should be written XIX, not IXX. One other thing, can we assume that the operators will be separated by a space, or no? \$\endgroup\$
    – user10766
    Feb 12, 2014 at 0:32
  • 1
    \$\begingroup\$ Hello! This looks like a good but abandoned meta post, would you be willing to offer it for adoption? (If you want to, you can still post to main.) \$\endgroup\$
    – user58826
    Jun 9, 2017 at 16:06
  • \$\begingroup\$ 1. I don't need to handle I/III but need to handle I/III+II/III? 2. For the extra can I output maybe [V] for 5000? \$\endgroup\$
    – l4m2
    Apr 12, 2018 at 15:05
  • \$\begingroup\$ @programmer5000 it was posted to main awhile ago. codegolf.stackexchange.com/questions/20670/… \$\endgroup\$
    – Danny
    Apr 26, 2018 at 11:58
3
\$\begingroup\$

Create a calendar

We all know HDD-space is precious and bandwidth is expensive, therefore it is best to reduce the size of your executables. Let's start with your calendar:

Your task is to build a calendar app in at most 512 bytes. The calendar must at least support the following features, but additional features may gain you additional upvotes:

  • It must be able to show the current month with the current day highlighted
  • The user must be able to find out the week day of each day

Rules:

  • Maximum code length is 512 bytes (counted as UTF-8 without BOM)
  • You may subtract the bootstrapping code (i.e. int main(int argc, char **argv) in C or <?php in PHP) and imports from the final size to allow for more verbose languages to be in
  • You may use standard time / date functions of your programming language, as long as they don't allow you to output a ready to use calendar
  • No network access (I said bandwidth is expensive!)
  • Voters decide on the amount of features / look and feel / creativity

This needs a tag for the size restriction, any suggestions?

\$\endgroup\$
9
  • 1
    \$\begingroup\$ "bandwidth is expensive" <sup>[citation needed]</sup> \$\endgroup\$ Mar 22, 2014 at 5:27
  • 1
    \$\begingroup\$ Seems rather close to Output: Calendar Month \$\endgroup\$ Mar 22, 2014 at 5:33
  • \$\begingroup\$ Who decides what counts as bootstrapping code? It seems odd to arbitrarily exclude code like that, and the examples you gave can be golfed a lot: they're more or less equivalent to main(){ and <? respectively. \$\endgroup\$ Mar 24, 2014 at 20:49
  • \$\begingroup\$ @WanderNauta Bootstrapping code is the code that's essentiell to get a working noop program. \$\endgroup\$
    – TimWolla
    Mar 24, 2014 at 21:00
  • \$\begingroup\$ @TimWolla That definition won't fly. A zero-byte file is a working noop PHP script, for example. \$\endgroup\$ Mar 24, 2014 at 21:01
  • 1
    \$\begingroup\$ @WanderNauta A zero byte file is a working noop in every language. \$\endgroup\$
    – TimWolla
    Mar 24, 2014 at 22:12
  • \$\begingroup\$ So what's bootstrapping code then? :) \$\endgroup\$ Mar 24, 2014 at 22:53
  • 1
    \$\begingroup\$ for the limit I'd say code-shuffleboard or restricted-source \$\endgroup\$
    – Einacio
    Mar 26, 2014 at 15:57
  • \$\begingroup\$ This sandbox post has had little activity in a while. Please improve / edit it or delete it to help us clean up the sandbox. Due to community guidelines, if you don't respond to this comment in 7 days I have permission to vote to delete this. \$\endgroup\$
    – user58826
    Jun 9, 2017 at 16:28
1
10 11
12
13 14
131

You must log in to answer this question.

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