Skip to content

Commit

Permalink
solution1.6.2.2 added
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Roehler <[email protected]>
  • Loading branch information
andreas-roehler committed Jan 6, 2024
1 parent d92f1dd commit 3949f62
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions chapter01/worksheets/solution1.6.2.2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/** author: Andreas Röhler */

/**
Exercise 1.6.2.2
An integer n is called a “3-factor” if it is divisible by only three different integers i,j,k
such that 1 < i,j,k < n. Compute the set of all “3-factor” integers n among n ∈ [1, ..., 1000] .
*/

val p = (1 to 1000)
val q = (2 to 999)

val r = p.map(x => q.filter(y => (x != y) && (x % y == 0)) )
val s = p zip r
val t = s.map{ case (x, y) => (x, y.length) }
val result = t.filter{ case (x, y) => 3 == y }.map{ case (x, y) => x }

print("3-factor result among n ∈ [1, ..., 1000]: %s\n".format(result))

// 3-factor result among n ∈ [1, ..., 1000]: Vector(16, 81, 625)

0 comments on commit 3949f62

Please sign in to comment.