File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -3248,8 +3248,8 @@ In order to achieve greater coverage and encourage more people to contribute to
3248
3248
</a>
3249
3249
</td>
3250
3250
<td> <!-- Scala -->
3251
- <a href="./CONTRIBUTING.md ">
3252
- <img align="center" height="25" src="./logos/github .svg" />
3251
+ <a href="./src/scala/Bogosort.scala ">
3252
+ <img align="center" height="25" src="./logos/scala .svg" />
3253
3253
</a>
3254
3254
</td>
3255
3255
<td> <!-- Kotlin -->
Original file line number Diff line number Diff line change
1
+ import scala .annotation .tailrec
2
+ import scala .util .Random
3
+
4
+
5
+ @ tailrec
6
+ def isSorted (data : Seq [Int ]): Boolean = {
7
+ if (data.size < 2 ) true
8
+ else if (data(0 ) > data(1 )) false
9
+ else isSorted(data.tail)
10
+ }
11
+
12
+
13
+ @ tailrec
14
+ def bogosort (data : Seq [Int ]): Seq [Int ] = {
15
+ val result : Seq [Int ] = Random .shuffle(data)
16
+ if (isSorted(result)) result
17
+ else bogosort(data)
18
+ }
19
+
20
+
21
+ object Main extends App {
22
+ val data : Seq [Int ] = Seq .fill(10 )(Random .nextInt(10 ))
23
+ println(s " Unsorted data: $data" )
24
+ println(s " Sorted data: ${bogosort(data)}" )
25
+ }
You can’t perform that action at this time.
0 commit comments