40
7
Problem:
Your goal is to add two input numbers without using any of the following math operators: +,-,*,/
.
Additionally, you can't use any built-in functions that are designed to replace those math operators.
Scoring:
Smallest code (in number of bytes) wins.
Update
Most of the programs i've seen either concatenate two arrays containing their numbers, or make
first number
of a character, appendsecond number
characters, then count them all.Shortest array counter: APL with 8 chars, by Tobia
Shortest array concatenation: Golfscript with 4 chars, by Doorknob
Shortest logarithmic solution: TI-89 Basic with 19 chars, by Quincunx
Integration solution: Mathematica with 45 chars, by Michael Stern
Coolest, in my opinion: bitwise operators in javascript, by dave
Do Brainf**k's
+
and-
count? – ASCIIThenANSI – 2015-05-19T14:09:21.5002Define "number". Any integer? Non-negative integers? Do they have to be base-10? – SuperJedi224 – 2017-01-20T13:44:00.567
Will it have floats? – Ismael Miguel – 2014-02-16T01:06:19.980
@IsmaelMiguel - Nope. No floats. – TheDoctor – 2014-02-16T03:09:58.457
7Will it have negative numbers? (Currently, all the answers assume that the numbers will be positive, so you probably shouldn't change that) – Doorknob – 2014-02-16T03:48:21.190
@Doorknob the "make two lists, concatenate them, return the length of the resulting list" approach, which many are using, requires positive integers, but other solutions are possible that allow non-integer inputs, negative numbers, or both. – Michael Stern – 2014-02-16T03:55:36.380
I'd like to suggest that the title be changed to
Add without addition, multiplication, subtraction, or division!
or something similar (maybeAdd without +*-/
) to reflect that we cannot use those operators as well. – Justin – 2014-02-16T08:27:19.557a=lambda x,y:'%s%s'%(x,y)
– nyuszika7h – 2014-02-16T10:30:01.780Related: Adding without using a + or - sign
– Ilmari Karonen – 2014-02-16T15:28:12.6174
What about the mathematical solutions? You forgot to list those! This integrates, and this plays with logarithms
– Justin – 2014-02-17T00:54:41.0533
Why did you accept one of the longer solutions? Is it because it accepts negative numbers while the shortest solutions (this and this) don't? If so, my answer supports negative numbers (it also supports floating point) and is shorter than this one. You tagged this question as [tag:code-golf], thus you are obliged to accept the shortest solution.
– Justin – 2014-02-20T21:01:55.193I chose that solution because it dealt with negative numbers and it didn't use array concatenation, like the 4 char Golfscript – TheDoctor – 2014-02-20T21:26:08.223
Do FMAs count as replacements for + and *? – me' – 2019-09-20T11:23:21.423