20120208, 23:25  #13  
"Forget I exist"
Jul 2009
Dumbassville
8369_{10} Posts 
Quote:
Quote:


20120209, 04:47  #14 
Jun 2003
2^{3}×19×31 Posts 

20120209, 05:34  #15 
"Serge"
Mar 2008
Phi(4,2^7658614+1)/2
9124_{10} Posts 
axn's method is the strippedtothebone implementation of fivemack's metamethod (a bitmask is the smallest hash array, etc etc).

20120211, 15:38  #16  
Jul 2004
Mid Calder, Scotland
5·37 Posts 
Quote:
Bitshifting left is raises by a power of 2? So 1<<1: would be 00000001 = 1 So 1<<2: becoming 00000010 = 2 So 1<<3: becoming 00000100 = 4 So 1<<4: becoming 00001000 = 8 So 3<<1: would be 00000011 = 3 So 3<<2: becoming 00000110 = 6 So 3<<3: becoming 00001100 = 12 So 3<<4: becoming 00011000 = 24 Now looking at the formula am I correct in understanding that within the for loop (x = (1 << v[i]);) you are bitshifting 1 by the numerical value of each card in the array? and if there is an ace present (v[i] == 1) a further (repeat?) bitshift is done to the value of 14 so if the array is [1,2,3,4,5,6,7] then we get 00000001 00000010 00000100 00001000 00010000 00100000 01000000 and since there is an ace present 10000000000000 ? Now the tutorial I read on binary was dealing with 8 bit strings but modern computers use 32? So would it be more correct to say the above is actually 00000000 00000000 00000000 00000001 00000000 00000000 00000000 00000010 00000000 00000000 00000000 00000100 00000000 00000000 00000000 00001000 00000000 00000000 00000000 00010000 00000000 00000000 00000000 00100000 00000000 00000000 00000000 01000000 00000000 00000000 00100000 00000000 So the result of the for loop is series of binary strings which will then be looked at by this: x &= (x << 1) & (x << 2) & (x << 3) & (x << 4); return (x > 0); and will give us a TRUE/FALSE result if there is a numerical sequence present? Hopefully I am correct so far ( I haven't quite figured out the last bit x &= (x << 1) & (x << 2) & (x << 3) & (x << 4); Yet but given a little more study I am hoping I will get it! EDIT: Looking at this a little more, I was wondering if I have made an error in my assumption that there are multiple binary strings? I did think that the for loop result would be: 00000000 00000000 00000000 00000001 00000000 00000000 00000000 00000010 00000000 00000000 00000000 00000100 00000000 00000000 00000000 00001000 00000000 00000000 00000000 00010000 00000000 00000000 00000000 00100000 00000000 00000000 00000000 01000000 00000000 00000000 00100000 00000000 but is it actually: 00000000 00000000 00100000 01111111 ? Last fiddled with by Bundu on 20120211 at 16:14 

20120211, 17:34  #17 
Jun 2003
1268_{16} Posts 
Yes.
Code:
x = (1 << v[i]); Code:
x = x  (1 << v[i]); Then compute: x ____ : 00000000 00000000 00100000 01111111 x << 1 : 00000000 00000000 01000000 11111110 x << 2 : 00000000 00000000 10000001 11111100 x << 3 : 00000000 00000001 00000011 11111000 x << 4 : 00000000 00000010 00000111 11110000 Then AND them all together (Again... x &= y is shorthand for x = x & y). See if there are any '1' bits left in the result. If so, it indicates that there are 5 consecutive '1's in x. Last fiddled with by axn on 20120211 at 17:35 
20120211, 20:07  #18 
Jul 2004
Mid Calder, Scotland
271_{8} Posts 
Sir you are a legend. I know I am asking a lot of questions, hopefully you won't mind a few more!
Ok so longhand x = x & (x << 1) & (x << 2) & (x << 3) & (x << 4); Now I am not 100% certain but I am assuming that we work from left to right in this calculation 00000000 00000000 00100000 01111111 = x &00000000 00000000 01000000 11111110 = (x << 1) Gives 00000000 00000000 00000000 01111110 &00000000 00000000 10000001 11111100 = (x << 2) Gives 00000000 00000000 00000000 01111100 &00000000 00000001 00000011 11111000 = (x << 3) Gives 00000000 00000000 00000000 01111000 &00000000 00000010 00000111 11110000 = (x << 4) Final Result 00000000 00000000 00000000 01110000 so since the final result is >0 we get a true and we have a straight! [2,4,6,8,10,12,14] 00000000 00000000 00101010 10101010 = x 00000000 00000000 01010101 01010100 = (x << 1) 00000000 00000000 10101010 10101000 = (x << 2) 00000000 00000001 01010101 01010000 = (x << 3) 00000000 00000010 10101010 10100000 = (x << 4) 00000000 00000000 00101010 10101010 = x &00000000 00000000 01010101 01010100 = (x << 1) Gives 00000000 00000000 00000000 00000000 &00000000 00000000 10101010 10101000 = (x << 2) Gives 00000000 00000000 00000000 00000000 &00000000 00000001 01010101 01010000 = (x << 3) Gives 00000000 00000000 00000000 00000000 &00000000 00000010 10101010 10100000 = (x << 4) Final Result 00000000 00000000 00000000 00000000 so since the final result is not >0 we get a false and we do not have a straight! Quite beautiful really. Which leads me to assume/understand: a) the reason sorting is not required is becuase this happens during the  for loop (in a way) when the bits are distributed by shifting? b) repeated numbers become a non issue again becuase the for loop OR sequence sets the flag to 1 the first time the number occurs and then keeps it set any time a repeat occurs c) this formula could be modified to look for longer or shorter sequences quite *easily* so if I wanted to check 5 cards for a seqence of 3 numbers then Code:
function is_shortstraight(v) { // v is a vector of card values var x = 0; var i; for(i=0; i < 5; i++) { x = (1 << v[i]); // v[i] is assumed to be between 1 and 13, where 1 = 'A' and 13 = 'K' if (v[i] == 1) // special check for Ace x = (1 << 14); } x &= (x << 1) & (x << 2); return (x > 0); // return result } Code:
function is_longstraight(v) { // v is a vector of card values var x = 0; var i; for(i=0; i < 9; i++) { x = (1 << v[i]); // v[i] is assumed to be between 1 and 13, where 1 = 'A' and 13 = 'K' if (v[i] == 1) // special check for Ace x = (1 << 14); } x &= (x << 1) & (x << 2) & (x << 3) & (x << 4) & (x << 5); return (x > 0); // return result } Last fiddled with by Bundu on 20120211 at 20:08 Reason: If only we could edit the things we say as easily, my wife would never be in a huff with me.... 
20120212, 03:38  #19 
Dec 2010
Monticello
2^{4}×107 Posts 
As an inpractice programmer, if I have to know that the associativity of an operation goes in a particular direction in order to get the right result, then the code is unclear and gets parentheses.
What has happened to your sorting is that since there are only so many boxes to put things in, and you set a bit in the box when you find something, you ARE sorting...you just don't know that it is, since the standard sorting algorithms are significantly more general. 
20120215, 20:30  #20  
"Richard B. Woods"
Aug 2002
Wisconsin USA
2^{2}·3·599 Posts 
Quote:
"<<" is a bitshift to the left. ">>" is a bitshift to the right. Quote:
Quote:
Should be: 1<<1: would be 00000010 = 2 = multiplication by 2^1 and so forth ... But you do have the shifts correct in your second post. :) Last fiddled with by cheesehead on 20120215 at 20:34 

20120219, 18:09  #21 
Jul 2004
Mid Calder, Scotland
271_{8} Posts 
Well thanks to everyone's help I have managed to complete the first part of my work which is hand evaluation! I know it isn't the prettiest code in the world but it works, I coded it myself almost entirely and I am pretty happy with it so far. No doubt as my skills improve I will come back and improve it over time. But for now at least I can tackle the next section which is player interaction and betting!
If anyone is interested the attached text file is what I have so far, simply save as an html and bash away at the refresh button :) 
Thread Tools  
Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
Shift Number in LL Test  Kalli Hofmann  Information & Answers  1  20180108 12:24 
how can I test a number in any prime95?  Welton  Information & Answers  7  20160729 12:07 
P95: Sequential (?!) Stage 2 of P1?  LaurV  Software  11  20120628 09:57 
What's the largest known sequential prime?  Unregistered  Homework Help  4  20090911 11:46 
Time to test arbitrary number  JuanTutors  Math  3  20070516 12:13 