This file contains 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
(defn flatten-sets | |
"Like flatten, but pulls elements out of sets instead of sequences." | |
[v] | |
(filter (complement set?) | |
(rest (tree-seq set? seq (set v))))) |
This file contains 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
// <iostream> and <fstream> have been included | |
void lines() { | |
ifstream in_file; | |
in_file.open("input.txt"); | |
string line; | |
while (in_file.getline(line, 256)) { | |
cout << "line: \"" << line << "\"\n"; | |
} |
This file contains 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
(defn modify-vals | |
[f m] | |
(zipmap | |
(keys m) | |
(for [item (vals m)] (f item)))) |
This file contains 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
(defn square-matrix? | |
[mat] | |
(apply = | |
(count mat) | |
(for [r mat] (count r)))) | |
(defn transpose | |
[mat] | |
{:pre [(square-matrix? mat)]} | |
(loop [res [], |
This file contains 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
;; Utility functions that will be used later | |
(def naturals (iterate inc 1)) | |
(defn all-factors | |
[n] | |
(filter #(= (mod n %) 0) | |
(take-while #(<= % (sqrt n)) | |
(rest naturals)))) |
This file contains 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
ul.slideshow { | |
list-style: none; | |
width: 294px; | |
height: 286px; | |
float: right; | |
overflow: hidden; | |
position: relative; | |
margin: 0; | |
padding: 0; | |
padding-left: 0.5em; |
This file contains 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
// return the version of OS X in an array, e.g. a[0] = 10, a[1] = 2, a[2] = 2 | |
function get_macosx_version() | |
{ | |
var re = new RegExp(".+Mac OS X (\\d+)_(\\d+)_(\\d+)\\).+"); | |
var match = re.exec(navigator.appVersion); | |
return [parseInt(match[1]), parseInt(match[2]), parseInt(match[3])]; | |
} |
This file contains 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
; Replaces each character with an HTML escape code like " ". | |
; This is useful as some lightweight protection against e-mail harvesting; | |
; it probably won't perform correctly with non-ASCII input. | |
; | |
; example: | |
; (obfuscate "example.com") | |
; => "example.com" | |
(defn obfuscate | |
[text] |
This file contains 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
grades = {} | |
for i in range(number_of_students): | |
# using input() can be unsafe; use raw_input() instead | |
name = raw_input("Name: ") | |
first_grade = int(raw_input("First grade: ")) | |
second_grade = int(raw_input("Second grade: ")) | |
grades[name] = (first_grade, second_grade) | |
# after running, grades will be something like |
This file contains 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
(defn matrix | |
[vectors] | |
(for [i (range (count vectors)) | |
j (range (count vectors))] | |
(distance-between (nth vectors i) (nth vectors j)))) | |
; originally written in Python as | |
; def generate_matrix(vectors): | |
; size = len(vectors) | |
; return [[distance_between(vectors[i], vectors[j]) for i in range(size)] for j in range(size)] |
OlderNewer