485
\$\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\$

2924 Answers 2924

1
91 92
93
94 95
98
-2
\$\begingroup\$

Google Logo in Conway's Game of Life

Conway's Game of Life base challenges are always fun so here is a new one.

This is Google's Logo (if you have not somehow seen it): Google Logo

The font is called Product Sans. Your job is to replicate this logo (no color of course) in 800x439px just like the image (just the letters).

Have fun! This is a popularity contest so the most votes wins. :D Good luck. Of course, this may not be possible but, you never know until you try.

Usual rules apply.

Inspired by this.

| |
\$\endgroup\$
  • 6
    \$\begingroup\$ "looks like" isn't a tight enough specification for a challenge. \$\endgroup\$ – Mego May 29 '17 at 21:20
  • 1
    \$\begingroup\$ Also consider some method besides first-past-the-post, that winning criteria doesn't really work well with this site. \$\endgroup\$ – FryAmTheEggman May 30 '17 at 0:22
  • 1
    \$\begingroup\$ So the answer could replicate it at the 0th generation? \$\endgroup\$ – Peter Taylor May 30 '17 at 10:48
  • \$\begingroup\$ @PeterTaylor Good point \$\endgroup\$ – arodebaugh May 30 '17 at 13:14
  • \$\begingroup\$ @FryAmTheEggman Popularity contest? \$\endgroup\$ – arodebaugh May 30 '17 at 13:14
  • \$\begingroup\$ @Mego Also good point \$\endgroup\$ – arodebaugh May 30 '17 at 13:15
  • \$\begingroup\$ OK I updated stuff maybe it will make this challenge better \$\endgroup\$ – arodebaugh May 30 '17 at 13:16
  • 3
    \$\begingroup\$ 1. I don't see how the change you've made addresses my previous point. 2. Pop-con is barely any better than fastest-gun-in-the-west. 3. It's possible to test whether this is possible or not (I highly doubt it) by running the CA backwards. \$\endgroup\$ – Peter Taylor May 30 '17 at 16:09
-2
\$\begingroup\$

The 2017 Loader contest

Here's a thing: Let's do the bignum bakeoff again.

Because why not.

What to do

Write a program in less than 256 characters that outputs the biggest number you can.
Yep, that's it. Biggest return value wins.

We'll run the program on a VM with infinite memory. (How do we do this?)

Rules

  • 256 chars max, excluding whitespace
  • Different leagues for each language
  • Output however you want
    • No explicitly printing numbers until your loop runs out. Print the number you generate directly. {1}
  • Program must terminate
  • No implementation-dependent shenanigans.
  • Implementation-independent shenanigans is encouraged.
  • ints are infinite.
  • Program must return the same number every time
  • Submission must include the approximate return value in any suitable googological notation.
  • Whitespace is space, tab, newline, formfeed, and return
    • BrainF***: Whitespace is all non-[]+-<> characters

{1} Allowed ways to return: printf("%d", num); return num;, etc.
Banned ways to return: for(;num>0;num--)printf("99999");, etc.


This is not a dupe of...

This because you can put any characters you want, not just non-digits; because we're hard-limiting the characters.


Suggested rules

  • No floats: float double long double, etc
  • No strings or chars
  • No bitfeilds
  • No looking at Command-line args

Next year's contest will be named after this year's winner, for no particular reason.

http://djm.cc/bignum-rules-posted.txt


Sandbox

  • How do you even test these programs?
  • What other rules should we have?
