459
\$\begingroup\$

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.

The Sandbox works best if you sort posts by "active".

Add Proposal

Search the Sandbox

Browse your pending proposals

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]

\$\endgroup\$
  • \$\begingroup\$ How are tags added to questions? \$\endgroup\$ – guest271314 Jan 9 at 7:51
  • \$\begingroup\$ @guest271314 You can use this markup to create a tag in a draft: [tag:code-golf] \$\endgroup\$ – DJMcMayhem Aug 29 at 15:19
  • \$\begingroup\$ Why no featured anymore? Can't we have it auto-added or something? \$\endgroup\$ – JL2210 Sep 26 at 15:57
  • 1
    \$\begingroup\$ @JL2210 We now have a permanent info box that links to the Sandbox, so the featured tag isn't necessary \$\endgroup\$ – caird coinheringaahing Sep 29 at 13:43
  • \$\begingroup\$ I think the sentence 'replace the post here with a link to the challenge and delete it' may specify that the deletion should be done immediately . \$\endgroup\$ – AZTECCO Oct 5 at 19:39

2566 Answers 2566

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

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.
\$\endgroup\$
  • \$\begingroup\$ need some comments for down-vote... \$\endgroup\$ – mdahmoune Apr 20 '18 at 19:01
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – Jonathan Frech Apr 20 '18 at 19:34
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – BradC Apr 20 '18 at 20:59
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – Jonathan Frech Apr 20 '18 at 22:01
  • \$\begingroup\$ I don't think this is anyhow related to math. Only "inspired by math", maybe. \$\endgroup\$ – user202729 Apr 21 '18 at 10:54
  • \$\begingroup\$ 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"? \$\endgroup\$ – user202729 Apr 21 '18 at 10:55
  • \$\begingroup\$ @user202729 No, there is no predefined specific pattern, I prepared this MANUALLY. How could I specify that in the challenge? \$\endgroup\$ – mdahmoune Apr 21 '18 at 11:00
  • \$\begingroup\$ I believe it's customary to specify if trailing spaces / new lines are permitted and if so, how many \$\endgroup\$ – Asone Tuhid Apr 21 '18 at 19:30
  • \$\begingroup\$ @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? \$\endgroup\$ – mdahmoune Apr 21 '18 at 19:54
  • \$\begingroup\$ Not between the lines, of course. I mean new lines after the whole drawing. Some people put restrictions (none, one, whatever). Nice art btw \$\endgroup\$ – Asone Tuhid Apr 21 '18 at 19:57
  • \$\begingroup\$ @AsoneTuhid yes of-course, thanks a lot for this remarks. \$\endgroup\$ – mdahmoune Apr 21 '18 at 20:06
  • \$\begingroup\$ Can you write a reference implementation which beats bzip2 and gzip, preferably by a few percent? \$\endgroup\$ – Peter Taylor Apr 25 '18 at 12:05
-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\$
  • \$\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\$ – HyperNeutrino May 2 '18 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\$ – HyperNeutrino May 2 '18 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\$ – Peter Taylor May 2 '18 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\$
  • \$\begingroup\$ Any reason why full programs are not allowed? \$\endgroup\$ – user202729 May 2 '18 at 9:29
  • \$\begingroup\$ What happens if the language is not compiled? \$\endgroup\$ – user202729 May 2 '18 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\$ – user202729 May 2 '18 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 '18 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\$ – Kevin Cruijssen May 2 '18 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 '18 at 10:08
  • \$\begingroup\$ @Angs dependent typing. In fact, this challenge is about dependent typing. \$\endgroup\$ – Akangka May 2 '18 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\$ – Akangka May 2 '18 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\$ – Akangka May 2 '18 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\$ – Akangka May 2 '18 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 '18 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\$ – user202729 May 3 '18 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\$ – Akangka May 3 '18 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 '18 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\$ – Akangka May 3 '18 at 6:50
