You Are the User: Create the Requirements

15

2

My boss* does not understand why her programmers react negatively to users changing program requirements. Help her understand! On every answer, create a new requirement. Then, write a program/function that solves that requirement and all prior requirements, while in a new programming language.

Examples

User 1 posts the first answer. He specifies that the program must output "Hello, World." He creates a program in Java that outputs "Hello, World."

User 2 posts the second answer. She specifies that the program must accept input n and output the nth prime, up to the language's number max. She creates a program in C++ that accepts input n and outputs the nth prime and outputs "Hello, World." She could not have created a program in Java.

User 3 posts the third answer. He specifies that the program source cannot contain the text "Hello". He creates a function in Python that accept input n and outputs the nth prime and "Hello, World." while not using the text "Hello" in his source. He could not have created a program in Java or C++.

Answer Format

#Answer # - <language name> [version, if pertinent]

Requirement: <rule>.

<code>

[explanations, encoding, TIO link, etc.]

Answer Rules

  • The answer must follow the above format, or similar.

  • The answer can be a program or a function.

  • The answer must fulfill all requirements up to and including the current answer.

  • The same user may not post two answers in a row.

  • If two answers are posted with the same number, the one posted later should be deleted.

  • Do not edit your requirement unless you messed up badly and no other answers have been posted.

  • If your answer does not comply with your rule and all other rules, it is invalid. Try to fix this before someone else posts the next answer.

  • Different versions of the same language only count as different languages if the program or function created in either version will behave differently in the other version.

  • The answer may not accept any input not required, and may not output anything not required except for necessary whitespace. However, while behind the scenes the program must fulfill all "hidden" (from the user) requirements, it may do whatever else you want it to, especially if you must fulfill an execution time requirement.

Requirement Rules

  • The requirement must only specify one requirement. This requirement can be conditional, and if this requirement requires an input and/or an output, this may be included.

  • The requirement may not remove or modify prior requirements, or conflict with them, but may extend one (specify which).

  • If the requirement restricts the source (), or requires text in the source, it may only remove a single string (e.g. 0, Hello), or require a single character.

  • The requirement cannot require the source to be under 100 bytes, require a specific encoding, or, in and of itself, rule out a majority of common languages.

  • The requirement may not force the source to conform to a certain pattern (for example, starting each line with a certain character, or (@Conor) hashing to a certain value) other than that specified in restricted source.

This is , so all answers build on previous answers. I and maybe others will try to keep a list of all requirements. To see answers in order, you can sort by oldest. To see the newest answer, sort by oldest, then navigate to the end of the list.

How to Win (changed for hold vote):

When no answer is posted for two weeks, the challenge is over, and scores will be calculated. The scores will be calculated by summing the totals number of answers by each user, but weighting posts based on how far into the chain they are (since the later posts have more requirements, they are harder).

Pseudocode:

for each answer in user.Answers {
   score += 1 + (answer.number / 100)
}

Example:

Sally has three answers. She posted answer 5, answer 7, and answer 20.

Her score will be 1.05 + 1.07 + 1.2 = 3.32. If it was a straight sum of answers, her score would be 3, but the weighting of chain depth rewards harder answers.

To start:

Here is the first requirement, given by my boss*:

Requirement 0: The program must output 0 before anything else.

*fictional

List of Requirements and Languages

Note that this may be out of date - please look at the last posted answer immediately prior to posting your answer to ensure you are fulfilling every requirement. I am very sorry if you create an exquisite program, only for someone to snipe it - if you really really want to post it anyway, specify non-competing.

Full (but maybe not current) Requirement: Cannot contain 0, * or ] in the source code, and cannot use a join-on-newline builtin. Outputs 0, then takes a non-negative integer input n and outputs a newline followed by the 0-indexed nth Fibonacci number (may be 1 indexed), followed by a newline, followed by the same input n squared, followed by a newline, followed by n multiplied by a new input m, followed by a newline, followed by 10^B, where B is the number of bytes in the source code, followed by a newline, followed by the nth 0-indexed (may also be 1-indexed) prime number, followed by a newline, followed by the Greatest Common Divisor of n and m.

