Skip to content

Instantly share code, notes, and snippets.

@einblicker
einblicker / gist:3115976
Created July 15, 2012 08:55
POJ 3669 Meteor Shower
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
@einblicker
einblicker / gist:3115842
Created July 15, 2012 08:12
POJ 3009 Curling 2.0
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)
@einblicker
einblicker / gist:3115268
Created July 15, 2012 05:58
AOJ 0558 Cheese
let [| height; width; cheeseSize |] = System.Console.ReadLine().Split([|' '|]) |> Array.map int
let maze =
[| for x = 0 to height - 1 do
yield System.Console.ReadLine().ToCharArray() |]
let start = ref (0, 0)
for h = 0 to height - 1 do
for w = 0 to width - 1 do
if maze.[h].[w] = 'S' then
@einblicker
einblicker / gist:3114925
Created July 15, 2012 04:07
AOJ 0033 Balls
let lineSize = System.Console.ReadLine() |> int
for x = 0 to lineSize - 1 do
let nums = System.Console.ReadLine().Split([|' '|]) |> Array.map int
let suc = ref false
let rec dfs i bMax cMax =
if i < nums.Length - 1 then
if nums.[i] > bMax then
dfs (i+1) nums.[i] cMax
if nums.[i] > cMax then
@einblicker
einblicker / gist:3114828
Created July 15, 2012 03:45
AOJ 0118 Property Distribution
let ringo = '@'
let kaki = '#'
let mikan = '*'
let loopEnd = ref false
while not !loopEnd do
let [|I; J|] = System.Console.ReadLine().Split([|' '|]) |> Array.map int
if I = 0 && J = 0 then
loopEnd := true
else
let maze =
@einblicker
einblicker / gist:3114762
Created July 15, 2012 03:23
POJ 1979 Red and Black
let blackTile = '.'
let redTile = '#'
let man = '@'
let loopEnd = ref false
while not !loopEnd do
let [|I; J|] = System.Console.ReadLine().Split([|' '|]) |> Array.map int
if I = 0 && J = 0 then
loopEnd := true
else
let maze =
@einblicker
einblicker / gist:2993628
Created June 26, 2012 05:57
eliminating array bound checking in F#
module ElimArrayBoundCheck =
type BIndex<'Tag>(idx) =
member this.Idx = idx
type BArray<'Tag, 'T>(arr : 'T[]) =
member this.lookup(bidx : BIndex<'Tag>) = arr.[bidx.Idx]
type C<'T, 'R> = interface
abstract s<'Tag> : BIndex<'Tag> * BArray<'Tag, 'T> -> 'R
abstract f : 'R
end
package ;
import js.JQuery;
import js.Lib;
enum Pair<A, B> {
pair(a : A, b : B);
}
class Util {
public static function fst<A, B>(p: Pair<A, B>) {
@einblicker
einblicker / gist:2928877
Created June 14, 2012 07:56
FS0193 internal errorになるコード
type A<'X, 'Y when 'X :> A<'X, 'Y> and 'Y :> B<'X, 'Y>> = interface end
and B<'X, 'Y when 'X :> A<'X, 'Y> and 'Y :> B<'X, 'Y>> = interface end
type C = inherit A<C, D>
and D = inherit B<C, D>
@einblicker
einblicker / gist:2928049
Created June 14, 2012 04:51
Expression Problem in F#
(*
type IFoo =
 abstract M1 : unit -> int
 abstract M2 : unit -> int
このインターフェースの一部だけを実装した抽象クラス
[<AbstractClass>]
type Bar() =
 interface IFoo with
  override x.M1() = 0
が作れないのでF#でthisをプロパティにするアプローチは微妙。