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])
The big O notation, and its relatives, the big Theta, the big Omega, the small o and the small omega are ways of saying something about how a function behaves at a limit point (for example, when approaching infinity, but also when approaching 0, etc.) without saying much else about the function. They are commonly … Read more
First solutions for shifting (shift is the shift distance, must not be negative, a is the operand to be shifted and contains also the result when done). The power table is used by all three shift operations. // table used for shift operations powtab = { 1, 2, 4, 8, 16, 32, 64, 128, 256, … Read more
Much as I love Haskell, here are the reasons I would prefer SML for a class in discrete math and data structures (and most other beginners’ classes): Time and space costs of Haskell programs can be very hard to predict, even for experts. SMLÂ offers much more limited ways to blow the machine. Syntax for function … 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