A+B Problem

From Esolang
Jump to navigation Jump to search

A+B problem is a challenge that reads two decimal integers, add, and output.

Usually, the input value is constrained in some way.

For languages that can't do I/O, the "input" is done by manually modifying the program before it is executed so that it stores its two numbers in the memory, the "output" is done by storing the result in the memory.

Implementations

1

111*111*111*11*1*,111*111*11*1*,*1,

Befunge

&&+.@

Brain-Flak

({}{})

brainfuck

The following is a not so decent implementation in brainfuck, by User:None1.

,------------------------------------------------>,,------------------------------------------------[-<+>]<++++++++++++++++++++++++++++++++++++++++++++++++.

Both the input and the result have to be one-digit numbers, and the two numbers in the input are separated by exactly one space (or any other character, but there must be exactly one).

Actually I have a better one that uses algorithms mentioned in brainfuck algorithms.

[-]>[-]+[[-]>[-],[+[-----------[>[-]++++++[<------>-]<--<<[->>++++++++++<<]>>[-<<+>>]<+>]]]<]>>[-]>[-]+[[-]>[-],[+[-----------[>[-]++++++[<------>-]<--<<[->>++++++++++<<]>>[-<<+>>]<+>]]]<]<[-<<<+>>>]<++++++++++<<[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>>[-]>>>++++++++++<[->-[>+>>]>[+[-<+>]>+>>]<<<<<]>[-]>>[>++++++[-<++++++++>]<.<<+>+>[-]]<[<[->-<]++++++[->++++++++<]>.[-]]<<++++++[-<++++++++>]<.

It only works on 8 bit cells, and the numbers in the input and the result should not exceed 255. The two numbers in the input are separated by line feeds.

Also, there is an awesome implementation that supports 32-bit integers, actually, it is compiled from The Headache implementation, and because of its length, it is not shown here, go and compile it yourself.

Brainfuck extended

(@(+%)

BrainZ

The following programs are in hex dump

01 55 55 55 55 55 55 55 55 55 55 55 55 20 20 2A AA AA AA AA AA AA AA AA AA AA AA A1 46 41 1F FF FF FF FF FF F0 20

Both the input and the result have to be one-digit numbers, and the two numbers in the input are separated by exactly one space (or any other character, but there must be exactly one).

Actually I have a better one that uses algorithms mentioned in brainfuck algorithms.

0A 09 0A 0C 21 41 21 41 01 0C 2A AA AA 84 85 07 F0 8A AA 94 11 51 10 A4 FF E2 20 92 14 46 48 23 20 82 08 82 48 50 48 50 61 0A 09 0A 08 08 61 55 55 54 24 28 3F 84 55 54 A0 8A 88 85 27 FF 11 04 90 A2 32 41 19 04 10 44 11 0A 22 32 48 23 FF 88 85 32 84 C9 04 86 14 64 13 24 11 11 11 10 49 0A 09 27 FF 10 A5 09 92 09 0C 28 C8 26 48 22 22 22 09 0A 09 21 3F 85 1F F2 08 81 11 99 0A 08 22 11 0A 51 07 F0 A7 FC 41 20 42 82 08 8F E1 47 FC 82 20 40

It only works on 8 bit cells, and the numbers in the input and the result should not exceed 255. The two numbers in the input are separated by line feeds.

bruh():bruh()

bruh():out(add(in(),in()))

C

#include<stdio.h>
int main(){
    int x,y;
    scanf("%d%d",&x,&y);
    printf("%d",x+y);
    return 0;
}

C++

#include<cstdio>
int main(){
    int x,y;
    scanf("%d%d",&x,&y);
    printf("%d",x+y);
    return 0;
}

enGLish

Declare a variable named a, initially 0
Input x
Declare a variable named b, initially 0
Input y
Declare a variable named sum, initially 0
Store the sum of a and b into sum
Output sum

Factor

1550312130344523405322670672726144276060320428835586125982062278216873380299547785445888965317356993578998458894062824590818181343465544643203278969789760306483260898195025071606514680066312822882289150961729164240257496460164711229028838279617380759313885377180750696493806042467569915139382024410955786156745725726158898119

Both the input and the result have to be one-digit numbers, and the two numbers in the input are separated by exactly one space (or any other character, but there must be exactly one).

Actually I have a better one that uses algorithms mentioned in brainfuck algorithms.

223410076043971245540455586062108671976382093084650814048455942695029728847248299149137635554999424822108920506098868033476214459320120499009107004136078049794893673781761295204469664667935339948220791969940797178711884552892973753625015470549096824911093718441469356768533249165014176626741614824403577081277068387982322629535712447454364104489588780254372499850172986326729405696524997412110326083025627210689998917530563991619062944140202877791117569707740865348999991542007107447224733604600000527878988213435845838869570404281302989627799961769506811874060021300896611729156306973830638599329303622560576731383760330633151857809874340774202118735387543078461597660714598235881914663270305145053382281893795661261671652072174089103101132267118681988227624613185931131543618491818705958774014872388695403663087930058282062807944776002596264627880492322717384703232216135346484920131957918341425918130884150142467794506237984533771367614705105664172251120356711890741861382387138254921794223791411080320254372901167902742308408394759875459949509185990551844055573095741697932045088640395955024237597472362455681672376050549253700368981271604291990235515264750252871044914433037348488635473615344302888662605466698658948109839364491561884085899786063927241502662408998462517291640998101657371778834680047837565519172095276588293322125139653792272461457837353049108094141833488627267796682360797868482152871439304768041176143520773935566597

It only works on 8 bit cells, and the numbers in the input and the result should not exceed 255. The two numbers in the input are separated by line feeds.

Gofe

,&s,As.

Headache (Lang that compiles to brainfuck)

void main(){
    int a;
    int b;
    #a;
    #b;
    @((a+b) as int);
}

It supports 32-bit integers, the compiled brainfuck program is 135420 bytes long so I'm not gonna show it here.

Java

import java.util.Scanner;
class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        System.out.println(a+b);
     }
}

Func++

intoutput(add(intinput(),intinput())

JavaScript

function add(a,b){
    console.log(a+b);
}

I use a function, because it seems that JavaScript has no functions for input.

Powershell

$a=read-host
$b=read-host
$c=[Convert]::ToInt32($a)+[Convert]::ToInt32($b)
write-host $c

Python

print(sum([int(i) for i in input().split()]))

Sokolang

 ###
 #*#
##I####
#@*.O*#
#..####
 #.#
 ###
---

@:13
i:13
o:1,11

---

rudwup2[dlr]dwp2u2rplwplwprlwp2r2lud

Stack-based

VAR x
I x
VAR y
I y
VAR z
A x y z
O z

This esolang is not a push-down automata

,,+.