Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
27
Task/Nim-game/Swift/nim-game.swift
Normal file
27
Task/Nim-game/Swift/nim-game.swift
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
var tokens = 12
|
||||
|
||||
while tokens != 0 {
|
||||
print("Tokens remaining: \(tokens)\nPlease enter a number between 1 and 3: ", terminator: "")
|
||||
|
||||
guard let input = readLine(), let n = Int(input), n >= 1 && n <= 3 else {
|
||||
fatalError("Invalid input")
|
||||
}
|
||||
|
||||
tokens -= n
|
||||
|
||||
if tokens == 0 {
|
||||
print("You win!")
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
print("I'll remove \(4 - n) tokens.")
|
||||
|
||||
tokens -= 4 - n
|
||||
|
||||
if tokens == 0 {
|
||||
print("I win!")
|
||||
}
|
||||
|
||||
print()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue