Pancake numbers: Difference between revisions

Content added Content deleted
(Add Cowgol)
Line 642: Line 642:
19 21
19 21
20 23
20 23
</pre>

=={{header|Ring}}==
{{trans|C}}
<lang ring>
for i = 0 to 3
for j = 1 to 5
n = i * 5 + j
see "p(" + n + ") = " + pancake(n) + nl
next
next
return 0

func pancake(n)
gap = 2
sum = 2
adj = -1;
while (sum < n)
adj = adj + 1
gap = gap * 2 - 1
sum = sum + gap
end
return n + adj
</lang>
Output:
<pre>
p(1) = 0
p(2) = 1
p(3) = 3
p(4) = 4
p(5) = 5
p(6) = 7
p(7) = 8
p(8) = 9
p(9) = 10
p(10) = 11
p(11) = 13
p(12) = 14
p(13) = 15
p(14) = 16
p(15) = 17
p(16) = 18
p(17) = 19
p(18) = 20
p(19) = 21
p(20) = 23
</pre>
</pre>