Petit exercice algorithmique en Swift

leon44
1,723 views
undefined

Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content

Les 64 fenêtres

Présentation

Exercice 1

Ecrire un programme permettant d'afficher l'état des 64 fenêtres sous la forme d'un tableau de String.

Exercice 1
class swift_template_fenetre{
static func solve(fenetres:[String])-> [String]{
return ["F", "F", "F", "G", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "G", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F"]
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Exercice 2

Modifiez le programme de façon à renvoyer les numéros des visiteurs qui ont gagné à ce jeu. Le résultat est un tableau de Int.

Exercice 2
class swift_template_fenetre2{
static func getWinner(fenetres:[String])-> [Int]{
return [0]
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Exercice 3

Modifiez le code précédent de façon à faire gagner avec une nouvelle règle:

On déclare gagant tous les visiteurs dont le numéros de brassard est égal aux numéros de fenêtres ouvertes (position 0).

Exercice 3
class swift_template_fenetre3{
static func getWinnerVersion2(fenetres:[String])-> [Int]{
return [0]
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Référence

Livre de l'exercice

Open Source Your Knowledge: become a Contributor and help others learn. Create New Content