Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions go100/09-exercices/correction/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@ package main

import "fmt"

func realSyracuse(val, currentItern, maxIter int) (bool, int) {
if val == 1 {
return true, currentItern
} else if currentItern >= maxIter {
return false, currentItern
} else if val % 2 == 0 {
return realSyracuse(val / 2, currentItern+1, maxIter)
} else {
return realSyracuse(3*val + 1, currentItern+1, maxIter)
}
}

func recursiveSyracuse(val, nbMaxIteration int) (bool, int) {
return realSyracuse(val, 0, nbMaxIteration)
}

//syracuse prend en paramètre un entier et un nombre max d'itérations à effectuer.
//Elle retourne un booléen indiquant si le nombre 1 a été atteint, suivi du nombre d'itérations qui ont été effectuées.
func syracuse(start int, maxIterations int) (bool, int) {
Expand Down