Skip to main content
edited body
Source Link
Nick Kennedy
  • 21.2k
  • 3
  • 17
  • 43
ṭ             Ʋ  | Tack output of part 1 onto the following:
 œcJ             | - Combinations of lengths 1,2,3,4,5
    ;2/          | - Pairwise reduce using concatenation
            Ɗ€€   | - Following as a monad for each innermost list:
          |   - Sort
         ṭ,`      |   - Tacked onto the list paired with itself
               Ḋ | - Remove first (i.e. the combinations of lengths 1 and 2)
ṭ             Ʋ  | Tack output of part 1 onto the following:
 œcJ             | - Combinations of lengths 1,2,3,4,5
    ;2/          | - Pairwise reduce using concatenation
            Ɗ€€  | - Following as a monad for each innermost list:
        Ṣ        |   - Sort
         ṭ,`     |   - Tacked onto the list paired with itself
               Ḋ | - Remove first (i.e. the combinations of lengths 1 and 2)
ṭ             Ʋ  | Tack output of part 1 onto the following:
 œcJ             | - Combinations of lengths 1,2,3,4,5
    ;2/          | - Pairwise reduce using concatenation
           Ɗ€€   | - Following as a monad for each innermost list:
       Ṣ         |   - Sort
        ṭ,`      |   - Tacked onto the list paired with itself
               Ḋ | - Remove first (i.e. the combinations of lengths 1 and 2)
added 2481 characters in body; deleted 12 characters in body
Source Link
Nick Kennedy
  • 21.2k
  • 3
  • 17
  • 43

Jelly, 71 6665 bytes

J4Ṭ;-+ʋ€ịṭ@Wẋ¥€3ṭœcⱮ5;2+ʋ€ịṭ@Wẋ¥€3ṭœcJ;2/ḊṢṭṢṭ,`Ɗ€€Ʋ`Ɗ€€ƲḊ,UṢƑ€o\ƲI,I$E€ƊIỊẠƊ3ƭ€€€»/€¬µ5ƤFS

Try it online!Try it online!

A monadic link taking a list if integers and returning an integer. I’m sure this can be shortened further. More code than I’d like is taken up

Explanation

...µ5Ƥ   | Run the main chain (below) for each 5-integer-long infix of the list
      F  | Flatten list
       S | Sum

Main chain

This generates the lists for the each set of tests. To deal with the variation in test 3, there are 3 copies made of each innermost list. For the first and second sets of tests, the last copy of each innermost list is sorted, while for the third set of tests it is not.

Main chain part 1 (generates swapped lists for third set of tests)

J                | Sequence along list [1,2,3,4,5]
 4    ʋ€         | Do the following as a dyad for each of 1,2,3,4 with 1,2,3,4,5 as the right argument:
  Ṭ              | - Convert to logical list with 1 at the relevant index [[1],[0,1],[0,0,1],[0,0,0,1]]
   ;-            | - Concatenate -1 to this
     +           | - Add (to [1,2,3,4,5])
        ị        | Index into original list
         ṭ@      | Tack onto end the original list
           Wẋ¥€3 | Repeat each inner list 3 times

Main chain part 2 (generates lists for first and second sets of tests)

ṭ             Ʋ  | Tack output of part 1 onto the following:
 œcJ             | - Combinations of lengths 1,2,3,4,5
    ;2/          | - Pairwise reduce using concatenation
            Ɗ€€  | - Following as a monad for each innermost list:
        Ṣ        |   - Sort
         ṭ,`     |   - Tacked onto the list paired with itself
               Ḋ | - Remove first (i.e. the combinations of lengths 1 and 2)

Main chain part 3 (runs the tests)

                   3ƭ€€€     | For each innermost list, do one of the following three in turn:
       Ʋ                     | - Tests 1 and 2
,U                           |   - Pair with reversed list
  ṢƑ€                        |   - Check whether each invariant if sorted
     o\                      |   - Cumulative or
              Ɗ              | - Tests 4 and 5
        I                    |   - Increments (test 4)
         ,I$                 |   - Paired with increments of increments (test 5)
            E€               |   - Check if all equal for each of these
                  Ɗ          | - Test 3
               I             |   - Increments
                Ị            |   - Absolute value <= 1
                 Ạ           |   - All
                        »/€  | Reduce each using max - picks the best results for each test for each set of tests
                           ¬ | Not (vectorises)

Jelly, 71 66 bytes