-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\$
  • \$\begingroup\$ Related: codegolf.stackexchange.com/questions/66276/quat-quine-cat \$\endgroup\$ – Beefster Jun 1 '18 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 '18 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 '18 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\$
  • \$\begingroup\$ @AdmBorkBork : So i should put nothing ? \$\endgroup\$ – Muhammad Salman Jun 1 '18 at 14:59
  • \$\begingroup\$ @AdmBorkBork : Thanks, done. \$\endgroup\$ – Muhammad Salman Jun 1 '18 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\$ – Kamil Drakari Jun 1 '18 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\$ – Kamil Drakari Jun 1 '18 at 15:09
  • \$\begingroup\$ @KamilDrakari : Changed. Hopefully better \$\endgroup\$ – Muhammad Salman Jun 1 '18 at 15:09
  • \$\begingroup\$ @KamilDrakari : I think I will put that as something I would like to know (reasons why this is sandboxed)\ \$\endgroup\$ – Muhammad Salman Jun 1 '18 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\$ – Kamil Drakari Jun 1 '18 at 15:32
  • \$\begingroup\$ @KamilDrakari : Okay \$\endgroup\$ – Muhammad Salman Jun 1 '18 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 '18 at 18:58
  • \$\begingroup\$ @wastl : undefined behaviour is ok. \$\endgroup\$ – Muhammad Salman Jun 1 '18 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\$ – Rɪᴋᴇʀ Jun 1 '18 at 22:37
  • \$\begingroup\$ 1. Hopefully done, 2. done, 3. Ok, 2 votes for not having comments. \$\endgroup\$ – Muhammad Salman Jun 2 '18 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 Jun 4 '18 at 2:11
  • \$\begingroup\$ @JoKing : yes, you can \$\endgroup\$ – Muhammad Salman Jun 4 '18 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\$
  • 1
    \$\begingroup\$ Actually we have no standard rule for code-bowling to prevent unused code. \$\endgroup\$ – user202729 Jul 5 '18 at 9:52
  • \$\begingroup\$ (although for this particular challenge, it's not possible to make program arbitrarily long) \$\endgroup\$ – user202729 Jul 5 '18 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 Jul 5 '18 at 10:34
  • \$\begingroup\$ @JoKing Your solution seems to break the "no rubbish rule" \$\endgroup\$ – l4m2 Jul 6 '18 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 Jul 6 '18 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 Jul 7 '18 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\$ – Nathaniel Jul 7 '18 at 4:28
  • 3
    \$\begingroup\$ The "unused code" test is unlikely to be practical for programs longer than about 100 characters. \$\endgroup\$ – Peter Taylor Jul 7 '18 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\$
  • \$\begingroup\$ Actually I think there are just 12 dimensions. \$\endgroup\$ – user202729 Jul 12 '18 at 14:55
  • \$\begingroup\$ @user202729 More dimensions exist and you can use them, but they are initally empty \$\endgroup\$ – l4m2 Jul 12 '18 at 14:59
  • 5
    \$\begingroup\$ What does it mean to sort an infinite-dimension cube? Currently this very unclear. \$\endgroup\$ – Laikoni Jul 13 '18 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 '18 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 Jul 15 '18 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\$ – user202729 Jul 19 '18 at 14:35
  • \$\begingroup\$ @Laikoni Better now? \$\endgroup\$ – user202729 Jul 19 '18 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\$
  • 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 '18 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\$ – user202729 Jul 28 '18 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\$ – user202729 Jul 28 '18 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 '18 at 15:21
  • \$\begingroup\$ @OMᗺ Just saying...... // For the first comment, typically the answerer just specify the regex flavor in the answer. \$\endgroup\$ – user202729 Jul 28 '18 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\$ – user202729 Aug 1 '18 at 2:49
-2
\$\begingroup\$

Largest and Smallest Numbers Printable

Related: Largest Number Printable

Your goal is to write code that produces a large number. However, when your code is reversed, you must output a small number.

Rules

  • No constants over 10 (like the other challenge)
  • No numeric literals
  • No infinite numbers
  • Each program can only output one number
  • You must have at least two bytes in your program.
  • Your small number must be less than your large number.

Scoring:

Your score is: \$\frac{code~length}{N_{large} - N_{small}}\$. Smallest score wins.

\$\endgroup\$
  • \$\begingroup\$ Ban numeric literals. having the code of n 9's and n 0's in a golving language with auto output results in having a score of \$\frac{2n}{(10^n-1)^2}\$ which will go to 0 for arbitrary large n \$\endgroup\$ – Kroppeb Aug 25 '18 at 11:26
  • \$\begingroup\$ Even with "no constant over 10" the strategy above will still works in languages such as cat. \$\endgroup\$ – user202729 Aug 25 '18 at 14:16
  • \$\begingroup\$ @kroppeb that's interesting, thanks. \$\endgroup\$ – NoOneIsHere Aug 25 '18 at 14:49
  • \$\begingroup\$ Like the other challenge I'd suggest a maximum code length and putting a higher penalty on code length. Also, are we allowed to print negative numbers? \$\endgroup\$ – Jo King Aug 28 '18 at 6:14
-2
\$\begingroup\$

The Tiniest Generic Evolutionary AI



Introduction

The smallest program you can make (measured in bytes) that builds evolving AIs that parses unknown text string A into unknown text string B that still evolves.

All languages are options. Internet connectivity is allowed (but not providing any specific links). The AI must have a choice of commands (allowing variables) from a Turing Complete instruction set.


Scoring

Scoring is two fold: N = Number of bytes of program (ignoring size of AIs generated)

T = The average generations (generations of 200 AIs or less) before your program can evolve an AI that can do the 5 test cases.

Score = 1000/(N*T)


Challenge

Rules: Using the fewest bytes possible, create a generic evolutionary AI that will evolve to parse one supplied but previously unknown string into another supplied but previously unknown string.

What qualifies as an evolutionary AI in this context:

Your Code
Takes an input string
Takes a seed AI Instruction Set(s)
Runs AI Instruction Sets
Rates Each AI Instruction Set against others and against test strings
Evolves AI to create a new set of AI Instruction Set(s) through random mutation and breeding of existing AIs.
=================
AI Code
Is not written by you (except for possibly a seed AI), to be created by your program instead.
Uses a set of *available* instructions that are or are inspired by a known Turing complete instruction set (such as RISC)
Should consist of references to the available instructions and values for them.
  1. The code you write does not parse the strings directly. Instead, it writes output that is a collection of instructions, and reads in a collection of instructions and applies these instructions. (Ugly as it may be, eval is allowed).

  2. It reads in multiple optional instruction sets.

  3. It rates those instruction sets based on which gets closest to parsing the input string into the target string.

  4. The best performing instructions sets are encouraged in some way.

  5. The worst performing instruction sets are discouraged and/or eliminated in some way.

  6. Using existing AI-oriented libraries is discouraged.

  7. Allowing evolutionary AIs to use develop using a turing-complete set of instructions is encouraged. (Example solution uses a modified RISC instruction set.)

  8. Instruction sets must be able to mutate (randomly change) between generations. They are allowed to breed (selectively change) between generations as well.

  9. Multiple iterations of comparing and evolving instructions sets is possible.

  10. How quickly your AIs evolve or how well they do the job doesn't matter so much as they can get better at the task over iterations.

  11. A seed starting instruction set is allowed. If your solution requires an inputed file for an initial instruction set, a functional example is required and counts towards the byte count.

  12. It handles if an instruction set it runs fails to complete, or times out if an AI instruction set goes on too long (default to 30 seconds).

  13. Program must accept in one arbitrary string from a source. (Your choice of a generic commonly used source, such as a web form, command line, or file). It outputs each AI instruction set's result in a similar format it took them in. It may also optionally accept a starter AI set of instructions.

  14. The AI code never gets to interact with the test string it's being graded against.

  15. Your program cannot do any string conversions on the input string on its own, only may act as it's instructed to by the AI.

  16. A seed AI is not allowed to have anything more than a start, end, or return call of some kind (it must evolve any processing steps on its own).


Test Cases:

Can the program evolve an AI that approaches being capable of string conversion of an unknown conversion? (It is recommended not to build the AI to these specific test cases, these are for the point of testing genericness. Do not specifically target these cases until reporting results, and others testing your program may test them against other string conversions and rate accordingly.)

Five examples follow -

abcdefghijklmnopqrstuvwxyz

will be converted into

zyxwvutsrqponmlkjihgfedcba

or possibly

1010101100110101011001

will be converted into

0101010011001010100110

or possibly

"Mary had a little lamb."

will be converted into

"Gary had a little ham."

or possibly

"Banana"

will be converted to

"Banananananananananananananananana."

Or maybe

The entire text of the Bible

will be converted to

The entire text of the Bible, but every instance of "sheep" is replaced with "codfish".


Short Diagram of interaction.

   STEP 1                         STEP 2                     STEP 3  ...

 Input String           ->
 Expected Output String ->   Your Code Starts  ->    Assorted AI Instruction sets. ->      ->        ->       ->      Your Code Processes AI Instruction Sets -> Your code compares, mutates, and breeds AIs to create new generation -> Return to Step 3
 Seed AI                ->                     (Example: AI1 -> Start(Input); Output(Input)
                                                         AI2 -> Start(Input); CP(Mem1, Mem2); Output (Mem2);)

Example

An on-a-whim project done that roughly followed these rules and inspired this challenge that ran <1000 lines of code (although short, it did not aim for minimal characters.)

myLittleAI

\$\endgroup\$
  • 1
    \$\begingroup\$ There are a lot of restrictions and rules, however there is no clear description of the task itself: What does "parse one string into another string" mean? About the rules: Overriding loop-holes such as allowing internet-connectivity is likely to create problems or allow boring answers. "Answer must evolve using options that are or are inspired by a Turing complete instruction set." seems like it's a non-observable requirement (and you override the rule in the second rule anyways). Why do you want to disallow libraries? \$\endgroup\$ – ბიმო Sep 22 '18 at 23:01
  • \$\begingroup\$ Some of the other rules don't make sense to me, but it's likely to be caused by me not being able to understand the challenge itself. \$\endgroup\$ – ბიმო Sep 22 '18 at 23:01
  • \$\begingroup\$ @BMO Reason to disallow libraries is that there are existing libraries that are AI libraries. Allowing them means you just call some monolithic AI library and you're done. I guess it'd make sense to just not allow AI libraries though? \$\endgroup\$ – liljoshu Sep 24 '18 at 15:57
  • \$\begingroup\$ Maybe disallowing AI-libraries could be a sensible idea, but I wouldn't know how to put this (ie. what is an AI-library and what is a regular library) formally. Though the standard (this does not mean that it's always the case or that you need to follow it) is to not disallow such things but rather discourage it. If I'd use a library which is not part of the standard libraries it would count as a different language, eg. Python 3 + scikit and in a perfect world less interesting submissions would be given less upvotes. \$\endgroup\$ – ბიმო Sep 24 '18 at 17:00
  • \$\begingroup\$ @BMO Rewrote it, does this look better? \$\endgroup\$ – liljoshu Sep 24 '18 at 18:29
  • \$\begingroup\$ I think the rules do look more structured and clean, but I still don't understand the challenge itself. Some questions I think the challenge should answer for which I can't find an answer might help: Are you requiring a program, function or a set of functions? What is the input and output format? What makes a solution valid? What is parsing string A to string B? \$\endgroup\$ – ბიმო Sep 24 '18 at 22:38
  • \$\begingroup\$ Also, keep in mind that golfed solutions might try to find some kind of weaknesses in your definitions to reduce the problem to the easiest way of solving it which might result in solutions that aren't very interesting from an AI perspective. This challenge might fit better test-battery (you can set a byte-limit motivated by your own code if you want). \$\endgroup\$ – ბიმო Sep 24 '18 at 22:43
  • \$\begingroup\$ There are 2 critical pieces to this challenge that need to be clear before we can really make this post: 1. What are "Instructions"? 2. When an InstructionSet applies a string, what feedback does the AI get? \$\endgroup\$ – Nathan Merrill Sep 25 '18 at 16:37
  • 1
    \$\begingroup\$ Finally, realize that rule #10 simply means I can iterate over every possible program until I land on one that works, no AI needed. \$\endgroup\$ – Nathan Merrill Sep 25 '18 at 16:40
  • \$\begingroup\$ @NathanMerrill Did some clarifying randomness... better? \$\endgroup\$ – liljoshu Sep 27 '18 at 18:49
  • \$\begingroup\$ Not really. Let's chat \$\endgroup\$ – Nathan Merrill Sep 27 '18 at 19:10
-2
\$\begingroup\$

Rotations Required

Given input 2 values:

\$x >= 0\$ :Distance to travel (float)

\$r>0\$ :Radius of wheel (float)

Output the number of rotations required by the wheel to travel that distance.

Constraints:

Your code must not contain any digits.

You cannot use pi functions (math.pi)

Output must be an integer.(In case exact int is not obtained, floor it) 1.0 is not a valid output, it should be 1.

Test Cases

x       r    o/p
50      1    7
0       34   0
50      0.3  26
44      33   0
5.5     5.5  0
105     5    3
155     5    4
6.28318 1    1 #This signifies that pi was approximated to 3.1419

Scoring:

Score= No. of bytes+20/number of digits taken for pi after decimal point

If you have taken more than 10 digits:

Score= No. of bytes

\$\endgroup\$
  • 3
    \$\begingroup\$ "You cannot use pi functions" is an unobservable requirement, which is not allowed. You need some test cases. The no-digits rule won't actually make this problem harder for most golflangs. \$\endgroup\$ – Nathan Merrill Oct 16 '18 at 12:43
  • \$\begingroup\$ @NathanMerrill The latter is less problematic (and more objective) than the former. \$\endgroup\$ – user202729 Oct 16 '18 at 14:21
  • \$\begingroup\$ Test cases are not strictly required, but it would make it easier to check if a solution is definitely incorrect. \$\endgroup\$ – user202729 Oct 16 '18 at 14:22
  • 3
    \$\begingroup\$ Info: Adding constraints just "because the challenge is too easy" usually doesn't make it more interesting (unless the constraints are the main difficulty of the challenge, for example for radiation-hardened challenges) \$\endgroup\$ – user202729 Oct 16 '18 at 14:24
  • \$\begingroup\$ I will add test cases. @NathanMerrill, there just shouldn't be any inbuilt functions that give pi directly is what I want to say. \$\endgroup\$ – Vedant Kandoi Oct 17 '18 at 5:35
  • \$\begingroup\$ @VedantKandoi I understand what you want, but we allow any language on this site, and it's impossible to define what a "pi-giving function" is to work for all possible languages. \$\endgroup\$ – Nathan Merrill Oct 17 '18 at 6:26
  • \$\begingroup\$ Is there any other way I could word it then, as I don't want python, java etc. users to use math.pi or should I just remove it? \$\endgroup\$ – Vedant Kandoi Oct 17 '18 at 7:15
  • \$\begingroup\$ Also, since pi is in the formula, exact int will never be obtained, and if anyone uses approximate value of pi, they may get exact int at certain value or 1 less than desired answer. What can I add for this? \$\endgroup\$ – Vedant Kandoi Oct 17 '18 at 7:48
  • \$\begingroup\$ I changed the scoring method for the above issue, so should be okay now. \$\endgroup\$ – Vedant Kandoi Oct 17 '18 at 8:15
  • \$\begingroup\$ Why would the output be floored? Surely you should use ceiling so that the wheel is actually travelling that distance. \$\endgroup\$ – Jo King Oct 17 '18 at 8:26
  • \$\begingroup\$ I was thinking of something like how many full rotations need to be completed. \$\endgroup\$ – Vedant Kandoi Oct 17 '18 at 8:31
  • 2
    \$\begingroup\$ "Not using a pi function" is a non-observable program requirement, which is one of the things to avoid when writing a challenge. I don't see any way to fix this challenge: fundamentally what it's asking is too trivial to be interesting. My advice would be to delete the body of this answer and then delete the answer (to keep the sandbox tidy) and then to try to come up with a challenge which is inherently interesting enough that it doesn't need that kind of restriction. \$\endgroup\$ – Peter Taylor Oct 17 '18 at 14:06
