19
\$\begingroup\$

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

\$\endgroup\$
13
  • 4
    \$\begingroup\$ Why accept the last answer? That makes it seem like you win for adding a requirement nobody can meet. \$\endgroup\$
    – xnor
    Mar 8, 2017 at 23:46
  • 6
    \$\begingroup\$ For example, "the md5 hash of the program must be ..." \$\endgroup\$ Mar 8, 2017 at 23:51
  • 3
    \$\begingroup\$ Even 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. \$\endgroup\$
    – xnor
    Mar 8, 2017 at 23:59
  • 3
    \$\begingroup\$ @StephenS Well, people seem not be playing to win, so looks like my concern is misplaced. \$\endgroup\$
    – xnor
    Mar 9, 2017 at 2:13
  • 3
    \$\begingroup\$ This should be called 'Scope Creep' \$\endgroup\$ Mar 9, 2017 at 15:28

11 Answers 11

8
\$\begingroup\$

Answer 1 - 05AB1E

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

¾
\$\endgroup\$
0
7
\$\begingroup\$

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))
\$\endgroup\$
6
\$\begingroup\$

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!

\$\endgroup\$
6
\$\begingroup\$

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.

¼,≡ƒ,²,*,
\$\endgroup\$
6
\$\begingroup\$

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!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ @R.Kap No problem :) \$\endgroup\$
    – Stephen
    Mar 9, 2017 at 0:10
  • 3
    \$\begingroup\$ When I read the new requirement, for some reason I started laughing. +1. \$\endgroup\$
    – sporkl
    Mar 9, 2017 at 0:11
5
\$\begingroup\$

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)&
\$\endgroup\$
1
  • 2
    \$\begingroup\$ Yep, hence my hasty edit after I saw that EricRoe beat me by a minute :) \$\endgroup\$ Mar 9, 2017 at 1:05
4
\$\begingroup\$

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

\$\endgroup\$
2
  • \$\begingroup\$ Yes this is also golfed :-) \$\endgroup\$ Mar 12, 2017 at 9:18
  • \$\begingroup\$ Also, before commenting, no, I can't just use j instead of jb, since then I would be using a join-on-newlines builtin. \$\endgroup\$ Mar 12, 2017 at 9:19
4
\$\begingroup\$

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>

\$\endgroup\$
1
  • 1
    \$\begingroup\$ 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) \$\endgroup\$ Mar 9, 2017 at 12:35
3
\$\begingroup\$

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!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Yes this is golfed. \$\endgroup\$ Mar 12, 2017 at 7:42
3
\$\begingroup\$

C (gcc), submission #11, 432 bytes

n,m,z,c,q,a,s,t;A(a,b){return b?A(b,a%b):a;}B(n){if(n<=1)return 1-1;for(int i=2;i<n;i++)if(n%i==1-1)return 1-1;return 1;}C(n,c,z){while(c<n){if(B(z++))c++;}return z-1;}D(n){return(!n||n==1)?n:(D(n-1)+D(n-2));}main(){putchar(48);scanf("%d",&n);t=s=n;while(--t)s+=n;printf("\n%d\n%d\n",D(n),s);scanf("%d",&m);q=A(n, m);a=n;while(--m-1)n+=n;printf("%d\n",n);putchar(49);for(z=0;z<432;z++)putchar(48);printf("\n%d\n%d",C(a,1-1,1-1),q);}

I hereby ban line endings appearing anywhere in the source code :v).

Try it online!

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Been a while since I posted this, but I believe your answer must conform to your added requirement :) \$\endgroup\$
    – Stephen
    Jul 17, 2020 at 17:49
  • 1
    \$\begingroup\$ > The answer must fulfill all requirements up to and including the current answer. Oh crap! hahaha. I'll get it done in a second \$\endgroup\$ Jul 17, 2020 at 17:50
  • 1
    \$\begingroup\$ Done! I swapped it to line endings :p \$\endgroup\$ Jul 17, 2020 at 17:57
2
\$\begingroup\$

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

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.