J4Ṭ;-+ʋ€ịṭ@Wẋ¥€3ṭœcⱮ5;2/ḊṢṭ,`Ɗ€€Ʋ,UṢƑ€o\ƲI,I$E€ƊIỊẠƊ3ƭ€€€»/€¬µ5ƤFS

Try it online!

A monadic link taking a list if integers and returning an integer. I’m sure this can be shortened further. More code than I’d like is taken up with the variation in test 3 for the third set of tests.

Jelly, 71 65 bytes

J4Ṭ;-+ʋ€ịṭ@Wẋ¥€3ṭœcJ;2/Ṣṭ,`Ɗ€€ƲḊ,UṢƑ€o\ƲI,I$E€ƊIỊẠƊ3ƭ€€€»/€¬µ5ƤFS

Try it online!

A monadic link taking a list if integers and returning an integer. I’m sure this can be shortened further.

Explanation

...µ5Ƥ   | Run the main chain (below) for each 5-integer-long infix of the list
      F  | Flatten list
       S | Sum

Main chain

This generates the lists for the each set of tests. To deal with the variation in test 3, there are 3 copies made of each innermost list. For the first and second sets of tests, the last copy of each innermost list is sorted, while for the third set of tests it is not.

Main chain part 1 (generates swapped lists for third set of tests)

J                | Sequence along list [1,2,3,4,5]
 4    ʋ€         | Do the following as a dyad for each of 1,2,3,4 with 1,2,3,4,5 as the right argument:
  Ṭ              | - Convert to logical list with 1 at the relevant index [[1],[0,1],[0,0,1],[0,0,0,1]]
   ;-            | - Concatenate -1 to this
     +           | - Add (to [1,2,3,4,5])
        ị        | Index into original list
         ṭ@      | Tack onto end the original list
           Wẋ¥€3 | Repeat each inner list 3 times

Main chain part 2 (generates lists for first and second sets of tests)

ṭ             Ʋ  | Tack output of part 1 onto the following:
 œcJ             | - Combinations of lengths 1,2,3,4,5
    ;2/          | - Pairwise reduce using concatenation
            Ɗ€€  | - Following as a monad for each innermost list:
        Ṣ        |   - Sort
         ṭ,`     |   - Tacked onto the list paired with itself
               Ḋ | - Remove first (i.e. the combinations of lengths 1 and 2)

Main chain part 3 (runs the tests)

                   3ƭ€€€     | For each innermost list, do one of the following three in turn:
       Ʋ                     | - Tests 1 and 2
,U                           |   - Pair with reversed list
  ṢƑ€                        |   - Check whether each invariant if sorted
     o\                      |   - Cumulative or
              Ɗ              | - Tests 4 and 5
        I                    |   - Increments (test 4)
         ,I$                 |   - Paired with increments of increments (test 5)
            E€               |   - Check if all equal for each of these
                  Ɗ          | - Test 3
               I             |   - Increments
                Ị            |   - Absolute value <= 1
                 Ạ           |   - All
                        »/€  | Reduce each using max - picks the best results for each test for each set of tests
                           ¬ | Not (vectorises)
deleted 11 characters in body
Source Link
Nick Kennedy
  • 21.2k
  • 3
  • 17
  • 43

Jelly, 71 6966 bytes

J4Ṭ;-+ʋ€ịṭ@ṭœcⱮ5;2+ʋ€ịṭ@Wẋ¥€3ṭœcⱮ5;2/ḊƊWẋ3Ɗ€€Ṣ€3¦€€Ø½¦ḊṢṭ,`Ɗ€€Ʋ,UṢƑ€o\ƲI,I$E€ƊIỊẠƊ3ƭ€€€»/€¬µ5ƤFS

Try it online!Try it online!

A monadic link taking a list if integers and returning an integer. I’m sure this can be shortened further. More code than I’d like is taken up with the variation in test 3 for the third set of tests.

Jelly, 71 69 bytes

J4Ṭ;-+ʋ€ịṭ@ṭœcⱮ5;2/ḊƊWẋ3Ɗ€€Ṣ€3¦€€Ø½¦,UṢƑ€o\ƲI,I$E€ƊIỊẠƊ3ƭ€€€»/€¬µ5ƤFS

Try it online!

A monadic link taking a list if integers and returning an integer. I’m sure this can be shortened further. More code than I’d like is taken up with the variation in test 3 for the third set of tests.

Jelly, 71 66 bytes

J4Ṭ;-+ʋ€ịṭ@Wẋ¥€3ṭœcⱮ5;2/ḊṢṭ,`Ɗ€€Ʋ,UṢƑ€o\ƲI,I$E€ƊIỊẠƊ3ƭ€€€»/€¬µ5ƤFS

Try it online!

A monadic link taking a list if integers and returning an integer. I’m sure this can be shortened further. More code than I’d like is taken up with the variation in test 3 for the third set of tests.

deleted 5 characters in body
Source Link
Nick Kennedy
  • 21.2k
  • 3
  • 17
  • 43
Loading
Source Link
Nick Kennedy
  • 21.2k
  • 3
  • 17
  • 43
Loading