A number adder, not a death adder
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!
Vyxal `Ṫ`, 3 bytes …
3y ago
Japt, 4 bytes P1 is: …
3y ago
[Haskell], 64 bytes …
3y ago
Ruby, 28 bytes ```ruby put …
3y ago
[PHP], 58 28 bytes P1: …
3y ago
[Ahead], 10 bytes IO"@O …
3y ago
[C (gcc)], 87 bytes P1: …
3y ago
[Python 3], 58 39 bytes P1: …
3y ago
J, 7 char ``` '+/',": `` …
2y ago
ESCR, 35 bytes show "show [ …
2y ago
J, 21 bytes ```J ,&'+".1!: …
2y ago
Ruby, 25 bytes ```ruby put …
3y ago
Rockstar, 40 bytes list …
3y ago
[Lua], 51 bytes P1: …
3y ago
14 answers
Vyxal Ṫ
, 3 bytes
?\?
Outputs N1?
, which when run with the same flag as P1, will add the two inputs together.
0 comment threads
Haskell, 64 bytes
main=do a<-getLine;putStr$"main=getLine>>=print.("++a++"+).read"
0 comment threads
Python 3, 58 39 bytes
P1:
print(f"print(int(input())+{input()})")
P2 (given I inputted 10
, 30 22 bytes):
print(int(input())+10)
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
C (gcc), 87 bytes
P1:
i;main(){scanf("%d",&i);printf("i;main(){scanf(\"%%d\",&i);printf(\"%%d\",%d+i);}",i);}
Generated P2 for input 10:
i;main(){scanf("%d",&i);printf("%d",10+i);}
0 comment threads
Ruby, 25 bytes
puts"p #{gets}+gets.to_i"
P1 - Try this online!
P2 - Try this online!
0 comment threads
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)
0 comment threads
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.
0 comment threads
Lua, 51 bytes
P1:
print("print(tonumber(io.read())+"..io.read()..")")
P2 (given I inputted 10, 29 bytes):
print(tonumber(io.read())+10)
0 comment threads
J, 7 char
'+/',":
Sample runs:
'+/',": 6
+/6
+/6 5
11
'+/',": 55
+/55
+/55 45
100
1 comment thread