Skip to content

Commit 3de734e

Browse files
committed
add cutAllStartPositions body
1 parent fb01518 commit 3de734e

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/main/java/com/google/hashcode/utils/DFSMethods.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package com.google.hashcode.utils;
22

33
import com.google.hashcode.entity.Cell;
4+
import com.google.hashcode.entity.Ingredient;
45
import com.google.hashcode.entity.Pizza;
56
import com.google.hashcode.entity.Slice;
67
import com.google.hashcode.entity.Step;
78
import org.slf4j.Logger;
89
import org.slf4j.LoggerFactory;
910

1011
import java.util.ArrayList;
12+
import java.util.Iterator;
1113
import java.util.List;
1214
import java.util.Optional;
1315
import java.util.stream.Collectors;
@@ -76,7 +78,19 @@ Slice performStep(Pizza pizza, List<Step> steps) {
7678

7779
List<Slice> cutAllStartPositions(Pizza pizza) {
7880
//TODO pick-ups a step with a minimal steps number, execute it(cut it from the pizza, and a slice). The pizza is a mutable object
79-
return new ArrayList<>();
81+
List<Cell> currentPizza = pizza.getCells();
82+
List<Slice> starts = new ArrayList<Slice>();
83+
Iterator<Cell> iter = currentPizza.iterator();
84+
while(iter.hasNext()){
85+
Cell cell = iter.next();
86+
if(cell.ingredient == Ingredient.MUSHROOM){
87+
Slice slice = new Slice();
88+
slice.cells.add(cell);
89+
starts.add(slice);
90+
iter.remove();
91+
}
92+
}
93+
return starts;
8094
}
8195

8296
}

0 commit comments

Comments
 (0)