Search in sources :

Example 1 with Seq

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);
}
Also used : CharSeq(javaslang.collection.CharSeq) List(javaslang.collection.List) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Seq(javaslang.collection.Seq) Test(org.junit.Test) CharSeq(javaslang.collection.CharSeq)

Aggregations

CharSeq (javaslang.collection.CharSeq)1 List (javaslang.collection.List)1 Seq (javaslang.collection.Seq)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Test (org.junit.Test)1