From 80407491504ab6349654dc5aa3906bd95ff9104c Mon Sep 17 00:00:00 2001
From: Vaclav Synacek \r\nIn what follows, \r\nIn mathematics, the function \r\nWrite a function that accepts 1, 3 and 5 arguments\r\n\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" },
{ "_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\n
", "difficulty" : "Easy", "restricted" : null, "tags" : null, "tests" : [ "(= :gt (__ < 5 1))", "(= :eq (__ (fn [x y] (< (count x) (count y))) \"pear\" \"plum\"))", "(= :lt (__ (fn [x y] (< (mod x 5) (mod y 5))) 21 3))", "(= :gt (__ > 0 2))\r\n" ], "title" : "Comparisons", "user" : "daowen" },
{ "_id" : 168, "description" : "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\nf
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\nf
, 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,...
;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;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.
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\nIn 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\nIt 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\nGenerate 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 [].
There is an interesting pattern in the numbers!
", "tags" : [ "math", "combinatorics" ], "restricted" : null, "tests" : [ "(= [#{\"\"} #{\"()\"} #{\"()()\" \"(())\"}] (map (fn [n] (__ n)) [0 1 2]))", "(= #{\"((()))\" \"()()()\" \"()(())\" \"(())()\" \"(()())\"} (__ 3))", "(= 16796 (count (__ 10)))", "(= (nth (sort (filter #(.contains ^String % \"(()()()())\") (__ 9))) 6) \"(((()()()())(())))\")", "(= (nth (sort (__ 12)) 5000) \"(((((()()()()()))))(()))\")" ], "user" : "djtrack16" }, +{ "_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" }, +{ "_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" }, +{ "_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" }, +{ "_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\nIn 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\nIt 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\nGenerate 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 [].
There is an interesting pattern in the numbers!
", "tags" : [ "math", "combinatorics" ], "restricted" : null, "tests" : [ "(= [#{\"\"} #{\"()\"} #{\"()()\" \"(())\"}] (map (fn [n] (__ n)) [0 1 2]))", "(= #{\"((()))\" \"()()()\" \"()(())\" \"(())()\" \"(()())\"} (__ 3))", "(= 16796 (count (__ 10)))", "(= (nth (sort (filter #(.contains ^String % \"(()()()())\") (__ 9))) 6) \"(((()()()())(())))\")", "(= (nth (sort (__ 12)) 5000) \"(((((()()()()()))))(()))\")" ], "user" : "djtrack16" }, { "_id" : 5, "description" : "When operating on a list, the conj function will return a new list with one or more items \"added\" to the front.
\r\nNote that there are two test cases, but you are expected to supply only one answer, which will cause all the tests to pass.
", "difficulty" : "Elementary", "tags" : null, "tests" : [ "(= __ (conj '(2 3 4) 1))", "(= __ (conj '(3 4) 2 1))" ], "times-solved" : 1260, "title" : "Lists: conj", "user" : "dbyrne", "restricted" : null }]