Skip to content

Question about task 1 and 2 #7

Description

@siripersson

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions