Escolar Documentos
Profissional Documentos
Cultura Documentos
Paulo Torrens
paulotorrens@gnu.org
20 de Outubro de 2017
“É só aprender lógica de
programação que você aprende
todas as linguagens, só muda a
sintaxe.”
e ::= x | λx.e | e e
ZERO = λf .λx . x
ONE = λf .λx . f x
TWO = λf .λx . f (f x)
THREE = λf .λx . f ( f ( f x ))
FOUR = λf .λx . f ( f ( f ( f x )))
TRUE = λt .λe . t
FALSE = λt .λe . e
IF = λp .λt .λe . p t e
Y = λf .(λx . f ( x x )) (λx . f ( x x ))
take2 =
filter ((==2) ◦ length ) ◦ map ( take 2) ◦ tails
doLZW _ [] = []
doLZW as ( x : xs ) =
lzw ( map return as ) [ x ] xs
where
lzw a w [] = [ fromJust $ elemIndex w a ]
lzw a w ( x : xs ) =
if w ’ ∈ a then
lzw a w ’ xs
else
let rest = lzw ( a + + [w ’]) [ x ] xs
in fromJust ( elemIndex w a ) : rest
where w ’ = w + + [x]
solution ( [ ] ) .
s o l u t i o n ( [ X/Y | O t h e r s ] ) :−
s o l u t i o n ( Others ) ,
member (Y , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] ) ,
n o a t t a c k (X/Y , O t h e r s ) .
n o a t t a c k (_ , [ ] ) .
n o a t t a c k (X/Y , [ X1/Y1 | O t h e r s ] ) :−
Y =\= Y1 ,
Y1 − Y =\= X1 − X ,
Y1 − Y =\= X − X1 ,
n o a t t a c k (X/Y , O t h e r s ) .