use of javaslang.collection.Seq in project javaslang by javaslang.
the class Euler43Test method tenDigitPandigitalsWithProperty.
private static Seq<Long> tenDigitPandigitalsWithProperty() {
final CharSeq ALL_DIGITS = CharSeq.of("0123456789");
final List<Integer> DIVISORS = List.of(2, 3, 5, 7, 11, 13, 17);
return ALL_DIGITS.combinations(2).flatMap(CharSeq::permutations).flatMap(firstTwoDigits -> DIVISORS.foldLeft(List.of(firstTwoDigits), (accumulator, divisor) -> accumulator.flatMap(digitsSoFar -> ALL_DIGITS.removeAll(digitsSoFar).map(nextDigit -> digitsSoFar.append(nextDigit))).filter(digitsToTest -> digitsToTest.takeRight(3).parseInt() % divisor == 0))).map(tailDigitsWithProperty -> tailDigitsWithProperty.prepend(ALL_DIGITS.removeAll(tailDigitsWithProperty).head())).map(CharSeq::parseLong);
}
Aggregations