Search in sources :

Example 1 with CharSeq

use of io.vavr.collection.CharSeq in project javaslang by javaslang.

the class Euler36Test method isDoubleBasePalindrome.

private static boolean isDoubleBasePalindrome(int x) {
    final CharSeq seq = CharSeq.of(Integer.toString(x));
    final CharSeq rev = CharSeq.of(Integer.toBinaryString(x));
    return isPalindrome(seq) && isPalindrome(rev);
}
Also used : CharSeq(io.vavr.collection.CharSeq)

Example 2 with CharSeq

use of io.vavr.collection.CharSeq in project javaslang by javaslang.

the class AbstractValueTest method shouldConvertToCharSeq.

@Test
public void shouldConvertToCharSeq() {
    final Value<Integer> value = of(1, 2, 3);
    final CharSeq charSeq = value.toCharSeq();
    final CharSeq expected = CharSeq.of(of(1, 2, 3).iterator().mkString());
    assertThat(charSeq).isEqualTo(expected);
}
Also used : CharSeq(io.vavr.collection.CharSeq) Test(org.junit.Test)

Example 3 with CharSeq

use of io.vavr.collection.CharSeq 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 : Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Assertions(org.assertj.core.api.Assertions) Test(org.junit.Test) Seq(io.vavr.collection.Seq) CharSeq(io.vavr.collection.CharSeq) List(io.vavr.collection.List) CharSeq(io.vavr.collection.CharSeq)

Aggregations

CharSeq (io.vavr.collection.CharSeq)3 Test (org.junit.Test)2 List (io.vavr.collection.List)1 Seq (io.vavr.collection.Seq)1 Assertions (org.assertj.core.api.Assertions)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1