# What is the Sandbox?

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

To post to the Sandbox, scroll to the bottom of this page or click on the "Add Proposal" link below, and click "Answer This Question". Click "OK" when it asks if you really want to add another answer. Write your challenge just as you would when actually posting it. You may also add some notes about specific things you would like to clarify before posting it. Other users will help you improve your challenge by rating and discussing it. When you think your challenge is ready for the public, go ahead and post it, replace the post here with a link to the challenge and delete it.

See the Sandbox FAQ for more information on how to use the Sandbox.

## Get the Sandbox Viewer to view the sandbox more easily

To add an inline tag to a proposal use shortcut link syntax with a prefix: [tag:king-of-the-hill]

# 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.

• 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. – user2284570 Oct 1 '17 at 20:37

# 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.


# 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?

• 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). – Jonathan Frech Nov 11 '17 at 22:26
• @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. – Heimdall Nov 12 '17 at 12:19
• 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. – user202729 Nov 12 '17 at 12:42
• @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? – Heimdall Nov 12 '17 at 15:13
• 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. – user202729 Nov 12 '17 at 16:47
• @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... – Heimdall Nov 13 '17 at 10:23

# Highest code size∕output ratio to generate a large executable section inside an elf file.

Your challenge is to create the shortest code in your language of choice or the tools of your choice (like objcopy) that will create an elf file with a the executable section as large as possible.
I mean that if I extract the.text section of the elf binary, the resulting extracted file should be at least 90% of the elf binary.

# Requirements

• The program should takes the desired section size as input.
• The .text section name needs to corresponds to the executable section.
• The type of the .text section should bePROGBITSand it should contains instructions.
• The elf file should have a .shstrtab section.
• The .text section should be readable and writable.
• The target architecture should be Pnacl or armelv7 or x86_64.
• The elf file should be valid and pass Google nacl’s validation whitelist in order to be loaded (but I don´t care if the sandbox segfault).
If you have no idea about what Google native client is, just create a script that call the patched version of binutils from the nacl_sdk, or make sure the elf file is valid and can be executed on Linux.

Of course, you normally can’t use a compiler because it would takes too much computational years in order to finish.

# Winner

The answer with the highest code size∕program output ratio.

• Why not make scoring output size / code size? – anna328p Apr 4 '17 at 3:49
• Make it a code-challenge – anna328p Apr 4 '17 at 3:49
• This is essentially the same challenge as this one, and would be closed as a duplicate. Although it's not exactly the same, some answers to the previous question would require very little modification and answers to this question would also require very little modification to be answers to the other one. – Peter Taylor Apr 4 '17 at 8:37
• @Alt-F4 : it was a code challenge. – user2284570 Apr 4 '17 at 21:52
• @PeterTaylor : they were no answer to the previous question. In order to be closed as a duplicate the target needs to be already answered. You known it was closed an unclear, so please suggest change to make this answer clearer. – user2284570 Apr 4 '17 at 21:54
• Huh? It's open and has 15 answers. – Peter Taylor Apr 4 '17 at 22:09
• @PeterTaylor sorry, I thought to an another question that was closed as unclear and didn’t take time to read your link. In that case NO, the aim is to not use the compiler in order to actually build the file. This normally can’t be done with a compiler or an assembler. – user2284570 Apr 4 '17 at 22:16
• Can't it? Why not? – wizzwizz4 Dec 16 '17 at 19:55
• Wait... shortest code that generate any program? Or what? Don't think this is a good idea... – user202729 Jan 6 '18 at 12:10

## 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.

• 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. – Esolanging Fruit Jan 24 '18 at 5:04
• @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. – PyRulez Jan 24 '18 at 5:06
• 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. – Esolanging Fruit Jan 24 '18 at 5:10
• @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. – PyRulez Jan 24 '18 at 5:19
• @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). – PyRulez Jan 24 '18 at 5:20
• 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). – Esolanging Fruit Jan 24 '18 at 5:25
• 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 – Esolanging Fruit Jan 24 '18 at 5:27
• @EsolangingFruit OW, that sounds even cooler! – PyRulez Jan 24 '18 at 5:39

# 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.
• 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" – Nathan Merrill Jan 31 '18 at 20:26
• 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. – histocrat Jan 31 '18 at 21:02
• 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. – Peter Taylor Feb 2 '18 at 12:28

# 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.

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

• Define "short" Otherwise answers could just go on and on to approach infinite score. – Adám Feb 28 '18 at 10:05
• How long may function/variable names be? – Adám Feb 28 '18 at 10:07
• How do we determine the exact expansion of operators? E.g. is * "times" or "multipliedBy"? – Adám Feb 28 '18 at 10:09
• 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 (⊢). – Adám Feb 28 '18 at 10:26
• @Adám I'll edit my answer to answer these. As for APL, I guess my puzzle is no match for it :P – K3v1n Feb 28 '18 at 10:46
• @Adám I'd actually aim for english literature rather than procedure sentences – K3v1n Feb 28 '18 at 10:50
• What is a "determiner"? Some programming languages do not use white space. What is a word? – Adám Feb 28 '18 at 11:05
• "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". – Adám Feb 28 '18 at 11:07
• Are built-in functions "keywords"? What about imported functions? – Adám Feb 28 '18 at 11:08
• @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. – K3v1n Feb 28 '18 at 12:13
• 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. – Adám Feb 28 '18 at 12:53
• 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. – Laikoni Feb 28 '18 at 12:56
• 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 ;) – K3v1n Feb 28 '18 at 13:17
• No one have said that? Welcome to PPCG! – Weijun Zhou Mar 1 '18 at 0:05
• 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. – Jo King Mar 1 '18 at 2:19

# 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.

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

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.

• Is there anything else that could make this challenge a bit more interesting? Maybe a scoring method? – RamenChef Mar 26 '18 at 14:01
• @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? – user9206 Mar 26 '18 at 14:05
• What counts as a "window"? I think this might be quite hard to define objectively in a way which is OS-agnostic. – Peter Taylor Mar 26 '18 at 15:38

# 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.
• If it only has to be run once a day, wouldn't millis() % 2 be truly random? – geokavel Apr 2 '18 at 3:22
• @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. – Esolanging Fruit Apr 2 '18 at 4:11
• Is a time cost of maybe read a file in nanoseconds allowed? – l4m2 Apr 2 '18 at 4:42
• In its current form, it appears to be impossible to define the validity criteria objectively. Temporary -1. – user202729 Apr 2 '18 at 6:39
• @user202729 If it were up to you, how would you define them? – Esolanging Fruit Apr 2 '18 at 6:45
• /dev/random seems to be really random. Is it allowed? – the default. Apr 2 '18 at 7:30
• @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. – Esolanging Fruit Apr 2 '18 at 7:42
• Would a HRNG such as RdRand work? – the default. Apr 2 '18 at 8:24
• ... I admit that my downvote/comment is not constructive, but I found absolutely no way to objectively define the challenge. – user202729 Apr 2 '18 at 14:02
• Maybe define "real random" as "not only based on xxx"(currently last state, calling current) – l4m2 Apr 2 '18 at 15:38
• @l4m2 That was what I was trying to imply by saying it shouldn't be pseudorandom. – Esolanging Fruit Apr 2 '18 at 18:47
• @EsolangingFruit but you need to define what's pseudo – l4m2 Apr 2 '18 at 18:52

# 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]

• 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. – moonheart08 Mar 29 '18 at 16:38
• @moonheart08 would banning hardcoding the test cases help? – Dat Mar 29 '18 at 17:57
• "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. – Kevin Cruijssen Apr 3 '18 at 12:54

# ♫ 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);
}
}

• What if my platform doesn't support windows that large? – Nissa Apr 20 '18 at 23:17
• What is the 400x400 measured in? Pixels? Does it qualify if I somehow emulate a screen with larger resolution? – user202729 Apr 21 '18 at 9:23
• Does making the whole screen black count? – user202729 Apr 21 '18 at 9:24
• Stephen then make the whole screen black? What kind of system doesn't support that? – Jared K Apr 22 '18 at 0:16
• user202729 i was thinking pixels – Jared K Apr 22 '18 at 0:16
• 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. – JayCe Jun 11 '18 at 3:34

# 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?

• 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 – HyperNeutrino May 2 '18 at 13:09
• 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. – HyperNeutrino May 2 '18 at 13:09
• IMO this is well past the threshold of "Too Broad", so I would vote to close for that reason. – Peter Taylor May 2 '18 at 15:23

