-
Notifications
You must be signed in to change notification settings - Fork 0
/
LevelTwoExercises.scala
executable file
·73 lines (57 loc) · 1.31 KB
/
LevelTwoExercises.scala
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
73
// def checkEven(num:Int): Boolean = {
// return num%2 == 0
// }
def checkEven(num:Int)= num%2 == 0
// println(checkEven(4))
// println(checkEven(3))
def checkList(numbers: List[Int]): Boolean = {
for (n <- numbers){
if (n%2==0){
return true
}
}
return false
}
// val evensample = List(1,2,3,4,5)
// val oddsample = List(1,3,5,7)
//
// println(checkList(evensample))
// println(checkList(oddsample))
def lucky(nums: List[Int]): Int = {
var output = 0
for (n <- nums){
if (n == 7){
output = output + 14
}else{
output = output + n
}
}
return output
}
// val numbers = List(1,2,3,7)
// println(lucky(numbers))
def balanceCheck(mylist: List[Int]): Boolean = {
var firsthalf = 0
var secondhalf = 0
secondhalf = mylist.sum
for (i <- Range(0,mylist.length)){
firsthalf = firsthalf + mylist(i)
secondhalf = secondhalf - mylist(i)
if (firsthalf == secondhalf){
return true
}
}
return false
}
// val ballist = List(1,2,3,4,10)
// val ballist2 = List(2,3,3,2)
// val unballist = List(10,20,70)
//
// println(balanceCheck(ballist))
// println(balanceCheck(ballist2))
// println(balanceCheck(unballist))
def palindromeCheck(st:String): Boolean = {
return (st == st.reverse)
}
println(palindromeCheck("abccba"))
println(palindromeCheck("hello"))