568
\$\begingroup\$

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

Sandbox FAQ

Posting

To post to the sandbox, scroll to the bottom of this page and click "Answer This Question". Click "OK" when it asks if you really want to add another answer.

Write your challenge just as you would when actually posting it, though you can optionally add a title at the top. You may also add some notes about specific things you would like to clarify before posting it. Other users will help you improve your challenge by rating and discussing it.

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

Discussion

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

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

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

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

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

Other

Search the sandbox / Browse your pending proposals

The sandbox works best if you sort posts by active.

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

\$\endgroup\$
0

4563 Answers 4563

1
144 145
146
147 148
153
-2
\$\begingroup\$

Is it cat-urday?

Caturday is one of the oldest memes out there. For this challenge you need to write a program that outputs the input, but only on Saturday.

The catch:

You can acquire the date via UNIX timestamp, or as a formatted date string (local or UTC). However, you can not:

  • use day of the week information in a date string
  • directly acquire the day of the week of a date by some other means
  • use Date or Calendar functions, beyond one to simply give you the current date
  • use any external resources (files, Internet)

Don't forget leap years!


Does this question work as is? Should I make anything clearer?

\$\endgroup\$
1
  • 5
    \$\begingroup\$ This is a "do X without Y" challenges, and those have been done to death. \$\endgroup\$ Jul 22, 2017 at 20:28
-2
\$\begingroup\$

Output the infinite sequence of middle positions of odd square numbers

As everyone knows, every odd square number has an element at its central position — I represent those central elements as an *:

n=1 => 1
*

n=9 => 5
###
#*#
###

n=25 => 13
#####
#####
##*##
#####
#####

n=49 => 25
#######
#######
#######
###*###
#######
#######
#######

The challenge consists on output the sequence 1, 5, 13, 25, ... uninterruptedly. The separator does not need to be a comma, but use the same separator always.

There will not be any accepted answer, except if I see some very creative answer. There will be a winner for each language (I will steal Leader board code somewhere)

\$\endgroup\$
4
  • \$\begingroup\$ Is this equivalent to "output (N+1)/2 for every odd square number N"? \$\endgroup\$ Aug 3, 2017 at 17:15
  • \$\begingroup\$ @trichoplax: Yes. \$\endgroup\$
    – sergiol
    Aug 3, 2017 at 17:40
  • 1
    \$\begingroup\$ There will not be any accepted answer, except if I see some very creative answer The whole point of code-golf is the shortest answer wins. Why output constantly and not return the Nth or first N terms? \$\endgroup\$ Aug 4, 2017 at 10:08
  • 2
    \$\begingroup\$ Also surely this boils down to for(i=1;;i+=2)Output((i**2+1)/2+",") which isn't that exciting. \$\endgroup\$ Aug 4, 2017 at 10:09
-2
\$\begingroup\$

Hello, Quine!

Your task is to write a program which, if given an input of "Hello," will output "Hello, world!", if given any other input, it will output its source code.


Rules

  • Input does not have to be case-sensitive.
  • Your program may not contain the string "Hello, world!" or any variation with different cases of letters (i.e "hELLO, WORLD!", "HeLlO, WoRlD!", and "hello, world!").
  • No "cheating quines."
  • Standard loopholes are strictly forbidden.

This is , so may the shortest code win and the best programmer prosper...

\$\endgroup\$
4
  • 4
    \$\begingroup\$ This is combining two different challenges into one, and I don't see a good reason to do so. (Output your source, and output Hello, World! without it in your source). Also, restricted-source. \$\endgroup\$
    – Stephen
    Aug 3, 2017 at 17:36
  • \$\begingroup\$ @StepHen How could I distinguish it somewhat? \$\endgroup\$
    – ckjbgames
    Aug 3, 2017 at 17:40
  • \$\begingroup\$ Distinguish it from what? It's just combing two already used challenges - Hello, World! without important characters, and quining, into one. \$\endgroup\$
    – Stephen
    Aug 3, 2017 at 17:43
  • \$\begingroup\$ @StepHen Definitely true. \$\endgroup\$
    – ckjbgames
    Aug 3, 2017 at 17:46
-2
\$\begingroup\$

Complicating Simple Maths

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

Goal:

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

Examples:

Input: 5 - 1
Output: 5 + 2i

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

Rules:

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

  • No standard loopholes.

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

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

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

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

  • This is , so shortest answer wins.

Sandbox use only:

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

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

The Self-Referential Algorithm

Most people are familiar with Tupper's self-referential formula. When the formula is graphed on a calculator it magically graphs itself. Wouldn't it be interesting if we could do something similar with a programming language?

Your task

Write a small program that will be able to output exactly itself when ran.

This is a question so answers will be scored in bytes, with the fewest bytes winning.

\$\endgroup\$
1
-2
\$\begingroup\$

Pascal's Particulars

Pascal is feeling very particular today. He wants to get an element from his famous triangle without going through the work of generating all the prior elements. He'll provide you with a row number and an entry number and you'll provide him with the element at that location.

Example:
Input row = 1, entry = 1, output 1. (row 1 is 1)
Input row = 3, entry = 2, output 2. (row 3 is 1-2-1)
Input row = 6, entry = 3, output 10. (row 6 is 1-5-10-10-5-1)

Rules

  • You will only be provided valid inputs (i.e. x will never be higher than n).
  • Your code should either print or return the output value, either works.
  • Standard golfing rules apply (lowest byte-count wins, etc.).

Happy golfing!

\$\endgroup\$
2
  • 2
    \$\begingroup\$ you know that you are just asking for binomial(n,k), don't you? this is trivial \$\endgroup\$
    – ZaMoC
    Aug 17, 2017 at 17:33
  • \$\begingroup\$ Duplicate \$\endgroup\$ Aug 17, 2017 at 17:39
-2
\$\begingroup\$

Break this block

Your challenge is to break this block. floating diamond

But of course that would be a pretty easy challenge, that's why this is a challenge.
The robber's challenge: Break the block. As breaking qualifies everything that has the result that no diamond block is at the coordinates 0 128 0 (even pushing it with a piston) and that follows the rules (see below).
The cop's challenge: Prevent the robbers from breaking the block. As preventing the breaking counts everything that guarantees that there is a diamond block at 0 128 0 in every future game tick despite the robber attempting his solution (and also if he doesn't). You are not in the world while the robber makes his attempt, so you have to prepare the world for him.

Rules

  • You may not use modded Minecraft or external tools that change the save file. Reading it with external tools is allowed.
  • You have to show a reproducible way to break/secure the block. Just uploading a world save without saying what you changed is invalid. You should offer a detailed explanation and preferably more (video, screenshots, structure file, etc.), if necessary.
  • This challenge starts with a normal world (default generation, Creative+cheats, random seed), where one diamond block was placed using the command
    /setblock 0 128 0 diamond_block
    The spawn chunks can include 0 0, but they don't have to. Since both sides have access to commands, that shouldn't matter anyway.

Sandbox questions

  • How should I restrict the version? Should it be "latest release", "any stable release", "only 1.12.1", "any snapshot, release or historical version" or something else? People could come up with interesting solutions using past versions (maybe even past snapshots that aren't selectable in the launcher anymore), but I have to somewhat restrict it. If a certain downgrade automatically breaks the block, it's of course boring, especially since they instantly win. And if they load the world in any of the 9 oldest versions in the launcher (called "Classic" and "pre-Classic), there isn't even a diamond block in the game, so it would be deleted.
  • Should I discourage people from instantly preventing every single breaking method with their first "cops" post? To have an interesting challenge, it should slowly become more difficult. If I should discourage it, how to "enforce" it?
  • What other rules do I need?
  • I'm planning to be very active myself on the "cops" side (I already have some nice ideas), possibly creating the majority of posts there. Is there a problem with that? If no, would it be considered unfair or boring to ask the others to wait up to a day with their solutions? Of course they don't have to do it, I just originally planned this to create programming challenges for myself.
  • If every answer on one side can have multiple answers on the other side, which itself could have answers on the first side and so on, that could lead to a tree-like structure. But such a structure would lead to many unanswered questions (if it doesn't keep growing exponentially, what I highly doubt). Is there a way to prevent that or should I even try it?
  • Apparently this is the first Minecraft-only programming challenge here. Should a tag be created for it?
\$\endgroup\$
2
  • 4
    \$\begingroup\$ This doesn't make sense. What are the submissions? Minecraft commands? A set of instructions? A program that reads a save file and outputs a new one? \$\endgroup\$
    – DJMcMayhem
    Aug 22, 2017 at 20:02
  • \$\begingroup\$ Submissions would mostly be Minecraft commands, but maybe in the first few rounds instructions. \$\endgroup\$ Aug 23, 2017 at 5:39
-2
\$\begingroup\$

The Compressor

You are given this list of 100 positive integers that are at between 7 and 18 digits long:

[list to come]

You need to generate 100 snippets that will produce these numbers in some language (either as a numeric or string). Your score is the total length of the snippets. Lowest score overall wins, but you should also try to get the lowest score in whichever language your snippets are in. Please include both your snippets and any code you used to generate them in your submission. Note: the generating code isn't actually scored.

Rules

  • The snippets must all be in one language, however it does not need to be the same language as the generating program(s).
  • You may assume that any pre-existing libraries you use are already imported.
  • You don't need to include the line terminator (i.e ';' in Java and others) for snippets that fit on one line. For multi-line snippets, you don't need to put a terminator on the last line.

Examples

  • 1357000 => 1357e3 (many languages)
  • 1234567 => 1234567 (most languages)
  • 307422089600 => S6*99b (CJam, returns value of [32,32,32,32,32,32] in base 99)
  • 12582912 => 12<<20 (JS + others)

Alternative:

I generated this 100 digit random number with random.org:

7160708104901559695507628057638725214364226867212714872539720713967912042100814603497742352846014272

Write the shortest possible program that outputs this number.


Related: No strings (or numbers) attached

Questions? Clarifications?

\$\endgroup\$
6
  • \$\begingroup\$ I would say that rather than having the input be a list of 100 numbers, have the input be a single number and just have score be the sum of output lengths when applied to each of the 100 numbers. I think that this will avoid confusion over valid output formats, without altering the interesting part of the problem. \$\endgroup\$ Sep 7, 2017 at 21:14
  • \$\begingroup\$ I would also say that this could be dangerously close to a duplicate, since answers to that challenge seem likely to score well in this one with relatively minor modifications. \$\endgroup\$ Sep 7, 2017 at 21:15
  • \$\begingroup\$ @KamilDrakari I'm trying to understand your suggestion. Currently the score is lowest sum of output lengths. \$\endgroup\$
    – geokavel
    Sep 7, 2017 at 22:15
  • \$\begingroup\$ currently the challenge is for a program which takes a list of numbers and outputs 100 snippets. I think the challenge would be better if the program takes 1 number and outputs 1 snippet, and gets run 100 times to score it. \$\endgroup\$ Sep 8, 2017 at 13:04
  • \$\begingroup\$ @KamilDrakari You're allowed to make a program that takes 1 snippet at a time, because you are score on the snippets, not the program. The program is a meta-program. \$\endgroup\$
    – geokavel
    Sep 8, 2017 at 14:46
  • \$\begingroup\$ I think having both options should be more clearly stated then. One other suggestion: you mention "Lowest score in a particular language", which I think should be explicitly clarified whether answers compete based on the language of their snippets or their generating program. \$\endgroup\$ Sep 8, 2017 at 14:59
-2
\$\begingroup\$

Ulam spiral 2

Like Ulam, I had a boring moment and began drawing a spiral like him's. But his version is utterly incorrect, as the \ diagonal distorts the equation n^2.

The following picture illustrates an wrong Ulam spiral at left and a correct at right:

enter image description here

I challenge you to output a numbered Ulam spiral, the right version, where it is mandatory to highlight the primes. The input is n, meaning the point where the spiral ends. For the image example I gave n was 100. It will always begin at 1

I don't care what highlight style you use (different color, font weight, circle around number, etc), given it makes the primes easily distinguishable form the rest.

There will be no accepted answer; just did it for fun.

\$\endgroup\$
7
  • \$\begingroup\$ This isn't [arithmetic]. \$\endgroup\$
    – Riker
    Sep 19, 2017 at 19:06
  • \$\begingroup\$ Also, can you provide an actual explanation of how you got the second one? \$\endgroup\$
    – Riker
    Sep 19, 2017 at 19:07
  • \$\begingroup\$ You can only have a maximum of 5 tags per question. \$\endgroup\$ Sep 19, 2017 at 19:36
  • \$\begingroup\$ @Riker there is a pattern. Interpreting it is part of the challenge. \$\endgroup\$
    – sergiol
    Sep 19, 2017 at 19:50
  • 3
    \$\begingroup\$ @sergiol -1, that's no fun at all. The first person can figure it out, and the rest can and will copy the pattern. PPCG doesn't work well with the "find the pattern and decode it" style. \$\endgroup\$
    – Riker
    Sep 19, 2017 at 21:40
  • \$\begingroup\$ wrong Ulam spiral at left; I thought the spiral on the left was the Ulam spiral? \$\endgroup\$ Sep 20, 2017 at 2:20
  • \$\begingroup\$ @JonathanFrech: Yes. \$\endgroup\$
    – sergiol
    Sep 20, 2017 at 9:21
-2
\$\begingroup\$

Looking for some help to make this code golf/question better.

Proposal:

Now that twitter has increased it's character limit from 140 to 280, there's a joke of almost enough to write Hello World! in Java. But what actual programs could you write in 280 characters, fizz buzz? Sure you could write many in 140 or less, but maximum points if you get a good program in the full 280.

\$\endgroup\$
4
  • 3
    \$\begingroup\$ Hello! Your programming challenge needs an actual task... Think of an idea first, then come here again! \$\endgroup\$
    – hyper-neutrino Mod
    Sep 27, 2017 at 14:01
  • \$\begingroup\$ So "do something in exactly 280 bytes"? Yeah, you're going to need a much better spec than that. As well as a winning criterion. \$\endgroup\$
    – Shaggy
    Sep 27, 2017 at 14:25
  • \$\begingroup\$ There is some precedent for a similar challenge, but that was more narrow, more clearly defined, and it was still closed for being "too broad" (though it did have some interesting answers). I don't think this would really offer any improvements over that existing challenge. \$\endgroup\$ Sep 27, 2017 at 14:40
  • \$\begingroup\$ codegolf.stackexchange.com/questions/35569/… is basically what you're describing except the limit is 280 rather than 140 characters \$\endgroup\$
    – Beta Decay
    Sep 28, 2017 at 21:40
-2
\$\begingroup\$

Shortest golang code to println the first byte of a function’s code

Rules

  • The code must be a function which takes another function as parameter and will print the first cpu instruction byte of parameter such as :

.

func dummy() {
}
print_first_native_instruction_byte(dummy)

would print :

0x90

which is a nop instruction on x86.

  • You don’t need to perform disassembling : if the first instruction is longer than one byte, just print it’s first byte anyway without caring about instruction meaning or instruction length. Please note this is harder than just printing the value pointed by &dummy in the case of my example though.
  • The function parameter must be a go function, not a cgo or assembly function.
  • You can include as many golang packages as you want.
  • The code need to be written in Go. A well known language developped at Google and part of the four Google’s app engines supported languages and answers should be able to run on the official go playground.

Winner

The one with the shortest code… Import statements included.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Please note this is a little harder than just getting the value of &dummy in my example code, and requires internal knowlwedge of the official go implementation. but it doesn’t requires architecture specific code beside handling big endian or little endian. \$\endgroup\$ Oct 1, 2017 at 20:37
-2
\$\begingroup\$

Preposition, not possession

Enthralling background

Back in 1960s Soviet Russia, communism was the thing, and –– as we all know –– in a completely socialist society, there is ideally no personal property.

Our dear client is an author who is moving to the Soviet Union. However, as is Bolshevik custom, our client is afraid his works will be censored. That is why we are going to help this industrious author by revising his writings so that they will not be censored.

What will be censored? Any overt references to ownership.

How will we do this? Quite simply: we will replace all possession with preposition.

Let's get specific

Example

Text in parenthesis is added; text in curly-brackets is removed.

[Input]   All the author's works will be censored!
[Output]  All (the works of )the author{'s works} will be censored!

Algorithmically

  1. For each word with a 's attached to it:
  2. Call the word with an 's attached to it _word_
  3. Call the following word _object_
  4. Remove all 'ss and _object_
  5. Insert The _object_ of two words before _word_
  6. If there are not two words before _word_, place _object_ right before _word_.

Here are some more examples:

Then the red horse stopped and took the orangutang's oranges. What a fuss ensued!
Then the red horse stopped and took the oranges of the orangutang. What a fuss ensued!

It is the people's right to not own anything!
It is the right of the people to not own anything!

The world's tallest building was once the Empire State Building.
The tallest of the world building was once the Empire State Building.

Bill likes Fred's shoes, and Jill likes Beth's dress.
Bill likes the shoes of Fred, and Jill likes the dress of Beth.

Ryan's fear was a stack overflow.
The fear of Ryan was a stack overflow.
\$\endgroup\$
-2
\$\begingroup\$

Output the first digit of Graham's number

Code golf

Write a program that will output the first digit of Graham's number (and nothing else), terminate and produce no error.

I'll be lenient about loopholes. But if your submission is something like print("4"), the burden of proof will be on you.* Also, if you submit 9 answers like that, each printing one digit, then yes, one will definitely be correct, but I will need to know which one, and, you guessed it, the burden of proof is on you.*

* Catch: at the moment, no one has yet worked out what the first digit of Graham's number is.

But I want a "practical" solution. Yes, the algorithm is simple, but I'm sure your computer doesn't have unlimited storage. Nor do language implementations have arbitrarily large int. (OK, some do, but there is memory constraint.)

However, you will have a tape device attached to your computer. The library which is automatically loaded into the interpreter or compiler controls the tape device. Here things do become theoretical: the tape has a beginning, but no end, or you can imagine the device will manufacture more tape to extend it if more is needed. The tape has discrete positions. On each position a sector is stored. The device has access to one sector at the time but it can move the tape. All sectors have the same size.

The library provides you with the following functions (subroutines, whatever):
- detect if the tape is at the beginning
- move the tape left by n positions (stops at the beginning if sent beyond)
- move the tape right by n positions (n has to be one of atomic integer types of your chosen language)
- read the whole sector at current position
- read a part of the sector (zero indexed location within the sector and number of bytes to be read are arguments of an atomic integer type)
- overwrite the whole sector
- overwrite a part of the sector

The names of functions are your choice, as is the size of a sector. Reading loads the contents into a variable / into the memory area starting with a pointer given as an argument. Similar about writing.

Because the tape is effectively infinite, you have no function to tell you the actual position on the tape, as you'd have no way to store the result on a "real" computer.

So the real parts are: computer, possibly tape device.
Theoretical parts are:
- infinite storage tape or availability of material to manufacture as much tape as needed, which may well exceed the total amount of matter in our universe
- the computer, device, tape, ... not deteriorating, getting tangled up nor power falling or anything else going wrong for the time it takes the program to complete the task, which may well exceed total lifetime of our universe.

Sandbox questions

Ideas how to improve the question... or should I abandon the idea?

\$\endgroup\$
6
  • \$\begingroup\$ As you say this is code-golf, I think you should better define your library functions (are they well-written and only require one-byte functions or is there considerable cost to using specific library features). \$\endgroup\$ Nov 11, 2017 at 22:26
  • \$\begingroup\$ @JonathanFrech I thought I made clear about each of the 7 functions what they do. As for functions' names, some esoteric languages use funny identifiers so I thought I would leave naming to contestants. (I guess everyone will use single character names.) I'm open to suggestions if anyone has a better idea. \$\endgroup\$
    – Heimdall
    Nov 12, 2017 at 12:19
  • \$\begingroup\$ Some languages doesn't even have definition of "function" (BF, ///). Some other languages doesn't have definition of "extension/library" (Jelly). Practical is subjective. Sector size is not specified. Atomic integer type is not defined. The amount of memory the program takes depends on several things, not just the program. \$\endgroup\$
    – DELETE_ME
    Nov 12, 2017 at 12:42
  • \$\begingroup\$ @user202729 Maybe I should just name the functions and languages that can't handle named functions are out. Although brainfuck should be fine because its built-in commands will, using the library, manipulate the tape device (which enables it to be infinite, not possible otherwise); a sector would then probably only contain 8 or 16 bits. The solution in infinite brainfuck does indeed exist (because it's Turing complete) but how long is it? \$\endgroup\$
    – Heimdall
    Nov 12, 2017 at 15:13
  • \$\begingroup\$ Language specific things are heavily discouraged. I would expect some downvotes if you say that. / Some languages may already had that name as builtin (Mathematica E, N). / The issue of unclear-ness of other specifications still remains. \$\endgroup\$
    – DELETE_ME
    Nov 12, 2017 at 16:47
  • \$\begingroup\$ @user202729 What other specifications? Anyway, I'm trying to be as language-open as possible, but apart from very few I don't know of any other languages that actually have access to something infinite. So for other languages some kind of extension to get new actions is necessary. Is that too language specific? Maybe I should give up on this question, considering the popularity vote... \$\endgroup\$
    – Heimdall
    Nov 13, 2017 at 10:23
-2
\$\begingroup\$

Golf an interpreter

The challenge is to find a path from A to B, but you must also provide an interpreter for your program. The shortest interpreter wins.

Input to path finder:

A list of edges in a graph e.g.

AC
CD
DB

Output from path finder:

A list of vertices e.g. A C D B

Feel free to somewhat adjust the input/output format.

Scoring:

Your score is the number of bytes of your interpreter/compiler. The lowest score wins.

Note:

It's possible to work around the question and interpret a language that is too similar to an existing one by doing something like:

eval(input_file.replace("this never happens", ""))

I don't have a good rule to prevent this other than to ask that you don't.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Not interesting, so downvote. Yes, you can't restrict that. \$\endgroup\$
    – DELETE_ME
    Jan 7, 2018 at 4:25
-2
\$\begingroup\$

Brainf*** Polygot

Write a brainf*** interpreter in as many languages as possible.

You will take the brainf*** code on standard input, and then execute it.

Your score is bytes / (n * sqrt n) (where n is the number of languages in which your program works), which you will seek to minimize.

\$\endgroup\$
8
  • \$\begingroup\$ I don't think the generic "preform <simple task> in as many languages as possible" [polyglot] task is gonna cut it anymore. Maybe add some new BF-related task. \$\endgroup\$ Jan 24, 2018 at 5:04
  • \$\begingroup\$ @EsolangingFruit This isn't "preform some simple task". This is "be Turing complete". No other polygot challenge can be used a universal turing machine. In particular, it requires you to use the turing complete facilities of all the languages involved. \$\endgroup\$
    – PyRulez
    Jan 24, 2018 at 5:06
  • \$\begingroup\$ If your goal is "prove turing completeness", then maybe "write a polyglot interpreter for a Turing-complete language". Allow different languages to interpret different TC languages. \$\endgroup\$ Jan 24, 2018 at 5:10
  • \$\begingroup\$ @EsolangingFruit I guess that would make it more interesting. I kind of like the idea of them all doing the same thing though, so you can just "feed in" an algorithm and get an instant polygot. \$\endgroup\$
    – PyRulez
    Jan 24, 2018 at 5:19
  • \$\begingroup\$ @EsolangingFruit What about a caveat that the you must feed in the currently executing language as a parameter (for example, when run with python, it executes the code with "python" as its first input). \$\endgroup\$
    – PyRulez
    Jan 24, 2018 at 5:20
  • \$\begingroup\$ In my opinion, polyglot challenges are better when you're solving different problems in each language. That has the advantage of being more interesting to solve, as well as not needing to ban multiple similar versions of the same language (since making polyglots would be trivial in those). \$\endgroup\$ Jan 24, 2018 at 5:25
  • \$\begingroup\$ Alternatively, a more difficult version: a polyglot in some set of languages languages that acts a compiler from BF to a new polyglot in each of those languages. In that case you probably want to score by no. of languages \$\endgroup\$ Jan 24, 2018 at 5:27
  • \$\begingroup\$ @EsolangingFruit OW, that sounds even cooler! \$\endgroup\$
    – PyRulez
    Jan 24, 2018 at 5:39
-2
\$\begingroup\$

Gatherer Golf: The 61 Dwarves

Gatherer is the official tool for searching for Magic: The Gathering cards. Its advanced mode allows searching by most of the criteria you could hope for, as well as simple boolean combinations within a single kind of criterion (for example, you can do "name contains X or Y and not Z").

I've been using it a lot recently, and have been trying to get better at more quickly finding the exact set of cards I need. For example, if I want creatures that can generate mana, searching for "dd {" seems to be the minimal exact string match on their rules text.

For this inaugural Gatherer Golf, your challenge is to create a query that lists, exactly, the 61 Dwarf cards (not counting creatures that are all creature types), without using the key "subtype". The result generated the normal way can be found here.

Rules

  • Your score is the length of the full URL in Gatherer. For example, searching for "name contains Dw or Resp and type contains Creature" generates the URL gatherer.wizards.com/Pages/Search/Default.aspx?action=advanced&name=|[Dw]|[Resp]&type=+[%22Creature%22] for a score of 104.

    • Lowest score wins.
    • Your URL can be manually generated; it doesn't have to be possible to create it via the advanced search form.
    • Cards added to Gatherer after this challenge was posted (in this case, after Rivals of Ixalan) do not invalidate existing answers. Your answer may include or exclude any card published after that date, regardless of whether it's a dwarf, and answers that no longer give correct results (for example, because the Oracle text of a card changed) do not need to be deleted.
    • Other than as described above, all cards in Gatherer are relevant to this challenge, regardless of whether they're legal for tournament play.
    • Don't DOS Gatherer or otherwise break its terms of service.
    • The cards may be listed in any order. This may be relevant if your search contains more than just dwarves, but concentrates all the dwarves into one page of the search results.
\$\endgroup\$
3
  • 1
    \$\begingroup\$ I'm not sure that this requires code to solve. Also, I'd ban the word "subtype" in the query, as that's more solid than "without querying on subtype" \$\endgroup\$ Jan 31, 2018 at 20:26
  • \$\begingroup\$ Thanks, edited. I was thinking of the query itself as code--it's declarative and certainly doesn't meet our definition of a programming language, but I'd've expected an HTML or SQL golfing challenge to be on-topic here and this seems the same in principle. \$\endgroup\$
    – histocrat
    Jan 31, 2018 at 21:02
  • \$\begingroup\$ I wouldn't expect HTML golfing to be on-topic; and SQL meets the definition of a programming language. IMO the way to make this on-topic is to somehow supply a database (maybe abusing imgur with steganography?) and then ask for a program which takes input as a list of card names to match and outputs a minimal query. \$\endgroup\$ Feb 2, 2018 at 12:28
-2
\$\begingroup\$

xkcd-esque Reverse Code Golf

Introduction

A new xkcd comic came out recently, seemed to be a fun challenge and a change from the usual code golfing.

enter image description here

So I set out on making this challenge!

Challenge

Make a short snippet of code in any language which, when read out, sounds like 1 sentence of normal English literature (for example, Moby Dick in the comic).

Rules

  • The snippet doesn't have to run, so you are free to add statements which would not execute (for example: undeclared variables, functions, etc.). However, it must be syntactically correct.

  • A word in this challenge is any sequence of letters considered as valid English as in a dictionary. Articles (a, an, the) are counted as words.

  • To prevent too long answers, the maximum number of words will be fixed at 200 individual words. This includes operator expansion.

  • The maximum length of any function or variable name will be 10 words.

  • The expansion used for an operator must be specified in the answer.

  • Imported and built-in functions are not considered as operators.

  • Since this is reverse code golf, the answer with the most points wins.

Scoring criteria:

  • Characters used to structure code (0): All kinds of brackets, statement terminators, whitespace, etc.
  • Comments and String literals (0): To avoid making large comments/literals with actual literature
  • Names of functions or variables (1 per character):
  • Keywords (2 per letter): Using keywords in the story as valid syntax.
  • Operators (2 per letter of expansion): For example, > is worth 2x13 (isGreaterThan).

Examples

Valid:

try { throw IngTheBallAnd; } catch (Ing it) {}
// Worth 3x2 + 5x2 + 13 + 5x2 + 3 + 5 = 37 points

let myLife = "a quote";
// Worth 3x2 + 6 + 2x2 = 16 points ("=" used as "be")

Invalid:

// One does not simply write everything in a comment
// Worth 0

Hope this meets PPCG puzzle criteria :D

\$\endgroup\$
16
  • \$\begingroup\$ Define "short" Otherwise answers could just go on and on to approach infinite score. \$\endgroup\$
    – Adám
    Feb 28, 2018 at 10:05
  • \$\begingroup\$ How long may function/variable names be? \$\endgroup\$
    – Adám
    Feb 28, 2018 at 10:07
  • \$\begingroup\$ How do we determine the exact expansion of operators? E.g. is * "times" or "multipliedBy"? \$\endgroup\$
    – Adám
    Feb 28, 2018 at 10:09
  • \$\begingroup\$ So the APL function ×× would count as 28: (signOfTheTimes)? Indeed APL functions often read nicely as plain English. E.g. (?∘≢⊃⊢)¨(⊂⍳3)/⍨¨1+⊢ reads as "a random number up to (?) the length () selects from () the value of () each of (¨) the entire () indices until () three (3) replicated (/) by () each of (¨) one (1) added to (+) the value of the argument (). \$\endgroup\$
    – Adám
    Feb 28, 2018 at 10:26
  • \$\begingroup\$ @Adám I'll edit my answer to answer these. As for APL, I guess my puzzle is no match for it :P \$\endgroup\$ Feb 28, 2018 at 10:46
  • \$\begingroup\$ @Adám I'd actually aim for english literature rather than procedure sentences \$\endgroup\$ Feb 28, 2018 at 10:50
  • \$\begingroup\$ What is a "determiner"? Some programming languages do not use white space. What is a word? \$\endgroup\$
    – Adám
    Feb 28, 2018 at 11:05
  • \$\begingroup\$ "Context" determination of expansion is not an exact science. As long as your challenge has that feature, I predict it will be closed as "unclear what you are asking". \$\endgroup\$
    – Adám
    Feb 28, 2018 at 11:07
  • \$\begingroup\$ Are built-in functions "keywords"? What about imported functions? \$\endgroup\$
    – Adám
    Feb 28, 2018 at 11:08
  • \$\begingroup\$ @Adám Edited to answer. Determiners were meant to be Articles (a, an, the). Lack of whitespace is not a concern as long as it is readable. I mentioned the need for specifying the intended meaning of operators before, but it was a partial change. \$\endgroup\$ Feb 28, 2018 at 12:13
  • \$\begingroup\$ built-in functions are not considered as operators? Uh, what exactly is an operator then? Some languages use single letters as operators. I'm afraid this question makes far too many assumptions about the features of programming languages. A common mistake, but often hard to fix. Compare to the problems with atomic code-golf. \$\endgroup\$
    – Adám
    Feb 28, 2018 at 12:53
  • 5
    \$\begingroup\$ There have been a few questions about reading code as sentences, e.g. 1, 2, 3. Because answers can't be objectively scored, those are popularity-contests. However those types of challenge have mostly fallen out of scope on the site and are very hard to get right, see the tag wiki for more infos. \$\endgroup\$
    – Laikoni
    Feb 28, 2018 at 12:56
  • \$\begingroup\$ Hmm.... alrighty. I shall disband this puzzle. I hope someone can make a better puzzle with the comic, it ought to get its own challenge ;) \$\endgroup\$ Feb 28, 2018 at 13:17
  • 3
    \$\begingroup\$ No one have said that? Welcome to PPCG! \$\endgroup\$ Mar 1, 2018 at 0:05
  • \$\begingroup\$ Note that this is called code-bowling on PPCG. Typically code bowling questions have strict scoring rules to avoid arbitrary score inflation which usually prevents large variable/function names. \$\endgroup\$
    – Jo King Mod
    Mar 1, 2018 at 2:19
-2
\$\begingroup\$

Bees?

Inspired by SCP-3045

Write a program that takes the input, extracts all of the words, and looks for the word bee; then:

  • If bee is not detected, pick sections of the text at random and delete them.
  • If bee is detected, add instances of the word bee to the input such that it has significantly more bytes than the original input.

The program should then output these modifications.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ How much is significantly more? Why is it popularity-contest? \$\endgroup\$
    – Laikoni
    Mar 18, 2018 at 14:00
  • 1
    \$\begingroup\$ Do X creatively pop cons have fallen out of scope. This will get closed instantly if posted on main. \$\endgroup\$
    – Dennis
    Mar 19, 2018 at 12:51
-2
\$\begingroup\$

Move a window around the screen

Your code should open a new window that is at least 100 by 100 pixels in size. Once the window is open you should be able to move the window around the screen using the keyboard. The window should move smoothly but it doesn't matter how fast it moves.

\$\endgroup\$
3
  • 2
    \$\begingroup\$ Is there anything else that could make this challenge a bit more interesting? Maybe a scoring method? \$\endgroup\$
    – RamenChef
    Mar 26, 2018 at 14:01
  • \$\begingroup\$ @RamenChef I suppose the scoring method was meant to be by the code-golf rules. I could make the challenge more interesting maybe by insisting that you can type into the window? \$\endgroup\$
    – user9206
    Mar 26, 2018 at 14:05
  • 1
    \$\begingroup\$ What counts as a "window"? I think this might be quite hard to define objectively in a way which is OS-agnostic. \$\endgroup\$ Mar 26, 2018 at 15:38
-2
\$\begingroup\$

Output a Random Bit

Your task is simple: print either 1 or 0.

Chosen uniformly randomly every time.

No, not your silly pseudorandom nonsense. No system calls. No reading /dev/urandom. The randomness has to be unpredictable (i.e. reliant on chaotic, impossible-to-reasonably-model natural phenomena, and not on some configuration of bits in your computer).

Specifications

  • It is OK to query a site such as random.org for your bit.
  • Your program only needs to be runnable once per day (i.e. you can assume there is a 24 hour gap between executions). This is to work around the fact that sites like random.org often have rate-limits.
\$\endgroup\$
12
  • \$\begingroup\$ If it only has to be run once a day, wouldn't millis() % 2 be truly random? \$\endgroup\$
    – geokavel
    Apr 2, 2018 at 3:22
  • 1
    \$\begingroup\$ @geokavel No, because you can't assume that the calling actions will be random (e.g. I could always invoke the program at 25-hour intervals, meaning that millis() % 2 would always be a consistent value. \$\endgroup\$ Apr 2, 2018 at 4:11
  • \$\begingroup\$ Is a time cost of maybe read a file in nanoseconds allowed? \$\endgroup\$
    – l4m2
    Apr 2, 2018 at 4:42
  • 1
    \$\begingroup\$ In its current form, it appears to be impossible to define the validity criteria objectively. Temporary -1. \$\endgroup\$
    – DELETE_ME
    Apr 2, 2018 at 6:39
  • \$\begingroup\$ @user202729 If it were up to you, how would you define them? \$\endgroup\$ Apr 2, 2018 at 6:45
  • \$\begingroup\$ /dev/random seems to be really random. Is it allowed? \$\endgroup\$ Apr 2, 2018 at 7:30
  • \$\begingroup\$ @someone Wikipedia says it's a PRNG, and I've heard that system randomness tends to draw entropy from sources like startup times and user actions, so that wouldn't count. \$\endgroup\$ Apr 2, 2018 at 7:42
  • \$\begingroup\$ Would a HRNG such as RdRand work? \$\endgroup\$ Apr 2, 2018 at 8:24
  • \$\begingroup\$ ... I admit that my downvote/comment is not constructive, but I found absolutely no way to objectively define the challenge. \$\endgroup\$
    – DELETE_ME
    Apr 2, 2018 at 14:02
  • \$\begingroup\$ Maybe define "real random" as "not only based on xxx"(currently last state, calling current) \$\endgroup\$
    – l4m2
    Apr 2, 2018 at 15:38
  • \$\begingroup\$ @l4m2 That was what I was trying to imply by saying it shouldn't be pseudorandom. \$\endgroup\$ Apr 2, 2018 at 18:47
  • \$\begingroup\$ @EsolangingFruit but you need to define what's pseudo \$\endgroup\$
    – l4m2
    Apr 2, 2018 at 18:52
-2
\$\begingroup\$

Let's play the too high too - low game!

TL:DR : write a code that plays the too high - too low game


Given this pseudo code function for the too high - too low game, write it in your language of choice. This is just to make the challenge work better across all languages. This code won't count in the final score. You may also change the function's name and any of its variable's name too.

function isRight(number, guess):  # where the number is the correct answer and the guess is your code's guess

    if guess < number:            # if the guess is too low
        return 0                  # return 0

    else if guess > number:       # if the guess is too high
        return 2                  # return 2

    else if guess == number:      # if the guess is right
        return 1                  # return 1

    else:                         # if there is an error
        return -1                 # return -1

The challenge

Write a code, function, script, etc. that guesses the right number. The range of the "random" number will be between 0 inclusively and 100 exclusively. For the sake of this challenge, the "random" numbers will be the test cases. Note that hard-coding the test cases is banned.


Scoring

This is how the score will be counted:

bytes = number of bytes in your code
tries = the sum of all the tries used to guess all the test cases

score = bytes + tries

Rules

  • Hard-coding the test cases if forbidden.

Test cases

[0,2,4,13,19,21,26,33,38,42,48,50,51,56,66,69,74,75,80,89,98,99]
\$\endgroup\$
3
  • \$\begingroup\$ For one, i'd say the randomness is unfair. If you manipulate the seed python is given, you can just have it output a known sequence. Alongside that, can't you just hardcode the testcase? EDIT: Hardcoding the test case is the only way to get a good score. \$\endgroup\$ Mar 29, 2018 at 16:38
  • \$\begingroup\$ @moonheart08 would banning hardcoding the test cases help? \$\endgroup\$
    – Dat
    Mar 29, 2018 at 17:57
  • 1
    \$\begingroup\$ "the sum of all the tries used to guess all the test cases" Won't this be the same for all answers (with the only difference being floor vs ceil when taking halve the previous guess (as in 75 & higher could result in a next guess of either 87 or 88).First guess will always be 50. Is it lower, guess 25; is it higher, guess 75. etc. etc. Btw, there are already a few Guess the number challenges: Here is one; and here is another one. \$\endgroup\$ Apr 3, 2018 at 12:54
-2
\$\begingroup\$

I see a window and I want it painted black

Yes, I know this is a popular mishearing of the lyrics. But instead of a red door, I really do want an (application) window painted black.

Your standalone program should launch an application window at least 400x400 and fill it entirely with black. It doesn't need to be borderless, and it doesn't need to exit gracefully.

Running in a browser is insufficient because there are still elements of the window such as the address-bar and tab-bar that aren't painted black. You must paint the whole window black except for borders added by your window manager.

This is code golf. Standard loopholes apply. Additional challenge is to listen to The Rolling Stones while making your submission.

Here is an un-golfed Java solution:

#compile: javac BlackWindow.java
#run: java BlackWindow
import java.awt.Color;
import java.awt.Frame;

public class BlackWindow{
  public static void main(String[] args){
    Frame frame = new Frame("no colors anymore");
    frame.setsize(400, 400);
    frame.setLocationRelativeTo(null);
    frame.setBackground(Color.Black);
    frame.setvisible(true);
  }
}
\$\endgroup\$
6
  • \$\begingroup\$ What if my platform doesn't support windows that large? \$\endgroup\$
    – Nissa
    Apr 20, 2018 at 23:17
  • \$\begingroup\$ What is the 400x400 measured in? Pixels? Does it qualify if I somehow emulate a screen with larger resolution? \$\endgroup\$
    – DELETE_ME
    Apr 21, 2018 at 9:23
  • \$\begingroup\$ Does making the whole screen black count? \$\endgroup\$
    – DELETE_ME
    Apr 21, 2018 at 9:24
  • \$\begingroup\$ Stephen then make the whole screen black? What kind of system doesn't support that? \$\endgroup\$
    – Jared K
    Apr 22, 2018 at 0:16
  • \$\begingroup\$ user202729 i was thinking pixels \$\endgroup\$
    – Jared K
    Apr 22, 2018 at 0:16
  • \$\begingroup\$ What if I am listening to The Feelies cover of the song? Do I get the bonus point? +1 from me for an unusual challenge. \$\endgroup\$
    – JayCe
    Jun 11, 2018 at 3:34
-2
\$\begingroup\$

Shorter coding in non-golfing language

Copper write a requirement, a sample program in a golfing language, and a required non-golfing language. Rob hack it with the required language, with fewer bytes of code.

I guess it'd be cuz it's sometimes hard to define which is "golfing language". Also is it a duplicate?

\$\endgroup\$
3
  • \$\begingroup\$ If it's a cops-and-robbers, then it can't be a popularity-contest. I personally don't think this challenge would work out; first of all, it's virtually impossible to outgolf a golfing language using a non-golfing languages because most golfing languages can complete most reasonable tasks in fewer bytes than it takes a non-golfing language to even print Hello World. Also like you said, golfing/non-golfing is extremely difficult to define. I also don't think this challenge would be particularly interesting because you'd likely end up with a bunch of miscellaneous cops posts with all \$\endgroup\$
    – hyper-neutrino Mod
    May 2, 2018 at 13:09
  • \$\begingroup\$ sorts of random requirements, which is basically just going to be a bunch of questions that either exist on PPCG already or could be posted to PPCG main as its own challenge, without any robber posts because it would be basically impossible. \$\endgroup\$
    – hyper-neutrino Mod
    May 2, 2018 at 13:09
  • 3
    \$\begingroup\$ IMO this is well past the threshold of "Too Broad", so I would vote to close for that reason. \$\endgroup\$ May 2, 2018 at 15:23
-2
\$\begingroup\$

(Now I don't know what the name should be)

Intention

I want to create a challenge based on dependent typing, feature that exists in Idris, Coq, Agda and the similiar.

Text

You should create a function in dependently typed language (Idris, Coq, Agda, etc) so that:

  1. The function will receive a string that denotes format.
  2. The format string will have s or n, s means it will receive a string, n means it will receive a number. You can assume that there is no other thing in the string
  3. Arguments is received in order. If there is type mismatch, the error must be reported on compile-time.
  4. After all arguments is received, the function will return a string, that is list of all passed argument

For example

formatf "sn" "goods" 25
> "goods 25"
formatf "sn" "goods" "bad"
> Type error in compile time
formatf "ak" "Akangka" 25
> You can do anything.
formatf "nnn" 24 25
> Either type error or return a function expecting a number and return string (currying is almost universal in these languages)
formatf "ss" "Akangka" "Martin Ender" "Adám"
> Type error on compile time

This challenge is similiar to printf-style string formatting, the difference that the function in this challenge has to be type safe.

Note that you cannot use build-in function or macro to do this

Discussion

  1. What should be the name of this challenge?
\$\endgroup\$
15
  • \$\begingroup\$ Any reason why full programs are not allowed? \$\endgroup\$
    – DELETE_ME
    May 2, 2018 at 9:29
  • \$\begingroup\$ What happens if the language is not compiled? \$\endgroup\$
    – DELETE_ME
    May 2, 2018 at 9:32
  • 1
    \$\begingroup\$ (if you didn't realize, it's not just some languages can't solve it, but in some languages your requirements don't make any sense. There are languages without functions, language with only monadic functions, languages without integers, language without macros, language where macros have different meaning than C #define, language without string (C), etc.) \$\endgroup\$
    – DELETE_ME
    May 2, 2018 at 9:59
  • \$\begingroup\$ If the string is possibly not known at compile time, how can it produce a type error at compile time? \$\endgroup\$
    – Angs
    May 2, 2018 at 10:04
  • \$\begingroup\$ Personally I think it's a bit too similar to the challenge you linked.. The only difference is validating the input-type with the format.. In which case it would be better to have a challenge dedicated to that, as in: Given this format and a variable amount of other objects, check if the format and types of these objects match. In which case "%s: %i%%", "Percentage", 25 would be truthy, and "%s: %i%%", 123.45, 25 would be falsey. In addition, most languages are type independent, which can change during run-time based on their use.. 10.0 could be all three types in some languages.. \$\endgroup\$ May 2, 2018 at 10:07
  • \$\begingroup\$ Suggested re-working of the problem: Given a pattern using only %s and %n (for number), slot in the given list of strings and numbers in the given order, but return a distinct value or throw an error if the given list doesn't fit right. \$\endgroup\$
    – Adám
    May 2, 2018 at 10:08
  • \$\begingroup\$ @Angs dependent typing. In fact, this challenge is about dependent typing. \$\endgroup\$
    – Xwtek
    May 2, 2018 at 10:17
  • \$\begingroup\$ @user202729 well, by compile-time, I mean about typechecking time. I specifically disallow dynamic typing, as one of the point of the challenge is to make the program fail to typecheck if %s format is supplied by integer, etc. \$\endgroup\$
    – Xwtek
    May 2, 2018 at 10:21
  • \$\begingroup\$ @KevinCruijssen Indeed, not all language can do this challenge. After all the intention is on the dependent typing, which most programming language (but not Idris, Coq, etc) lack. \$\endgroup\$
    – Xwtek
    May 2, 2018 at 10:26
  • \$\begingroup\$ @Adám nice suggestion. But the type-safe feature (i.e. all error is on type-checking time) is integral part of the challenge \$\endgroup\$
    – Xwtek
    May 2, 2018 at 10:28
  • \$\begingroup\$ @Akangka I don't understand why my suggestion doesn't satisfy that. You get a list of strings and numbers and need to check against each tag in the format that you've been given the right tag. \$\endgroup\$
    – Adám
    May 2, 2018 at 12:12
  • \$\begingroup\$ I think you should limit to some languages (perhaps extend the language list if needed), as the challenge does not make sense in other languages anyway. \$\endgroup\$
    – DELETE_ME
    May 3, 2018 at 1:26
  • \$\begingroup\$ @Adám I actually implement your suggestion, except the throw an error part. I make the challenge require the result is type error \$\endgroup\$
    – Xwtek
    May 3, 2018 at 2:03
  • \$\begingroup\$ @Akangka I don't understand why you insist on language specific features like "type errors" and "compile time". Your examples do not show how to format ss, ns, and nn. You mention float dots, but floats are not part of the examples any more. \$\endgroup\$
    – Adám
    May 3, 2018 at 5:46
  • \$\begingroup\$ @Adám thanks about float dots. About language specific features, I just want to create a challenge about dependent typing. \$\endgroup\$
    – Xwtek
    May 3, 2018 at 6:50
-2
\$\begingroup\$

The challenge

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

  • Gracefully failing in DM channels is not required.

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

Sample discord.py implementation

import discord
client = discord.Client()
@client.event
async def on_message(M):
 if(M.content=="!oldest"):
  N=sorted([x.id for x in M.server.members])[1]
  await client.send_message(M.channel, str(M.server.get_member(N)))
client.run("MjM4NDk0NzU2NTIxMzc3Nzky.CunGFQ.wUILz7z6HoJzVeq6pyHPmVgQgV4")
  1. Get a list of every user in the server
  2. Sort their snowflake IDs
  3. Print the username and discriminator of the member with the smallest ID.

No API for your language? Have fun.

Standard loopholes forbidden, etc, etc.

Shortest code in bytes wins.


Sandbox

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

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

Quecho, a quine-like implementation of echo.

Challenge:

Your challenge is to write a quine-like program that takes a string from stdin and gives two outputs: Output A is the input string. Output B is your source code.

Output Formats:

You can send your outputs to stdout, stderr, and/or files. If A and B go to the same output, they must be separated by a newline. Having a newline at the beginning of your source doesn't count. You'd need to print that newline from your source and then another newline to separate A and B.

Examples:

source: print($stdin+"\n"+codeThatGeneratesSource)

input: Hello, World!

Both outputs on stdout:

Hello, World!
print($stdin+"\n"+codeThatGeneratesSource)

Separate Outputs:

stdout: Hello, World!

stderr: print($stdin+"\n"+codeThatGeneratesSource)

Standard loopholes are forbidden.

Submissions should be proper quines except that they produce the additional specified output.

\$\endgroup\$
3
  • \$\begingroup\$ Related: codegolf.stackexchange.com/questions/66276/quat-quine-cat \$\endgroup\$
    – Beefster
    Jun 1, 2018 at 16:27
  • \$\begingroup\$ Good find. Not a dupe because that calls for either printing the source or printing the input, not both. Also it requires testing length of input, where this does not. \$\endgroup\$
    – Jared K
    Jun 1, 2018 at 16:38
  • 2
    \$\begingroup\$ How is this any different from that, though? The concept of printing the source and printing the output is the same, and I can't see how only a small tweak wouldn't be able to port an answer between the challenges. \$\endgroup\$
    – LyricLy
    Jun 3, 2018 at 5:32
-2
\$\begingroup\$
  • This is in sandbox to check whether or not to repost the BrainF**k interpreter challenge. The links have been given in credits.
  • Should comment handling be required.
  • Also any other improvements are welcome

BrainF**k:

BrainF**k is an esoteric programming language designed in the 90s. The reason for its fame is that understanding a program longer than 10 characters in the language is quite hard.

Example program :

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

Guess what this does.


Commands:

Brainf**k operates on an array of memory cells, also referred to as the tape, each initially set to zero. There is a pointer, initially pointing to the first memory cell.

There are a total of eight commands in BF and these are as follows:

Command       |                              Purpose
  >           |      increment the data pointer (to point to the next cell to the right).
  <           |      decrement the data pointer (to point to the next cell to the left).
  +           |      increment (increase by one) the byte at the data pointer. 
  -           |      decrement (decrease by one) the byte at the data pointer.
  .           |      output the byte at the data pointer
  ,           |      one byte of input, storing its value in the byte at the data pointer.
  [           |      if the byte at the data pointer is zero, then instead of moving the instruction pointer forward to the next command, jump it forward to the command after the matching ] command.
  ]           |      if the byte at the data pointer is nonzero, then instead of moving the instruction pointer forward to the next command, jump it back to the command after the matching [ command.

Note :

+ and - operators increment and decrement the bytes at the at the data pointer, note that if the value reaches 255 then upon a + it would become 0.

255 + 1 = 0

Similarly if the value reaches 0 then upon the next - it would become 255.

0 - 1 = 255

Input:

You will be given two strings as input:

  • The actual BrainF**k code that you are supposed to interpret.
  • the program input (that will eventually be emptied) to be interpreted as an array of bytes using each character's ASCII code and will be consumed by the , instruction

Example:

Program : +[,>,]<.
stdin   : 11111 

Output:

  • the output of the interpreted code, if any was produced by the . instruction.

Example:

For the above mentioned program, the output should be:

output: 1

Notes:

  • Both program and stdin will be given as strings.
  • The output should be a string showing the result after operations.
  • Given input will always be valid, with a valid BrainF**k program.
  • In order to avoid confusion, note that you do not need to output the word output as well

e.g :

 output : 1

in this your output should only be 1. (asked by @Picard)

Credits:

The question was (more or less) already asked here. This has been reposted since that was 7 years old and was outdated as well.

Meta posts on that:


Examples:

Program: +[>>>>+++++[-<++>]<[-<++++++++++>]<[-<<->>]<<-[>-<[-]]>+<,]>[>>+>+<<<-]>>>[<<<+>>>-]<<+>[<->[>++++++++++<[->-[>+>>]>[+[-<+>]>+>>]<<<<<]>[-]++++++++[<++++++>-]>[<<+>>-]>[<<+>>-]<<]>]<[->>++++++++[<++++++>-]]<[.[-]<]<
stdin: Hello, World. This is a program for checking eeeeeeee. Well I have plenty of e
output: 14

Program: ++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.
stdin: 
output: Hello, World

Winning-criteria:

This is , so the shortest code in bytes for each language wins.

\$\endgroup\$
14
  • \$\begingroup\$ @AdmBorkBork : So i should put nothing ? \$\endgroup\$ Jun 1, 2018 at 14:59
  • \$\begingroup\$ @AdmBorkBork : Thanks, done. \$\endgroup\$ Jun 1, 2018 at 15:01
  • \$\begingroup\$ I think some of your notes are too ambiguous to be useful. In particular, "You can have numbers as output where numbers are expected" and "The input will be what it should be" seem to just be... "You are allowed to output numbers if you're allowed to output numbers" and "You can assume that the input is the input" \$\endgroup\$ Jun 1, 2018 at 15:07
  • \$\begingroup\$ Also, it would be good to clarify whether the BF commands are the only characters that will be in the program string, or if we are required to handle other characters as comments. \$\endgroup\$ Jun 1, 2018 at 15:09
  • \$\begingroup\$ @KamilDrakari : Changed. Hopefully better \$\endgroup\$ Jun 1, 2018 at 15:09
  • \$\begingroup\$ @KamilDrakari : I think I will put that as something I would like to know (reasons why this is sandboxed)\ \$\endgroup\$ Jun 1, 2018 at 15:09
  • \$\begingroup\$ I don't believe comment handling would be interesting, so I would rather leave it as "you may assume the program input contains no characters other than ><+-.,[]" \$\endgroup\$ Jun 1, 2018 at 15:32
  • \$\begingroup\$ @KamilDrakari : Okay \$\endgroup\$ Jun 1, 2018 at 15:34
  • \$\begingroup\$ What happens if you move left of the starting position on the tape? Is it undefined behaviour or does it have to work? \$\endgroup\$
    – wastl
    Jun 1, 2018 at 18:58
  • \$\begingroup\$ @wastl : undefined behaviour is ok. \$\endgroup\$ Jun 1, 2018 at 19:00
  • 1
    \$\begingroup\$ 3 things: 1, you need to explain how the memory tape works. You hvaen't really explained that. 2, you should clarify that the output doesn't need to say literally output: 1, you should really allow just 1. 3, don't really bother with comments, it's basically just ignoring other characters. \$\endgroup\$
    – Riker
    Jun 1, 2018 at 22:37
  • \$\begingroup\$ 1. Hopefully done, 2. done, 3. Ok, 2 votes for not having comments. \$\endgroup\$ Jun 2, 2018 at 9:26
  • \$\begingroup\$ What if our language has only one input stream? Can we also accept input as the program and input separated by a ! (or some other character)? \$\endgroup\$
    – Jo King Mod
    Jun 4, 2018 at 2:11
  • \$\begingroup\$ @JoKing : yes, you can \$\endgroup\$ Jun 4, 2018 at 7:42
-2
\$\begingroup\$

Longest reference

Write two code A and B, where len(A)<=1024, running A returns B and running B returns A. Longest B win.

Proper quine rule and no rubbish rule(for code-bowling) apply.

Un-used Code

All code must be used. Meaning the program must fail to always properly complete the task if any individual character (or varying set(s) of characters) is/are removed. Naturally, a subset of the program should not be able complete the task on its own without the rest of the program.

Sandbox notes

  • The "1024" may change
\$\endgroup\$
8
  • 1
    \$\begingroup\$ Actually we have no standard rule for code-bowling to prevent unused code. \$\endgroup\$
    – DELETE_ME
    Jul 5, 2018 at 9:52
  • \$\begingroup\$ (although for this particular challenge, it's not possible to make program arbitrarily long) \$\endgroup\$
    – DELETE_ME
    Jul 5, 2018 at 9:53
  • 3
    \$\begingroup\$ It's pretty easy to abuse this one. Program A prints program C n times, where program C prints program A and then comments out any further copies of C. Make n as large as you can and it's easy. Good code-bowling challenges usually have more restrictions \$\endgroup\$
    – Jo King Mod
    Jul 5, 2018 at 10:34
  • \$\begingroup\$ @JoKing Your solution seems to break the "no rubbish rule" \$\endgroup\$
    – l4m2
    Jul 6, 2018 at 1:10
  • 1
    \$\begingroup\$ As user202729 says, there is no standard "rubbish rule". And if there was, there would be many ways of getting around it. \$\endgroup\$
    – Jo King Mod
    Jul 6, 2018 at 1:25
  • 1
    \$\begingroup\$ Suggestion: Why not have the challenge be to minimise the length of A while maximising the length of B? I'm not sure what the scoring system would be though... \$\endgroup\$
    – Jo King Mod
    Jul 7, 2018 at 3:25
  • 2
    \$\begingroup\$ @JoKing I really like that idea but I don't think it would solve the problem. The issue is that B can still contain "rubbish", so it becomes a kind of busy-beaver problem for A to print the largest amount of nonfunctional code in B. \$\endgroup\$
    – N. Virgo
    Jul 7, 2018 at 4:28
  • 3
    \$\begingroup\$ The "unused code" test is unlikely to be practical for programs longer than about 100 characters. \$\endgroup\$ Jul 7, 2018 at 12:04
-2
\$\begingroup\$

Sort on an infinite-dimension cube

Given a unit cube in the \$n\$-dimensional space. Assume that the vertices of the cube has coordinate \$(x_0, x_1, x_2, \dots, x_n)\$ where \$x_i \in \{0,1\} \forall i\in \mathbb N, 0\le i<n\$.

It's possible to number all vertices with non-negative integers less than \$2^n\$. In this challenge, the vertex with coordinate \$(x_0, x_1, x_2, \dots, x_n)\$ will be assigned with number \$2^0\times x_0+2^1\times x_1+\dots+2^n\times x_n\$.

Each vertex can hold an integer.

In this challenge, you can assume \$n\$ contains a very large (practically infinite) value.


Given \$4096\$ items placing in vertex 0 - vertex 4095, you're to sort them. Other vertices contain undefined values, and may be modified by the program.

However, the program cannot directly access the values held by the vertices. You can only control a memory pointer M, which always lie at a vertex of the cube (call this vertex V). Initially M is at the coordinate \$(0,0,0,\dots)\$. This memory pointer can store exactly 1 integer value.

The following operations on the memory pointer M are alllowed:

  • Store the value held by V into memory of M.
  • Write the value stored by M into V.
  • Compare value stored by M and value held by V. This operation should report to the program 3 different values based on whether the comparison is \$<\$, \$=\$ or \$>\$.
  • Move along an edge (in the direction specified by the program) of the cube. This corresponds to changing exactly 1 coordinate of M from 0 to 1, or vice versa.

Your score is the distance traveled by the memory pointer.


A psuedo-code sample interaction library may be:

obj[Infinity] = {[4096 values]}
ptr = 0, cry = undefined
function move(i): ptr = ptr xor (1 shl i)
function carry(): cry = obj[ptr]
function place(): obj[ptr] = cry
function compare(): return sgn(obj[ptr] - cry)

You can write functions, use IO, or anyway to interact. Lowest move callings win.

\$\endgroup\$
7
  • \$\begingroup\$ Actually I think there are just 12 dimensions. \$\endgroup\$
    – DELETE_ME
    Jul 12, 2018 at 14:55
  • \$\begingroup\$ @user202729 More dimensions exist and you can use them, but they are initally empty \$\endgroup\$
    – l4m2
    Jul 12, 2018 at 14:59
  • 5
    \$\begingroup\$ What does it mean to sort an infinite-dimension cube? Currently this very unclear. \$\endgroup\$
    – Laikoni
    Jul 13, 2018 at 12:46
  • \$\begingroup\$ @Laikoni I'd say code shows enough to understand, so it's not ready to post but not unclear \$\endgroup\$
    – l4m2
    Jul 13, 2018 at 14:25
  • 2
    \$\begingroup\$ No, sorry, it's not so clear to the rest of us. I have no idea what the input is, what the output is, even what obj we're working with and how it relates to an "infinite dimension cube". Many of your questions here (including this one) seem to contain something interesting in them, but they'd be much better received if you post them on the chat room first and explained what you had in mind, and got some help with the question text, at least to the level that they can be meaningfully discussed on. That way your challenges will reach more people too. \$\endgroup\$
    – Sundar R
    Jul 15, 2018 at 10:41
  • 5
    \$\begingroup\$ @sundar I think the sandbox is exactly the place for improving challenges. I'm not sure if using the chat room is necessary. \$\endgroup\$
    – DELETE_ME
    Jul 19, 2018 at 14:35
  • \$\begingroup\$ @Laikoni Better now? \$\endgroup\$
    – DELETE_ME
    Jul 19, 2018 at 15:10
-2
\$\begingroup\$

Golf a regex that matches syntactically valid programs in the language of your choice.

1: Pick a programming language, P, that meets these requirements:

  • P is known to be Turing-Complete.
  • P has a freely available and working compiler or interpreter.

2: Create a regular expression, R, such that:

  • R matches any string that is a syntactically valid program of P.
  • R rejects any string that is a syntactically invalid program of P

3: Golf R. Shortest regex wins.

\$\endgroup\$
6
  • 1
    \$\begingroup\$ For a lot of Esolangs it would just be .*, I think you'd need to restrict the languages to something that doesn't allow any string ALPHABET* or ALPHABET+. Also you'd need to specify a regex flavour. \$\endgroup\$ Jul 27, 2018 at 20:49
  • \$\begingroup\$ Warning: Most low-level languages are not known to be TC. For example C (which is only recently proved TC, AFAIK. Ref) \$\endgroup\$
    – DELETE_ME
    Jul 28, 2018 at 9:21
  • \$\begingroup\$ Hm. int main(){int x=__builtin_popcount(1);} is not syntactically valid C (undefined identifier), but it compiles in GCC. Also, most compilers don't allow too long identifiers. What do you think? \$\endgroup\$
    – DELETE_ME
    Jul 28, 2018 at 9:23
  • 3
    \$\begingroup\$ @user202729: I doubt that you'll find a regex for C (or pretty much any non-esoteric, high-level language) anyways since most of the time you need to check if () are balanced. \$\endgroup\$ Jul 28, 2018 at 15:21
  • \$\begingroup\$ @OMᗺ Just saying...... // For the first comment, typically the answerer just specify the regex flavor in the answer. \$\endgroup\$
    – DELETE_ME
    Jul 28, 2018 at 15:23
  • \$\begingroup\$ Because only those high-level languages have a proper definition of what is a syntax error. The low-level languages are often just "what the interpreter complains about", and there are still different forms of error -- assertion error, runtime, return 1, .... \$\endgroup\$
    – DELETE_ME
    Aug 1, 2018 at 2:49
1
144 145
146
147 148
153

You must log in to answer this question.

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