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

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]

• How are tags added to questions? – guest271314 Jan 9 '19 at 7:51
• @guest271314 You can use this markup to create a tag in a draft: [tag:code-golf] – DJMcMayhem Aug 29 '19 at 15:19
• Why no featured anymore? Can't we have it auto-added or something? – S.S. Anne Sep 26 '19 at 15:57
• @JL2210 We now have a permanent info box that links to the Sandbox, so the featured tag isn't necessary – caird coinheringaahing Sep 29 '19 at 13:43

# 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

Write a program who return the current month.

## The Rules

• The result needs to be correct even if the program is run in the future.
• It's so the shortest code wins!

## Optional

Add an interpreter so the submission can be tested. It is allowed to write this interpreter yourself for a previously unimplemented language.

It's my first code-golf idea I'm fully open to improving it with more experienced users.

• That's usually a problem with trivial challenges. If this isn't a duplicate of an existing challenge, I predict it will get a lot of answers very quickly, many of which will be very short golfing language solutions. – Adám Apr 11 '18 at 14:54
• Possible duplicate? codegolf.stackexchange.com/questions/114787/… – DIDIx13 Apr 11 '18 at 14:54
• Nope, still not all that good. – Nissa Apr 13 '18 at 12:41
• @StephenLeppik Hm, what can I improve so? – DIDIx13 Apr 13 '18 at 12:42
• IMO you're wasting your time trying to improve this. Delete it and try to come up with something which is inherently interesting. – Peter Taylor Apr 13 '18 at 12:50
• Write a program who return the current month should probably change that to Write a program which return the current month. what do you think. Also JSYK : This is a one line task for languages like JS and Ruby. So you should probably ban those – Muhammad Salman Apr 13 '18 at 12:51
• good point. I guess leave it as is. – Muhammad Salman Apr 13 '18 at 13:06
• @MuhammadSalman Easier challenges get shorter solutions. If you don't want to see short solutions (no idea why), write hard challenges. – user202729 Apr 13 '18 at 13:12
• @user202729 : I never said I don't want short solutions. But these aren't much of a challenge. For example even a ten year old kid would be able to solve this in JavaScript using built in's. in all a total of 10 chars spent and 2 seconds. Not fun. Challenges that make you stop and think and actually work for them are best. Of course feel free to disagree. – Muhammad Salman Apr 13 '18 at 13:16

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

# Output Infinity (updated v2)

## Challenge

Output the following infinity symbol:

         ∞∞infinity                         ∞infinity
infinity∞∞infinity                 infinity∞∞infinity
infinity∞∞∞∞∞∞∞infinity           infinity∞∞∞∞∞∞∞infinity
infinity        ∞∞infinity      ∞∞∞∞∞infinity        ∞∞∞∞∞∞∞
∞∞∞∞∞                 ∞∞∞∞∞∞∞  ∞∞∞infinity               ∞∞∞∞∞
∞∞∞                      ∞∞∞∞∞∞∞infinity                   ∞∞∞
∞∞∞                         ∞∞infinity                       ∞∞∞
∞∞∞                       ∞∞infinity                         ∞∞∞
∞∞∞                    ∞∞∞∞∞∞infinity                      ∞∞∞
∞∞∞∞∞               ∞∞∞infinity  ∞∞∞∞∞∞∞                 ∞∞∞∞∞
infinity       ∞∞∞∞∞infinity     ∞∞∞infinity        infinity
infinity∞∞∞∞∞∞∞infinity           infinity∞∞∞∞∞∞∞infinity
infinity∞∞infinity                infinity∞∞∞infinity
∞infinity                        ∞∞∞infinity


## Rules

• No input.
• Output can be given in any convenient format.
• Any number of trailing spaces at the end of each line is allowed.
• Any number of trailing new lines at the end of the shape is permitted.
• Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
• If possible, please include a link to an on-line testing environment so other people can try out your code!
• Standard loopholes are forbidden.
• This is so all usual golfing rules apply, and the shortest code (in bytes) wins.
• need some comments for down-vote... – mdahmoune Apr 20 '18 at 19:01
• If the challenge's goal is -- as I understand it -- to output one of the five objects, in most languages that would result in an optimal submission of something along the lines of print("∞"). A rather boring but valid submission to a challenge that effectively asks to print a single unicode character. – Jonathan Frech Apr 20 '18 at 19:34
• The downvotes are probably because you're allowing multiple outputs, some of which are interesting (4-5), some of which are trivial (1-3). As @JonathanFrech suggests, for a code-golf challenge, everyone is going to chose a trivial output for shortness. Alternate ideas: Input an integer 1-5, output the corresponding form of infinity. Or perhaps narrow to just output option #4 (or an even larger, fancier ASCII infinity), and make it a kolmogorov-complexity question. – BradC Apr 20 '18 at 20:59
• I would even say that this challenge in its current form should be tagged kolmogorov-complexity. If you decide to go in the direction @BradC suggested, you could maybe also consider to incorporate the challenge's theme into your challenge rather than posting yet another Kolmogorov complexity challenge. Something along the lines of infinitely outputting the ASCII art or taking two numbers as input, dividing them and producing the infinity symbol when the second one is zero. – Jonathan Frech Apr 20 '18 at 22:01
• I don't think this is anyhow related to math. Only "inspired by math", maybe. – user202729 Apr 21 '18 at 10:54
• Now -- is there any exploitable pattern in the output such that it should not be closed as a dupe of "We're no stranger to code golf, you know the rules, and so do I"? – user202729 Apr 21 '18 at 10:55
• @user202729 No, there is no predefined specific pattern, I prepared this MANUALLY. How could I specify that in the challenge? – mdahmoune Apr 21 '18 at 11:00
• I believe it's customary to specify if trailing spaces / new lines are permitted and if so, how many – Asone Tuhid Apr 21 '18 at 19:30
• @AsoneTuhid for spaces I think it is ok because it does not deform the shape, but I do not think so for new lines, what do you think? – mdahmoune Apr 21 '18 at 19:54
• Not between the lines, of course. I mean new lines after the whole drawing. Some people put restrictions (none, one, whatever). Nice art btw – Asone Tuhid Apr 21 '18 at 19:57
• @AsoneTuhid yes of-course, thanks a lot for this remarks. – mdahmoune Apr 21 '18 at 20:06
• Can you write a reference implementation which beats bzip2 and gzip, preferably by a few percent? – Peter Taylor Apr 25 '18 at 12:05

# 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"
> 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. – Akangka 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. – Akangka 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. – Akangka 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 – Akangka 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 – Akangka 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. – Akangka 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

# Output an alphabet suite

A successor to the ŋarâþ crîþ alphabet challenge.

Outputting the alphabet song with as few letters as possible was too easy, but what about outputting many of them?

Your challenge is to write as many programs as you can, with no two programs sharing any Unicode codepoints, and each program outputting the names of the letters of the alphabet (or the glyphs of some other kind of phonetic script) used by a different language. For instance, one program can output

a bee cee dee e eff gee aitch i jay kay el em en o pee cue ar ess tee u vee double-u ex wye zed


and another program can output

a be ce de e efe ge hache i jota ka ele eme ene eñe o pe cu erre ese te u uve uve doble equis ye zeta


Notes:

• For a given language, there will probably be some leeway in what you can output.
• Unlike in the previous challenge, you don't need to worry about any particular punctuation. You should at least separate each letter name with whitespace.
• You must output the names of the letters, not the letters themselves (so A B C... is invalid), unless the letters are literally pronounced so in the language in question.
• If a language uses both capital and lowercase letters, then you may output the letter names in either case. If it uses only one of them, then you must output the alphabet in that case.
• You must use a different language's alphabet for each program, but you are allowed to use the same script in the context of different languages.
• Constructed languages are allowed, as long as they predate the challenge.
• You may use different programming languages for each program. Or the same.
• Standard loopholes are forbidden.

TODO:

• is the requirement against sharing any codepoints too strict?
• I haven't downvoted you, but suspect that the major reason that you're getting downvoted is that it's totally unclear what outputs are valid or not, and skimming the edges of that is where most of the byte savings are going to come from in a code-golf. That said, I don't think this is code golf, despite having the tag. You'll probably find that, when any golfing aspect is removed, the strings to print are more or less irrelevant, so you might as well use a fixed, objective set of strings instead of the ones you have. – ais523's temporary account May 13 '19 at 16:24

# Count the Trees

## Challenge

Given an input consisting of ASCII art of trees such as

  0            <
|      >       @
|   @          |    0
|   |    #     |    |
|   |    |     |    |
==========================


count the number of trees present (5 in this case).

## Rules

### Input

• The input might not have all lines at the same length.
• You can take your input from stdin or take it as a string argument.
• There will be a ground as the last line, consisting of = characters.
• All trees have a straight trunk of | characters.
• The crown of the tree can be one of 0@#.
• Each tree will have at least one trunk character.
• You may assume that there is at least one tree.
• Unfortunately, there might be birds (< and >) photobombing the ASCII art. They should be ignored.
• If you find a bird on the ground, then it is dead and another tree will grow in its place tomorrow (carcasses make great fertiliser). In the ASCII art below, there will be two trees tomorrow:
   #
|   <
=========


### Output

• Output the number of trees that are present today and those that will be present tomorrow.

### Test cases

  0            <
|      >       @
|   @          |    0
|   |    #     |    |
|   |    |     |    |
==========================


