About
object G1 {
def main(args:Array[String])= {
var T1 = Array(1,2,3,5,4)
var index = 0
var last = T1.length - 1
var temp1 = 0
var temp2 = 0
while(index < last) {
temp1 = T1(index)
temp2 = T1(last)
T1(index) = temp2
T1(last) = temp1
index = index + 1
last = last -1
}
for ( x <- T1) {
print(s"${x}, ")
}
print("\n")
var T2 = Array(1,2,3,9,8,7)
var T3 = T1.intersect(T2)
for(x <- T3){
print(s"${x},")
}
print("\n")
var a1 = T1.max
var a2 = T1.min
var a3 = a1 - a2
print(a3)
print("\n")
var T4 = T2.toList
T4 = T4.reverse
var T5 = T4.toArray
for(x<-T5){
print(s"${x},")
}
var a4 = Array(-1,-2,-4,-5,7,8,9,6)
} }
chain :: (Integral a) => a ->[a]
chain 1 = [1]
chain n
|even n = n:chain(ndiv
2)
| odd n = n:chain(n*3 + 1)
numLongChains::Int numLongChains = length(filter isLong(map chain [1..1000])) where isLong xs = length xs > 15
zipWith'::(a->b->c)->[a]->[b]->[c] zipWith' _ [] _=[] zipWith' _ _ [] = [] zipWith' f (x:xs) (y:ys) = f x y : zipWith' f xs ys
sumallodd::Int sumallodd = sum(takeWhile(<10000)(filter odd(map(^2)[1..])))
sumoddsquares::Int sumoddsquares = sum(takeWhile (<1000) (filter odd(map (^2) [1..])))
sumevensquares::Int sumevensquares = sum(takeWhile (<1000) (filter even(map (^2)[1..])))