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 math | |
| class CollidingCircles(object): | |
| def get_expected_value(self, radii, steps_count): | |
| return math.pi * self.__get_expected_value_for_step(radii, steps_count) | |
| def __get_expected_value_for_step(self, radii_set, step_idx): | |
| if step_idx == 0: | |
| return sum(radius * radius for radius in radii_set) |
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 _get_next_words(self, word): | |
| if word not in self.next_words_dict: | |
| self._generate_next_words_list(word) | |
| return self.next_words_dict[word] | |
| def _generate_next_words_list(self, word): | |
| next_words = [] | |
| word_array = list(word) | |
| for i in range(len(word_array)): |
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 _bfs(self): | |
| word_queue = [(self.begin_word, 1)] | |
| word_enqueued = {self.begin_word: True} | |
| while word_queue: | |
| word, level = word_queue.pop(0) | |
| self.word_levels[word] = level | |
| if word == self.end_word: return level |
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
| queue = [hit] | |
| pop hit, enqueue hot | |
| queue = [hot] | |
| pop hot, enqueue dot, lot | |
| queue = [dot, lot] | |
| pop dot, enqueue dog, ignore lot | |
| queue = [lot, dog] |
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
| begin_word = "hit" | |
| end_word = "cog" | |
| dictionary = "hot", "dot", "dog", "lot", "log", "cog" |
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 WeightedQuickUnion(object): | |
| def __init__(self, size): | |
| self.group_count = self.size= size | |
| self.group = [i for i in range(size)] | |
| self.tree_size = [1] * size | |
| def union(self, child, parent): | |
| child_root = self.find(child) | |
| parent_root = self.find(parent) |
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 memoize(dict): | |
| def __init__(self, func): | |
| self.func = func | |
| def __call__(self, *args): | |
| return self[args] | |
| def __missing__(self, key): | |
| result = self[key] = self.func(*key) |
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
| anuvrat@ ~/Documents/goWorkspace $ go run hw.go | |
| hello, world | |
| anuvrat@ ~/Documents/goWorkspace $ go install hw.go | |
| go install: no install location for .go files listed on command line (GOBIN not set) | |
| ✘ anuvrat@ ~/Documents/goWorkspace $ export GOBIN=/Users/anuvrat/Documents/goWorkspace/bin | |
| anuvrat@ ~/Documents/goWorkspace $ bin/hw | |
| hello, world |
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
| package main | |
| import "fmt" | |
| func main() { | |
| fmt.Printf("hello, world\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
| anuvrat@ ~/Documents $ mkdir -p goWorkspace | |
| anuvrat@ ~/Documents $ cd goWorkspace | |
| anuvrat@ ~/Documents/goWorkspace $ export GOPATH=/Users/anuvrat/Documents/goWorkspace | |
| anuvrat@ ~/Documents/goWorkspace $ vi hw.go |
NewerOlder