can you solve this, without using "+"? :)
can you solve this, without using "+"? :)
Re: can you solve this, without using "+"? :)
-(-a-b)
Re: can you solve this, without using "+"? :)
Posted by
Nurbek 21 Dec 2006 23:30
-(-a-b)
BRAVO !!! :)
Edited by author 21.12.2006 23:31
Re: can you solve this, without using "+"? :)
a--b
a------------------------b :)))
I can do it without using + and - :-)
#include <stdio.h>
#include <math.h>
void main()
{
double a, b;
scanf("%lf%lf", &a, &b);
double c = log(exp(a)*exp(b));
printf("%.0lf", c);
}
Of course!!!
var
a, b: integer;
begin
read(a, b);
asm
mov ax, a;
add ax, b;
mov a, ax;
end;
writeln(a);
end.
Or using bitwise operations only :)
Posted by
it4.kp 8 Jan 2007 22:13
#include <iostream>
using namespace std;
int sum(int a, int b){
return (!a||!b ? a|b : sum((a&b)<<1,a^b));
}
int main(){
int a, b;
cin >> a >> b;
cout << sum(a,b);
return 0;
}
Re: Or using bitwise operations only :)
You stole my Idea :) I just think about it, but you write it faster then me :).
Edited by author 08.01.2007 22:17
Re: Or using bitwise operations only :)
Posted by
it4.kp 8 Jan 2007 22:26
Ok, let's make problem more interesting...
What is the shortest program to add A and B?
Rules:
1. Whitespace chars are ignored.
2. You cannot use +, -, * and / operations.
3. Assembler is "off the table".
4. Java's BigInteger too
5. any non-integer functions (like log() and exp()) are forbidden
My very raw variant's length is 129:
#include <iostream>
int s(int a, int b){
return (!a||!b ? a|b : s((a&b)<<1,a^b));
}
int main(){
int a, b;
std::cin >> a >> b;
std::cout << s(a,b);
return 0;
}
Edited by author 08.01.2007 22:40
119 )
#include<iostream.h>
#define _(x,y) for(i=1;x&i;y^=i,i<<=1);y^=i;
main(){
int x,y,i;
for(cin>>x>>y;y;){_(x,x)_(~y,y)}
cout<<x;
}
108 )
Posted by
it4.kp 8 Jan 2007 23:48
#include <iostream.h>
int s(int a, int b){
return !a||!b ? a|b : s((a&b)<<1,a^b);
}
main(){
int a, b;
cin >> a >> b;
cout << s(a,b);
}
Edited by author 09.01.2007 00:14
106 )
#include<iostream.h>
main(){
int x,y,i;
for(cin>>x>>y,x=~x;x^~0;x^=y^=x^=y)
for(y^=i=1;y&i;y^=i<<=1);
cout<<~y;
}
Edited by author 09.01.2007 01:03
Re: Or using bitwise operations only :)
But with ASM it'll run more quickly!!!
Re: can you solve this, without using "+"? :)
I've solved it on pascal some time ago, but not post
It's not short of course :)
var
i,a,b,s,c:integer;
begin
read(a,b);
for i:=0 to 31 do
begin
s:=s or (a and 1 xor b and 1 xor c) shl i;
c:=(c and (a and 1 xor b and 1)) or (a and 1 and b and 1);
a:=a shr 1;
b:=b shr 1
end;
write(s)
end.
Re: Or using bitwise operations only :)
But with ASM it'll run more quickly!!!
Compiler generates better assembler code
for a:=a+b than your one
Re: Or using bitwise operations only :)
And what is it??? Try to use 10^10 my code and c:=a+b;!!!
No subject
Edited by author 10.01.2007 02:09
Or using ':=' operator only :)
Without :
Ok, let's make problem more interesting...
What is the shortest program to add A and B?
Rules:
1. Whitespace chars are ignored.
2. You cannot use +, -, * and / operations.
3. Assembler is "off the table".
4. Java's BigInteger too
5. any non-integer functions (like log() and exp()) are forbidden
and without bitwise operation:) :
63 symbols:
var a,b,i:integer;
begin
read(a,b);
for i:=1 to a do inc(b);
write(b)
end.
Re: Or using ':=' operator only :)
Tests are simple. You solution pass TL easily, but
for i:=1 to a do inc(b); equal to inc(b,a);
Re: Or using ':=' operator only :)
inc() is using + itself so its forbidden