Skip to content

Instantly share code, notes, and snippets.

View ShaneRich5's full-sized avatar
🏠
Working from home

Shane Richards ShaneRich5

🏠
Working from home
  • FTI Consulting
  • New York, NY
View GitHub Profile
@ShaneRich5
ShaneRich5 / bit_counting.py
Last active March 3, 2018 02:41
Code Wars
# 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):
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
@ShaneRich5
ShaneRich5 / power_hungry.py
Last active November 1, 2017 01:43
Google's foo.bar challenges
def answer(xs):
negatives = []
result = 0
if len(xs) == 1:
return xs[0]
for element in xs:
if element > 0:
if result == 0:
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']):
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):
#!/bin/python
import sys
def happy_ladybugs(n, bugs):
mappings = {}
free_cell = False
happy = True
for i, bug in enumerate(bugs):
@ShaneRich5
ShaneRich5 / super_reduced_string.java
Created May 24, 2017 12:40
Solution to the Super Reduce String problem on Hackerrank. https://www.hackerrank.com/challenges/reduced-string
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;
@ShaneRich5
ShaneRich5 / mansa_stones.py
Created May 24, 2017 01:42
Solution to the Mansa Stones problem on Hackerrank. https://www.hackerrank.com/challenges/manasa-and-stones
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
#!/bin/python
import csv
import xml.etree.ElementTree as ET
from util import prettify, capitalize
class AutoBuilder:
def __init__(self):
self.create_rss_element()
@ShaneRich5
ShaneRich5 / encription.py
Last active May 25, 2017 06:01
Solution to the Encryption problem on Hackerrank. https://www.hackerrank.com/challenges/encryption
#!/bin/python
import sys
from math import floor, ceil
sentence = raw_input().replace(" ", "")
size = len(sentence)
root = size ** .5
row = int(floor(root))