Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 12th, 2005, 3:26 PM   #1
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,791
Rep Power: 5 Sane will become famous soon enough
Little Challenge For A Bored Programmer

Creating a function that returns the sum of two integers, without any usage of mathematical operators!!

It's a neat challenge, and was a good learning experience for me. After I'm done fixing some minor glitches, I'll post my method in Python.

Try it!
Sane is offline   Reply With Quote
Old Oct 12th, 2005, 3:50 PM   #2
iignotus
Professional Programmer
 
iignotus's Avatar
 
Join Date: Apr 2005
Location: Nowhere Special
Posts: 466
Rep Power: 4 iignotus is on a distinguished road
Send a message via AIM to iignotus
What do you consider a mathematical operator.......
__________________
% rc4 hexkey < input > output
#define S ,t=s[i],s[i]=s[j],s[j]=t /* rc4 hexkey <file */
unsigned char k[256],s[256],i,j,t;main(c,v,e)char**v;{++v;while(++i)s[ 
i]=i;for(c=0;*(*v)++;k[c++]=e)sscanf((*v)++-1,"%2x",&e);while(j+=s[i]
+k[i%c]S,++i);for(j=0;c=~getchar();putchar(~c^s[t+=s[i]]))j+=s[++i]S;}
iignotus is offline   Reply With Quote
Old Oct 12th, 2005, 3:51 PM   #3
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
Hold on, even if you write a program that does nothing, wouldn't the eventual machine code, or even the microcode behind the instruction set technically use mathematical operators...
Rory is offline   Reply With Quote
Old Oct 12th, 2005, 3:51 PM   #4
ivan
Professional Programmer
 
ivan's Avatar
 
Join Date: Sep 2005
Location: serbia & montenegro
Posts: 482
Rep Power: 3 ivan is on a distinguished road
I think he means without +,-,* and /
ivan is offline   Reply With Quote
Old Oct 12th, 2005, 3:53 PM   #5
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,791
Rep Power: 5 Sane will become famous soon enough
Yes. But only within the code. I don't mean if the computer is actually doing math. As long as you aren't cheating by making the code do it directly as however the language states:

Pyton
exec "print %s%s%s"%(a,chr(43),b)
lol...
Sane is offline   Reply With Quote
Old Oct 12th, 2005, 4:11 PM   #6
Polyphemus_
Expert Programmer
 
Polyphemus_'s Avatar
 
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 3 Polyphemus_ is on a distinguished road
1 + 2 = 3:

int answer = 1 | 2;
Polyphemus_ is offline   Reply With Quote
Old Oct 12th, 2005, 4:16 PM   #7
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,791
Rep Power: 5 Sane will become famous soon enough
Quote:
Originally Posted by Sane
As long as you aren't cheating by making the code do it directly as however the language states
Meow ...
Sane is offline   Reply With Quote
Old Oct 12th, 2005, 4:28 PM   #8
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 8 Ooble is on a distinguished road
Hold on... are we allowed bitwise operators?
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Oct 12th, 2005, 4:31 PM   #9
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,791
Rep Power: 5 Sane will become famous soon enough
What's dat?

o.@
Sane is offline   Reply With Quote
Old Oct 12th, 2005, 4:32 PM   #10
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 8 Ooble is on a distinguished road
Operators that AND, OR, XOR and NOT bits.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:57 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC