Transformation p1 en 2 fonctions pour préparer p2
This commit is contained in:
parent
16791f2ae5
commit
bda2bcbb5f
1 changed files with 27 additions and 16 deletions
|
@ -30,17 +30,9 @@ func coordDansListe(l *list.List, e Coord) (bool) {
|
|||
return false
|
||||
}
|
||||
|
||||
func p_partie(file *os.File) {
|
||||
reader := bufio.NewReader(file)
|
||||
var pred Coord
|
||||
pred.x = 0
|
||||
pred.y = 0
|
||||
nbMaison := 1
|
||||
listeMaison := list.New()
|
||||
listeMaison.PushFront(pred)
|
||||
|
||||
for char, _, err := reader.ReadRune(); err != io.EOF; {
|
||||
switch string(char) {
|
||||
func nouvCoord(l *list.List, c string, pred Coord) (Coord, bool) {
|
||||
ret := false
|
||||
switch c {
|
||||
case "^":
|
||||
pred.y++
|
||||
case ">":
|
||||
|
@ -51,13 +43,32 @@ func p_partie(file *os.File) {
|
|||
pred.y--
|
||||
}
|
||||
|
||||
if !coordDansListe(listeMaison, pred) {
|
||||
if !coordDansListe(l, pred) {
|
||||
l.PushFront(pred)
|
||||
ret = true
|
||||
}
|
||||
|
||||
return pred, ret
|
||||
}
|
||||
|
||||
func p_partie(file *os.File) {
|
||||
reader := bufio.NewReader(file)
|
||||
var nouvMaison bool
|
||||
var pred Coord
|
||||
pred.x = 0
|
||||
pred.y = 0
|
||||
nbMaisons := 1
|
||||
listeMaison := list.New()
|
||||
listeMaison.PushFront(pred)
|
||||
nbMaison++
|
||||
|
||||
for char, _, err := reader.ReadRune(); err != io.EOF; {
|
||||
pred, nouvMaison = nouvCoord(listeMaison, string(char), pred)
|
||||
if nouvMaison {
|
||||
nbMaisons++
|
||||
}
|
||||
char, _, err = reader.ReadRune()
|
||||
}
|
||||
fmt.Printf("Il y a %d maisons déservies\n", nbMaison)
|
||||
fmt.Printf("Il y a %d maisons déservies\n", nbMaisons)
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
|
Loading…
Reference in a new issue