Number reversal game: Difference between revisions

no edit summary
m (syntax highlighting fixup automation)
No edit summary
Line 4,791:
8 : 1 2 3 4 5 6 7 8 9
You took 8 turns to put the digits in order.</pre>
 
=={{header|Vlang}}==
<syntaxhighlight lang="vlang">
import rand
import os
 
fn main() {
mut score, mut rnum := 0, 0
mut mix, mut unmix := []int{}, []int{}
for mix.len < 9 {
rnum = rand.int_in_range(1, 10) or {println('Error: invalid number') exit(1)}
if mix.contains(rnum) == false {
mix << rnum
}
}
unmix = mix.clone()
unmix.sort()
println("Select how many digits from the left to reverse.")
for {
print("The list is: ${mix} ==> How many digits to reverse? ")
input := os.input('').str().trim_space().int()
score++
if input == 0 || input < 2 || input > 9 {
println("\n(Enter a number from 2 to 9)")
continue
}
for idx, rdx := 0, input - 1; idx < rdx; idx, rdx = idx + 1, rdx - 1 {
mix[idx], mix[rdx] = mix[rdx], mix[idx]
}
if mix == unmix {
print("The list is: ${mix}.\n")
print("Your score: ${score}. Good job.\n")
break
}
}
}
</syntaxhighlight>
 
{{out}}
<pre>
Select how many digits from the left to reverse.
The list is: [3, 4, 9, 7, 6, 1, 5, 8, 2] ==> How many digits to reverse? 8
The list is: [8, 5, 1, 6, 7, 9, 4, 3, 2] ==> How many digits to reverse? 5
The list is: [7, 6, 1, 5, 8, 9, 4, 3, 2] ==> How many digits to reverse? 4
The list is: [5, 1, 6, 7, 8, 9, 4, 3, 2] ==> How many digits to reverse? 2
The list is: [1, 5, 6, 7, 8, 9, 4, 3, 2] ==> How many digits to reverse? 9
The list is: [2, 3, 4, 9, 8, 7, 6, 5, 1] ==> How many digits to reverse? 8
The list is: [5, 6, 7, 8, 9, 4, 3, 2, 1] ==> How many digits to reverse? 5
The list is: [9, 8, 7, 6, 5, 4, 3, 2, 1] ==> How many digits to reverse? 9
The list is: [1, 2, 3, 4, 5, 6, 7, 8, 9].
Your score: 8. Good job.
</pre>
 
=={{header|Wren}}==
291

edits