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
Int.MaxValue // Int の最大値 | |
Int.MinValue // Int の最小値 | |
Long.MaxValue // Long の最大値 | |
Long.MinValue // Long の最小値 | |
Byte.MaxValue // Byte の最大値 | |
Byte.MinValue // Byte の最小値 | |
Short.MaxValue // Short の最大値 |
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 static java.lang.Math.*; | |
Math.PI // 円周率 | |
Math.E // 自然対数の底 | |
Integer.MAX_VALUE // int の最大値 | |
Integer.MIN_VALUE // int の最小値 | |
Long.MAX_VALUE // long の最大値 | |
Long.MIN_VALUE // long の最小値 | |
Byte.MAX_VALUE // byte の最大値 |
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 math._ | |
1L // Long型の 1 | |
1:Long // Long型の 1 | |
127:Byte // Byte型の 127 | |
32767:Short // Short型の 32767 | |
(1+2).toLong // Long型への変換 | |
(2+3) toLong // Long型への変換 |
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
# Ruby の整数は Bignum なので,上限,下限は無い。 | |
# 数学定数 | |
Math::PI # 円周率 | |
Math::E # 自然対数の底 e | |
# Float は,多くの実装で IEEE 754 double precision floating point number が使われる | |
Float.MAX # 最大値 |
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
# | |
# 配列 | |
# | |
xs = Array.new | |
xs = [1,2,4,8,16,32] | |
xs(0) # => 1 ; 先頭の成分 | |
xs.last # => 32 ; 最後の成分 | |
xs[1..-1] # => [2,4,8,16,32] ; 先頭を除いた部分列 |
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
;;; | |
;;; Algorithm: iterative square method | |
;;; | |
;;; Basic Idea: a^(2*n) = (a^2)^n (mod m) | |
;;; e.g. a^4 = (a^2)^2, a^8 = ((a^2)^2)^2, a^16 = (((a^2)^2)^2)^2 | |
;;; | |
;;; Haskell like code that scans the exponential from LSB to MSB | |
;;; pow-mod a 1 m = a mod m | |
;;; pow-mod a 2*n m = powMod (a^2 mod m) n m | |
;;; pow-mod a 2*n+1 m = (powMod (a^2 mod m) n m) * a mod m |
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
// | |
// Scala の Array の実体は Java の配列 | |
// - 各成分は mutable | |
// - 要素数の動的変更はできない | |
// - 必要に応じて implicite conversion で WrappedArray に変換されるため | |
// Seq (or IndexedSeq ≒ Vector) と同じように扱うことができる | |
// | |
var xs = Array(1,2,4,8,16,32) // 6個の成分を列挙した配列を作る | |
xs(3) // 丸カッコで index を与える |
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
;;; | |
;;; 無限大と NaN | |
;;; | |
(define negative-infinity (log 0.0)) | |
(define positive-infinity (- negative-infinity)) | |
(define NaN (+ positive-infinity negative-infinity)) | |
;;; | |
;;; 数値の変換 | |
;;; |
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
(cond-expand | |
(guile (use-modules (srfi srfi-6))) | |
(gauche (use srfi-6)) | |
(plt (require (lib "6.ss" "srfi"))) | |
(srfi-6 #t)) | |
;;; SRFI-6 provides open-input-string | |
(define *eof* | |
(let ((port (open-input-string ""))) | |
(read port))) |
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
# | |
for n in 1..100 | |
if n % 15 == 0 | |
puts 'fizzbuzz' | |
elsif n % 3 == 0 | |
puts 'fizz' | |
elsif n % 5 == 0 | |
puts 'buzz' | |
else |
OlderNewer