Skip to content

Instantly share code, notes, and snippets.

View ihavenonickname's full-sized avatar
🔬
Searching

Gabriel ihavenonickname

🔬
Searching
  • The Future
View GitHub Profile
@ihavenonickname
ihavenonickname / script.py
Last active January 23, 2018 12:16
r/learnpython 23-01-2018
def none_slice_gabriel(lst, start, stop):
i = start
while i < 0 and i < stop:
yield None
i += 1
while i < len(lst) and i < stop:
yield lst[i]
i += 1
@ihavenonickname
ihavenonickname / something-better.peg
Last active December 9, 2017 18:55
i dont know what im doing
Expr0 = Ws expr:(Appl / Expr1) Ws {
return expr
}
Expr1 = expr:(Func / Name / Expr0Parenthesis) {
return expr
}
Expr0Parenthesis = '(' expr:Expr0 ')' {
return expr
@ihavenonickname
ihavenonickname / Program.fs
Last active March 15, 2017 02:12
Hello genetic algorithms
let chanceToMutate = 5
let possibleChars = Array.append [|'A'..'Z'|] [|' '|]
let random = new System.Random()
let randomChar () =
let index = random.Next(Array.length possibleChars)
Array.item index possibleChars
@ihavenonickname
ihavenonickname / Program.fs
Last active October 26, 2016 20:45
fsharp matrix multiplication
let transposeColumn matrix index =
seq { for row in matrix -> Seq.item index row }
let transposeMatrix matrix =
matrix
|> Seq.mapi (fun index _ -> transposeColumn matrix index)
let multiplyRows row1 row2 =
Seq.zip row1 row2
|> Seq.map (fun (a, b) -> a * b)
class Graph(object):
def __init__(self):
self.g = {}
def add(self, vertex1, vertex2, weight):
if vertex1 not in self.g:
self.g[vertex1] = {}
if vertex2 not in self.g:
self.g[vertex2] = {}
type FiniteAutomaton<'a> = {
InitialState: string
FinalStates: Set<string>
Transitions: Map<string * char, 'a>
}
type DeterministicFiniteAutomaton = FiniteAutomaton<string>
type NondeterministicFiniteAutomaton = FiniteAutomaton<string List>
let private nextState symbol state fa =
fa.Transitions |> Map.tryFind (state, symbol)