So you're a programmer, huh?

>So you're a programmer, huh?
>How about you add two numbers without using addition, bitch.

Other urls found in this thread:

en.wikipedia.org/wiki/Kogge–Stone_adder
twitter.com/SFWRedditImages

So, bit shifting?

1 and 1

1 - (-1) isnt technically addition

How about you take off that fake mustache?

>How about you add two numbers without using addition, bitch.
n -(-n)

>How about you add two numbers without using addition, bitch.

With side effects, just to piss the anti-c fags off a little more.
#include

int add(int x)
{
static int b = 0, s = 0;
int a = 0, t;
if (!s) {
a = b; b = x;
} else {
a = x; t = b;
do {
a ^= b;
b = (a^b) & b;
b

nice

how did you do it this fast

>-(-
Looks like a + to me

I was asked this in an interview half a year ago or something, so I implemented it after the interview and had it lying around.

Cleaned up version, it's not really hard:

int add(int a, int b)
{
do {
a ^= b;
b = (a^b) & b;
b

Nice.

But how many of you can average two ints in C?

>Mi'dama

#define NOTADDITION +

a NOTADDITION b;

>All these plebs using hardware accelerated addition

Did you know there are some really old CPUs that don't even have hardware division and multiplication?

Who cares, this isn't 1963 anymore fgt.

Well, I understand the while loop, just not what's inside!

Actually, I just don't get why the bit operators somehow combine to make addition here.

int avg = a - b/2;

>the average of 2 and 7 is -1

This doesn't work on OpenBSD/sparc64???

Big endian != little endian

add a and b:

-((-a) - b)

int add(int a, int b) {
printf("quick, i need your help! whats %d + %d?", a, b);

int result;
scanf("%d", &result);

puts("thx m8! =)");

return result;
}

I like this one.

local num = 0
num = 2

Why do you hate fun? And this was something that still happened in the 80's.

>fun
Only if you are some sort of nostalgic dinosaur I guess

>1980
That's about 15 years before I was even born

GOT EM

2

3+3 without addition

flip symbols

- 3 - 3 = -6

flip result

6

Flip off

what cpu is that? lol

...

is that the 6502?

Greek ripoff

>int only

Thanks, we'll call you back.

if(a

...

for ( 0...b){
a++
}

Easy as fuck:
Definition add : nat -> nat -> nat :=
let fix loop accu n {struct n} :=
match n with
| O => accu
| S na => loop (S accu) na
end in
fun a b => loop a b.

Eval compute in add 400 12.

def add(a, b):
return a - (b * -1)

a-(-b)

int fround (float x) {
return (int) x + (x < 0.0 ? -0.5 : 0.5);
}

int add (int a, int b) {
return fround (log (exp (a) * exp (b)));
}

uh, subtraction is really adding an inverse

CL-USER> (defun addition (a b) (- (- (- a) b)))
ADDITION
CL-USER> (addition 5 5)
10

Also can't be equal.

mov eax, 5
mov ebx, 7

; 5 + 7

neg ebx
sub eax, ebx

; or

lea eax, [eax+ebx]

I don't know Coq, but isn't that just adding 1 to accu and subtracting 1 from b each loop? I didn't think that was allowed, but Coq seems pretty cool.

or
; 5 + 7

mov eax, 5
mov ebx, 7
.l:
mov ecx, eax
and ecx, ebx
xor eax, ebx
mov ebx, ecx
shl ebx, 1
jnz .l

bitch

You can do anything in Coq except writing bottom.

translated to C for plebs that don't understand asm
int add(int a, int b) {
int c;
while (b) {
c = a & b;
a ^= b;
b = c

Write a version that doesn't depend on endianness then.

Floating point is trash.

It technically isn't adding either.

Another homework thread? How do you expect to learn anything?

kek

take two 1-bit integers, then think about how you'd get their sum and carry to the 2nd-bit position from them, using only bit ops.

Then figure out how you handle the same idea, but with an extra carry input.

the sum goes into the 1-bit position, and the carry feeds into the next loop iteration

carry = 0 (initial carry is 0)
out0, carry = carry + a0 + b0
out1, carry = carry + a1 + b1
out2, carry = carry + a2 + b2
...

you get the idea

it shouldn't depend on endianness because the data is all in registers

Does this count?
function add(a, b)
if a > 0 then
return string.format("s(%s)", add(a - 1, b))
elseif b > 0 then
return string.format("s(%s)", add(a, b - 1))
else
return "0"
end
end

print(add(tonumber(arg[1]) or 0, tonumber(arg[2]) or 0))

def halfadd(x,y):
return (x ^ y , (x & y) 0:
(x,y) = halfadd(x,y)
return x

add b = las t. take b . iterate succ

function add(a, b)
int total = 0;
while (--a)
--total
while(--b)
--total
return -total

>writing bottom
explain

c = 0
while ((c - a - b) != 0):
c = random.random()*2**64 + random.random()

a + b := (a^2 - b^2)/(a - b)

Not him, but thanks for the explanation.

Using bitshift and leading zeroes function:
add(x,y) := Lz((1

Addition is closed under the positive integers (and indeed any other positive set), subtraction is not. Different properties, therefore different functions.

I won't do anything, faggot, you're just a spic.

var s = new Stopwatch();
s.Start();
Thread.Sleep(a);
Thread.Sleep(b);
Console.WriteLine(s.ElapsedMilliseconds);

Who mentioned positive integers? Why wouldn't all integers, real number, or even complex numbers be allowed?

int addition (int a, int b)
{
int c;

while (a-c != b)
c = rand();

return c;
}

Overflowing addition of 1-bit integers:
x & y
wrapping version:
x ^ y

1 and 1 is 11

eat it faglord

I used an example to demonstrate that addition and subtraction are not the same function.

Sure, they're not the same function, but what the other user said was correct. It's just adding an inverse.
If you consider that we're working with modular arithmetic, subtraction is still closed for the positive integers.

You're hired!

a-(!b)-1

Write a version that doesn't depend on the existence of registers then.

sum(5,4)

here is a faster algorithm O(log_n) for bigger lengths

en.wikipedia.org/wiki/Kogge–Stone_adder

>95
gtfo underageban

while (b--)
a++;

well allright 2 + 2 without addition is 2.....

+ FUCK FU CK GOD DAM CUNT YOU FUCKING FAGGOT I COULD HAVE DONE IT MY FINGER SLIPPED YOUF CUKING CUK CUKC UCKC OSIDJFOSIJFO*J$FO*JO*U(*!U(*U&(&(&&R

in a post about addition
what a shit joke

I'm a mathematician so I don't need a computer to add numbers

Maybe if you stopped flipping burgers, you'll learn how to flip bits.

>without using addition
>uses addition and subtraction

Idiot.

public static int add(int a, int b) {
if(a==0)
return b;
else if(b ==0)
return a;
else
throw new exception();

(defun add (a b)
(when (= b 0) (return-from add a))
(add (logxor a b) (ash (logand a b) 1)))

Definition := fix
Why not just Fixpoint add :=...?
You don't have to nest the fix inside a definition

Go away Microsoft

int avg = floor(((float) a)/2 + ((float) b)/2);

...

Python:

a.__add__(b)

Easy

nice c# stuff

ADDC a, b

>How about you add two numbers without using addition
Another one who has never heard of look up tables

sum = table [a, b]