A+B Problem
A+B problem is a challenge that reads two decimal integers, add, and output.
Usually, the input value is constrained in some way.
For languages that can't do I/O, the "input" is done by manually modifying the program before it is executed so that it stores its two numbers in the memory, the "output" is done by storing the result in the memory.
Implementations
!Мова
Since !Мова doesn't have interger conversion. We will have to make variable a and b
(a,7) (b,3) (c,a+b) Пачаць main Скажы "A:" a {пр} Скажы "B:" b {пр} Скажы "Result:" c {пр} Стоп
$+-?
$------------------------------------------------A?p-$+$aP$
1
111*111*111*11*1*,111*111*11*1*,*1,
4ME
ns ns + get
Adj
ADJ 1 a X ADJ 1 b X ADJ a b X ADJ 0 a X
Aheui
방방다망희
Befunge
&&+.@
BracketOnly
(()()()()()()()()()()()()()()()())((()())((()()()()()()()()()()()())()(()()()()()()()()()()()())()))
Brain-Flak
({}{})
Brainf*ck
>[,,,++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++]<>[.]<
Only supports adding one-digit numbers, numbers have to be separated by exactly one space:
Input: 1 2 Output: 3
brainfuck
- More implementations at A+B Problem/brainfuck.
This implementation accepts any number of decimal integers separated by spaces. It will add them all up and output the result in decimal.
>,[-------------------------------->+<[>>+++++++++ [>>> [<+>->[>]>[>]+[<]<[<]>]<< [->+<<]<- ]>>>[>]+[>]<-<[<]<<<<---------------- [>>>>>[>]+[<]<<<<-] >>]>[->>>>[-<<<<<+>>>>>>]<<<<+>>]<<-<,]>>>>>[-<<<<<+>>>>>>]<<----------<<<< [ [<]>->[>]>>+ [>[+<-]<[->---------<<]>+>[<-]<[->---------->>+<]>] >[<<<]< ] >>>>[>>>]<<<[++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.<<<]
In the first stage, characters are read from STDIN while an accumulated value is stored in unary on the tape. For each digit character, the accumulated value is multiplied by 10 and the character’s value added to it. For each space character, the accumulated value is appended to the previous accumulated value and a new one started. When input runs out, the result is available in unary. The second stage converts the unary number back into decimal, then converts digits to ASCII and outputs them.
Brainfuck+
;>;<a:
Brainfuck+2
Unlike brainfuck, you don't have to handle number input/output yourself, which results in a more simple program:
';>;[<+>-]<:
It turns off overflow mode to accept all unbounded unsigned integers.
Brainfuck extended
(@(+%)
BrainZ
The following programs are in hex dump
01 55 55 55 55 55 55 55 55 55 55 55 55 20 20 2A AA AA AA AA AA AA AA AA AA AA AA A1 46 41 1F FF FF FF FF FF F0 20
Both the input and the result have to be one-digit numbers, and the two numbers in the input are separated by exactly one space (or any other character, but there must be exactly one).
Actually I have a better one that uses algorithms mentioned in brainfuck algorithms.
0A 09 0A 0C 21 41 21 41 01 0C 2A AA AA 84 85 07 F0 8A AA 94 11 51 10 A4 FF E2 20 92 14 46 48 23 20 82 08 82 48 50 48 50 61 0A 09 0A 08 08 61 55 55 54 24 28 3F 84 55 54 A0 8A 88 85 27 FF 11 04 90 A2 32 41 19 04 10 44 11 0A 22 32 48 23 FF 88 85 32 84 C9 04 86 14 64 13 24 11 11 11 10 49 0A 09 27 FF 10 A5 09 92 09 0C 28 C8 26 48 22 22 22 09 0A 09 21 3F 85 1F F2 08 81 11 99 0A 08 22 11 0A 51 07 F0 A7 FC 41 20 42 82 08 8F E1 47 FC 82 20 40
It only works on 8 bit cells, and the numbers in the input and the result should not exceed 255. The two numbers in the input are separated by line feeds.
bruh():bruh()
bruh():out(add(in(),in()))
C
#include<stdio.h> void main() { int x,y; scanf("%d%d",&x,&y); printf("%d",x+y); }
C++
#include<iostream> using namespace std; int main() { int x,y; cin >> x >> y; cout << (x+y) << endl; return 0; }
C#
using System; class Program { static void Main(string[] args) { Console.WriteLine(Convert.ToInt64(Console.ReadLine())+Convert.ToInt64(Console.ReadLine())); } }
Chicken
Only supports one-digit A+B, for example, input is 1 2
and output will be 3
.
chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken
Chinese
定义 甲,乙,丙 为 整数 读入 甲 读入 乙 丙=甲+乙 打印 丙
Deadfish++
yrya~[0]+[1];rmao
enGLish
Declare a variable named a, initially 0 Input x Declare a variable named b, initially 0 Input y Declare a variable named sum, initially 0 Store the sum of a and b into sum Output sum
Expansion
[0 0]=0 [0 1]=1 [0 2]=2 [0 3]=3 [0 4]=4 [0 5]=5 [0 6]=6 [0 7]=7 [0 8]=8 [0 9]=9 [1 0]=1 [1 1]=2 [1 2]=3 [1 3]=4 [1 4]=5 [1 5]=6 [1 6]=7 [1 7]=8 [1 8]=9 [1 9]=10 [2 0]=2 [2 1]=3 [2 2]=4 [2 3]=5 [2 4]=6 [2 5]=7 [2 6]=8 [2 7]=9 [2 8]=10 [2 9]=11 [3 0]=3 [3 1]=4 [3 2]=5 [3 3]=6 [3 4]=7 [3 5]=8 [3 6]=9 [3 7]=10 [3 8]=11 [3 9]=12 [4 0]=4 [4 1]=5 [4 2]=6 [4 3]=7 [4 4]=8 [4 5]=9 [4 6]=10 [4 7]=11 [4 8]=12 [4 9]=13 [5 0]=5 [5 1]=6 [5 2]=7 [5 3]=8 [5 4]=9 [5 5]=10 [5 6]=11 [5 7]=12 [5 8]=13 [5 9]=14 [6 0]=6 [6 1]=7 [6 2]=8 [6 3]=9 [6 4]=10 [6 5]=11 [6 6]=12 [6 7]=13 [6 8]=14 [6 9]=15 [7 0]=7 [7 1]=8 [7 2]=9 [7 3]=10 [7 4]=11 [7 5]=12 [7 6]=13 [7 7]=14 [7 8]=15 [7 9]=16 [8 0]=8 [8 1]=9 [8 2]=10 [8 3]=11 [8 4]=12 [8 5]=13 [8 6]=14 [8 7]=15 [8 8]=16 [8 9]=17 [9 0]=9 [9 1]=10 [9 2]=11 [9 3]=12 [9 4]=13 [9 5]=14 [9 6]=15 [9 7]=16 [9 8]=17 [9 9]=18 *[''A'' ''B'']
Replace A and B to the two numbers you want to add, they must be one-digit.
Factor
1550312130344523405322670672726144276060320428835586125982062278216873380299547785445888965317356993578998458894062824590818181343465544643203278969789760306483260898195025071606514680066312822882289150961729164240257496460164711229028838279617380759313885377180750696493806042467569915139382024410955786156745725726158898119
Both the input and the result have to be one-digit numbers, and the two numbers in the input are separated by exactly one space (or any other character, but there must be exactly one).
Actually I have a better one that uses algorithms mentioned in brainfuck algorithms.
223410076043971245540455586062108671976382093084650814048455942695029728847248299149137635554999424822108920506098868033476214459320120499009107004136078049794893673781761295204469664667935339948220791969940797178711884552892973753625015470549096824911093718441469356768533249165014176626741614824403577081277068387982322629535712447454364104489588780254372499850172986326729405696524997412110326083025627210689998917530563991619062944140202877791117569707740865348999991542007107447224733604600000527878988213435845838869570404281302989627799961769506811874060021300896611729156306973830638599329303622560576731383760330633151857809874340774202118735387543078461597660714598235881914663270305145053382281893795661261671652072174089103101132267118681988227624613185931131543618491818705958774014872388695403663087930058282062807944776002596264627880492322717384703232216135346484920131957918341425918130884150142467794506237984533771367614705105664172251120356711890741861382387138254921794223791411080320254372901167902742308408394759875459949509185990551844055573095741697932045088640395955024237597472362455681672376050549253700368981271604291990235515264750252871044914433037348488635473615344302888662605466698658948109839364491561884085899786063927241502662408998462517291640998101657371778834680047837565519172095276588293322125139653792272461457837353049108094141833488627267796682360797868482152871439304768041176143520773935566597
It only works on 8 bit cells, and the numbers in the input and the result should not exceed 255. The two numbers in the input are separated by line feeds.
Func++
intoutput(add(intinput(),intinput())
Funciton
This program requires several of the library functions — to make it a fully self-contained program, all of those functions could be pasted in.
╔════╗ ┌───╖ ╔═══╗ ║ 32 ╟─┤ ǁ ╟─╢ ║ ╚════╝ ╘═╤═╝ ╚═══╝ ┌─┴─╖ ┌───╖ ┌───╖ │ ɱ ╟─┤ ∑ ╟─┤ 》 ╟─ ╘═╤═╝ ╘═══╝ ╘═══╝ ┌───╖ ╔═╧═╕ ╔═══╗ ┌─┤《 ╟─╢ ├─╢ 0 ║ │ ╘═══╝ ╚═╤═╛ ╚═══╝ └─────────┘
The program first splits (ǁ
) the input string at the spaces (32
), uses map (ɱ
) to convert each substring to an integer (《
), sums those integers (∑
) and converts the result back to a string (》
).
G#
integer assign a;b as input make main; [ assign #a as #b + print(#a) ]
Gofe
,&s,As.
Headache (lang that compiles to brainfuck)
void main(){ int a; int b; #a; #b; @((a+b) as int); }
It supports 32-bit integers, the compiled brainfuck program is 135420 bytes long so I'm not gonna show it here.
How dare you fuck the brain
IIIII # Input 1 ^IIIII # Input 2 vI^D)vNH
H̱
H̱hHhH̱HhH̱H̱hHhH̱HH̱HhhH̱HhH̱H̱hHhH̱HH̱h
HZCode
听听加说停
Java
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int a=sc.nextInt(); int b=sc.nextInt(); System.out.println(a+b); } }
JavaScript
function add(a,b){ console.log(a+b); }
I use a function, because it seems that JavaScript has no functions for input.
This is an alternative for browser JS only:
f=prompt;alert(+f()+(+f()))
JSFuck
This is a JScrew.it conversion from f=prompt;alert(+f()+(+f()))
, works only in new browsers (Chrome, Firefox, Edge, Safari and Opera), 3559 bytes, if you have a shorter one please replace this.
[][(![]+[])[+!![]]+(!![]+[])[+[]]][([]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[!![]+!![]+!![]]+(!![]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[+!![]+[+[]]]+([][[]]+[])[+!![]]+(![]+[])[!![]+!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+[])[+[]]+([]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[!![]+!![]+!![]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[+!![]+[+[]]]+(!![]+[])[+!![]]]((!![]+[])[+!![]]+(!![]+[])[!![]+!![]+!![]]+(!![]+[])[+[]]+([][[]]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+[])[+!![]]+(+[![]]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[+!![]+[+!![]]]+(!![]+[])[!![]+!![]+!![]]+([![]][+(+[]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[!![]+!![]+[+[]]]]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[!![]+!![]+!![]+[+[]]]+(![]+[])[+!![]]+(![]+[])[!![]+!![]])()((![]+[])[+[]]+([]+[])[(![]+[])[+[]]+(!![]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[+!![]+[+[]]]+([][[]]+[])[+!![]]+(!![]+[])[+[]]+([]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[!![]+!![]+!![]]+(!![]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[+!![]+[+[]]]+(![]+[])[!![]+!![]]+(!![]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[+!![]+[+[]]]+(!![]+[])[+!![]]]()[+!![]+[+!![]]]+(+(!![]+!![]+[+!![]]+(+[])+(+[])+(+!![])+(!![]+!![])+(!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![])+(!![]+!![]+!![]+!![]+!![])))[(!![]+[])[+[]]+(!![]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[+!![]+[+[]]]+([]+[])[([]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[!![]+!![]+!![]]+(!![]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[+!![]+[+[]]]+([][[]]+[])[+!![]]+(![]+[])[!![]+!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+[])[+[]]+([]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[!![]+!![]+!![]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[+!![]+[+[]]]+(!![]+[])[+!![]]][([][[]]+[])[+!![]]+(![]+[])[+!![]]+([]+(+[])[([]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[!![]+!![]+!![]]+(!![]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[+!![]+[+[]]]+([][[]]+[])[+!![]]+(![]+[])[!![]+!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+[])[+[]]+([]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[!![]+!![]+!![]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[+!![]+[+[]]]+(!![]+[])[+!![]]])[+!![]+[+!![]]]+(!![]+[])[!![]+!![]+!![]]]](!![]+!![]+!![]+[+[]])+(!![]+[])[+[]]+([]+[])[(![]+[])[+[]]+(!![]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[+!![]+[+[]]]+([][[]]+[])[+!![]]+(!![]+[])[+[]]+([]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[!![]+!![]+!![]]+(!![]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[+!![]+[+[]]]+(![]+[])[!![]+!![]]+(!![]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[+!![]+[+[]]]+(!![]+[])[+!![]]](([]+[])[(![]+[])[+[]]+(!![]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[+!![]+[+[]]]+([][[]]+[])[+!![]]+(!![]+[])[+[]]+([]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[!![]+!![]+!![]]+(!![]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[+!![]+[+[]]]+(![]+[])[!![]+!![]]+(!![]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[+!![]+[+[]]]+(!![]+[])[+!![]]]())[!![]+!![]+!![]+[+[]]]+(![]+[])[+!![]]+(![]+[])[!![]+!![]]+(!![]+[])[!![]+!![]+!![]]+(!![]+[])[+!![]]+(!![]+[])[+[]]+([]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[+!![]+[+!![]]]+(+(+!![]+(!![]+[])[!![]+!![]+!![]]+(+!![])+(+[])+(+[]))+[])[!![]+!![]]+(![]+[])[+[]]+([]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[+!![]+[+!![]]]+([]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[+!![]+[!![]+!![]]]+(+(+!![]+(!![]+[])[!![]+!![]+!![]]+(+!![])+(+[])+(+[]))+[])[!![]+!![]]+([]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[+!![]+[+!![]]]+(+(+!![]+(!![]+[])[!![]+!![]+!![]]+(+!![])+(+[])+(+[]))+[])[!![]+!![]]+(![]+[])[+[]]+([]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[+!![]+[+!![]]]+([]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[+!![]+[!![]+!![]]]+([]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[+!![]+[!![]+!![]]]+([]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[+!![]+[!![]+!![]]])
This is a JScrew.it conversion from (f,t)=>f+t
, works in the browser and in Node.js, 1644 bytes, if you have a shorter one please replace this.
[][(![]+[])[+!![]]+(!![]+[])[+[]]][([]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[!![]+!![]+!![]]+(!![]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[+!![]+[+[]]]+([][[]]+[])[+!![]]+(![]+[])[!![]+!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+[])[+[]]+([]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[!![]+!![]+!![]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[+!![]+[+[]]]+(!![]+[])[+!![]]]((!![]+[])[+!![]]+(!![]+[])[!![]+!![]+!![]]+(!![]+[])[+[]]+([][[]]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+[])[+!![]]+(![]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[!![]+!![]+[+[]]]+(!![]+[])[!![]+!![]+!![]]+([]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[!![]+!![]+[+!![]]]+(![]+[])[+!![]]+(![]+[])[!![]+!![]])()(([]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[+!![]+[+!![]]]+[][(![]+[])[+[]]+(![]+[])[!![]+!![]]+(![]+[])[+!![]]+(!![]+[])[+[]]][([]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[!![]+!![]+!![]]+(![]+[])[+!![]]+(![]+[])[!![]+!![]]+(![]+[])[!![]+!![]]]((![]+[])[+[]]+(!![]+[])[+[]])+([]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[+!![]+[!![]+!![]]]+([]+[])[(![]+[])[+[]]+(!![]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[+!![]+[+[]]]+([][[]]+[])[+!![]]+(!![]+[])[+[]]+([]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[!![]+!![]+!![]]+(!![]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[+!![]+[+[]]]+(![]+[])[!![]+!![]]+(!![]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[+!![]+[+[]]]+(!![]+[])[+!![]]]()[+!![]+[+!![]]]+([]+[])[([![]]+[][[]])[+!![]+[+[]]]+(!![]+[])[+[]]+(![]+[])[+!![]]+(![]+[])[!![]+!![]]+([![]]+[][[]])[+!![]+[+[]]]+([]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[!![]+!![]+!![]]+(![]+[])[!![]+!![]+!![]]]()[!![]+!![]]+(![]+[])[+[]]+(+(+!![]+(!![]+[])[!![]+!![]+!![]]+(+!![])+(+[])+(+[]))+[])[!![]+!![]]+(!![]+[])[+[]])
Mode Spam
,,,z,>,>,z<}<+{<,,,,z>o
ObjLang
e9oFcHJpbnRbAgAAAHvaCGludGlucHV0WwAAAAAwe3IBAAAAWwAAAAAwMA==
Unmarshalled form:
{'print': [{'intinput': []}, {'intinput': []}]}
PostScriptum
AFAIK, IO pls a pls b read a read b ASAP (e.g.:a,b)
Powershell
$a=read-host $b=read-host $c=[Convert]::ToInt32($a)+[Convert]::ToInt32($b) write-host $c
Python
print(sum([int(i) for i in input().split()]))
Or:
print(int(input())+int(input()))
You also can write this:
a = int(input()) b = int(input()) c = a + b; print(c)
Sokolang
### #*# ##I#### #@*.O*# #..#### #.# ### --- @:13 i:13 o:1,11 --- rudwup2[dlr]dwp2u2rplwplwprlwp2r2lud
Spam
Hear a, please read line 4. I want to tell you a secret, please read line 1. I just want to say, you are fooled. Hear b, please read line 6. Say a, please read line 3. Add a by b, please read line 5.
Spoiler:
∅|^ī|^ī+"∅
Stack-based
VAR x I x VAR y I y VAR z A x y z O z
Standard modern vernacular
定义整型变量 A 、 B 和 C 。 读入 A 和 B,然后将 A+B 存储到 C 中。 输出 C 的值。
Stringle
The number of characters in e
represents the upper bound for a
and b
.
e "!!!!!!!!!!!!!!!!" e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e a $ b $ f e #e a #f b g e f $ #g
Subleq
a b
are the inputs.
0 0 5 a b 4 0 8 0 3 11 0 -1 -1
first make address 0 -b, then substract a by -b to make a+b.
TESTLANG
in push in in push in op add
This esolang is not a push-down automata
,,+.