Skip to content

Instantly share code, notes, and snippets.

View sumoward's full-sized avatar

Brian Ward sumoward

  • Cazarola Ltd
  • Dublin
View GitHub Profile
@sumoward
sumoward / anagrams.py
Created February 21, 2017 10:29
test for anagagrams in a list of strings
from collections import defaultdict
def load_words(filename='/usr/share/dict/american-english'):
with open(filename) as f:
for word in f:
yield word.rstrip()
def get_anagrams(source):
d = defaultdict(list)
for word in source:
require 'open-uri'
require 'nokogiri'
require 'mechanize'
require 'csv'
def scrape(row)
puts '_________start_________'
mechanize = Mechanize.new
page = mechanize.get('http://www.aircraftbluebook.com/Tools/HVR/Calculate.do')
# find login form and add credentials
"""
make the loop go through each character in the text,
and see if you've got a palindrome when extending with the left and right character of your current character.
This way you'll stop checking when it's not a palindrome and don't waste time checking non-palindromes.
"""
DEFAULT_TEXT = "racecarenterelephantmalayalam"
def all_palindromes(text=DEFAULT_TEXT):
@sumoward
sumoward / gist:bfdfcfa91ab6c977fc7b
Created August 7, 2014 15:35
coding test films find most popular decade from a list
"""
short coding test to take a list of movies and
their year and rturn the most popular decade
"""
def movies():
frequency_of_decade = {
'1900': 0,
"""
Our robots are always working to improve their linguistic skills. For this mission, they research the latin alphabet and its applications.
The alphabet contains both vowel and consonant letters (yes, we divide the letters).
Vowels -- A E I O U Y
Consonants -- B C D F G H J K L M N P Q R S T V W X Z
You are given a block of text with different words. These words are separated by white-spaces and punctuation marks. Numbers are not considered words in this mission (a mix of letters and digits is not a word either). You should count the number of words (striped words) where the vowels with consonants are alternating, that is; words that you count cannot have two consecutive vowels or consonants. The words consisting of a single letter are not striped -- do not count those. Casing is not significant for this mission.
"""
def checkio(text):
text = text.lower()
check_list = sorted(set(text))
store_no = 0
store_letter = ''
for letter in check_list:
if letter.isalpha():
ans = text.count(letter)
if ans > store_no :
store_letter = letter
def checkio(number):
counter =0
ans = str(bin(number))
for num in ans:
if num == '1':
counter+=1
return counter
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
t0= time.clock()
do_something()
t= time.clock() - t0 # t is wall seconds elapsed (floating point)
class FileEntity
{
// members common to File & Folder
// create, copy, delete, move, getInfo, open, etc
};
class Folder : public FileEntity
{
// a folder can have multiple FileEntity (folders or files)
vector<FileEntity> m_VecFileEntity;
class CNode:
left , right, data = None, None, 0
def __init__(self, data):
# initializes the data members
self.left = None
self.right = None
self.data = data