Skip to content

Instantly share code, notes, and snippets.

View jvrmaia's full-sized avatar
🤓
bug is feature for hackers

João Maia jvrmaia

🤓
bug is feature for hackers
View GitHub Profile
@jvrmaia
jvrmaia / hanoi.hs
Created July 14, 2012 18:02
Torre de Hanoi em Haskell
hanoi :: Int -> a -> a -> a -> [(a,a)]
hanoi 1 x y z = [(x,y)]
hanoi n x y z = hanoi (n-1) x y z ++ hanoi 1 x z y ++ hanoi (n-1) y z x
tamhanoi :: Int -> Int
tamhanoi n = 2^n - 1
@jvrmaia
jvrmaia / deriva.pl
Last active October 6, 2015 16:57
Programa em PROLOG para calcular derivada - Parte do trabalho de Linguagens de Programação
/* FUNÇÕES PARA DERIVADA */
/* regras básicas */
deriva(U+V,X,DU+DV):- deriva(U,X,DU), deriva(V,X,DV).
deriva(U-V,X,DU-DV):- deriva(U,X,DU), deriva(V,X,DV).
deriva(U*V,X,DU*V+U*DV):- deriva(U,X,DU), deriva(V,X,DV).
deriva(U/V,X,(DU*V+U*DV)/V^2):- deriva(U,X,DU), deriva(V,X,DV).
/* regra do polinômio */
deriva(U^N,X,N*U^(N-1)*DU):-