| Bytes | Lang | Time | Link |
|---|---|---|---|
| 004 | How dare you fuck the brain | 241008T203114Z | Gleb |
| 010 | Regenerate | 220210T051314Z | DLosc |
| 025 | SAKO | 250323T072239Z | Acrimori |
| 001 | Uiua | 250205T174540Z | Joonas |
| 029 | Positionally | 220614T004643Z | emanresu |
| 008 | 7 | 181118T183642Z | ais523 |
| 002 | Branch | 210417T185722Z | hyperneu |
| 038 | Bespoke | 250115T185010Z | Josiah W |
| 005 | BrainChild ASM | 250114T221807Z | ATaco |
| 025 | Hatchback | 250114T154044Z | madeforl |
| 666 | SqueezeL | 250110T183332Z | AlephSqu |
| 037 | Qdeql | 240909T011231Z | Bbrk24 |
| 001 | Jelly | 160702T004637Z | Dennis |
| 003 | Pyth | 210928T194910Z | adrianus |
| 006 | Brainfuck extended | 240407T130017Z | None1 |
| 017 | in floop | 220130T052127Z | emanresu |
| 020 | Swift | 230723T224452Z | macOSist |
| 001 | Ultrarisky | 220201T204340Z | emanresu |
| 023 | MSWLogo | 230414T134117Z | badatgol |
| 229 | Logically | 230412T055538Z | ATaco |
| 009 | awk | 221219T041710Z | RARE Kpo |
| 711 | Billiards | 170212T022135Z | hyperneu |
| 015 | RubyGolf | 161010T193025Z | anna328p |
| 005 | Sesos | 160724T211540Z | acrolith |
| 012 | ObjectiveJava*#++Script.NETnotation.sh | 220627T021817Z | aketon |
| 011 | Quipu | 220729T233527Z | DLosc |
| 015 | Trianguish | 220729T232027Z | naffetS |
| 022 | Cubestack | 220627T010655Z | tybocopp |
| 005 | CATHY | 220626T220229Z | naffetS |
| 013 | makina | 220421T125324Z | Ginger |
| 1168 | SPDT | 220420T183523Z | rydwolf |
| 479 | Lexurgy | 220401T210745Z | bigyihsu |
| 023 | Fennel | 220401T152101Z | Alan Bag |
| nan | 220317T010116Z | carne | |
| 003 | Noxan | 220315T135940Z | Alan Bag |
| 003 | PostScript | 220225T095404Z | Toby Spe |
| 275 | sed | 161010T160629Z | Toby Spe |
| 010 | dotcomma | 200824T002506Z | rydwolf |
| 005 | Halfwit | 220221T073743Z | emanresu |
| 019 | tinylisp | 220220T232436Z | Axuary |
| 176 | Plumber | 191211T155735Z | rydwolf |
| 010 | Kotlin | 211219T085105Z | random p |
| 006 | APOL | 220109T185843Z | Myōga |
| 001 | Neutrino | 220109T032251Z | emanresu |
| 172 | CSS | 211218T172743Z | sheepsbl |
| 002 | Ly | 211218T093948Z | cnamejj |
| 002 | x86_32 machine code | 160724T071923Z | davey |
| 003 | abcn | 210909T080513Z | Eternal |
| 244 | TypeScript Compiler | 210828T141210Z | Bbrk24 |
| 021 | CSASM v2.5.1 | 210827T194722Z | absolute |
| 000 | Vyxal s | 210827T111249Z | emanresu |
| 028 | A0A0 | 210704T192713Z | stefvans |
| 002 | Concurr | 210311T182410Z | Wezl |
| 004 | Yggdrasil | 210417T182619Z | caird co |
| 005 | Duocentehexaquinquagesimal | 210416T171739Z | Makonede |
| 012 | BrainF*ck | 210309T202240Z | iamkai |
| 012 | Swift | 210311T195027Z | Eric Xue |
| 237 | Scratch 3.0 scratchblocks3 syntax | 210307T172940Z | qarz |
| 004 | ARM Thumb2 machine code | 210210T193334Z | EasyasPi |
| 022 | Kotlin | 210210T184822Z | grian |
| 097 | Brainetry | 200614T141543Z | RGS |
| 403 | Mornington Crescent | 200614T010119Z | Cloudy7 |
| nan | 200207T201148Z | DeathInc | |
| 073 | Microsoft PowerPoint macrofree | 200116T185422Z | General |
| 001 | Help | 190703T202710Z | Luvexina |
| 093 | SystemVerilog HDL | 200115T044440Z | General |
| 018 | JavaScript Node.js | 180412T081026Z | Muhammad |
| 022 | Intcode | 191224T014302Z | The Fift |
| 014 | Python 3 | 191224T002620Z | Sagittar |
| 010 | hashmap | 160706T115244Z | user4701 |
| 004 | √ å ı ¥ ® Ï Ø ¿ | 170315T162802Z | caird co |
| 019 | Pepe | 190925T025944Z | lyxal |
| 004 | Cascade | 190924T182940Z | Edgex42 |
| 009 | Redirection | 190915T173435Z | Edgex42 |
| 011 | Seed | 190921T084555Z | Kamila S |
| 013 | Owk | 190921T021345Z | user8505 |
| 003 | Obx | 190921T020849Z | user8505 |
| 036 | Whitespace | 180313T084753Z | Kevin Cr |
| 004 | Clam | 190504T182504Z | MilkyWay |
| 022 | Intel 8080 machine code | 190408T213712Z | 640KB |
| 049 | BitCycle | 190407T003449Z | Jo King |
| nan | 190129T033808Z | MilkyWay | |
| 029 | RUST | 190129T074535Z | Chau Gia |
| 002 | Charcoal | 161031T074107Z | ASCII-on |
| 024 | RTFM | 181227T134159Z | TeslaX93 |
| 020 | PHP | 181227T125947Z | Francisc |
| 003 | F# Mono | 181225T205907Z | dana |
| 003 | Redirection | 181223T072137Z | ais523 |
| 205 | Alchemist | 181125T135606Z | ბიმო |
| 155 | Aheui esotope | 181118T232532Z | cobaltp |
| 004 | Burlesque | 181118T200308Z | mroman |
| 985 | Bit | 180913T234257Z | kepe |
| 004 | Flobnar | 180812T202112Z | Esolangi |
| 008 | 6502 machine code | 180711T183441Z | Tornado5 |
| 009 | Java | 161006T082558Z | Shaun Wi |
| 009 | Java JDK 10 | 180603T075144Z | Olivier |
| 003 | FRACTRAN | 180416T161217Z | Vincent |
| 028 | JavaScript Node.js | 180414T145950Z | user7985 |
| 019 | m4 | 180412T090113Z | manatwor |
| 022 | jamal | 180412T085720Z | manatwor |
| 006 | PainFlak | 180410T212459Z | DJMcMayh |
| 003 | Perl6 | 180302T022023Z | bb94 |
| 003 | √ å ı ¥ ® Ï Ø ¿ | 180302T005117Z | qqq |
| 009 | Beatnik | 180228T161211Z | Maya |
| 009 | Momema | 180212T071428Z | Esolangi |
| 005 | Forked | 180212T050610Z | MD XF |
| 005 | Wumpus | 180210T203633Z | Martin E |
| 011 | AWK | 160728T125739Z | Robert B |
| 026 | SNOBOL4 CSNOBOL4 | 171211T211927Z | Giuseppe |
| 006 | cubix | 160704T193105Z | MickyT |
| 388 | Verbosity | 171210T140705Z | caird co |
| 005 | Pyth 5 Bytes | 171208T162859Z | Tornado5 |
| 034 | Whispers | 171206T215115Z | caird co |
| 006 | Spiral | 171129T070619Z | Steadybo |
| 003 | ARBLE | 171123T230808Z | ATaco |
| 007 | Perl 5 | 171122T085237Z | Dom Hast |
| 037 | DUP | 171121T224334Z | M L |
| 008 | NotQuiteThere | 171114T175326Z | caird co |
| 075 | LOLCODE | 171108T200510Z | qqq |
| 074 | INTERCAL | 170927T141509Z | KSmarts |
| 012 | Bash script | 160702T220442Z | anna328p |
| 006 | MS Excel / Google Sheets | 170807T133022Z | Taylor R |
| 089 | Bitwise | 170926T040223Z | MD XF |
| 008 | Excel VBA | 170807T132706Z | Taylor R |
| 004 | Element | 170807T055652Z | aAaa aAa |
| 023 | Little Man Computer | 170807T025001Z | Gareth |
| nan | 170806T144556Z | justanot | |
| 009 | Lost | 170806T005222Z | Wheat Wi |
| 008 | Cubically | 170801T014242Z | Kamil Dr |
| 010 | tcl | 170109T205527Z | sergiol |
| 004 | Commentator | 170716T211040Z | caird co |
| 003 | R | 170703T152045Z | Giuseppe |
| 017 | Ruby | 160726T235130Z | anna328p |
| 001 | 170628T193535Z | totallyh | |
| 019 | SQL | 170614T170451Z | BradC |
| 006 | Triangular | 170614T161805Z | MD XF |
| 002 | Check | 170604T220956Z | Esolangi |
| 003 | Standard ML MLton | 170604T213444Z | musicman |
| 012 | Decimal | 170604T213147Z | MD XF |
| 007 | Add++ | 170604T190200Z | caird co |
| nan | Dominoes | 170314T033653Z | Nonlinea |
| 001 | Braingolf | 170602T200821Z | totallyh |
| 039 | Visual Basic.NET | 170517T213131Z | Stephen |
| 006 | Alice | 170411T112618Z | Martin E |
| nan | 170328T205400Z | Shaun Be | |
| 015 | AHK | 170328T180718Z | Engineer |
| 012 | Wise | 161020T024210Z | Wheat Wi |
| 009 | Wise | 170322T045532Z | MercyBea |
| 035 | C | 170315T124119Z | Bijan |
| 004 | J | 170314T155646Z | Bijan |
| 418 | Taxi | 170201T173402Z | Erik the |
| 015 | REXX | 170314T134608Z | idrougge |
| 017 | Scala | 170314T052842Z | Stefan A |
| 022 | Python 3 | 161224T175011Z | python-b |
| 003 | Python | 160702T012237Z | Leaky Nu |
| 005 | Carrot | 170211T132015Z | user4180 |
| 013 | SmileBASIC | 170124T042925Z | 12Me21 |
| 4125 | Binary lambda calculus | 160702T011923Z | Leaky Nu |
| 005 | Vim | 170123T195753Z | DJMcMayh |
| 002 | V | 170123T195426Z | DJMcMayh |
| 032 | Whirl | 170120T061427Z | 0 |
| 098 | Bubblegum | 170111T074953Z | DJMcMayh |
| 001 | PigeonScript | 170109T081828Z | TrojanBy |
| 015 | Kitanai | 170111T085107Z | Sygmei |
| 003 | ><> | 160702T190235Z | Emigna |
| 001 | Japt | 170109T154756Z | Oliver |
| 002 | TIBasic | 170109T152210Z | Timtech |
| 064 | Euphoria | 170109T142036Z | Offtkp |
| 006 | QBIC | 161010T155113Z | steenber |
| 005 | PHP | 170109T092047Z | Titus |
| 342 | Turing Machine Simulator | 161203T120538Z | Erik the |
| 066 | C | 161101T004901Z | James Mu |
| 010 | Ruby | 161031T215550Z | Niclas M |
| 091 | Java | 161031T205330Z | Niclas M |
| 001 | Swift | 161031T205023Z | ApolloZh |
| 007 | Befunge | 161030T194313Z | Will Ros |
| nan | 161030T212643Z | Yotam Sa | |
| 017 | Ruby | 161020T172137Z | BoeNoe |
| 014 | awk | 161027T181042Z | Lledargo |
| 141 | SQL | 161027T171754Z | Pete Ard |
| 035 | SHENZHEN I/O MCxxxx assembly code | 161027T145911Z | TuxCraft |
| 049 | C | 161020T180835Z | homersim |
| 027 | JavaScript | 161020T155958Z | Pete Ard |
| 006 | Brainflak | 160702T005857Z | DJMcMayh |
| 005 | Y | 161012T171805Z | TuxCraft |
| 512 | Minecraft 1.10.x | 160706T064443Z | Addison |
| 019 | C | 161009T100013Z | user5898 |
| 052 | Batch | 160706T161206Z | Nitrate |
| 007 | Elixir | 161007T143039Z | adrianmp |
| 010 | C# | 160702T082107Z | Yytsi |
| 006 | Codelike | 161006T012957Z | Connor D |
| 152 | Shakespeare Programming Language | 160827T122356Z | Copper |
| 003 | Perl 6 | 160827T130500Z | smls |
| 003 | Nim | 160827T120846Z | Copper |
| 224 | Brainfuck | 160827T105157Z | primo |
| 038 | S.I.L.O.S | 160724T235652Z | Rohan Jh |
| 013 | R | 160826T162917Z | Rudier |
| 019 | SQF | 160815T035607Z | Οurous |
| 002 | dc | 160702T183302Z | juh |
| 009 | Hexagony | 160728T104333Z | Sok |
| 017 | PowerShell v2+ | 160702T172239Z | AdmBorkB |
| 010 | MoonScript | 160727T124953Z | manatwor |
| 002 | Mathematica | 160702T023324Z | LegionMa |
| 012 | golflua | 160727T124417Z | manatwor |
| 003 | jq | 160727T120027Z | manatwor |
| 013 | Gema | 160727T115652Z | manatwor |
| 003 | Maple | 160725T165549Z | DSkoog |
| 002 | GAP | 160725T114108Z | Christia |
| 003 | Haskell | 160702T130857Z | Lazersmo |
| 003 | SML | 160717T235041Z | Laikoni |
| 006 | Yup | 160717T222435Z | Conor O& |
| 003 | Cheddar | 160717T220847Z | Downgoat |
| 031 | Java | 160702T032825Z | user8397 |
| 016 | Batch | 160702T184952Z | Neil |
| 029 | GO | 160713T111054Z | Sefa |
| 135 | Shakespeare Programming Language SPL | 160708T133648Z | Ioannes |
| 8412 | Stack Cats | 160710T123638Z | Sp3000 |
| 025 | C | 160705T162215Z | Giacomo |
| 056 | C++ – | 160704T190326Z | user1525 |
| 005 | Befunge 5 Bytes | 160704T112924Z | Yann |
| 003 | hashmap Yes | 160704T103141Z | user4701 |
| 004 | Prelude | 160704T090431Z | Martin E |
| 005 | Befunge | 160704T065451Z | user2548 |
| 001 | GoLScript | 160703T165528Z | Riker |
| 001 | Fuzzy Octo Guacamole | 160703T163919Z | Riker |
| 001 | Jolf | 160703T155805Z | Conor O& |
| 008 | Perl 5.10 | 160703T134501Z | Sake |
| 015 | Common Lisp | 160703T001959Z | Byeonggo |
| 004 | MATLAB | 160702T014346Z | Luis Men |
| 221 | Minecraft 1.10 | 160703T005114Z | quat |
| 022 | Fishing | 160702T184200Z | Emigna |
| 042 | Retina | 160702T154954Z | Martin E |
| 009 | PHP 4.1 | 160702T164417Z | Ismael M |
| 020 | PHP | 160702T112714Z | insertus |
| 005 | Labyrinth | 160702T091728Z | Martin E |
| 003 | Silicon | 160702T090718Z | m654 |
| 002 | Brachylog | 160702T055246Z | Fatalize |
| 001 | MATL | 160702T052806Z | Suever |
| 018 | Bash | 160702T033757Z | anna328p |
| 009 | JavaScript ES6 | 160702T043937Z | Patrick |
| 002 | Golfscript | 160702T022139Z | NoOneIsH |
| 005 | Minkolang 0.15 | 160702T011140Z | El'e |
| 001 | 05AB1E | 160702T010439Z | Adnan |
How dare you fuck the brain, 13 7 6 4 bytes
;=;+
Explained
;=; #Get user input on cell 1, copy it to cell 2, then overwrite the input on cell 1
+ #Adds the two cells together and implicit print it as a number
Regenerate, 10 bytes
${$~1+$~2}
Takes the input numbers as command-line arguments. Attempt This Online!
Explanation
${ } Treat the result of this expression as a string:
$~1 First cmdline arg
+ Plus
$~2 Second cmdline arg
SAKO, 25 bytes
CALKOWITE:I
SUM(I,1,W(I))
Takes input as a list of size 2 under the name of W.
This is a solution by using a builtin. I included the variable declaration, as it must use an integer variable, but this isn't supposed to be a full programme.
Positionally, 33 29 bytes
^+ @<
> , v
;<
Try It Online! -4 bytes thanks to Mukundan314.
Positionally is a language I made where there are only two commands - space and non-space. The instruction run depends on the position of the IP.
The characters in the above could be any character aside from spaces. The instruction pointer starts at the @, moving right. Positionally has implicit input, so the + command adds two numbers from input. Then, , prints it, before ; halts the program.
7, 22 characters, 8 bytes
1717023740344172360303
This program is encoded on disk as (xxd hexdump):
00000000: 3cf0 9f81 c87a 7830 <....zx0
7 doesn't really support numbers natively, and thus it's hard to define what a number is for the purpose of a function submission. As such, this is a full program, reading from stdin, outputting to stdout (which explains where much of the length comes from).
This program doesn't support negative numbers, because 7 can't input those using numeric I/O (although it can output them). As such, supporting negative numbers would require the use of character input (and a decimal→integer parser), which would make the program much, much more complex.
Explanation
1717023740344172360303
7 7 7 Stack element separators
1 1 023 Initial stack
40344172360303 Initial program (also stored on the stack)
(Implicit: run the initial program, but leave it on the stack)
4 Swap with blank element between
0 Escape top stack element, append it to element below
So at this point, we've effectively swapped the program below the 023 element, escaping that element in the process. The 023 is a program in a domain-specific I/O language; and putting the program as the second stack element means that we can discard it (the second stack element is the only one that can be discarded).
3 Do I/O using top element, discard second element
0 Set I/O format: numeric in decimal
23 Input via repeating the third stack element
We now have only two stack elements; 1 at the bottom, and the first input in unary just above it (because we repeated the second-last stack element, which was 1, and thus will have a number of 1s).
4 Swap with blank element between
4 Swap with blank element between
172360 Append an escaped representation of "23" to TOS
3 Do I/O using top element, discard second element
23 Input via repeating the third stack element
So now our stack consists of the first input (in unary) directly below the second stack element (in unary).
0 Escape top element, appending it to the element below
3 Do I/O using top element, and exit
The 3 command exits the program as we're out of stack, but not before it outputs the number we calculated. The number in question will consist of a number of 7s equal to the first number input, followed by a number of 1s equal to the second number input (these are the unescaped and escaped representations of the same command). Numeric I/O treats 1 and 7 as equivalent, and having a value of +1; thus, the unary number gets translated into decimal and output.
Branch, 2 bytes
+#
Try it on the online Branch interpreter!
Explanation
+ adds the values of the children of the current node. If any nodes are missing, they are usually created with a value of 0; however, binary operations will instead read from STDIN (this usually gets 0 if the input is exhausted, but if the input was empty to begin with, feof doesn't seem to work the way I want it to).
# just outptus the value of the current node as a number (as opposed to a character, which . does)
Bespoke, 38 bytes
would I total a quantity?yeah
should I
Bespoke is a new esoteric programming language I created near the start of 2025. It's similar to my earlier esolang Poetic, in that word lengths are converted to instructions. This time, however, the instructions are part of a stack-based language, with arbitrary-precision signed integers and loop breaking/continuing and functions and everything!
Here is this program in "pseudocode" (which is able to run as Bespoke code - in fact, it's equivalent to the given code!):
INPUT N
INPUT N
STACKTOP PLUS
OUTPUT N
This should be self-explanatory.
BrainChild ASM, 5 bytes
asm function add(int, int) -> int {
xpopa
xpopb
addab
xpushb
ret
}
Hex-dump of bytecode
0 1 2 3 4 5 6 7 8 9 A B C D E F
00000000: 34 35 1B 2F 14 | 45./.
Pops the x stack into the a and b registers, sums them, then pushes the result back unto the x stack. Only supports Unsigned 32 bit integers.
Hatchback, 25 bytes
16 0 16 1 2 0 1 1 0 65535
gets 2 inputs (16 0 16 1), adds them together (2 0 1), and prints it (1 0)
Qdeql, 37 bytes
Input in bytes rather than ASCII. Although Qdeql is limited to bytes, this would work with any (arbitrarily large) finite cell size.
-&=\--\/\/=/&=\--\/\/=/\=/-\--\/\/=/*
That was... surprisingly easy.
The core of this is the loop \--\/\/=/. It computes the difference between two values, and appears three times in this code. Here's an explanation of the loop:
Queue: {x, y}
\ While x is not 0, move it to the back of the queue and add two 0s
Queue: {y, x, 0, 0}
-- Decrement both values
Queue: {0, 0, y minus 1, x minus 1}
\/ Remove a 0 from the queue
\/ Remove the other 0
Queue: {y minus 1, x minus 1}
= Swap the order of the values in the queue
/ End while
When that loop exits, the queue is guaranteed to have a single value that is y - x.
Given this, if the two inputs to the program are x and y, this program computes 255 - (255 - x - y).
- Start the queue with a single 255
& Add the first input to the queue
= Swap the order, so the input is ahead of the 255
\--\/\/=/ Compute 255 minus x
& Add the second input to the queue
= Swap them again
\--\/\/=/ Compute 255 minus x minus y
\=/- Add another 255 to the queue
\--\/\/=/ Compute 255 minus (255 minus x minus y)
* Print the result
Jelly, 1 byte
+
Also works in 05AB1E, Actually, APL, BQN, Brachylog, Braingolf, Chocolate, ,,, (Commata), dc, Deorst, Factor, Fig**, Forth, Halfwit*, HBL*, Implicit, J, Julia, K, kdb+, Keg, Ly, MathGolf, MATL, Pyke, Q, Racket, Scheme, Swift, Thunno**, Thunno 2, tinylisp 2, Uiua, and Vyxal.
* Language uses a half-byte code page, and therefore + counts as 0.5 bytes.
** In Fig and Thunno, this is \$\log_{256}(96)\approx\$ 0.823 bytes.
Pyth, 4 3 bytes
+vw
Or also:
s.Q
Because this is shorter than both other Pyth answers I thought I'd add this one.
Brainfuck extended, 6 bytes
(@(+%)
Explanation
( #Input a decimal integer and store it into the cell at the pointer#
@ #Rewrite the value of the register with the cell at the pointer#
( #Input a decimal integer and store it into the cell at the pointer#
+ #Add the register by the cell at the pointer, now the register contains the sum#
% #Rewrite the cell at the pointer with the value of the register#
) #Output the cell as the pointer (the sum) as decimal integer#
in floop, 17 bytes
r+o?+n?-[r-]r[o;]
in floop is a language created by Rydwolf Programs which runs in an infinite loop. It's a true tarpit, and incredibly hard to program in. It also has four variables (n, o, r, s), three of which we use here, and a tape.
o?+ Take an input into variable o and increment it
? does nothing if all input is consumed
n?- Ditto with n, but decrement it
r+ Increment r
[ ] If n is nonzero
r- Decrement r
If n is nonzero, r will be zero, and vice versa
r[ ] If r is nonzero (n is zero)
o; Output o
In other words, this decrements n and increments o until n is zero, then outputs o.
Swift, 25 20 bytes
var t:(_,_)->Int=(+)
Ultrarisky, 1 byte
I0{I
Ultrarisky is a derivative of Risky made by Rydwolf Programs. While risky uses a 4-bit codepage (and thus has 16 commands that fit two to a byte) ultrarisky uses a two-bit codepage, and has 4 commands that fit four to a byte. It's quite hard to program in due to the lack of identity functions.
0 # Add
I # One input
{I # Absolute value of other input
Logically, 229 Bytes.
@m:3i:o,c:3t;XOR(3i)(o)AND(i0,i1)(t0)AND(i1,i2)(t1)AND(i0,i2)(t2)OR(3t)(c)
@M:8a,8b:8o:7c;m(a0,b0)(o0,c0)m(a1,b1,c0)(o1,c1)m(a2,b2,c1)(o2,c2)m(a3,b3,c2)(o3,c3)m(a4,b4,c3)(o4,c4)m(a5,b5,c4)(o5,c5)m(a6,b6,c5)(o6,c6)m(a7,b7,c6)(o7)
Ungolfed
@FullAdder
Input: 3i;
Output: o,c;
Bus: 3t;
XOR (3i) (o)
AND (i0,i1) (t0)
AND (i1,i2) (t1)
AND (i0,i2) (t2)
OR (3t) (c)
@Main
Input: 8a,8b;
Output: 8o:
Bus: 7c;
FullAdder (a0,b0) (o0,c0)
FullAdder (a1,b1,c0) (o1,c1)
FullAdder (a2,b2,c1) (o2,c2)
FullAdder (a3,b3,c2) (o3,c3)
FullAdder (a4,b4,c3) (o4,c4)
FullAdder (a5,b5,c4) (o5,c5)
FullAdder (a6,b6,c5) (o6,c6)
FullAdder (a7,b7,c6) (o7)
I/O as 8 bit Non-negative integers.
Use the /ib /ob for Decimal Input/Output. Binary otherwise.
Currently no Online Interpreter :(
awk, 9-bytes
($_+=$2)_
echo "${test_data}\n-2 2" | gtee >( gcat -n >&2;) |
awk '($_+=$2)_'
- no idea why slipping
(……)_works, but somehow it does. my best guess is that it's forcing a string concat with an empty string, thus allowing the zero to print properly.
.
1 1 2
2 14 15
3 7 9
4 -1 8
5 8 -9
6 -8 -9
7 -2 2
3
29
16
7
-1
-17
0
Billiards, 7 characters = 11 bytes
Language made after the challenge.
↧ # Takes an input
↧ # Takes another input
+ # Adds them together
P # Outputs as an integer
Alternatively, for the same number of bytes:
↧↧ # Takes two inputs
+/ # Adds them together; the '/' deflects the second input into the '+'
P # Output as an integer
RubyGolf, 15 bytes
p gets.i+gets.i
code is so short it hit the character limit. ugh.
New language created by me, interpreter going up soon.
Sesos, 5 bytes
0000000: d605ba 8f07 .....
set numin
set numout
get
fwd 1
get
jmp
sub 1
rwd 1
add 1
fwd 1
jnz
rwd 1
put
Objective-Java*#++--Script.NETnotation.sh, 12 bytes.
.cmd.vbs.txt
Try it online!
How it works:
.cmd # Gets the input and pushes it to the stack
.vbs # Adds the top two items on the stack
.txt # Prints the top item on the stack
Quipu, 11 bytes
\/
\/
++
/\
Explanation
Each side-by-side pair of characters is a command ("knot"), and execution proceeds from top to bottom:
\/ Input a number
\/ Input another number
++ Add the values of the previous two knots
/\ Output the value of the previous knot
Cubestack, 22 bytes
b' S S' y S S' y2 R y'
Explanation:
b' # Push all inputs wrapped in a list (the array to iterate through)
S S' # Push loop variable name (an empty string)
y # Open for loop
S S' y2 # Get the value of the loop variable
R # Add
y' # End for loop
makina, 13 bytes
P >iN
>>+
Ni<
SPDT, 1168 bytes
p 0
t 0 1
t 0 2
t 0 3
t 0 4
t 0 5
t 0 6
t 0 7
t 0 8
t 0 9
t 0 10
t 0 11
t 0 12
t 0 13
t 0 14
t 0 15
t 0 16
r 1 0 33 34
r 9 34 33 17
r 1 0 35 36
r 9 18 36 35
r 2 0 40 41
r 10 37 41 40
r 37 0 42 43
r 17 20 43 42
r 2 0 44 45
r 10 45 44 38
r 37 0 46 47
r 17 47 46 39
r 38 0 48 19
r 39 0 48 19
r 3 0 52 53
r 11 49 53 52
r 49 0 54 55
r 19 22 55 54
r 3 0 56 57
r 11 57 56 50
r 49 0 58 59
r 19 59 58 51
r 50 0 60 21
r 51 0 60 21
r 4 0 64 65
r 12 61 65 64
r 61 0 66 67
r 21 24 67 66
r 4 0 68 69
r 12 69 68 62
r 61 0 70 71
r 21 71 70 63
r 62 0 72 23
r 63 0 72 23
r 5 0 76 77
r 13 73 77 76
r 73 0 78 79
r 23 26 79 78
r 5 0 80 81
r 13 81 80 74
r 73 0 82 83
r 23 83 82 75
r 74 0 84 25
r 75 0 84 25
r 6 0 88 89
r 14 85 89 88
r 85 0 90 91
r 25 28 91 90
r 6 0 92 93
r 14 93 92 86
r 85 0 94 95
r 25 95 94 87
r 86 0 96 27
r 87 0 96 27
r 7 0 100 101
r 15 97 101 100
r 97 0 102 103
r 27 30 103 102
r 7 0 104 105
r 15 105 104 98
r 97 0 106 107
r 27 107 106 99
r 98 0 108 29
r 99 0 108 29
r 8 0 112 113
r 16 109 113 112
r 109 0 114 115
r 29 32 115 114
r 8 0 116 117
r 16 117 116 110
r 109 0 118 119
r 29 119 118 111
r 110 0 120 31
r 111 0 120 31
l 18
l 20
l 22
l 24
l 26
l 28
l 30
l 32
l 31
Try it: https://radvylfprograms.com/spdt
SPDT is an esolang I've been wanting to make for a while now. Aside from I/O, it consists entirely of Single Pole Double Throw, or Form C, relays. This answer, which is possibly imperfectly golfed since I used a custom transpiler with macros to generate it, consists of relays arranged into AND, OR, and XOR gates, which are arranged into half adders and full adders, which are then used to make an 8-bit adder. This could be scaled up arbitrarily, at an \$n\log(n)\$ byte count for \$n\$ input bits.
I generated it with the following SPDT-c code, with SPDT-c being a transpiled language I made shortly after that makes it easier to design complex circuits (run it at https://radvylfprograms.com/spdt/c):
t 0 1
t 0 2
t 0 3
t 0 4
t 0 5
t 0 6
t 0 7
t 0 8
t 0 11
t 0 12
t 0 13
t 0 14
t 0 15
t 0 16
t 0 17
t 0 18
add 1 11 c1 21
addc 2 12 c1 c2 22
addc 3 13 c2 c3 23
addc 4 14 c3 c4 24
addc 5 15 c4 c5 25
addc 6 16 c5 c6 26
addc 7 17 c6 c7 27
addc 8 18 c7 29 28
l 21
l 22
l 23
l 24
l 25
l 26
l 27
l 28
l 29
and i i2 o:
r i 0 - c
r i2 c - o
or i i2 o:
r i 0 - o
r i2 0 - o
xor i i2 o:
r i 0 1 2
r i2 o 2 1
add i i2 o1 o2:
and i i2 o1
xor i i2 o2
addc i i2 c o1 o2:
xor i i2 x
xor x c o2
and i i2 a
and x c a2
or a a2 o1
The transpiler currently lacks any optimizations, and the wire names it generates are numbers, while SPDT technically allows any non-whitespace combination of characters to be used. I didn't change that for this answer, as it's not a particularly interesting optimization, but it will be coming soon.
Lexurgy, 479 bytes
Port of @Toby Speight's answer. Input as a|b.
class b {\5,\6,\7}
class a {\1,\2,\3,\4,@b,\8}
a:
{@a,\9}$1 => A $1
b:
{@b,\8,\9}$1 => \4 $1
c:
{\8,\9}$1 => \4 $1
d:
{\2,\3,\6,\7}$1 => xx $1
e:
{\1,\3,\5,\7,\9} => x
f:
\4=>xxxx
g:
@a=>*
h:
*=>|/_ $
i propagate:
([]*)$1 A (x*)$2 | ([]*)$3 A (x*)$4 |=>$1 | $3 | A $2 $4
j:
|=>*
k propagate:
A x*10=>* xA
l:
Ax=>\-x
m:
xx=>\2
n:
x=>\1
o:
\2\2=>\4
p:
\4\4=>\8
q:
\8\1=>\9
r:
\2\1=>\3
s:
\4\2=>\6
t:
\4\3=>\7
u:
\4\1=>\5
v:
\-=>*
A=>\0
Lexurgy, 267 bytes, non-competing
Golfed version of the example adding machine. Input as a|b.
The general process is to increment each a digit by the value of the b digit, then handle any carries afterwards. Carries are denoted by a ', and increments the digit to its left when consumed.
As a result, this doesn't handle negative numbers, which the spec requires.
Class d {\0,\1,\2,\3,\4,\5,\6,\7,\8,\9}
Class i {\1,\2,\3,\4,\5,\6,\7,\8,\9,'\0}
a propagate:
` @d$1 | @d$2=>$2 ` $1 |/_ @d
then:
@d$1 | @d$2 * *=>| $2 ` $1 |/_ @d//` _
c propagate:
@d | @i => @i | @d
|0 => *
d:
{`,|}=>*
e propagate:
@d '=>@i *
'=>\1/$ _
Fennel, 23 bytes:
(fn add [x y] (+ x y ))
PostScript, 3 bytes
add
This consumes two arguments from top of stack and pushes its result to the stack.
sed, 275 bytes
s/[1-9]/0&/g
s/[5-9]/4&/g
s/[89]/4&/g
s/[2367]/xx&/g
s/[13579]/x/g
s/4/xxxx/g
s/[1-8]//g
s/$/ /
:a
s/\(.*\)0\(x*\) \(.*\)0\(x*\) /\1 \3 0\2\4/
ta
s/ *//g
:c
s/0xxxxxxxxxx/x0/g
tc
s/0x/-x/g
s/xx/2/g
y/x/1/
s/22/4/g
s/44/8/g
s/81/9/g
s/21/3/g
s/42/6/g
s/43/7/g
s/41/5/g
s/-//g
Takes 2 space-separated non-negative decimal integers on standard input; prints their sum to standard output
Explanation
We represent each input in unary-coded decimal, using x as our digit, and 0 as separator. For example, 42 is written 0xxxx0xx.
#!/bin/sed -f
# Convert to unary decimal
s/[1-9]/0&/g
s/[5-9]/4&/g
s/[89]/4&/g
s/[2367]/xx&/g
s/[13579]/x/g
s/4/xxxx/g
s/[1-8]//g
# Append space to separate second input from output
s/$/ /
# Consume the smallest of each digit from input, and push
# the sum to output
:add
s/\(.*\)0\(x*\) \(.*\)0\(x*\) /\1 \3 0\2\4/
tadd
# Everything is now accumulated in output; remove the spaces
s/ *//g
# Add carry to the next position
:carry
s/0xxxxxxxxxx/x0/g
tcarry
# Back to decimal
s/0x/-x/g
s/xx/2/g
y/x/1/
s/22/4/g
s/44/8/g
s/81/9/g
s/21/3/g
s/42/6/g
s/43/7/g
s/41/5/g
s/-//g
The extension to support decimal fractions is left as an exercise for the reader.
dotcomma, 10 bytes
[,.][,.].,
Dotcomma is a language I recently invented, designed to do things in an interesting way with as few instructions as possible. In order to accomplish this, there are two operators (predicatably . and ,) which can do entirely different things depending on context. This answer's explanation will be very introductory. To see some more complicated code, check out the examples in the page linked in the title.
Anything between brackets is a block. Every block has a return value, which is set by the operator before the closing bracket (or 0 if there is none). The basic reason this program functions is because, when one or more blocks (with no operators in between) are followed by a ., the sum of their return values is computed.
In this program, both blocks start with ,. When preceded by the start of a block, a , will take input. Additionally, when followed by the end of a block, it will output the value given to it (from input or another operator). The .s here do pretty much nothing; they take the return values of the ,s and use it as the return value of their respective blocks, which spaces the , from the end of the block and suppresses its output.
The final , simply takes the value computed by the final . and outputs it.
Plumber, 244 176 bytes
[] [] []
][=][]
[]=][][=][
[]=]===]]
][]][=[=]] =]]
[]][ ][===[=[]
]][]=][[[=]=]][][
[]]=]=]=]=[]
][]=[]][
[]]=][=][]
= =]=]][[=[==
][=]=]=]=]===][=
Old Design (244 bytes)
[] []
[][=[]
[[=[][] [][] ][]][=
][[] ][[=]]]][]=[[]
[]===][] ][===][]
][][ [] ][ ] [][]
[ ][]=][[[===][[
][]]]=][[]=[=]=]=]]==]=]][
][=]=]]==]=][] ][
[][=][=[[][[=]][
==]=]][[=[= =
I thought I had a good solution for a while...except it didn't work with 0 or 1 as the first input. This program consists of three parts: incrementer, decrementer, and outputter.
The decrementer is on the left, and holds the first value. It is incremented, since a 0 would cause an infinite loop (as the program tries to decrement to 0 and gets a negative value). It will decrement the stored value at execution, and send a packet to the incrementer.
The incrementer is on the right, and stores the second input. When the decrementer sends a packet, it increments its stored value, and sends a packet back to the decrementer.
Whenever the decrementer sends the packet to the incrementer, it is checked by the outputter. If the packet is 0, execution stops and the value of the incrementer is read and outputted. It uses a NOT gate, one of the most complicated parts of the program.
Older design (doesn't work with some inputs), 233 bytes
[] []
[][] [][] =][]
[]=][]=][[=]][
[][===][ [][===[]
[][] [ [] ][][
] [===][=]][ ]
][[=[=[=[=[=]=[]][=[[[][
][[=[=[=[==[[=[=][
[]]=][=][]
= =]=]][[=[==
The new one is flipped to save bytes, and it's really confusing me. This design is the one I worked with for a week or so when designing the interpreter.
APOL, 6 bytes
+(i i)
I AM BOT FEED ME BUTTER
CSS 172 bytes
For every button add 1 and for every input add 1. Might be buggy on some browsers and also not very practical. Make sure your html file has a body and you actually put in buttons and inputs
*{—n: 0;—d: 0;}li{—-n: calc(var(—-n) + 1 )
}button{—-d: calc(var(—-d) + 1 )
}input{—-d:calc(var(—-d) + 1)}body::after{content: calc(var(—-d) + var(—n))}
Ly, 2 bytes
+u
The + command adds the top two entries on the stack. And if there's nothing on the stack, it will read from STDIN. Then the u prints the results as a number.
x86_32 machine code, 2 bytes
08048540 <add7>:
8048540: 01 c8 add %ecx,%eax
Assuming the two values are already in the ecx and eax registers, performing the add instruction will add the values of the two registers and store the result in the destination register.
You can see the full program written in C and inline assembly here. Writing the wrapper in C makes it easier to provide inputs and do testing, but the actual add function can be reduced down to these two bytes.
abcn, 3 bytes
@@x
Explanation :
@ ---> take input 1
@ ---> input 2
---> nothing in between so they auto get added
x ---> print
TypeScript Compiler, 244 bytes
Yes, you read that right. Not TypeScript, but specifically its compiler.
type R<T,U,V>=T extends U?V:T
type N<T>=R<R<R<R<R<R<R<R<R<R<T,9,null>,8,9>,7,8>,6,7>,5,6>,4,5>,3,4>,2,3>,1,2>,0,1>
type P<T>=R<R<R<R<R<R<R<R<R<T,1,0>,2,1>,3,2>,4,3>,5,4>,6,5>,7,6>,8,7>,9,8>
type A<T,U>=T extends 0?U:A<P<T>,N<U>>
let x:A<1,2>=[]
Enter the inputs as the type parameters of A (where I put 1 and 2) and the inferred type of x is their sum. It only takes one-digit inputs, and the output will be null if the addition overflows. It is in theory infinitely extendible, but in practice the compiler will just stop computing it if you allow numbers bigger than 20 (or 21 without overflow handling).
Because the inferred type gets erased by the compiler, I use the last three characters (=[]) to trigger a type error (TS2322), which contains the answer. For example, the error message may read
Type 'never[]' is not assignable to type '3'.
As for how this works:
R<T, U, V> returns V if T is U, and T otherwise.
N<T> returns T + 1.
P<T> returns T - 1.
A<T, U> returns U if T is 0, and A<T - 1, U + 1> otherwise. Recursion!
One neat thing this can do is handle adding elements from two sets. For example, A<1|2,4|7> evaluates to 5 | 6 | 8 | 9.
CSASM v2.5.1, 21 bytes
func a:
add
print
ret
end
Defines a function named a which pops two number-type values of the same type from the stack and prints their sum.
A0A0, 28 bytes
I0A1V0O0
I0V0S0
G-2G-1G-1G-1
Each number is first put into two separate operands (V0 instructions) on two lines via the I0 instructions on each line and then later combined together for adding. After taking input, we jump to the top. The A1 adds the V0 O0 onto the next line, to get the following code: V2 S0 V1 O0. I've labelled the operands with V1 and V2 to represent the different operands. During execution these contain the actual inputs. From there it's simple.
V2 S0 V1 O0
V2 ; operand, put into the S0 next to it
S0 ; adds its value to the operand next to it (V1)
V1 ; operand, put into the O0 next to it
O0 ; outputs its value as a number
The line of jumps at the bottom just goes back to the correct line each time.
Concurr, pre-pre-release, 2 bytes
$+
A number of items within parentheses is a call, and calling a function with zero arguments returns that function because of currying. This could not just be + because Concurr is a lisp-2, meaning it has a separate namespace for global functions and local variables. $ expr is a shortcut for ( expr ).
Yggdrasil, 4 bytes
+__$
Yggdrasil automatically substitutes 2 characters for different values when turning the source code in a binary tree. % represents a null byte and _ represents a None value. Yggdrasil then traverses the tree and replaces Nones with sequential command line arguments (i.e. the first encountered, depth-first, is the first argument etc.).
This forms the following binary tree for the memory, where ¹ represents the first argument and ² the second:
+
/ \
¹ ²
We then run the commands linearly, starting with the memory pointer at the + node. We execute +, which adds the left and right nodes of the memory point, setting the root of the program to ¹+². _ then does nothing, and $ outputs the value under the memory pointer as an integer
BrainF*ck, 12 Bytes
,>,<[->+<]>.
I'm completely new to code golfing, so if I messed something up or did something wrong please let me know.
Here's how it works:
,>,< - Stores the two inputs into the first and second cells
[->+<] - Decrements the first cell and adds it to the second,
repeats until the first cell is 0
>. - Moves to the second cell and outputs its value
The inputs and outputs are both as ASCII characters (not too sure if this is allowed. I think it is but I could definitely be wrong, so if it is just let me know).
Swift, 12 bytes
Without types
{a,b in a+b}
{ a, b in // take two parameters
a + b // return sum
}
With types (21 bytes)
{(a:Int,b:Int)in a+b}
{ (a: Int, b: Int) in // take two `Int` parameters
a + b // return sum
}
Scratch 3.0 (scratchblocks3 syntax), 23 bytes/7 points
define (x)(y
say((x)+(y
ARM Thumb-2 machine code, 4 bytes
Machine code:
1840 4770
Assembly:
.syntax unified
.arch armv6t2
.thumb
.globl add
.thumb_func
// input: r0, r1
// output: r0
add:
// r0 += r1
adds r0, r1
// return
bx lr
Boring, obvious solution.
It is a function, following the standard C calling convention.
uint32_t add(uint32_t r0, uint32_t r1);
The input is in r0 and r1, and the result is in r0.
Kotlin, 22 bytes
fun n(a:Int,b:Int)=a+b
Brainetry, 97 bytes
Golfed version:
a b c d e f
a b
a b c d e f
a b c d e f g h
a b c d e
a b c d
a
a b c d e f g h i
a b c d e f g
Does I/O like brainfuck programs, so you input ASCII codepoints and get ASCII characters as output, e.g. inputting two spaces (ASCII 32) the program pints @ (ASCII 64).
To try it online follow this repl.it link, paste the code in the btry/replit.btry file and hit the green "Run" button.
Golfed version was based off of this program:
This Brainetry program is a rather
simple one.
We just need to take two
integers as input from the user (ASCII codepoints)
and then we sum them.
Easier said than done,
right?
Wrong, this one is easy said AND done ;)
Just have to manipulate the inputs wisely.
Mornington Crescent, 403 bytes
This challenge is pretty trivial given Mornington Crescent's many functions, but it still clocks in at 403 bytes due to the syntax of the language itself.
Take Northern Line to Bank
Take Circle Line to Bank
Take District Line to Parsons Green
Take District Line to Bank
Take Circle Line to Hammersmith
Take District Line to Parsons Green
Take District Line to Parsons Green
Take District Line to Upminster
Take District Line to Bank
Take District Line to Upminster
Take District Line to Bank
Take Circle Line to Bank
Take Northern Line to Mornington Crescent
The program parses the two numbers from the input string via Parsons Green, adds them in Upminster, and returns the result. This is slightly complicated by the fact that a number must be used to 'reset' Parsons Green after it has been used once so it doesn't overwrite any data.
Quantum Circuit 6*Nbits+1 Gates (25 for two 4-bit numbers)
Based on the ripple adder of Cuccaro et al
- Qubits 0/9 should be left as 0
- 1:3 represent A in binary
- 5:8 represent B in binary
- Answer appears in qubits 5:9
Microsoft PowerPoint (macro-free), 176 animations, 73 shapes on main slide
(Numbers estimated from XML explorer)
I made a 2-bit adder with carry input and carry output. Numbers represented in binary. Get the PPTX here. Directions are included in the presentation.
I'm thinking this is very golf-able, but it's a fun proof of concept anyway. Obviously, this can be extended to more bits, but frankly, programming in PowerPoint is extremely tedious with its current UI, so I'm going to move on to other things.
How it works
When the presentation starts, it is in input mode. The switches toggle a motion path animation back and forth to indicate 1 or 0.
When the Run button is clicked, it steps through each of the input bits and uses the K-maps for the carry and result bits. If there is a value dependent on the result (such as the carry bit over the second column), it uncovers a button that allows the machine to read that bit. When the final digit is clicked, the machine enters a halt state, displaying the final result in the bottom row.
Help, Wardoq!, 1 byte
A
Note: Due to technical limitations, this interpreter takes code as the first line, and input as every line after.
SystemVerilog (HDL) (93 chars)
Here's a pretty simple 8-bit full adder implementation (including input carry for chaining).
module a(input[7:0] a,input[7:0] b,input d,output c,output[8:0] f);
assign f=a+b+d;
endmodule
Inputs: [7:0]a and b, carry bit d.
Outputs: [8:0]f. The top bit can be used as a carry output signal.
JavaScript (Node.js), 18 bytes
a=>eval(a.join`+`)
Explanation :
a => // lambda function taking array as input
eval( // begin eval
a.join`+` // joins all elements in `a` with a `+` sign in between
) // end eval (since this is now a string it gets added up)
Alternate :
JavaScript (Node.js), 9 bytes
x=>y=>x+y
Explanation :
x => // lambda taking x as input 1
y => // which returns lambda with input y
x + y // which returns sum of x and y
Intcode, 22 bytes
3,0,3,1,1,0,1,2,4,2,99
Fairly basic. IO boilerplate takes up most of the bytecount, given that the language has addition as a builtin (1,0,1,2 would be a valid answer, if snippets were allowed)
Python 3, 14 bytes
lambda x,y:x+y
Pretty self-explanatory lol
hashmap, 10 bytes
i" "ĥdĐ+
Explanation:
i" "ĥdĐ+
i Take input
" " Push space
ĥ Split the input by space
dĐ Convert the list to a double then flatten the list
+ Add them together
√ å ı ¥ ® Ï Ø ¿ , 4 bytes
II+o
Fairly basic program, as to be expected.
Explanation
I › Take input from the command line, evaluate and push to stack
I › Take another input
+ › Add the two together and push to the stack
o › Output the top value on the stack
Pepe 19 bytes
REeerEeeREEEEEEReEE
Try it not online but at the online interpreter
My first Pepe answer... made me want to reeeeeee (not reeally)
REee #Input first integer
rEee #Input second integer
REEEEEE #Add two integers
ReEE #Print result as integer
Re:direction, 9 bytes
▲♦▼
►♦
▲
Suprisingly small for a language like this. Re:direction is a language that only uses arrows, a queue, and ♦ to go in the direction of the first item on the queue
Explanation
Note: I'll be using .'s to represent instructions I'm not talking about, and I'll split it up into a couple of sections
Input is automatically pushed to the queue as ►'s seperated by ▼'s
▲..
►. Pushes ▲ into the queue, used as a marker later
.
...
►♦ Loop that goes through every item of the queue (the input). If its ►, it does nothing to it.
▲ If it is ▼, it gets replaced by ▲, which is ignored by the output
.♦▼ If it is an ▲, another ♦ is run, which goes right and removes one item from the queue to make the output correct
.♦ Then, since the ▼ is the only arrow in it's column, it gets pushed to the queue then the program halts
.
Seed, 11 bytes
4 141745954
Damn, It's quite small
Owk, 13 bytes
Owk is an abandoned language created by Phase.
a:λx.λy.x+y
This is written in an unofficial fork(but it's shorter):
a:x+y
Obx, 3 bytes
Obx is an abandoned language created by Phase in 2016.
+xy
With an input of 1 and 2, this program would output 3. Let's learn why.
+xy creates a function that adds x (the first argument) and y (the second argument). The last function created is called with whatever the input is.
Whitespace, 36 bytes
[S S S N
_Push_0][S N
S _Duplicate][T N
T T _Read_STDIN_as_integer][T T T _Retrieve][S S S N
_Push_0][S N
S _Duplicate][T N
T T _Read_STDIN_as_integer][T T T _Retrieve][T S S S _Add][T N
S T _Print_as_integer]
Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.
Try it online (with raw spaces, tabs, and newlines only).
Explanation:
When a number is read from STDIN it stores it in the heap-address specified at the top of the stack, and then the Retrieve function can be used to get it later on. So to read a number from STDIN you'll need the following sub-steps:
- Put a number on the stack:
Sat the start: Enable Stack ManipulationS: Push what follows as number to the top of the stackS/T: Positive or negative number- Some
Sand/orTfollowed by aN: Number as binary, whereS=0andT=1.
- Duplicate this number:
Sat the start: Enable Stack ManipulationNS: Duplicate the top value on the stack
- Read a number from STDIN, and store it in the heap-address specified at the top of the stack:
TNat the start: Enable I/OTT: Read a number, and place it in the heap specified at the top of the stack
- Retrieve this number from the heap
TTat the start: Enable Heap AccessT: Retrieve a value from the heap with the given heap-address at the top of the stack
So here is every step of the full program above:
Command Explanation Stack Heap STDIN STDOUT STDERR
SSSN Push 0 [0] {}
SNS Duplicate top (0) [0,0] {}
TNTT Read STDIN as integer [0] {0:-3} -3
TTT Retrieve heap (at 0) [-3] {0:-3}
SSSN Push 0 [-3,0] {0:-3}
SNS Duplicate top (0) [-3,0,0] {0:-3}
TNTT Read STDIN as integer [-3,0] {0:5} 5
TTT Retrieve heap (at 0) [-3,5] {0:5}
TSSS Add top two [2] {0:5}
TNST Print top as integer [] {0:5} 2
Exit with error
Unfortunately the heap-address cannot be negative, otherwise the second SSSN (Push 0) could have been golfed to SNS (duplicate first STDIN input as heap-address).
Clam, 4 bytes
p+rr
Explanation
p print ...
+ the sum of ...
r the first line of STDIN and ...
r the second line of STDIN
Intel 8080 machine code, Altair 8800, 22 bytes
This will add two integers of nearly any size (16, 32, 64-bit, etc) using an Intel 8080 8-bit CPU (c. 1974). This is implemented as a full program, running on a MITS Altair 8800.
Code listing and programming instructions:
Step Switches 0-7 Control Switch Instruction Comment
1 RESET
2 00 001 110 DEPOSIT MVI C, 2 ; loop counter set to word size
3 00 000 010 DEPOSIT NEXT ; value is 2
4 00 010 001 " LXI D, 16H ; load address of first term into E:D
5 00 010 110 " ; at memory address 16H
6 00 000 000 "
7 00 100 001 " LXI H, 18H ; load address of second term into H:L
8 00 011 000 " ; memory address 16H + word size = 18H
9 00 000 000 "
10 10 101 111 " XRA A ; clear accumulator
11 00 011 010 " LOOP:LDAX D ; load [E:D] into A
12 10 001 110 " ADC M ; add [H:L] + previous carry, to A
13 00 010 010 " STAX D ; store result in A to [E:D]
14 00 001 101 " DCR C ; decrement loop counter
15 11 001 010 " JZ DONE ; if counter is zero, end addition
16 00 010 101 " ; jump to step 23
17 00 000 000 "
18 00 010 011 " INX D ; first term next byte
19 00 100 011 " INX H ; second term next byte
20 11 000 011 " JMP LOOP ; restart loop
21 00 001 001 " ; jump to step 11
22 00 000 000 "
23 01 110 110 " DONE:HLT ; halt CPU
24 00 001 110 " ; Term 1 low byte (14)
25 00 000 000 " ; Term 1 high byte (0)
26 00 001 111 " ; Term 2 low byte (15)
27 00 000 000 " ; Term 2 high byte (0)
31 RESET ; Reset program counter to beginning
32 RUN
33 STOP
34 00 010 110 EXAMINE ; low byte of output displayed on D7-D0
35 EXAMINE NEXT ; high byte of output displayed on D7-D0
If entered correctly, RAM contents should look like:
0000 0e 02 11 16 00 21 18 00 af 1a 8e 12 0d ca 15 00
0010 13 23 c3 09 00 76 0e 00 0f 00
I/O:
The above program adds two 16-bit integers, located in memory address 16H and 18H. This could accept larger integers, for example 32-bit integers by changing steps 3 and 8 to values 4 and 20H respectively, and then input would be in 16H and 20H. Numbers are represented in memory as little endian.
Output is displayed on lights D7-D0.
Example: 14 + 15 = 29 = 00 011 101
Example: 1234 + 4321 = 5555 = 00 010 101, 10 110 011
BitCycle, 49 bytes
?Av
?v<> \Cv
~=B/Av
^+ <
+ B\^v /~v
> /! <
Made so much more complicated by the signed numbers, otherwise it could just be:
?!
?^
This takes input and outputs as signed unary, though the -U flag is used to translate to decimal.
Explanation:
?Av From input 1
?v< And input 2
~=B Push positive numbers into the top B collector
^
+ B Invert bits of negative numbers and push into the bottom B collector
> \ Filter one bit from each collector
B/Av And the rest go into the A collector
+ < And then back into the B collectors
B\^ If both positive and negative, then both bits are destroyed
> / Otherwise they reflect off the > and go right of each of the \/
> \Cv Collect the remainder of negative bits in the C collector
Invert the bits and output
v /~v Send one of the 0s to output to represent a negative number
> /! < Positive remainders go straight to output
Geometry Dash - 15 objects
Finally done.
15 objects aren't much, but it was still a nightmare to do this (especially because of the negative numbers).
Because I would have to insert 15 images here for how to reproduce this, I just uploaded the level. The level ID is 5216804. The description tells you how to run it and you can copy it since it is copyable.
Explanation:
The top-left trigger (Instant Count 2) checked if the first addend was 0. If it was, it then checked if the second addend was positive or negative. If it was positive, it transferred the value from the second addend to the sum (BF-style, using loops) and if it was negative, it would do the same thing.
The reason why we need to check if the second addend is positive or negative is that we would need to subtract one from the second addend and add one to the sum or add one to the second addend and subtract one from the sum respectively.
If the first addend is not zero, it tests whether it is positive or negative using the process above. After one iteration in the while loop, it tests to see if the first addend is zero and if it is, it does the process described at the beginning of the explanation.
Since Geometry Dash is remarkably similar to BF, you could make a BF solution out of this.
RUST, 29 bytes
Save 5 bytes thank to ASCII-only
fn s(a:i32,b:i32)->i32{a+b}
ASCII-only also beat my solution here
Charcoal, 4 2 bytes
I⁺
Explanation
I Cast to string
⁺ Add
(implicit) Input number
(implicit) Input number
PHP, 20 bytes
Assuming the script will always have 2 arguments
<?php
$argv[0] = 10;
$argv[1] = 23;
?>
<?=array_sum($argv); // Well, all the arguments are stored on the $argv array
// the array can just be added
F# (Mono), 3 bytes
(+)
In F#, the + operator is defined as a function named (+).
The following prints 3 and shows how to pass parameters to this function. To me, this is the clearest way to see that (+) is actually a function.
printf "%d" ((+) 1 2)
Re:direction, 9 characters, 3 bytes
♦►
♦►
◄ ▼
In Re:direction's packed encoding:
F1 F1 B6
(Byte F1 encodes ♦►; B6 encodes ◄ ▼).
Explanation
Re:direction is a 2D language that uses a queue of direction commands. At the start of the program, the queue is initialized from user input; an integer n becomes n copies of ►, then ▼. From that point onwards, whenever we use a direction command, it controls the direction in which the instruction pointer moves but also gets pushed onto the tail of the queue.
The ♦ command shifts one direction from that queue, and moves in that direction. So ♦► is effectively a loop that moves any number of ► from the head of the queue to the tail; as long as the queue starts with ►, we'll shift it and go right, and hit the ► in the program, which sends the IP right back where it started (wrapping around the edge of the program) and pushes the ► to the tail of the queue instead. Once we hit the ▼, it gets deleted from the queue and we move onwards.
We can note that ♦► does not preserve the ▼ in the queue. As such, running it twice deletes both ▼ from the initial queue, leaving us with a number of ► equal to the sum of the initial two numbers.
We need to encode the output the same way as the input, meaning that we need to add a ▼ and halt the program. A direction command that points to itself will run and then immediately halt the program, so we can use a ▼ on a column by itself to do both jobs. We do, however, need to get there; this program uses a ◄ to do so (because stray ups and lefts in the queue won't affect the output).
Alchemist, 253 211 205 bytes
_->u+v+2r
u+r->In_a+In_x
v+r->In_b+In_y
a+b->Out_"-"
0_+0r+0d+0a+0b->d
0d+0a+x+b+y->b
0r+0d+a+0b+0y->d+Out_"-"
0r+0d+0b+a+0x->d
a+x+0b+y->a
0r+0d+0a+b+0x->d+Out_"-"
0r+0d+0a+b+0y->d
d+x->d+y
d+y->d+Out_"1"
Since Alchemist can't handle negative numbers (there can't be a negative amount of atoms) this takes 4 inputs on stdin in this order:
- sign of
x(0 ->+and 1 ->-) - the number
xitself - sign of
y(0 ->+and 1 ->-) - the number
yitself
Output is in unary, try it online!
(for your convenience, here is a wrapper, converting inputs and returning decimal outputs)
Explanation & ungolfed
Since Alchemist applies the rules non-deterministically we need a lot of 0-rules.. Initially there is only one _ atom, so we use that to read the inputs:
_->u+v+2r
u+r->In_a+In_x
v+r->In_b+In_y
The following rules can't be applied because they all require 0r, now we have a, b as the signs of x and y respectively.
# Case -x -y: we output the sign and remove a,b
# therefore we will handle them the same as +x +y
0_+0r+0d+a+b->Out_"-" #: 0_+0r+0d ⇐ a+b
# Case +x +y: doesn't need anything done
0_+0r+0d+0a+0b->d
# Case +x -y:
## remove one atom each
0_+0r+0d+0a+x+b+y->b #: 0_+0r ⇐ x+b
## if we had |y| > x: output sign and be done
0_+0r+0d+a+0b+0y->d+Out_"-" #: 0_ ⇐ 0r+a
## else: be done
0_+0r+0d+0b+a+0x->d #: 0_ ⇐ 0r+a
# Case -x +y is symmetric to the +x -y case:
0_+0r+0d+a+x+0b+y->a #: 0_+0r+0d ⇐ a+y
0_+0r+0d+0a+b+0x->d+Out_"-" #: 0_ ⇐ 0r+b
0_+0r+0d+0a+b+0y->d #: 0_ ⇐ 0r+b
# All computations are done and we can output in unary:
0_+d+x->d+Out_"1" #: 0_ ⇐ d
0_+d+y->d+Out_"1" #: 0_ ⇐ d
To the right of some rules I marked some golfs with #: y ⇐ x which should read as: "The conditions x imply y at this stage and thus we can remove it without changing the determinism"
Aheui (esotope), 15 bytes(5 characters)
방방다망히
Meet Aheui(아희), A Korean alphabet-based esoteric programming language.
Bit, 985 bytes (non-competing)
I spent 2 hours on this, I present to you, an answer in Bit.
Behavior is undefined if one of the input numbers OR the sum of them is >= 10000, each of the 4 digits should be written aka 5 -> 0005, STDIN is read 2 times to get the 2 numbers.
Done without using extra files (that's an achievement for Bit programs, because no extra files means no if statements)
BIT 1
BYTE 1
BIT 0
BIT 1
BYTE 2
BIT 1
BIT 1
BYTE 3
BIT 0
BIT 1
BIT 0
BIT 1
BYTE a
BYTE b
BYTE c
BIT 0
BIT 0
BIT 0
BIT 0
BIT 1
BIT 1
BYTE d
BYTES 1 e
POWER a 2 b
POWER a 3 c
STORE 4 i
BYTE n
BYTE r
BYTE 0
BYTE t
BYTE y
BYTES 1 m
IN e i
DUMP_ARRAY i
SUBTRACT d
SHIFT
SUBTRACT d
MULTIPLY a
SHIFT
SUBTRACT d
MULTIPLY b
SHIFT
SUBTRACT d
MULTIPLY c
SHIFT
ADD
ADD
ADD
PUSH n
IN e i
DUMP_ARRAY i
SUBTRACT d
SHIFT
SUBTRACT d
MULTIPLY a
SHIFT
SUBTRACT d
MULTIPLY b
SHIFT
SUBTRACT d
MULTIPLY c
SHIFT
ADD
ADD
ADD
DUMP n
ADD
PUSH r
DIVIDE r a
DUP
TRUNC 0
FLIP
SUBTRACT
MUlTIPLY a
DUP
PUSH m
PUSH t
DIVIDE r b
DUP
TRUNC 0
FLIP
SUBTRACT
MUlTIPLY b
DUP
PUSH y
SUBTRACT t
DIVIDE a
PUSH m
DIVIDE r c
DUP
TRUNC 0
FLIP
SUBTRACT
MUlTIPLY c
DUP
PUSH t
SUBTRACT y
DIVIDE b
PUSH m
SUBTRACT r t
DIVIDE c
PUSH m
DUMP_ARRAY m
FLIP
ADD d
SHIFT
ADD d
SHIFT
ADD d
SHIFT
ADD d
SHIFT
OUTOF
PRINT
PRINTLN
6502 machine code - 8 bytes
A5 08 65 09 85 0A 4C 06
Input stored at 0x08 and 0x09, output storad at 0x0A
Java, 11 10 9 bytes
a->b->a+b
Ungolfed test code
public static void main(String[] args) {
Function<Integer, Function<Integer, Integer>> func = (a -> b -> a + b);
System.out.println(func.apply(5).apply(10));
}
FRACTRAN, 3 bytes
2/3
Take 2^a*3^b as input, return 2^(a+b).
I'm not sure whether or not extra bytes should be added for input encoding and output decoding.
JavaScript (Node.js), 28 bytes
f=(a,b)=>b?f(a^b,(a&b)<<1):a
Not for winning rather just for fun. Definitely not the shortest but my fav.
m4, 19 characters
(9 characters code + 10 characters command line options)
eval(a+b)
Strictly because the question owner wrote “I'm interested to see how it can be implemented”.
Sample run:
bash-4.4$ m4 -Da=5 -Db=16 <<< 'eval(a+b)'
21
jamal, 22 characters
(12 characters code + 10 characters command line options)
{#+ {a} {b}}
Strictly because the question owner wrote “I'm interested to see how it can be implemented”.
Sample run:
bash-4.4$ perl jamal.pl -Da=5 -Db=16 add.jam
21
Pain-Flak, 6 bytes
)}{}{(
Pain-Flak is Brain-Flaks evil twin. When translated into regular brain-flak, we get:
({}{})({}{})
The first one is the standard addition snippet. The second one is effectively a NO-OP.
Perl6, 3
Standalone function:
*+*
Complete program (19 bytes):
say [+] slurp.words
Beatnik, 9 bytes
x x kg ja
I/O in codepoint values, so !! -> B, B! -> c. Works with larger numbers on Unicode interpreters.
Momema, 9 bytes
-8+*-8*-8
Momema uses prefix syntax, and assignment statements are implicit (simply writing two expressions ab acts as *a = b;), so this program looks like this:
*(-8) = *(-8) + *(-8)
The cell -8 in Momema is memory-mapped for numeric I/O. Reading from it causes input, and writing to it causes output.
print_num(read_num() + read_num())
Forked, 5 bytes
$$+%&
$$- read two integers+- add top two stack values%- print top of stack as integer&- "terminate", prevents the IP from wrapping
Wumpus, 5 bytes
II+O@
Explanation
Straight-forward and boring:
I Read the first integer.
I Read the second integer.
+ Add them.
O Output the result.
@ Terminate the program.
AWK - 11 bytes
The code:
{$0=$1+$2}1
Can run as:
awk '{$0=$1+$2}1' <<< "98.342 77.123"
Could also store the code in a file sum.awk and run as:
awk -f sum.awk <<< "98.342 77.123"
If you wanted a program that wouldn't require knowing that you were using awk, you could create a file sum that looks like:
#!/bin/awk -f
{$0=$1+$2}1
Assuming of course that the awk executable is located at /bin/awk.
If this file is made executable, it could simply be run as:
sum <<< "98.342 77.123"
or
echo "98.342 77.123" | sum
Or place the numbers in a file, DATA, and run as:
sum DATA
A tiny bit of explanation. $0 represents a single line of input that is also automatically split into numbered fields. This line is then overwritten by the assignment. The lone 1 acts as a label that always evaluates to true and its default action is to simply print the current $0.
cubix, 6 bytes
OI\@+I
This maps onto a cube with edge length one.
O
I \ @ +
I
Much the same as other stack based answers, push input to the stack twice, add, output and terminate.
Operations are
I, input number\, reflect downI, input number+, add top two of stackO, output number\, reflect to the right@, terminate
The following will also work
II/@+O
Mapping to
I
I / @ +
O
Verbosity, 388 bytes
Include<Input>
Include<Output>
Include<Integer>
Include<MetaFunctions>
Input:DefineVariable<i; 0>
Output:DefineVariable<o; 0>
Integer:DefineVariable<f; Input:ReadEvaluatedLineFromInput<i>>
Integer:DefineVariable<s; Input:ReadEvaluatedLineFromInput<i>>
Integer:DefineVariable<r; Integer:Sum<f; s>>
Output:DisplayAsText<o; r>
DefineMain<> [
MetaFunctions:ExecuteScript<MetaFunctions@FILE>
]
Outputs as Integer<result> (the natural representation of integers in Verbosity)
Ungolfed
Include<Input>
Include<Output>
Include<Integer>
Include<MetaFunctions>
Input:DefineVariable<in; 0>
Output:DefineVariable<out; 0>
Integer:DefineVariable<first; Input:ReadEvaluatedLineFromInput<in>>
Integer:DefineVariable<second; Input:ReadEvaluatedLineFromInput<in>>
Integer:DefineVariable<result; Integer:Sum<first; second>>
Output:DisplayAsText<out; result>
DefineMain<> [
MetaFunctions:ExecuteScript<MetaFunctions@FILE>
]
Pyth - 5 Bytes
AQ+GH
A Set variables G and H to the first two elements of
Q Input;
Implicitly Print
G G
+ plus
H H
Whispers, 34 bytes
> Input
> Input
>> 1+2
>> Output 3
Don't worry, this doesn't just Output 3, or perform 1+2
DUP, 37 bytes
[0[`$32-][\10*($48-)+\%]#%]⇒II(I)+.
Both integers have to be space terminated (ASCII 32)
Explanation, taking example 11+3:
[0[`$32-][\10*($48-)+\%]#%]⇒I {I defines an operator that converts space-terminated character strings to integer numbers}
[ ]⇒I {Definition of operator I}
0 {push 0 on ds (data stack)}
[cond.][ block ]# {while condition nonzero do block}
` {read character from STDIN to ds}
$ {DUP ds top value}
32- {push 32 on ds, SUB}
\ {SWAP topmost ds values}
10* {push 10 on ds, MUL}
( {move ds top value to rs (return stack)}
$ {DUP}
48- {push 48, SUB}
) {move rs top back to ds}
+ {ADD}
\% {SWAP, POP}
% {POP}
I reads in numbers as single characters and converts them to decimal numbers (basically by a base 10 shift left, add loop). I also checks if a terminating space is found, and if that’s the case, exits the read in loop and removes junk from the stack.
Actual program:
I {Read in first integer character by character}
( {move ds top to rs}
I {read in second integer}
) {move first integer back from rs to ds}
+ {ADD}
. {output sum to STDOUT}
Try it out in this online DUP interpreter.
NotQuiteThere, 8 bytes
0-- 0- 0
Given that one of the aims of this languages was to be unable to perform addition, I think I failed.
How it works
# Implicit input; 10 and 20
0 # Push 0; STACK = [10 20 0]
- # Subtract; STACK = [10 -20]
- # Subtract; STACK = [-30]
0 # Push 0; STACK = [-30 0]
- # Subtract; STACK = [30]
0 # Push 0; STACK = [30 0]
# Output 30;
LOLCODE, 75 bytes
HAI 1.3
I HAS A J
GIMMEH J
I HAS A Q
GIMMEH Q
VISIBLE SUM OF J AN Q
KTHXBYE
INTERCAL, 74 bytes
DO WRITE IN .1
DO WRITE IN .2
DO (1000) NEXT
PLEASE READ OUT .3
DO GIVE UP
INTERCAL is so user-friendly that even something so simple as adding requires a call to the system library in DO (1000) NEXT. I'm working on a more complete answer using only INTERCAL's, uh, "unique", built-in operators.
PLEASE NOTE for those trying this program: INTERCAL takes input in numbers with each digit as an English (or Sanskrit, Basque, Tagalog, Classical Nahuatl, Georgian, or Kwakiutl) word, separated by spaces, so ONE ONE inputs 11, DALAWA LIMA inputs 25, and ZAZPI BAT BI inputs 712. A newline separates different inputs, and because of how the parser works, there must be a trailing space at the end of the last input. Numbers are output as Roman Numerals.
Bash script, 12 bytes
expr $1 + $2
Save as add.sh, then run bash add.sh [argument] [argument].
MS Excel / Google Sheets, 6 Bytes
Anonymous Worksheet function that takes input from the range A1:B1 and outputs their sum to the worksheet cell that holds this formula.
=A1+B1
Bitwise, 89 bytes
IN 1 &1
IN 2 &1
LABEL &1
AND 1 2 *1
XOR 1 2 *2
SL *1 &1 1
MOV 2 *2 &1
JMP @1 *1
OUT *2 -1
Input and output are raw byte values as that is the only method of I/O for this language. Allowed per this consensus. Try it online!
Ungolfed, written properly, and commented:
IN 1 &1 -1 read a character into r1 if l1 truthy, discarding result
IN 2 &1 -1 read a character into r2
LABEL &1 create label 1 here
AND 1 2 *1 set fr1 to r1 & r2 where & represents bitwise AND
XOR 1 2 *2 set fr2 to r1 ^ r2 where ^ represents bitwise exclusive or
SL *1 &1 1 set r1 to fr1 << 1 where << represents bitwise left shift
MOV 2 *2 &1 move fr2 into r2 if &1 truthy
JMP @1 *1 jump to label 1 if fr1 truthy
OUT *2 &1 -1 print frame register 2 if l1 truthy, discarding result
Note that fr is short for frame register, r is short for register and l is short for literal.
Excel VBA, 8 Bytes
Anonymous VBE immediate window function that takes arguments from the range [A1:B1] and outputs their sum to the VBE immediate window
?[A1+B1]
Element, 4 bytes
__+`
Explanation:
_ input to stack
_ input to stack
+ add top two stack elements
` pop to output
Little Man Computer, 23 bytes (source)
INP
STA 6
INP
ADD 6
OUT
With HLT, 27 bytes (source)
INP
STA 6
INP
ADD 6
OUT
HLT
Piet - 5 Codels
I didn't see one in Piet, so I decided to post one.
Hold on, let me scale that up a bit for you to see.
The codel size is 25.
I tested this on npiet. When run, the program will ask for a number, then for another, and then print it out. Due to the nature of Piet, it will continue this cycle until you interrupt it.
There are 17 other variants of the same code. Everything is relative in Piet, so changing the start color will change the rest of the colors. Breaking down the code is as follows:
Light Red - Does nothing.
Dark Blue (hue shift 4, darkness shift 2) - Pushes a number from STDIN.
Green (hue shift 4, darkness shift 2) - Pushes a number from STDIN.
Teal (hue shift 1, darkness shift 0) - Pushes the sum of the top two numbers in the stack.
Dark Green (hue shift 5, darkness shift 1) - Writes top of stack to STDOUT as a number.
Lost, 9 bytes
v<<<
>%+@
Explanation
This is about as simple as lost programs get. Since the start location and direction are random we need to have a stream around the edges to catch the ip we then direct it into the %+@ which will perform the addition.
Alternative version
////
\%+@
Cubically, 10 8 bytes
$+7$+7%6
Cubically is a language relatively early in development. Its most unique feature is that its primary memory takes the form of a virtual Rubik's Cube with the colors replaced by numbers from 0 to 5. This Rubik's Cube cannot be written to, and manipulation of it is done only through rotation commands, with only a single "notepad" memory space which supports more traditional manipulation. All operations consist of a non-digit character, followed by any number of digits representing the memory location to use: 0-5 for the face centered on the chosen number, 6 for the notepad, and 7 for the "input buffer".
All that said, this program uses none of the language's unique features and instead does all operations in the notepad and the input buffer which was added today to finally qualify for this challenge since before now there simply was no input. Explanation:
Notepad defaults to 0
$ Read an integer from STDIN
+7 Add the value in [7] (input buffer) to the notepad
$ Read an integer from STDIN
+7 Add the value in [7] (input buffer) to the notepad
%6 Output the value in [6] (notepad) to STDOUT
The language was updated and now allows the $ command to be called without an argument, saving 2 bytes by not including unused characters
Look forward to more Cubically answers as advanced features are added such as looping and branching!
tcl, 10
expr $a+$b
If you have namespace path tcl::mathop you can do it shorter for every arithmetic operation:
tcl, 7
+ $a $b
test case on: http://rextester.com/live/FLFPTH24568
Commentator, 4 bytes
////
Outputs by char code. If this isn't allowed, a 6 byte solution is
////*/
which outputs by numerical value.
R, 3 bytes
"+"
or
sum
"+" can be called as a function like so: "+"(a,b) because the R interpreter will interpret it (with the parentheses) as the primitive addition function .Primitive("+"). Alternatively, sum will add arbitrary arguments. These are both functions.
Ruby, 17 bytes
def f(i,j)i+j;end
Functions in Ruby return the last evaluated expression.
SQL, 19 bytes
SELECT SUM(a)FROM t
Our rules allow SQL to input via a pre-existing named table (in this case table t with INT field a), so just SUM it up and output the results.
Works for however many rows are in the input table.
Triangular, 6 bytes
$.$%+<
Formats into this triangle:
$
. $
% + <
Without directionals or no-ops, the above turns into this: $$+%
Triangular uses postfix notation.
$- read input as integer+- add%- print as integer
Check, 2 bytes
+p
Input is from command-line args.
+ adds the two numbers, and p prints it.
Standard ML (MLton), 3 bytes
op+
An anonymous function that behaves as the + operator, on a tuple of two integers.
Decimal, 12 bytes
81D81D41D301
Explanation:
81D ; builtin - read INT from STDIN, push to stack
81D ; builtin - read INT from STDIN, push to stack
41D ; math +, pop values used, push result
301 ; print from stack to STDOUT
Add++, 7 bytes
+?
+?
O
+? adds the input to the accumulator and the O outputs it as a number.
A function is 1 byte longer at
D,f,@@,+
Dominoes, 38,000 bytes or 37 tiles
This is created in Tabletop Simulator. Here is a video and here is the file. It is a standard half-adder, composed of an and gate for the 2^1 place value and an xor gate for the 2^0 place value.
Details
- I/O
- Start - This is included for clarity (not counted towards total) and is what 'calls' or 'executes' the function. Should be 'pressed' after input is given [Yellow].
- Input A - This is included for clarity (not counted towards total) and is 'pressed' to indicated a 1 and unpressed for 0 [Green].
- Input B - This is included for clarity (not counted towards total) and is 'pressed' to indicated a 1 and unpressed for 0 [Blue].
- Output - This is counted towards total. These dominoes declare the sum. The left is
2^1and the right is2^0[Black].
- Pressing
- To give input or start the chain, spawn the metal marble
- Set the lift strength to
100% - Lift the marble above the desired domino
- Drop the marble
Visual Basic.NET, 39 bytes
Function F(x,y)
Return x+y
End Function
Without Option Strict On (which you definitely want for any real coding), no data types are required (As type).
With Option Strict On:
Function F(x As Integer,y As Integer) As Integer
Return x+y
End Function
Alice, 7 6 bytes
Thanks to Sp3000 for saving 1 byte.
+/
o@i
Explanation
Someone say again that golfing addition in languages that have an addition built-in is trivial...
A quick primer on Alice:
- Alice has two modes: if the instruction pointer moves orthogonally, Alice is in Cardinal mode and can perform operations on integers. If the instruction pointer moves diagonally, Alice is in Ordinal mode and can perform operations on strings.
- Data type conversion happens automatically when a value of the wrong type is popped from the stack.
- Mirrors (
\and/) reflect the path of the IP through 67.5 degrees and switch between Cardinal and Ordinal mode. Here is a diagram of every possible reflection. - In Cardinal mode, if the IP hits the boundary of the grid it wraps around, as it does in many other 2D languages. If in Ordinal mode, the IP is reflected off the boundary instead.
The instruction pointer bounces all over the place in this solution:
+ Adds two implicit zeros on the stack, but effectively does nothing.
/ Send the IP southeast. Switch to Ordinal mode.
i Read all input as a single string.
We're in Ordinal mode, so the IP bounces off the corner of the grid
and moves back northwest.
/ Send the IP west. Switch to Cardinal mode.
We're in Cardinal mode, so the IP wraps to the end of the first line.
+ Try to add two numbers. The top of the stack is a string though, so Alice
implicitly replaces it with the integers contained in the string, and
then adds those two numbers.
/ Send the IP northwest. Switch to Ordinal mode.
We're in Ordinal mode, so the IP immediately bounces off the top boundary
and moves southwest instead.
o Print a string to STDOUT. Since the top of the stack is a number, that
number is first implicitly converted to its decimal string representation.
We're in Ordinal mode, so the IP bounces off the corner of the grid
and moves back northwest.
/ Send the IP south. Switch to Cardinal mode.
@ Terminate the program.
Sinclair ZX80 BASIC (4K ROM)
The usual rules about the ZX80 and its 16 bit signed integer range apply here. Anything out of this range will not add. And because PRINT A+B is too easy, I came up with two solutions:
Method 1 ~64 bytes:
This assumes that you're adding a positive integer to the first number entered:
1 INPUT A
2 INPUT B
3 IF B=0 THEN GO TO 7
4 FOR B=B/B TO ABS(B)
5 LET A=A+1
6 NEXT B
7 PRINT A
Method 2 ~24 bytes
A much simpler solution, where you are adding two -/+ integers together, simply do this:
1 INPUT A
2 INPUT B
3 PRINT A+B
Both of these listings are likely to work on all variants of 8-bit BASIC, although would not be optimised on most of them.
AHK, 15 bytes
1+=%2%
Send,%1%
1 and 2 are, by default, the first two arguments passed in to a program. Sometimes you have to escape them with percent signs so it doesn't confuse the variable 1 with the number one.
Wise, 12 bytes (non-competing)
Mistah Figgins has me beat here
[:??:?^?&<]|
I just made this language so I thought I would try the basics.
Explanation
[ ... ] #Loop until our carry is zero
: #Duplicate the top
?? #Roll the top two to the bottom
: #Duplicate the top
? #Roll to the bottom
At this point we have n m m n on the stack
^ #Xor n and m
? #Roll that to the bottom
& #And n and m to create the carry over
< #Bitshift to the left
| #Remove the extra zero with an or
Wise, 9 bytes
[?~-!-~]|
Takes 2 numbers in, A, and B.
Implicit input
[ .... ] While the top (B) != 0, repeat:
? Move B to the bottom
~- Add 1 to the top (A)
! Move B back to the top
-~ Subtract 1 from the top (B)
| Gets rid of the 0 on top by ORing the top 2
Implicit output
It boils down to "Add 1 to A, B times."
Less cool than the other Wise answer, but also shorter.
C, 35 bytes
s(x,y){return y?s(x^y,(x&y)<<1):x;}
What I've done here is defined addition without the use of boolean or arithmetic operators. This recursively makes x the sum bits by 'xor', and y the carry bits by 'and' until there is no carry. Here's the ungolfed version:
int sum(int x,int y){
if(y==0){
//anything plus 0 is itself
return x;
}
//if it makes you happier imagine there's an else here
int sumBits=x^y;
int carryBits=(x&y)<<1;
return sum(sumBits,carryBits);
}
J, 4 bytes
I've defined a function f and set it to the built-in addition operator.
f=:+
Taxi, 418 bytes
Go to Post Office:w 1 l 1 r 1 l.Pickup a passenger going to The Babelfishery.Pickup a passenger going to The Babelfishery.Go to The Babelfishery:w 1 l 1 r.Pickup a passenger going to Addition Alley.Pickup a passenger going to Addition Alley.Go to Addition Alley:e 5 l 1 l.Pickup a passenger going to The Babelfishery.Go to The Babelfishery:w 1 r 1 r.Pickup a passenger going to Post Office.Go to Post Office:e 1 l 1 r.
REXX, 15 bytes
arg a b
say a+b
Scala, 17 Bytes
x:Int=>y:Int=>x+y
Python 3, 22 bytes
lambda a,b:a+b
Trivial answer for a kind of trivial question.
Python, 11 3 bytes
sum
int.__add__
A simple special operator.
Carrot, 5 bytes, non-competing
$^F+$
Try it online! (no permalink)
Input numbers are separated by a newline like so:
x
y
$ in c^rrot mode (the code before the first ^) pops the first value from the input array. So now the stack contains x. After that, this value is converted to a number using F. Then we add it with $, the next value in the input array, ie y. Output is implicit, so this outputs x+y.
An alternative at the cost of 1 byte would be:
#^A +
note the trailing space
# takes all of the input (separated by a space), and converts it to an Array by splitting on s. Then encounter a +, which is given a as its argument, meaning that all the elements of the array will be summed up.
SmileBASIC, 13 bytes
INPUT A,B?A+B
Binary lambda calculus, 4.125 bytes
Input and output as Church numerals.
00000000 01011111 01100101 11101101 0
In lambda calculus, it is λm. λn. λf. λx. m f (n f x).
De Bruijn index: λ λ λ λ 4 2 (3 2 1)
Lambda calculus is a concise way of describing a mapping (function).
For example, this task can be written as λx. λy. x + y
The thing to note is, that this is not a lambda (function) which takes two arguments. This is actually a nested lambda. However, it behaves like a lambda which takes two arguments, so it can be informally described as such. Every lambda formally only takes one argument.
For example, if we apply this lambda to 3 and 4:
(λx. λy. x + y) 3 4 ≡ (λy. 3 + y) 4 ≡ 3 + 4 = 7
So, the first lambda actually returns another lambda.
Church numerals is a way of doing away with the extra signs, leaving with only lambda symbols and variables.
Each number in the Church system is actually a lambda that specifies how many times the function is applied to an item.
Let the function be f and the item be x.
So, the number 1 would correspond to λf. λx. f x, which means apply f to x exactly once.
The number 3, for example, would be λf. λx. f (f (f x)), which means apply f to x exactly three times.
Therefore, to add two Church numerals (say, m and n) together, it is the same as applying f to x, m + n times.
We can observe that this is the same as first applying f to x, n times, and then applying f to the resulting item m times.
For example, 2 would mean f(f(x)) and 3 would mean f(f(f(x))), so 2 + 3 would be f(f(f(f(f(x))))).
To apply f to x, n times, we have n f x.
You can view m and n as functions taking two arguments, informally.
Then, we apply f again to this resulting item, m times: m f (n f x).
Then, we add back the boilerplate to obtain λm. λn. λf. λx. m f (n f x).
Now, we have to convert it to De Bruijn index.
Firstly, we count the "relative distance" between each variable to the lambda declaration. For example, the m would have a distance of 4, because it is declared 4 lambdas "ago". Similarly, the n would have a distance of 3, the f would have a distance of 2, and the x would have a distance of 1.
So, we write it as this intermediate form: λm. λn. λf. λx. 4 2 (3 2 1)
Then, we remove the variable declarations, leaving us with: λ λ λ λ 4 2 (3 2 1)
Now, we convert it to binary lambda calculus.
The rules are:
- λ becomes
00. - m n (grouping) becomes
01 m n. - numbers i becomes
1i times +0, for example 4 becomes11110.
λ λ λ λ 4 2 (3 2 1)
≡ λ λ λ λ 11110 110 (1110 110 10)
≡ λ λ λ λ 11110 110 0101 111011010
≡ λ λ λ λ 0101 111101100101111011010
≡ 00 00 00 00 0101 111101100101 111011010
≡ 000000000101111101100101111011010
Vim, 5 bytes
DJ@"<C-a>
Note that <C-a> is one byte: 0x01, which is an unprintable character.
Since V is mostly backwards compatible, you can Try it online!
Explanation:
D " Delete this line.
" By default this will save it into the unnamed register (@")
J " Get rid of this empty line
@" " Run the unnamed register as if it was typed.
" Since it's a number, it will provide a count to the next command
<C-a> " Increment the next number on this line
V, 2 bytes
À
You can't see it, but after the À there is a control-a character (ASCII 0x01).
This answer is nice because it shows one of the nice things about V: Numeric input is more convenient. Note how one input is an argument and the other is in the "input" field. This is an allowed input method, and it saves bytes because we want to run something n times, in this case the increment command or ctrl-a.
À " Arg1 times:
<C-a> " Increment the next number found on this line
Whirl, 32 bytes
01100100001100011110001000111100
Explanation
Whirl has two "rings" of operations, one for control and I/O operations and the other for math operations. The 1 command rotates the current operation ring while the 0 command switches direction of the rotation. Two 0s in a row run the current operation and switch to the other ring.
01100 Read an integer from stdin and store it at the memory pointer
100 Load that value into the math ring data storage
00 Read an integer from stdin and store it at the memory pointer
1100 Add the the values under the memory pointer to the math ring data storage
0111100 Set the control ring data storage to 1
0100 Save the math ring data storage to the memory at the memory pointer
0111100 Print the result from the memory at the memory pointer
Bubblegum, 98 bytes
00000000: 6672 6f6d 206d 6174 6820 696d 706f 7274 from math import
00000010: 2066 6163 746f 7269 616c 2061 7320 4623 factorial as F#
00000020: 0a74 7279 3a6e 3d69 6e74 2869 292d 313b .try:n=int(i)-1;
00000030: 6f3d 6e2a 2846 286e 2925 2d7e 6e3d 3d6e o=n*(F(n)%-~n==n
00000040: 290a 6578 6365 7074 3a6f 3d73 756d 286d ).except:o=sum(m
00000050: 6170 2869 6e74 2c69 2e73 706c 6974 2829 ap(int,i.split()
00000060: 2929 ))
Try it online! (Note that the online interpreter takes input in xxd format)
Bubblegum is really good at three things:
Compressing large outputs,
Testing for primality, and
Adding a sequence of numbers.
It's really really really bad at everything else.
PigeonScript, 1 byte
+
Explanation: + pops the last two items from the stack, adds them, and pushes the result to the stack. Since there is nothing on the stack, the user is prompted for input twice. The inputs are pushed, popped, added, pushed, and the program ends, outputting what's on the stack (the result of input1 + input2)
TI-Basic, 2 bytes
Very straightforward.
sum(Ans
QBIC, 6 bytes
::?a+b
It takes two cmd line params as numbers (with two :'s), names them a and b, and adds them while printing (?).
PHP, 5 bytes
bcadd
PHP has the BC-Math library for arbitrary length integers.
bcadd adds the numbers represented by the two string operands.
A full program would need 21 bytes:
<?=$argv[1]+$argv[2];
alright 20 bytes with array_sum (assuming that the file name does not start with a digit).
Turing Machine Simulator, 342 bytes
0 _ * r 1
0 * * r *
1 _ * r *
1 * * * 2
2 0 _ r *
2 * * * 3
3 _ * l 4
3 * * r *
4 _ * * halt
4 0 9 l *
4 1 0 l 5
4 2 1 l 5
4 3 2 l 5
4 4 3 l 5
4 5 4 l 5
4 6 5 l 5
4 7 6 l 5
4 8 7 l 5
4 9 8 l 5
5 _ * l 6
5 * * l *
6 _ * l *
6 * * * 7
7 _ 1 r 0
7 0 1 r 0
7 1 2 r 0
7 2 3 r 0
7 3 4 r 0
7 4 5 r 0
7 5 6 r 0
7 6 7 r 0
7 7 8 r 0
7 8 9 r 0
7 9 0 l *
Input: Two decimal integers. These can be given to the code in standard input, as arguments to the program or function, or as a list.
Ugh...
C, 66 bytes
Typical C omissions with regard to declarations, header files, and return statements. This actually works for any number of decimal integers (up to the limitations of one's shell), including none. The program can be invoked with ./a.out 1 2 [...], as an example.
main(c,v,x)char**v;{x=0;while(c-1)x+=atoi(v[--c]);printf("%d",x);}
Or, more legibly:
main(c,v,x) char**v; {
x=0;
while(c-1) x+=atoi(v[--c]);
printf("%d",x);
}
Ruby, 10 bytes
->a,b{a+b}
An anonymous Proc (I guess, if not a lambda idc) just adds its parameters. Makes use of implicit return in Ruby.
Usage: ->a,b{a+b}[1,2] or ->a,b{a+b}.call(1,2)
Java, 91 bytes
interface M{static void main(String[]a){System.out.print(new Long(a[0])+new Long(a[1]));}}
Usage: java M <num1> <num2>
Tips appreciated.
Swift, 1 byte
+
since operator + is defined as function(public func +(lhs: Int, rhs: Int) -> Int)
Befunge, 7 bytes
#v&<
+
.
@
Befunge is an esoteric language that can execute in any cardinal direction on a 2 dimensional plane. Executing left to right from the top left (default) we get the following set of operations ((x,y) = coordinates of operation with (0,0) in the top left)
(0,0): skip next cell in execution path (1,0)
(2,0): ask for user input and push it to the stack
(3,0): reverse direction of execution
(2,0): ask for user input and push it to the stack
(1,0): begin executing downward
(1,1): pop first two values on stack, add them and push result
(1,2): pop stack and output value
(1,3): end
&&+.@ would also work, and in only 5 bytes, but is not nearly as cool
2 cases:
Pyth, 5 bytes
Input format: n1, n2
code: +hQeQ
Pyth, 1 byte
Input format: n1+n2
code: Q
(But I'm not sure if the second is called "cheating" :-P)
Ruby, 17 bytes
** Edit: Big thank you to @steenbergh and @TùxCräftîñg for their help **
def c(a,b)a+b end
awk, 14 bytes
{print $1+$2}
I am not sure if this is acceptable because the arguments must be passed through a pipe using echo, or through the stdin stream in a file like so:
[user@localhost ~]$ echo '15 6' | awk -E add.awk
21
[user@localhost ~]$ echo '15 6' > numbers
[user@localhost ~]$ awk -E add.awk < numbers
21
Permissible or not, I am excited to take my first swing at code golf!
SQL, 141 Bytes
Just for fun...
Golfed:
CREATE PROCEDURE S @a INT,@b INT AS BEGIN DELETE FROM ABC INSERT INTO ABC(A)VALUES(@a)INSERT INTO ABC(A)VALUES(@b)SELECT SUM(A)FROM ABC END
GO
Ungolfed:
CREATE PROCEDURE S
@a INT,
@b INT
AS
BEGIN
DELETE FROM ABC
INSERT INTO ABC(A)
VALUES(@a)
INSERT INTO ABC(A)
VALUES(@b)
SELECT SUM(A)FROM ABC END
GO
Requires a 1 column table creating:
CREATE TABLE ABC
(
A INT,
);
Then call the stored procedure like this:
EXEC S 4, 9
--13
SHENZHEN I/O MCxxxx assembly code, 35 bytes
slx x0
mov x0 acc
add x0
mov acc x0
Take the two numbers via XBus on x0, and send the result on x0
C, 49 bytes
main(a,b){scanf("%d %d",&a,&b);printf("%d",a+b);}
Can't really do much to golf it down.
For fun:
The following works only if 0 <= sum < 256 (it's 59 bytes long):
a;main(c,v)char**v;{return a++&2?c-3:main(c+atoi(*++v),v);}
Use gcc to compile, and ./a.out [your 2 nums]; echo $? to run it.
Here's the ungolfed version of that program:
/* Global int auto-initialized to 0 */
a;
/* The main method with two int params */
/* 'c' is argc, and 'v' is argv */
main(c, v)
/* Yes, this is valid. It defines 'v' as a char** */
char** v;
{
/* Checks to see if a == 2, and increments a.
* I only want recursion to happen twice. */
if (a++ & 2)
{
/* Since "argc" is 3, we need to subtract it from the final answer */
return c - 3;
}
else
{
/* Get the next int value of "argv" and add it to 'c'.
* Then call main() again with the updated value */
return main(c + atoi(*++v), v);
}
}
So, main() returns the value of the sum of the two numbers (essentially, I'm forcing it to return a custom exit code). The program won't output the exit code, so calling echo $?, in the same command as running the program, outputs the return value of that program.
The range of exit codes only exist between 0 and 255, so if you run the program trying to sum 255 and 1, it will wrap around and output 0.
JavaScript, 27 bytes
function s(a,b){return a+b}
I thought this needed a semi-colon after the return statement, but when typing it into the Chrome Console, it works fine without.
Brain-flak, 6 bytes
({}{})
Brain-flak is a really interesting language with two major restrictions on it.
The only valid characters are brackets, i.e. any of these characters:
(){}[]<>Every single set of brackets must be entirely matched, otherwise the program is invalid.
A set of brackets with nothing between them is called a "nilad". A nilad creates a certain numerical value, and all of these nilads next to each other are added up. A set of brackets with something between them is called a "monad". A monad is a function that takes an numerical argument. So the brackets inside a monad are evaluated, and that is the argument to the monad. Here is a more concrete example.
The () nilad equals 1. So the following brain-flak code:
()()()
Is evaluated to 3. The () monad pushes the value inside of it on the global stack. So the following
(()()())
pushes a 3. The {} nilad pops the value on top of the stack. Since consecutive nilads are always added, a string of {} sums all of the top elements on the stack. So my code is essentially:
push(pop() + pop())
Minecraft 1.10.x, 924 512 bytes
Thanks to @quat for reducing the blytecount by 48 points and the bytecount by 412.
Alright, so, I took some of the ideas from this answer and made a version of my own, except that this one is capable of accepting non-negative input. A version may be found here in structure block format.
(new version looks kinda boring tbh)
Similar commands as the other answer:
scoreboard objectives add a dummy
execute @e[type=Pig] ~ ~ ~ scoreboard players add m a 1
execute @e[type=Cow] ~ ~ ~ scoreboard players add n a 1
scoreboard players operation n a += m a
tellraw @a {"score":{"name":"n","objective":"a"}}
To input numbers, spawn in a number of cows and pigs. Cows will represent value "n" and pigs will represent value "m". The command block system will progressively kill the cows and pigs and assign values as necessary.
This answer assumes that you are in a world with no naturally occurring cows or pigs and that the values stored in "n" and "m" are cleared on each run.
C, 19 bytes
f(a,b){return a+b;}
Batch, 52 Bytes
set/p x=
set/p y=
set/a z=%x%+%y%
echo %z%
pause>nul
This is the lowest byte number you will have while still making the program work. I did the challenge by making a program, not just what the operation was. This method will allow you to input any number and then any other number, including negatives, and the program will output a number.
Elixir, 7 bytes
& &1+&2
Anonymous function defined using the capture operator. Another version is &(&1+&2), however this approach saves 1 byte. The verbose version is fn a,b->a+b end - 15 bytes.
Full program with test case (yes, the . in the function call is mandatory!):
s=& &1+&2
IO.puts s.(1,6) #7
Try it online on ElixirPlayground !
C# - 11 10 bytes
a=>b=>a+b;
Apparently works in ES6 with no semicolon: 10 bytes
(a,b)=>a+b
A lambda expression.
Codelike, 6 bytes
code:
ouuabe
breakdown:
o changes the direction that the code proceeds in, turning counterclockwise until it hits a command
uu takes 2 integers from user input
a adds the two integers together and pushes the result to the stack
b prints the integer value at the top of the stack
e ends the program
You can download the compiler here!
(Full disclosure, I did create this language and I did add the b command after reading this challenge but it was something I was already considering adding and it doesn't complete the challenge on its own so I feel that it doesn't violate the rules.)
Shakespeare Programming Language, 155 152 bytes
.
Ajax,.
Ford,.
Act I:.
Scene I:.
[Enter Ajax and Ford]
Ajax:
Listen to thy heart
Ford:
Listen to THY heart!You is sum you and I.Open thy heart
[Exeunt]
Ungolfed:
Summing Two Numbers in Verona.
Romeo, a numerical man.
Juliet, his lover and numerical counterpart.
Act I: In which Italian addition is performed.
Scene I: In which our two young lovers have a short chat.
[Enter Romeo and Juliet]
Romeo:
Listen to thy heart.
Juliet:
Listen to THY heart! Thou art the sum of thyself and I. Open thy heart.
[Exeunt]
I'm using drsam94's SPL compiler to compile this. To test:
$ python splc.py sum.spl > sum.c
$ gcc sum.c -o sum.exe
$ echo -e "5\n16" | ./sum
21
Nim, 3 bytes
`+`
In Nim, the functions behind operators are specified by surrounding them in backticks. This is then the function behind the addition operator, which adds its two parameters.
Use like this:
echo `+`(1, 1)
To test:
$ echo "echo \`+\`(1, 1)" > sum.nim
$ nim c sum.nim
$ ./sum
2
Brainfuck, 224 bytes
+[-->++++++[-<------>]+>>,----------]<,[<+++++[->-------
-<]+[<<<]>>[-]>[>[-<<<+<[-]+>>>>]>>]<<,]<-<<<[>[->+<]>[-
<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<[-]<<+<<[-
]+>>>>>[-<+>]]]]]]]]]]]<<<<<]>>>[+++++[->++++++++<]>.>>]
Arbitrary precision. Input is taken newline separated, null terminated.
S.I.L.O.S 38
readIO
a = i
readIO
a + i
printInt a
For documentation see the repo https://github.com/rjhunjhunwala/S.I.L.O.S Fee free to try this code online!
R, 13 bytes
scan()+scan()
Will ask twice for an input, and outputs the result of the sum.
Other possibility (18 bytes), using the sum function :
sum(scan(),scan())
SQF, 19
Using the function-as-a-file format:
params["x","y"];x+y
Call as: [X, Y] call NAME_OF_COMPILED_FUNCTION
dc, 2 bytes
+f
Adds top two items on stack (previously taken from stdin), then dumps the stack's contents to stdout.
EDIT: Upon further consideration, it seems there are several ways this might be implemented, depending on the desired I/O behaviour.
+ # adds top two items and pushes on stack
+n # adds top two and prints it, no newline, popping it from stack
+dn # ditto, except leaves result on stack
??+ # takes two inputs from stdin before adding, leaving sum on stack
I suppose the most complete form for the sum would be this:
??+p # takes two inputs, adds, 'peeks'
# (prints top value with newline and leaves result on stack)
Wait! Two numbers can be taken on the same line, separated by a space! This gives us:
?+p
Hexagony, 9 bytes
?{?+@/!'/
Embiggened:
? { ?
+ @ / !
' / . . .
. . . .
. . .
Interestingly, this is only 2 bytes shorter than (what I think is) the most basic version, which is:
? { ?
. . . .
' + ! @ .
. . . .
. . .
This requires 7 commands, of which one (?, which reads a number from STDIN). Now, as 7 is the 2nd centered hexagonal number, it might be able to fit inside a hexagon of side length 2, if you can use a single flow control character and reuse the ?. I've not been able to figure that out yet though :o(
PowerShell v2+, 17 bytes
$args-join'+'|iex
Takes input as two separate command-line arguments, which get pre-populated into the special array $args. We form a string with the -join operator by concatenating them together with a + in the middle, then pipe that string to Invoke-Expression (similar to eval).
Thanks to @DarthTwon for reminding me that when dealing with such minimal programs, there are multiple methods of taking input all at the same byte-count.
$args[0]+$args[1]
param($a,$b)$a+$b
PowerShell is nothing if not flexible.
MoonScript, 10 characters
(a,b)->a+b
Sample run:
bash-4.3$ .luarocks/moon <(echo 'print ((a,b)->a+b)(5,16)')
21
Mathematica, 4 2 bytes
Tr
Crossed out 4 is still regular 4...
Tr applied to a one-dimensional list takes the sum of said list's elements.
golflua, 12 characters
\f(a,b)~a+b$
Sample run:
> \f(a,b)~a+b$
> w(f(5,16))
21
Gema, 13 characters
* *=@add{*;*}
Sample run:
bash-4.3$ gema '* *=@add{*;*}' <<< '5 16'
21
Maple, 3 bytes
`+`
Usage:
> `+`(1,2)
3
GAP, 2 Bytes
\+
The backslash is GAP's way to turn an infix operator (and some more, there is also \[\] for indexing) to a function.
Here is an example use:
gap> \+(4,3);
7
Haskell, 3 bytes
(+)
The parentheses are here because it needs to be an prefix function. This is the same as taking a section of the + function, but no arguments are applied. It also works on a wide range of types, such as properly implemented Vectors, Matricies, Complex numbers, Floats, Doubles, Rationals, and of course Integers.
Because this is Haskell, here is how to do it on the type-level. This will be done at compile time instead of run time:
-- This *type* represents Zero
data Zero
-- This *type* represents any other number by saying what number it is a successor to.
-- For example: One is (Succ Zero) and Two is (Succ (Succ Zero))
data Succ a
-- a + b = c, if you have a and b, you can find c, and if you have a and c you can find b (This gives subtraction automatically!)
class Add a b c | a b -> c, a c -> b
-- 0 + n = n
instance Add Zero n n
-- If (a + b = c) then ((a + 1) + b = (c + 1))
instance (Add a b c) => Add (Succ a) b (Succ c)
Code adapted from Haskell Wiki
SML, 3 bytes
op+
This is the prefix version of the infix +. If we input it like this in an interpreter (for example Moscow ML), it's type is displayed
- op+;
> val it = fn : int * int -> int
which tells us how to use it: Given a tuple of integers, an integer will be returned.
- op+(17,25);
> val it = 42 : int
Yup, 6 bytes
0*-*-#
Explanation
0*-*-#
0 push 0 to the stack [0]
* place input [0 a]
- subtract [-a]
* place input [-a b]
- subtract [-a-b]
= [b+a]
# output
As a function on -cheat mode, 9 bytes:
0~--0~-=+
Cheddar, 3 bytes
(+)
This is a cool feature of Cheddar called "functionized operators". Credit for this idea goes to @CᴏɴᴏʀO'Bʀɪᴇɴ.
Here are more examples of functionized operators:
(+)(1,2) // 3
(/)(6,2) // 3
(-)(5) // -5
Java, 31 bytes
int A(int b,int B){return b+B;}
Making the above snippet code compilable costs 9 bytes, resulting in a 40-byte program:
class a{int A(int b,int B){return b+B;}}
The "equivalent" monolithic program that can also handle numbers between 231 and 263-1 (inclusive) is 98 bytes long:
interface a{static void main(String[]A){System.out.print(Long.valueOf(A[0])+Long.valueOf(A[1]));}}
Java (lambda expression), 11 bytes
(a,b)->a+b;
This is a java.util.function.BinaryOperator<Integer>. It can also be a java.util.function.BinaryOperator<Long> if you have to add larger numbers.
Batch, 25 18 16 bytes
@cmd/cset/a%1+%2
Edit: saved 7 9 bytes by using my trick from Alternating Sign Sequence.
GO, 29 bytes
func (a,b int)int{return a+b}
Not that much to say
Shakespeare Programming Language (SPL) , 137 135 bytes
Complete program, golfed:
.
A.
B.
Act I
Scene I
[Enter A and B]
A: Listen to your heart!
B: Listen to your heart! You are the sum of me and you. Open your heart!
And a brief explanation:
----
. <- Title, everything before the first
full stop is considered as the tittle and treated as a comment
----
A. <- Dramatis personae. Here are introduced the characters in the play.
|Characters are treated as variables.
B. <--
----
Act I <- Acts and scenes are used to divide a program into smaller
chunks in order to be able to refer to them later.
|
Scene I <--
----
[Enter A and B] <- Characters on stage in the current scene, which are the
variables the program will have access to.
----
A: Listen to your heart! <- Line of code. All of them have the same structure
Variable: code. In this case, the concrete sentence
"Listen to your heart!" reads an input number and stores it
on the character (variable) refered to.
B: Listen to your heart! <- Same as above
You are the sum of me and you. <- Sum the values of itself and the caharacter (variable)
refered to.
Open your heart! <- Output the value of the character (value) refered to.
I am not actualy sure this is the shortest it can go. Check the official page for more info.
Edit 1: Removed the : after Act I and Scene I as it seems that everything after the roman numeral is ignored, thus saving 2 bytes.
Stack Cats, 8 + 4 = 12 bytes
]_:]_!<X
Run with the -mn flags. Try it online!
Golfing in Stack Cats is highly counterintuitive, so this program above was found with a few days of brute forcing. For comparison, a more intuitive, human-written solution using the *(...)> template is two bytes longer
*(>-_:[:)>
with the -ln flags instead (see the bottom of this post for an explanation).
Explanation
Here's a primer on Stack Cats:
- Stack Cats is a reversible esoteric language where the mirror of a snippet undoes the effect of the original snippet. Programs must also be mirror images of itself — necessarily, this means that even-length programs are either no-ops or infinite loops, and all non-trivial terminating programs are of odd length (and are essentially a conjugation of the central operator).
- Since half the program is always implied, one half can be left out with the
-mor-lflag. Here the-mflag is used, so the half program above actually expands to]_:]_!<X>!_[:_[. - As its name suggests, Stack Cats is stack-based, with the stacks being bottomless with zeroes (i.e. operations on an otherwise empty stack return 0). Stack Cats actually uses a tape of stacks, e.g.
<and>move one stack left and one stack right respectively. - Zeroes at the bottom of the stack are swallowed/removed.
- All input is pushed to an initial input stack, with the first input at the top and an extra -1 below the last input. Output is done at the end, using the contents of the current stack (with an optional -1 at the bottom being ignored).
-ndenotes numeric I/O.
And here's a trace of the expanded full program, ]_:]_!<X>!_[:_[:
Initial state (* denotes current stack):
... [] [-1 b a]* [] [] ...
] Move one stack right, taking the top element with you
... [] [-1 b] [a]* [] ...
_ Reversible subtraction, performing [x y] -> [x x-y] (uses an implicit zero here)
... [] [-1 b] [-a]* [] ...
: Swap top two
... [] [-1 b] [-a 0]* [] ...
] Move one stack right, taking the top element with you
... [] [-1 b] [-a] []* ...
_ Reversible subtraction (0-0, so no-op here)
! Bit flip top element, x -> -x-1
... [] [-1 b] [-a] [-1]* ...
< Move one stack left
... [] [-1 b] [-a]* [-1] ...
X Swap the stack to the left and right
... [] [-1] [-a]* [-1 b] ...
> Move one stack right
... [] [-1] [-a] [-1 b]* ...
! Bit flip
... [] [-1] [-a] [-1 -b-1]* ...
_ Reversible subtraction
... [] [-1] [-a] [-1 b]* ...
[ Move one stack left, taking the top element with you
... [] [-1] [-a b]* [-1] ...
: Swap top two
... [] [-1] [b -a]* [-1] ...
_ Reversible subtraction
... [] [-1] [b a+b]* [-1] ...
[ Move one stack left, taking the top element with you
... [] [-1 a+b]* [b] [-1] ...
a+b is then outputted, with the base -1 ignored. Note that the trickiest part about this solution is that the output stack must have a -1 at the bottom, otherwise an output stack of just [-1] would ignore the base -1, and an output stack of [0] would cause the base zero to be swallowed (but an output stack of [2], for example, would output 2 just fine).
Just for fun, here's the full list of related solutions of the same length found (list might not be complete):
]_:]^!<X
]_:]_!<X
]_:]!^<X
]_:!]^<X
[_:[^!>X
[_:[_!>X
[_:[!^>X
[_:![^>X
The *(>-_:[:)> solution is longer, but is more intuitive to write since it uses the *(...)> template. This template expands to <(...)*(...)> when used with the -l flag, which means:
< Move one stack left
(...) Loop - enter if the top is positive and exit when the top is next positive again
Since the stack to the left is initially empty, this is a no-op (top is 0)
* XOR with 1 - top of stack is now 1
(...) Another loop, this time actually run
> Move one stack right
As such, the *(...)> template means that the first loop is skipped but the second is executed. This allows more straightforward programming to take place, since we don't need to worry about the effects of the loop in the other half of the program.
In this case, the inside of the loop is:
> Move one stack right, to the input stack
- Negate top, [-1 b a] -> [-1 b -a]
_ Reversible subtraction, [-1 b -a] -> [-1 b a+b]
: Swap top two, [-1 b a+b] -> [-1 a+b b]
[ Move one stack left, taking top of stack with you (removing the top b)
: Swap top two, putting the 1 on this stack on top again
The final > in the template then moves us back to the input stack, where a+b is outputted.
C, 25 Bytes
p(a,b){printf("%d",a+b);}
Usage
p(a,b){printf("%d",a+b);}
main(c,v)char**v;{p(atoi(*++v),atoi(*++v));}
Or, if you want a full program: (+29 chars)
main(c,v)char**v;{printf("%d",atoi(*++v)+atoi(*++v));}
Take 2 arguments and outputs the results in STDOUT
C++ – 56 bytes
Should work on all unsigned integer types:
template<typename U>U f(U a,U b){return b?f(++a,--b):a;}
This is multiplication in the same style:
template<typename U>U g(U a,U b){return b>1?f(g(a,--b),a):(b?a:0);}
Finally exponentiation:
template<typename U>U h(U a,U b){return b>1?g(h(a,--b),a):(b?a:1);}
To test:
#include <iostream>
template<typename U>U f(U a,U b){return b?f(++a,--b):a;}
template<typename U>U g(U a,U b){return b>1?f(g(a,--b),a):(b?a:0);}
template<typename U>U h(U a,U b){return b>1?g(h(a,--b),a):(b?a:1);}
int main()
{
std::cout << f(3, 4) << std::endl;
std::cout << g(3, 4) << std::endl;
std::cout << h(3, 4) << std::endl;
return 0;
}
Output:
7
12
81
Befunge - 5 Bytes
&&+.@
& - Request int from user and push to stack
+ - Pop top two elements from stack and add and push result
. - Pop value and output as int
@ - End program
Try it here (Although you will have to copy/paste into the text area)
Edit: oops, didn't notice the earlier (identical) befunge answer, I'll leave this here unless I'm told to delete it, not sure of the opinion on that.
hashmap (Yes, the name starts with a lowercase letter.), 3 bytes
hh+
h Take input
h Take input
+ Get the sum
Prelude, 4 bytes
??+!
Requires my modified Prelude interpreter which uses decimal I/O.
Like several other answers, this is just read, read, add, write.
Befunge, 5 bytes
&&+.@
&takes an integer as input and puts it on the stack+pops two numbers from the stack and puts the sum back on the stack.pops a number from the stack and outputs it as an integer@ends the program
GoLScript, 1 byte (non-competiting)
K
Adds the top 2 numbers on the stack. That's it.
Now how to push them on to the stack, I have no clue. I don't think it's possible.. cough @CᴏɴᴏʀO'Bʀɪᴇɴ cough
Fuzzy Octo Guacamole, 1 byte
a
A function that takes inputs from the top of the stack and outputs by pushing to the stack.
Example running in the REPL:
>>> 8 9 :
[8,9]
>>> a :
17
Jolf, 1 byte
u
Take sum of list.
Or, for two bytes, +j, takes two inputs seperated by double newline.
Perl 5.10, 8 bytes
The two numbers to add must be on 2 separate lines for this one to work:
say<>+<>
One with input on the same line (14 + 1 bytes for -a flag)
say$F[0]+$F[1]
One with input on the same line (19 + 1 bytes for -a flag)
map{$s+=$_}@F;say$s
Another one, by changing the array default separator (19 + 1 bytes for -a flag as well)
$"="+";say eval"@F"
Common Lisp, 15 bytes
(+(read)(read))
MATLAB, 4 bytes
1 byte removed thanks to @LeakyNun
@sum
This is an anonymous function that takes an array and gives the sum. Example use:
>> f = @sum
f =
@sum
>> f([3 4])
ans =
7
Minecraft 1.10, 221 characters (non-competing)
See, this is what we have to deal with when we make Minecraft maps.
Aside: There's no way to take a string input in Minecraft, so I'm cheating a bit by making you input the numbers into the program itself. (It's somewhat justifiable because quite a few maps, like Lorgon111's Minecraft Bingo, require you to copy and paste commands into chat in order to input a number.)
Thank you abrightmoore for the Block Labels MCEdit filter.
scoreboard objectives add a dummy
scoreboard players set m a 6
scoreboard players set n a 8
scoreboard players operation r a += m a
scoreboard players operation r a += n a
tellraw @a {"score":{"name":"r","objective":"a"}}
Non-competing due to difficulties in input, and I have no idea how to count bytes in this thing (the blytes system is flawed for command blocks).
Fishing, 22 bytes
v+CCCCCCCC
In{In}aP
Explained
Sets casting direction down and casting length to 1.
Read input to the first 2 cells on the tape and convert to numbers.
Add the first 2 cells together and print.
Retina, 42 bytes
\d+
$*
T`1p`-_` |-1+
+`.\b.
^(-)?.*
$1$.&
Explanation
Adding numbers in unary is the easiest thing in the world, but once you introduce negative numbers, things get fiddly...
\d+
$*
We start by converting the numbers to unary. This is done by matching each number with \d+ and replacing it with $*. This is a Retina-specific substitution feature. The full syntax is count$*character and inserts count copies of character. Both of those can be omitted where count defaults to $& (i.e. the match itself) and character defaults to 1. So for each input n we get n ones, and we still have potential minus signs in there, as well as the space separator. E.g. input 8 -5 gives:
11111111 -11111
Now in order to deal with negative numbers it's easiest to use a separate -1 digit. We'll use - for that purpose.
T`1p`-_` |-1+
This stage does two things. It gets rid of the space, the leading minus signs, and turns the 1s after a minus sign into - themselves. This is done by matching |-1+ (i.e. either a space or a negative number) and performing a transliteration on it. The transliteration goes from 1p to -_, but here, p expands to all printable ASCII characters and _ means delete. So 1s in those matches get turned into -s and minuses and spaces get removed. Our example now looks like this:
11111111-----
+`.\b.
This stage handles the case where there's one positive and one negative number in the input. If so, there will be 1s and -s in the string and we want them to cancel. This is done by matching two characters with a word-boundary between them (since 1s is considered a word character and - isn't), and replacing the match with nothing. The + instructs Retina to do this repeatedly until the string stops changing.
Now we're left with only 1s or only -s.
^(-)?.*
$1$.&
To convert this back to decimal, we match the entire input, but if possible we capture a - into group 1. We write back group 1 (to prepend a - to negative numbers) and then we write back the length of the match with $.& (also a Retina-specific substitution feature).
PHP 4.1, 9 bytes
This assumes a standard php.ini file, with short_open_tag=On and register_globals=On (default in PHP 4.1).
<?=$A+$B;
This assumes that you are acessing the file through a webserver (like Apache).
The keys A and B contain the numbers you want to sum.
An example: http://localhost/sum.php?A=5&B=16. (POST, GET, SESSION and COOKIE can be used too).
PHP, 20 bytes
Surprisingly short this time:
<?=array_sum($argv);
Runs from command line, like:
$ php sum.php 1 2
Silicon, 3 bytes
II+
Simple enough. Takes input and converts it to an integer twice and adds them together. Output is implicit.
Brachylog, 2 bytes
+.
Expects a list with the two numbers as input
Alternatively, if you want the answer to STDOUT:
+w
MATL, 1 byte
s
Accepts an array of two integers as input and sums them. While the simple program of + also works, that has already been shown for other languages.
Bash, 18 bytes
f(){expr $1 + $2;}
JavaScript (ES6), 9 bytes
a=>b=>a+b
Golfscript, 9 2 bytes
~+
~ casts to int[], and + adds.
Minkolang 0.15, 5 bytes
nn+N.
Explanation
nn Take two numbers from input
+ Add
N. Output as number and stop.










