Skip to content

Instantly share code, notes, and snippets.

View trygvea's full-sized avatar

Trygve Matland Amundsen trygvea

View GitHub Profile
@trygvea
trygvea / ml.ts
Created February 26, 2019 19:46
Machine learning - pedagogical
type Data = number[]
type Observation = number
type Prediction = Observation
function learn(xs: Data[], ys: Observation[]) {
return (x: Data): Prediction => {
// use xs and ys to predict outcome of x
return 1
}
}
@trygvea
trygvea / learn_to_add.ts
Last active February 26, 2019 21:22
Machine learning - learn to add
import * as tf from '@tensorflow/tfjs'
/*
* Experiment with
* - multiplication, combined (ie x1+3*x2). May have to train 500 epochs to get satisfactory results.
*/
const randomInt = (max: number) =>
Math.floor(Math.random() * Math.floor(max))
@trygvea
trygvea / ShortestPathAlgorithm.kt
Created January 13, 2021 11:53
Djikstras shortest path algorithm in kotlin
package algorithms.shortestpath
interface Node
data class Edge(val node1: Node, val node2: Node, val distance: Int)
/**
* See https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm
*/
fun findShortestPath(edges: List<Edge>, source: Node, target: Node): ShortestPathResult {
@trygvea
trygvea / permutations.kt
Created February 10, 2021 10:52
Kotlin Permutations
package foo
fun <T> permutations(list: List<T>): List<List<T>> = when {
list.size > 10 -> throw Exception("You probably dont have enough memory to keep all those permutations")
list.size <= 1 -> listOf(list)
else ->
permute(list.drop(1)).map { perm ->
(list.indices).map { i ->
perm.subList(0, i) + list.first() + perm.drop(i)
}
#!/bin/bash
# Smcn
# =============
if [ $# -eq 0 ]; then
echo "Enter date and module, ex 20-05-2021-modul-6"
exit
fi
#!/usr/bin/env python3
"""
Very simple HTTP server in python for logging requests
Usage::
./server.py [<port>]
"""
from http.server import BaseHTTPRequestHandler, HTTPServer
import logging
import json