-2
\$\begingroup\$

Write a Self-Hosting Ouroboros: each quine produces the next quine AND its interpreter

My meta-questions, please give feedback and/or add your own:

  • Too elaborate or long post?
  • Rules too strict? Too lax?
  • Not having a deadline: good or bad idea?

A Quine is a program that prints its own source code as output when it is run.

A Self-Hosting Quine (which is something I just made up, although I'm sure it exists already) is a quine that also produces an interpreter/compiler/emulator/whatever for itself (from now on I will just say "interpreter").

I believe this actually means that a lot of essential functionality must be "circularly defined" - for example, to print output, the interpreter must rely on the parent interpreter's ability to print output. So maybe we should call this a Von Munchausen Quine?

An Ouroboros Program or Quine Relay is a quine that prints a different quine, which then prints yet another program, and so on, until the last quine produces the original quine. See this famous example that cycles through over a hundred languages.

A Self-Hosting Ouroboros, then, is quine that produces a program in another language, and also produces an interpreter for that language. The interpreter should be in the current language, so that the next quine can immediately be run and produce the quine after that.

Tangent: obviously, the idea can also be extended to interpreter multiquines but that can be another challenge. Let's make Von Munchausen's Ouroboros first!

Rules

  • The ouroboros must be able to make a complete cycle
  • Score by total quines in chain / shortest source code (in bytes) in the chain (bytes to allow non-textual outputs)
  • Empty quines and interpreters do not count - two character minimum
  • Code-golf languages allowed
  • No languages defined just for this challenge - no "I define language x to always produce quine y in C plus the complete GCC compiler when fed any input"-stuff please
  • Quines must be valid code in their programming languages
  • Interpreters that are partial language implementations are fine, however:
    • it must be able to run the quine, and produce the next quine (obviously).
    • it should be able to run any other correct code that is limited to the same language subset¹. No hyperfitting²!
    • for the sake of code golfing it may accept incorrect code that a normal interpreter should not (the quine is already restricted to correct code anyway)

Clarifications

Yes, you can make a quine that produces itself and its own interpreter

Counts as a 1-chain ouroboros.

What would an "interpreter" for machine code be?

An emulator. Which of course needs some way to load a program and produce the output. You may define a fictional simplified, minimal hardware set-up to do so. For example: a (partial) Z80 emulator where:

  • two hardware ports are connected to send output bytes to (one for interpreter, one for quine). Are those bytes interpreted as raw bytes/ASCI/UTF8 text/whatever? Up to you!
  • the program is already loaded in memory, at whatever address is most convenient (quine too big to fit in the addressable memory space? Define an input port to scan bytes from I guess :P)
  • the PC (program counter), and SP (stack pointer) registers initiate at whatever value is most convenient for creating a quine in Z80 opcode

Obviously, no set-ups with fictional ROM that just happens to contain a new quine, or stuff like that (even though this would be hard to really abuse, since that ROM would still need to be implemented in the emulator).

Am I seriously expecting anyone to create an emulator like this? No, but let's keep the possiblity open (some stack machines might be code golf-friendly enough for the challenge).

"Borrowing" snippets from each other is encouraged, but give accreditation and link to sources!

Because we all really just want to see how long this can get, no? Besides, whatever you take probably has to be heavily modified to fit it in your existing ouroboros chain anyway. Sharing is caring, and accreditation is the decent thing to do.

No dead-line, nor will a winner be selected. Just make as long a chain as possible.


¹ You wrote an interpreter for a subset of Rust, but it doesn't feature the borrow checker? That is fine long as:

  • it works with correct Rust code limited to the language subset
  • it works with the quine itself
  • the quine itself is correct rust code

² Example of what I do and do not consider hyperfitting: if your interpreter can deal with for(var i; i < 10; i++) { a[i] = i; } but crashes without the enclosing {} because it expects them to designate code blocks, that counts as a partial implementation. If var only expects i, or < only expects i and 10? Hyperfitting. If var only accepts single letter names, and < only expects variables on the left and literals on the right? Probably hyperfitting but debatable.

\$\endgroup\$
  • \$\begingroup\$ What would the interpreter of a program written in machine code be? \$\endgroup\$ – user202729 Oct 19 '18 at 15:14
  • \$\begingroup\$ How should we separate the quine output and the interpreter output? \$\endgroup\$ – Jo King Oct 21 '18 at 0:10
  • \$\begingroup\$ @user202729: an emulator \$\endgroup\$ – Job Oct 21 '18 at 13:01
  • \$\begingroup\$ @JoKing: hmm, good question. Two separate calls to whatever output method is chosen? (print or its equivalent) \$\endgroup\$ – Job Oct 21 '18 at 13:03
-2
\$\begingroup\$

Unicode encoder

Do Invent your own Unicode 7.0.0 encoding (as efficient as possible) with score 317754(the lowest possible score). Shortest encode+decode program win.

You can either write two programs doing encode and decode, or write one with argument/input method difference deciding whether it's encoding or decoding

As you may know, the Unicode standard has room for 1,114,111 code points, and each assigned code point represents a glyph (character, emoji, etc.).

Most code points are not yet assigned.

Current Unicode implementations take a lot of space to encode all possible code points (UTF-32 takes 4 bytes per code point, UTF-16: 2 to 4 bytes, UTF-8: 1 to 4 bytes, etc.)


Task
-

Today, your task is to implement your own Unicode implementation, with the following rules:

- Write an encoder and a decoder in any language of your choice
- The encoder's input is a list of code points (as integers) and it outputs a list of bytes (as integers) corresponding to your encoding.
- The decoder does the opposite (bytes => code points)
- Your implementation has to cover all Unicode 7.0.0 assigned code points
- It has to stay backwards-compatible with ASCII, i.e. encode Basic latin characters (U+0000-U+007F) on one byte, with 0 as most significant bit.
- Encode all the other assigned code points in any form and any number of bytes you want, as long as there is no ambiguity (i.e. two code points or group of code points can't have the same encoding and vice versa)
- Your implementation doesn't have to cover UTF-16 surrogates (code points U+D800-U+DFFF) nor private use areas (U+E000-U+F8FF, U+F0000-U+10FFFF)
- Your encoding must be context-independant (i.e. not rely on previously encoded characters) and does NOT require self-synchronization (i.e. each byte doesn't have to infer where it's located in the encoding of a code point, like in UTF-8).

To sum up, here are the blocks that you have to cover, in JSON:

[
  [0x0000,0x007F], // Basic Latin
  [0x0080,0x00FF], // Latin-1 Supplement
  [0x0100,0x017F], // Latin Extended-A
  [0x0180,0x024F], // Latin Extended-B
  [0x0250,0x02AF], // IPA Extensions
  [0x02B0,0x02FF], // Spacing Modifier Letters
  [0x0300,0x036F], // Combining Diacritical Marks
  [0x0370,0x03FF], // Greek and Coptic
  [0x0400,0x04FF], // Cyrillic
  [0x0500,0x052F], // Cyrillic Supplement
  [0x0530,0x058F], // Armenian
  [0x0590,0x05FF], // Hebrew
  [0x0600,0x06FF], // Arabic
  [0x0700,0x074F], // Syriac
  [0x0750,0x077F], // Arabic Supplement
  [0x0780,0x07BF], // Thaana
  [0x07C0,0x07FF], // NKo
  [0x0800,0x083F], // Samaritan
  [0x0840,0x085F], // Mandaic
  [0x08A0,0x08FF], // Arabic Extended-A
  [0x0900,0x097F], // Devanagari
  [0x0980,0x09FF], // Bengali
  [0x0A00,0x0A7F], // Gurmukhi
  [0x0A80,0x0AFF], // Gujarati
  [0x0B00,0x0B7F], // Oriya
  [0x0B80,0x0BFF], // Tamil
  [0x0C00,0x0C7F], // Telugu
  [0x0C80,0x0CFF], // Kannada
  [0x0D00,0x0D7F], // Malayalam
  [0x0D80,0x0DFF], // Sinhala
  [0x0E00,0x0E7F], // Thai
  [0x0E80,0x0EFF], // Lao
  [0x0F00,0x0FFF], // Tibetan
  [0x1000,0x109F], // Myanmar
  [0x10A0,0x10FF], // Georgian
  [0x1100,0x11FF], // Hangul Jamo
  [0x1200,0x137F], // Ethiopic
  [0x1380,0x139F], // Ethiopic Supplement
  [0x13A0,0x13FF], // Cherokee
  [0x1400,0x167F], // Unified Canadian Aboriginal Syllabics
  [0x1680,0x169F], // Ogham
  [0x16A0,0x16FF], // Runic
  [0x1700,0x171F], // Tagalog
  [0x1720,0x173F], // Hanunoo
  [0x1740,0x175F], // Buhid
  [0x1760,0x177F], // Tagbanwa
  [0x1780,0x17FF], // Khmer
  [0x1800,0x18AF], // Mongolian
  [0x18B0,0x18FF], // Unified Canadian Aboriginal Syllabics Extended
  [0x1900,0x194F], // Limbu
  [0x1950,0x197F], // Tai Le
  [0x1980,0x19DF], // New Tai Lue
  [0x19E0,0x19FF], // Khmer Symbols
  [0x1A00,0x1A1F], // Buginese
  [0x1A20,0x1AAF], // Tai Tham
  [0x1AB0,0x1AFF], // Combining Diacritical Marks Extended
  [0x1B00,0x1B7F], // Balinese
  [0x1B80,0x1BBF], // Sundanese
  [0x1BC0,0x1BFF], // Batak
  [0x1C00,0x1C4F], // Lepcha
  [0x1C50,0x1C7F], // Ol Chiki
  [0x1CC0,0x1CCF], // Sundanese Supplement
  [0x1CD0,0x1CFF], // Vedic Extensions
  [0x1D00,0x1D7F], // Phonetic Extensions
  [0x1D80,0x1DBF], // Phonetic Extensions Supplement
  [0x1DC0,0x1DFF], // Combining Diacritical Marks Supplement
  [0x1E00,0x1EFF], // Latin Extended Additional
  [0x1F00,0x1FFF], // Greek Extended
  [0x2000,0x206F], // General Punctuation
  [0x2070,0x209F], // Superscripts and Subscripts
  [0x20A0,0x20CF], // Currency Symbols
  [0x20D0,0x20FF], // Combining Diacritical Marks for Symbols
  [0x2100,0x214F], // Letterlike Symbols
  [0x2150,0x218F], // Number Forms
  [0x2190,0x21FF], // Arrows
  [0x2200,0x22FF], // Mathematical Operators
  [0x2300,0x23FF], // Miscellaneous Technical
  [0x2400,0x243F], // Control Pictures
  [0x2440,0x245F], // Optical Character Recognition
  [0x2460,0x24FF], // Enclosed Alphanumerics
  [0x2500,0x257F], // Box Drawing
  [0x2580,0x259F], // Block Elements
  [0x25A0,0x25FF], // Geometric Shapes
  [0x2600,0x26FF], // Miscellaneous Symbols
  [0x2700,0x27BF], // Dingbats
  [0x27C0,0x27EF], // Miscellaneous Mathematical Symbols-A
  [0x27F0,0x27FF], // Supplemental Arrows-A
  [0x2800,0x28FF], // Braille Patterns
  [0x2900,0x297F], // Supplemental Arrows-B
  [0x2980,0x29FF], // Miscellaneous Mathematical Symbols-B
  [0x2A00,0x2AFF], // Supplemental Mathematical Operators
  [0x2B00,0x2BFF], // Miscellaneous Symbols and Arrows
  [0x2C00,0x2C5F], // Glagolitic
  [0x2C60,0x2C7F], // Latin Extended-C
  [0x2C80,0x2CFF], // Coptic
  [0x2D00,0x2D2F], // Georgian Supplement
  [0x2D30,0x2D7F], // Tifinagh
  [0x2D80,0x2DDF], // Ethiopic Extended
  [0x2DE0,0x2DFF], // Cyrillic Extended-A
  [0x2E00,0x2E7F], // Supplemental Punctuation
  [0x2E80,0x2EFF], // CJK Radicals Supplement
  [0x2F00,0x2FDF], // Kangxi Radicals
  [0x2FF0,0x2FFF], // Ideographic Description Characters
  [0x3000,0x303F], // CJK Symbols and Punctuation
  [0x3040,0x309F], // Hiragana
  [0x30A0,0x30FF], // Katakana
  [0x3100,0x312F], // Bopomofo
  [0x3130,0x318F], // Hangul Compatibility Jamo
  [0x3190,0x319F], // Kanbun
  [0x31A0,0x31BF], // Bopomofo Extended
  [0x31C0,0x31EF], // CJK Strokes
  [0x31F0,0x31FF], // Katakana Phonetic Extensions
  [0x3200,0x32FF], // Enclosed CJK Letters and Months
  [0x3300,0x33FF], // CJK Compatibility
  [0x3400,0x4DBF], // CJK Unified Ideographs Extension A
  [0x4DC0,0x4DFF], // Yijing Hexagram Symbols
  [0x4E00,0x9FFF], // CJK Unified Ideographs
  [0xA000,0xA48F], // Yi Syllables
  [0xA490,0xA4CF], // Yi Radicals
  [0xA4D0,0xA4FF], // Lisu
  [0xA500,0xA63F], // Vai
  [0xA640,0xA69F], // Cyrillic Extended-B
  [0xA6A0,0xA6FF], // Bamum
  [0xA700,0xA71F], // Modifier Tone Letters
  [0xA720,0xA7FF], // Latin Extended-D
  [0xA800,0xA82F], // Syloti Nagri
  [0xA830,0xA83F], // Common Indic Number Forms
  [0xA840,0xA87F], // Phags-pa
  [0xA880,0xA8DF], // Saurashtra
  [0xA8E0,0xA8FF], // Devanagari Extended
  [0xA900,0xA92F], // Kayah Li
  [0xA930,0xA95F], // Rejang
  [0xA960,0xA97F], // Hangul Jamo Extended-A
  [0xA980,0xA9DF], // Javanese
  [0xA9E0,0xA9FF], // Myanmar Extended-B
  [0xAA00,0xAA5F], // Cham
  [0xAA60,0xAA7F], // Myanmar Extended-A
  [0xAA80,0xAADF], // Tai Viet
  [0xAAE0,0xAAFF], // Meetei Mayek Extensions
  [0xAB00,0xAB2F], // Ethiopic Extended-A
  [0xAB30,0xAB6F], // Latin Extended-E
  [0xABC0,0xABFF], // Meetei Mayek
  [0xAC00,0xD7AF], // Hangul Syllables
  [0xD7B0,0xD7FF], // Hangul Jamo Extended-B
  [0xF900,0xFAFF], // CJK Compatibility Ideographs
  [0xFB00,0xFB4F], // Alphabetic Presentation Forms
  [0xFB50,0xFDFF], // Arabic Presentation Forms-A
  [0xFE00,0xFE0F], // Variation Selectors
  [0xFE10,0xFE1F], // Vertical Forms
  [0xFE20,0xFE2F], // Combining Half Marks
  [0xFE30,0xFE4F], // CJK Compatibility Forms
  [0xFE50,0xFE6F], // Small Form Variants
  [0xFE70,0xFEFF], // Arabic Presentation Forms-B
  [0xFF00,0xFFEF], // Halfwidth and Fullwidth Forms
  [0xFFF0,0xFFFF], // Specials
  [0x10000,0x1007F], // Linear B Syllabary
  [0x10080,0x100FF], // Linear B Ideograms
  [0x10100,0x1013F], // Aegean Numbers
  [0x10140,0x1018F], // Ancient Greek Numbers
  [0x10190,0x101CF], // Ancient Symbols
  [0x101D0,0x101FF], // Phaistos Disc
  [0x10280,0x1029F], // Lycian
  [0x102A0,0x102DF], // Carian
  [0x102E0,0x102FF], // Coptic Epact Numbers
  [0x10300,0x1032F], // Old Italic
  [0x10330,0x1034F], // Gothic
  [0x10350,0x1037F], // Old Permic
  [0x10380,0x1039F], // Ugaritic
  [0x103A0,0x103DF], // Old Persian
  [0x10400,0x1044F], // Deseret
  [0x10450,0x1047F], // Shavian
  [0x10480,0x104AF], // Osmanya
  [0x10500,0x1052F], // Elbasan
  [0x10530,0x1056F], // Caucasian Albanian
  [0x10600,0x1077F], // Linear A
  [0x10800,0x1083F], // Cypriot Syllabary
  [0x10840,0x1085F], // Imperial Aramaic
  [0x10860,0x1087F], // Palmyrene
  [0x10880,0x108AF], // Nabataean
  [0x10900,0x1091F], // Phoenician
  [0x10920,0x1093F], // Lydian
  [0x10980,0x1099F], // Meroitic Hieroglyphs
  [0x109A0,0x109FF], // Meroitic Cursive
  [0x10A00,0x10A5F], // Kharoshthi
  [0x10A60,0x10A7F], // Old South Arabian
  [0x10A80,0x10A9F], // Old North Arabian
  [0x10AC0,0x10AFF], // Manichaean
  [0x10B00,0x10B3F], // Avestan
  [0x10B40,0x10B5F], // Inscriptional Parthian
  [0x10B60,0x10B7F], // Inscriptional Pahlavi
  [0x10B80,0x10BAF], // Psalter Pahlavi
  [0x10C00,0x10C4F], // Old Turkic
  [0x10E60,0x10E7F], // Rumi Numeral Symbols
  [0x11000,0x1107F], // Brahmi
  [0x11080,0x110CF], // Kaithi
  [0x110D0,0x110FF], // Sora Sompeng
  [0x11100,0x1114F], // Chakma
  [0x11150,0x1117F], // Mahajani
  [0x11180,0x111DF], // Sharada
  [0x111E0,0x111FF], // Sinhala Archaic Numbers
  [0x11200,0x1124F], // Khojki
  [0x112B0,0x112FF], // Khudawadi
  [0x11300,0x1137F], // Grantha
  [0x11480,0x114DF], // Tirhuta
  [0x11580,0x115FF], // Siddham
  [0x11600,0x1165F], // Modi
  [0x11680,0x116CF], // Takri
  [0x118A0,0x118FF], // Warang Citi
  [0x11AC0,0x11AFF], // Pau Cin Hau
  [0x12000,0x123FF], // Cuneiform
  [0x12400,0x1247F], // Cuneiform Numbers and Punctuation
  [0x13000,0x1342F], // Egyptian Hieroglyphs
  [0x16800,0x16A3F], // Bamum Supplement
  [0x16A40,0x16A6F], // Mro
  [0x16AD0,0x16AFF], // Bassa Vah
  [0x16B00,0x16B8F], // Pahawh Hmong
  [0x16F00,0x16F9F], // Miao
  [0x1B000,0x1B0FF], // Kana Supplement
  [0x1BC00,0x1BC9F], // Duployan
  [0x1BCA0,0x1BCAF], // Shorthand Format Controls
  [0x1D000,0x1D0FF], // Byzantine Musical Symbols
  [0x1D100,0x1D1FF], // Musical Symbols
  [0x1D200,0x1D24F], // Ancient Greek Musical Notation
  [0x1D300,0x1D35F], // Tai Xuan Jing Symbols
  [0x1D360,0x1D37F], // Counting Rod Numerals
  [0x1D400,0x1D7FF], // Mathematical Alphanumeric Symbols
  [0x1E800,0x1E8DF], // Mende Kikakui
  [0x1EE00,0x1EEFF], // Arabic Mathematical Alphabetic Symbols
  [0x1F000,0x1F02F], // Mahjong Tiles
  [0x1F030,0x1F09F], // Domino Tiles
  [0x1F0A0,0x1F0FF], // Playing Cards
  [0x1F100,0x1F1FF], // Enclosed Alphanumeric Supplement
  [0x1F200,0x1F2FF], // Enclosed Ideographic Supplement
  [0x1F300,0x1F5FF], // Miscellaneous Symbols and Pictographs
  [0x1F600,0x1F64F], // Emoticons
  [0x1F650,0x1F67F], // Ornamental Dingbats
  [0x1F680,0x1F6FF], // Transport and Map Symbols
  [0x1F700,0x1F77F], // Alchemical Symbols
  [0x1F780,0x1F7FF], // Geometric Shapes Extended
  [0x1F800,0x1F8FF], // Supplemental Arrows-C
  [0x20000,0x2A6DF], // CJK Unified Ideographs Extension B
  [0x2A700,0x2B73F], // CJK Unified Ideographs Extension C
  [0x2B740,0x2B81F], // CJK Unified Ideographs Extension D
  [0x2F800,0x2FA1F], // CJK Compatibility Ideographs Supplement
  [0xE0000,0xE007F], // Tags
  [0xE0100,0xE01EF]  // Variation Selectors Supplement
]

Total: 116,816 code points.

Scoring
--

Your score is the number of bytes that your encoder outputs when you feed it with all the 116,816 possible code points (in one time or separately).

\$\endgroup\$
  • \$\begingroup\$ I suppose 317754 is the optimal score, right? \$\endgroup\$ – user202729 Oct 22 '18 at 9:37
  • \$\begingroup\$ @user202729 Yes if there are 116,816 code points \$\endgroup\$ – l4m2 Oct 22 '18 at 9:38
  • 1
    \$\begingroup\$ p.s. I think you should expand it while it is on the sandbox, just in case somebody don't understand the specification. \$\endgroup\$ – user202729 Oct 22 '18 at 9:38
-2
\$\begingroup\$

Forcing a kernel panic from a mountaintop

This is a thought resulting from a curious incident where C# code opening file apparently caused a BSOD. In the conclusion, it was due to a faulty driver, but from that a thought came up --- can one cause a kernel panic (or BSOD) using managed code exclusively?

Why?

Typically in such environment, there are many compile-time and run-time checks that safeguard the code from doing something that would cause a kernel panic. For a mature managed environment, it should be impossible to cause the operating system to arrive into a bad state. In the case, though it was C# code, the fact that a faulty driver was involved breached the walled garden. But can we breach it from within?

Rules

  • The code must be managed in some fashion (e.g. Java, C#, VB.NET), and normally comes with both compile-time and run-time checks.
  • The code should be running in a virtual machine or equivalent. (e.g. Java's JVM or .NET's AppDomain)
  • The code should NOT rely on any external anything. No extern declarations, no networking, no dodgy APIs.
  • The code should NOT use any construct which allow direct access to resources (e.g. unsafe in C#)
  • The code should use only the native libraries & API available as part of its usual environment.
  • Throwing an exception is not sufficient. To qualify, the code must result in a kernel panic.

Criteria

Essentially a code-golf -

  • The less code to kernel panic, the better
  • The fewer dependencies the code uses to make it happen, the better
  • The code that consistently causes a kernel panic is better than one that only does it sometimes
\$\endgroup\$
  • 2
    \$\begingroup\$ Is the code considered malicious code? \$\endgroup\$ – user202729 Nov 10 '18 at 15:26
  • \$\begingroup\$ What is "managed code"? \$\endgroup\$ – user202729 Nov 10 '18 at 15:26
  • \$\begingroup\$ While it can be used with malicious intent, the goal is more toward proving whether it's possible to unintentionally break through the walled garden. RE: "managed code" --- it might be a .NET-specific term but I use it in general sense to refer to any programming language that usually run in a some kind of sandbox -- I cited Java's JVM or .NET's AppDomain as such examples. Those usually enforce runtime checks in addition to compile-time checks to prevent doing stupid thing like passing a null pointer which usually is a trappable exception. \$\endgroup\$ – this Nov 10 '18 at 19:06
-2
\$\begingroup\$

Integer or decimal to array and array to decimal or integer

Task

Write two functions

1) Convert an integer or decimal to array of integers that potentially includes a single decimal

2) Convert array including integers and potentially a single decimal to integer or decimal

Input

Integer or decimal to array

  • An integer or decimal

Array to integer or decimal

  • An array

Output

Integer or decimal to array

  • An array containing each digit of the input at an individual index with the first decimal portion of input containing the decimal character.

Array to integer or decimal

  • An integer or decimal equal to input

Specification

When the first digit of a decimal is a 0 , and a digit follows, that value includes all 0's up to and including the last digit of that decimal, else the decimal portion is spread or expanded to the remainder of the decimal portion for the remainder of indexes of the array, that is: -0.01 <-> [-0.01], 100.01 <-> [1,0,0,0.01], 100.0001 <-> [1,0,0,0.0001]

Test cases

Input <----------> Output

-123               [-1,-2,-3]
4.4                [4,0.4]
44.44              [4,4,0.4,4]
-0.01              [-0.01]
123                [1,2,3]
200                [2,0,0]
2.718281828459     [2,0.7,1,8,2,8,1,8,2,8,4,5,8,9]
321.7000000001     [3,2,1,0.7,0,0,0,0,0,0,0,0,1]
809.56             [8,0,9,0.5,6]
1.61803398874989   [1,0.6,1,8,0,3,3,9,8,8,7,4,9,8,9]
1.999              [1,0.9,9,9]
100.01             [1,0,0,0.01]
545454.45          [5,4,5,4,5,4,0.4,5]
-7                 [-7]
-83.782            [-8,-3,-0.7,-8,-2]
1.5                [1,0.5]
100.0001           [1,0,0,0.0001]

Winning criteria

Least amount of total (each of function or programs 1 and 2) bytes used.

code-golf

\$\endgroup\$
  • \$\begingroup\$ 1) What should output be for test cases 0, 200, and 1.0015? 2) I would suggest a more descriptive title. 3) Bonuses are generally discouraged in code golf, so make sure they add something to this challenge. \$\endgroup\$ – lirtosiast Dec 18 '18 at 23:43
  • 1
    \$\begingroup\$ The string method thing is very iffy. Won't a print function in any language be converting a number/list of numbers to a string? \$\endgroup\$ – Jo King Dec 19 '18 at 0:16
  • \$\begingroup\$ @lirtosiast [0], [200], [1,0.001,5]. What title do you suggest? Not using string methods does add something to the challenge. \$\endgroup\$ – guest271314 Dec 19 '18 at 0:47
  • \$\begingroup\$ @JoKing Not sure what you mean by a print function converting a number or list to a string? If JavaScript is used it means not using ``, '', String, template literal, RegExp.prototype.match(), etc. to create or convert the input to output or add, subtract, divide, multiply, manipulate arrays are what is meant, not print(output) or console.log(output). A user is not obligated to try for the bonus in their answer. \$\endgroup\$ – guest271314 Dec 19 '18 at 0:49
  • 1
    \$\begingroup\$ @guest271314 The challenge is not clear to me: why is 200 [200] but 100.01 [1,0,0,.01]? Maybe a worked-through example in the question as well as a reference implementation would help. For a title "Modified decimal expansion of a number" is a start. \$\endgroup\$ – lirtosiast Dec 19 '18 at 0:57
  • \$\begingroup\$ @guest271314 Some languages have builtins for the digits of an integer or float e.g. Mathematica RealDigits[3.14159] = [{3,1,4,1,5,9},1] . Do those count as string methods? \$\endgroup\$ – lirtosiast Dec 19 '18 at 0:59
  • \$\begingroup\$ @lirtosiast 200 does not contain a decimal, 100.01 contains a decimal. The reference implementation is at the question. Created the requirement from scratch while attempting to solve another inquiry. Does Mathematica have a method to check if a value is a string, integer or decimal? \$\endgroup\$ – guest271314 Dec 19 '18 at 1:03
  • \$\begingroup\$ I don't see any reference implementation. It might be better if you explicitly listed the rules behind the transformation \$\endgroup\$ – Jo King Dec 19 '18 at 1:05
  • \$\begingroup\$ @JoKing See "Test cases". That goes back to whether to post the question here or at Software Engineering. The question does not ask users to write an entire specification (frequently edited; maintained; an entire process in and of itself). Observing the test cases: when the first digit of a decimal is a 0 , and a digit follows, that value includes all 0's up to and including the last digit of that decimal, else the decimal portion is spread or expanded to the remainder of the decimal portion for the remainder of indexes of the array, that is: [-0.01], [1,0,0,0.01], [1,0,0,0.0001]. \$\endgroup\$ – guest271314 Dec 19 '18 at 1:09
  • 1
    \$\begingroup\$ Right, you should include those rules in the question, along with what happens when the input is an integer and/or ends in zero. I'm not sure what you'd achieve by posting on Software Engineering because I doubt any form of this question would be on-topic. \$\endgroup\$ – Jo King Dec 19 '18 at 1:22
  • 1
    \$\begingroup\$ Also, the specification should be given as a specification, not as a set of test cases to reverse-engineer. \$\endgroup\$ – Peter Taylor Dec 19 '18 at 9:42
  • 1
    \$\begingroup\$ "The specification ... is WIP." That's fine: that's what the sandbox is for. I'm trying to identify things which need addressing before the question leaves the sandbox. "A users' answer could redefine the specification, in a good way" This is completely against the ethos of this site. All users should implement the same specification, because otherwise it's not a fair contest. \$\endgroup\$ – Peter Taylor Dec 19 '18 at 14:56
  • 1
    \$\begingroup\$ I'm guessing he means move the specification from below the test cases to the task section and remove the Observing the test cases part. And perhaps make it a bit clearer, for example giving us the inputs that led to [-0.01], [1,0,0,0.01], [1,0,0,0.0001] rather than having them in isolation. \$\endgroup\$ – Jo King Dec 20 '18 at 5:36
  • 2
    \$\begingroup\$ Specifically? Nothing is clear to me. Try reading through the spec yourself without the test cases and forgetting that you already know in your head how everything should work - is it clear to you? As for a solution to making it clearer: start by having a look through the specs of recent, well-received challenges and note the detail they go into about what is expected of solutions and what is & isn't allowed. Then rewrite your own spec in a similar manner so there's no (or very little) room for doubt or confusion. (1/2) \$\endgroup\$ – Shaggy Dec 20 '18 at 19:11
  • 1
    \$\begingroup\$ Ah, I didn't realise you'd deleted the bounty post. I think you misunderstood what I meant when I commented. I was just clarifying that if an answer were to be posted, the 500 rep would come from me, though you could add some rep if you wanted. There was no censorship of your post and I'm not sure why you deleted it. Typically on PPCG, we post the bounties after a valid answer has been posted, in order to make sure the rep doesn't go to waste, especially if the task is very hard or possibly impossible \$\endgroup\$ – Jo King Feb 19 at 10:37
