This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Using lua to parse CSV file to a table. | |
-- Notice: first line must be data description filed. | |
-- The separator is '|', change it if you want. | |
-- Usage: csv = require('csv') | |
-- tab = csv.load('test.csv', ',') | |
-- table.foreach(tab[1], print) | |
-- print(tab[1].you_field) | |
--encoding=utf-8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defonce init | |
(reset! app-state | |
{:home {:home? true | |
:score 0 | |
:timeouts 3} | |
:away {:home? false | |
:score 0 | |
:timeouts 3} | |
:ball-on 50 | |
:to-go 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns scoreboard.test | |
(:require [scoreboard.events :as e :refer [publish!]] | |
[scoreboard.core :as s])) | |
(def score-range (range 0 150)) | |
(def timeouts-range (range 1 4)) | |
(def paths-values | |
[[[:home :score] score-range] | |
[[:home :timeouts] timeouts-range] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns om-life.core | |
(:require [om.core :as om :include-macros true] | |
[om.dom :as dom :include-macros true] | |
[om-life.events :as e :refer [publish! event]] | |
[sablono.core :as html :refer-macros [html]])) | |
(def seed | |
#{[8 13] [9 13] [4 11] [6 13] [8 14] [11 14] [4 12] [5 13] | |
[4 13] [14 14] [12 13] [15 14] [12 14] [14 13] [38 13] | |
[37 13] [34 13] [35 14] [4 14] [34 14] [5 14] [32 13] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn fact [x] | |
(if (< x 2) ;; the <= avoids error if non-integer is entered. | |
1 | |
(* x (fact (dec x))))) | |
(fact 10) | |
;;3628800 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns student.dialect | |
(use: [clojure.contrib.str-utils :only [str-join]])) | |
(defn babyize [s] "replace l and r with w if first letter of each word" | |
(let [b-word (fn [[first-letter & word]] | |
(let [new-first (cond (some #{first-letter} [\l \r]) \w | |
(some #{first-letter} [\L \R]) \W | |
:else first-letter)] | |
(apply str new-first word)))] | |
(str-join " " (map b-word (.split s " "))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;problem 2 sum even fibonacci #s up to 4000000 | |
(defn fib-seq [] | |
(let [step (fn [pair] | |
[(last pair) (+ (first pair) (last pair))])] | |
(map first (iterate step [0 1])))) | |
(def fibs (fib-seq)) | |
(apply + (filter even? (take-while #(<= % 4000000) fibs))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;problem 3 largest prime factor of 600851475143 | |
(defn prime? [x] | |
(if (>= x 2) | |
(zero? | |
(count | |
(filter #(divides? x %) | |
(range 2 (inc (int (sqrt x))))))) | |
false)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;problem 3 largest prime factor of 600851475143 | |
(defn prime? [x] | |
(if (>= x 2) (zero? (count (filter #(divides? x %) (range 2 (inc (int (sqrt x))))))) false)) | |
(defn get-biggest-prime-factor [x] | |
(if (prime? x) | |
x | |
(/ x (first |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns student.dialect | |
(:use [clojure.contrib.str-utils :only [str-join]] | |
[clojure.contrib.math :only [sqrt lcm]] | |
[clojure.contrib.lazy-seqs :only [primes]])) | |
(defn babyize [s] "replace l and r with w if first letter of each word" | |
(let [b-word (fn [[first-letter & word]] | |
(let [new-first (cond (some #{first-letter} [\l \r]) \w | |
(some #{first-letter} [\L \R]) \W | |
:else first-letter)] |
OlderNewer