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.IO | |
let ReadLines fn = | |
seq { use inp = File.OpenText fn in | |
while not(inp.EndOfStream) do | |
yield (inp.ReadLine()) | |
} | |
#load @"FSharpChart.fsx" | |
#load @"FSharpChartAutoDisplay.fsx" | |
open Samples.Charting |
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
// Simple counter | |
type cell = { mutable content : int } | |
let new_counter n = | |
let x :cell = { content = n } | |
fun () -> | |
(x.content <- x.content+1; x.content) | |
// The same, using F# refs | |
let new_counter' n = |
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 | |
let read() = | |
printf ">" | |
let s = Console.ReadLine() | |
try | |
Some((int)s) | |
with | |
_ -> None |
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
(* Nondeterministic *) | |
type Nondet<'a> = 'a list | |
let ret x = [x] | |
let ret' x = x | |
let fail = [] | |
let (>>=) mA b = List.collect b mA | |
ret' [1;2;3] >>= fun x -> | |
[x+1;x+2] |
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
// Simple computations | |
let read() = System.Int32.Parse(System.Console.ReadLine()) | |
let double x = x*2 | |
let print x = printfn "%d" x | |
(read >> double >> print)() | |
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 | |
let L = 14. // Space between wheels || Your values might be quite different | |
let R = 2.7 // Wheel's radius || | |
let ticksPerRotation = 12000. // ~ amount of ticks is taken by one full rotation | |
let desiredAngle = int ((L/R/4.) * ticksPerRotation) // Math routine to calculate how many ticks is taken to turn | |
type Direction = Forward | Backward | Left | Right | |
// <Twitter boilerplate part> |
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 id = string | |
type expr = | |
| Var of id | |
| Lam of id*expr | |
| App of expr*expr | |
| Int of int | |
| Cond of expr*expr*expr | |
| Let of id*expr*expr | |
| LetRec of id*expr*expr | |
| PFunc of id |
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 | |
open System.IO | |
let read fn = File.ReadAllLines(sprintf "%s\%s" __SOURCE_DIRECTORY__ fn) | |
let data = read @"trainingsample.csv" | |
type Example = { Label:int; Pixels:int[] } | |
let prepare (x:string[]) = | |
let res = | |
x.[1..] | |
|> Array.map (fun x-> x.Split(',')|>Array.map int) |
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 rec ins z = function | |
| [] -> [[z]] | |
| x::xs -> | |
let res = ins z xs | |
let res1 = List.map (fun t -> x::t) res | |
(z::x::xs)::res1 | |
let rec ins z = function | |
| [] -> [[z]] | |
| x::xs as L -> |
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
from os.path import basename | |
def get_text(s): | |
return ' '.join([x['text'] for x in s]) | |
os.makedirs('text',exist_ok=True) | |
for fn in glob.glob('noncomm_use_subset/pdf_json/*'): | |
with open(fn) as f: | |
x = json.load(f) | |
nfn = os.path.join('text',basename(fn).replace('.json','.txt')) |