| |
\$\endgroup\$
  • \$\begingroup\$ You don't actually explain the rules of the challenge, we would have to go to that link to find out what we are supposed to do. Aside from that, I think this has a lot of problems with your typing restrictions if these are not limited to C, but limiting it to C wouldn't really fit the spirit of the site. I think you may want to rethink how you want to approach this question. \$\endgroup\$ – FryAmTheEggman May 29 '17 at 16:43
  • \$\begingroup\$ @FryAmTheEggman "Typing restrictions"? (Added proper instructions) \$\endgroup\$ – SIGSTACKFAULT May 29 '17 at 16:45
  • \$\begingroup\$ Your post doesn't describe how people win. Is it by the largest possible number? Anyway, the problems are things like not counting whitespace, which can easily result in degenerate answers, as well as things like I/O streams and whatnot. All of your extra rules seem entirely based around C with no regard for other languages, which will not go well. \$\endgroup\$ – FryAmTheEggman May 29 '17 at 16:48
  • 4
    \$\begingroup\$ In answer to "Because why not": because it will be closed as a dupe. \$\endgroup\$ – Peter Taylor May 29 '17 at 17:59
  • \$\begingroup\$ Here's a couple of rules I would consider. 1. Program must generate the same result every time (e.g. not based on timer, probability, or the like). 2. Submissions should include, if not the exact resulting number, at least a best estimate, in scientific notation if need be. \$\endgroup\$ – Computronium May 30 '17 at 18:32
  • \$\begingroup\$ Scientific notation? People will post answers that far, far exceed that. In fact, Mathematica, 22: Fold[Power,2~Range~9999] It's 2^3^4^...^9999. That's not being represented anytime soon. \$\endgroup\$ – CalculatorFeline May 31 '17 at 3:31
  • 1
    \$\begingroup\$ This is a duplicate, and is also going to come down a lot to whether or not you allow programs that exceed the computational capacity of any existing computer. (If you require programs to work on a physical computer, the best they can possibly do is to use the entirety of memory as a counter and print out 9s over and over again. If you don't, the answers can easily be large enough that you need to use notation invented specifically for describing the number, because all other notations are not enough.) \$\endgroup\$ – user62131 May 31 '17 at 22:40
  • \$\begingroup\$ If your code can simulate a Turing machine, it becomes hard to judge who the winner is, and whether an answer is valid at all. \$\endgroup\$ – anatolyg Jun 1 '17 at 20:35
  • \$\begingroup\$ Re your latest edit: you're wrong. The question it's a dupe of also has a hard limit to the number of characters; in fact it's a harder one, but the best answers could be copied with slight tweaking to take advantage of the extra space. And the digit restriction turned out not to be a serious problem: the winning answer would gain extremely little from being able to use digits. \$\endgroup\$ – Peter Taylor Jun 2 '17 at 9:07
-2
\$\begingroup\$

Buzzfeed's Ultimate Coder Challenge

Buzzfeed recently published a coding test which the guys over in TNB have determined is the world's hardest coding test [citation-needed].

In the language of your choice, given no input, output 8 separate snippets of code in your language. The snippets should do the following, in order:

1 - Print "Hello, world!"
2 - Print 200
3 - Read input from STDIN then print "Hello "[input]
4 - Print 10
5 - Print 25
6 - Terminate silently (do nothing)
7 - Print "a is 1", "a is 2"... all the way to "a is 10"
8 - Print "a is 5", "a is 6", "a is 7", "a is 8"

For challenges 7 and 8, the outputted source should output each output newline separated

Scoring

This is so fewest bytes in each language wins!

Meta

  • What needs clarifying?
  • What other tags could this use?
  • Would this perform better as a ?
  • Is it even worth posting this challenge at all?
| |
\$\endgroup\$
  • \$\begingroup\$ citation \$\endgroup\$ – Adám Jun 7 '17 at 12:10
  • 3
    \$\begingroup\$ Generally, bunching a lot of unrelated tasks is frowned upon. \$\endgroup\$ – Adám Jun 7 '17 at 12:11
  • \$\begingroup\$ Also, several of these tasks will have almost identical answers (2, 4, and 5 being the worst offenders I think). I don't feel this fits very well for any tag on this site. \$\endgroup\$ – FryAmTheEggman Jun 7 '17 at 18:26
  • \$\begingroup\$ 2, 4, and 5 are actually radically different in golfing languages (a builtin for 200 would be very unusual, and it's just large enough to make for an interesting competition between compressed representations, whereas most have a builtin for 10 and some have a builtin for 25). However, that doesn't change the facts that a) they're nonetheless far too easy, and b) asking people to solve a number of unrelated tasks is inferior to splitting them all up into separate questions (which in this case, is inferior to posting them at all). \$\endgroup\$ – user62131 Jun 8 '17 at 0:11
-2
\$\begingroup\$

Do nothing

Write a program which terminates normally (not in an error), producing no output on the standard output stream (or the language's closest equivalent), nor on the standard error stream, regardless of what content is present on the standard input stream. (Note that this is intentionally overriding the normal I/O defaults; this is a challenge entirely about input/output handling.)

Additionally, your program may not have any other side effects (e.g. writing files, changing persistent state), unless they're an unavoidable consequence of running a program on the operating system you're using (e.g. on Linux, it's OK to change the "next process ID number to be assigned" value inside the kernel, because that happens whenever you run a program).

Finally, to avoid numerous uninteresting 0-byte (or boilerplate-plus-0-byte) solutions, you may not use a language in which the shortest program that does nothing (i.e. complies with the above specification) is also the shortest (or tied for the shortest) program which runs without error (but possibly reacts to input or produces output). In other words, you can't use a language unless doing nothing is more verbose than doing something.

Clarifications

  • Intentionally exiting the program early is permitted. If you do exit the program manually, on a system that uses exit codes, you may do so with any exit code.
  • Crashing the program is not permitted, even if it (for some reason) exits with a "success" code after the crash.
  • "No output" means 0 bytes of output, not even a trailing newline.
  • Likewise, your program must be able to handle any finite sequence of bytes on the standard input stream, even if it isn't, say, made of characters in the current encoding (but rather of arbitrary octets). You do not need to handle infinite input, though (e.g. your program won't be connected to /dev/zero or the like).
  • You don't have to actually read input; it's your choice as to whether you want to read and discard it, or not read it at all.

Victory condition

As a challenge, shorter is better, measured in bytes. (Remember that if you need to run the program in an unusual way, that incurs a byte penalty, under standard PPCG rules.)

Because languages which are particularly suited for this task (such as Perl and Python) are excluded by the rules, there's not much point in talking about the best answer cross-language; rather, the aim is to find the best answer you can in the language which you submit in. (Historically, on this sort of challenge, answers that are more unusual, interesting, or better-explained have tended to get more votes.)

Sandbox questions

Is this too trivial? We were discussing it in chat as a joke, and realised that it's actually possibly more interesting than it sounds. I'm fairly sure the spec's correct (although would definitely appreciate knowing if something's wrong here!), but would appreciate feedback on how much people would hate me if I posted it to main.

| |
\$\endgroup\$
  • \$\begingroup\$ you can't use a language unless doing nothing is more verbose than doing something.you can't use a program unless your program is more verbose than any other program which does something. You must provide a shorter program which does something to prove your solutions validity. \$\endgroup\$ – Adám Jun 8 '17 at 1:03
  • \$\begingroup\$ @Adám: If you did that, people would just add a comment byte or two to create a program of the shortest possible length that was longer than a program that did something. That isn't particularly interesting. \$\endgroup\$ – user62131 Jun 8 '17 at 1:21
-2
\$\begingroup\$

Plan and Chain a route through OEIS

Your Task is to reach so many OEIS sequences you could make with chaining your last sequence with a operation to a new sequence.

You must avoid last sequence minus last sequence plus first sequence or something similar that your new sequence is based on the first sequence except to make the second sequence.

Your starting OEIS sequence is in every case https://oeis.org/A001477

Given as Input an positive Integer and a Letter that matches [A-Z] or [a-Z]

Example

PHP, 171 bytes

for($a=0;$a<=$argv[1];$a++)$r[]=[$a,$b=$a&1,$c=$a+!$b,$d=(($c-!$b)/2^0)+$b,$A[$b]=$e=$d*$c,$f=$e+$A[!$b],$g=$a?$g*sqrt($f):1,$h=$g%2];echo$r[$argv[1]][ord($argv[2])%32-1];

Try it online!

The example gives back the n value of a OEIS sequence for the following letters. A letter greater h is for this example a invalid input

  • a https://oeis.org/A001477 numbers
    $a Valid first sequence

  • b https://oeis.org/A000035 mod 2
    $b=$a&1 Valid use the variable in the sequence before

  • c https://oeis.org/A109613 odd numbers
    $c=$a+!$b Valid Can use sequences before

  • d https://oeis.org/A110654 a(n) = floor(n/2) + n mod 2
    $d=(($c-!$b)/2^0)+$b Valid an invalid example is $d=(($a/2)^0)+$b cause it not use the sequence before

  • e https://oeis.org/A000217 triangular
    $A[$b]=$e=$d*$c Valid you can create help variables

  • f https://oeis.org/A000290 square
    $f=$e+$A[!$b] Valid use a help variabale and the variable of the sequence before. $f=$A[!$b]+$A[!$b] Invalid causes it makes the same value but use indirectly the variable of the sequence before

  • g https://oeis.org/A000142 factorial $g=$a?$g*sqrt($f):1 Valid cause your condition is not always the case that it have no relationship to the sequence before.

  • h https://oeis.org/A019590 Fermat's Last Theorem $h=$g%2 Valid but now we have the problem to find the next sequence

Could You make a full alphabet? My alphabet ends with the letter h

| |
\$\endgroup\$
  • \$\begingroup\$ I'm rather confused as to what is being asked here. It might be helpful to state how one can get from one sequence to another. \$\endgroup\$ – Ad Hoc Garf Hunter Jun 10 '17 at 20:47
  • \$\begingroup\$ @WheatWizard I could understand you. The problem is at the moment to make rules that avoid that a trivial solution exits. There are too many sequences in OEIS. The way from every sequence to the next should not end in a simple addition or multiplication. But evrything else should be allowed to get more creative solutions \$\endgroup\$ – Jörg Hülsermann Jun 10 '17 at 20:56
  • \$\begingroup\$ (1) The first sentence says that the aim is to build the longest chain possible, but the scoring mechanism rewards average code length per element in the chain rather than number of chains. I would think it most likely as it stands that the winner would be a chain of length 1 or at most 2. (2) If you delete everything from the header Example to the end, do you think that the question still makes sense? If not (and I don't think it does), it needs a lot of work. (3) What do the two values in the input mean? Why is the second one a letter rather than a number? \$\endgroup\$ – Peter Taylor Jun 10 '17 at 21:10
  • \$\begingroup\$ (4) I'm not sure how feasible it is to write objective rules which forbid "trivial" expressions. (5) It is not clear how to interpret the rule about the 32nd term where either it is not known or the sequence is finite and shorter than 32 terms. \$\endgroup\$ – Peter Taylor Jun 10 '17 at 21:12
  • \$\begingroup\$ @PeterTaylor (1) Think you that popularity Contest is a better winning criteria? (2+3) to limit the chaining length to 26. The goal is to show relationsships between two or more sequences. (4+5) Yes it is not easy and I can drop it if I switch to popularity Contest \$\endgroup\$ – Jörg Hülsermann Jun 10 '17 at 21:26
  • \$\begingroup\$ @WheatWizard I allow now trivial solutions \$\endgroup\$ – Jörg Hülsermann Jun 10 '17 at 21:53
  • \$\begingroup\$ I'm not clear on the purpose of the inputs if we're just supposed to hard code our way from one sequence to the next​. Replacing your PHP example with more generic, more verbose pseudo-code might help. \$\endgroup\$ – Shaggy Jun 11 '17 at 0:16
  • \$\begingroup\$ @programmer5000 exists a limit of correct tags? \$\endgroup\$ – Jörg Hülsermann Jun 11 '17 at 11:39
  • \$\begingroup\$ @Shaggy See it as restriction for ways to code. You must have a chaining to the sequence before. So far I know any working code is a pseudocode \$\endgroup\$ – Jörg Hülsermann Jun 11 '17 at 11:48
-2
\$\begingroup\$

Print a Variable's Memory Address

Similar to this puzzle I posted earlier, with a difference that should make this challenge easier.

Create a function (not a full program) that prints or returns the memory address of the parameter passed in. Literal values should return a falsey value.

Examples:

var foo = 4901
var bar = "foobarbaz"
var baz = true

getMemoryAddress(from: foo) // 0x00000000004030f0
getMemoryAddress(from: bar) // 0x00000000004030f8
getMemoryAddress(from: baz) // 0x0000000000403110
getMemoryAddress(from: "Bad Value") // false

Note that you probably won't get the same exact result as show above.

| |
\$\endgroup\$
  • \$\begingroup\$ Example(s) please. \$\endgroup\$ – Shaggy Jun 15 '17 at 15:15
  • \$\begingroup\$ @Shaggy Updated. \$\endgroup\$ – Caleb Kleveter Jun 15 '17 at 15:38
-2
\$\begingroup\$

Migrate questions to and from the Sandbox!

Challenge

Write user scripts that will migrate challenges to and from the Sandbox.

Criteria

These are my suggestions for criteria that will create the most beautiful user scripts. Feel free to suggest your own!

Migrating to the Sandbox

The script should...

  • only act on a question that has been closed for "unclear what you're asking"
  • answer the Sandbox as the original author of the question
  • make the title and tags the first line of the answer as a H1-sized header
  • link the original question to the Sandbox post, and then delete it

Migrating from the Sandbox

The script should...

  • use the first line to determine the title and tags for the post, and eliminate it from the post body
    • error handling here would be a good idea
  • create the question as the author of the Sandbox answer
  • comment on the question with a link to the Sandbox answer
  • replace the Sandbox answer with just the title and link to the question, then delete the Sandbox answer

Scoring

This is a , so the answer with the highest net of votes will win.

Sandbox

  • Is what I'm asking for even possible? I've never written a user script before. Maybe it should be a question?
  • Should this be a Community effort rather than a challenge? Does it even belong on main?
| |
\$\endgroup\$
  • \$\begingroup\$ This is not within the capabilities of a userscript. Also, automating this wouldn't really help at all, since the sandbox only does anything if the poster wants to use it. Anyway, if you disagree with me and still want to pursue this, it should be a question on meta, asking if people want a sandbox migration bot. \$\endgroup\$ – FryAmTheEggman Jun 20 '17 at 4:15
  • \$\begingroup\$ @FryAmTheEggman Thanks for your feedback! I've asked on meta as you suggested. \$\endgroup\$ – musicman523 Jun 20 '17 at 4:45
-2
\$\begingroup\$

Grep for math in a pdf document

This challenge is likely to need the use of libraries. You may use any free library of your choice as well as any library.

The challenge is simply to write a tool that can grep for "2^n" in a pdf document. That is the math that represents 2 to the power n. You may assume that the pdf was produced from LaTeX which contains $2^n$ and that the pdfr was made using the command line tool pdflatex.

What should the code do?

The code should take a pdf file as input either by reading a file or from standard in. It should output if the file contains "2^n" or not.

Scoring

I will provide a number of pdf files as test examples. Your score will just be how many your code gets right.

Requests for help

I could provide sample pdf documents that do or do not contain 2^n in them.

Does it always appear as an image in the pdf as Mego suggests? If so, this image will depend on the font and font size and this is an image processing task.

| |
\$\endgroup\$
  • 2
    \$\begingroup\$ 1. How are you going to score this? Code golf? Popularity contest? 2. PDFs can vary wildly in how something is displayed. If you're specifying that it's produced from a specific program in a specific way, then it's likely just a search for a static string of bytes, which is IMO a boring challenge. 3. What exactly is the output? Is it a simple yes/no, or is it supposed to be location within the file? \$\endgroup\$ – Shelvacu Jul 1 '17 at 19:37
  • \$\begingroup\$ @Shelvacu I was going to score by how often the code gives the right answer. I would ideally like the code to output the first page number it finds 2^n on but I don't know if that is too hard. If it is then the output is just yes/no. \$\endgroup\$ – user9206 Jul 2 '17 at 17:38
  • \$\begingroup\$ So test-battery. \$\endgroup\$ – user202729 Mar 23 '18 at 14:35
-2
\$\begingroup\$

Braid Badly Boundlessly


Your program or function must, given a string in any standard input format, output an infinite stream of delimiter-separated strings where each string is determined from the previous by a braiding algorithm. The program starts with printing the input string.

The algorithm is described as follows: Infinitely alternate between

(1) splitting the string into three substrings then swapping the first two substrings and flattening.

and

(2) splitting the string into three substrings then swapping the last two substrings and flattening.

starting with (1).

The three substrings should be of non-increasing length with the maximum length no more than 1 greater than the minimum length of the three substrings. (This means that when the length of the given string is a multiple of three, the three substrings should be the same length. When the length of the given string is one more than a multiple of three, the first substring should be one character longer than each of the last two substrings. When the length of the given string is two more than a multiple of three, the first and second substrings should each be one character longer than the last substring.)

Example

Let the input be "abcdefg". Let the delimiter be a newline.

Then the program would first print "abcdefg".

It applies (1) which splits the string into ["abc","de","fg"] and swaps the first two elements, reaching ["de","abc","fg"]. It flattens to get "deabcfg" which it prints and uses for the next step.

The program applies (2) to "deabcfg" to split into ["dea","bc","fg"] and swaps into ["dea","fg","bc"], flattening to reach "deafgbc".

The program applies (1) to "deafgbc" and the process repeats ad infinitum.

Then the output would be the newline-separated

abcdefg
deabcfg
deafgbc
fgdeabc
fgdbcea
bcfgdea
bcfeagd
eabcfgd
eabgdcf
gdeabcf
gdecfab
cfgdeab
cfgabde
abcfgde
abcdefg
deabcfg
deafgbc
fgdeabc
fgdbcea
bcfgdea
bcfeagd
eabcfgd
eabgdcf
gdeabcf
gdecfab
cfgdeab
cfgabde
abcfgde
abcdefg
[...]

Specifications

  • Note that the string should not be split at the beginning and then only swapped later. The string should be split on each and every iteration
  • The delimiter between lines could be whichever character is convenient. You may assume it does not appear in the input string.
  • The string input shall be at least three characters
  • The input consists solely of printable characters (0x20-0x7F)
  • Of course, standard loopholes are forbidden.

I/O

  • The input and output should be taken in standard I/O methods.
  • The input and output should be taken as string, list of characters, or equivalent.
  • The output should be output continuously, which means you may assume infinite memory.

Test cases

For the test cases, we will assume that the delimiter is a newline. Just the portion before the endless stream is repeats is shown.

input
--
output
-----
abcdefg
--
abcdefg
deabcfg
deafgbc
fgdeabc
fgdbcea
bcfgdea
bcfeagd
eabcfgd
eabgdcf
gdeabcf
gdecfab
cfgdeab
cfgabde
abcfgde
-----
abc
--
abc
bac
bca
cba
cab
acb
-----
abcdefgh
--
abcdefgh
defabcgh
defghabc
ghadefbc
ghabcdef
bcdghaef
bcdefgha
efgbcdha
efghabcd
habefgcd
habcdefg
cdehabfg
cdefghab
fghcdeab
fghabcde
abcfghde
abcdefgh
-----
Braid
--
Braid
aiBrd
aidBr
dBair
dBrai
radBi
raidB
idraB
idBra
Brida
-----
Cycle
--
Cycle
clCye
cleCy
eCcly
eCycl
yceCl
ycleC
leycC
leCyc
Cylec
-----
O Canada!
--
O Canada!
anaO Cda!
anada!O C
da!anaO C
da!O Cana
O Cda!ana
-----
A man, a plan, a canal - panama!
--
A man, a plan, a canal - panama!
an, a canalA man, a pl - panama!
an, a canal - panama!A man, a pl
 - panama!Aan, a canal man, a pl
 - panama!A man, a plan, a canal
 man, a pla - panama!An, a canal
 man, a plan, a canal - panama!A
n, a canal  man, a pla- panama!A
n, a canal - panama!A man, a pla
- panama!A n, a canal man, a pla
- panama!A man, a plan, a canal 
man, a plan- panama!A , a canal 
man, a plan, a canal - panama!A 
, a canal -man, a plan panama!A 
, a canal - panama!A man, a plan
 panama!A m, a canal -an, a plan
 panama!A man, a plan, a canal -
an, a plan, panama!A m a canal -
an, a plan, a canal - panama!A m
 a canal - an, a plan,panama!A m
 a canal - panama!A man, a plan,
panama!A ma a canal - n, a plan,
panama!A man, a plan, a canal - 
n, a plan, panama!A maa canal - 
n, a plan, a canal - panama!A ma
a canal - pn, a plan, anama!A ma
a canal - panama!A man, a plan, 
anama!A mana canal - p, a plan, 
anama!A man, a plan, a canal - p
, a plan, aanama!A man canal - p
, a plan, a canal - panama!A man
 canal - pa, a plan, anama!A man
 canal - panama!A man, a plan, a
nama!A man, canal - pa a plan, a
nama!A man, a plan, a canal - pa
 a plan, a nama!A man,canal - pa
 a plan, a canal - panama!A man,
canal - pan a plan, a ama!A man,
canal - panama!A man, a plan, a 
ama!A man, canal - pana plan, a 
ama!A man, a plan, a canal - pan
a plan, a cama!A man, anal - pan
a plan, a canal - panama!A man, 
anal - panaa plan, a cma!A man, 
anal - panama!A man, a plan, a c
ma!A man, aanal - pana plan, a c
ma!A man, a plan, a canal - pana
 plan, a cama!A man, anal - pana
 plan, a canal - panama!A man, a
nal - panam plan, a caa!A man, a
nal - panama!A man, a plan, a ca
a!A man, a nal - panamplan, a ca
a!A man, a plan, a canal - panam
plan, a cana!A man, a al - panam
plan, a canal - panama!A man, a 
al - panamaplan, a can!A man, a 
al - panama!A man, a plan, a can
!A man, a pal - panamalan, a can
!A man, a plan, a canal - panama
lan, a cana!A man, a pl - panama
lan, a canal - panama!A man, a p
l - panama!lan, a canaA man, a p
l - panama!A man, a plan, a cana
A man, a pll - panama!an, a cana
| |
\$\endgroup\$
-2
\$\begingroup\$

Rock Paper Scissors, but it's a big, custom tournament

We all know "Rock, Paper, Scissors", and it's pretty variated.

A world tournament is held every year, and it's dang popular.

However, the contestants are able to bring their own ways of play to the plate, and they play with them.

The challenge:

Create a program that, by process of elimination through RPS, determines the winner of the tournament.

The tournament rules:

  • No slackers. (Let the amount of players be an integer equally divisible by 2. [In other words, an even number.])

  • You can bring 2 of either of the 4 variants:

    None: Play regular RPS.

    RPSLV: Play "Rock, Paper, Scissors, Lizard, Spock" (play diagram shown here).

    Best out of three: Play 3 rounds; if by round 2, a player wins the round and has two points, they auto win. Else, winner of the next round wins.

    Double RPS: Play with four hands (two hands used by each player).

  • You cannot bring two of the same variant.

  • In order to use a variant, the two players must have the same type of variant. If there are no matching variants, the gameplay is automatically None.

  • However, if there are more than one variant matches, a game of mode None will be played. The winner of the game mentioned decides what mode they play for the match they will play to see who goes to the next round.

  • In the case of a tie, replay until a win occurs (for all modes)

  • There can be only one winner.

The coding rules:

  • All choices must be randomized (no strategies, to make this simple.).

  • No standard loopholes.

  • Give an explanation as much as you can. (If possible, include a "Try it out online" sample.)

Sample Input/Output:

You must make a table variable with all the player numbers, from 1 to n, with two variants for each player.

n = the amount of players you intend to enter.

Example Input:

Player # | Var 1 | Var 2
1        | RSPLV | None
2        | None  | x2 RPS
3        | x2 RPS| Boo3
4        | Boo3  | x2 RPS
...      |...    | ...

Make a func() that:

1: Checks the variants of the next two availible players on the list, starting at player 1, then does the second to third last rules depending on what happens.

2: Makes the pair engage in battle, gameplay depending on the chosen variant.

3: Finally, boot the loser off the game and add the winner to the next list (round). (The "boot the loser" part isn't that required, but I recommend so as to not make the program add a player to the next table.)

Output (uses table from input):

 Round 1:
 1 vs. 2 // None, since the None variant matches both of them
 ["Rock"/*1*/,"Scissors"/*2*/]
 1 wins

 3 vs. 4 // They have more than one match, so they fight for who decides
 ["P"/*3*/,"S"/*4*/]
 4 wins, and chooses Best out of 3 
 Match 1:
 ["P"/*3*/,"R"/*4*/] // 1(3) - 0(4)

 Match 2:
 ["P"/*3*/,"S"/*4*/] // 1(3) - 1(4)

 Match 3:
 ["P"/*3*/,"R"/*4*/] // 2(3) - 1(4)
 3 wins

 Round 2:
 1 vs. 4 //No matches, defaults to None
 ["R"/*1*/,"R"/*4*/] // No-one wins
 ["R"/*1*/,"S"/*4*/]
 1 wins the tournament

Misc. requirements (some optional):

A {!} means it is required.

  • {!} Print each match, and who wins.

  • {!} Print the tournament winner.

  • {!} The number of players must be flexible.

  • Print the table for each round.

Scenarios:

None:

a vs. b //Either they have no matches, or they have both None matches
["R"/*a*/,"S"/*b*/]
a wins

RPSLV (will make this one quick):

a vs. b //RPSLV chosen
["V"/*a*/,"L"/*b*/]
b wins

Best out of Three:

Scenario 1: (a tie occurs at match 2)

a vs. b //Boo3 chosen
Match 1:
["P"/*a*/,"S"/*b*/] // 0(a) - 1(b)

Match 2:
["P"/*a*/,"P"/*b*/] // tie
["P"/*a*/,"S"/*b*/] // 1(a) - 1(b)

Match 3:
["R"/*a*/,"S"/*4*/] // 2(a) - 1(b)
a wins

Scenario 2: (a player has two points by the end of match 2)

a vs. b //Boo3 chosen
Match 1:
["P"/*a*/,"S"/*b*/] // 0(a) - 1(b)

Match 2:
["S"/*a*/,"P"/*b*/] // 0(a) - 2(b)
b automatically wins

Double RPS:

a vs. b //x2 RPS chosen
[("R", "P")/*a*/, ("S", "S")/*b*/] // lock
[("P", "P")/*a*/, ("S", "S")/*b*/]
b wins

Both the coding and tournament rules apply to your code.

For sandbox use only (won't be included in real question)

I don't know if this kind of problem is suitable for code golf, it could be a programming puzzle, I'm not sure. Go ahead in the comments and tell me what mode it should be, and if I should improve it. (Also, sorry for the mix of Python lists and C++ comments, if it confuses you.) A ** means the choice is random.

| |
\$\endgroup\$
  • \$\begingroup\$ Hi and welcome to PPCG, and thanks for using the sandbox! I had a hard time following what you intended from this challenge. The rules are rather disorganised with many points early on not making sense until later. For example, you say: "No slackers. (Let p be a number equally divisible by 2.)" before it is clear that you intend for us to implement a single elimination tournament. I had no idea what "p" was supposed to mean, or why this should matter. I'd recommend trying to explain this to someone verbally, perhaps, to try to organise your thoughts better. Good luck! \$\endgroup\$ – FryAmTheEggman Jul 15 '17 at 21:50
  • \$\begingroup\$ Ah, thanks. I will edit the problem. \$\endgroup\$ – S.G. Harmonia Jul 15 '17 at 22:03
  • \$\begingroup\$ I'm not quite sure what we're supposed to implement. The controller for the tournament and what else? Do we also implement the players, so that we're simulating the entire thing? Or do we have to provide some kind of API for the players? In the first case, how does "The winner decides what mode they play" work? \$\endgroup\$ – Peter Taylor Jul 16 '17 at 7:14
  • \$\begingroup\$ Again, any multi-choice is random. \$\endgroup\$ – S.G. Harmonia Jul 16 '17 at 19:29
-2
\$\begingroup\$

Quick! Tell me all the numbers from 1 to 100,000!

Your task is to write a program or function that, when run, output all the numbers from 1 to 100 thousand as quickly as possible to STDOUT. It's that simple. All answers are tested on an HP Compaq nx9420 with an Intel Core Duo @ 1.83 GHz and 3 gigs of RAM using the time command.


Of course, standard loopholes are strictly forbidden.
This is , so may the fastest code win and the best programmer prosper...

| |
\$\endgroup\$
  • 3
    \$\begingroup\$ Have you tried running an example to see if the times are variable enough to be meaningful? As-is, this is going to be strongly dependent upon how fast the code can do I/O, which makes the challenge pretty uninteresting, IMO. \$\endgroup\$ – AdmBorkBork Jul 19 '17 at 18:16
  • \$\begingroup\$ @AdmBorkBork Might be interesting \$\endgroup\$ – ckjbgames Jul 19 '17 at 21:12
  • 1
    \$\begingroup\$ As far as I can tell, this takes less than a tenth of a second, which means submissions will probably be differentiated solely by noise on your computer. \$\endgroup\$ – FryAmTheEggman Jul 20 '17 at 2:37
  • \$\begingroup\$ upvoted, though I think the differenciation is really difficult, unless you test it on a raspberry PI (for example) having ONLY the program and its compiler installed. \$\endgroup\$ – V. Courtois Jul 20 '17 at 13:36
  • \$\begingroup\$ @FryAmTheEggman How could I improve on that? \$\endgroup\$ – ckjbgames Jul 20 '17 at 23:38
  • 1
    \$\begingroup\$ @V.Courtois I do have a Pi, and I think I will use that (it has Raspbian installed). \$\endgroup\$ – ckjbgames Jul 20 '17 at 23:39
  • \$\begingroup\$ The time is still so small even a basic operating system will have to much noise in process creation, etc, for this to work out. You need to make what we are computing substantially more complicated for this to be reasonable. \$\endgroup\$ – FryAmTheEggman Jul 21 '17 at 0:10
  • \$\begingroup\$ @FryAmTheEggman K \$\endgroup\$ – ckjbgames Jul 21 '17 at 1:20
  • \$\begingroup\$ @ckjbgames good then :) \$\endgroup\$ – V. Courtois Jul 21 '17 at 5:26
-2
\$\begingroup\$

Is it cat-urday?

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

The catch:

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

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

Don't forget leap years!


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

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

Lennyface parser and selector

Your mission

Create, in the language of your choice, a program that outputs a randomly selected lennyface (artistic minifigures, see this) from an input - a string composed of numbers and lennyfaces. You will have to : first, parse this input; second, extract a probability mass function f from the parsed input; third, select and output a lennyface respecting f. Read the rules for more details.

Rules

  • Input : A string with lennyfaces and numbers (positive AND negative integers), separated by newlines. You may take input by STDIN or function parameter for example.
  • Output (STDOUT for example) : the randomly-selected lennyface, as a string.
  • The input creates a probability mass function f. If l is a lennyface, then f(l)=(sum of all numbers since the previous lennyface)/x where x is obtained afterwards by summing each of those numerators. @Sandbox : is it clear enough?
  • If (sum of all numbers since the previous lennyface) is equal to zero or negative, you must do as if the numerator is equal to 1 in f's definition.
  • A line with a number contains only this number ; same for a line with a lennyface. So you can assume there will never be a number in a lennyface.
  • If there is nothing on a line (two newlines in a row), you must consider it as a lennyface.
  • You must consider that the last line of the string is directly before its first line. See Test 1 for an example.
  • You can assume there will be at least 1 lennyface in the list; it cannot be composed just by numbers (don't forget that an empty line is a lennyface too).

Example

Given this input list :

( ͡° ͜ʖ ͡°)
2
¯\_ツ_/¯
34
-4
8
└[⸟‿⸟]┘

1

You must have 1/42 chances of outputting ( ͡° ͜ʖ ͡°), 2/42 chances of outputting ¯\_ツ_/¯, 38/42 chances of outputting └[⸟‿⸟]┘ and 1/42 chances of outputting nothing (line 7).

Test cases

Test 1

(⌐■_■)
3

Must output (⌐■_■) with 3/3 chances.

Test 2

ʢ◉ᴥ◉ʡ

Must output ʢ◉ᴥ◉ʡ with 1/1 chance.

Test 3

0
\(ᗝ)/

Must output \(ᗝ)/ with 1/1 chance.

Test 4

( ͡° ͜ʖ ͡°)
2
¯\_ツ_/¯
34
4
☞   ͜ʖ  ☞

0

Must output ( ͡° ͜ʖ ͡°) with 1/42 chance, ¯\_ツ_/¯ with 1/21 chance, ☞  ͜ʖ  ☞ with 19/21 chances and nothing with 1/42 chance.

Test 5

1



( ͡° ͜ʖ ͡°)

Must output ( ͡° ͜ʖ ͡°) with 1/4 chance and nothing with 3/4 chance, since there are 3 empty lines.

Test 6

42

-1
( ͡° ͜ʖ ͡°)

Must output nothing with 43/44 chance and ( ͡° ͜ʖ ͡°) with 1/44 chance.

@Sandbox : should I add test cases?

This is , so shortest code in bytes wins. Standard loopholes apply.

Note : Please do not be discouraged if the parsing is difficult to handle in your language, or if testing is hard because of randomness. Your solution might be very interesting algorithmically, not obviously in terms of golfing. Just please explain in your answer why it works.

Moreover, this is the first code-golf I create, so please let me know if something is not appropriate or if I should give more details on a point. And overall, if you downvote, explain me why so I can improve it.

| |
\$\endgroup\$
  • \$\begingroup\$ Yours tests seems a bit contraditory. The number is the chance of the next face (line), so what's the point of the empty line in the example / test 4? By the same logic, the test1 should have a 3/4 of outputting nothing? What is the point of the 0 in the test 4? \$\endgroup\$ – Rod Jul 3 '17 at 14:03
  • \$\begingroup\$ Why is the chance of outputting ( ͡° ͜ʖ ͡°) 1/42 and not 0 ? (since there are no numbers above it) \$\endgroup\$ – Dada Jul 3 '17 at 14:04
  • \$\begingroup\$ Sorry ! I forgot to copy paste the fact that the minimal chance is 1! \$\endgroup\$ – V. Courtois Jul 3 '17 at 14:05
  • \$\begingroup\$ Also, a common thing to do on challenges involving randomness, and therefore, hard to test, is to ask people to provide a mandatory explanation, or at least ask them to show why it works. \$\endgroup\$ – Dada Jul 3 '17 at 14:05
  • \$\begingroup\$ @Dada thanks. I note this. \$\endgroup\$ – V. Courtois Jul 3 '17 at 14:06
  • \$\begingroup\$ @Rod the empty line is a lennyface, as said here : If there is nothing on a line, you must consider it as a lennyface. \$\endgroup\$ – V. Courtois Jul 3 '17 at 14:08
  • \$\begingroup\$ @V.Courtois I meant and empty line without a preceding number \$\endgroup\$ – Rod Jul 3 '17 at 14:09
  • \$\begingroup\$ As I said, the minimum is one (sorry again for forgetting it). \$\endgroup\$ – V. Courtois Jul 3 '17 at 14:10
  • 1
    \$\begingroup\$ If only positive integers are to be expected, you should write it. Otherwise, give some details and examples about what you consider "numbers". \$\endgroup\$ – Dada Jul 3 '17 at 14:12
  • \$\begingroup\$ @Dada editing. In fact I said the minimum is 1, but you can have things like 2,-1,-3,17 and then your lennyface ; that means the probability is 15/ total. \$\endgroup\$ – V. Courtois Jul 3 '17 at 14:14
  • \$\begingroup\$ @V.Courtois just a small suggestion, to make the "list as circle" more explicit you could change the value to something else than 0 or 1, this way it would not overlap the "missing number" rule \$\endgroup\$ – Rod Jul 3 '17 at 14:15
  • \$\begingroup\$ @Rod does it? Sorry if I'm not getting what you are saying, but the list is always a circle, meaning if your list is 2,3,( ͡° ͜ʖ ͡°),4,5,☞  ͜ʖ  ☞,6, you have 6+2+3 chance of getting ( ͡° ͜ʖ ͡°) and 4+5 chance of getting ☞  ͜ʖ  ☞. \$\endgroup\$ – V. Courtois Jul 3 '17 at 14:18
  • \$\begingroup\$ thanks for editing @musicman523 \$\endgroup\$ – V. Courtois Jul 4 '17 at 7:21
  • 5
    \$\begingroup\$ KISS. This is far more complicated than common sense would require. Deliberately overcomplicating things to make it "more difficult" is a guaranteed method to make a bad question. \$\endgroup\$ – Peter Taylor Jul 4 '17 at 7:32
  • 1
    \$\begingroup\$ The challenge has two parts as far as I can tell. a) Create a probability mass function from an input by parsing b) sample from the probability mass function. Part a) needs to be rewritten as it is at best ambiguous and at worst just incorrect. \$\endgroup\$ – user9206 Jul 5 '17 at 7:50
-2
\$\begingroup\$

Output the infinite sequence of middle positions of odd square numbers

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

n=1 => 1
*

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

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

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

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

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

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

Hello, Quine!

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


Rules

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

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

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

Complicating Simple Maths

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

Goal:

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

Examples:

Input: 5 - 1
Output: 5 + 2i

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

Rules:

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

  • No standard loopholes.

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

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

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

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

  • This is , so shortest answer wins.

Sandbox use only:

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

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

The Self-Referential Algorithm

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

Your task

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

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

| |
\$\endgroup\$
-2
\$\begingroup\$

The Compressor

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

[list to come]

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

Rules

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

Examples

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

Alternative:

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

7160708104901559695507628057638725214364226867212714872539720713967912042100814603497742352846014272

Write the shortest possible program that outputs this number.


Related: No strings (or numbers) attached

Questions? Clarifications?

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

Ulam spiral 2

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

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

enter image description here

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

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

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

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

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

Proposal:

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

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

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

Rules

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

.

func dummy() {
}
print_first_native_instruction_byte(dummy)

would print :

0x90

which is a nop instruction on x86.

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

Winner

The one with the shortest code… Import statements included.

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

Preposition, not possession

Enthralling background

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

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

What will be censored? Any overt references to ownership.

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

Let's get specific

Example

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

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

Algorithmically

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

Here are some more examples:

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

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

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

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

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

Output the first digit of Graham's number

Code golf

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

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

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

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

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

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

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

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

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

Sandbox questions

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

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

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

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

Requirements

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

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

Winner

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

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

Brainf*** Polygot

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

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

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

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

Gatherer Golf: The 61 Dwarves

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

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

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

Rules

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

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

xkcd-esque Reverse Code Golf

Introduction

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

enter image description here

So I set out on making this challenge!

Challenge

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

Rules

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

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

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

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

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

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

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

Scoring criteria:

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

Examples

Valid:

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

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

Invalid:

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

Hope this meets PPCG puzzle criteria :D

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

Bees?

Inspired by SCP-3045

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

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

The program should then output these modifications.

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

Move a window around the screen

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

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

Output a Random Bit

Your task is simple: print either 1 or 0.

Chosen uniformly randomly every time.

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

Specifications

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

You must log in to answer this question.

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