(5, 5)

   #
|   <
=========


(1, 2)

 0#@
|||
|||
=====


(3, 3)

• What about languages that can't handle input over multiple lines? Can the input be taken as a list of strings? Or a single string with \n as separators? Also, the task is basically just counting all non-space characters on the second line from the bottom. The birds in the air, different crowns etc. won't affect the answers in any way. MATLAB: @(s)nnz(s(2,:)-32). – Stewie Griffin May 23 '19 at 10:16
• A single string should be fine; a list is not acceptable. And thanks for pointing out the shortcut. Maybe it would be better to require validation? – bb94 May 24 '19 at 15:50

The heights of Natural Numbers

Every number can be expressed as the product of itself and/or smaller numbers. This is a fundamental feature of our world.

For example 10 can be expressed as the product of 5 and 2, or as the product of 1 and 10.

9 can be expressed as the product of 3 and 3, or 1 and 9.

12 can be expressed as the product of 2 and 6. 6, in turn, can be expressed as the product of 2 and 3. It could also be the product of 3 and 4, and in turn 4 is the product of 2 and 2. Lastly there is 1 and 12.

7 can only be expressed as the product 1 and itself.

The numbers in the products are called factors. Every number has at least 2 factors, itself and 1. Numbers with only those two factors are called prime. Numbers with more than 2 are called composite.

These factors can be written as trees. The root begins with the number itself, and factors are written below, by adding branches to the root.

7 has 1 and 7. This is a short tree. It has one prime.

9 has 3 and 3. This is also a short tree, but it has two branches. It has two primes, but they are both at depth of 1 down the tree.

10 has 5 and 2. Again, short. Again, primes are at depth 1.

12 has 6 and 2, 6 has 3 and 2. This tree has two levels of height. Note that at the second level, every factor is prime, but at the first level, some factors are composite. 12 has also 3 and 4, and 4 becomes 2 and 2 - the tree looks similar to when using 6 and 2, this is called Isomorphic, which comes from the Greek language words for same shape.

In other words, every number has several trees of factors, and each tree has leaves that are prime factors. And every tree has a height, the number of branches one must travel between the root and the furthest leaf.

For example, every number has a tree of height 1. Itself and 1. So.

7 has height 1, because 1x7=7

9 also is height 1, because 3x3=9, and 1x9=9, are both of height 1.

12 is height 2. 3x2x2 becomes 3x4, which becomes 12. There are two branches between 12 and either leaf of 2.

But 12 is also height 1 because it has a different tree of height 1: 1x12=12.

16 is height 3, because 16 becomes 2*8 becomes 2*2*4, becomes 2*2*2*2. But 16 is also depth 1 because 1x16=16. However 16 is not depth 2, because no tree of it's factors has primes up two branches from the root.

Write a program that given an integer n, returns a sequence of the first 100 numbers that have prime factor trees of height n.

• The prologue about factors and primes is unnecessary-- we know what they are. A diagram would be nice. You didn't explicitly mention the rules for creating trees-- why can't 16 = 4x4 = (2x2)x(2x2), or 16 = 8x2 = (8x1)x2? Are depth and height the same? – lirtosiast Jun 29 '19 at 7:12

# Best Mile Time

## Introduction

Your friend has been trying to improve his mile time on. Unfortunately, he isn't very good at keeping a steady pace and constantly speeds up and then slows down. He usually runs for many miles at a time and wants to choose the fastest mile of his run to determine his mile time.

Given your friend's distance versus time, determine his fastest mile time for a contiguous mile stretch.

## Input

A list of distances (in miles) sampled at an even interval.

## Output

The length of the smallest interval during which a distance of at least one mile was traveled.

## Rules

• You may assume that the the total distance traveled is at least 1 mile.
• The mile time must be for a continuous time interval.
• Standard loop-holes are forbidden.
• Standard rules apply.
• This is , so the program with the smallest asymptotic time complexity wins!
• Ties will be broken by fastest run time.

## Example

### Python 3.7, O(n ^ 2)

Try it online!

from typing import List

def fastest_mile_time(distances):
"""Determines the fastest mile time from a list of distances.

Parameters
----------
distances : List[float]
The list of distances in miles.

Returns
-------
int
The length of the smallest interval during which at least one mile was traveled.
"""
intervals = []
for i in range(len(distances) - 1):
for j in range(i + 1, len(distances)):
if distances[j] - distances[i] >= 1:
intervals.append((i, j))
break

return min(map(lambda x: x[1] - x[0], intervals))