0: The program must output 0 before anything else. Language: N/A
1: The program source cannot contain 0. Language: 05AB1E
2: The program takes a non-negative integer input n and outputs a newline followed by the 0-indexed n'th Fibonacci number (may be 1 indexed). Language: dc
3: The program outputs a newline, followed by the same input n squared. Language: J
4: The program outputs a newline, followed by n multiplied by a new input m. Language: Ohm
5: The program cannot contain * (ASCII code 0x2A). Language: Python 3
6: The program outputs a newline, followed by 10^B, where B is the number of bytes in the source code. Language: Mathematica
7: The program outputs a newline, followed by the nth 0-indexed (may also be 1-indexed) prime number. Language: JavaScript (ES6)
8: The program does not use a join-on-newlines builtin, but can use any other join builtin. Language: Jelly
9: The program outputs a newline followed by the Greatest Common Divisor of n and m. Language: Scala
10: The program cannot contain ]. Language: Pyth

Current Scores (ordered by first post)

Okx: 1.01
R. Kap: 2.09
Conor O'Brien: 1.03
Nick Clifford: 1.04
Eric Rose: 1.05
Greg Martin: 1.06
Erik the Outgolfer: 2.18
math_junkie: 1.09

Stephen

Posted 2017-03-08T23:29:23.387

Reputation: 12 293

3Why accept the last answer? That makes it seem like you win for adding a requirement nobody can meet. – xnor – 2017-03-08T23:46:23.370

@xnor your program has to fulfill that requirement. So at least you have to be able to meet it. Though if you can obfuscate it enough, kudos to you. – Stephen – 2017-03-08T23:47:48.107

1To go along with what xnor said, I'd suggest accepting the second-to-last answer, to make sure that the requirement added in the winning answer is in fact possible. – ETHproductions – 2017-03-08T23:48:30.610

I believe it would possible to create a requirement that's only possible in the language you answer in, though the rules on restricted-source requirements may have that covered well enough... – ETHproductions – 2017-03-08T23:50:53.063

1(Also, welcome to PPCG!) – ETHproductions – 2017-03-08T23:51:02.027

5For example, "the md5 hash of the program must be ..." – Conor O'Brien – 2017-03-08T23:51:57.830

@ETHproductions Thank you! I tried to rule that out with this section: "or, in and of itself, rule out a majority of common languages." Not sure if that is sufficient - I would be OK if a requirement, combined with other requirements created by other users, made it harder for other languages to compete, but not if a single requirement eliminated a swath of languages. – Stephen – 2017-03-08T23:52:17.120

1Perhaps something like "The requirement must not rely on hashing" would be sufficient. I'd add a more general rule, but I can't pinpoint what exactly to rule out that's more general than hashing. Randomness or near-randomness, maybe? – ETHproductions – 2017-03-08T23:56:13.430

2Even if the rules hold up to prevent a requirement that ends the chain, I still think having a "win condition" encourages people to make near-impossible rules rather than fun ones. – xnor – 2017-03-08T23:59:58.620

@ETHproductions edited in new requirement rule, I believe that should fix that. Thanks! – Stephen – 2017-03-09T00:01:19.780

Hmm... that's not really a win condition, more of another restriction. – ETHproductions – 2017-03-09T00:04:05.917

2@StephenS Well, people seem not be playing to win, so looks like my concern is misplaced. – xnor – 2017-03-09T02:13:39.207

2This should be called 'Scope Creep' – NonlinearFruit – 2017-03-09T15:28:47.490

Answers

2

Answer 10 - Pyth

Requirement: Takes two inputs, n (>=0) and m. Outputs 0 without the use of 0, * or ] anywhere in the source code, and without builtins for joining on newlines. Then outputs a newline followed by the 1-indexed nth Fibonacci number (may be 0 indexed), followed by a newline, followed by n squared, followed by a newline, followed by n multiplied by m, followed by a newline, followed by 10^B where B is the number of bytes in the source code, followed by a newline and the nth 1-indexed (may also be 0-indexed) prime number, and finally followed by a newline and the Greatest Common Divisor of n and m.

