Find non-common elements in lists
Use the symmetric difference operator for sets (aka the XOR operator): >>> set([1,2,3]) ^ set([3,4,5]) set([1, 2, 4, 5])
Use the symmetric difference operator for sets (aka the XOR operator): >>> set([1,2,3]) ^ set([3,4,5]) set([1, 2, 4, 5])
OK, here’s your code (and btw, thanks for posting such an interesting and challenging problem – at least for me… :-)) – using recursion for all possible permutations (by N) given an array of elements) Code : <?php function permutations($arr,$n) { $res = array(); foreach ($arr as $w) { if ($n==1) $res[] = $w; else … Read more
This is the function that I use for this calculation: public static int binlog( int bits ) // returns 0 for bits=0 { int log = 0; if( ( bits & 0xffff0000 ) != 0 ) { bits >>>= 16; log = 16; } if( bits >= 256 ) { bits >>>= 8; log += … Read more