Skip to content

Instantly share code, notes, and snippets.

View alarsyo's full-sized avatar
🧑‍💻
tinkering

Antoine Martin alarsyo

🧑‍💻
tinkering
View GitHub Profile
@alarsyo
alarsyo / string_tools.ml
Last active March 23, 2016 19:16
String tools
yourstring.[i] ;; (* retourne le caractère de rang i de ta chaîne de caractères *)
"exemple".[4] ;;
(* - : char = 'p' *)
(* le rang va de 0 à (n-1), attention ! *)
String.make n char ;; (* construit à partir de ton caractère char une string longue de n caractères *)
String.make 1 'e' ;;
(* - : string = "e" *)
@alarsyo
alarsyo / char_list_list.ml
Last active March 23, 2016 19:20
TP03 3.2
(* ---3.2 char list list...--- *)
let rec sentence_to_single_list morse_sentence = match morse_sentence with
|[] -> []
|[]::sentence -> '/' :: sentence_to_single_list sentence (* on ajoute un '/' si le mot est fini *)
|([]::word)::sentence -> ' ' :: sentence_to_single_list (word::sentence) (* on ajoute un espace ' ' si la lettre est finie *)
|((e::letter)::word)::sentence -> e :: (sentence_to_single_list ((letter::word)::sentence)) ;; (* on extrait un caractère d'une lettre en morse pour le mettre dans notre liste *)
(* val sentence_to_single_list : char list list list -> char list = <fun> *)
sentence_to_single_list (sentence_to_morse [['y'; 'o']; ['d'; 'a'; 'w'; 'g']]) ;;
@alarsyo
alarsyo / get_cell.ml
Created March 29, 2016 18:02
TP04 3.1
(* --- 3.1 Cellule --- *)
let get_cell (x, y) board =
let rec row list n = match (list, n) with (* this function reads the y value of the row sent by column *)
|[], _ -> invalid_arg "y coordinate doesn't exist !"
|e::l, 1 -> e (* return the cell value *)
|e::l, n -> row l (n-1)
in let rec column board n = match (board, n) with (* this function sends the correct row (our 'int list' inside our 'list') to the 'row' function *)
|[], _ -> invalid_arg "x coordinate doesn't exist !"
|e::l, 1 -> row e y (* when column reaches the correct n, it sends the selected row to the 'row' function along with the y parameter *)
@alarsyo
alarsyo / correction_tp5.ml
Last active April 21, 2016 08:59
Correction du TP5 Caml
type 'a bundle =
| Empty
| Item of 'a * 'a bundle
;;
let empty_bundle () = Empty ;;
let cons bundle element = Item (element, bundle);;
@alarsyo
alarsyo / perfect.py
Created May 11, 2016 13:35
Perfect number
def sumDivs(n,accu, i):
if i > (n//2):
return accu
elif n % i == 0:
print(i)
return sumDivs (n, accu + i , i+1)
else :
return sumDivs (n, accu, i+1)
@alarsyo
alarsyo / list9.py
Last active May 12, 2016 13:53
List 9 python
def checkValidlist9AB(n):
a = n // 10
b = n % 10
return (a != b)
def checkValidlist9(n):
return (n > 9 and n < 100)
false || (1/0 = 0);;
true || (1/0 = 0);;
false && (1/0 = 0);;
true && (1/0 = 0);;
'Z' < 'a';;
"A long sentence to see how string comparisons work" > "a little one";;
(* to see how functions with several parameters work *)
@alarsyo
alarsyo / td5.py
Last active September 22, 2016 19:45
### Correction des fonctions du lundi 19/09 ###
def print_mat(M, d):
s = "| {:" + str(d) + "d}"
l = len(M[0])
t = '-' * (d+3) * l + '-'
for i in range(len(M)):
print(t)
for j in range(l):
print(s.format(M[i][j]), end=' ')
@alarsyo
alarsyo / matrix.py
Created December 23, 2016 22:08
Matrix rotation
def rotateMatrix(matrix):
newMatrix = []
l = len(matrix)
for i in range(l):
newMatrix.append([])
for j in range(l):
newMatrix[i].append(matrix[l - 1 - j][i])
return newMatrix
@alarsyo
alarsyo / solution.sh
Last active February 7, 2017 18:23
TP1 THLR
#!/bin/sh
# EX 1
perl -0777 -pe 's/{.*}/COMMENTAIRE/gsm' exo1/q1
perl -0777 -pe 's/{[^}]*}/COMMENTAIRE/gsm' exo1/q2
# EX 2
perl -0777 -pe 's/"[^"]*"/CHAINE/gsm' exo2/q1
perl -0777 -pe 's/"([^"\\]|\\.)*"/CHAINE/gsm' exo2/q2