Skip to content

Instantly share code, notes, and snippets.

View liquidz's full-sized avatar
👶
hello world!

Iizuka Masashi liquidz

👶
hello world!
View GitHub Profile
@liquidz
liquidz / core.clj
Created April 16, 2012 14:54
Clojure1.4 Reader Literals Test
(ns myreader.core
"Reader Literals Test"
(:require [clojure.string :as str]))
(defn debug-print
"Gauche debug print"
[x]
`(let [res# ~x]
(println "?=" res#)
res#))
(def fib
(map second (iterate (fn [[a b]] [b (+ a b)]) [0 1])))
; (1 1 2 3 5 8 13 21 34 55)
(println (take 10 fib))
(some #(->> % inc range rest (apply *) (str % "! = ") println)
(-> (Integer/parseInt (nth *command-line-args* 0 "1")) inc range rest))
(defn get-first
"条件にあう最初の要素を返す"
[pred [x & rst]]
(if (nil? x) nil
(if (pred x) x (recur pred rst))))
(defn calc-body
"四則演算の優先順で1つの演算だけ処理する。処理結果を元の式に反映して式を返す"
[exp]
(let [indexed-exp (partition 2 (interleave exp (range)))]
(defn correct-order
"中置記法を後置記法に並び替え。乗算、除算は優先するよう並び替える"
[ls]
(reduce
(fn [[op res] x]
(cond
(symbol? x) [x res]
(nil? op) [op (conj res x)]
(or (= 1 (count res)) (some #(= % op) '(+ -))) [nil (conj res x op)]
:else (let [[n last-op] (take-last 2 res)]
(defn 一 ([] 1) ([f] (f 1)))
(defn 二十 ([] 20) ([f] (f 20)))
(defn から [numfn]
(fn [n] (list (numfn) (inc n))))
(defn まで数えて [ls]
(list (apply range ls) ()))
(defn- make-pred [pred]
def fizzbuzz(n)
(1..n).map do |x|
res = ""
res += "Fizz" if x % 3 == 0
res += "Buzz" if x % 5 == 0
(res == "") ? x : res
end
end
puts fizzbuzz(15)
#!/usr/bin/perl
use strict;
use warnings;
sub fizzbuzz {
my $n = shift;
for(1 .. $n){
my $res = "";
; nがmで割り切れるかどうか
(defn divisible? [m n]
(zero? (mod n m)))
; 1〜無限のFizzBuzzリスト
(def all-fizzbuzz-list
(map #(condp divisible? %
15 "FizzBuzz"
5 "Buzz"
3 "Fizz"
def fizzbuzz(n:Int):IndexedSeq[String] = {
(1 to n).map(x => List(x % 15, x % 5, x % 3) match {
case List(0, _, _) => "FizzBuzz"
case List(_, 0, _) => "Buzz"
case List(_, _, 0) => "Fizz"
case _ => x + ""
})
}
println(fizzbuzz(15))