Pancake numbers: Difference between revisions

Update Java/Kotlin a tiny it
(→‎modified (9th March 2021): corrected to 5th Dec 2020)
(Update Java/Kotlin a tiny it)
Line 387:
 
=={{header|Java}}==
===MaximumFast number of flips onlyapproximation===
{{trans|Go|Original algorithm from [[#Phix|Phix]]}}
<lang java>public class Pancake {
private static int pancake(int n) {
Line 418:
p(16) = 18 p(17) = 19 p(18) = 20 p(19) = 21 p(20) = 23 </pre>
 
===Maximum number of flips plus examples usingWith exhaustive search===
{{trans|Kotlin}}
Uses a standard breadth-first search using a queue. Note that because java is very verbose at defining classes, we instead had <code>pancake</code> return a <code>Map.Entry<List<Integer>, Integer></code> directly, rather than a dedicated named class. This is arguably bad practice, but keeps the snippet terse.
Line 548:
 
=={{header|Kotlin}}==
===MaximumFast number of flips onlyapproximation===
{{trans|CGo|OnlyOriginal thealgorithm algorithmfrom [[#Phix|Phix]]. The printing in main was adapted to use something more idiomatic, and a little less algorithmic.}}
<lang kotlin>fun pancake(n: Int): Int {
var gap = 2
Line 573:
p(16) = 18 p(17) = 19 p(18) = 20 p(19) = 21 p(20) = 23 </pre>
 
===Maximum number of flips plus examples usingUsing exhaustive search===
Using classic breadth-first search with running queue.
 
Line 583:
val stackFlips = mutableMapOf(initialStack to 1)
val queue = ArrayDeque(listOf(initialStack))
while (!queue.isEmptyisNotEmpty()) {
val stack = queue.removeFirst()
val flips = stackFlips[stack]!! + 1