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
| #!/usr/bin/env python | |
| import sys | |
| try: | |
| word = sys.argv[1] | |
| except IndexError: | |
| print 'usage: anagrams.py <word>' | |
| exit(1) |
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
| class PriorityQueue | |
| def initialize() @store = {} end | |
| # Takes element and it's priority. | |
| # Returns an array of elements with the same priority. | |
| def enq(el, p) | |
| @store[p] ? @store[p].push(el) : @store[p] = [el] | |
| return @store[p] | |
| end |
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
| class PriorityQueue(object): | |
| def __init__(self): | |
| self.store = {} | |
| def enq(self, element, weight): | |
| if weight in self.store: | |
| self.store[weight].append(element) | |
| else: | |
| self.store[weight] = [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
| Integer::class_eval do | |
| def power_of_2?() (self & (self - 1)) == 0 end | |
| end |
NewerOlder