-2
\$\begingroup\$

HTML-tac-toe

Build a one-player tic-tac-toe game with only HTML and CSS.

Introduction

You can do just about anything with a fully-featured programming language, but how much can you accomplish on a Neopets petpage? Inspired by http://www.neopets.com/~vuh

Challenge

Build a one-player tic-tac-toe game with only HTML and CSS.

  • Use no more than one file.
  • GIFs (including animations), PNGs, and JPEGs are allowed.
  • Flash, embedded scripts, iframes, and JavaScript are not allowed.
  • It must work in the at least two standard browsers (FF, Chrome, Safari, Opera, IE)

Inputs: The player will click on a space when it's their turn to move there.

Outputs: The page will show the current board state at all times. The page will play an optimal move whenever the player moves, unless the game is over.

You're free to decide who starts and who has X or O.

Scores

  • -10 per image
  • -1 per opening bracket or brace (< / { )

Brownie points for design, flair, and new tricks!

Example Input and Output

Input:

Click on the top left of an empty grid

Output:

Grid shows my mark where I clicked and the opposite mark in the left middle or top middle.

\$\endgroup\$
  • \$\begingroup\$ I'd recommend against restricting languages, and against score bonuses too \$\endgroup\$ – ASCII-only Jan 22 at 4:15
  • \$\begingroup\$ @ASCII-only I can drop the bonuses without much consequence, but it's not a new challenge without a language or host restriction. Any suggestions? \$\endgroup\$ – Qaz Jan 22 at 4:45
  • \$\begingroup\$ True, but... language restrictions are pretty frowned upon \$\endgroup\$ – ASCII-only Jan 22 at 4:47
  • 1
    \$\begingroup\$ Welcome to PPCG! You may want to check this post out, it certainly helped me when starting with writing my own challenges. Also, your post does not have a well-defined objective winning criterion. It seems like it is atomic code-golf or code-challenge [1/2] \$\endgroup\$ – ბიმო Jan 22 at 19:32
  • \$\begingroup\$ , but you will need to define how answers are scored (in this case lower is worse) and how ties are treated. Also why do you disallow GIFs but JPGs not? I know most will know, but maybe explain or at the very least link to somewhere where the rules for tic-tac-toe are explained. What counts as an X, what as an O? There are a lot of open question atm. [2/2] \$\endgroup\$ – ბიმო Jan 22 at 19:36
  • \$\begingroup\$ JPGs are allowed. (That's the same format as JPEG, just a different extension.) I can change it to 'images', but I'm worried about some image format I don't know of that makes the challenge trivial. More points, more better! That seems clear enough, but I can certainly spell it out. Are ties forbidden? Two entries with the same number of points seem equally good to me, but the first posted could be the winner. If I link to tic-tac-toe rules, does that answer "What counts as an X, what as an O?" or are you asking something else? \$\endgroup\$ – Qaz Jan 23 at 0:13
  • 4
    \$\begingroup\$ "Standard exceptions are allowed IF they work on Neopets.com." How do we know what works on Neopets.com? If we have to create accounts on a random third party site to test answers and know whether they're valid or not, the question should and probably will end up closed with a lot of downvotes. \$\endgroup\$ – Peter Taylor Jan 24 at 15:34
  • 1
    \$\begingroup\$ This isn't very interesting in general. It essentially amounts to creating every possible layout of a tic-tac-toe board and linking them together with clever CSS and HTML hacks so it fits in 25 pages. I think it could be made a bit more interesting by making it atomic code golf scoring on the total number of html files used, lowest scores win rather than limiting the total number of pages. \$\endgroup\$ – Beefster Jan 25 at 20:36
  • \$\begingroup\$ @PeterTaylor very well, dropped that altogether \$\endgroup\$ – Qaz Jan 25 at 22:53
  • \$\begingroup\$ @Beefster The page I link to as the inspiration (neopets.com/~vuh) uses only one html file, and the source isn't too hard to understand, so perhaps I should link to the creator of the page instead, limit the solutions to one page, or both. \$\endgroup\$ – Qaz Jan 25 at 22:53
  • 1
    \$\begingroup\$ I highly suggest looking through current codegolf questions to see which are well-received by the community. This question seems highly arbitrary and leaves too much under-specified. \$\endgroup\$ – qwr Jan 27 at 20:28
-2
\$\begingroup\$

Introduction

The original creator of this meme has gone blind, lost his internet and accidentally deleted all his memes. Except this one. He has this one last meme on his desktop, and since he can't see, he wants to know what this meme is.

By hearing it.

Challenge

Your challenge is to write the shortest program that will produce a playable audio file that the meme creator will play to hear the text in this meme.

  • The input is the meme below
  • The output will be a audio file that reads the output text in English and has a slight pause after a colon or a new line. But don't read out 'colon'

Answer the following questions for your readers.

  • You can use any programming language
  • You can use any existing library
  • Output audio must be playable by vlc
  • Networking is not allowed, you cannot connect to any internet services
  • Shortest answer wins

Input and Output

Input:

surprised pikachu eyesight

Output:

Me: spends 8 hours per day on the internet

Eyesight: gets worse

me:

\$\endgroup\$
  • 7
    \$\begingroup\$ The output would always be hardcoded, so there's no point in the input \$\endgroup\$ – Jo King Mar 8 at 9:43
  • 1
    \$\begingroup\$ This challenge would be nice with different memes as test cases. Otherwise it would be hardcoded as said previously. \$\endgroup\$ – Belhenix Mar 20 at 19:35
-2
\$\begingroup\$

Compress briefly

Compress and decompress the first chapter of Worm, beginning with the opening words "Class ended" and ending with the closing words "my best friend." (including the period). You do not need to include any of the formatting (copy and paste as plain text).

Rules

  • You may not use any built-in or imported compression functions or procedures. You must implement the compression yourself.

  • You may either write one program to compress and another to decompress, or one program that does both. If you wish, the second option can be a polyglot, where compiling as one language compresses and compiling as the other decompresses.

  • Your program must be no more than 2000 bytes long. You may, at your option, compress your program with bzip2 or gzip before measuring its size for the purpose of meeting this limit.

  • Your program does not need to work for any other text.

  • Standard loopholes apply.

  • Standard I/O rules apply.

Scoring

  • The score is the sum of the total number of bytes of your program(s) and the total number of bytes in the compressed text.

  • If you use a single program to compress and decompress, then you may have to pay a penalty. Specifically, you must pay a number of bytes equal to the Levenshtein distance between the shell command needed to (compile and) run your compression program and the one needed to run your decompression program. You can calculate this online. A special exception: if you choose to write a polyglot, then you can leave out the paths to the compilers/interpreters when you calculate the penalty.

Tags: code-challenge, compression

\$\endgroup\$
  • \$\begingroup\$ Related \$\endgroup\$ – Beefster Mar 19 at 22:31
  • \$\begingroup\$ @Beefster, a bit, but I think there are enough differences to make competitive answers largely incompatible. \$\endgroup\$ – dfeuer Mar 19 at 22:36
  • 2
    \$\begingroup\$ I don't think any answers are going to outperform gzip/bzip/whatever. There's no obvious patterns to exploit in the text. \$\endgroup\$ – Beefster Mar 19 at 22:37
  • 2
    \$\begingroup\$ Also: how is this different from kolmogorov-complexity? \$\endgroup\$ – Beefster Mar 19 at 22:38
  • \$\begingroup\$ @Beefster, it's different because I don't allow the code to be big enough to have much chance of encoding the text in it. It doesn't have to outperform industrial-strength algorithms. That mention had to do with the source code size limit, intended to give extremely verbose languages the opportunity to participate. \$\endgroup\$ – dfeuer Mar 20 at 0:28
  • \$\begingroup\$ Every answer will be some variant of import gzip; gzip.compress(story) \$\endgroup\$ – Beefster Mar 20 at 16:21
  • \$\begingroup\$ @Beefster, is my explicit prohibition of that insufficient? My first rule is that you can't use a built-in or imported compression function. \$\endgroup\$ – dfeuer Mar 20 at 16:42
  • \$\begingroup\$ That sounds a lot more interesting than it actually is. There's a reason "do X without Y" questions have fallen out of favor. Compression challenges are hard to write. At the very least, you need some exploitable pattern common to a class of strings. This simply isn't the case in the linked text. \$\endgroup\$ – Beefster Mar 20 at 19:29
  • \$\begingroup\$ Even without using built-ins the best answer will use some variant of Huffman coding that fits in 2000 bytes. LZ77 is also pretty easy to implement and works well on text. \$\endgroup\$ – Beefster Mar 20 at 19:44
-2
\$\begingroup\$

Bit flipper

Given a string s and a positive number n, return the string s with n random bits flipped. (A random number can be generated in any way, including pseudo-random number generators)

Example:

Before:

Hello World

After (n = 2, 2 bits flipped):

Hello wOrld
\$\endgroup\$
  • 2
    \$\begingroup\$ How exact are the bytes being 'flipped'? Are we changing the bits? Is the output deterministic? It doesn't look like you're modifying any specific bit of the byte, or reversing it, or doing bitwise negation. \$\endgroup\$ – Rɪᴋᴇʀ Mar 21 at 1:55
  • 1
    \$\begingroup\$ @Riker well changing from uppercase to lowercase is just xor 32. But they'rem saying byte flipper not bit flipper which is a bit confusing \$\endgroup\$ – ASCII-only Mar 21 at 6:09
  • \$\begingroup\$ @Riker The bits are flipped \$\endgroup\$ – smileycreations15 Mar 21 at 9:42
  • \$\begingroup\$ @JoKing No, that was an example because I didn’t wanted binary non-unicode characters in the post. \$\endgroup\$ – smileycreations15 Mar 21 at 9:44
  • \$\begingroup\$ What is n? On the basis of what little is specified in the question, I would be tempted to write an implementation for n=0 which consists of the empty program in GolfScript... \$\endgroup\$ – Peter Taylor Mar 21 at 16:44
  • \$\begingroup\$ @PeterTaylor A user defined count of how many bytes will be flipped \$\endgroup\$ – smileycreations15 Mar 21 at 18:12
  • 1
    \$\begingroup\$ I think the confusion here is that "bytes" doesn't mean what you think it means. From the lone test case I think what you're trying to ask us is: given a string s and a number n, change the case of n random letters in s - would that be correct? \$\endgroup\$ – Shaggy Mar 22 at 0:41
  • \$\begingroup\$ I assume case was just an example of bit 5 flipping. I'd recommend writing it like Given a string s and a positive number n, return the string s with n random bits flipped. Though from there you run into problems about invalid unicode sequences in the output \$\endgroup\$ – Jo King Mar 22 at 3:45
  • \$\begingroup\$ @JoKing I replaced with your example. \$\endgroup\$ – smileycreations15 Mar 22 at 7:47
  • \$\begingroup\$ What do you mean by Default n = 3? Also, how should programs handle invalid unicode sequences? \$\endgroup\$ – Jo King Mar 22 at 9:14
  • \$\begingroup\$ @JoKing By default, n should be 3. And invalid unicode sequences should not be handled, and the data should be directly printed out to stdout or any output file. \$\endgroup\$ – smileycreations15 Mar 22 at 12:35
  • \$\begingroup\$ When you say random, do you mean of our choice? pseudo-random? fetched from random.org? \$\endgroup\$ – Artemis Fowl Mar 26 at 23:16
  • \$\begingroup\$ @ArtemisFowl It is selected by the program. \$\endgroup\$ – smileycreations15 Mar 27 at 10:45
  • \$\begingroup\$ @smileycreations15 It's gonna be hard to make that 100% random \$\endgroup\$ – Artemis Fowl Mar 27 at 15:46
  • 1
    \$\begingroup\$ @smileycreations15 Maybe you should add that to the question. \$\endgroup\$ – Artemis Fowl Mar 27 at 20:35
-2
\$\begingroup\$

You can't tell me what to do!!!

Intentionally break as many coding conventions as possible while crafting a working Hello World

For each language, a coding convention standard will be selected. The following is the current list:

javascript -> Google's Style Guide

PHP -> PSR-2

C++ -> ISO C++ Style Guide

Python -> PEP-8

The maximum file length is 6000 characters. Any code beyond the first 6000 will not count towards broken conventions. (Using conventions that you have set to break after the 6000 point, however, will count against you.)

If you do not see your language, you may choose one of the most common coding standards for your language, and use that, and (hopefully) it will be noticed and added to the list. Each language is its own competition. (For example: If your code is in Ruby, you're not competing against C++ code)

This is the coding equivalent of an ugly baby contest, and pushes you to think outside the box (possibly way too far outside the box). The goal is to write a 'simple' Hello World program. However, you have to do it while breaking as many coding conventions as possible, and being as ugly as possible (but still working!)

The advantages of this puzzle are multi-purpose. This is to challenge the coder to separate long-standing habits (which generally follow coding conventions) from functionality - to encourage creativity. Further, it also serves as a reverse example to demonstrate when coding conventions are a help vs a hindrance.

Remember, ugly doesn't have to mean gibberish or unnecessarily long or poorly running. In fact, code length or runtime do not factor into the evaluation.

For example, you could write procedural code using only classes, use an eval() to declare constants, or use only use variable names using characters that have nothing to do with what the variable does, reverse indentation, or rely exclusively on gotos in an interpreted language. The only thing your code has to do is output "Hello World" to the command line or an equivalent.

Each answer should list and link to coding conventions it breaks and receives 1 point for each broken code convention (but instant total of zero points the code follows any coding convention it says its breaking). If a voter agrees it violates all the listed coding conventions, upvote the code that violates the most while still functioning. (Accidentally violating coding conventions, however, does not count. Each one violated coding convention must be documented and intentional.)

Note: For each coding convention taken on, it must be consistently broken across the entire program. Following the convention even once invalidates your entire code. Habits are your enemy. Further note: If you declare you're breaking a convention, you MUST break it. If it's not applicable, it doesn't count.

Alternate Scoring method:

Don't like the "call your shot and then try to make it" scoring method? Do you have a readily available git functionality? Does the coding convention have a convenient git-hook for code style enforcement? Fear not, you have the option for an alternate scoring method: 1. Write up your code. 2. Run it through the git commit with the hook active. 3. If your hook auto-changes code, commit it, and do step 4. If it gives you coding style errors and rejects the commit, count the errors; you get one point for each error and skip to step 5. If you break git due to the hook crashing, list the broken code enforcement, add 50 points, and try again with a different code-enforcement hook. (You CANNOT be an author or contributor to any git-hook before you test against it. This is considered cheating and will be disqualify you.) 4. If your hook auto-changes code to fit style enforcement, do a git-diff between your code and the code it committed. Each change is one point. 5. Total your points. List your points as an alternate score in your answer's header. List the code-enforcement hooks you tested it against.

I'm personally not a fan of this scoring method as it allows accidental points and becomes more like it's testing the enforcement hook rather than creative code style breaking, but some like the more computer-controlled scoring method... so there ya go.

Sandbox Reminder: Sandbox is a place for constructive criticism. Saying, "I don't like it" or "I wouldn't do it" isn't constructive criticism. Last time I had this in the sandbox, most criticism was built on disliking the type of challenge, not actually building it properly. If you don't like the challenge concept, then just don't do it. If you have legitimate suggestions on how to make the challenge better then do so. I will do my best to address legitimate points.

Standard Example Answer format


My Oh so wrong Hello world - PHP - Attempting 2 points

Breaking conventions in PSR-2:

  • breaking "Opening braces for classes MUST go on the next line, and closing braces MUST go on the next line after the body."
  • breaking "All PHP files MUST end with a single blank line."

--

<?php
class hiworld{public $printme = "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

\$\endgroup\$
  • \$\begingroup\$ That just makes it better. \$\endgroup\$ – liljoshu Mar 8 at 23:29
  • \$\begingroup\$ Hate as measured by votes, however, is a discrete value, and therefore objective. \$\endgroup\$ – liljoshu Mar 8 at 23:37
  • \$\begingroup\$ 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. \$\endgroup\$ – trichoplax Mar 10 at 10:00
  • \$\begingroup\$ @trichoplax Fair enough on that. I'll change encouragement to just be on coding style. \$\endgroup\$ – liljoshu Mar 10 at 22:25
  • 3
    \$\begingroup\$ 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. \$\endgroup\$ – Jo King Mar 12 at 21:38
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – Jo King Mar 13 at 0:06
  • 2
    \$\begingroup\$ I've removed my downvote and the related comment. \$\endgroup\$ – trichoplax Mar 13 at 6:59
  • 2
    \$\begingroup\$ 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? \$\endgroup\$ – trichoplax Mar 13 at 7:05
  • 4
    \$\begingroup\$ 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. \$\endgroup\$ – trichoplax Mar 13 at 7:08
  • 5
    \$\begingroup\$ "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. \$\endgroup\$ – Peter Taylor Mar 13 at 12:00
  • 2
    \$\begingroup\$ @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? \$\endgroup\$ – liljoshu Mar 13 at 15:33
  • 2
    \$\begingroup\$ 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. \$\endgroup\$ – Spitemaster Mar 14 at 16:36
  • 2
    \$\begingroup\$ I know this probably isn't going anywhere, but the most 'official' python style guide is probably PEP 8. \$\endgroup\$ – Artemis Fowl Apr 6 at 18:17
  • 1
    \$\begingroup\$ @liljoshu You've got my upvote for what it's worth, though I agree this needs some improvements. \$\endgroup\$ – Artemis Fowl Apr 8 at 22:35
  • 2
    \$\begingroup\$ Something like codegolf.stackexchange.com/questions/172445/… might be ok \$\endgroup\$ – Embodiment of Ignorance Apr 10 at 3:04
-2
\$\begingroup\$

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?
\$\endgroup\$
  • 2
    \$\begingroup\$ 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. \$\endgroup\$ – ais523's temporary account May 13 at 16:24
-2
\$\begingroup\$

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)

\$\endgroup\$
  • 4
    \$\begingroup\$ 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). \$\endgroup\$ – Stewie Griffin May 23 at 10:16
  • 1
    \$\begingroup\$ 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? \$\endgroup\$ – bb94 May 24 at 15:50
-2
\$\begingroup\$

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.

\$\endgroup\$
  • 1
    \$\begingroup\$ 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? \$\endgroup\$ – lirtosiast Jun 29 at 7:12
-2
\$\begingroup\$

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.
  • Please provide a link to test your code as well as an explanation.
  • 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))
