This file contains hidden or 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
exception Done of int | |
let loopEnd = ref false | |
while not !loopEnd do | |
let [| width; height |] = System.Console.ReadLine().Split([|' '|]) |> Array.map int | |
if height = 0 && width = 0 then loopEnd := true | |
else | |
let maze = | |
[| for x = 0 to height - 1 do | |
yield System.Console.ReadLine().Split([|' '|]) |> Array.map int |] | |
let start = ref (0, 0) |
This file contains hidden or 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
module Util = | |
let fordir x y f = | |
for (dx, dy) in [ (-1, 0); (0, -1); (1, 0); (0, 1) ] do | |
f (x+dx) (y+dy) | |
open Util | |
let size = System.Console.ReadLine() |> int | |
let inputs = [| | |
for x = 0 to size - 1 do |
This file contains hidden or 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
module Util = | |
let toStr x = Array.fold (fun x y -> x + string y) "" x | |
let fordir (arr : int[]) x f = | |
for (i, d) in List.mapi (fun a b -> (a, b)) [ 1; -1; 4; -4 ] do | |
if not(x%4=0 && i=1) && not(x%4=3 && i=0) && x+d<8 && x+d>=0 then | |
let arr = arr.Clone() :?> int[] | |
let t = arr.[x] | |
arr.[x] <- arr.[x + d] | |
arr.[x + d] <- t | |
f arr |
This file contains hidden or 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
let size = System.Console.ReadLine() |> int | |
let input = [| | |
for i = 0 to size - 1 do | |
yield System.Console.ReadLine().Split([|' '|]) |> Array.map int | |
|] | |
let rec permutations list taken = | |
seq { if Set.count taken = List.length list then yield [] else | |
for l in list do | |
if not (Set.contains l taken) then |
This file contains hidden or 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
let [| n; sum |] = System.Console.ReadLine().Split([|' '|]) |> Array.map int | |
let rec permutations list taken = | |
seq { if Set.count taken = List.length list then yield [] else | |
for l in list do | |
if not (Set.contains l taken) then | |
for perm in permutations list (Set.add l taken) do | |
yield l::perm } | |
let step xs = seq { |
This file contains hidden or 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
type ty = | |
| TyVar of int * int | |
| TyArr of ty * ty | |
| TyAll of string * ty | |
| TySome of string * ty | |
type binding = | |
| NameBind | |
| VarBind of ty | |
| TyVarBind |
This file contains hidden or 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
let levenshteinDistance (str1 : string) (str2 : string) = | |
let d = Array.init (str1.Length+1) (fun _ -> Array.init (str2.Length+1) (fun _ -> 0)) | |
let mutable cost = 0 | |
for i1 = 0 to str1.Length do | |
d.[i1].[0] <- i1 | |
for i2 = 0 to str2.Length do | |
d.[0].[i2] <- i2 | |
for i1 = 1 to str1.Length do | |
for i2 = 1 to str2.Length do | |
if str1.[i1-1] = str2.[i2-1] then |
This file contains hidden or 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
type Tree<'T when 'T : comparison> = Null | Fork of 'T * Tree<'T> * Tree<'T> | |
let isEmpty = function | |
| Null -> true | |
| _ -> false | |
let minElem (Fork(x,_,_)) = x | |
let rec merge a b = |
This file contains hidden or 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
open System | |
type Class = Virus | Noise | |
type Datum = { Image : float[]; Class : Class } | |
type NeuralNetwork(inputSize, hiddenSize, outputSize, patternSize, maxT, eps, alpha, beta, W0, high, low) = | |
let mutable eta = 0.005 | |
let inputLayer = Array.init (inputSize+1) (fun _ -> 0.0) | |
let hiddenLayer = Array.init (hiddenSize+1) (fun _ -> 0.0) |
This file contains hidden or 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
(* 何かがおかしい。要検証。 *) | |
module MCMC = | |
let random = new Random() | |
let select x = x + (random.NextDouble() - 0.5) * 10.0 | |
let prob x = 1.0 / (1.0 + System.Math.Exp(-x)) | |
let nextStatus x = | |
let xt = select x | |
let p = prob xt / prob x |