My code for task 1 is the following:
val textFile = sc.textFile("data/dna.txt")
textFile.count(c => c == 'g')
val linesWithCG = textFile.filter(line => line.contains("cg")).count()
linesWithCG
Which gives the result: 164
Bu when I check the text file "dna.txt" the occurrence of "cg" seems to be much more.
My code for task 2:
val n = 1000
val count = sc.parallelize(1 to n)
.map { _ =>
val x = math.random
val y = math.random
if(x*x + y*y < 4) 1 else 0
}.reduce(_+_)
val result =(1-0)*4.0*(count / n)
println(result)
Which gives the result: 4.0
But it seems to big to be correct.
My code for task 1 is the following:
Which gives the result: 164
Bu when I check the text file "dna.txt" the occurrence of "cg" seems to be much more.
My code for task 2:
Which gives the result: 4.0
But it seems to big to be correct.