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 spiral_flatten(matrix_chunks) | |
| [].tap do |result| | |
| until matrix_chunks.empty? | |
| result.concat matrix_chunks.shift | |
| matrix_chunks[0..-2].to_a.each { |chunk| result << chunk.pop } | |
| break if matrix_chunks.empty? | |
| result.concat matrix_chunks.pop.reverse | |
| matrix_chunks[1..-1].to_a.reverse_each { |chunk| result << chunk.shift } | |
| end | |
| 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
| def foo | |
| puts "This is a test" | |
| 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
| import Control.Arrow | |
| import Data.Function | |
| import Data.List | |
| import Data.Ord | |
| -- mapReduce key_func val_func reduce_func -- | |
| mapReduce :: Ord c => (b1 -> c) -> (b1 -> b) -> ([b] -> c1) -> [b1] -> [(c, c1)] | |
| mapReduce k r v = reduce' r . group' . map' k v | |
| where | |
| reduce' f = map (fst . head &&& f . map snd) |
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
| # Read the CSV file into R | |
| citations <- read.csv("citations2013.csv") | |
| # At this point, people were told to attach(). Apparently that's icky. | |
| print("Dataset contains the following columns:") | |
| print(names(citations)) | |
| print("Length of citations$Citations2013:") | |
| print(length(citations$Citations2013)) |
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
| # Exercise: | |
| # Given the Pre-order and In-order traversals of a tree, | |
| # reconstruct the original tree structure. | |
| # | |
| # Pre-order node output: Node (Left) (Right) | |
| # In-order node output: (Left) Node (Right) | |
| # | |
| # Example: | |
| # 'a' | |
| # | | |
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
| \documentclass[10pt, a4paper]{article} % use "amsart" instead of "article" for AMSLaTeX format | |
| \usepackage{microtype} | |
| \usepackage[textwidth=17cm,textheight=24cm]{geometry} | |
| \usepackage{fullpage} % See geometry.pdf to learn the layout options. There are lots. | |
| \usepackage{helvet} | |
| \usepackage{listings} | |
| \usepackage[usenames,dvipsnames,svgnames,table]{xcolor} | |
| \usepackage[normalem]{ulem} | |
| \usepackage{epstopdf} | |
| \usepackage{rotating} |
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 heapq | |
| import random | |
| class HeapSorter: | |
| def __init__(self, num_blocks, input_sequence): | |
| self.num_blocks = num_blocks | |
| self.input_sequence = input_sequence | |
| def sorted(self): | |
| return heapq.merge(*self.__sorted_subsequences__()) |
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
| Benchmark.realtime do | |
| File.new('./one_to_a_million.txt') | |
| .readlines.map(&:to_i) | |
| .map { |x| x - 999_990} | |
| .select { |x| x >= 0 } | |
| end | |
| #=> 0.598499 | |
| Benchmark.realtime do | |
| File.new('./one_to_a_million.txt')[Int] |
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 | |
| True, False = False, True | |
| class ExamBoard(object): | |
| def submit(self, work): | |
| work_is_passing_grade = len([work]) > 0 | |
| return work_is_passing_grade |
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 | |
| from __future__ import braces | |
| True, False = False, True | |
| class ExamBoard(object): | |
| def submit(self, work): | |
| work_is_passing_grade = len([work]) > 0 |