This file contains 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
import os | |
import bz2 | |
from pathlib import Path | |
files = list(Path('.').rglob('*.*')) | |
for file in files: | |
if file.name == __file__: continue | |
if file.suffix == '.bz2': continue |
This file contains 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
# Using Mercator projection formula | |
def mercator(lon, lat, width = 14, height = 8): | |
lon, lat, width, height = float(lon), float(lat), float(width), float(height) | |
r = width / (2 * PI) | |
x = r * np.radians(lon) | |
y = (height / 2) - r * np.log(np.tan(PI / 4 + np.radians(lat) / 2)) | |
return np.array([x, y, 0]) |
This file contains 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 'a cell_lc = { tete : 'a ; queue : 'a lc } | |
and 'a lc = ListecVide | Listec of 'a cell_lc | |
let tete = function | |
| ListecVide -> failwith "Liste vide" | |
| Listec(cell) -> cell.tete | |
let queue = function | |
| ListecVide -> ListecVide | |
| Listec(cell) -> cell.queue |
This file contains 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 member x = function | |
| [] -> false | |
| h :: t when x = h -> true | |
| h :: t -> member x t | |
let rec subset a = function (* quite dumb, in O(n²) *) | |
| [] -> true | |
| h :: t when (member h a) -> subset a t | |
| h :: t -> false |
This file contains 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 begaie b = | |
let rec begaie_aux l = function | |
| [] -> l | |
| h :: t -> begaie_aux (h :: h :: l) t | |
in | |
List.rev (begaie_aux [] b) | |
(* sans utiliser List.rev (et donc sans la version récursive terminale) | |
let rec begaie = function |
This file contains 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 lmax = 100 | |
type 'a stack = { tab: 'a array; mutable length: int } | |
let empty default = | |
{ tab = Array.make lmax default; length = 0 } | |
let push x stack = match stack with | |
| { tab = _; length = 100 } -> failwith "Stack overflow" | |
| { tab = t; length = n } -> t.(n + 1) <- x; stack.length <- n + 1 |
This file contains 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
(* Empty the list l into m, reversing it *) | |
let rec clear l m = match l with | |
| [] -> m | |
| h :: t -> clear t (h :: m) | |
type 'a file = {top: 'a list; back: 'a list} | |
let empty () = {top= []; back = []} | |
let add a f = match f with |
This file contains 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
(* Evaluate postfixed expressions *) | |
type 'a status = | |
Number of 'a | |
|Operator of ('a -> 'a -> 'a) | |
|Function of ('a -> 'a) | |
let eval exp = | |
let s = Stack.create () in | |
let n = Array.length exp in |
This file contains 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 Printf | |
let rec ackermann n p = | |
if n = 0 then p + 1 | |
else if p = 0 then ackermann (n - 1) 1 | |
else ackermann (n - 1) (ackermann n (p - 1)) | |
(* Returns the list's head *) | |
let head = function | |
| [] -> failwith "Incorrect list, sorry man" |
NewerOlder