Skip to content

Instantly share code, notes, and snippets.

let rec power n x =
if n = 0 then .<1>. else .< .~x * .~(power (n-1) x) >.;;
let rec power n x =
if n = 0 then .<1>. else .< x * .~(power (n-1) x) >.;;
let power5 = power 5;;
power5 .<3>.;;
Runcode.run;;
// data type
sealed abstract class Tree {
def foldLeft[B](z: B)(f: (B, Int) => B): B
}
case class Branch(value: Int, left: Tree, right: Tree) extends Tree {
def foldLeft[B](z: B)(f: (B, Int) => B): B =
right.foldLeft(f(left.foldLeft(z)(f), value))(f)
}
case object Empty extends Tree {
def foldLeft[B](z: B)(f: (B, Int) => B): B = z
type nat = Z | S of nat
let rec nat_of_int = function
| 0 -> Z
| n -> S (nat_of_int (n-1))
let rec plus n m =
match n with
| Z -> m
| S n' -> plus n' (S m)
@Gobi03
Gobi03 / judge_base.ml
Last active August 19, 2017 04:26
『プログラミング言語の基礎概念』の演習システム用の導出木生成DSL
open Printf
(** ペアノ数 **)
type nat = Z | S of nat
let rec string_of_nat = function
| Z -> "Z"
| S n -> sprintf "S(%s)" @@ string_of_nat n
let rec int_of_nat = function
| Z -> 0
@Gobi03
Gobi03 / derivetree_DSL_small_subset.ml
Last active August 12, 2017 04:12
『プログラミング言語の基礎概念』の演習システムの導出木生成用DSLのサブセット
(** ペアノ数 **)
type nat = Z | S of nat
let rec nat_of_string = function
| Z -> "Z"
| S n -> "S(" ^ nat_of_string n ^ ")"
(*** DSL ***)
(* syntax *)
type exp = Plus of nat * nat (* _1 plus _2 *)
import java.util.Scanner
import scala.collection.mutable.PriorityQueue
sealed trait NodeState
case object Free extends NodeState
case class Half(a: Int) extends NodeState
case class Full(a: Int, b: Int) extends NodeState
case class Point(x: Long, y: Long){
@Gobi03
Gobi03 / VList.ml
Last active October 29, 2017 06:56
VList の実装(コメント欄に説明付き)
module type VLIST = sig
type 'a t
val nth: 'a t -> int -> 'a
val length: 'a t -> int
val cons: 'a -> 'a t -> 'a t
val head: 'a t -> 'a
val tail: 'a t -> 'a t
import java.util.Scanner
import scala.xml.XML
import scala.util.Random
/** div.boardを入力として与える **/
object Main extends App {
val answer = Array(
"00000000",
"00000000",
function solve() {
const board = document.getElementsByClassName('board')[0].children
const side = board.length
document.dispatchEvent(new KeyboardEvent( 'keypress', {key: "w"}))
var table = new Array(side);
for (let y = 0; y < side; y++) {
table[y] = new Array(side).fill(false);
for (let x = 0; x < side; x++) {
// sisisin is true
function solve() {
// a / b
function modDiv(a, b, p) {
function repeatSquares(x, n) {
if (n === 0)
return 1
else if (n % 2 === 0)
return repeatSquares(x*x % p, n/2)
else