This file contains hidden or 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
# Write a function that takes an (unsigned) integer as input, and returns the number of bits that are equal to one in the binary representation of that number. | |
# Example: The binary representation of 1234 is 10011010010, so the function should return 5 in this case | |
def countBits(n): | |
binary = bin(n)[2:] | |
return len(filter(lambda x: x == '1', binary)) | |
# Alternative solution | |
# def countBits(n): |
This file contains hidden or 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
def sum_two(a, b): | |
return int(a) + int(b) | |
def compare_versions(version_a, version_b): | |
a = map(int, version_a.split('.')) | |
b = map(int, version_b.split('.')) | |
first_a, first_b = int(a[0]), int(b[0]) | |
# check if a release number is greater |
This file contains hidden or 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
def answer(xs): | |
negatives = [] | |
result = 0 | |
if len(xs) == 1: | |
return xs[0] | |
for element in xs: | |
if element > 0: | |
if result == 0: |
This file contains hidden or 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
import os | |
import json | |
from pprint import pprint | |
for filename in os.listdir('./'): | |
if (filename.endswith('.json')): | |
with open(filename, 'r') as json_file: | |
data = json.load(json_file) | |
if (data['email'] != data['username']): |
This file contains hidden or 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
from tweepy import OAuthHandler, Stream | |
from tweepy.streaming import StreamListener | |
class Listener(StreamListener): | |
def on_data(self, data): | |
print data | |
return True | |
def on_error(self, status): |
This file contains hidden or 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
#!/bin/python | |
import sys | |
def happy_ladybugs(n, bugs): | |
mappings = {} | |
free_cell = False | |
happy = True | |
for i, bug in enumerate(bugs): |
This file contains hidden or 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
import java.io.*; | |
import java.util.*; | |
public class Solution { | |
public static void main(String[] args) { | |
Scanner scan = new Scanner(System.in); | |
StringBuilder s = new StringBuilder(scan.nextLine()); | |
int i = 0; |
This file contains hidden or 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
for _ in xrange(test_cases): | |
n = int(raw_input()) - 1 | |
a = int(raw_input()) | |
b = int(raw_input()) | |
low = a if a < b else b | |
high = a + b - low | |
diff = high - low | |
This file contains hidden or 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
#!/bin/python | |
import csv | |
import xml.etree.ElementTree as ET | |
from util import prettify, capitalize | |
class AutoBuilder: | |
def __init__(self): | |
self.create_rss_element() |
This file contains hidden or 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
#!/bin/python | |
import sys | |
from math import floor, ceil | |
sentence = raw_input().replace(" ", "") | |
size = len(sentence) | |
root = size ** .5 | |
row = int(floor(root)) |