mirror of
https://bitbucket.org/Mattrixwv/projecteulerjava.git
synced 2025-12-06 17:13:58 -05:00
Updated tests
This commit is contained in:
@@ -44,6 +44,7 @@ package com.mattrixwv.project_euler.problems;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
|
||||
public class Problem18 extends Problem{
|
||||
@@ -211,13 +212,14 @@ public class Problem18 extends Problem{
|
||||
//Returns the pyramid that was traversed as a string
|
||||
public String getPyramid(){
|
||||
solvedCheck("pyramid of numbers");
|
||||
StringBuilder results = new StringBuilder();
|
||||
StringJoiner results = new StringJoiner("\n");
|
||||
//Loop through all elements of the list and print them
|
||||
for(ArrayList<Integer> row : list){
|
||||
StringJoiner rowJoiner = new StringJoiner(" ");
|
||||
for(int column : row){
|
||||
results.append(String.format("%2d ", column));
|
||||
rowJoiner.add(String.format("%2d", column));
|
||||
}
|
||||
results.append('\n');
|
||||
results.add(rowJoiner.toString());
|
||||
}
|
||||
return results.toString();
|
||||
}
|
||||
@@ -225,7 +227,7 @@ public class Problem18 extends Problem{
|
||||
public String getTrail(){
|
||||
solvedCheck("trail of the shortest path");
|
||||
|
||||
StringBuilder results = new StringBuilder();
|
||||
StringJoiner results = new StringJoiner("->");
|
||||
//Save the trail the algorithm took
|
||||
ArrayList<Location> trail = new ArrayList<>();
|
||||
trail.add(foundPoints.get(foundPoints.size() - 1));
|
||||
@@ -236,7 +238,7 @@ public class Problem18 extends Problem{
|
||||
Location toAdd = null;
|
||||
while(!found){
|
||||
if(loc < 0){
|
||||
results.append("Error: Location < 0\n");
|
||||
results.add("Error: Location < 0\n");
|
||||
System.exit(1);
|
||||
}
|
||||
Iterator<Location> it = foundPoints.iterator();
|
||||
@@ -272,10 +274,7 @@ public class Problem18 extends Problem{
|
||||
}
|
||||
|
||||
for(Location loc : trail){
|
||||
results.append(list.get(loc.yLocation).get(loc.xLocation));
|
||||
if(loc.yLocation < (list.size() - 1)){
|
||||
results.append("->");
|
||||
}
|
||||
results.add(list.get(loc.yLocation).get(loc.xLocation).toString());
|
||||
}
|
||||
|
||||
return results.toString();
|
||||
|
||||
Reference in New Issue
Block a user