![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,791
Rep Power: 5
![]() |
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! |
|
|
|
|
|
#2 |
|
Professional Programmer
|
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;} |
|
|
|
|
|
#3 |
|
Expert Programmer
|
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...
|
|
|
|
|
|
#4 |
|
Professional Programmer
Join Date: Sep 2005
Location: serbia & montenegro
Posts: 482
Rep Power: 3
![]() |
I think he means without +,-,* and /
|
|
|
|
|
|
#5 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,791
Rep Power: 5
![]() |
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) |
|
|
|
|
|
#6 |
|
Expert Programmer
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 3
![]() |
|
|
|
|
|
|
#7 | |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,791
Rep Power: 5
![]() |
Quote:
|
|
|
|
|
|
|
#8 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 8
![]() |
Hold on... are we allowed bitwise operators?
|
|
|
|
|
|
#9 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,791
Rep Power: 5
![]() |
What's dat?
o.@ |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|