• @FryAmTheEggman how's this? – Billylegota Jul 19 '19 at 2:32
• Unless I'm missing something this is trivially O(n): keep two pointers into the list, advance them keeping them 1 mile apart, and keep track of the running minimum time. I'm downvoting, so ping me if I was mistaken or if this is updated so I can update my vote. – lirtosiast Jul 19 '19 at 2:52
• @lirtosiast O(n) is trivial. I just gave O(n ^ 2) as an example. However it isn't clear to me that O(n) is the lower bound. I think the fact that the sequence is monotonically increasing may be of some use (although I've yet to show that to be the case). – Billylegota Jul 19 '19 at 3:20
• The optimal solution is O(n). You need to iterate two pointers through the entire list one time to ensure that you have found the minimum valid difference. The range of time this will take ranges from Ω(n) to O(2n) in the optimized case. for(i=j=0;j<length;i++){for(;array[j]-array[i]<1&&j<length;j++){}minTime=min(minTime , j-i)} – fəˈnɛtɪk Jul 20 '19 at 17:00
• Consider a list where every element at even index 2n is n, and every element at index 2n+1 is either n+.5 or n+1. If there is an integer at an odd index, the fastest mile time is 1, otherwise it's 2. But we have no way of determining this without reading all n/2 odd indices. – lirtosiast Jul 20 '19 at 18:17
• @lirtosiast +1 thanks for such a clear example! – Billylegota Jul 21 '19 at 6:16

## Produce a self-reproducing data structure

Write the shortest code to produce a self-reproducing list, dictionary, array, and so on and so forth. That is, when you index any one of the logically-available items that belongs to the resulting data structure that you have produced, you get the same data structure when you compare the equality between the data structure before you indexed and the data structure after you indexed.

• In order to verify your code with automatically-provided constructions in programming languages, you should pick an operator that compares whether two values are equal (or does type-comparisons, if available).
• If your language does not provide an equality operator, you should simulate an equality operator yourself using operators like - or other operators that do the job of comparing values (as in Acc!, where an explicit comparison operator is not provided.)

## Example

This is an example of a validity/equality test of a possible solution in a Python REPL (when you have already produced a list, namely list, where it produces itself at its 0th item). This test simply compares the equality between the non-indexed list and the indexed list:

>>> list
[[...]]
>>> list[0]
[[...]]
>>> list==list[0]
True


However, if the result of the last line (the equality comparison) is not a truthy value in your language (for example False and 0 in Python), then your answer is invalid and should be improved.

## Rules

• Your program does not have to take input; neither does it have to explicitly output the data structure. However, your resulting data structure has to be accessible in some way.
• This is a contest; the shortest answer will win.
• In this challenge, the values on both operands in the equality check should have the same type.
• Your code (both your testing code and your producing code) should not produce any errors; any outputs to stderr are considered non-truthy values and demonstrates that your code is invalid.
• What does "compare it" mean? There are many many types of comparison one can perform, and they don't necessarily give the same result for the same values. – Peter Taylor Jul 24 '19 at 7:11
• @A__ For JavaScript, is it == or ===? Either way, people will be angry. – wizzwizz4 Jul 24 '19 at 13:16
• @A__ Because either the challenge is trivial (['']) or you're arbitrarily restricting a language. Work on your definition of "equality operator". – wizzwizz4 Jul 24 '19 at 13:46
• @A__ So, basically, you want (x=[])[0]=x? No clever tricks? Just a bog-standard recursive data structure? (Though, it might be interesting in languages where those aren't allowed.) – wizzwizz4 Jul 24 '19 at 14:07
• @wizzwizz4 In fact, your program is a clever trick that I have not thought of. Mine is 13 bytes, yours is 11 bytes. Yes, what I want is a bog-standard recursive data structure, as long as it is not a duplicate of another question. (My program is a=[];a.push(a)) – a'_' Jul 24 '19 at 14:10
• @U10-Forward 0 bytes – tjjfvi Jul 24 '19 at 14:32
• @tjjfvi I thought about that one, but I didn't think it'd be syntactically valid. It does, however, work. – wizzwizz4 Jul 24 '19 at 15:19
• @wizzwizz4 How do you know which language? – tjjfvi Jul 24 '19 at 15:31
• @tjjfvi I just assumed it was a language where the "null" / "undefined" singleton was indexable, returning the very same value. – wizzwizz4 Jul 24 '19 at 15:34
• @wizzwizz4 No, JS: window.window === window :) – tjjfvi Jul 24 '19 at 15:38
• @tjjfvi I read the challenge differently to you. I thought it meant "any one of the logically-available items". By this rule, (x={}).x=x is the shortest I can think of, other than the trivial case. – wizzwizz4 Jul 24 '19 at 15:53
• @tjjfvi Well i do it in Python so no such a thing called 0 bytes in python – U10-Forward Jul 25 '19 at 1:08
• Alternative: window["window"]===window – a'_' Jul 25 '19 at 4:06