Bitcoin Forum
May 24, 2024, 05:23:00 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: « 1 [2] 3 4 5 »  All
  Print  
Author Topic: This message was too old and has been purged  (Read 6010 times)
tubbyjr
Full Member
***
Offline Offline

Activity: 182
Merit: 100


View Profile
January 23, 2014, 04:07:37 AM
 #21

He basically wants to be able to put it into a calculator... Try doing 0x0001000 in a calculator and see what you get.
BurtW
Legendary
*
Offline Offline

Activity: 2646
Merit: 1136

All paid signature campaigns should be banned.


View Profile WWW
January 23, 2014, 05:55:26 AM
 #22

Most good calculators will accept hex numbers exactly as shown in my post.  At any rate all the constants can be converted to decimal if needed.  The formula is correct and satisfies the rules.

Did I win?

Our family was terrorized by Homeland Security.  Read all about it here:  http://www.jmwagner.com/ and http://www.burtw.com/  Any donations to help us recover from the $300,000 in legal fees and forced donations to the Federal Asset Forfeiture slush fund are greatly appreciated!
Evil-Knievel (OP)
Legendary
*
Offline Offline

Activity: 1260
Merit: 1168



View Profile
January 23, 2014, 07:45:12 AM
Last edit: April 17, 2016, 09:22:17 PM by Evil-Knievel
 #23

This message was too old and has been purged
Evil-Knievel (OP)
Legendary
*
Offline Offline

Activity: 1260
Merit: 1168



View Profile
January 23, 2014, 07:56:47 AM
Last edit: April 17, 2016, 09:22:04 PM by Evil-Knievel
 #24

This message was too old and has been purged
tubbyjr
Full Member
***
Offline Offline

Activity: 182
Merit: 100


View Profile
January 23, 2014, 09:29:34 AM
 #25

Most good calculators will accept hex numbers exactly as shown in my post.  At any rate all the constants can be converted to decimal if needed.  The formula is correct and satisfies the rules.

Did I win?

Touche, I believe you do win, congrats either way. I just had a quick skim and it looked more like some C++ code at first, but now I see it is indeed purely mathematical.
Evil-Knievel (OP)
Legendary
*
Offline Offline

Activity: 1260
Merit: 1168



View Profile
January 23, 2014, 10:18:32 AM
Last edit: April 17, 2016, 09:21:51 PM by Evil-Knievel
 #26

This message was too old and has been purged
Evil-Knievel (OP)
Legendary
*
Offline Offline

Activity: 1260
Merit: 1168



View Profile
January 23, 2014, 10:19:56 AM
Last edit: April 17, 2016, 09:21:45 PM by Evil-Knievel
 #27

This message was too old and has been purged
deepceleron
Legendary
*
Offline Offline

Activity: 1512
Merit: 1032



View Profile WWW
January 23, 2014, 10:55:22 AM
Last edit: January 23, 2014, 01:35:29 PM by deepceleron
 #28

As far as I can tell this single equation should satisfy the requirements of the puzzle.

Code:
     x = (((a/0x00000001 + b/0x00000001) * 0x80000000) % 0x100000000) / 0x80000000 + 
