Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

A number adder, not a death adder

+5
−0

Create a program P1 which takes as input a base 10 number N1 (the numbers for the variables are important). Given N1, P1 will print a program P2. P2 will take as input a base 10 number N2 and output N1+N2.

P1 and P2 have to be in the same language.

If your language doesn't have STDIN, for P1 and P2 you may specify a placeholder in your answer where the "input" would be.

The person who creates the shortest scoring program wins. Have fun, everyone!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

Are [functions](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@z/P1i61LDFHIwHIUKnOq9XOS9D8n5yfV5yfk6qXk5@... (2 comments)

14 answers

You are accessing this answer with a direct link, so it's being shown above all other answers regardless of its score. You can return to the normal view.

+1
−0

C (gcc), 87 bytes

P1:

i;main(){scanf("%d",&i);printf("i;main(){scanf(\"%%d\",&i);printf(\"%%d\",%d+i);}",i);}

Try it online!

Generated P2 for input 10:

i;main(){scanf("%d",&i);printf("%d",10+i);}

Try it online!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+3
−0

Japt, 4 bytes

P1 is:

+"+U

Try it

Which outputs P2, where N1 is the input from P1:

N1+U

Try it

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+3
−0

Vyxal , 3 bytes

?\?

Try it Online!

Outputs N1?, which when run with the same flag as P1, will add the two inputs together.

Try it Online!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+2
−0

Haskell, 64 bytes

main=do a<-getLine;putStr$"main=getLine>>=print.("++a++"+).read"

Try it online!

Run both programs

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+1
−0

PHP, 58 28 bytes

P1:

<?="<?=\$argv[1]+$argv[1];";

Try it online!

Golfed 30 bytes thanks to @Shaggy's advice.

P2 (given I inputted 10):

<?=$argv[1]+10;

Try it online!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

28 bytes (1 comment)
+1
−0

Ahead, 10 bytes

IO"@O+I"W@

This prints N1I+0@.

Try it online!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+1
−0

Ruby, 28 bytes

puts"puts #{gets}+gets.to_i"

puts"puts                     # print P2, which prints
          #{gets}             # P1's input value, interpolated
                 +gets.to_i"  # plus P2's input value

For instance, if the input to P1 is 10, then P2 is

puts 10+gets.to_i

Attempt This Online!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

-1b when using $><< instead of puts (3 comments)
+1
−0

Python 3, 58 39 bytes

P1:

print(f"print(int(input())+{input()})")

Try it online!

P2 (given I inputted 10, 30 22 bytes):

print(int(input())+10)

Try it online!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

39 bytes (1 comment)
+0
−0

Lua, 51 bytes

P1:

print("print(tonumber(io.read())+"..io.read()..")")

Try it online!

P2 (given I inputted 10, 29 bytes):

print(tonumber(io.read())+10)

Try it online!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+0
−0

Ruby, 25 bytes

puts"p #{gets}+gets.to_i"

P1 - Try this online!

P2 - Try this online!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+0
−0

J, 7 char

'+/',": 

Sample runs:

'+/',": 6

+/6

+/6 5

11


'+/',": 55

+/55

+/55 45

100

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+0
−0

J, 21 bytes

,&'+".1!:1(3)'1!:1(3)

Try it online!

STDIN is ugly in J because you have to use foreigns.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+0
−0

ESCR, 35 bytes

show "show [+ [arg 1] " [arg 1] "]"

The SHOW command writes to standard output. The parameters in quotes are just fixed strings. The ARG function returns a numbered argument. In the case of programs, these are command line parameters. Running this program with 13 as example parameter yields:

show [+ [arg 1] 13]

Which writes the value of the first command line parameter plus 13 to standard output.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+0
−0

Rockstar, 40 bytes

listen to N
say "listen to N
say N-0+"+N

Which outputs P2, where X is the input from P1:

listen to N
say N-0+X

Try it here (Code will need to be pasted in)

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

Sign up to answer this question »