Skip to content

Instantly share code, notes, and snippets.

let isPrime (n: int) =
let max = sqrt (float32 n) |> int
let rec check m =
if m > max then true
elif n % m = 0 then false
else check (m+1)
check 2
let n = 600851475143L //
let rec fib n =
match n with
| 0 -> 1
| 1 -> 2
| x -> fib (x - 1) + fib (x - 2)
Seq.initInfinite fib
|> Seq.takeWhile (fun n -> n <= 4_000_000)
|> Seq.filter (fun n -> n % 2 = 0)
|> Seq.sum
let count = cval 10
let set = cset {
let! c = count
for i = 1 to c do yield int64 i
}
let sum = set |> CSet.sumBy id
count.SetValue 10
let makeQuad a b h=
let x0, y0, z0 = a
let x1, y1, z1 = b
let c = x1, y1 + h, z1
let d = x0, y0 + h, z0
(a, b, c), (a, c, d)
@vietnt
vietnt / example.fs
Last active December 29, 2020 21:54
unsafe in f#
[<Struct;StructLayout(LayoutKind.Explicit, Pack=1,Size=32)>]
type Bucket =
struct
[<FieldOffset(0)>]val mutable Free : int64
[<FieldOffset(8)>]val mutable FreeCount: int
[<FieldOffset(12)>]val mutable Used: int
[<FieldOffset(16)>]val mutable Size: int
[<FieldOffset(20)>]val mutable Full: bool
end
let inline drawQuadTexture (x0, y0, u0, v0, c0) (x1, y1, u1, v1, c1) (x2, y2, u2, v2, c2) (x3, y3, u3, v3, c3) add vbo =
vbo |> add x0 y0 u0 v0 c0
vbo |> add x1 y1 u1 v1 c1
vbo |> add x3 y3 u3 v3 c3
vbo |> add x1 y1 u1 v1 c1
vbo |> add x2 y2 u2 v2 c2
vbo |> add x3 y3 u3 v3 c3
open System
open System.Drawing
open System.Drawing.Imaging
let perlinNoise width height persistence octaves zoom seed bias amplitudeBias handler =
let inline noise x y =
let n = x + y * 57;
let n = (n <<< 13) ^^^ n
1.0 - (float ((n * (n * n * 15731 + 789221) + 1376312589) &&& 0x7fffffff)) / 1073741824.0
//// See the 'F# Tutorial' project for more help.
//
open System
type Command =
| Block of string * TimeSpan
| Unblock of string
| IsBlocked of string
let maxTimeSpan = TimeSpan.FromDays (365*1000 |> float)
public class UChecker:IDisposable
{
public int[,] CardSet;
public int[,] PhomMark;
private int _countNotPickedCard;
private int _countCardNotInPhom;
public int CountCardNotInPhom { get { return _countCardNotInPhom;} set{ _countCardNotInPhom = value;}}
private int _countEatenCardInHand;
let inline isPhom x y z =
let sx, sy, sz = x%13,y%13,z%13
if sx = sy && sy = sz then true
else
let tx, ty, tz = x/13, y/13, z/13
if tx = ty && ty = tz then
let a = max sx sy |> max sz
let c = min sx sy |> min sz
let b = (sx + sy + sz)/3
a = b + 1 && a = c + 2