JU2KE=H2VQ=+Js>2J=+YK=hHW!P_H=hH;jb[ZeJ^Q2sY^T51HiK

Online interpreter

Erik the Outgolfer

Posted 2017-03-08T23:29:23.387

Reputation: 38 134

Yes this is also golfed :-) – Erik the Outgolfer – 2017-03-12T09:18:02.720

Also, before commenting, no, I can't just use j instead of jb, since then I would be using a join-on-newlines builtin. – Erik the Outgolfer – 2017-03-12T09:19:47.303

6

Answer 1 - 05AB1E

Requirement: Prints 0... without a 0 in the source code

¾

Okx

Posted 2017-03-08T23:29:23.387

Reputation: 15 025

4

Answer 2 - dc

12298P?sa1 1-sb1sc[lblcdsb+scla1-dsa1 1-<y]dsyxlcp

Requirement: Outputs 0 without 0 in the source code, then takes a non-negative integer input n and outputs a newline followed by the 0-indexed n'th Fibonacci number (may be 1 indexed).

Try it online!

R. Kap

Posted 2017-03-08T23:29:23.387

Reputation: 4 730

@R.Kap No problem :) – Stephen – 2017-03-09T00:10:48.037

2When I read the new requirement, for some reason I started laughing. +1. – Comrade SparklePony – 2017-03-09T00:11:11.547

4

Answer 3 - J

echo"+(1-1),(*:,~[:+/@:!&i.-)@".1!:1(3)

Requirement: Outputs 0 without 0 in the source code, then takes a non-negative integer input n and outputs a newline followed by the 0-indexed n'th Fibonacci number (may be 1 indexed), followed by a newline, followed by the same input n squared.

Try it online!

Conor O'Brien

Posted 2017-03-08T23:29:23.387

Reputation: 36 228

4

Answer 4 — Ohm

Requirement: Outputs 0 without 0 in the source code, then takes a non-negative integer input n and outputs a newline followed by the 0-indexed nth Fibonacci number (may be 1 indexed), followed by a newline, followed by the same input n squared, followed by a newline, followed by n multiplied by a new input m.

¼,≡ƒ,²,*,

Nick Clifford

Posted 2017-03-08T23:29:23.387

Reputation: 1 184

4

Answer 5 - Python 3

Requirements: Outputs 0 without 0 in the source code, then takes a non-negative integer input n and outputs a newline followed by the 0-indexed nth Fibonacci number (may be 1 indexed), followed by a newline, followed by the same input n squared, followed by a newline, followed by n multiplied by a new input m. Do not use the character *, ASCII code 0x2A.

    def f(n, m):
        print(1-1)
        a = 1-1
        b = 1
        for i in range(n):
            c = a+b
            a = b
            b = c
        print(b)
        print(n.__mul__(n))
        print(n.__mul__(m))

EricRoe

Posted 2017-03-08T23:29:23.387

Reputation: 41

3

Answer 6 — Mathematica

Requirement: Outputs 0 without 0 or * in the source code, then takes a non-negative integer input n and outputs a newline followed by the 0-indexed nth Fibonacci number (may be 1 indexed), followed by a newline, followed by the same input n squared, followed by a newline, followed by n multiplied by a new input m, followed by a newline, followed by 10^B where B is the number of bytes in the source code.

((e=Echo)[1-1];e@Fibonacci@#;e[#^2];e[1##];2^# 5^#&@59)&

Greg Martin

Posted 2017-03-08T23:29:23.387

Reputation: 13 940

1Yep, hence my hasty edit after I saw that EricRoe beat me by a minute :) – Greg Martin – 2017-03-09T01:05:27.280

2

Answer 7 - JavaScript (ES6)

(a,b)=>String.fromCharCode(48)+'\n'+(m=(a)=>a>1?m(a-1)+m(a-2):1)(a)+'\n'+Math.pow(a,2)+'\n'+Math.exp(Math.log(a)+Math.log(b))+'\n'+1E257+'\n'+(T=(u,i=2,l=1-1,m=2)=>l<=u?(p=(o,z=2,s=1-1)=>z<o?p(o,z+1,s+(o%z<1&&z!=o)):s)(i)<1?T(u,i+1,l+1,i):T(u,i+1,l,m):m)(a)

Requirement: A function that takes two inputs, a non-negative integer n and any number m and returns a string containing 0 without the use of 0 anywhere in the source code, then a newline followed by the 0-indexed nth Fibonacci number (may be 1 indexed), followed by a newline, followed by n squared, followed by a newline, followed by n multiplied by m without the use of * anywhere in the source code, followed by a newline, followed by 10^B where B is the number of bytes in the source code, and finally followed by a newline and the nth 0-indexed (may also be 1-indexed) prime number.

Test Snippet

S=(a,b)=>String.fromCharCode(48)+'\n'+(m=(a)=>a>1?m(a-1)+m(a-2):1)(a)+'\n'+Math.pow(a,2)+'\n'+Math.exp(Math.log(a)+Math.log(b))+'\n'+1E257+'\n'+(T=(u,i=2,l=1-1,m=2)=>l<=u?(p=(o,z=2,s=1-1)=>z<o?p(o,z+1,s+(o%z<1&&z!=o)):s)(i)<1?T(u,i+1,l+1,i):T(u,i+1,l,m):m)(a)
m: <input type="number" min=0 id="i1"></input>
<br>
n: <input type="number" step="0.01" id="i2"></input>
<br>
<input type="button" value="Submit" onclick="console.log(S(document.getElementById('i1').value, document.getElementById('i2').value))"></input>

R. Kap

Posted 2017-03-08T23:29:23.387

Reputation: 4 730

You could save a considerable amount of bytes by changing String.fromCharCode(48) to 1-1. Not that it really matters ;-) (Also, there are two zeroes later on in the source code, which you can fix in the same way) – ETHproductions – 2017-03-09T12:35:02.877

1

Answer 8 - Jelly

Requirement: A function that takes two inputs, a non-negative integer n and any number m and returns a string containing 0 without the use of 0 anywhere in the source code, then a newline followed by the 0-indexed nth Fibonacci number (may be 1 indexed), followed by a newline, followed by n squared, followed by a newline, followed by n multiplied by m without the use of * anywhere in the source code, followed by a newline, followed by 10^B where B is the number of bytes in the source code, and finally followed by a newline and the nth 0-indexed (may also be 1-indexed) prime number. No builtins for joining on newlines allowed, but joining builtins still allowed.

ÆḞṭØDW⁺¤;⁸²¤;×;ȷ25;⁸ÆN¤j⁷

Try it online!

Erik the Outgolfer

Posted 2017-03-08T23:29:23.387

Reputation: 38 134

Yes this is golfed. – Erik the Outgolfer – 2017-03-12T07:42:07.463

1

Answer 9 - Scala

Requirements: Takes two inputs, n (>=0) and m. Outputs 0 without the use of 0 or * anywhere in the source code, and without builtins for joining on newlines. Then outputs a newline followed by the 1-indexed nth Fibonacci number (may be 0 indexed), followed by a newline, followed by n squared, followed by a newline, followed by n multiplied by m, followed by a newline, followed by 10^B where B is the number of bytes in the source code, followed by a newline and the nth 1-indexed (may also be 0-indexed) prime number, and finally followed by a newline and the Greatest Common Divisor of n and m.

(n:Int,m:Int)=>{
 val z=1-1;val o=println _;var i=1;var j=z
 o(z)
 o((1 to n).foldLeft(z,1)((a,b)=>(a._2,a._1+a._2))._1)
 o(math.pow(n,2))
 o(List.fill(n)(m).sum)
 o(math.pow(9+1,299))
 while(j!=n){i+=1;if((2 to i-1)forall(i%_!=z))j+=1};o(i)
 o((1 to math.min(n,m)).filter(c=>n%c==z&&m%c==z).last)
}

Try it out here

math junkie

Posted 2017-03-08T23:29:23.387

Reputation: 2 490