\$\endgroup\$
  • \$\begingroup\$ @FryAmTheEggman how's this? \$\endgroup\$ – Billylegota Jul 19 at 2:32
  • 2
    \$\begingroup\$ 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. \$\endgroup\$ – lirtosiast Jul 19 at 2:52
  • \$\begingroup\$ @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). \$\endgroup\$ – Billylegota Jul 19 at 3:20
  • 3
    \$\begingroup\$ 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)} \$\endgroup\$ – fəˈnɛtɪk Jul 20 at 17:00
  • 2
    \$\begingroup\$ 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. \$\endgroup\$ – lirtosiast Jul 20 at 18:17
  • \$\begingroup\$ @lirtosiast +1 thanks for such a clear example! \$\endgroup\$ – Billylegota Jul 21 at 6:16
-2
\$\begingroup\$

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.
  • No standard loopholes, please.
  • 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.
\$\endgroup\$
  • 4
    \$\begingroup\$ 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. \$\endgroup\$ – Peter Taylor Jul 24 at 7:11
  • 5
    \$\begingroup\$ @A__ For JavaScript, is it == or ===? Either way, people will be angry. \$\endgroup\$ – wizzwizz4 Jul 24 at 13:16
  • 2
    \$\begingroup\$ @A__ Because either the challenge is trivial (['']) or you're arbitrarily restricting a language. Work on your definition of "equality operator". \$\endgroup\$ – wizzwizz4 Jul 24 at 13:46
  • 2
    \$\begingroup\$ @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.) \$\endgroup\$ – wizzwizz4 Jul 24 at 14:07
  • \$\begingroup\$ @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)) \$\endgroup\$ – A _ Jul 24 at 14:10
  • 3
    \$\begingroup\$ @U10-Forward 0 bytes \$\endgroup\$ – tjjfvi Jul 24 at 14:32
  • 1
    \$\begingroup\$ @tjjfvi I thought about that one, but I didn't think it'd be syntactically valid. It does, however, work. \$\endgroup\$ – wizzwizz4 Jul 24 at 15:19
  • 1
    \$\begingroup\$ @wizzwizz4 How do you know which language? \$\endgroup\$ – tjjfvi Jul 24 at 15:31
  • 1
    \$\begingroup\$ @tjjfvi I just assumed it was a language where the "null" / "undefined" singleton was indexable, returning the very same value. \$\endgroup\$ – wizzwizz4 Jul 24 at 15:34
  • 1
    \$\begingroup\$ @wizzwizz4 No, JS: window.window === window :) \$\endgroup\$ – tjjfvi Jul 24 at 15:38
  • 2
    \$\begingroup\$ @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. \$\endgroup\$ – wizzwizz4 Jul 24 at 15:53
  • 1
    \$\begingroup\$ @tjjfvi Well i do it in Python so no such a thing called 0 bytes in python \$\endgroup\$ – U10-Forward Jul 25 at 1:08
  • \$\begingroup\$ Alternative: window["window"]===window \$\endgroup\$ – A _ Jul 25 at 4:06
