If you are not familiar with polish notation, simple arithmetic might seem confusing.
Note: Enter only enough to fill in the blank (in this case, a single number) - do not retype the whole problem.
", "difficulty" : "Elementary", "tags" : [], "tests" : [ "(= (- 10 (* 2 3)) __)" ], "times-solved" : 1389, "title" : "Simple Math", "user" : "dbyrne" },
3 | { "_id" : 3, "description" : "Clojure strings are Java strings. This means that you can use any of the Java string methods on Clojure strings.", "difficulty" : "Elementary", "tags" : [], "tests" : [ "(= __ (.toUpperCase \"hello world\"))" ], "times-solved" : 1373, "title" : "Intro to Strings", "user" : "dbyrne" },
4 | { "_id" : 4, "description" : "Lists can be constructed with either a function or a quoted form.", "difficulty" : "Elementary", "tags" : [], "tests" : [ "(= (list __) '(:a :b :c))" ], "times-solved" : 1294, "title" : "Intro to Lists", "user" : "dbyrne" },
5 | { "_id" : 6, "description" : "Vectors can be constructed several ways. You can compare them with lists.\r\n
Note: the brackets [] surrounding the blanks __ are part of the test case.", "difficulty" : "Elementary", "tags" : null, "tests" : [ "(= [__] (list :a :b :c) (vec '(:a :b :c)) (vector :a :b :c))" ], "times-solved" : 1177, "title" : "Intro to Vectors", "user" : "dbyrne", "restricted" : null },
6 | { "_id" : 7, "description" : "When operating on a Vector, the conj function will return a new vector with one or more items \"added\" to the end.", "difficulty" : "Elementary", "tags" : [], "tests" : [ "(= __ (conj [1 2 3] 4))", "(= __ (conj [1 2] 3 4))" ], "times-solved" : 1165, "title" : "Vectors: conj", "user" : "dbyrne" },
7 | { "_id" : 8, "description" : "Sets are collections of unique values.", "difficulty" : "Elementary", "tags" : [], "tests" : [ "(= __ (set '(:a :a :b :c :c :c :c :d :d)))", "(= __ (clojure.set/union #{:a :b :c} #{:b :c :d}))" ], "times-solved" : 1128, "title" : "Intro to Sets", "user" : "dbyrne" },
8 | { "_id" : 9, "description" : "When operating on a set, the conj function returns a new set with one or more keys \"added\".", "difficulty" : "Elementary", "tags" : [], "tests" : [ "(= #{1 2 3 4} (conj #{1 4 3} __))" ], "times-solved" : 1108, "title" : "Sets: conj", "user" : "dbyrne" },
9 | { "_id" : 10, "description" : "Maps store key-value pairs. Both maps and keywords can be used as lookup functions. Commas can be used to make maps more readable, but they are not required.", "difficulty" : "Elementary", "tags" : [], "tests" : [ "(= __ ((hash-map :a 10, :b 20, :c 30) :b))", "(= __ (:b {:a 10, :b 20, :c 30}))" ], "times-solved" : 1082, "title" : "Intro to Maps", "user" : "dbyrne" },
10 | { "_id" : 11, "description" : "When operating on a map, the conj function returns a new map with one or more key-value pairs \"added\".", "difficulty" : "Elementary", "tags" : [], "tests" : [ "(= {:a 1, :b 2, :c 3} (conj {:a 1} __ [:c 3]))" ], "times-solved" : 1061, "title" : "Maps: conj", "user" : "dbyrne" },
11 | { "_id" : 12, "description" : "All Clojure collections support sequencing. You can operate on sequences with functions like first, second, and last.", "difficulty" : "Elementary", "tags" : [], "tests" : [ "(= __ (first '(3 2 1)))", "(= __ (second [2 3 4]))", "(= __ (last (list 1 2 3)))" ], "times-solved" : 1051, "title" : "Intro to Sequences", "user" : "dbyrne" },
12 | { "_id" : 13, "description" : "The rest function will return all the items of a sequence except the first.", "difficulty" : "Elementary", "tags" : [], "tests" : [ "(= __ (rest [10 20 30 40]))" ], "times-solved" : 1045, "title" : "Sequences: rest", "user" : "dbyrne" },
13 | { "_id" : 14, "description" : "Clojure has many different ways to create functions.", "difficulty" : "Elementary", "tags" : [], "tests" : [ "(= __ ((fn add-five [x] (+ x 5)) 3))", "(= __ ((fn [x] (+ x 5)) 3))", "(= __ (#(+ % 5) 3))", "(= __ ((partial + 5) 3))" ], "times-solved" : 1038, "title" : "Intro to Functions", "user" : "dbyrne" },
14 | { "_id" : 15, "description" : "Write a function which doubles a number.", "difficulty" : "Elementary", "tags" : [], "tests" : [ "(= (__ 2) 4)", "(= (__ 3) 6)", "(= (__ 11) 22)", "(= (__ 7) 14)" ], "times-solved" : 1025, "title" : "Double Down", "user" : "dbyrne" },
15 | { "_id" : 16, "description" : "Write a function which returns a personalized greeting.", "difficulty" : "Elementary", "tags" : [], "tests" : [ "(= (__ \"Dave\") \"Hello, Dave!\")", "(= (__ \"Jenn\") \"Hello, Jenn!\")", "(= (__ \"Rhea\") \"Hello, Rhea!\")" ], "times-solved" : 986, "title" : "Hello World", "user" : "dbyrne" },
16 | { "_id" : 17, "description" : "The map function takes two arguments: a function (f) and a sequence (s). Map returns a new sequence consisting of the result of applying f to each item of s. Do not confuse the map function with the map data structure.", "difficulty" : "Elementary", "tags" : [], "tests" : [ "(= __ (map #(+ % 5) '(1 2 3)))" ], "times-solved" : 986, "title" : "Sequences: map", "user" : "dbyrne" },
17 | { "_id" : 18, "description" : "The filter function takes two arguments: a predicate function (f) and a sequence (s). Filter returns a new sequence consisting of all the items of s for which (f item) returns true.", "difficulty" : "Elementary", "tags" : [], "tests" : [ "(= __ (filter #(> % 5) '(3 4 5 6 7)))" ], "times-solved" : 978, "title" : "Sequences: filter", "user" : "dbyrne" },
18 | { "_id" : 19, "description" : "Write a function which returns the last element in a sequence.", "difficulty" : "Easy", "restricted" : [ "last" ], "tags" : [ "seqs", "core-functions" ], "tests" : [ "(= (__ [1 2 3 4 5]) 5)", "(= (__ '(5 4 3)) 3)", "(= (__ [\"b\" \"c\" \"d\"]) \"d\")" ], "times-solved" : 911, "title" : "Last Element", "user" : "dbyrne" },
19 | { "_id" : 20, "description" : "Write a function which returns the second to last element from a sequence.", "difficulty" : "Easy", "tags" : [ "seqs" ], "tests" : [ "(= (__ (list 1 2 3 4 5)) 4)", "(= (__ [\"a\" \"b\" \"c\"]) \"b\")", "(= (__ [[1 2] [3 4]]) [1 2])" ], "times-solved" : 884, "title" : "Penultimate Element", "user" : "dbyrne" },
20 | { "_id" : 21, "description" : "Write a function which returns the Nth element from a sequence.", "difficulty" : "Easy", "restricted" : [ "nth" ], "tags" : [ "seqs", "core-functions" ], "tests" : [ "(= (__ '(4 5 6 7) 2) 6)", "(= (__ [:a :b :c] 0) :a)", "(= (__ [1 2 3 4] 1) 2)", "(= (__ '([1 2] [3 4] [5 6]) 2) [5 6])" ], "times-solved" : 782, "title" : "Nth Element", "user" : "dbyrne" },
21 | { "_id" : 22, "description" : "Write a function which returns the total number of elements in a sequence.", "difficulty" : "Easy", "restricted" : [ "count" ], "tags" : [ "seqs", "core-functions" ], "tests" : [ "(= (__ '(1 2 3 3 1)) 5)", "(= (__ \"Hello World\") 11)", "(= (__ [[1 2] [3 4] [5 6]]) 3)", "(= (__ '(13)) 1)", "(= (__ '(:a :b :c)) 3)" ], "times-solved" : 723, "title" : "Count a Sequence", "user" : "dbyrne" },
22 | { "_id" : 23, "description" : "Write a function which reverses a sequence.", "difficulty" : "Easy", "restricted" : [ "reverse", "rseq" ], "tags" : [ "seqs", "core-functions" ], "tests" : [ "(= (__ [1 2 3 4 5]) [5 4 3 2 1])", "(= (__ (sorted-set 5 7 2 7)) '(7 5 2))", "(= (__ [[1 2][3 4][5 6]]) [[5 6][3 4][1 2]])" ], "times-solved" : 650, "title" : "Reverse a Sequence", "user" : "dbyrne" },
23 | { "_id" : 24, "description" : "Write a function which returns the sum of a sequence of numbers.", "difficulty" : "Easy", "tags" : [ "seqs" ], "tests" : [ "(= (__ [1 2 3]) 6)", "(= (__ (list 0 -2 5 5)) 8)", "(= (__ #{4 2 1}) 7)", "(= (__ '(0 0 -1)) -1)", "(= (__ '(1 10 3)) 14)" ], "times-solved" : 722, "title" : "Sum It All Up", "user" : "dbyrne" },
24 | { "_id" : 25, "description" : "Write a function which returns only the odd numbers from a sequence.", "difficulty" : "Easy", "tags" : [ "seqs" ], "tests" : [ "(= (__ #{1 2 3 4 5}) '(1 3 5))", "(= (__ [4 2 1 6]) '(1))", "(= (__ [2 2 4 6]) '())", "(= (__ [1 1 1 3]) '(1 1 1 3))" ], "times-solved" : 697, "title" : "Find the odd numbers", "user" : "dbyrne" },
25 | { "_id" : 26, "description" : "Write a function which returns the first X fibonacci numbers.", "difficulty" : "Easy", "tags" : [ "Fibonacci", "seqs" ], "tests" : [ "(= (__ 3) '(1 1 2))", "(= (__ 6) '(1 1 2 3 5 8))", "(= (__ 8) '(1 1 2 3 5 8 13 21))" ], "times-solved" : 507, "title" : "Fibonacci Sequence", "user" : "dbyrne" },
26 | { "_id" : 27, "description" : "Write a function which returns true if the given sequence is a palindrome.
\n Hint: \"racecar\" does not equal '(\\r \\a \\c \\e \\c \\a \\r)", "difficulty" : "Easy", "tags" : [ "seqs" ], "tests" : [ "(false? (__ '(1 2 3 4 5)))", "(true? (__ \"racecar\"))", "(true? (__ [:foo :bar :foo]))", "(true? (__ '(1 1 3 3 1 1)))", "(false? (__ '(:a :b :c)))" ], "times-solved" : 546, "title" : "Palindrome Detector", "user" : "dbyrne" },
27 | { "_id" : 28, "description" : "Write a function which flattens a sequence.", "difficulty" : "Easy", "restricted" : [ "flatten" ], "tags" : [ "seqs", "core-functions" ], "tests" : [ "(= (__ '((1 2) 3 [4 [5 6]])) '(1 2 3 4 5 6))", "(= (__ [\"a\" [\"b\"] \"c\"]) '(\"a\" \"b\" \"c\"))", "(= (__ '((((:a))))) '(:a))" ], "times-solved" : 356, "title" : "Flatten a Sequence", "user" : "dbyrne" },
28 | { "_id" : 29, "description" : "Write a function which takes a string and returns a new string containing only the capital letters.", "difficulty" : "Easy", "tags" : [ "strings" ], "tests" : [ "(= (__ \"HeLlO, WoRlD!\") \"HLOWRD\")", "(empty? (__ \"nothing\"))", "(= (__ \"$#A(*&987Zf\") \"AZ\")" ], "times-solved" : 444, "title" : "Get the Caps", "user" : "dbyrne" },
29 | { "_id" : 30, "description" : "Write a function which removes consecutive duplicates from a sequence.", "difficulty" : "Easy", "tags" : [ "seqs" ], "tests" : [ "(= (apply str (__ \"Leeeeeerrroyyy\")) \"Leroy\")", "(= (__ [1 1 2 3 3 2 2 3]) '(1 2 3 2 3))", "(= (__ [[1 2] [1 2] [3 4] [1 2]]) '([1 2] [3 4] [1 2]))" ], "times-solved" : 339, "title" : "Compress a Sequence", "user" : "dbyrne" },
30 | { "_id" : 31, "description" : "Write a function which packs consecutive duplicates into sub-lists.", "difficulty" : "Easy", "tags" : [ "seqs" ], "tests" : [ "(= (__ [1 1 2 1 1 1 3 3]) '((1 1) (2) (1 1 1) (3 3)))", "(= (__ [:a :a :b :b :c]) '((:a :a) (:b :b) (:c)))", "(= (__ [[1 2] [1 2] [3 4]]) '(([1 2] [1 2]) ([3 4])))" ], "times-solved" : 279, "title" : "Pack a Sequence", "user" : "dbyrne" },
31 | { "_id" : 32, "description" : "Write a function which duplicates each element of a sequence.", "difficulty" : "Easy", "tags" : [ "seqs" ], "tests" : [ "(= (__ [1 2 3]) '(1 1 2 2 3 3))", "(= (__ [:a :a :b :b]) '(:a :a :a :a :b :b :b :b))", "(= (__ [[1 2] [3 4]]) '([1 2] [1 2] [3 4] [3 4]))", "(= (__ [[1 2] [3 4]]) '([1 2] [1 2] [3 4] [3 4]))" ], "times-solved" : 368, "title" : "Duplicate a Sequence", "user" : "dbyrne" },
32 | { "_id" : 33, "description" : "Write a function which replicates each element of a sequence a variable number of times.", "difficulty" : "Easy", "tags" : [ "seqs" ], "tests" : [ "(= (__ [1 2 3] 2) '(1 1 2 2 3 3))", "(= (__ [:a :b] 4) '(:a :a :a :a :b :b :b :b))", "(= (__ [4 5 6] 1) '(4 5 6))", "(= (__ [[1 2] [3 4]] 2) '([1 2] [1 2] [3 4] [3 4]))", "(= (__ [44 33] 2) [44 44 33 33])" ], "times-solved" : 331, "title" : "Replicate a Sequence", "user" : "dbyrne" },
33 | { "_id" : 34, "description" : "Write a function which creates a list of all integers in a given range.", "difficulty" : "Easy", "restricted" : [ "range" ], "tags" : [ "seqs", "core-functions" ], "tests" : [ "(= (__ 1 4) '(1 2 3))", "(= (__ -2 2) '(-2 -1 0 1))", "(= (__ 5 8) '(5 6 7))" ], "times-solved" : 358, "title" : "Implement range", "user" : "dbyrne" },
34 | { "_id" : 35, "description" : "Clojure lets you give local names to values using the special let-form.", "difficulty" : "Elementary", "tags" : [ "syntax" ], "tests" : [ "(= __ (let [x 5] (+ 2 x)))", "(= __ (let [x 3, y 10] (- y x)))", "(= __ (let [x 21] (let [y 3] (/ x y))))" ], "times-solved" : 496, "title" : "Local bindings", "user" : "amalloy" },
35 | { "_id" : 36, "description" : "Can you bind x, y, and z so that these are all true?", "difficulty" : "Elementary", "tags" : [ "math", "syntax" ], "tests" : [ "(= 10 (let __ (+ x y)))", "(= 4 (let __ (+ y z)))", "(= 1 (let __ z))" ], "times-solved" : 491, "title" : "Let it Be", "user" : "amalloy" },
36 | { "_id" : 37, "description" : "Regex patterns are supported with a special reader macro.", "difficulty" : "Elementary", "tags" : [ "regex", "syntax" ], "tests" : [ "(= __ (apply str (re-seq #\"[A-Z]+\" \"bA1B3Ce \")))" ], "times-solved" : 468, "title" : "Regular Expressions", "user" : "dbyrne" },
37 | { "_id" : 38, "description" : "Write a function which takes a variable number of parameters and returns the maximum value.", "difficulty" : "Easy", "restricted" : [ "max", "max-key" ], "tags" : [ "core-functions" ], "tests" : [ "(= (__ 1 8 3 4) 8)", "(= (__ 30 20) 30)", "(= (__ 45 67 11) 67)" ], "times-solved" : 412, "title" : "Maximum value", "user" : "dbyrne" },
38 | { "_id" : 39, "description" : "Write a function which takes two sequences and returns the first item from each, then the second item from each, then the third, etc.", "difficulty" : "Easy", "restricted" : [ "interleave" ], "tags" : [ "seqs", "core-functions" ], "tests" : [ "(= (__ [1 2 3] [:a :b :c]) '(1 :a 2 :b 3 :c))", "(= (__ [1 2] [3 4 5 6]) '(1 3 2 4))", "(= (__ [1 2 3 4] [5]) [1 5])", "(= (__ [30 20] [25 15]) [30 25 20 15])" ], "times-solved" : 321, "title" : "Interleave Two Seqs", "user" : "dbyrne" },
39 | { "_id" : 40, "description" : "Write a function which separates the items of a sequence by an arbitrary value.", "difficulty" : "Easy", "restricted" : [ "interpose" ], "tags" : [ "seqs", "core-functions" ], "tests" : [ "(= (__ 0 [1 2 3]) [1 0 2 0 3])", "(= (apply str (__ \", \" [\"one\" \"two\" \"three\"])) \"one, two, three\")", "(= (__ :z [:a :b :c :d]) [:a :z :b :z :c :z :d])" ], "times-solved" : 306, "title" : "Interpose a Seq", "user" : "dbyrne" },
40 | { "_id" : 41, "description" : "Write a function which drops every Nth item from a sequence.", "difficulty" : "Easy", "tags" : [ "seqs" ], "tests" : [ "(= (__ [1 2 3 4 5 6 7 8] 3) [1 2 4 5 7 8])", "(= (__ [:a :b :c :d :e :f] 2) [:a :c :e])", "(= (__ [1 2 3 4 5 6] 4) [1 2 3 5 6])" ], "times-solved" : 276, "title" : "Drop Every Nth Item", "user" : "dbyrne" },
41 | { "_id" : 42, "description" : "Write a function which calculates factorials.", "difficulty" : "Easy", "tags" : [ "math" ], "tests" : [ "(= (__ 1) 1)", "(= (__ 3) 6)", "(= (__ 5) 120)", "(= (__ 8) 40320)" ], "times-solved" : 335, "title" : "Factorial Fun", "user" : "amalloy" },
42 | { "_id" : 43, "description" : "Write a function which reverses the interleave process into x number of subsequences.", "difficulty" : "Medium", "tags" : [ "seqs" ], "tests" : [ "(= (__ [1 2 3 4 5 6] 2) '((1 3 5) (2 4 6)))", "(= (__ (range 9) 3) '((0 3 6) (1 4 7) (2 5 8)))", "(= (__ (range 10) 5) '((0 5) (1 6) (2 7) (3 8) (4 9)))" ], "times-solved" : 216, "title" : "Reverse Interleave", "user" : "amalloy" },
43 | { "_id" : 44, "description" : "Write a function which can rotate a sequence in either direction.", "difficulty" : "Medium", "tags" : [ "seqs" ], "tests" : [ "(= (__ 2 [1 2 3 4 5]) '(3 4 5 1 2))", "(= (__ -2 [1 2 3 4 5]) '(4 5 1 2 3))", "(= (__ 6 [1 2 3 4 5]) '(2 3 4 5 1))", "(= (__ 1 '(:a :b :c)) '(:b :c :a))", "(= (__ -4 '(:a :b :c)) '(:c :a :b))" ], "times-solved" : 233, "title" : "Rotate Sequence", "user" : "dbyrne" },
44 | { "_id" : 45, "description" : "The iterate function can be used to produce an infinite lazy sequence.", "difficulty" : "Easy", "tags" : [ "seqs" ], "tests" : [ "(= __ (take 5 (iterate #(+ 3 %) 1)))" ], "times-solved" : 342, "title" : "Intro to Iterate", "user" : "dbyrne" },
45 | { "_id" : 46, "description" : "Write a higher-order function which flips the order of the arguments of an input function.", "difficulty" : "Medium", "tags" : [ "higher-order-functions" ], "tests" : [ "(= 3 ((__ nth) 2 [1 2 3 4 5]))", "(= true ((__ >) 7 8))", "(= 4 ((__ quot) 2 8))", "(= [1 2 3] ((__ take) [1 2 3 4 5] 3))" ], "times-solved" : 277, "title" : "Flipping out", "user" : "dbyrne" },
46 | { "_id" : 47, "description" : "The contains? function checks if a KEY is present in a given collection. This often leads beginner clojurians to use it incorrectly with numerically indexed collections like vectors and lists.", "difficulty" : "Easy", "tags" : null, "tests" : [ "(contains? #{4 5 6} __)", "(contains? [1 1 1 1 1] __)", "(contains? {4 :a 2 :b} __)", "(not (contains? [1 2 4] __))" ], "times-solved" : 349, "title" : "Contain Yourself", "user" : "dbyrne", "restricted" : null },
47 | { "_id" : 48, "description" : "The some function takes a predicate function and a collection. It returns the first logical true value of (predicate x) where x is an item in the collection.", "difficulty" : "Easy", "tags" : [], "tests" : [ "(= __ (some #{2 7 6} [5 6 7 8]))", "(= __ (some #(when (even? %) %) [5 6 7 8]))" ], "times-solved" : 384, "title" : "Intro to some", "user" : "dbyrne" },
48 | { "_id" : 49, "description" : "Write a function which will split a sequence into two parts.", "difficulty" : "Easy", "restricted" : [ "split-at" ], "tags" : [ "seqs", "core-functions" ], "tests" : [ "(= (__ 3 [1 2 3 4 5 6]) [[1 2 3] [4 5 6]])", "(= (__ 1 [:a :b :c :d]) [[:a] [:b :c :d]])", "(= (__ 2 [[1 2] [3 4] [5 6]]) [[[1 2] [3 4]] [[5 6]]])" ], "times-solved" : 266, "title" : "Split a sequence", "user" : "dbyrne" },
49 | { "_id" : 50, "description" : "Write a function which takes a sequence consisting of items with different types and splits them up into a set of homogeneous sub-sequences. The internal order of each sub-sequence should be maintained, but the sub-sequences themselves can be returned in any order (this is why 'set' is used in the test cases).", "difficulty" : "Medium", "tags" : [ "seqs" ], "tests" : [ "(= (set (__ [1 :a 2 :b 3 :c])) #{[1 2 3] [:a :b :c]})", "(= (set (__ [:a \"foo\" \"bar\" :b])) #{[:a :b] [\"foo\" \"bar\"]})", "(= (set (__ [[1 2] :a [3 4] 5 6 :b])) #{[[1 2] [3 4]] [:a :b] [5 6]})" ], "times-solved" : 207, "title" : "Split by Type", "user" : "dbyrne" },
50 | { "_id" : 51, "description" : "Here is an example of some more sophisticated destructuring.", "difficulty" : "Easy", "tags" : [ "destructuring" ], "tests" : [ "(= [1 2 [3 4 5] [1 2 3 4 5]] (let [[a b & c :as d] __] [a b c d]))" ], "times-solved" : 279, "title" : "Advanced Destructuring", "user" : "dbyrne" },
51 | { "_id" : 52, "description" : "Let bindings and function parameter lists support destructuring.", "difficulty" : "Elementary", "tags" : [ "destructuring" ], "tests" : [ "(= [2 4] (let [[a b c d e] [0 1 2 3 4]] __))" ], "times-solved" : 301, "title" : "Intro to Destructuring", "user" : "amalloy", "restricted" : null },
52 | { "_id" : 53, "description" : "Given a vector of integers, find the longest consecutive sub-sequence of increasing numbers. If two sub-sequences have the same length, use the one that occurs first. An increasing sub-sequence must have a length of 2 or greater to qualify.", "difficulty" : "Hard", "tags" : [ "seqs" ], "tests" : [ "(= (__ [1 0 1 2 3 0 4 5]) [0 1 2 3])", "(= (__ [5 6 1 3 2 7]) [5 6])", "(= (__ [2 3 3 4 5]) [3 4 5])", "(= (__ [7 6 5 4]) [])" ], "times-solved" : 156, "title" : "Longest Increasing Sub-Seq", "user" : "dbyrne" },
53 | { "_id" : 54, "description" : "Write a function which returns a sequence of lists of x items each. Lists of less than x items should not be returned.", "difficulty" : "Medium", "restricted" : [ "partition", "partition-all" ], "tags" : [ "seqs", "core-functions" ], "tests" : [ "(= (__ 3 (range 9)) '((0 1 2) (3 4 5) (6 7 8)))", "(= (__ 2 (range 8)) '((0 1) (2 3) (4 5) (6 7)))", "(= (__ 3 (range 8)) '((0 1 2) (3 4 5)))" ], "times-solved" : 170, "title" : "Partition a Sequence", "user" : "dbyrne" },
54 | { "_id" : 55, "description" : "Write a function which returns a map containing the number of occurences of each distinct item in a sequence.", "difficulty" : "Medium", "restricted" : [ "frequencies" ], "tags" : [ "seqs", "core-functions" ], "tests" : [ "(= (__ [1 1 2 3 2 1 1]) {1 4, 2 2, 3 1})", "(= (__ [:b :a :b :a :b]) {:a 2, :b 3})", "(= (__ '([1 2] [1 3] [1 3])) {[1 2] 1, [1 3] 2})" ], "times-solved" : 193, "title" : "Count Occurrences", "user" : "dbyrne" },
55 | { "_id" : 56, "description" : "Write a function which removes the duplicates from a sequence. Order of the items must be maintained.", "difficulty" : "Medium", "restricted" : [ "distinct" ], "tags" : [ "seqs", "core-functions" ], "tests" : [ "(= (__ [1 2 1 3 1 2 4]) [1 2 3 4])", "(= (__ [:a :a :b :b :c :c]) [:a :b :c])", "(= (__ '([2 4] [1 2] [1 3] [1 3])) '([2 4] [1 2] [1 3]))", "(= (__ (range 50)) (range 50))" ], "times-solved" : 170, "title" : "Find Distinct Items", "user" : "dbyrne" },
56 | { "_id" : 57, "description" : "A recursive function is a function which calls itself. This is one of the fundamental techniques used in functional programming.", "difficulty" : "Elementary", "tags" : [ "recursion" ], "tests" : [ "(= __ ((fn foo [x] (when (> x 0) (conj (foo (dec x)) x))) 5))" ], "times-solved" : 326, "title" : "Simple Recursion", "user" : "dbyrne" },
57 | { "_id" : 58, "description" : "Write a function which allows you to create function compositions. The parameter list should take a variable number of functions, and create a function that applies them from right-to-left.", "difficulty" : "Medium", "restricted" : [ "comp" ], "tags" : [ "higher-order-functions", "core-functions" ], "tests" : [ "(= [3 2 1] ((__ rest reverse) [1 2 3 4]))", "(= 5 ((__ (partial + 3) second) [1 2 3 4]))", "(= true ((__ zero? #(mod % 8) +) 3 5 7 9))", "(= \"HELLO\" ((__ #(.toUpperCase %) #(apply str %) take) 5 \"hello world\"))" ], "times-solved" : 167, "title" : "Function Composition", "user" : "dbyrne" },
58 | { "_id" : 59, "description" : "Take a set of functions and return a new function that takes a variable number of arguments and returns a sequence containing the result of applying each function left-to-right to the argument list.", "difficulty" : "Medium", "restricted" : [ "juxt" ], "tags" : [ "higher-order-functions", "core-functions" ], "tests" : [ "(= [21 6 1] ((__ + max min) 2 3 5 1 6 4))", "(= [\"HELLO\" 5] ((__ #(.toUpperCase %) count) \"hello\"))", "(= [2 6 4] ((__ :a :c :b) {:a 2, :b 4, :c 6, :d 8 :e 10}))" ], "times-solved" : 169, "title" : "Juxtaposition", "user" : "dbyrne" },
59 | { "_id" : 60, "description" : "Write a function which behaves like reduce, but returns each intermediate value of the reduction. Your function must accept either two or three arguments, and the return sequence must be lazy.", "difficulty" : "Medium", "restricted" : [ "reductions" ], "tags" : [ "seqs", "core-functions" ], "tests" : [ "(= (take 5 (__ + (range))) [0 1 3 6 10])", "(= (__ conj [1] [2 3 4]) [[1] [1 2] [1 2 3] [1 2 3 4]])", "(= (last (__ * 2 [3 4 5])) (reduce * 2 [3 4 5]) 120)" ], "times-solved" : 119, "title" : "Sequence Reductions", "user" : "dbyrne" },
60 | { "_id" : 61, "description" : "Write a function which takes a vector of keys and a vector of values and constructs a map from them.", "difficulty" : "Easy", "restricted" : [ "zipmap" ], "tags" : [ "core-functions" ], "tests" : [ "(= (__ [:a :b :c] [1 2 3]) {:a 1, :b 2, :c 3})", "(= (__ [1 2 3 4] [\"one\" \"two\" \"three\"]) {1 \"one\", 2 \"two\", 3 \"three\"})", "(= (__ [:foo :bar] [\"foo\" \"bar\" \"baz\"]) {:foo \"foo\", :bar \"bar\"})" ], "times-solved" : 197, "title" : "Map Construction", "user" : "dbyrne" },
61 | { "_id" : 62, "description" : "Given a side-effect free function f and an initial value x write a function which returns an infinite lazy sequence of x, (f x), (f (f x)), (f (f (f x))), etc.", "difficulty" : "Easy", "restricted" : [ "iterate" ], "tags" : [ "seqs", "core-functions" ], "tests" : [ "(= (take 5 (__ #(* 2 %) 1)) [1 2 4 8 16])", "(= (take 100 (__ inc 0)) (take 100 (range)))", "(= (take 9 (__ #(inc (mod % 3)) 1)) (take 9 (cycle [1 2 3])))" ], "times-solved" : 163, "title" : "Re-implement Iterate", "user" : "amalloy" },
62 | { "_id" : 63, "description" : "Given a function f and a sequence s, write a function which returns a map. The keys should be the values of f applied to each item in s. The value at each key should be a vector of corresponding items in the order they appear in s.", "difficulty" : "Easy", "restricted" : [ "group-by" ], "tags" : [ "core-functions" ], "tests" : [ "(= (__ #(> % 5) [1 3 6 8]) {false [1 3], true [6 8]})", "(= (__ #(apply / %) [[1 2] [2 4] [4 6] [3 6]])\n {1/2 [[1 2] [2 4] [3 6]], 2/3 [[4 6]]})", "(= (__ count [[1] [1 2] [3] [1 2 3] [2 3]])\n {1 [[1] [3]], 2 [[1 2] [2 3]], 3 [[1 2 3]]})" ], "times-solved" : 154, "title" : "Group a Sequence", "user" : "dbyrne" },
63 | { "_id" : 64, "description" : "Reduce takes a 2 argument function and an optional starting value. It then applies the function to the first 2 items in the sequence (or the starting value and the first element of the sequence). In the next iteration the function will be called on the previous return value and the next item from the sequence, thus reducing the entire collection to one value. Don't worry, it's not as complicated as it sounds.", "difficulty" : "Elementary", "tags" : [ "seqs" ], "tests" : [ "(= 15 (reduce __ [1 2 3 4 5]))", "(= 0 (reduce __ []))", "(= 6 (reduce __ 1 [2 3]))" ], "times-solved" : 339, "title" : "Intro to Reduce", "user" : "citizen428" },
64 | { "_id" : 65, "description" : "Clojure has many sequence types, which act in subtly different ways. The core functions typically convert them into a uniform \"sequence\" type and work with them that way, but it can be important to understand the behavioral and performance differences so that you know which kind is appropriate for your application.
Write a function which takes a collection and returns one of :map, :set, :list, or :vector - describing the type of collection it was given. You won't be allowed to inspect their class or use the built-in predicates like list? - the point is to poke at them and understand their behavior.", "difficulty" : "Medium", "restricted" : [ "class", "type", "Class", "vector?", "sequential?", "list?", "seq?", "map?", "set?", "instance?", "getClass" ], "tags" : [ "seqs", "testing" ], "tests" : [ "(= :map (__ {:a 1, :b 2}))", "(= :list (__ (range (rand-int 20))))", "(= :vector (__ [1 2 3 4 5 6]))", "(= :set (__ #{10 (rand-int 5)}))", "(= [:map :set :vector :list] (map __ [{} #{} [] ()]))" ], "times-solved" : 107, "title" : "Black Box Testing", "user" : "amalloy" },
65 | { "_id" : 66, "description" : "Given two integers, write a function which\nreturns the greatest common divisor.", "difficulty" : "Easy", "tags" : [], "tests" : [ "(= (__ 2 4) 2)", "(= (__ 10 5) 5)", "(= (__ 5 7) 1)", "(= (__ 1023 858) 33)" ], "times-solved" : 187, "title" : "Greatest Common Divisor", "user" : "dbyrne" },
66 | { "_id" : 67, "description" : "Write a function which returns the first x\nnumber of prime numbers.", "difficulty" : "Medium", "tags" : [ "primes" ], "tests" : [ "(= (__ 2) [2 3])", "(= (__ 5) [2 3 5 7 11])", "(= (last (__ 100)) 541)" ], "times-solved" : 122, "title" : "Prime Numbers", "user" : "dbyrne" },
67 | { "_id" : 68, "description" : "Clojure only has one non-stack-consuming looping construct: recur. Either a function or a loop can be used as the recursion point. Either way, recur rebinds the bindings of the recursion point to the values it is passed. Recur must be called from the tail-position, and calling it elsewhere will result in an error.", "difficulty" : "Elementary", "tags" : [ "recursion" ], "tests" : [ "(= __\n (loop [x 5\n result []]\n (if (> x 0)\n (recur (dec x) (conj result (+ 2 x)))\n result)))" ], "times-solved" : 224, "title" : "Recurring Theme", "user" : "dbyrne" },
68 | { "_id" : 69, "description" : "Write a function which takes a function f and a variable number of maps. Your function should return a map that consists of the rest of the maps conj-ed onto the first. If a key occurs in more than one map, the mapping(s) from the latter (left-to-right) should be combined with the mapping in the result by calling (f val-in-result val-in-latter)", "difficulty" : "Medium", "restricted" : [ "merge-with" ], "tags" : [ "core-functions" ], "tests" : [ "(= (__ * {:a 2, :b 3, :c 4} {:a 2} {:b 2} {:c 5})\n {:a 4, :b 6, :c 20})", "(= (__ - {1 10, 2 20} {1 3, 2 10, 3 15})\n {1 7, 2 10, 3 15})", "(= (__ concat {:a [3], :b [6]} {:a [4 5], :c [8 9]} {:b [7]})\n {:a [3 4 5], :b [6 7], :c [8 9]})" ], "times-solved" : 109, "title" : "Merge with a Function", "user" : "dbyrne" },
69 | { "_id" : 70, "description" : "Write a function that splits a sentence up into a sorted list of words. Capitalization should not affect sort order and punctuation should be ignored.", "difficulty" : "Medium", "restricted" : null, "tags" : [ "sorting" ], "tests" : [ "(= (__ \"Have a nice day.\")\r\n [\"a\" \"day\" \"Have\" \"nice\"])", "(= (__ \"Clojure is a fun language!\")\r\n [\"a\" \"Clojure\" \"fun\" \"is\" \"language\"])", "(= (__ \"Fools fall for foolish follies.\")\r\n [\"fall\" \"follies\" \"foolish\" \"Fools\" \"for\"])" ], "times-solved" : 138, "title" : "Word Sorting", "user" : "fotland" },
70 | { "_id" : 71, "description" : "The -> macro threads an expression x through a variable number of forms. First, x is inserted as the second item in the first form, making a list of it if it is not a list already. Then the first form is inserted as the second item in the second form, making a list of that form if necessary. This process continues for all the forms. Using -> can sometimes make your code more readable.", "difficulty" : "Elementary", "restricted" : null, "tags" : null, "tests" : [ "(= (__ (sort (rest (reverse [2 5 4 1 3 6]))))\r\n (-> [2 5 4 1 3 6] (reverse) (rest) (sort) (__))\r\n 5)" ], "times-solved" : 246, "title" : "Rearranging Code: ->", "user" : "amalloy" },
71 | { "_id" : 72, "description" : "The ->> macro threads an expression x through a variable number of forms. First, x is inserted as the last item in the first form, making a list of it if it is not a list already. Then the first form is inserted as the last item in the second form, making a list of that form if necessary. This process continues for all the forms. Using ->> can sometimes make your code more readable.", "difficulty" : "Elementary", "tags" : [], "tests" : [ "(= (__ (map inc (take 3 (drop 2 [2 5 4 1 3 6]))))\n (->> [2 5 4 1 3 6] (drop 2) (take 3) (map inc) (__))\n 11)" ], "times-solved" : 230, "title" : "Rearranging Code: ->>", "user" : "amalloy" },
72 | { "_id" : 73, "description" : "A tic-tac-toe board is represented by a two dimensional vector. X is represented by :x, O is represented by :o, and empty is represented by :e. A player wins by placing three Xs or three Os in a horizontal, vertical, or diagonal row. Write a function which analyzes a tic-tac-toe board and returns :x if X has won, :o if O has won, and nil if neither player has won.", "difficulty" : "Hard", "tags" : [ "game" ], "tests" : [ "(= nil (__ [[:e :e :e]\n [:e :e :e]\n [:e :e :e]]))", "(= :x (__ [[:x :e :o]\n [:x :e :e]\n [:x :e :o]]))", "(= :o (__ [[:e :x :e]\n [:o :o :o]\n [:x :e :x]]))", "(= nil (__ [[:x :e :o]\n [:x :x :e]\n [:o :x :o]]))", "(= :x (__ [[:x :e :e]\n [:o :x :e]\n [:o :e :x]]))", "(= :o (__ [[:x :e :o]\n [:x :o :e]\n [:o :e :x]]))", "(= nil (__ [[:x :o :x]\n [:x :o :x]\n [:o :x :o]]))" ], "times-solved" : 100, "title" : "Analyze a Tic-Tac-Toe Board", "user" : "fotland" },
73 | { "_id" : 74, "description" : "Given a string of comma separated integers, write a function which returns a new comma separated string that only contains the numbers which are perfect squares.", "difficulty" : "Medium", "tags" : [], "tests" : [ "(= (__ \"4,5,6,7,8,9\") \"4,9\")", "(= (__ \"15,16,25,36,37\") \"16,25,36\")" ], "times-solved" : 126, "title" : "Filter Perfect Squares", "user" : "dbyrne" },
74 | { "_id" : 75, "description" : "Two numbers are coprime if their greatest common divisor equals 1. Euler's totient function f(x) is defined as the number of positive integers less than x which are coprime to x. The special case f(1) equals 1. Write a function which calculates Euler's totient function.", "difficulty" : "Medium", "tags" : [], "tests" : [ "(= (__ 1) 1)", "(= (__ 10) (count '(1 3 7 9)) 4)", "(= (__ 40) 16)", "(= (__ 99) 60)" ], "times-solved" : 92, "title" : "Euler's Totient Function", "user" : "dbyrne" },
75 | { "_id" : 76, "description" : "The trampoline function takes a function f and a variable number of parameters. Trampoline calls f with any parameters that were supplied. If f returns a function, trampoline calls that function with no arguments. This is repeated, until the return value is not a function, and then trampoline returns that non-function value. This is useful for implementing mutually recursive algorithms in a way that won't consume the stack.", "difficulty" : "Medium", "tags" : [ "recursion" ], "tests" : [ "(= __\n (letfn\n [(foo [x y] #(bar (conj x y) y))\n (bar [x y] (if (> (last x) 10)\n x\n #(foo x (+ 2 y))))]\n (trampoline foo [] 1)))" ], "times-solved" : 117, "title" : "Intro to Trampoline", "user" : "dbyrne" },
76 | { "_id" : 77, "description" : "Write a function which finds all the anagrams in a vector of words. A word x is an anagram of word y if all the letters in x can be rearranged in a different order to form y. Your function should return a set of sets, where each sub-set is a group of words which are anagrams of each other. Each sub-set should have at least two words. Words without any anagrams should not be included in the result.", "difficulty" : "Medium", "tags" : [], "tests" : [ "(= (__ [\"meat\" \"mat\" \"team\" \"mate\" \"eat\"])\n #{#{\"meat\" \"team\" \"mate\"}})", "(= (__ [\"veer\" \"lake\" \"item\" \"kale\" \"mite\" \"ever\"])\n #{#{\"veer\" \"ever\"} #{\"lake\" \"kale\"} #{\"mite\" \"item\"}})" ], "times-solved" : 96, "title" : "Anagram Finder", "user" : "dbyrne" },
77 | { "_id" : 78, "description" : "Reimplement the function described in \"Intro to Trampoline\".", "difficulty" : "Medium", "restricted" : [ "trampoline" ], "tags" : [ "core-functions" ], "tests" : [ "(= (letfn [(triple [x] #(sub-two (* 3 x)))\n (sub-two [x] #(stop?(- x 2)))\n (stop? [x] (if (> x 50) x #(triple x)))]\n (__ triple 2))\n 82)", "(= (letfn [(my-even? [x] (if (zero? x) true #(my-odd? (dec x))))\n (my-odd? [x] (if (zero? x) false #(my-even? (dec x))))]\n (map (partial __ my-even?) (range 6)))\n [true false true false true false])" ], "times-solved" : 86, "title" : "Reimplement Trampoline", "user" : "dbyrne" },
78 | { "_id" : 79, "description" : "Write a function which calculates the sum of the minimal path through a triangle. The triangle is represented as a collection of vectors. The path should start at the top of the triangle and move to an adjacent number on the next row until the bottom of the triangle is reached.", "difficulty" : "Hard", "restricted" : null, "tags" : [ "graph-theory" ], "tests" : [ "(= 7 (__ '([1]\r\n [2 4]\r\n [5 1 4]\r\n [2 3 4 5]))) ; 1->2->1->3", "(= 20 (__ '([3]\r\n [2 4]\r\n [1 9 3]\r\n [9 9 2 4]\r\n [4 6 6 7 8]\r\n [5 7 3 5 1 4]))) ; 3->4->3->2->7->1" ], "times-solved" : 72, "title" : "Triangle Minimal Path", "user" : "dbyrne" },
79 | { "_id" : 80, "description" : "A number is \"perfect\" if the sum of its divisors equal the number itself. 6 is a perfect number because 1+2+3=6. Write a function which returns true for perfect numbers and false otherwise.", "difficulty" : "Medium", "tags" : [], "tests" : [ "(= (__ 6) true)", "(= (__ 7) false)", "(= (__ 496) true)", "(= (__ 500) false)", "(= (__ 8128) true)" ], "times-solved" : 118, "title" : "Perfect Numbers", "user" : "dbyrne" },
80 | { "_id" : 81, "description" : "Write a function which returns the intersection of two sets. The intersection is the sub-set of items that each set has in common.", "difficulty" : "Easy", "restricted" : [ "intersection" ], "tags" : [ "set-theory" ], "tests" : [ "(= (__ #{0 1 2 3} #{2 3 4 5}) #{2 3})", "(= (__ #{0 1 2} #{3 4 5}) #{})", "(= (__ #{:a :b :c :d} #{:c :e :a :f :d}) #{:a :c :d})" ], "times-solved" : 150, "title" : "Set Intersection", "user" : "dbyrne" },
81 | { "_id" : 82, "description" : "A word chain consists of a set of words ordered so that each word differs by only one letter from the words directly before and after it. The one letter difference can be either an insertion, a deletion, or a substitution. Here is an example word chain:
cat -> cot -> coat -> oat -> hat -> hot -> hog -> dog
Write a function which takes a sequence of words, and returns true if they can be arranged into one continous word chain, and false if they cannot.", "difficulty" : "Hard", "tags" : [ "seqs" ], "tests" : [ "(= true (__ #{\"hat\" \"coat\" \"dog\" \"cat\" \"oat\" \"cot\" \"hot\" \"hog\"}))", "(= false (__ #{\"cot\" \"hot\" \"bat\" \"fat\"}))", "(= false (__ #{\"to\" \"top\" \"stop\" \"tops\" \"toss\"}))", "(= true (__ #{\"spout\" \"do\" \"pot\" \"pout\" \"spot\" \"dot\"}))", "(= true (__ #{\"share\" \"hares\" \"shares\" \"hare\" \"are\"}))", "(= false (__ #{\"share\" \"hares\" \"hare\" \"are\"}))" ], "times-solved" : 48, "title" : "Word Chains", "user" : "dbyrne" },
82 | { "_id" : 83, "description" : "Write a function which takes a variable number of booleans. Your function should return true if some of the parameters are true, but not all of the parameters are true. Otherwise your function should return false.", "difficulty" : "Easy", "tags" : [], "tests" : [ "(= false (__ false false))", "(= true (__ true false))", "(= false (__ true))", "(= true (__ false true false))", "(= false (__ true true true))", "(= true (__ true true true false))" ], "times-solved" : 184, "title" : "A Half-Truth", "user" : "cmeier" },
83 | { "_id" : 84, "description" : "Write a function which generates the transitive closure of a binary relation. The relation will be represented as a set of 2 item vectors.", "difficulty" : "Hard", "tags" : [ "set-theory" ], "tests" : [ "(let [divides #{[8 4] [9 3] [4 2] [27 9]}]\n (= (__ divides) #{[4 2] [8 4] [8 2] [9 3] [27 9] [27 3]}))", "(let [more-legs\n #{[\"cat\" \"man\"] [\"man\" \"snake\"] [\"spider\" \"cat\"]}]\n (= (__ more-legs)\n #{[\"cat\" \"man\"] [\"cat\" \"snake\"] [\"man\" \"snake\"]\n [\"spider\" \"cat\"] [\"spider\" \"man\"] [\"spider\" \"snake\"]}))", "(let [progeny\n #{[\"father\" \"son\"] [\"uncle\" \"cousin\"] [\"son\" \"grandson\"]}]\n (= (__ progeny)\n #{[\"father\" \"son\"] [\"father\" \"grandson\"]\n [\"uncle\" \"cousin\"] [\"son\" \"grandson\"]}))" ], "times-solved" : 57, "title" : "Transitive Closure", "user" : "dbyrne" },
84 | { "_id" : 85, "description" : "Write a function which generates the power set of a given set. The power set of a set x is the set of all subsets of x, including the empty set and x itself.", "difficulty" : "Medium", "restricted" : null, "tags" : [ "set-theory" ], "tests" : [ "(= (__ #{1 :a}) #{#{1 :a} #{:a} #{} #{1}})", "(= (__ #{}) #{#{}})", "(= (__ #{1 2 3})\r\n #{#{} #{1} #{2} #{3} #{1 2} #{1 3} #{2 3} #{1 2 3}})", "(= (count (__ (into #{} (range 10)))) 1024)" ], "times-solved" : 64, "title" : "Power Set", "user" : "peteris" },
85 | { "_id" : 86, "description" : "Happy numbers are positive integers that follow a particular formula: take each individual digit, square it, and then sum the squares to get a new number. Repeat with the new number and eventually, you might get to a number whose squared sum is 1. This is a happy number. An unhappy number (or sad number) is one that loops endlessly. Write a function that determines if a number is happy or not.", "difficulty" : "Medium", "restricted" : null, "tags" : [ "math" ], "tests" : [ "(= (__ 7) true)", "(= (__ 986543210) true)", "(= (__ 2) false)", "(= (__ 3) false)" ], "times-solved" : 94, "title" : "Happy numbers", "user" : "daviddavis" },
86 | { "_id" : 88, "description" : "Write a function which returns the symmetric difference of two sets. The symmetric difference is the set of items belonging to one but not both of the two sets.", "difficulty" : "Easy", "tags" : [ "set-theory" ], "tests" : [ "(= (__ #{1 2 3 4 5 6} #{1 3 5 7}) #{2 4 6 7})", "(= (__ #{:a :b :c} #{}) #{:a :b :c})", "(= (__ #{} #{4 5 6}) #{4 5 6})", "(= (__ #{[1 2] [2 3]} #{[2 3] [3 4]}) #{[1 2] [3 4]})" ], "times-solved" : 107, "title" : "Symmetric Difference", "user" : "dbyrne" },
87 | { "_id" : 89, "description" : "Starting with a graph you must write a function that returns true if it is possible to make a tour of the graph in which every edge is visited exactly once.
The graph is represented by a vector of tuples, where each tuple represents a single edge.
The rules are:
- You can start at any node. - You must visit each edge exactly once.- All edges are undirected.", "difficulty" : "Hard", "restricted" : null, "tags" : [ "graph-theory" ], "tests" : [ "(= true (__ [[:a :b]]))", "(= false (__ [[:a :a] [:b :b]]))", "(= false (__ [[:a :b] [:a :b] [:a :c] [:c :a]\r\n [:a :d] [:b :d] [:c :d]]))", "(= true (__ [[1 2] [2 3] [3 4] [4 1]]))", "(= true (__ [[:a :b] [:a :c] [:c :b] [:a :e]\r\n [:b :e] [:a :d] [:b :d] [:c :e]\r\n [:d :e] [:c :f] [:d :f]]))", "(= false (__ [[1 2] [2 3] [2 4] [2 5]]))" ], "times-solved" : 31, "title" : "Graph Tour", "user" : "lucas1000001" },
88 | { "_id" : 90, "description" : "Write a function which calculates the Cartesian product of two sets.", "difficulty" : "Easy", "restricted" : null, "tags" : [ "set-theory" ], "tests" : [ "(= (__ #{\"ace\" \"king\" \"queen\"} #{\"♠\" \"♥\" \"♦\" \"♣\"})\r\n #{[\"ace\" \"♠\"] [\"ace\" \"♥\"] [\"ace\" \"♦\"] [\"ace\" \"♣\"]\r\n [\"king\" \"♠\"] [\"king\" \"♥\"] [\"king\" \"♦\"] [\"king\" \"♣\"]\r\n [\"queen\" \"♠\"] [\"queen\" \"♥\"] [\"queen\" \"♦\"] [\"queen\" \"♣\"]})", "(= (__ #{1 2 3} #{4 5})\r\n #{[1 4] [2 4] [3 4] [1 5] [2 5] [3 5]})", "(= 300 (count (__ (into #{} (range 10))\r\n (into #{} (range 30)))))" ], "times-solved" : 120, "title" : "Cartesian Product", "user" : "dbyrne" },
89 | { "_id" : 91, "description" : "Given a graph, determine whether the graph is connected. A connected graph is such that a path exists between any two given nodes.
-Your function must return true if the graph is connected and false otherwise.
-You will be given a set of tuples representing the edges of a graph. Each member of a tuple being a vertex/node in the graph.
-Each edge is undirected (can be traversed either direction).\r\n", "difficulty" : "Hard", "restricted" : null, "tags" : [ "graph-theory" ], "tests" : [ "(= true (__ #{[:a :a]}))", "(= true (__ #{[:a :b]}))", "(= false (__ #{[1 2] [2 3] [3 1]\r\n [4 5] [5 6] [6 4]}))", "(= true (__ #{[1 2] [2 3] [3 1]\r\n [4 5] [5 6] [6 4] [3 4]}))", "(= false (__ #{[:a :b] [:b :c] [:c :d]\r\n [:x :y] [:d :a] [:b :e]}))", "(= true (__ #{[:a :b] [:b :c] [:c :d]\r\n [:x :y] [:d :a] [:b :e] [:x :a]}))" ], "times-solved" : 41, "title" : "Graph Connectivity", "user" : "lucas1000001" },
90 | { "_id" : 92, "description" : "Roman numerals are easy to recognize, but not everyone knows all the rules necessary to work with them. Write a function to parse a Roman-numeral string and return the number it represents.\r\n
\r\nYou can assume that the input will be well-formed, in upper-case, and follow the subtractive principle. You don't need to handle any numbers greater than MMMCMXCIX (3999), the largest number representable with ordinary letters.", "difficulty" : "Hard", "restricted" : null, "tags" : [ "strings", "math" ], "tests" : [ "(= 14 (__ \"XIV\"))", "(= 827 (__ \"DCCCXXVII\"))", "(= 3999 (__ \"MMMCMXCIX\"))", "(= 48 (__ \"XLVIII\"))\r\n" ], "times-solved" : 58, "title" : "Read Roman numerals", "user" : "amalloy" },
91 | { "_id" : 93, "description" : "Write a function which flattens any nested combination of sequential things (lists, vectors, etc.), but maintains the lowest level sequential items. The result should be a sequence of sequences with only one level of nesting.", "difficulty" : "Medium", "restricted" : null, "tags" : [ "seqs" ], "tests" : [ "(= (__ [[\"Do\"] [\"Nothing\"]])\r\n [[\"Do\"] [\"Nothing\"]])", "(= (__ [[[[:a :b]]] [[:c :d]] [:e :f]])\r\n [[:a :b] [:c :d] [:e :f]])", "(= (__ '((1 2)((3 4)((((5 6)))))))\r\n '((1 2)(3 4)(5 6)))" ], "times-solved" : 54, "title" : "Partially Flatten a Sequence", "user" : "dbyrne" },
92 | { "_id" : 94, "description" : "The game of life is a cellular automaton devised by mathematician John Conway.
The 'board' consists of both live (#) and dead ( ) cells. Each cell interacts with its eight neighbours (horizontal, vertical, diagonal), and its next state is dependent on the following rules:
1) Any live cell with fewer than two live neighbours dies, as if caused by under-population. 2) Any live cell with two or three live neighbours lives on to the next generation. 3) Any live cell with more than three live neighbours dies, as if by overcrowding. 4) Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
Write a function that accepts a board, and returns a board representing the next generation of cells.", "difficulty" : "Hard", "restricted" : null, "tags" : [ "game" ], "tests" : [ "(= (__ [\" \" \r\n \" ## \"\r\n \" ## \"\r\n \" ## \"\r\n \" ## \"\r\n \" \"])\r\n [\" \" \r\n \" ## \"\r\n \" # \"\r\n \" # \"\r\n \" ## \"\r\n \" \"])", "(= (__ [\" \"\r\n \" \"\r\n \" ### \"\r\n \" \"\r\n \" \"])\r\n [\" \"\r\n \" # \"\r\n \" # \"\r\n \" # \"\r\n \" \"])", "(= (__ [\" \"\r\n \" \"\r\n \" ### \"\r\n \" ### \"\r\n \" \"\r\n \" \"])\r\n [\" \"\r\n \" # \"\r\n \" # # \"\r\n \" # # \"\r\n \" # \"\r\n \" \"])" ], "times-solved" : 34, "title" : "Game of Life", "user" : "lucas1000001" },
93 | { "_id" : 95, "description" : "Write a predicate which checks whether or not a given sequence represents a binary tree. Each node in the tree must have a value, a left child, and a right child.", "difficulty" : "Easy", "restricted" : null, "tags" : [ "trees" ], "tests" : [ "(= (__ '(:a (:b nil nil) nil))\r\n true)", "(= (__ '(:a (:b nil nil)))\r\n false)", "(= (__ [1 nil [2 [3 nil nil] [4 nil nil]]])\r\n true)", "(= (__ [1 [2 nil nil] [3 nil nil] [4 nil nil]])\r\n false)", "(= (__ [1 [2 [3 [4 nil nil] nil] nil] nil])\r\n true)", "(= (__ [1 [2 [3 [4 false nil] nil] nil] nil])\r\n false)", "(= (__ '(:a nil ()))\r\n false)\r\n" ], "times-solved" : 81, "title" : "To Tree, or not to Tree", "user" : "dbyrne" },
94 | { "_id" : 96, "description" : "Let us define a binary tree as \"symmetric\" if the left half of the tree is the mirror image of the right half of the tree. Write a predicate to determine whether or not a given binary tree is symmetric. (see To Tree, or not to Tree for a reminder on the tree representation we're using).", "difficulty" : "Easy", "restricted" : null, "tags" : [ "trees" ], "tests" : [ "(= (__ '(:a (:b nil nil) (:b nil nil))) true)", "(= (__ '(:a (:b nil nil) nil)) false)", "(= (__ '(:a (:b nil nil) (:c nil nil))) false)", "(= (__ [1 [2 nil [3 [4 [5 nil nil] [6 nil nil]] nil]]\r\n [2 [3 nil [4 [6 nil nil] [5 nil nil]]] nil]])\r\n true)", "(= (__ [1 [2 nil [3 [4 [5 nil nil] [6 nil nil]] nil]]\r\n [2 [3 nil [4 [5 nil nil] [6 nil nil]]] nil]])\r\n false)", "(= (__ [1 [2 nil [3 [4 [5 nil nil] [6 nil nil]] nil]]\r\n [2 [3 nil [4 [6 nil nil] nil]] nil]])\r\n false)" ], "times-solved" : 61, "title" : "Beauty is Symmetry", "user" : "dbyrne" },
95 | { "_id" : 97, "description" : "Pascal's triangle is a triangle of numbers computed using the following rules: - The first row is 1.- Each successive row is computed by adding together adjacent numbers in the row above, and adding a 1 to the beginning and end of the row.
Write a function which returns the nth row of Pascal's Triangle.\r\n\r\n\r\n", "difficulty" : "Easy", "restricted" : null, "tags" : [], "tests" : [ "(= (__ 1) [1])", "(= (map __ (range 1 6))\r\n [ [1]\r\n [1 1]\r\n [1 2 1]\r\n [1 3 3 1]\r\n [1 4 6 4 1]])", "(= (__ 11)\r\n [1 10 45 120 210 252 210 120 45 10 1])" ], "times-solved" : 82, "title" : "Pascal's Triangle", "user" : "dbyrne" },
96 | { "_id" : 98, "description" : "A function f defined on a domain D induces an equivalence relation on D, as follows: a is equivalent to b with respect to f if and only if (f a) is equal to (f b). Write a function with arguments f and D that computes the equivalence classes of D with respect to f.", "difficulty" : "Medium", "restricted" : null, "tags" : [], "tests" : [ "(= (__ #(* % %) #{-2 -1 0 1 2})\r\n #{#{0} #{1 -1} #{2 -2}})", "(= (__ #(rem % 3) #{0 1 2 3 4 5 })\r\n #{#{0 3} #{1 4} #{2 5}})", "(= (__ identity #{0 1 2 3 4})\r\n #{#{0} #{1} #{2} #{3} #{4}})", "(= (__ (constantly true) #{0 1 2 3 4})\r\n #{#{0 1 2 3 4}})\r\n" ], "times-solved" : 59, "title" : "Equivalence Classes", "user" : "drcabana" },
97 | { "_id" : 99, "description" : "Write a function which multiplies two numbers and returns the result as a sequence of its digits.", "difficulty" : "Easy", "restricted" : null, "tags" : [ "math", "seqs" ], "tests" : [ "(= (__ 1 1) [1])", "(= (__ 99 9) [8 9 1])", "(= (__ 999 99) [9 8 9 0 1])" ], "times-solved" : 105, "title" : "Product Digits", "user" : "jneira" },
98 | { "_id" : 100, "description" : "Write a function which calculates the least common multiple. Your function should accept a variable number of positive integers or ratios. ", "difficulty" : "Easy", "restricted" : null, "tags" : [ "math" ], "tests" : [ "(== (__ 2 3) 6)", "(== (__ 5 3 7) 105)", "(== (__ 1/3 2/5) 2)", "(== (__ 3/4 1/6) 3/2)", "(== (__ 7 5/7 2 3/5) 210)" ], "times-solved" : 66, "title" : "Least Common Multiple", "user" : "dbyrne" },
99 | { "_id" : 101, "description" : "Given two sequences x and y, calculate the Levenshtein distance of x and y, i. e. the minimum number of edits needed to transform x into y. The allowed edits are:
- insert a single item - delete a single item - replace a single item with another item
WARNING: Some of the test cases may timeout if you write an inefficient solution!", "difficulty" : "Hard", "restricted" : null, "tags" : [ "seqs" ], "tests" : [ "(= (__ \"kitten\" \"sitting\") 3)", "(= (__ \"closure\" \"clojure\") (__ \"clojure\" \"closure\") 1)", "(= (__ \"xyx\" \"xyyyx\") 2)", "(= (__ \"\" \"123456\") 6)", "(= (__ \"Clojure\" \"Clojure\") (__ \"\" \"\") (__ [] []) 0)", "(= (__ [1 2 3 4] [0 2 3 4 5]) 2)", "(= (__ '(:a :b :c :d) '(:a :d)) 2)", "(= (__ \"ttttattttctg\" \"tcaaccctaccat\") 10)", "(= (__ \"gaattctaatctc\" \"caaacaaaaaattt\") 9)" ], "times-solved" : 31, "title" : "Levenshtein Distance", "user" : "patsp" },
100 | { "_id" : 102, "description" : "When working with java, you often need to create an object with fieldsLikeThis, but you'd rather work with a hashmap that has :keys-like-this until it's time to convert. Write a function which takes lower-case hyphen-separated strings and converts them to camel-case strings.", "difficulty" : "Medium", "restricted" : null, "tags" : [ "strings" ], "tests" : [ "(= (__ \"something\") \"something\")", "(= (__ \"multi-word-key\") \"multiWordKey\")", "(= (__ \"leaveMeAlone\") \"leaveMeAlone\")" ], "times-solved" : 65, "title" : "intoCamelCase", "user" : "amalloy" },
101 | { "_id" : 103, "description" : "Given a sequence S consisting of n elements generate all k-combinations of S, i. e. generate all possible sets consisting of k distinct elements taken from S.\r\n\r\nThe number of k-combinations for a sequence is equal to the binomial coefficient.", "difficulty" : "Medium", "restricted" : null, "tags" : [ "seqs", "combinatorics" ], "tests" : [ "(= (__ 1 #{4 5 6}) #{#{4} #{5} #{6}})", "(= (__ 10 #{4 5 6}) #{})", "(= (__ 2 #{0 1 2}) #{#{0 1} #{0 2} #{1 2}})", "(= (__ 3 #{0 1 2 3 4}) #{#{0 1 2} #{0 1 3} #{0 1 4} #{0 2 3} #{0 2 4}\r\n #{0 3 4} #{1 2 3} #{1 2 4} #{1 3 4} #{2 3 4}})", "(= (__ 4 #{[1 2 3] :a \"abc\" \"efg\"}) #{#{[1 2 3] :a \"abc\" \"efg\"}})", "(= (__ 2 #{[1 2 3] :a \"abc\" \"efg\"}) #{#{[1 2 3] :a} #{[1 2 3] \"abc\"} #{[1 2 3] \"efg\"}\r\n #{:a \"abc\"} #{:a \"efg\"} #{\"abc\" \"efg\"}})" ], "times-solved" : 30, "title" : "Generating k-combinations", "user" : "patsp" },
102 | { "_id" : 104, "description" : "This is the inverse of Problem 92, but much easier. Given an integer smaller than 4000, return the corresponding roman numeral in uppercase, adhering to the subtractive principle.", "difficulty" : "Medium", "restricted" : null, "tags" : [ "strings", "math" ], "tests" : [ "(= \"I\" (__ 1))", "(= \"XXX\" (__ 30))", "(= \"IV\" (__ 4))", "(= \"CXL\" (__ 140))", "(= \"DCCCXXVII\" (__ 827))", "(= \"MMMCMXCIX\" (__ 3999))", "(= \"XLVIII\" (__ 48))" ], "times-solved" : 33, "title" : "Write Roman Numerals", "user" : "0x89" },
103 | { "_id" : 105, "description" : "Given an input sequence of keywords and numbers, create a map such that each key in the map is a keyword, and the value is a sequence of all the numbers (if any) between it and the next keyword in the sequence.", "difficulty" : "Medium", "restricted" : null, "tags" : [ "maps", "seqs" ], "tests" : [ "(= {} (__ []))", "(= {:a [1]} (__ [:a 1]))", "(= {:a [1], :b [2]} (__ [:a 1, :b 2]))", "(= {:a [1 2 3], :b [], :c [4]} (__ [:a 1 2 3 :b :c 4]))" ], "times-solved" : 40, "title" : "Identify keys and values", "user" : "amalloy" },
104 | { "_id" : 106, "description" : "Given a pair of numbers, the start and end point, find a path between the two using only three possible operations:
\r\n
double
\r\n
halve (odd numbers cannot be halved)
\r\n
add 2
\r\n\r\nFind the shortest path through the \"maze\". Because there are multiple shortest paths, you must return the length of the shortest path, not the path itself.", "difficulty" : "Hard", "restricted" : null, "tags" : [ "numbers" ], "tests" : [ "(= 1 (__ 1 1)) ; 1", "(= 3 (__ 3 12)) ; 3 6 12", "(= 3 (__ 12 3)) ; 12 6 3", "(= 3 (__ 5 9)) ; 5 7 9", "(= 9 (__ 9 2)) ; 9 18 20 10 12 6 8 4 2", "(= 5 (__ 9 12)) ; 9 11 22 24 12\r\n" ], "times-solved" : 33, "title" : "Number Maze", "user" : "lucas1000001" },
105 | { "_id" : 107, "description" : "
Lexical scope and first-class functions are two of the most basic building blocks of a functional language like Clojure. When you combine the two together, you get something very powerful called lexical closures. With these, you can exercise a great deal of control over the lifetime of your local bindings, saving their values for use later, long after the code you're running now has finished.
\r\n\r\n
It can be hard to follow in the abstract, so let's build a simple closure. Given a positive integer n, return a function (f x) which computes xn. Observe that the effect of this is to preserve the value of n for use outside the scope in which it is defined.
Given any number of sequences, each sorted from smallest to largest, find the smallest single number which appears in all of the sequences. The sequences may be infinite, so be careful to search lazily.
Write a function that returns a lazy sequence of \"pronunciations\" of a sequence of numbers. A pronunciation of each element in the sequence consists of the number of repeating identical numbers and the number itself. For example, [1 1] is pronounced as [2 1] (\"two ones\"), which in turn is pronounced as [1 2 1 1] (\"one two, one one\").
Your function should accept an initial sequence of numbers, and return an infinite lazy sequence of pronunciations, each element being a pronunciation of the previous element.
", "difficulty" : "Medium", "restricted" : null, "tags" : [ "seqs" ], "tests" : [ "(= [[1 1] [2 1] [1 2 1 1]] (take 3 (__ [1])))", "(= [3 1 2 4] (first (__ [1 1 1 4 4])))", "(= [1 1 1 3 2 1 3 2 1 1] (nth (__ [1]) 6))", "(= 338 (count (nth (__ [3 2]) 15)))\r\n" ], "times-solved" : 34, "title" : "Sequence of pronunciations", "user" : "mlni" },
109 | { "_id" : 111, "description" : "Write a function that takes a string and a partially-filled crossword puzzle board, and determines if the input string can be legally placed onto the board.\r\n\r\n\r\nThe crossword puzzle board consists of a collection of partially-filled rows. Empty spaces are denoted with an underscore (_), unusable spaces are denoted with a hash symbol (#), and pre-filled spaces have a character in place; the whitespace characters are for legibility and should be ignored.\r\n\r\nFor a word to be legally placed on the board:\r\n\r\n- It may use empty spaces (underscores)\r\n\r\n- It may use but must not conflict with any pre-filled characters.\r\n\r\n- It must not use any unusable spaces (hashes).\r\n\r\n- There must be no empty spaces (underscores) or extra characters before or after the word (the word may be bound by unusable spaces though).\r\n\r\n- Characters are not case-sensitive. \r\n\r\n- Words may be placed vertically (proceeding top-down only), or horizontally (proceeding left-right only).", "difficulty" : "Hard", "restricted" : null, "tags" : [ "game" ], "tests" : [ "(= true (__ \"the\" [\"_ # _ _ e\"]))", "(= false (__ \"the\" [\"c _ _ _\"\r\n \"d _ # e\"\r\n \"r y _ _\"]))", "(= true (__ \"joy\" [\"c _ _ _\"\r\n \"d _ # e\"\r\n \"r y _ _\"]))", "(= false (__ \"joy\" [\"c o n j\"\r\n \"_ _ y _\"\r\n \"r _ _ #\"]))", "(= true (__ \"clojure\" [\"_ _ _ # j o y\"\r\n \"_ _ o _ _ _ _\"\r\n \"_ _ f _ # _ _\"]))\r\n" ], "times-solved" : 15, "title" : "Crossword puzzle", "user" : "mlni" },
110 | { "_id" : 112, "description" : "Create a function which takes an integer and a nested collection of integers as arguments. Analyze the elements of the input collection and return a sequence which maintains the nested structure, and which includes all elements starting from the head whose sum is less than or equal to the input integer.", "difficulty" : "Medium", "restricted" : null, "tags" : [ "seqs" ], "tests" : [ "(= (__ 10 [1 2 [3 [4 5] 6] 7])\r\n '(1 2 (3 (4))))", "(= (__ 30 [1 2 [3 [4 [5 [6 [7 8]] 9]] 10] 11])\r\n '(1 2 (3 (4 (5 (6 (7)))))))", "(= (__ 9 (range))\r\n '(0 1 2 3))", "(= (__ 1 [[[[[1]]]]])\r\n '(((((1))))))", "(= (__ 0 [1 2 [3 [4 5] 6] 7])\r\n '())", "(= (__ 0 [0 0 [0 [0]]])\r\n '(0 0 (0 (0))))", "(= (__ 1 [-10 [1 [2 3 [4 5 [6 7 [8]]]]]])\r\n '(-10 (1 (2 3 (4)))))" ], "times-solved" : 17, "title" : "Sequs Horribilis", "user" : "ghoseb" },
111 | { "_id" : 113, "description" : "Write a function that takes a variable number of integer arguments. If the output is coerced into a string, it should return a comma (and space) separated list of the inputs sorted smallest to largest. If the output is coerced into a sequence, it should return a seq of unique input elements in the same order as they were entered.", "difficulty" : "Hard", "restricted" : [ "proxy" ], "tags" : [ "types" ], "tests" : [ "(= \"1, 2, 3\" (str (__ 2 1 3)))", "(= '(2 1 3) (seq (__ 2 1 3)))", "(= '(2 1 3) (seq (__ 2 1 3 3 1 2)))", "(= '(1) (seq (apply __ (repeat 5 1))))", "(= \"1, 1, 1, 1, 1\" (str (apply __ (repeat 5 1))))", "(and (= nil (seq (__)))\r\n (= \"\" (str (__))))" ], "times-solved" : 20, "title" : "Making Data Dance", "user" : "amcnamara" },
112 | { "_id" : 114, "description" : "
take-while\r\nis great for filtering sequences, but it limited: you can only examine\r\na single item of the sequence at a time. What if you need to keep\r\ntrack of some state as you go over the sequence?
\r\n\r\n
Write a function which accepts an integer n, a predicate p, and a sequence. It should return a lazy sequence of items in the list up to, but not including, the nth item that satisfies the predicate.
", "difficulty" : "Medium", "restricted" : null, "tags" : [ "seqs", "higher-order-functions" ], "tests" : [ "(= [2 3 5 7 11 13]\r\n (__ 4 #(= 2 (mod % 3))\r\n [2 3 5 7 11 13 17 19 23]))", "(= [\"this\" \"is\" \"a\" \"sentence\"]\r\n (__ 3 #(some #{\\i} %)\r\n [\"this\" \"is\" \"a\" \"sentence\" \"i\" \"wrote\"]))", "(= [\"this\" \"is\"]\r\n (__ 1 #{\"a\"}\r\n [\"this\" \"is\" \"a\" \"sentence\" \"i\" \"wrote\"]))" ], "times-solved" : 24, "title" : "Global take-while", "user" : "amalloy" },
113 | { "_id" : 115, "description" : "A balanced number is one whose component digits have the same sum on the left and right halves of the number. Write a function which accepts an integer n, and returns true iff n is balanced.", "difficulty" : "Medium", "restricted" : null, "tags" : [ "math" ], "tests" : [ "(= true (__ 11))", "(= true (__ 121))", "(= false (__ 123))", "(= true (__ 0))", "(= false (__ 88099))", "(= true (__ 89098))", "(= true (__ 89089))", "(= (take 20 (filter __ (range)))\r\n [0 1 2 3 4 5 6 7 8 9 11 22 33 44 55 66 77 88 99 101]) " ], "times-solved" : 20, "title" : "The Balance of N", "user" : "amcnamara" },
114 | { "_id" : 116, "restricted" : null, "title" : "Prime Sandwich", "times-solved" : 0, "difficulty" : "Medium", "tests" : [ "(= false (__ 4))", "(= true (__ 563))", "(= 1103 (nth (filter __ (range)) 15))" ], "user" : "amcnamara", "description" : "A balanced prime is a prime number which is also the mean of the primes directly before and after it in the sequence of valid primes. Create a function which takes an integer n, and returns true iff it is a balanced prime.", "tags" : [ "math" ] },
115 | { "_id" : 117, "description" : "A mad scientist with tenure has created an experiment tracking mice in a maze. Several mazes have been randomly generated, and you've been tasked with writing a program to determine the mazes in which it's possible for the mouse to reach the cheesy endpoint. Write a function which accepts a maze in the form of a collection of rows, each row is a string where:\r\n
\r\n
spaces represent areas where the mouse can walk freely
\r\n
hashes (#) represent walls where the mouse can not walk
\r\n
M represents the mouse's starting point
\r\n
C represents the cheese which the mouse must reach
Map is one of the core elements of a functional programming language. Given a function f and an input sequence s, return a lazy sequence of (f x) for each element x in s.", "difficulty" : "Easy", "restricted" : [ "map", "map-indexed", "mapcat", "for" ], "tags" : [ "core-seqs" ], "tests" : [ "(= [3 4 5 6 7]\r\n (__ inc [2 3 4 5 6]))", "(= (repeat 10 nil)\r\n (__ (fn [_] nil) (range 10)))", "(= [1000000 1000001]\r\n (->> (__ inc (range))\r\n (drop (dec 1000000))\r\n (take 2)))" ], "times-solved" : 0, "title" : "Re-implement Map", "user" : "semisight" },
117 | { "_id" : 119, "description" : "
As in Problem 73, a tic-tac-toe board is represented by a two dimensional vector. X is represented by :x, O is represented by :o, and empty is represented by :e. Create a function that accepts a game piece and board as arguments, and returns a set (possibly empty) of all valid board placements of the game piece which would result in an immediate win.
\r\n\r\n
Board coordinates should be as in calls to get-in. For example, [0 1] is the topmost row, center position.
", "difficulty" : "Hard", "restricted" : null, "tags" : [ "game" ], "tests" : [ "(= (__ :x [[:o :e :e] \r\n [:o :x :o] \r\n [:x :x :e]])\r\n #{[2 2] [0 1] [0 2]})", "(= (__ :x [[:x :o :o] \r\n [:x :x :e] \r\n [:e :o :e]])\r\n #{[2 2] [1 2] [2 0]})", "(= (__ :x [[:x :e :x] \r\n [:o :x :o] \r\n [:e :o :e]])\r\n #{[2 2] [0 1] [2 0]})", "(= (__ :x [[:x :x :o] \r\n [:e :e :e] \r\n [:e :e :e]])\r\n #{})", "(= (__ :o [[:x :x :o] \r\n [:o :e :o] \r\n [:x :e :e]])\r\n #{[2 2] [1 1]})" ], "times-solved" : 8, "title" : "Win at Tic-Tac-Toe", "user" : "shockbob" },
118 | { "_id" : 120, "description" : "Write a function which takes a collection of integers as an argument. Return the count of how many elements are smaller than the sum of their squared component digits. For example: 10 is larger than 1 squared plus 0 squared; whereas 15 is smaller than 1 squared plus 5 squared.", "difficulty" : "Easy", "restricted" : null, "tags" : [ "math" ], "tests" : [ "(= 8 (__ (range 10)))", "(= 19 (__ (range 30)))", "(= 50 (__ (range 100)))", "(= 50 (__ (range 1000)))" ], "times-solved" : 0, "title" : "Sum of square of digits", "user" : "danilo" },
119 | { "_id" : 121, "description" : "\t Given a mathematical formula in prefix notation, return a function that calculates\r\n\t the value of the formula.\r\n\t The formula can contain nested calculations using the four basic\r\n\t mathematical operators, numeric constants, and symbols representing variables.\r\n\t The returned function has to accept a single parameter containing the map\r\n\t of variable names to their values.\r\n", "difficulty" : "Medium", "restricted" : [ "eval", "resolve" ], "tags" : [ "functions" ], "tests" : [ "(= 2 ((__ '(/ a b))\r\n '{b 8 a 16}))", "(= 8 ((__ '(+ a b 2))\r\n '{a 2 b 4}))", "(= [6 0 -4]\r\n (map (__ '(* (+ 2 a)\r\n \t (- 10 b)))\r\n\t '[{a 1 b 8}\r\n\t {b 5 a -2}\r\n\t {a 2 b 11}]))", "(= 1 ((__ '(/ (+ x 2)\r\n (* 3 (+ y 1))))\r\n '{x 4 y 1}))\r\n" ], "title" : "Universal Computation Engine", "user" : "mlni" },
120 | { "_id" : 124, "description" : "
Reversi is normally played on an 8 by 8 board. In this problem, a 4 by 4 board is represented as a two-dimensional vector with black, white, and empty pieces represented by 'b, 'w, and 'e, respectively. Create a function that accepts a game board and color as arguments, and returns a map of legal moves for that color. Each key should be the coordinates of a legal move, and its value a set of the coordinates of the pieces flipped by that move.
\r\n\r\n
Board coordinates should be as in calls to get-in. For example, [0 1] is the topmost row, second column from the left.
", "difficulty" : "Hard", "restricted" : null, "tags" : [ "game" ], "tests" : [ "(= {[1 3] #{[1 2]}, [0 2] #{[1 2]}, [3 1] #{[2 1]}, [2 0] #{[2 1]}}\r\n (__ '[[e e e e]\r\n [e w b e]\r\n [e b w e]\r\n [e e e e]] 'w))", "(= {[3 2] #{[2 2]}, [3 0] #{[2 1]}, [1 0] #{[1 1]}}\r\n (__ '[[e e e e]\r\n [e w b e]\r\n [w w w e]\r\n [e e e e]] 'b))", "(= {[0 3] #{[1 2]}, [1 3] #{[1 2]}, [3 3] #{[2 2]}, [2 3] #{[2 2]}}\r\n (__ '[[e e e e]\r\n [e w b e]\r\n [w w b e]\r\n [e e b e]] 'w))", "(= {[0 3] #{[2 1] [1 2]}, [1 3] #{[1 2]}, [2 3] #{[2 1] [2 2]}}\r\n (__ '[[e e w e]\r\n [b b w e]\r\n [b w w e]\r\n [b w w w]] 'b))\r\n" ], "title" : "Analyze Reversi", "user" : "shockbob" },
121 | { "_id" : 125, "description" : "Create a function of no arguments which returns a string that is an exact copy of the function itself.\r\n
\r\nHint: read this if you get stuck (this question is harder than it first appears); but it's worth the effort to solve it independently if you can!\r\n
\r\nFun fact: Gus is the name of the 4Clojure dragon.", "difficulty" : "Hard", "restricted" : null, "tags" : [ "logic", "fun", "brain-teaser" ], "tests" : [ "(= (str '__) (__))" ], "title" : "Gus' Quinundrum", "user" : "amcnamara" },
122 | { "_id" : 126, "description" : "Enter a value which satisfies the following:", "difficulty" : "Easy", "restricted" : null, "tags" : [ "fun", "brain-teaser" ], "tests" : [ "(let [x __]\r\n (and (= (class x) x) x))" ], "title" : "Through the Looking Class", "user" : "amcnamara" },
123 | { "_id" : 127, "description" : "Everyone loves triangles, and it's easy to understand why—they're so wonderfully symmetric (except scalenes, they suck).\r\n
\r\nYour passion for triangles has led you to become a miner (and part-time Clojure programmer) where you work all day to chip out isosceles-shaped minerals from rocks gathered in a nearby open-pit mine. There are too many rocks coming from the mine to harvest them all so you've been tasked with writing a program to analyze the mineral patterns of each rock, and determine which rocks have the biggest minerals.\r\n
\r\nSomeone has already written a computer-vision system for the mine. It images each rock as it comes into the processing centre and creates a cross-sectional bitmap of mineral (1) and rock (0) concentrations for each one.\r\n
\r\nYou must now create a function which accepts a collection of integers, each integer when read in base-2 gives the bit-representation of the rock (again, 1s are mineral and 0s are worthless scalene-like rock). You must return the cross-sectional area of the largest harvestable mineral from the input rock, as follows:\r\n \r\n
\r\n
The minerals only have smooth faces when sheared vertically or horizontally from the rock's cross-section
\r\n
The mine is only concerned with harvesting isosceles triangles (such that one or two sides can be sheared)
\r\n
If only one face of the mineral is sheared, its opposing vertex must be a point (ie. the smooth face must be of odd length), and its two equal-length sides must intersect the shear face at 45° (ie. those sides must cut even-diagonally)
\r\n
The harvested mineral may not contain any traces of rock
\r\n
The mineral may lie in any orientation in the plane
\r\n
Area should be calculated as the sum of 1s that comprise the mineral
\r\n
Minerals must have a minimum of three measures of area to be harvested
\r\n
If no minerals can be harvested from the rock, your function should return nil
A standard American deck of playing cards has four suits - spades, hearts, diamonds, and clubs - and thirteen cards in each suit. Two is the lowest rank, followed by other integers up to ten; then the jack, queen, king, and ace.
\r\n\r\n
It's convenient for humans to represent these cards as suit/rank pairs, such as H5 or DQ: the heart five and diamond queen respectively. But these forms are not convenient for programmers, so to write a card game you need some way to parse an input string into meaningful components. For purposes of determining rank, we will define the cards to be valued from 0 (the two) to 12 (the ace)
\r\n\r\n
Write a function which converts (for example) the string \"SJ\" into a map of {:suit :spade, :rank 9}. A ten will always be represented with the single character \"T\", rather than the two characters \"10\".
", "difficulty" : "Easy", "restricted" : null, "tags" : [ "strings", "game" ], "tests" : [ "(= {:suit :diamond :rank 10} (__ \"DQ\"))", "(= {:suit :heart :rank 3} (__ \"H5\"))", "(= {:suit :club :rank 12} (__ \"CA\"))", "(= (range 13) (map (comp :rank __ str)\r\n '[S2 S3 S4 S5 S6 S7\r\n S8 S9 ST SJ SQ SK SA]))" ], "title" : "Recognize Playing Cards", "user" : "amalloy" },
125 | { "_id" : 130, "description" : "Every node of a tree is connected to each of its children as\r\nwell as its parent. One can imagine grabbing one node of\r\na tree and dragging it up to the root position, leaving all\r\nconnections intact. For example, below on the left is\r\na binary tree. By pulling the \"c\" node up to the root, we\r\nobtain the tree on the right.\r\n \r\n\r\n \r\nNote it is no longer binary as \"c\" had three connections\r\ntotal -- two children and one parent.\r\n\r\nEach node is represented as a vector, which always has at\r\nleast one element giving the name of the node as a symbol.\r\nSubsequent items in the vector represent the children of the\r\nnode. Because the children are ordered it's important that\r\nthe tree you return keeps the children of each node in order\r\nand that the old parent node, if any, is appended on the\r\nright.\r\n\r\nYour function will be given two args -- the name of the node\r\nthat should become the new root, and the tree to transform.\r\n", "difficulty" : "Hard", "restricted" : null, "tags" : [ "tree" ], "tests" : [ "(= '(n)\r\n (__ 'n '(n)))", "(= '(a (t (e)))\r\n (__ 'a '(t (e) (a))))", "(= '(e (t (a)))\r\n (__ 'e '(a (t (e)))))", "(= '(a (b (c)))\r\n (__ 'a '(c (b (a)))))", "(= '(d \r\n (b\r\n (c)\r\n (e)\r\n (a \r\n (f \r\n (g) \r\n (h)))))\r\n (__ 'd '(a\r\n (b \r\n (c) \r\n (d) \r\n (e))\r\n (f \r\n (g)\r\n (h)))))", "(= '(c \r\n (d) \r\n (e) \r\n (b\r\n (f \r\n (g) \r\n (h))\r\n (a\r\n (i\r\n (j\r\n (k)\r\n (l))\r\n (m\r\n (n)\r\n (o))))))\r\n (__ 'c '(a\r\n (b\r\n (c\r\n (d)\r\n (e))\r\n (f\r\n (g)\r\n (h)))\r\n (i\r\n (j\r\n (k)\r\n (l))\r\n (m\r\n (n)\r\n (o))))))\r\n" ], "title" : "Tree reparenting", "user" : "chouser" },
126 | { "_id" : 131, "description" : "Given a variable number of sets of integers, create a function which returns true iff all of the sets have a non-empty subset with an equivalent summation.", "difficulty" : "Medium", "restricted" : null, "tags" : [ "math" ], "tests" : [ "(= true (__ #{-1 1 99} \r\n #{-2 2 888}\r\n #{-3 3 7777})) ; ex. all sets have a subset which sums to zero", "(= false (__ #{1}\r\n #{2}\r\n #{3}\r\n #{4}))", "(= true (__ #{1}))", "(= false (__ #{1 -3 51 9} \r\n #{0} \r\n #{9 2 81 33}))", "(= true (__ #{1 3 5}\r\n #{9 11 4}\r\n #{-3 12 3}\r\n #{-3 4 -2 10}))", "(= false (__ #{-1 -2 -3 -4 -5 -6}\r\n #{1 2 3 4 5 6 7 8 9}))", "(= true (__ #{1 3 5 7}\r\n #{2 4 6 8}))", "(= true (__ #{-1 3 -5 7 -9 11 -13 15}\r\n #{1 -3 5 -7 9 -11 13 -15}\r\n #{1 -1 2 -2 4 -4 8 -8}))", "(= true (__ #{-10 9 -8 7 -6 5 -4 3 -2 1}\r\n #{10 -9 8 -7 6 -5 4 -3 2 -1}))" ], "title" : "Sum Some Set Subsets", "user" : "amcnamara" },
127 | { "_id" : 132, "description" : "Write a function that takes a two-argument predicate, a value, and a collection; and returns a new collection where the value is inserted between every two items that satisfy the predicate.", "difficulty" : "Medium", "restricted" : null, "tags" : [ "seqs", "core-functions" ], "tests" : [ "(= '(1 :less 6 :less 7 4 3) (__ < :less [1 6 7 4 3]))", "(= '(2) (__ > :more [2]))", "(= [0 1 :x 2 :x 3 :x 4] (__ #(and (pos? %) (< % %2)) :x (range 5)))", "(empty? (__ > :more ()))", "(= [0 1 :same 1 2 3 :same 5 8 13 :same 21]\r\n (take 12 (->> [0 1]\r\n (iterate (fn [[a b]] [b (+ a b)]))\r\n (map first) ; fibonacci numbers\r\n (__ (fn [a b] ; both even or both odd\r\n (= (mod a 2) (mod b 2)))\r\n :same))))" ], "title" : "Insert between two items", "user" : "srid" },
128 | { "_id" : 134, "description" : "Write a function which, given a key and map, returns true iff the map contains an entry with that key and its value is nil.", "difficulty" : "Elementary", "restricted" : null, "tags" : [ "maps" ], "tests" : [ "(true? (__ :a {:a nil :b 2}))", "(false? (__ :b {:a nil :b 2}))", "(false? (__ :c {:a nil :b 2}))" ], "title" : "A nil key", "user" : "goranjovic" },
129 | { "_id" : 135, "description" : "Your friend Joe is always whining about Lisps using the prefix notation for math. Show him how you could easily write a function that does math using the infix notation. Is your favorite language that flexible, Joe?\r\n\r\nWrite a function that accepts a variable length mathematical expression consisting of numbers and the operations +, -, *, and /. Assume a simple calculator that does not do precedence and instead just calculates left to right.", "difficulty" : "Easy", "restricted" : null, "tags" : [ "higher-order-functions", "math" ], "tests" : [ "(= 7 (__ 2 + 5))", "(= 42 (__ 38 + 48 - 2 / 2))", "(= 8 (__ 10 / 2 - 1 * 2))", "(= 72 (__ 20 / 2 + 2 + 4 + 8 - 6 - 10 * 9))" ], "title" : "Infix Calculator", "user" : "fdaoud" },
130 | { "_id" : 137, "description" : "Write a function which returns a sequence of digits of a non-negative number (first argument) in numerical system with an arbitrary base (second argument). Digits should be represented with their integer values, e.g. 15 would be [1 5] in base 10, [1 1 1 1] in base 2 and [15] in base 16. ", "difficulty" : "Medium", "restricted" : null, "tags" : [ "math" ], "tests" : [ "(= [1 2 3 4 5 0 1] (__ 1234501 10))", "(= [0] (__ 0 11))", "(= [1 0 0 1] (__ 9 2))", "(= [1 0] (let [n (rand-int 100000)](__ n n)))", "(= [16 18 5 24 15 1] (__ Integer/MAX_VALUE 42))" ], "title" : "Digits and bases", "user" : "goranjovic" },
131 | { "_id" : 138, "description" : "Create a function of two integer arguments: the start and end, respectively. You must create a vector of strings which renders a 45° rotated square of integers which are successive squares from the start point up to and including the end point. If a number comprises multiple digits, wrap them around the shape individually. If there are not enough digits to complete the shape, fill in the rest with asterisk characters. The direction of the drawing should be clockwise, starting from the center of the shape and working outwards, with the initial direction being down and to the right.", "difficulty" : "Hard", "restricted" : null, "tags" : [ "data-juggling" ], "tests" : [ "(= (__ 2 2) [\"2\"])", "(= (__ 2 4) [\" 2 \"\r\n \"* 4\"\r\n \" * \"])", "(= (__ 3 81) [\" 3 \"\r\n \"1 9\"\r\n \" 8 \"])", "(= (__ 4 20) [\" 4 \"\r\n \"* 1\"\r\n \" 6 \"])", "(= (__ 2 256) [\" 6 \"\r\n \" 5 * \"\r\n \"2 2 *\"\r\n \" 6 4 \"\r\n \" 1 \"])", "(= (__ 10 10000) [\" 0 \"\r\n \" 1 0 \"\r\n \" 0 1 0 \"\r\n \"* 0 0 0\"\r\n \" * 1 * \"\r\n \" * * \"\r\n \" * \"])" ], "title" : "Squares Squared", "user" : "amcnamara" },
132 | { "_id" : 140, "description" : "Create a function which accepts as input a boolean algebra function in the form of a set of sets, where the inner sets are collections of symbols corresponding to the input boolean variables which satisfy the function (the inputs of the inner sets are conjoint, and the sets themselves are disjoint... also known as canonical minterms). Note: capitalized symbols represent truth, and lower-case symbols represent negation of the inputs. Your function must return the minimal function which is logically equivalent to the input.\r\n\r\nPS — You may want to give this a read before proceeding: K-Maps", "difficulty" : "Hard", "restricted" : null, "tags" : [ "math", "circuit-design" ], "tests" : [ "(= (__ #{#{'a 'B 'C 'd}\r\n #{'A 'b 'c 'd}\r\n #{'A 'b 'c 'D}\r\n #{'A 'b 'C 'd}\r\n #{'A 'b 'C 'D}\r\n #{'A 'B 'c 'd}\r\n #{'A 'B 'c 'D}\r\n #{'A 'B 'C 'd}})\r\n #{#{'A 'c} \r\n #{'A 'b}\r\n #{'B 'C 'd}})", "(= (__ #{#{'A 'B 'C 'D}\r\n #{'A 'B 'C 'd}})\r\n #{#{'A 'B 'C}})", "(= (__ #{#{'a 'b 'c 'd}\r\n #{'a 'B 'c 'd}\r\n #{'a 'b 'c 'D}\r\n #{'a 'B 'c 'D}\r\n #{'A 'B 'C 'd}\r\n #{'A 'B 'C 'D}\r\n #{'A 'b 'C 'd}\r\n #{'A 'b 'C 'D}})\r\n #{#{'a 'c}\r\n #{'A 'C}})", "(= (__ #{#{'a 'b 'c} \r\n #{'a 'B 'c}\r\n #{'a 'b 'C}\r\n #{'a 'B 'C}})\r\n #{#{'a}})", "(= (__ #{#{'a 'B 'c 'd}\r\n #{'A 'B 'c 'D}\r\n #{'A 'b 'C 'D}\r\n #{'a 'b 'c 'D}\r\n #{'a 'B 'C 'D}\r\n #{'A 'B 'C 'd}})\r\n #{#{'a 'B 'c 'd}\r\n #{'A 'B 'c 'D}\r\n #{'A 'b 'C 'D}\r\n #{'a 'b 'c 'D}\r\n #{'a 'B 'C 'D}\r\n #{'A 'B 'C 'd}})", "(= (__ #{#{'a 'b 'c 'd}\r\n #{'a 'B 'c 'd}\r\n #{'A 'B 'c 'd}\r\n #{'a 'b 'c 'D}\r\n #{'a 'B 'c 'D}\r\n #{'A 'B 'c 'D}})\r\n #{#{'a 'c}\r\n #{'B 'c}})", "(= (__ #{#{'a 'B 'c 'd}\r\n #{'A 'B 'c 'd}\r\n #{'a 'b 'c 'D}\r\n #{'a 'b 'C 'D}\r\n #{'A 'b 'c 'D}\r\n #{'A 'b 'C 'D}\r\n #{'a 'B 'C 'd}\r\n #{'A 'B 'C 'd}})\r\n #{#{'B 'd}\r\n #{'b 'D}})", "(= (__ #{#{'a 'b 'c 'd}\r\n #{'A 'b 'c 'd}\r\n #{'a 'B 'c 'D}\r\n #{'A 'B 'c 'D}\r\n #{'a 'B 'C 'D}\r\n #{'A 'B 'C 'D}\r\n #{'a 'b 'C 'd}\r\n #{'A 'b 'C 'd}})\r\n #{#{'B 'D}\r\n #{'b 'd}})" ], "title" : "Veitch, Please!", "user" : "amcnamara" },
133 | { "_id" : 141, "description" : "
\r\n In trick-taking\r\n card games such as bridge, spades, or hearts, cards are played\r\n in groups known as \"tricks\" - each player plays a single card, in\r\n order; the first player is said to \"lead\" to the trick. After all\r\n players have played, one card is said to have \"won\" the trick. How\r\n the winner is determined will vary by game, but generally the winner\r\n is the highest card played in the suit that was\r\n led. Sometimes (again varying by game), a particular suit will\r\n be designated \"trump\", meaning that its cards are more powerful than\r\n any others: if there is a trump suit, and any trumps are played,\r\n then the highest trump wins regardless of what was led.\r\n
\r\n
\r\n Your goal is to devise a function that can determine which of a\r\n number of cards has won a trick. You should accept a trump suit, and\r\n return a function winner. Winner will be called on a\r\n sequence of cards, and should return the one which wins the\r\n trick. Cards will be represented in the format returned\r\n by Problem 128, Recognize Playing Cards:\r\n a hash-map of :suit and a\r\n numeric :rank. Cards with a larger rank are stronger.\r\n
", "difficulty" : "Medium", "restricted" : null, "tags" : [ "game", "cards" ], "tests" : [ "(let [notrump (__ nil)]\r\n (and (= {:suit :club :rank 9} (notrump [{:suit :club :rank 4}\r\n {:suit :club :rank 9}]))\r\n (= {:suit :spade :rank 2} (notrump [{:suit :spade :rank 2}\r\n {:suit :club :rank 10}]))))", "(= {:suit :club :rank 10} ((__ :club) [{:suit :spade :rank 2}\r\n {:suit :club :rank 10}]))", "(= {:suit :heart :rank 8}\r\n ((__ :heart) [{:suit :heart :rank 6} {:suit :heart :rank 8}\r\n {:suit :diamond :rank 10} {:suit :heart :rank 4}]))" ], "title" : "Tricky card games", "user" : "amalloy" },
134 | { "_id" : 143, "description" : "Create a function that computes the dot product of two sequences. You may assume that the vectors will have the same length.", "difficulty" : "Easy", "restricted" : null, "tags" : [ "seqs", "math" ], "tests" : [ "(= 0 (__ [0 1 0] [1 0 0]))", "(= 3 (__ [1 1 1] [1 1 1]))", "(= 32 (__ [1 2 3] [4 5 6]))", "(= 256 (__ [2 5 6] [100 10 1]))" ], "title" : "dot product", "user" : "bloop" },
135 | { "_id" : 144, "description" : "Write an oscillating iterate: a function that takes an initial value and a variable number of functions. It should return a lazy sequence of the functions applied to the value in order, restarting from the first function after it hits the end.", "difficulty" : "Medium", "restricted" : null, "tags" : [ "sequences" ], "tests" : [ "(= (take 3 (__ 3.14 int double)) [3.14 3 3.0])", "(= (take 5 (__ 3 #(- % 3) #(+ 5 %))) [3 0 5 2 7])", "(= (take 12 (__ 0 inc dec inc dec inc)) [0 1 0 1 0 1 2 1 2 1 2 3])\r\n" ], "title" : "Oscilrate", "user" : "bloop" },
136 | { "_id" : 145, "description" : "Clojure's for macro is a tremendously versatile mechanism for producing a sequence based on some other sequence(s). It can take some time to understand how to use it properly, but that investment will be paid back with clear, concise sequence-wrangling later. With that in mind, read over these for expressions and try to see how each of them produces the same result.", "difficulty" : "Elementary", "restricted" : null, "tags" : [ "core-functions", "seqs" ], "tests" : [ "(= __ (for [x (range 40)\r\n :when (= 1 (rem x 4))]\r\n x))", "(= __ (for [x (iterate #(+ 4 %) 0)\r\n :let [z (inc x)]\r\n :while (< z 40)]\r\n z))", "(= __ (for [[x y] (partition 2 (range 20))]\r\n (+ x y)))" ], "title" : "For the win", "user" : "amalloy" },
137 | { "_id" : 146, "description" : "
Because Clojure's for macro allows you to \"walk\" over multiple sequences in a nested fashion, it is excellent for transforming all sorts of sequences. If you don't want a sequence as your final output (say you want a map), you are often still best-off using for, because you can produce a sequence and feed it into a map, for example.
\r\n\r\n
For this problem, your goal is to \"flatten\" a map of hashmaps. Each key in your output map should be the \"path\"1 that you would have to take in the original map to get to a value, so for example {1 {2 3}} should result in {[1 2] 3}. You only need to flatten one level of maps: if one of the values is a map, just leave it alone.
\r\n\r\n
1 That is, (get-in original [k1 k2]) should be the same as (get result [k1 k2])
", "difficulty" : "Easy", "restricted" : null, "tags" : [ "seqs", "maps" ], "tests" : [ "(= (__ '{a {p 1, q 2}\r\n b {m 3, n 4}})\r\n '{[a p] 1, [a q] 2\r\n [b m] 3, [b n] 4})", "(= (__ '{[1] {a b c d}\r\n [2] {q r s t u v w x}})\r\n '{[[1] a] b, [[1] c] d,\r\n [[2] q] r, [[2] s] t,\r\n [[2] u] v, [[2] w] x})", "(= (__ '{m {1 [a b c] 3 nil}})\r\n '{[m 1] [a b c], [m 3] nil})" ], "title" : "Trees into tables", "user" : "amalloy" },
138 | { "_id" : 147, "description" : "
Write a function that, for any given input vector of numbers, returns an infinite lazy sequence of vectors, where each next one is constructed from the previous following the rules used in Pascal's Triangle. For example, for [3 1 2], the next row is [3 4 3 2].
\r\n
Beware of arithmetic overflow! In clojure (since version 1.3 in 2011), if you use an arithmetic operator like + and the result is too large to fit into a 64-bit integer, an exception is thrown. You can use +' to indicate that you would rather overflow into Clojure's slower, arbitrary-precision bigint.
Write a function which calculates the sum of all natural numbers under n (first argument) which are evenly divisible by at least one of a and b (second and third argument). Numbers a and b are guaranteed to be coprimes.
\r\n\r\n
Note: Some test cases have a very large n, so the most obvious solution will exceed the time limit.
A palindromic number is a number that is the same when written forwards or backwards (e.g., 3, 99, 14341).
\r\n\r\n
Write a function which takes an integer n, as its only argument, and returns an increasing lazy sequence of all palindromic numbers that are not less than n.
\r\n\r\n
The most simple solution will exceed the time limit!
\r\nA Latin square of order n \r\nis an n x n array that contains n different elements, \r\neach occurring exactly once in each row, and exactly once in each column. \r\nFor example, among the following arrays only the first one forms a Latin square:\r\n
\r\nA B C A B C A B C\r\nB C A B C A B D A\r\nC A B C A C C A B\r\n
\r\n\r\n
\r\nLet V be a vector of such vectors1 that they may differ in length2.\r\nWe will say that an arrangement of vectors of V in consecutive rows \r\nis an alignment (of vectors) ofV\r\nif the following conditions are satisfied:\r\n
\r\n
All vectors of V are used.
\r\n
Each row contains just one vector.
\r\n
The order of V is preserved.
\r\n
All vectors of maximal length are horizontally aligned each other.
\r\n
If a vector is not of maximal length then all its elements are aligned \r\n with elements of some subvector \r\n of a vector of maximal length.
\r\n
\r\nLet L denote a Latin square of order 2 or greater.\r\nWe will say that Lis included in V or \r\nthat VincludesL\r\niff there exists an alignment of V \r\nsuch that contains a subsquare that is equal to L.\r\n\r\n
\r\nFor example, if V equals [[1 2 3][2 3 1 2 1][3 1 2]] \r\nthen there are nine alignments of V (brackets omitted):\r\n
\r\nAlignment A1 contains Latin square [[1 2 3][2 3 1][3 1 2]], \r\nalignments A2, A3, B1, B2, B3 contain no Latin squares, and alignments\r\nC1, C2, C3 contain [[2 1][1 2]].\r\nThus in this case V includes one Latin square of order 3 \r\nand one of order 2 which is included three times.\r\n\r\n
\r\nOur aim is to implement a function which accepts a vector of vectors V as an argument, \r\nand returns a map which keys and values are integers. \r\nEach key should be the order of a Latin square included in V, \r\nand its value a count of different Latin squares of that order included in V. \r\nIf V does not include any Latin squares an empty map should be returned.\r\nIn the previous example the correct output of such a function is {3 1, 2 1} and not {3 1, 2 3}.\r\n
\r\n
\r\n1 Of course, we can consider sequences instead of vectors. \r\n \r\n2 Length of a vector is the number of elements in the vector.\r\n
", "difficulty" : "Hard", "restricted" : null, "tags" : [ "data-analysis", "math" ], "tests" : [ "(= (__ '[[A B C D]\r\n [A C D B]\r\n [B A D C]\r\n [D C A B]])\r\n {})", "(= (__ '[[A B C D E F]\r\n [B C D E F A]\r\n [C D E F A B]\r\n [D E F A B C]\r\n [E F A B C D]\r\n [F A B C D E]])\r\n {6 1})", "(= (__ '[[A B C D]\r\n [B A D C]\r\n [D C B A]\r\n [C D A B]])\r\n {4 1, 2 4})", "(= (__ '[[B D A C B]\r\n [D A B C A]\r\n [A B C A B]\r\n [B C A B C]\r\n [A D B C A]])\r\n {3 3})", "(= (__ [ [2 4 6 3]\r\n [3 4 6 2]\r\n [6 2 4] ])\r\n {})", "(= (__ [[1]\r\n [1 2 1 2]\r\n [2 1 2 1]\r\n [1 2 1 2]\r\n [] ])\r\n {2 2})", "(= (__ [[3 1 2]\r\n [1 2 3 1 3 4]\r\n [2 3 1 3] ])\r\n {3 1, 2 2})", "(= (__ [[8 6 7 3 2 5 1 4]\r\n [6 8 3 7]\r\n [7 3 8 6]\r\n [3 7 6 8 1 4 5 2]\r\n [1 8 5 2 4]\r\n [8 1 2 4 5]])\r\n {4 1, 3 1, 2 7})" ], "title" : "Latin Square Slicing", "user" : "maximental" },
142 | { "_id" : 153, "description" : "\r\n
\r\nGiven a set of sets, create a function which returns true \r\nif no two of those sets have any elements in common1 and false otherwise. \r\nSome of the test cases are a bit tricky, so pay a little more attention to them. \r\n
\r\n\r\n
\r\n1Such sets are usually called pairwise disjoint or mutually disjoint.\r\n
However, what if you want the map itself to contain the default values? Write a function which takes a default value and a sequence of keys and constructs a map.", "difficulty" : "Elementary", "restricted" : null, "tags" : [ "seqs" ], "tests" : [ "(= (__ 0 [:a :b :c]) {:a 0 :b 0 :c 0})", "(= (__ \"x\" [1 2 3]) {1 \"x\" 2 \"x\" 3 \"x\"})", "(= (__ [:a :b] [:foo :bar]) {:foo [:a :b] :bar [:a :b]})" ], "title" : "Map Defaults", "user" : "jaycfields" },
144 | { "_id" : 157, "description" : "Transform a sequence into a sequence of pairs containing the original elements along with their index.", "difficulty" : "Easy", "restricted" : null, "tags" : [ "seqs" ], "tests" : [ "(= (__ [:a :b :c]) [[:a 0] [:b 1] [:c 2]])", "(= (__ [0 1 3]) '((0 0) (1 1) (3 2)))", "(= (__ [[:foo] {:bar :baz}]) [[[:foo] 0] [{:bar :baz} 1]])" ], "title" : "Indexing Sequences", "user" : "jaycfields" },
145 | { "_id" : 158, "description" : "Write a function that accepts a curried function of unknown arity n. Return an equivalent function of n arguments.\r\n \r\nYou may wish to read this.", "difficulty" : "Medium", "restricted" : null, "tags" : [ "partial-functions" ], "tests" : [ "(= 10 ((__ (fn [a]\r\n (fn [b]\r\n (fn [c]\r\n (fn [d]\r\n (+ a b c d))))))\r\n 1 2 3 4))", "(= 24 ((__ (fn [a]\r\n (fn [b]\r\n (fn [c]\r\n (fn [d]\r\n (* a b c d))))))\r\n 1 2 3 4))", "(= 25 ((__ (fn [a]\r\n (fn [b]\r\n (* a b))))\r\n 5 5))\r\n" ], "title" : "Decurry", "user" : "amcnamara" },
146 | { "_id" : 161, "description" : "Set A is a subset of set B, or equivalently B is a superset of A, if A is \"contained\" inside B. A and B may coincide.", "difficulty" : "Elementary", "restricted" : null, "tags" : [ "set-theory" ], "tests" : [ "(clojure.set/superset? __ #{2})", "(clojure.set/subset? #{1} __)", "(clojure.set/superset? __ #{1 2})", "(clojure.set/subset? #{1 2} __)" ], "title" : "Subset and Superset", "user" : "hangkous" },
147 | { "_id" : 162, "description" : "In Clojure, only nil and false represent the values of logical falsity in conditional tests - anything else is logical truth.", "difficulty" : "Elementary", "restricted" : null, "tags" : [ "logic" ], "tests" : [ "(= __ (if-not false 1 0))", "(= __ (if-not nil 1 0))", "(= __ (if true 1 0))", "(= __ (if [] 1 0))", "(= __ (if [0] 1 0))", "(= __ (if 0 1 0))", "(= __ (if 1 1 0))" ], "title" : "Logical falsity and truth", "user" : "hangkous" },
148 | { "_id" : 164, "description" : "A deterministic finite automaton (DFA) is an abstract machine that recognizes a regular language. Usually a DFA is defined by a 5-tuple, but instead we'll use a map with 5 keys:\r\n\r\n
\r\n
:states is the set of states for the DFA.
\r\n
:alphabet is the set of symbols included in the language recognized by the DFA.
\r\n
:start is the start state of the DFA.
\r\n
:accepts is the set of accept states in the DFA.
\r\n
:transitions is the transition function for the DFA, mapping :states ⨯ :alphabet onto :states.
\r\n
\r\n\r\nWrite a function that takes as input a DFA definition (as described above) and returns a sequence enumerating all strings in the language recognized by the DFA.\r\n\r\nNote: Although the DFA itself is finite and only recognizes finite-length strings it can still recognize an infinite set of finite-length strings. And because stack space is finite, make sure you don't get stuck in an infinite loop that's not producing results every so often!", "difficulty" : "Hard", "restricted" : null, "tags" : [ "automata", "seqs" ], "tests" : [ "(= #{\"a\" \"ab\" \"abc\"}\r\n (set (__ '{:states #{q0 q1 q2 q3}\r\n :alphabet #{a b c}\r\n :start q0\r\n :accepts #{q1 q2 q3}\r\n :transitions {q0 {a q1}\r\n q1 {b q2}\r\n q2 {c q3}}})))", "\r\n(= #{\"hi\" \"hey\" \"hello\"}\r\n (set (__ '{:states #{q0 q1 q2 q3 q4 q5 q6 q7}\r\n :alphabet #{e h i l o y}\r\n :start q0\r\n :accepts #{q2 q4 q7}\r\n :transitions {q0 {h q1}\r\n q1 {i q2, e q3}\r\n q3 {l q5, y q4}\r\n q5 {l q6}\r\n q6 {o q7}}})))", "(= (set (let [ss \"vwxyz\"] (for [i ss, j ss, k ss, l ss] (str i j k l))))\r\n (set (__ '{:states #{q0 q1 q2 q3 q4}\r\n :alphabet #{v w x y z}\r\n :start q0\r\n :accepts #{q4}\r\n :transitions {q0 {v q1, w q1, x q1, y q1, z q1}\r\n q1 {v q2, w q2, x q2, y q2, z q2}\r\n q2 {v q3, w q3, x q3, y q3, z q3}\r\n q3 {v q4, w q4, x q4, y q4, z q4}}})))", "(let [res (take 2000 (__ '{:states #{q0 q1}\r\n :alphabet #{0 1}\r\n :start q0\r\n :accepts #{q0}\r\n :transitions {q0 {0 q0, 1 q1}\r\n q1 {0 q1, 1 q0}}}))]\r\n (and (every? (partial re-matches #\"0*(?:10*10*)*\") res)\r\n (= res (distinct res))))", "(let [res (take 2000 (__ '{:states #{q0 q1}\r\n :alphabet #{n m}\r\n :start q0\r\n :accepts #{q1}\r\n :transitions {q0 {n q0, m q1}}}))]\r\n (and (every? (partial re-matches #\"n*m\") res)\r\n (= res (distinct res))))", "(let [res (take 2000 (__ '{:states #{q0 q1 q2 q3 q4 q5 q6 q7 q8 q9}\r\n :alphabet #{i l o m p t}\r\n :start q0\r\n :accepts #{q5 q8}\r\n :transitions {q0 {l q1}\r\n q1 {i q2, o q6}\r\n q2 {m q3}\r\n q3 {i q4}\r\n q4 {t q5}\r\n q6 {o q7}\r\n q7 {p q8}\r\n q8 {l q9}\r\n q9 {o q6}}}))]\r\n (and (every? (partial re-matches #\"limit|(?:loop)+\") res)\r\n (= res (distinct res))))\r\n" ], "title" : "Language of a DFA", "user" : "daowen" },
149 | { "_id" : 166, "description" : "For any orderable data type it's possible to derive all of the basic comparison operations (<, ≤, =, ≠, ≥, and >) from a single operation (any operator but = or ≠ will work). Write a function that takes three arguments, a less than operator for the data and two items to compare. The function should return a keyword describing the relationship between the two items. The keywords for the relationship between x and y are as follows:\r\n\r\n
\r\nIn what follows, m, n, s, t \r\ndenote nonnegative integers, f denotes a function that accepts two \r\narguments and is defined for all nonnegative integers in both arguments.\r\n
\r\n\r\n
\r\nIn mathematics, the function f can be interpreted as an infinite \r\nmatrix\r\nwith infinitely many rows and columns that, when written, looks like an ordinary \r\nmatrix but its rows and columns cannot be written down completely, so are terminated \r\nwith ellipses. In Clojure, such infinite matrix can be represented \r\nas an infinite lazy sequence of infinite lazy sequences, \r\nwhere the inner sequences represent rows.\r\n
\r\n\r\n
\r\nWrite a function that accepts 1, 3 and 5 arguments\r\n
\r\n
\r\nwith the argument f, it returns the infinite matrix A \r\nthat has the entry in the i-th row and the j-th column \r\nequal to f(i,j) for i,j = 0,1,2,...;
\r\n
\r\nwith the arguments f, m, n, it returns \r\nthe infinite matrix B that equals the remainder of the matrix A \r\nafter the removal of the first m rows and the first n columns;
\r\n
\r\nwith the arguments f, m, n, s, t,\r\nit returns the finite s-by-t matrix that consists of the first t entries of each of the first \r\ns rows of the matrix B or, equivalently, that consists of the first s entries \r\nof each of the first t columns of the matrix B.
\r\n
\r\n", "difficulty" : "Medium", "restricted" : [ "for", "range", "iterate", "repeat", "cycle", "drop" ], "tags" : [ "seqs", "recursion", "math" ], "tests" : [ "(= (take 5 (map #(take 6 %) (__ str)))\r\n [[\"00\" \"01\" \"02\" \"03\" \"04\" \"05\"]\r\n [\"10\" \"11\" \"12\" \"13\" \"14\" \"15\"]\r\n [\"20\" \"21\" \"22\" \"23\" \"24\" \"25\"]\r\n [\"30\" \"31\" \"32\" \"33\" \"34\" \"35\"]\r\n [\"40\" \"41\" \"42\" \"43\" \"44\" \"45\"]])", "(= (take 6 (map #(take 5 %) (__ str 3 2)))\r\n [[\"32\" \"33\" \"34\" \"35\" \"36\"]\r\n [\"42\" \"43\" \"44\" \"45\" \"46\"]\r\n [\"52\" \"53\" \"54\" \"55\" \"56\"]\r\n [\"62\" \"63\" \"64\" \"65\" \"66\"]\r\n [\"72\" \"73\" \"74\" \"75\" \"76\"]\r\n [\"82\" \"83\" \"84\" \"85\" \"86\"]])", "(= (__ * 3 5 5 7)\r\n [[15 18 21 24 27 30 33]\r\n [20 24 28 32 36 40 44]\r\n [25 30 35 40 45 50 55]\r\n [30 36 42 48 54 60 66]\r\n [35 42 49 56 63 70 77]])", "(= (__ #(/ % (inc %2)) 1 0 6 4)\r\n [[1/1 1/2 1/3 1/4]\r\n [2/1 2/2 2/3 1/2]\r\n [3/1 3/2 3/3 3/4]\r\n [4/1 4/2 4/3 4/4]\r\n [5/1 5/2 5/3 5/4]\r\n [6/1 6/2 6/3 6/4]])", "(= (class (__ (juxt bit-or bit-xor)))\r\n (class (__ (juxt quot mod) 13 21))\r\n (class (lazy-seq)))", "(= (class (nth (__ (constantly 10946)) 34))\r\n (class (nth (__ (constantly 0) 5 8) 55))\r\n (class (lazy-seq)))", "(= (let [m 377 n 610 w 987\r\n check (fn [f s] (every? true? (map-indexed f s)))\r\n row (take w (nth (__ vector) m))\r\n column (take w (map first (__ vector m n)))\r\n diagonal (map-indexed #(nth %2 %) (__ vector m n w w))]\r\n (and (check #(= %2 [m %]) row)\r\n (check #(= %2 [(+ m %) n]) column)\r\n (check #(= %2 [(+ m %) (+ n %)]) diagonal)))\r\n true)" ], "title" : "Infinite Matrix", "user" : "maximental" },
151 | { "_id" : 171, "description" : "Write a function that takes a sequence of integers and returns a sequence of \"intervals\". Each interval is a a vector of two integers, start and end, such that all integers between start and end (inclusive) are contained in the input sequence.", "difficulty" : "Medium", "restricted" : null, "tags" : null, "tests" : [ "(= (__ [1 2 3]) [[1 3]])", "(= (__ [10 9 8 1 2 3]) [[1 3] [8 10]])", "(= (__ [1 1 1 1 1 1 1]) [[1 1]])", "(= (__ []) [])", "(= (__ [19 4 17 1 3 10 2 13 13 2 16 4 2 15 13 9 6 14 2 11])\r\n [[1 4] [6 6] [9 11] [13 17] [19 19]])\r\n" ], "title" : "Intervals", "user" : "aiba" },
152 | { "_id" : 173, "description" : "Sequential destructuring allows you to bind symbols to parts of sequential things (vectors, lists, seqs, etc.): (let [bindings* ] exprs*)\r\n\r\nComplete the bindings so all let-parts evaluate to 3.", "difficulty" : "Easy", "restricted" : null, "tags" : [ "Destructuring" ], "tests" : [ "(= 3\r\n (let [[__] [+ (range 3)]] (apply __))\r\n (let [[[__] b] [[+ 1] 2]] (__ b))\r\n (let [[__] [inc 2]] (__)))" ], "title" : "Intro to Destructuring 2", "user" : "hangkous" },
153 | { "_id" : 177, "description" : "When parsing a snippet of code it's often a good idea to do a sanity check to see if all the brackets match up. Write a function that takes in a string and returns truthy if all square [ ] round ( ) and curly { } brackets are properly paired and legally nested, or returns falsey otherwise.", "difficulty" : "Medium", "restricted" : null, "tags" : [ "parsing" ], "tests" : [ "(__ \"This string has no brackets.\")", "(__ \"class Test {\r\n public static void main(String[] args) {\r\n System.out.println(\\\"Hello world.\\\");\r\n }\r\n }\")", "(not (__ \"(start, end]\"))", "(not (__ \"())\"))", "(not (__ \"[ { ] } \"))", "(__ \"([]([(()){()}(()(()))(([[]]({}()))())]((((()()))))))\")", "(not (__ \"([]([(()){()}(()(()))(([[]]({}([)))())]((((()()))))))\"))", "(not (__ \"[\"))" ], "title" : "Balancing Brackets", "user" : "daowen" },
154 | { "_id" : 178, "description" : "
Following on from Recognize Playing Cards, determine the best poker hand that can be made with five cards. The hand rankings are listed below for your convenience.
\r\n\r\n\r\n
Straight flush: All cards in the same suit, and in sequence
\r\n
Four of a kind: Four of the cards have the same rank
\r\n
Full House: Three cards of one rank, the other two of another rank
\r\n
Flush: All cards in the same suit
\r\n
Straight: All cards in sequence (aces can be high or low, but not both at once)
\r\n
Three of a kind: Three of the cards have the same rank
In a family of languages like Lisp, having balanced parentheses is a defining feature of the language. Luckily, Lisp has almost no syntax, except for these \"delimiters\" -- and that hardly qualifies as \"syntax\", at least in any useful computer programming sense.
\r\n\r\n
It is not a difficult exercise to find all the combinations of well-formed parentheses if we only have N pairs to work with. For instance, if we only have 2 pairs, we only have two possible combinations: \"()()\" and \"(())\". Any other combination of length 4 is ill-formed. Can you see why?
\r\n\r\n
Generate all possible combinations of well-formed parentheses of length 2n (n pairs of parentheses).\r\nFor this problem, we only consider '(' and ')', but the answer is similar if you work with only {} or only [].