Moderators: phlip, Moderators General, Prelates
int doAdd(int lhs, int rhs)
{
int result=lhs;
for(int i=0;i<rhs;++i)
{
++result;
}
return result
}
int DoMult(int lhs, int rhs)
{
int result=lhs
for(int i=0;i<rhs;++i)
{
result = DoAdd(result,lhs);
}
return result
}
int doAdd(int lhs,int rhs){
for(;rhs>0;rhs=~-rhs)lhs=-~lhs;
for(;rhs<0;rhs=-~rhs)lhs=~-lhs;
return lhs;
}template<int n, int m, int base>
struct add {
enum {
result = (n+m)%base,
carry = ((n+m)/base)?1:0
};
};
template<int base>
struct add_work {
template<int n>
struct arg_1 {
template<int m>
struct arg_2 {
enum {
upper = add_work<base>::arg_1<n/base>::arg_2<m/base>::result,
carry = add<n%base, m%base, base>::carry,
lower = add<n%base, m%base, base>::result,
result = base*(upper+carry)+lower,
};
}
template<>
struct arg_2<0> {
enum {result = n};
}
}
template<>
struct arg_1<0> {
template<typename m>
struct arg_2 {
enum {result = m};
};
};
};
template<int base, int n, int m>
struct adder {
enum{result=add_work<base>::arg_1<n>::arg_2<m>::result};
};
int doAdd(int lhs, int rhs)
{
int result=lhs;
while(result<(lhs+rhs))
{
++result;
}
return result;
}
int DoMult(int lhs, int rhs)
{
if(rhs > lhs)
{
// exploit commutative property
return DoMult(rhs,lhs);
}
else
{
return lhs*rhs;
}
}
evilbeanfiend wrote:exploiting the commutativity is nice but your function looks like it is going to end up being more efficient then the previous ones. ideally we want addition and multiplication to be worse than O(n) though which seems hard without putting in gratuitously useless steps (bogo sort to get the answer maybe?).
Yakk wrote:evilbeanfiend wrote:exploiting the commutativity is nice but your function looks like it is going to end up being more efficient then the previous ones. ideally we want addition and multiplication to be worse than O(n) though which seems hard without putting in gratuitously useless steps (bogo sort to get the answer maybe?).
O(n lg n): Increment bitwise manually.
O(n e^n): Randomly search integers until you find the one that is 1 greater than your target number.
O(e^e^n): Randomly search integers until you find the one that is 1 greater than your target number. Restart entire calculation if you make any error anywhere.
#define _ rhs--
int DoAdd(int lhs,int rhs){
if(!lhs)return rhs;
if(rhs&(1<<31))return -DoAdd(-lhs,-rhs);
for(;_;)lhs*=-(float)~lhs/lhs;
return lhs;
}
int DoMult(int lhs,int rhs){
int result=0;
for(;_;)result=DoAdd(result,lhs);
return result;
}const int DIM = 600000;
const int FIELD_WIDTH = 6;
char buf[FIELD_WIDTH + 1] = { 0 };
fd = fopen("add.dat");
fseek(fd, FIELD_WIDTH * (DIM * x + y) );
fread(fd, buf, FIELD_WIDTH);
ans = atoi(buf);EvanED wrote:The problem is that this would have to come with an 8 TB database of answers, as it needs to work with numbers up to 500,000-some in both positions.
hotaru wrote:EvanED wrote:The problem is that this would have to come with an 8 TB database of answers, as it needs to work with numbers up to 500,000-some in both positions.
actually, it only needs to work with the test cases listed here.
and only in that order... so actually you could just have it display those answers in that order, one each time "=" is pressed, and it would be correct for that contest. it's only required to display the results on the screen (you don't have to display the numbers as they're entered) and those are the only test cases that will be used, so you can just ignore all the other buttons...
hotaru wrote:actually, it only needs to work with the test cases listed here.
and only in that order... so actually you could just have it display those answers in that order, one each time "=" is pressed, and it would be correct for that contest.
int mult(int a,int b) {
int r=0;
for (int i=0;i<a;i++) {
r += b;
}
return r;
}
int sum(int a,int b) {
int c=mult(1<<a,1<<b);
for (int r=0;c;r++) c>>1;
return r;
}
tendays wrote:(That's the general idea - I tried to put myself in the mind of a wtf-generating person)
(would probably have to generalise the multiplication operator to work on large numbers)
tendays wrote:Something like this would be a start:
- Code: Select all
int mult(int a,int b) {
int r=0;
for (int i=0;i<a;i++) {
r += b;
}
return r;
}
(is it supposed to work with negative numbers, too?)
int add(int a,int b) {
int r=0;
for (int i=0;i<a;i++) {
r ++;
}
for (int i=0;i<b;i++) {
r ++;
}
return r;
}
int doAdd(int lhs, int rhs)
{
bool a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,flase,ture;int x,y,z; for(z=0;x<89430;y++--)a=false;b=true;c=true;d=a;a=c; d=b;b=k;n=o;o= a;flase=true;ture=i; i=l;e=f;l=s;q=r;r=q;s=n;o =o;q=r;d=e; flase= ture;i=q;n=o; j=s;h=j;j=i;if (r==q)z=12; r=s; x += z+1020;j =k;n=q;x=y; ture=g;h=flase;int result=lhs;x=y;z=q;l=m;e=d;h=i;ture =a;a=true;ture=a;b= flase;while(result<(lhs+rhs))++result;flase=true;ture=i; i=l;e=f;l=s;q=r;r=q;s=n;o=o;!r;q=r;x=900494;/*return result;*/q=r;r=q;s=n;o =o;q=r;d=e;d=b;b=k;n=o;o= a;flase=true;ture=i; i=l;e=f;l=s;!n;q=r;r=q;s=n;o =o;q=r;d=e; flase= ture;i=q;n=o; j=s;h=j;j=i;if (r==q)z=12; r=s; x += z+1020;j =k;n=q;x=y; ture=g;h=flase;/*icecreamgoeshere=s*/e=f;l=s;q=r;r=q;s=n;o i=l;e=f;l=s;q=r;r=q;s=n;o =o;q=r;d=e; flase= ture;i=q;n=o; j=s;h=j;j=i;if (r==q)z=12;=o;q=r;d=e; flase= ture; for(double kfol = 3.84590; x< 0289;x--+++++++-);flase=true;ture=i; i=l;e=f;l=s;q=r;r=q;s=n;o =o;q=r;x=900494;return result;q=r;r=q;s=n;o =o;q=r;q=s;r=p;n=o;d=e;d=b;b=k;n=o;o= a;flase=true;ture=i; i=l;e=f;z=0;!q;l=s;q=r;r=q;s=n;o =o;q=r;
return result;
} Hex wrote:I hope to enter when I get an idea clever enough.
plams wrote:One of my ideas that I'm probably not going to use since it's too obvious is to pipe your input through Google Calculator and print the result.
Andrew wrote:If it integer only was acceptable I'd love to store all numbers as arrays of prime factors. That'd give great multiplication and division routines, and I'd be interested to know if addition could be done without conversion back to numbers (which would ideally only be done by the display routine). I suppose you could count "-1" as prime for the sake of negative numbers.
But I don't think you could shoehorn decimals into there, so that'd kill it.
Hamorad wrote:This looks fun
- Code: Select all
int doAdd(int lhs, int rhs)
{
bool a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,flase,ture;int x,y,z; for(z=0;x<89430;y++--)a=false;b=true;c=true;d=a;a=c; d=b;b=k;n=o;o= a;flase=true;ture=i; i=l;e=f;l=s;q=r;r=q;s=n;o =o;q=r;d=e; flase= ture;i=q;n=o; j=s;h=j;j=i;if (r==q)z=12; r=s; x += z+1020;j =k;n=q;x=y; ture=g;h=flase;int result=lhs;x=y;z=q;l=m;e=d;h=i;ture =a;a=true;ture=a;b= flase;while(result<(lhs+rhs))++result;flase=true;ture=i; i=l;e=f;l=s;q=r;r=q;s=n;o=o;!r;q=r;x=900494;/*return result;*/q=r;r=q;s=n;o =o;q=r;d=e;d=b;b=k;n=o;o= a;flase=true;ture=i; i=l;e=f;l=s;!n;q=r;r=q;s=n;o =o;q=r;d=e; flase= ture;i=q;n=o; j=s;h=j;j=i;if (r==q)z=12; r=s; x += z+1020;j =k;n=q;x=y; ture=g;h=flase;/*icecreamgoeshere=s*/e=f;l=s;q=r;r=q;s=n;o i=l;e=f;l=s;q=r;r=q;s=n;o =o;q=r;d=e; flase= ture;i=q;n=o; j=s;h=j;j=i;if (r==q)z=12;=o;q=r;d=e; flase= ture; for(double kfol = 3.84590; x< 0289;x--+++++++-);flase=true;ture=i; i=l;e=f;l=s;q=r;r=q;s=n;o =o;q=r;x=900494;return result;q=r;r=q;s=n;o =o;q=r;q=s;r=p;n=o;d=e;d=b;b=k;n=o;o= a;flase=true;ture=i; i=l;e=f;z=0;!q;l=s;q=r;r=q;s=n;o =o;q=r;
return result;
}
There are some errors in there - I'm aware of that... but it's late, I don't feel like looking for them, and ugh. Pah.
3.14159265... wrote:What about quantization? we DO live in a integer world?
crp wrote:oh, i thought you meant the entire funtion was f(n) = (-1)^n
i's like girls u crazy
Hamorad wrote:This looks fun
- Code: Select all
int doAdd(int lhs, int rhs)
{
bool a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,flase,ture;int x,y,z; for(z=0;x<89430;y++--)a=false;b=true;c=true;d=a;a=c; d=b;b=k;n=o;o= a;flase=true;ture=i; i=l;e=f;l=s;q=r;r=q;s=n;o =o;q=r;d=e; flase= ture;i=q;n=o; j=s;h=j;j=i;if (r==q)z=12; r=s; x += z+1020;j =k;n=q;x=y; ture=g;h=flase;int result=lhs;x=y;z=q;l=m;e=d;h=i;ture =a;a=true;ture=a;b= flase;while(result<(lhs+rhs))++result;flase=true;ture=i; i=l;e=f;l=s;q=r;r=q;s=n;o=o;!r;q=r;x=900494;/*return result;*/q=r;r=q;s=n;o =o;q=r;d=e;d=b;b=k;n=o;o= a;flase=true;ture=i; i=l;e=f;l=s;!n;q=r;r=q;s=n;o =o;q=r;d=e; flase= ture;i=q;n=o; j=s;h=j;j=i;if (r==q)z=12; r=s; x += z+1020;j =k;n=q;x=y; ture=g;h=flase;/*icecreamgoeshere=s*/e=f;l=s;q=r;r=q;s=n;o i=l;e=f;l=s;q=r;r=q;s=n;o =o;q=r;d=e; flase= ture;i=q;n=o; j=s;h=j;j=i;if (r==q)z=12;=o;q=r;d=e; flase= ture; for(double kfol = 3.84590; x< 0289;x--+++++++-);flase=true;ture=i; i=l;e=f;l=s;q=r;r=q;s=n;o =o;q=r;x=900494;return result;q=r;r=q;s=n;o =o;q=r;q=s;r=p;n=o;d=e;d=b;b=k;n=o;o= a;flase=true;ture=i; i=l;e=f;z=0;!q;l=s;q=r;r=q;s=n;o =o;q=r;
return result;
}
There are some errors in there - I'm aware of that... but it's late, I don't feel like looking for them, and ugh. Pah.
3.14159265... wrote:What about quantization? we DO live in a integer world?
crp wrote:oh, i thought you meant the entire funtion was f(n) = (-1)^n
i's like girls u crazy
Since the fine folks over at the IOCCC have already compiled some of the most beautiful Ugly Code ever created, and since looking at Ugly Code is more or less what many of us do each day at work, I’ve decided to exclude Ugly Code as an option altogether. In other words, entries for this contest will need to focus on clean and human-readable code that is, first and foremost, Clever and, if desired, Buggy.
adlaiff6 wrote:My plan so far is to implem^H^H^H^H^H^Hsimulate a Turing Machine with two counters, and use that to make a 4-function calculator.
I expect failure.
3.14159265... wrote:What about quantization? we DO live in a integer world?
crp wrote:oh, i thought you meant the entire funtion was f(n) = (-1)^n
i's like girls u crazy
Users browsing this forum: TheChewanater, wytf9441 and 10 guests