Bitcoin Forum
May 09, 2024, 08:21:11 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: « 1 [2]  All
  Print  
Author Topic: 1 or 0. The Binary Guessing Game.  (Read 2754 times)
deepceleron
Legendary
*
Offline Offline

Activity: 1512
Merit: 1032



View Profile WWW
December 27, 2012, 09:13:57 PM
Last edit: December 27, 2012, 10:48:02 PM by deepceleron
 #21


Wow, really? Some JS:

var gridSize = 1024;
var bits = 512;

var assignedBits = 0;
var grid = [];

while(assignedBits < bits){
newLoc = Math.floor(Math.random() * gridSize);
if(!grid[newLoc]){
grid[newLoc] = 1;
assignedBits++;
}
}

No need for floats or anything.

Wow, really? Some Python (that produces output):

import random;s=1024;b=512;g=[1]*b+[0]*(s-b);random.shuffle(g)
for i in range(0,s,16):print '{0:4d}:{1}'.format(i,g[i:i+16])


I was initially making a number of bits (yes, a single 256-bit number, known in JavaScript as NaN), where the probability of a bit being set was based on a ratio, however "true randomness" could let the OP cheat so I had hacked a check loop on.
1715286071
Hero Member
*
Offline Offline

Posts: 1715286071

View Profile Personal Message (Offline)

Ignore
1715286071
Reply with quote  #2

1715286071
Report to moderator
1715286071
Hero Member
*
Offline Offline

Posts: 1715286071

View Profile Personal Message (Offline)

Ignore
1715286071
Reply with quote  #2

1715286071
Report to moderator
The forum strives to allow free discussion of any ideas. All policies are built around this principle. This doesn't mean you can post garbage, though: posts should actually contain ideas, and these ideas should be argued reasonably.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715286071
Hero Member
*
Offline Offline

Posts: 1715286071

View Profile Personal Message (Offline)

Ignore
1715286071
Reply with quote  #2

1715286071
Report to moderator
1715286071
Hero Member
*
Offline Offline

Posts: 1715286071

View Profile Personal Message (Offline)

Ignore
1715286071
Reply with quote  #2

1715286071
Report to moderator
1715286071
Hero Member
*
Offline Offline

Posts: 1715286071

View Profile Personal Message (Offline)

Ignore
1715286071
Reply with quote  #2

1715286071
Report to moderator
🏰 TradeFortress 🏰
Bitcoin Veteran
VIP
Legendary
*
Offline Offline

Activity: 1316
Merit: 1043

👻


View Profile
January 05, 2013, 05:40:41 AM
 #22


Wow, really? Some JS:

var gridSize = 1024;
var bits = 512;

var assignedBits = 0;
var grid = [];

while(assignedBits < bits){
newLoc = Math.floor(Math.random() * gridSize);
if(!grid[newLoc]){
grid[newLoc] = 1;
assignedBits++;
}
}

No need for floats or anything.

Wow, really? Some Python (that produces output):

import random;s=1024;b=512;g=[1]*b+[0]*(s-b);random.shuffle(g)
for i in range(0,s,16):print '{0:4d}:{1}'.format(i,g[i:i+16])


I was initially making a number of bits (yes, a single 256-bit number, known in JavaScript as NaN), where the probability of a bit being set was based on a ratio, however "true randomness" could let the OP cheat so I had hacked a check loop on.
Yes, but that is not going to work because the OP can just keep generating until he gets one that favors him, and only THEN reveal it.
deepceleron
Legendary
*
Offline Offline

Activity: 1512
Merit: 1032



View Profile WWW
January 05, 2013, 09:04:20 AM
 #23

I was initially making a number of bits (yes, a single 256-bit number, known in JavaScript as NaN), where the probability of a bit being set was based on a ratio, however "true randomness" could let the OP cheat so I had hacked a check loop on.
Yes, but that is not going to work because the OP can just keep generating until he gets one that favors him, and only THEN reveal it.
Please re-read my sentence. One sentence isn't too much to comprehend before posting. Finish reading until the end.

My second posted code only gives fair results. I added checking because I saw within minutes (not two months later) and addressed such a possibility for cheating:
I tweaked the code so only a secret grid with an equal number of 0 and 1 bits will be used (only about 1 in 20 will have an equal number). Otherwise the operator may search for one with bias.

The script also creates a unfalsifiable hash that can be published before gaming begins:
You post the SHA256 now so we can later verify the real secret "grid" was used.

The coding was just an example to show in comparison how preposterous, naive, and unprovable the original poster's game proposal was (bet against his unpublished Excel spreadsheet). Getting either a working Python environment or being able to do something with your JavaScript snippet are both tasks likely out of his depth.
Pages: « 1 [2]  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!