-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput2.txt
More file actions
61 lines (53 loc) · 1.07 KB
/
input2.txt
File metadata and controls
61 lines (53 loc) · 1.07 KB
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
facL ( n ) :: int -> int {
return product (fromTo ( 1, n ));
}
product ( list ) :: [ int ] -> int {
if ( isEmpty ( list ) ) {
return 1;
} else {
return list.hd * product ( list.tl );
}
}
fromTo ( from , to ) :: int int -> [ int ] {
if ( from <= to ) {
return from : fromTo ( from + 1, to );
} else {
return [] ;
}
}
reverse ( list ) :: [ t ] -> [ t ] {
var accu = [] ;
while ( ! isEmpty ( list ) ) {
accu = list.hd : accu ;
list = list.tl ;
}
return accu ;
}
abs ( n ) :: int -> int { if (n < 0) {return -n;} else {return n ;} }
swapCopy ( pair ) :: (a, b) -> (b, a) {
return ( pair.snd, pair.fst );
}
swap ( tuple ) :: (a, a) -> (a, a) {
var tmp = tuple.fst ;
tuple.fst = tuple.snd;
tuple.snd = tmp;
return tuple ;
}
append ( l1 , l2 ) :: [ t ] [ t ] -> [ t ] {
if ( isEmpty ( l1 ) ) {
return l2 ;
} else {
l1.tl = append ( l1.tl , l2 );
return l1 ;
}
}
squareOddNumbers ( list ) :: [ int ] -> [ int ] {
while (! isEmpty ( list ) && list.hd % 2 == 0) {
list = list.tl ;
}
if ( ! isEmpty ( list ) ) {
list.hd = list.hd * list.hd;
list.tl = squareOddNumbers( list.tl );
}
return list ;
}