(((a/0x00000002 + b/0x00000002) * 0x80000000) % 0x100000000) / 0x40000000 +
(((a/0x00000004 + b/0x00000004) * 0x80000000) % 0x100000000) / 0x20000000 +
(((a/0x00000008 + b/0x00000008) * 0x80000000) % 0x100000000) / 0x10000000 +
(((a/0x00000010 + b/0x00000010) * 0x80000000) % 0x100000000) / 0x08000000 +
(((a/0x00000020 + b/0x00000020) * 0x80000000) % 0x100000000) / 0x04000000 +
(((a/0x00000040 + b/0x00000040) * 0x80000000) % 0x100000000) / 0x02000000 +
(((a/0x00000080 + b/0x00000080) * 0x80000000) % 0x100000000) / 0x01000000 +
(((a/0x00000100 + b/0x00000100) * 0x80000000) % 0x100000000) / 0x00800000 +
(((a/0x00000200 + b/0x00000200) * 0x80000000) % 0x100000000) / 0x00400000 +
(((a/0x00000400 + b/0x00000400) * 0x80000000) % 0x100000000) / 0x00200000 +
(((a/0x00000800 + b/0x00000800) * 0x80000000) % 0x100000000) / 0x00100000 +
(((a/0x00001000 + b/0x00001000) * 0x80000000) % 0x100000000) / 0x00080000 +
(((a/0x00002000 + b/0x00002000) * 0x80000000) % 0x100000000) / 0x00040000 +
(((a/0x00004000 + b/0x00004000) * 0x80000000) % 0x100000000) / 0x00020000 +
(((a/0x00008000 + b/0x00008000) * 0x80000000) % 0x100000000) / 0x00010000 +
(((a/0x00010000 + b/0x00010000) * 0x80000000) % 0x100000000) / 0x00008000 +
(((a/0x00020000 + b/0x00020000) * 0x80000000) % 0x100000000) / 0x00004000 +
(((a/0x00040000 + b/0x00040000) * 0x80000000) % 0x100000000) / 0x00002000 +
(((a/0x00080000 + b/0x00080000) * 0x80000000) % 0x100000000) / 0x00001000 +
(((a/0x00100000 + b/0x00100000) * 0x80000000) % 0x100000000) / 0x00000800 +
(((a/0x00200000 + b/0x00200000) * 0x80000000) % 0x100000000) / 0x00000400 +
(((a/0x00400000 + b/0x00400000) * 0x80000000) % 0x100000000) / 0x00000200 +
(((a/0x00800000 + b/0x00800000) * 0x80000000) % 0x100000000) / 0x00000100 +
(((a/0x01000000 + b/0x01000000) * 0x80000000) % 0x100000000) / 0x00000080 +
(((a/0x02000000 + b/0x02000000) * 0x80000000) % 0x100000000) / 0x00000040 +
(((a/0x04000000 + b/0x04000000) * 0x80000000) % 0x100000000) / 0x00000020 +
(((a/0x08000000 + b/0x08000000) * 0x80000000) % 0x100000000) / 0x00000010 +
(((a/0x10000000 + b/0x10000000) * 0x80000000) % 0x100000000) / 0x00000008 +
(((a/0x20000000 + b/0x20000000) * 0x80000000) % 0x100000000) / 0x00000004 +
(((a/0x40000000 + b/0x40000000) * 0x80000000) % 0x100000000) / 0x00000002 +
(((a/0x80000000 + b/0x80000000) * 0x80000000) % 0x100000000) / 0x00000001 ;


I have tried to implement this in Python, and don't get a correct answer using integer or floating point math. ((EDIT: found my problem, and "int only" math works, I messed up the 231 ))
Code:
def int_xor(a, b):
        x = 0
        for n in xrange(32):  # loop values 0-31
            x += (((a / 2 ** n + b / 2 ** n) * 2 ** 31) % 2 ** 32 ) / 2 ** (31 - n)
        return x

>>> int_xor(255,0)
255L
>>> int_xor(128,256)
384L

Code:
def float_xor(a, b):
    x = 0.0
    for n in xrange(32):
        nf = float(n)
        x += (((a / 2.0 ** nf + b / 2.0 ** nf) * 2.0 ** 31.0) % 2.0 ** 32.0) / 2.0 ** (31.0 - nf)
    return x

>>> float_xor(255.0,0.0)
6622.0
>>> float_xor(128.0,256.0)
9344.0
>>>

It would seem out of the gate this still relies on or invokes int decimal truncation, for a = 3, the first op on line 2 is 3/2:
x = (((a/0x00000002 + b/0x00000002) ...
deepceleron
Legendary
*
Offline Offline

Activity: 1512
Merit: 1032



View Profile WWW
January 23, 2014, 11:22:08 AM
 #29

The first challenge in this thought exercise is how do you extract the value of a bit using only formulas, and not int or mod?

I give you two numbers, 0b0101 = 5 or 0b0111 = 7. Tell me if the 2 bit is set. Allowed operators: powers, *, /, + and -.
Evil-Knievel (OP)
Legendary
*
Offline Offline

Activity: 1260
Merit: 1168



View Profile
January 23, 2014, 11:27:24 AM
Last edit: April 17, 2016, 09:21:33 PM by Evil-Knievel
 #30

This message was too old and has been purged
niniyo
Member
**
Offline Offline

Activity: 118
Merit: 10


View Profile
January 23, 2014, 12:49:48 PM
 #31

E-K can you look at my latest submission on the first page of this thread and tell me what's wrong with it?

Thanks.
BurtW
Legendary
*
Offline Offline

Activity: 2646
Merit: 1136

All paid signature campaigns should be banned.


View Profile WWW
January 23, 2014, 01:21:07 PM
 #32

Yes, my solution is pure integer math - not floating point math.

The operation of "choping off everything above 32 bits" is mod 2^32 not mod 2^32-1, mod 2^32-1 makes very little sense as an operation for any purpose so perhaps you really mean that you are doing bitwise AND with 2^32-1 which is the same thing as mod 2^32?

If doing this with floating point then you need to throw away the fractional part of every divide.  

To answer the question why your python does not work you are multiplying by the wrong thing it is always 2^31 you have 2^(31-n)

Our family was terrorized by Homeland Security.  Read all about it here:  http://www.jmwagner.com/ and http://www.burtw.com/  Any donations to help us recover from the $300,000 in legal fees and forced donations to the Federal Asset Forfeiture slush fund are greatly appreciated!
deepceleron
Legendary
*
Offline Offline

Activity: 1512
Merit: 1032



View Profile WWW
January 23, 2014, 01:38:32 PM
 #33

I found the python problem. I didn't have a constant 231 in the middle, and it now seems to work when only using the integer function and of course passing integers. (stupid edits, I found my goof independently...)

I would think a mathematics computing and simulation platform would have no concept of int data types presented to the user though, you would have to call an int() function.
BurtW
Legendary
*
Offline Offline

Activity: 2646
Merit: 1136

All paid signature campaigns should be banned.


View Profile WWW
January 23, 2014, 01:46:12 PM
 #34

If there is a python operator to throw away the fraction after each divide can you modify your python to apply that on the two divides in your sript so we can make sure it works?

Our family was terrorized by Homeland Security.  Read all about it here:  http://www.jmwagner.com/ and http://www.burtw.com/  Any donations to help us recover from the $300,000 in legal fees and forced donations to the Federal Asset Forfeiture slush fund are greatly appreciated!
Evil-Knievel (OP)
Legendary
*
Offline Offline

Activity: 1260
Merit: 1168



View Profile
January 23, 2014, 01:50:14 PM
Last edit: April 17, 2016, 09:21:20 PM by Evil-Knievel
 #35

This message was too old and has been purged
deepceleron
Legendary
*
Offline Offline

Activity: 1512
Merit: 1032



View Profile WWW
January 23, 2014, 01:51:49 PM
 #36

I can put the int functions in the right place for float.

I think the OP has made a non-solvable challenge. The solution of shifting left and shifting right to truncate to one bit at a time is as elegant as it is going to get.

If mod is the only function that can be used, but unlimited variables can be used, you could discover the bits with maths.
deepceleron
Legendary
*
Offline Offline

Activity: 1512
Merit: 1032



View Profile WWW
January 23, 2014, 02:01:41 PM
Last edit: January 23, 2014, 02:14:02 PM by deepceleron
 #37

Just a pointer ... it might be sufficient to find a representation of the AND operator ;-)

I have not yet proven it, but I think that A XOR B = A+B-2(A AND B)

For individual bits using and, multiplication, and inversion:


(I'll keep adding)
The truth table for xor is:
ABX
000
011
101
110

Your truth table:
ABX
000+0-2(0)=0
010+1-2(1)=1
101+0-2(1)=1
111+1-2(1)=0
although if you can use a logic operation, why can't we just use the correct one?
Evil-Knievel (OP)
Legendary
*
Offline Offline

Activity: 1260
Merit: 1168



View Profile
January 23, 2014, 02:02:51 PM
Last edit: April 17, 2016, 09:21:13 PM by Evil-Knievel
 #38

This message was too old and has been purged
Evil-Knievel (OP)
Legendary
*
Offline Offline

Activity: 1260
Merit: 1168



View Profile
January 23, 2014, 02:34:16 PM
Last edit: April 17, 2016, 09:21:07 PM by Evil-Knievel
 #39

This message was too old and has been purged
deepceleron
Legendary
*
Offline Offline

Activity: 1512
Merit: 1032



View Profile WWW
January 23, 2014, 03:09:15 PM
Last edit: January 23, 2014, 04:21:38 PM by deepceleron
 #40

I think I can solve this using the initial terms, but it will have to be later today.
"Allowed operators: powers, *, /, + and -. Also modulo (2^32-1) is allowed."

The mod rule is not a hindrance if we were given infinite precision, as x % 2^32 can be obtained by x *((2^32-1)/(2^32)) % (2^32-1), but I assume this would not be allowed due to some computing platforms with limited float precision (it works in python to 53 sig figs):

def mod32(r):
   r = float(r)    
   return ((r/2.0**32.0 * (2.0**32.0-1.0)) % (2.0**32.0-1.0)) * 2.0**32.0 / (2.0**32.0-1.0)

>>> print mod32(1), 1 % 0x100000000
1.0 1
>>> print mod32(0xffffffff), 0xffffffff % 0x100000000
4294967295.0 4294967295
>>> print mod32(0x100000000), 0x100000000 % 0x100000000
0.0 0



If not, it will have to be via math->logic, as in all bits are set : (x-(x%(2^32-1)))/(2^32-1)

Pages: « 1 [2] 3 4 5 »  All
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!