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
import scala.math | |
import java.io.{Writer, FileWriter} | |
/** | |
* 引数nが素数かどうかを判定します。 | |
* 引数psには√n以下の素数が全て含まれている必要があります。 | |
*/ | |
def isPrimeNumber(n: Int, ps: Seq[Int]): Boolean = { | |
require(n > 0) | |
val sqrt = math.sqrt(n).toInt |
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
#!/opt/local/bin/perl | |
# | |
# 素数をカンマ区切りで各行10個ずつ出力するプログラム。 | |
# | |
# 使い方 | |
# $ perl prime.pl {number} [filename] | |
# | |
use strict; | |
use warnings; | |
use POSIX; |
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
isPrimeNumber :: Int -> [Int] -> Bool | |
isPrimeNumber n = not . any ((== 0) . (mod n)) . filter (<= sr) | |
where | |
sr = floor $ sqrt $ fromInteger $ toInteger n | |
createPrimeList :: Int -> [Int] | |
createPrimeList 0 = [] | |
createPrimeList len = _create 3 [2] | |
where | |
_create n ps |
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
# | |
# 番号,問題名,問題文,選択肢(選択肢は項目ごとに改行) | |
# とりあえず多岐選択、記述形式、組み合わせに対応 | |
# Cloze形式はログに出力してスキップ(後で手入力する) | |
# 単一選択は ~foo(1個以上) =bar(1個) | |
# 複数選択は ~%10%foo で、正の数の合計100になるように | |
# 記述形式は =foo を1個以上 | |
# 組み合わせは =foo -> bar を1個以上 | |
# |
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
/** | |
* do execute. | |
* $ scala payment.scala {pocket} {price} | |
*/ | |
object Main { | |
implicit val coins = List(1, 5, 10, 50, 100, 500, 1000, 5000, 10000) | |
def main(args: Array[String]): Unit = { | |
if (args.length != 2) sys.exit(-1) |
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
import scala.io.Source | |
def widthOfLength(s: String): Int = s.length.toString.length | |
if (args.length == 0) { | |
Console.err.println("Please enter filename") | |
sys.exit(-1) | |
} | |
val lines = Source.fromFile(args(0)).getLines().toList |
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
/** | |
* ハッカーと画家のP.198に載ってるアキュムレータをScalaで実装。 | |
* 元ネタは Common Lisp | |
* (defun foo (n) | |
* (lambda (i) (incf n i))) | |
* | |
* Int固定じゃなくてもっと汎用的にするにはどうするんだろ。 | |
*/ | |
def accum(n: Int): (Int => Int) = { | |
var m = n |
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
/** | |
* https://gist.github.com/2344525 の別バージョン | |
* 高階関数じゃなくてクラスを使用してみる。 | |
*/ | |
class Accum(private var n: Int) { | |
def apply(i: Int): Int = { n += i; n } | |
} | |
object Accum { | |
def apply(n: Int): Accum = new Accum(n) |
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
/* | |
* 実行にはjQueryが必要。 | |
* if文の中で関数外(forEachメソッドの引数は関数です)の変数 n を参照している。 | |
*/ | |
function doClick() { | |
var arr = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]; | |
var n = $('#num').val(); | |
arr.forEach(function(i) { | |
if (i % n == 0) { |
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
#!/bin/bash | |
# | |
# ./node-debug.sh app.js | |
# | |
function usage() { | |
echo "Usage $0 [-p port] [jsfile]" | |
exit 1 | |
} |
OlderNewer