Skip to content

Instantly share code, notes, and snippets.

View unclecode's full-sized avatar
🎯
Focusing

UncleCode unclecode

🎯
Focusing
View GitHub Profile
@unclecode
unclecode / app.css
Last active May 14, 2019 08:51
A simple gist on p5 js
body {
color:green;
}
@unclecode
unclecode / stupidSoldiers.py
Last active July 14, 2017 07:17
Algorithm to generate stupid soldier patterns
import math
def findAnomalyPosition(n):
bit_length = int(math.ceil(math.log(n, 2)))
#1010 & 0011 = 0010 It means and of any number to 33 << i is returning two consequitive bits at position i and i + 1
#XOR of n eith 2**i is toggling the bit at position i
#so XOR n with 3 >> i is toggling bits at positions i and i + 1 and in our case
#if bits in position i and i + 1 is 2 or 10 we want to make 01 which is this toggling with number 3
return [i for i in range(but_length) if ((x >> i) & 3) == 2 if ((x >> i) & 3) == 2]
def generateNext(x):