Skip to content

Instantly share code, notes, and snippets.

View fotonmoton's full-sized avatar

Gregory fotonmoton

  • Ukraine
View GitHub Profile
package main
import (
"fmt"
"math/rand"
"time"
)
type image int
@fotonmoton
fotonmoton / main.go
Created October 6, 2023 19:08
Golang Closures for decorator/middleware pattern
package main
import "fmt"
func Decorator(fn func(string)) func(string) {
return func(s string) {
fmt.Println("-----")
fn(s)
fmt.Println("-----")
}
package queue
type Queue[T any] interface {
Enqueue(T)
Dequeue() T
Size() int
IsEmpty() bool
}
// We use linked list as internal data structure
type Point = (int * int)
let path1 = """R999,D467,L84,D619,L49,U380,R287,U80,R744,D642,L340,U738,R959,U710,R882,U861,L130,D354,L579,D586,R798,D735,L661,D453,L828,U953,R604,D834,R921,D348,R620,U775,R364,U552,L221,U119,R590,U29,L267,D745,L128,U468,L978,D717,R883,D227,R691,D330,L33,U520,L862,D132,R99,U400,L455,U737,L603,U220,L689,U131,R158,D674,R617,D287,R422,U734,L73,U327,L525,D245,R849,D692,R114,U136,R762,D5,R329,U429,L849,U748,R816,U556,R614,D412,R416,D306,R307,U826,R880,U936,L164,U984,L689,D934,R790,D14,R561,D736,L3,D442,R301,D520,L451,U76,R844,D307,L144,D800,L462,D138,R956,U225,L393,D186,L924,D445,L86,D640,L920,D877,L197,U191,L371,D701,R826,D282,R856,D412,L788,D417,R69,D678,R978,D268,L268,U112,L69,U164,L748,U191,R227,D227,R59,U749,R134,U779,R865,U247,R55,D567,R821,U799,R937,D942,L445,D571,R685,D111,R107,D769,R269,D968,R102,U335,R538,U125,L725,D654,R451,D242,R777,U813,R799,D786,L804,U313,L322,U771,R219,U316,L973,U963,R84,D289,R825,D299,L425,D49,R995,D486,R550,D789,R735,D501,R966,U955,R432,U635,L353,D600,R67
module GradeSchool
type School = Map<int, string list>
let empty: School = Map.empty
let add student grade school: School =
let addTo school grade students = Map.add grade students school
let programCode = "1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,1,9,19,1,10,19,23,2,9,23,27,1,6,27,31,2,31,9,35,1,5,35,39,1,10,39,43,1,10,43,47,2,13,47,51,1,10,51,55,2,55,10,59,1,9,59,63,2,6,63,67,1,5,67,71,1,71,5,75,1,5,75,79,2,79,13,83,1,83,5,87,2,6,87,91,1,5,91,95,1,95,9,99,1,99,6,103,1,103,13,107,1,107,5,111,2,111,13,115,1,115,6,119,1,6,119,123,2,123,13,127,1,10,127,131,1,131,2,135,1,135,5,0,99,2,14,0,0"
let translate (programCode: string) =
let restore (codes: int array) =
codes.[1] <- 12
codes.[2] <- 2
codes
@fotonmoton
fotonmoton / Raindrops.fs
Created November 24, 2019 15:52
Raindrops
module Raindrops
let convert number =
let getSound (divider, sound) =
if (number % divider = 0)
then sound
else ""
let getSoundString drops =
module BankAccount
type Account = decimal option ref
let mkBankAccount(): Account = ref None
let openAccount (account: Account): Account =
account := Some 0m
account
module QueenAttack
let create (row, col) =
row >= 0 && row < 8 && col >= 0 && col < 8
let canAttack (row1, col1) (row2, col2) =
row1 = row2 || col1 = col2 || (abs (row1 - row2) = abs (col1 - col2))
module QueenAttack
let create (row, col) =
row >= 0 && row < 8 && col >= 0 && col < 8
let directions =
[ (-1, 0)
(-1, -1)
(0, -1)
(1, -1)