-2
\$\begingroup\$

Recursive Sum Up The Digits

Tags:

Produce the shortest code that sums up all the digits in a number, and after if it still has more than one digit, sum it up again and again until it's with one digit, example: 987 would become 6 since 9 + 8 + 7 is 24, whereas 2 + 4 is 6.

\$\endgroup\$
  • 2
    \$\begingroup\$ I have the feeling I've seen this challenge before, but I'm unable to find it. It could be that I'm confusing it with two similar loose challenges, since there are more challenges where we continue doing something until a single digit remains, and there are also loads of challenges summing the digits of an integer. I'm not 100% sure anymore whether there is already one with both combined. \$\endgroup\$ – Kevin Cruijssen Aug 5 at 6:37
  • 5
    \$\begingroup\$ This is just "Given n output n % 9". \$\endgroup\$ – Peter Taylor Aug 5 at 7:46
  • \$\begingroup\$ @PeterTaylor Ah, now I remember where I've seen it before: here in the sandbox, and you (or someone else) made that same comment. :) \$\endgroup\$ – Kevin Cruijssen Aug 5 at 12:24
  • \$\begingroup\$ Isnt this just a duplicate of codegolf.stackexchange.com/q/1775/87923? \$\endgroup\$ – EdgyNerd Aug 6 at 8:19
  • 1
    \$\begingroup\$ @EdgyNerd It's related, but not a dupe. That challenge takes multiple integers as input simultaneously, instead of a single input. And it outputs the amount of iterations for each of those integers to become a single digit, instead of the resulting digit itself. In addition, it has rather cumbersome output-format.. So that challenge would result in 987 2 for input [987]. The core part of both challenges is the same though: continue summing the digits of an integer until a single digit remains. \$\endgroup\$ – Kevin Cruijssen Aug 6 at 9:16
