(map #(.getName %) (.getMethods java.io.File))
; -> ("equals" "toString" "hashCode" "compareTo" "compareTo" "getName" "length" "getParent" "isAbsolute" "getCanonicalPath" "setReadOnly" "list" "list" "delete" "getParentFile" "getPath" "getAbsolutePath" "getAbsoluteFile" "getCanonicalFile" "toURL" "toURI" "canRead" "canWrite" "exists" "isDirectory" "isFile" "isHidden" "lastModified" "createNewFile" "deleteOnExit" "listFiles" "listFiles" "listFiles" "mkdir" "mkdirs" "renameTo" "setLastModified" "setWritable" "setWritable" "setReadable" "setReadable" "setExecutable" "setExecutable" "canExecute" "listRoots" "getTotalSpace" "getFreeSpace" "getUsableSpace" "createTempFile" "createTempFile" "wait" "wait" "wait" "getClass" "notify" "notifyAll")
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 check-inline | |
(:gen-class)) | |
(defmacro sqr-m [n] `(* ~n ~n)) | |
(definline sqr-i [n] `(* ~n ~n)) | |
(defn sqr-fwi | |
{:inline (fn [n] `(do (println "inline:") (* ~n ~n)))} | |
[n] (do (println "function:") (* n n))) |
#clojure 入門者向け勉強会 #mitori_clj 第二週担当分
Project Euler Problem 10
2,000,000 未満の素数の総和を求めよ. とのことです.
結果を出すために手に入るリソースを有効活用するという考えのもとでは --この問題自体の解答を述べている
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 hanoi-ops [s t d n] | |
(if (zero? n) '() | |
(concat | |
(hanoi s d t (dec n)) | |
(list [n s d]) | |
(hanoi t s d (dec n))))) | |
(hanoi-ops 'A 'B 'C 4) | |
; -> ([1 A B] [2 A C] [1 B C] [3 A B] [1 C A] [2 C B] [1 A B] [4 A C] | |
; [1 B C] [2 B A] [1 C A] [3 B C] [1 A B] [2 A C] [1 B C]) |
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
(define-module synhl | |
(use text.tree) | |
(export highlight)) | |
(select-module synhl) | |
;(use slib) | |
;(require 'trace) | |
(define (mk-tokenizer :rest args) | |
(letrec |
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
(require '[clojure.set :refer (difference)]) | |
(defn sudoku-level0 [coll] | |
(let [ics (vec (map #(if % #{%} (set (range 1 10))) coll)) | |
cnb (fn [cs i] | |
(set | |
(keep #(if (= 1 (count %)) (first %)) | |
(concat | |
(map first (partition-all 1 9 (drop (mod i 9) cs))) | |
(take 9 (drop (* 9 (quot i 9)) cs)) |
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 fibs [a b] | |
(cons a (lazy-seq (fibs b (+ a b))))) | |
(take 100 (fibs 1N 1N)) | |
; -> (1N 1N 2N 3N 5N 8N 13N 21N 34N 55N 89N 144N 233N 377N 610N 987N | |
; 1597N 2584N 4181N 6765N 10946N 17711N 28657N 46368N 75025N | |
; 121393N 196418N 317811N 514229N 832040N 1346269N 2178309N | |
; 3524578N 5702887N 9227465N 14930352N 24157817N 39088169N | |
; 63245986N 102334155N 165580141N 267914296N 433494437N | |
; 701408733N 1134903170N 1836311903N 2971215073N 4807526976N |
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 fizz-buzz [n] | |
(map #(cond (zero? (mod % 15)) "FizzBuzz" | |
(zero? (mod % 5)) "Buzz" | |
(zero? (mod % 3)) "Fizz" | |
:else %) | |
(range 1 (inc n)))) | |
(fizz-buzz 100) | |
; -> (1 2 "Fizz" 4 "Buzz" "Fizz" 7 8 "Fizz" "Buzz" 11 "Fizz" 13 14 "FizzBuzz" | |
; 16 17 "Fizz" 19 "Buzz" "Fizz" 22 23 "Fizz" "Buzz" 26 "Fizz" 28 29 "FizzBuzz" |
This gist has moved to https://gist.github.com/3937083 To be deleted near future
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
# Usage: | |
# Save this file as 'hello.s'. | |
# $ as -o hello.o hello.s | |
# $ ld -o hello hello.o | |
# $ ./hello | |
# | |
# How to call a system call | |
# 1) Set rax to the index of the system call. | |
# 2) Set rdi, rsi, rdx, ... to arguments in this order. | |
# 3) Call 'syscall'. |