Skip to content

Instantly share code, notes, and snippets.

View omasanori's full-sized avatar

Masanori Ogino omasanori

View GitHub Profile
function! Test()
let l:foo = 1
python << __END__
print type(vim.eval('l:foo'))
print type(1)
__END__
endfunction
call Test()
;; 第1回 Scheme コードバトン
;;
;; ■ これは何か?
;; Scheme のコードをバトンのように回していき面白い物ができあがるのを楽しむ遊びです。
;; 次回 Shibuya.lisp で成果を発表します。
;; Scheme 初心者のコードを書くきっかけに、中級者には他人のコードを読む機会になればと思います。
;;
;; ■ 2 つのルール
;;
;; (1)自分がこれだと思える変更をコードに加えて2日以内に次の人にまわしてください。
@omasanori
omasanori / baton.clj
Created February 11, 2010 00:16 — forked from tnoborio/baton.clj
;; The First Edition Of Scheme Code Baton
;;
;; * What Is This?
;; This is a recreation that we pass Scheme codes as a baton and enjoy it
;; changed to something interesting.
;; Results are make public at Shibuya.lisp (event about Lisp held in Shibuya,
;; Japan).
;; We want code baton being a chance to write codes for beginner and to read
;; others codes for middles.
;;
;;; base64.clj --- Base64 encode/decode utility
;;
;; Copyright (c) 2010 OGINO Masanori <masanori.ogino@gmail.com>
;;
;; Permission is hereby granted, free to charge, to any person obtaining a
;; copy of this software and associated documentation files (the "Software"),
;; to deal in the Software without restriction, including without limitation
;; the rights to use, copy, modify, merge, publish, distribute, sublicense,
;; and/or sell copies of the Software, and to permit persons to whom the
;; Software is furnished to do so, subject to the following conditions:
(defn rand-assign
[n]
(take n (repeatedly #(rand-nth [true false]))))
(defn clause-satisfied?
[assign clause]
(some #(= (nth assign (first %)) (second %)) clause))
(defn formula-satisfied?
[assign formula]
@omasanori
omasanori / make_number.clj
Created May 26, 2011 00:07 — forked from nyuichi/sisoku.clj
A library to make certain number from some numbers.
(ns
^{:author "OGINO Masanori"
:see-also [["http://www.cs.nott.ac.uk/~gmh/book.html" "Programming in Haskell"]]
:doc "A library to make certain number from some numbers.
This library solves a well-known problem called \"Ten Puzzle\" or \"Countdown
Problem\", but the target number is not limited to 10. You can get any integer
or rational number. Also, the number of source numbers is not limited to 4.
Note that source numbers are *not always* used once, but never or once.
@omasanori
omasanori / bar.clj
Created July 22, 2011 23:10
An example to use record constructor
(ns bar
"Other namespace."
(:use foo))
(println "WARNING: constructor functions are enabled from 1.3 series!")
(println "WARNING: for now, try beta version at your risk.")
(println "Simple constructor: ->Point"
(->Point 10 20))
@omasanori
omasanori / prime.clj
Created September 28, 2011 22:10
A hobby implementation to calculate prime numbers.
(defn prime?
"Returns true if x is prime number, false otherwise."
[x]
(not-any? zero?
(map #(rem x %)
(range 2 (inc (/ x 2))))))
(defn prime-numbers
"Returns a lazy seq of prime numbers."
[]
@omasanori
omasanori / leap_year.clj
Created September 28, 2011 22:24
A hobby implementation to calculate leap years.
(defn leap-year?
"Returns true if x is leap year, false otherwise."
[x]
(or (zero? (rem x 400))
(and (zero? (rem x 4))
(not (zero? (rem x 100))))))
(defn leap-years
"Returns a lazy seq of leap years."
[]
@omasanori
omasanori / lcg.clj
Created September 29, 2011 05:29
A hobby implementation of linearcongruential generators.
(defn lcg
"Returns a lazy seq of random numbers using linear congruential
generators (LCGs)."
[seed a b m]
(map #(float (/ %))
(drop 1
(iterate (fn [x] (mod (+ (* a x) b) m))
seed))))
(defn lcg-average