This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// "Given a number n, return the number of 1s in the binary representation of n." | |
// Assumptions: | |
// - n is an integer | |
function countOnesInBinaryOfNumber(number) { | |
let num = number; | |
if (num < 0) { | |
// This makes it so the binary conversion later for negative numbers actually | |
// uses the correct two's complement format | |
// See https://stackoverflow.com/questions/9939760/how-do-i-convert-an-integer-to-binary-in-javascript | |
num = num >>> 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function nIsAPowerOfTwo(num) { | |
return (Math.log2(num) % 1) === 0; | |
} | |
// > nIsAPowerOfTwo(0); | |
// false | |
// > nIsAPowerOfTwo(1); | |
// true | |
// > nIsAPowerOfTwo(2); | |
// true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import re | |
import sys | |
def main(): | |
num_str = '1' * int(sys.argv[1]) | |
match = re.match(r'^1?$|^(11+?)\1+$', num_str) | |
print('not prime' if match else 'is prime') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"email": "sgarcia0@wordpress.org", | |
"hiredate": "Wed, 01 Oct 2014 00:00:00 GMT", | |
"name": "Stephen Garcia", | |
"role": "VP Sales", | |
"team": { | |
"board": { | |
"backlog": [ | |
{ | |
"description": "Duis bibendum.", |