(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?
• Any reason why full programs are not allowed? – user202729 May 2 '18 at 9:29
• What happens if the language is not compiled? – user202729 May 2 '18 at 9:32
• (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.) – user202729 May 2 '18 at 9:59
• If the string is possibly not known at compile time, how can it produce a type error at compile time? – Angs May 2 '18 at 10:04
• 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.. – Kevin Cruijssen May 2 '18 at 10:07
• 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. – Adám May 2 '18 at 10:08
• @Angs dependent typing. In fact, this challenge is about dependent typing. – Xwtek May 2 '18 at 10:17
• @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. – Xwtek May 2 '18 at 10:21
• @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. – Xwtek May 2 '18 at 10:26
• @Adám nice suggestion. But the type-safe feature (i.e. all error is on type-checking time) is integral part of the challenge – Xwtek May 2 '18 at 10:28
• @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. – Adám May 2 '18 at 12:12
• 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. – user202729 May 3 '18 at 1:26
• @Adám I actually implement your suggestion, except the throw an error part. I make the challenge require the result is type error – Xwtek May 3 '18 at 2:03
• @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. – Adám May 3 '18 at 5:46
• @Adám thanks about float dots. About language specific features, I just want to create a challenge about dependent typing. – Xwtek May 3 '18 at 6:50

# 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!

$hiworld = new hiworld; echo$hiworld->$print; ?>  # Alternate Example Answer format # My Oh so wrong and totally fake Hello world - PHP - Alt.Points(53) <?php class hiworld{public$printme = "Hello World"}
$hiworld = new hiworld; echo$hiworld->\$print;
?>


Attempted with:

50 pts: PSR-2 Foo's Enforcement Hook: Foo-Checker [http://foo.example.com] (Broke)

3 pts: PSR-2 Bar's Enforcement Hook: Bar-Checker [http://bar.example.com]

Deleted Version

• That just makes it better. – liljoshu Mar 8 '19 at 23:29
• Hate as measured by votes, however, is a discrete value, and therefore objective. – liljoshu Mar 8 '19 at 23:37
• While I disagree that pop cons need an objective criterion for voting (anything objectively measurable wouldn't need votes), pop cons are out of favour for that very reason. It is rare for a pop con to be welcomed. – trichoplax Mar 10 '19 at 10:00
• @trichoplax Fair enough on that. I'll change encouragement to just be on coding style. – liljoshu Mar 10 '19 at 22:25
• The problem is mostly the popularity-contest tag, which are very hard to do correctly. For example, how do you define break as many coding conventions as possible? How do you define convention, especially for esoteric languages where there are no conventions? The amount of conventions broken also depends on the poster's and viewer's standards, and is therefore not objective. – Jo King Mar 12 '19 at 21:38
• If a voter agrees it violates all the listed coding conventions, upvote the code that violates the most while still functioning is still subjective. All conventions are going to be subjective, e.g. Proper indentation, does that mean 4 spaces or a tab? One voter might think one way, and another might think another way. In general, I think you've chosen a very subjective winning criterion, and short of listing and defining the conventions yourself, it's not going to become objective again. – Jo King Mar 13 '19 at 0:06
• I've removed my downvote and the related comment. – trichoplax Mar 13 '19 at 6:59
• The new scoring mechanism is still subjective, but a big improvement. What counts as a convention still seems like a grey area. Does it need to be from an official source, for some definition of official? Does it need to have been posted online prior to the posting of this challenge? Does it need to be stating that coders "must", "should", or something else? – trichoplax Mar 13 '19 at 7:05
• One way to make this objective would be as a language specific challenge, for example with something like JSLint. That way your score is the number of complaints triggered when running it through the linter, and highest wins. Only being able to compete in one language doesn't seem ideal, but I mention it as an example in case someone can come up with a more inclusive approach. – trichoplax Mar 13 '19 at 7:08
• "Whatever makes you feel dirty for having put it through your keyboard" and "Each answer should list and link to coding conventions it breaks" are mutually contradictory. – Peter Taylor Mar 13 '19 at 12:00
• @trichoplax I do like your idea of counting linter complaints to make it more objective, and feel that's on the right track. Maybe bringing some code-cleanup program into it, and seeing how much work it has to do? – liljoshu Mar 13 '19 at 15:33
• I feel like this could work if one language was selected, with associated style guide/linter, and an objective scoring system made for that. Otherwise, you're comparing a lot of apples and shoes. – Spitemaster Mar 14 '19 at 16:36
• I know this probably isn't going anywhere, but the most 'official' python style guide is probably PEP 8. – Artemis still doesn't trust SE Apr 6 '19 at 18:17
• @liljoshu You've got my upvote for what it's worth, though I agree this needs some improvements. – Artemis still doesn't trust SE Apr 8 '19 at 22:35
• Something like codegolf.stackexchange.com/questions/172445/… might be ok – Embodiment of Ignorance Apr 10 '19 at 3:04