-2
\$\begingroup\$

The goal is to make a program that is compilable in as many languages as possible.

  • The program must be compilable with a specific compiler version and compiler parameters without any errors.
  • The program may result in an error when run.
  • The source code must not be empty or whitespace.
\$\endgroup\$
  • 1
    \$\begingroup\$ This is somewhat similar in spirit but not the same. This probably is a duplicate of something, strictly or less so, but that's the first thing that came to mind \$\endgroup\$ – Unrelated String Aug 27 at 7:48
  • 2
    \$\begingroup\$ A null program is compilable in most(if not all) languages. (Including specific compilers of C(in IOCCC).) \$\endgroup\$ – A _ Aug 27 at 10:15
  • \$\begingroup\$ @A_ I've added an additional rule. \$\endgroup\$ – user2190035 Aug 27 at 10:58
  • 3
    \$\begingroup\$ As-is, this will be closed as Too Broad, since there's no "thing" for the program to do. Have a look at the polyglot tag and see what others have done. \$\endgroup\$ – AdmBorkBork Aug 27 at 14:25
  • \$\begingroup\$ Define "compile". \$\endgroup\$ – pppery Aug 28 at 23:23
-2
\$\begingroup\$

I reverse the source code, you keep the output

Yet another blatant rip-off of a rip-off of a rip-off of a rip-off. Go upvote those!

