# Adding without using a + or - sign

There have been many "Do __ without __" challenges before, but I hope that this is one of the most challenging.

## The Challenge

You are to write a program that takes two natural numbers (whole numbers > 0) from STDIN, and prints the sum of the two numbers to STDOUT. The challenge is that you must use as few + and - signs as possible. You are not allowed to use any sum-like or negation functions.

Examples

input

123
468


output

591


input

702
720


output

1422


Tie Breaker: If two programs have the same number of + and - characters, the winner is the person with fewer / * ( ) = . , and 0-9 characters.

Not Allowed: Languages in which the standard addition/subtraction and increment/decrement operators are symbols other than + or - are not allowed. This means that Whitespace the language is not allowed.

• Perhaps this challenge was a lot easier than I thought it would be, especially in other languages, where there are sum() functions. I have to fix this. – PhiNotPi Dec 1 '11 at 0:45
• 100 rep bounty for anybody who can do this in Brainfuck. – Peter Olson Dec 1 '11 at 5:57
• @Peter Olson Well, I guess BF is not turing complete without either + or -... – FUZxxl Dec 1 '11 at 10:21
• Just to clarify, this challenge does not care about code length right? Only the number of +,- and tie breaker characters? ...or do you need to change the rules again :-) – Tommy Dec 1 '11 at 19:39
• @Tommy No, it does not. – PhiNotPi Dec 1 '11 at 21:58

# PHP, 22 chars

echo array_sum($argv);  Documentation: array_sum() and $argv
Usage: php -r 'echo array_sum($argv);' 5 6 will output 11. • +/- and above mentioned tiebreakers are interesting, not chars. – user unknown May 30 '12 at 3:35 ## APL (10, 3 tie-breakers) ⎕←⍴(⍳⎕),⍳⎕  • 10x +/-? Chars arn't interesting, just +/- and the tie-breakers. – user unknown May 30 '12 at 3:34 ## Common Lisp Always surprising for such a verbose language. ((lambda(n m)(princ(length(append(make-list n)(make-list m)))))(read)(read))  # Python 3 - 159 characters | ().,*/= count: 39 A little long, but I felt like doing it HDL-style. a,b,c,d=int(input()),int(input()),0,0;l=max(a,b,key=int.bit_length) for i in range(len(bin(l<<1)[2:])): e=a>>i&1;f=b>>i&1;c|=(e^f^d)<<i;d=e&f|d&(e^f) print(c)  • +/- tiebreakers are interesting, not characters. – user unknown May 30 '12 at 3:33 • @userunknown: What's wrong with characters? – JAB May 30 '12 at 16:55 • Characters are counted in CodeGolf tagged questions. If a reader doesn't read the question again, he will get the impression that character count is important and probably make a misguided vote based on that assumption. So the rules say: No (+|-). In Tiebreak digits, ().,*/= are important. You should include that number in your answer, so that not every visitor has to count them himself. – user unknown May 30 '12 at 20:41 • @userunknown: Oh, right. – JAB May 30 '12 at 20:46 ## C# 141 characters 27 tiebreakers +/- : 0 = : 0 . : 9 () : 18 Console.WriteLine(Enumerable.Range(1,int.Parse(Console.ReadLine())) .Concat(Enumerable.Range(1,int.Parse(Console.ReadLine()))) .Count());  ## Python 42 a,b=input() print eval("~-"*a+"~-"*b+"0")  Seven tie breakers, but those are string operations C#, 12 tiebreakers (), 3 tiebreakers . using System; using System.Data; class Program { static string ReadLine { get { return Console.ReadLine(); } } static void Main(string[] args) { Console.Out.Write( new DataTable().Compute(string.Join("\u002b", ReadLine, ReadLine), "") ); } }  # JavaScript 69 My attempt, using bitwise operators for(x=(z=prompt().split(" "))[0],y=z[1];y;)x^=y,y=(y&x^y)<<1;alert(x) # R, 44 bytes nchar(paste(strrep(" ",scan()),collapse=""))  Try it online! Converts the two inputs to unary and "sums" via concatenation. Check out the other R answers: # C, score 0 with 8 tie-breakers f(a,b) { return b ? f(a^b, a<<1 & b<<1) : a; } ^ ^ ^ ^ ^ ^ ^^  I've highlighted the tie-break chars. Negative numbers are assumed to be 2s-complement. # Javascript (ES6) - 8 Tie-breaker characters add: { let a = prompt|false; let b = prompt|false; while (a & b) { a = a ^ b; b = [b & ~a][false|false] << true } alert(a | b); }  • 2 * ( • 2 * ) • 4 * = # Runic Enchantments, (no +/-, 1 tie-breaker, 11 bytes) 'V2,k!$wi|;


Try it online!

Not allowed to have + characters? Fine, I'll create them myself with math and reflection. V has the byte value 86, which gets divided by 2 (the , and only tie-breaker character) converted to a character, and finally, reflectively written into the program under the instruction pointer. It then reads input, hits a reflector (|), reads input again, then reaches the space originally containing a w and adds them together before printing. The IP then performs an illegal action at , and is silently terminated.

Is this cheating? Probably. But the challenge says "don't use + characters" and the source code contains 0 of them.

# Alternate method, (no +/-, 3 tie-breakers, 16 bytes)

"ab"1,i*}i*qul\$;


Try it online!

Makes two strings, one of length x and one of length y, concatenates them together, then computes the length of the string. Does this count as a "sum-like function"? Perhaps. + on two strings does do the same thing.

# APL (Dyalog Unicode), 4 bytesSBCS, 0 +/-, 0 tie breakers

Can sum any number of non-negative integers.

≢⎕⌿#


Try it online!

# reference to the root object

⎕/ replicate by the number(s) from STDIN
for each number, we get that many copies of the corresponding element on the right, but since there is only one, all numbers get paired up with that one, forming a single list of N1+N2+…+Nn references

≢ tally

Output is implicitly to STDOUT.

# Gol><>, 12 bytes

IITM:{P}?trh


Thanks to JoKing for reminding me there was a Teleport Pad!!

1st version, 25 bytes

II!/M:{P}?\rh
\     :/


Try it online!

This was alot easier than I thought it would be!!! I will be golfing this alot more!!!

• 12 bytes using teleports, 10 bytes using put. Or 13 bytes without tie breaker characters – Jo King Feb 10 at 3:02
• @JoKing Wow. Those use strategies I wasn't even thinking of!!!, nice! – KrystosTheOverlord Feb 10 at 3:44