-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathejsClase03.hs
executable file
·72 lines (50 loc) · 1.73 KB
/
ejsClase03.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
factorial :: Integer -> Integer
factorial n | n == 0 = 1
| n > 1 = n * factorial (n-1)
esPar :: Int -> Bool
esPar n | n == 0 = True
| n == 1 = False
| otherwise = esPar (n-2)
fib :: Int -> Int
fib n | n == 0 = 0
| n == 1 = 1
| otherwise = fib(n-1) + fib(n-2)
{-
toInt :: Float -> Int Esto tiene que tener algun truco para pasar
toInt n | n >= 0 && n < 1 = 0 de float a int/integer
-}
parteDecimal :: Float -> Float
parteDecimal n | n < 1 && n >= 0 = n
| n < 0 = 0
| otherwise = parteDecimal(n-1)
parteEntera :: Float -> Float
parteEntera n | n > 0 = (n - parteDecimal(n))
| otherwise = 0
div3 :: Int -> Bool
div3 n | n < 3 = False
| n == 3 = True
| otherwise = div3(n-3)
sumaImpares :: Int -> Int
sumaImpares n | n == 1 = 1 --1 + 3 + 5 + 7 + 9
| otherwise = (2 * n - 1) + sumaImpares(n-1)
mediofact :: Int -> Int
mediofact n | n == 0 = 1
| n == 1 = 1
| n >= 2 = n * mediofact (n-2)
-- traigo una func de la clase 1
digitoUnit :: Int -> Int
digitoUnit x = mod x 10
digitoDec :: Int -> Int
digitoDec x = div (mod x 100) 10
-- listo
sumDig :: Int -> Int
sumDig n | n >= 0 && n < 10 = digitoUnit(n)
| otherwise = (digitoUnit(n) + sumDig(div n 10))
digIguales :: Int -> Bool
digIguales n | n < 10 && n >= 0 = True
| n < 0 = digIguales(-n)
| mod n 10 == 0 = False
| (d == 1) && div n 100 == 0 = True
| (d == 1) && div n 100 /= 0 = digIguales(div n 10)
| otherwise = False
where d = div (digitoDec n) (digitoUnit n)