Your task, if you wish to accept it, is to write a program/function that outputs/returns its own output. The tricky part is that if I reverse your source code, the output must be preserved.

Examples

Let's say your code is ABC and the corresponding output is XYZ. If I run CBA, the output must also be XYZ

\$\endgroup\$
  • 3
    \$\begingroup\$ What's to prevent a trivial solution of just 1 in many (many) languages? \$\endgroup\$ – AdmBorkBork Sep 25 at 18:30
  • \$\begingroup\$ Or trivial comment abuse? \$\endgroup\$ – JL2210 Sep 25 at 20:39
  • \$\begingroup\$ @JL2210 This works in codegolf.stackexchange.com/questions/193315/… print("ABC")#("ABC")tnirp \$\endgroup\$ – gadzooks02 Sep 26 at 15:21
  • \$\begingroup\$ @AdmBorkBork This works in codegolf.stackexchange.com/questions/193315/… too: 1 is the reverse of 1 \$\endgroup\$ – gadzooks02 Sep 26 at 15:22
  • \$\begingroup\$ And to both of you: why did these not stop that code golf becoming a challenge? \$\endgroup\$ – gadzooks02 Sep 26 at 15:23
  • 2
    \$\begingroup\$ I didn't say it couldn't be a challenge. I just wanted to point out that this is trivial in many languages. And for what it's worth, I downvoted the challenge you linked for the same reason. \$\endgroup\$ – AdmBorkBork Sep 26 at 15:48
  • \$\begingroup\$ @gadzooks02 That challenge requires you to reverse the input. The input can be anything in that challenge. \$\endgroup\$ – JL2210 Sep 26 at 15:49
  • \$\begingroup\$ @JL2210 Ah yes. Would preserve the input work better? \$\endgroup\$ – gadzooks02 Sep 26 at 16:02
  • \$\begingroup\$ No, then it would be trivial in Bash and BrainFuck and C and, well, you get the point. \$\endgroup\$ – JL2210 Sep 26 at 16:26
  • \$\begingroup\$ @JL2210 Yes, OK. Do I need to do something if I've decided against a challenge? Delete the post? \$\endgroup\$ – gadzooks02 Sep 26 at 16:29
  • \$\begingroup\$ No idea. Read over the guidelines, they might help. \$\endgroup\$ – JL2210 Sep 26 at 16:31
-3
\$\begingroup\$

Code-challenge: Guess my number

The challenge

You have a number from 1 to 10 in mind, and your program should ask questions to find out which number. These questions can be any questions, the program only has to find out the number as fast as possible.

Your program should ask a question, such as "Is the number a prime?", and the user must answer either y or n (yes or no). Ask questions until you know the number.

The scoring

To calculate the score, you need to take the sum of the question count for each number. For example, if you need 1 question to find the number 1, 2 questions to find the number 2, and so on, the score is 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10, so the score is 55.

Important note: the question count for a specific number must always be the same. For example, if you need 4 questions to find out the number 10, then you have to ask always 4 questions to find out the number 10, otherwise it is impossible to calculate the score.

\$\endgroup\$
  • 5
    \$\begingroup\$ boooring. The Huffman tree for a uniform set is any perfectly balanced tree. The question asks us to perform a binary search on the usr device. Is the number greater than 5? Is the number greater than 2? Is the number greater than 1? Hey' I think it's 1. \$\endgroup\$ – John Dvorak Jan 2 '14 at 11:49
  • 3
    \$\begingroup\$ Maybe if this were a pop-contest and the goal was to make the most original set of questions while still keeping the score at its theoretical minimum. \$\endgroup\$ – John Dvorak Jan 3 '14 at 5:28

You must log in to answer this question.

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