Skip to content

Instantly share code, notes, and snippets.

@ha2ne2
ha2ne2 / IppatsuJanken.cs
Created February 26, 2020 09:26
一発ジャンケンというやつのシミュレータ
using System;
namespace Scratch
{
public class Program
{
public static void Main()
{
JankenTest();
}
@ha2ne2
ha2ne2 / NextPermutation.cs
Last active February 21, 2020 02:33
次の順列を求める関数 2020/02/20
using System;
namespace Scratch
{
public class Program
{
public static void Main()
{
int[] array = new int[] { 0, 1, 2, 3 };
for (int i = 0; i < 24; i++)
@ha2ne2
ha2ne2 / CurriedClojure.clj
Last active October 25, 2019 18:35
Clojureでラムダ計算
;; 2019-10-26
;;;; 関数をカリー化して定義します。
;; (defn-c add [a b] (+ a b)) が
;; (def add (fn [a] (fn [b] (+ a b)))) になります。
(defmacro defn-c [fn-name args body]
`(def ~fn-name (fn-c ~args ~body)))
(defmacro fn-c [[x & xs :as args] body]
(if (empty? args)
# -*- mode: python; coding: utf-8-with-signature-dos -*-
# JIS配列をUS配列に変換するかどうか
change_JIS_to_US = True
## nickname: fakeymacs
##
## Windows の操作を emacs のキーバインドで行うための設定(Keyhac版)ver.20171103_01
##
(defn iterate* [f x]
(if (nil? x) nil
(cons x (lazy-seq (iterate* f (f x))))))
(defn iter-perm [v]
(let [len (count v)
left (loop [i (- len 2)]
(cond (< i 0) nil
(< (v i) (v (inc i))) i
:else (recur (dec i))))]
# coding: utf-8
# 2017-02-04
# kinds種類の物がそれぞれlimit個あった時に
# その中からn個取ったときの組み合わせの数を求める関数
# 例えば麻雀の萬子は1~9種類の物がそれぞれ4枚あり
# その中から8枚取ったときの組み合わせの数は
# f(8,9,4) = 11385
# 参考:上限のある重複組合わせ(?)
@ha2ne2
ha2ne2 / swap_way.rb
Last active October 14, 2016 14:15
# coding: utf-8
# swap([0,1,2], 0, 2)
# => [2, 1, 0]
def swap(v, n, m)
v2 = v.dup
v2[m] = v[n]
v2[n] = v[m]
v2
end
#+sbcl
(eval-when (:compile-toplevel :execute)
(handler-case
(progn
(sb-ext:assert-version->= 1 2 2)
(setq *features* (remove 'old-sbcl *features*)))
(error ()
(pushnew 'old-sbcl *features*))))
(defun flatten (x)
import System.Environment (getArgs)
interactWith function inputFile outputFile = do
input <- readFile inputFile
writeFile outputFile (function input)
main = mainWith myFunction
where mainWith fn = do
args <- getArgs
case args of
# coding: utf-8
# irb(main):037:0> (scheme)
# (scheme)
# ==> (* 2 (call_cc (lambda (cc) (set! old_cc cc) 4)))
# 8
# ==> (old_cc 10)
# 20
# ==> (+ 1 (old_cc 10))
# 20