C Board  

Go Back   C Board > Community Boards > Contests Board

Reply
 
LinkBack Thread Tools Display Modes
Old 07-20-2007, 02:03 PM   #16
Anti-Poster
 
Join Date: Feb 2002
Posts: 1,241
If only multiplication and division are allowed, I'm willing to posit that this challenge is unsolvable. You are asking for an expression of the following form to produce addition and subtraction:
Code:
operand [*,/] operand
operand -> a constant, one of the inputs, or operand [*,/] operand 
I won't hold my breath on that one.

I will share my original thoughts. Since a double contains 11 bits of exponent, that part of a double can be used as an accumulator through multiplication. Note that not all states of the 11 bits are valid; I originally planned to only use 10 bits to avoid the NaN and infinity states. After building a 10-bit accumulator, it's a simple step to cascade five of them, add a three bit accumulator for the last three bits that the fraction part of a double can contain, and perform the addition in that context. This required the comparision operators to check to see if the initial state of the exponent was 0 since multiplying 0 by 2 wouldn't produce any usable input. The assignment operator was necessary to assign the first 1 into an empty accumulator.

Of course, with the comparision and assignment operators, you really don't need anything that convolted. A union with a bit field (with each bit as its own field) and a 64-bit integer would provide the space needed to perform the addition.
__________________
Rule #1: Every rule has exceptions
pianorain is offline   Reply With Quote
Old 07-20-2007, 02:58 PM   #17
Registered User
 
Join Date: Sep 2001
Posts: 752
I'm inclined to say it's impossible as well... but for the life of me, I just can't prove it.

On the other hand, if you only use pow() and ln(), you can do this easily.
__________________
Callou collei we'll code the way
Of prime numbers and pings!
QuestionC is offline   Reply With Quote
Old 07-20-2007, 03:27 PM   #18
Senior software engineer
 
brewbuck's Avatar
 
Join Date: Mar 2007
Location: Portland, OR
Posts: 5,768
Quote:
Originally Posted by QuestionC View Post
I'm inclined to say it's impossible as well... but for the life of me, I just can't prove it.

On the other hand, if you only use pow() and ln(), you can do this easily.
I suppose in some very special cases, you could arrive at the right answer by using numerical overflow in a clever way. But not in general.

Take, for instance, the expression 1 - 1. There simply is no sequence of multiplication and division operations on the value 1 that will ever result in zero. (Unless you multiply by zero somewhere, but that's hardly a general method either).
brewbuck is offline   Reply With Quote
Old 07-20-2007, 03:33 PM   #19
aoeuhtns
 
Join Date: Jul 2005
Posts: 581
The proof is pretty simple: Multiplying and dividing nonzero numbers produces a nonzero result. Thus you can't get the sum of 1 and -1 with only multiplication and division, unless you multiply by zero (and then your function adds everything to zero). You need some additional features, like control structures and comparison operators, to make progress towards zero.

Edit: beaten.

Edit 2: Hey, the ICFP contest has begun.
__________________
There are 10 types of people in this world, those who cringed when reading the beginning of this sentence and those who salivated to how superior they are for understanding something as simple as binary.
Rashakil Fol is offline   Reply With Quote
Old 07-29-2007, 11:44 PM   #20
</3 Segfaults
 
Join Date: Jul 2007
Posts: 27
Ints -> Rounding -> Zero.
Differ is offline   Reply With Quote
Old 08-05-2007, 10:15 AM   #21
Senior software engineer
 
brewbuck's Avatar
 
Join Date: Mar 2007
Location: Portland, OR
Posts: 5,768
Quote:
Originally Posted by Differ View Post
Ints -> Rounding -> Zero.
Where's -> Your -> Solution?
brewbuck is offline   Reply With Quote
Old 08-27-2007, 11:54 PM   #22
Registered User
 
Join Date: Aug 2007
Location: Barbados
Posts: 30
No Fear! I am here to save the Day!
*sea_4_ever rides up on a white horse.
I WILL ATTEMPT THIS!
so, am I allowed to use more than one variable?
I will need at least 7;

At least I think this can be solved with something similar to Pythagoras' Theorem.
A^2 + B^2 = C^2
So maybe :
((A^2)/B) * ((B^2)/A) = C
...
*sea_4_ever goes back to his notes

EDIT4:
I am inclined to give up.
EDIT5 :
maybe if I use that fibonacci series.
multiply the first number by the ratio, and then divide the answer by the third number...
erhm, what is the prize?
BUT I NEVER GIVE UP!

Last edited by sea_4_ever; 08-28-2007 at 02:05 PM.
sea_4_ever is offline   Reply With Quote
Old 08-28-2007, 04:33 AM   #23
Woof, woof!
 
zacs7's Avatar
 
Join Date: Mar 2007
Location: Australia
Posts: 3,295
Brute force is no way to win a contest

Just like 2 + 2 = 4, and 2 * 2 = 4, wow I did it! A * B = C, no
__________________
"I.T. gets the chicky-babes" - M. Kelly
bakefile | vim
zacs7 is offline   Reply With Quote
Old 08-28-2007, 06:45 PM   #24
Dr Dipshi++
 
mike_g's Avatar
 
Join Date: Oct 2006
Location: On me hyperplane
Posts: 1,219
Quote:
Originally Posted by sea_4_ever
BUT I NEVER GIVE UP!
Even when the challenge is impossible?

Think of this:
Quote:
Originally Posted by brewbuck
There simply is no sequence of multiplication and division operations on the value 1 that will ever result in zero.
Then give up
mike_g is offline   Reply With Quote
Old 09-13-2007, 10:41 PM   #25
Unregistered User
 
Yarin's Avatar
 
Join Date: Jul 2007
Posts: 982

Code:
void SubtractOne(DWORD *pdwQuery) {
   *pdwQuery *= 0.99999999999999;   }
__________________
May the Source be with you.
Yarin is offline   Reply With Quote
Old 09-19-2007, 12:20 AM   #26
</3 Segfaults
 
Join Date: Jul 2007
Posts: 27
Ah, I just came back and saw the "doubles" part. Many apologies; my solution will only work for integers.
Differ is offline   Reply With Quote
Old 09-19-2007, 12:40 AM   #27
MENTAL DETECTOR
 
whiteflags's Avatar
 
Join Date: Apr 2006
Location: United States
Posts: 3,295
Pardon me, but I don't think the type makes a difference at all. No amount of fudging can make -1 * 1 give the same result as 1 - 1. Of course abachler never said that you had to use the same terms as your input, however addition and subtraction treat the sign of a number fundamentally different than multiplication or division. If it's logically incomprehensible I doubt there is a reliable implementation that works for any combonation of 10,000 numbers. Whatever the range was.

Writing this for the fourth or fifth time now, I hope this thread has used up the last of its lives.
whiteflags is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Faster way to divide numbers scwizzo C++ Programming 3 04-29-2009 11:45 AM
Overflow and range checking for mul/div Elysia C++ Programming 28 06-06-2008 02:09 PM
working with rotation matrices hannibar Game Programming 23 03-30-2005 01:10 PM
How to multiply and Divide Huge int numbers Dewayne C++ Programming 3 10-21-2004 08:41 PM
calculator in c++ gamer C++ Programming 11 02-19-2003 10:46 AM


All times are GMT -6. The time now is 04:03 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22