Skip to content

Commit 56aa018

Browse files
committed
Add fatorial em scala
1 parent 0d3d6b8 commit 56aa018

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -871,8 +871,8 @@ Com o objetivo de alcançar uma abrangência maior e encorajar novas pessoas a c
871871
</a>
872872
</td>
873873
<td> <!-- Scala -->
874-
<a href="./CONTRIBUTING.md">
875-
<img align="center" height="30" src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/github/github-original.svg" />
874+
<a href="./src/scala/Fatorial.scala">
875+
<img align="center" height="30" src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/scala/scala-original.svg" />
876876
</a>
877877
</td>
878878
</tr>

src/scala/Fatorial.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
def fatorial(n: Long): Long = (1L to n).product
3+
4+
object Main extends App {
5+
val data: Map[Long, Long] = Map(
6+
0L -> 1L,
7+
1L -> 1L,
8+
5L -> 120L,
9+
20L -> 2432902008176640000L
10+
)
11+
data.foreach{ (key, value) =>
12+
val result: Long = fatorial(key)
13+
assert(result == value)
14+
println(s"Fatorial($key): $result")
15+
}
16+
}

0 commit comments

Comments
 (0)