Skip to content

Commit

Permalink
feat(FishCalculator): add first iteration of recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
oscar-schwarz committed Jun 17, 2024
1 parent 41c43d8 commit 7d47bfa
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
37 changes: 37 additions & 0 deletions src/main/java/fish_variety/FishCalculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package fish_variety;

import java.util.ArrayList;

public class FishCalculator {

public static FishCollection mostCompatibleFishTypesOfCollection(int price, FishCollection initialCollection) {
FishConstraints constraints = initialCollection.getConstraints();

ArrayList<FishCollection> variants = new ArrayList<>();

for (Fish fish : constraints.getAllFish()) {
FishCollection collectionVariant = new FishCollection(constraints, initialCollection.getFishes());

collectionVariant.add(fish);

if (collectionVariant.isValid() && collectionVariant.getPrice() <= price) {
variants.add(FishCalculator.mostCompatibleFishTypesOfCollection(price, collectionVariant));
}
}

if (variants.size() == 0) {
return initialCollection;
}

// Get largets collection in variants
FishCollection largestCollectionVariant = variants.get(0);

for (FishCollection fishCollection : variants) {
if (fishCollection.getFishes().size() > largestCollectionVariant.getFishes().size()) {
largestCollectionVariant = fishCollection;
}
}

return largestCollectionVariant;
}
}
3 changes: 2 additions & 1 deletion src/main/java/fish_variety/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public static void main( String[] args )
grueneMigraene, prachtpiranha, zitterling
});

FishCollection collection = new FishCollection(constraints);
FishCollection bestVariant = FishCalculator.mostCompatibleFishTypesOfCollection(170, new FishCollection(constraints));
System.out.println(bestVariant);
}
}

0 comments on commit 7d47bfa

Please sign in to comment.