Skip to main content
added 1497 characters in body
Source Link
Jonathan Allan
  • 110.2k
  • 7
  • 65
  • 282

Jelly, 25  25  27 bytes

+2 bytes to fix a bug with my golfing :( hopefully I'll find a shorter way though.

ṫi¥³ḣi
L2ṗŒ!瀵ạ2\S€ỊḄµÞṪ瀵ạ2\S€ỊẠ×LµÞṪ

Try it online!Try it online!

updating...

ṫi¥³ḣi - Link 1, getSlice: list of lists, bitstrings; list, toBitstring
   ³   - get 3rd command line argument (fromBitstring)
  ¥    - last two links as a dyad:
 i     -   index (of fromBitstring in bitstrings)
ṫ      -   tail (bitstrings) from (that) index
     i - index (of toBitstring in that result)
    ḣ  - head to (that) index

L2ṗŒ!瀵ạ2\S€ỊḄµÞṪ瀵ạ2\S€ỊẠ×LµÞṪ - Main link: list, fromBitstring; list, toBitstring
L                    - length (of fromBitstring)
 2                   - literal two
  ṗ                  - Cartesian power (of implicit range(2)=[1,2] with L(fromBitstring))
                     - ...i.e. all unique bitstrings of the required length (using [1,2])
   Œ!                - all permutations (of that list)
     ç€              - call the last link (1) as a dyad (i.e. f(that, toBitstring))
       µ         µÞ  - sort by the monadic function:
         2\          -   2-wise reduce with:
        ạ            -     absolute difference
           S€        -   sum €ach
             Ị       -   insignificant (vectorises) (abs(z)<=1 - for our purposes it's really just used for z==1 since only positive integers are possible)
                  -  - convert from binaryall truthy? (in1 theif endso we0 wantotherwise)
 (one of) the longest result with all-ones         L    - this is alength
 short cut for that)           ×     -   multiply
                   Ṫ - tail (the last one is one of the maximal results)
                     - implicit print

Jelly, 25 bytes

ṫi¥³ḣi
L2ṗŒ!瀵ạ2\S€ỊḄµÞṪ

Try it online!

ṫi¥³ḣi - Link 1, getSlice: list of lists, bitstrings; list, toBitstring
   ³   - get 3rd command line argument (fromBitstring)
  ¥    - last two links as a dyad:
 i     -   index (of fromBitstring in bitstrings)
ṫ      -   tail (bitstrings) from (that) index
     i - index (of toBitstring in that result)
    ḣ  - head to (that) index

L2ṗŒ!瀵ạ2\S€ỊḄµÞṪ - Main link: list, fromBitstring; list, toBitstring
L                  - length (of fromBitstring)
 2                 - literal two
  ṗ                - Cartesian power (of implicit range(2)=[1,2] with L(fromBitstring))
                   - ...i.e. all unique bitstrings of the required length (using [1,2])
   Œ!              - all permutations (of that list)
     ç€            - call the last link (1) as a dyad (i.e. f(that, toBitstring))
       µ       µÞ  - sort by the monadic function:
         2\        -   2-wise reduce with:
        ạ          -     absolute difference
           S€      -   sum €ach
             Ị     -   insignificant (vectorises) (abs(z)<=1 - for our purposes it's really just used for z==1 since only positive integers are possible)
                  -   convert from binary (in the end we want (one of) the longest result with all-ones - this is a short cut for that)
                 Ṫ - tail (the last one is one of the maximal results)
                   - implicit print

Jelly,  25  27 bytes

+2 bytes to fix a bug with my golfing :( hopefully I'll find a shorter way though.

ṫi¥³ḣi
L2ṗŒ!瀵ạ2\S€ỊẠ×LµÞṪ

Try it online!

updating...

ṫi¥³ḣi - Link 1, getSlice: list of lists, bitstrings; list, toBitstring
   ³   - get 3rd command line argument (fromBitstring)
  ¥    - last two links as a dyad:
 i     -   index (of fromBitstring in bitstrings)
ṫ      -   tail (bitstrings) from (that) index
     i - index (of toBitstring in that result)
    ḣ  - head to (that) index

L2ṗŒ!瀵ạ2\S€ỊẠ×LµÞṪ - Main link: list, fromBitstring; list, toBitstring
L                    - length (of fromBitstring)
 2                   - literal two
  ṗ                  - Cartesian power (of implicit range(2)=[1,2] with L(fromBitstring))
                     - ...i.e. all unique bitstrings of the required length (using [1,2])
   Œ!                - all permutations (of that list)
     ç€              - call the last link (1) as a dyad (i.e. f(that, toBitstring))
       µ         µÞ  - sort by the monadic function:
         2\          -   2-wise reduce with:
        ạ            -     absolute difference
           S€        -   sum €ach
             Ị       -   insignificant (vectorises) (abs(z)<=1 - for our purposes it's really just used for z==1 since only positive integers are possible)
                    -   all truthy? (1 if so 0 otherwise)
                L    -   length
               ×     -   multiply
                   Ṫ - tail (the last one is one of the maximal results)
                     - implicit print
added 1497 characters in body
Source Link
Jonathan Allan
  • 110.2k
  • 7
  • 65
  • 282

How?

ṫi¥³ḣi - Link 1, getSlice: list of lists, bitstrings; list, toBitstring
   ³   - get 3rd command line argument (fromBitstring)
  ¥    - last two links as a dyad:
 i     -   index (of fromBitstring in bitstrings)
ṫ      -   tail (bitstrings) from (that) index
     i - index (of toBitstring in that result)
    ḣ  - head to (that) index

L2ṗŒ!瀵ạ2\S€ỊḄµÞṪ - Main link: list, fromBitstring; list, toBitstring
L                  - length (of fromBitstring)
 2                 - literal two
  ṗ                - Cartesian power (of implicit range(2)=[1,2] with L(fromBitstring))
                   - ...i.e. all unique bitstrings of the required length (using [1,2])
   Œ!              - all permutations (of that list)
     ç€            - call the last link (1) as a dyad (i.e. f(that, toBitstring))
       µ       µÞ  - sort by the monadic function:
         2\        -   2-wise reduce with:
        ạ          -     absolute difference
           S€      -   sum €ach
             Ị     -   insignificant (vectorises) (abs(z)<=1 - for our purposes it's really just used for z==1 since only positive integers are possible)
              Ḅ    -   convert from binary (in the end we want (one of) the longest result with all-ones - this is a short cut for that)
                 Ṫ - tail (the last one is one of the maximal results)
                   - implicit print

How?

ṫi¥³ḣi - Link 1, getSlice: list of lists, bitstrings; list, toBitstring
   ³   - get 3rd command line argument (fromBitstring)
  ¥    - last two links as a dyad:
 i     -   index (of fromBitstring in bitstrings)
ṫ      -   tail (bitstrings) from (that) index
     i - index (of toBitstring in that result)
    ḣ  - head to (that) index

L2ṗŒ!瀵ạ2\S€ỊḄµÞṪ - Main link: list, fromBitstring; list, toBitstring
L                  - length (of fromBitstring)
 2                 - literal two
  ṗ                - Cartesian power (of implicit range(2)=[1,2] with L(fromBitstring))
                   - ...i.e. all unique bitstrings of the required length (using [1,2])
   Œ!              - all permutations (of that list)
     ç€            - call the last link (1) as a dyad (i.e. f(that, toBitstring))
       µ       µÞ  - sort by the monadic function:
         2\        -   2-wise reduce with:
        ạ          -     absolute difference
           S€      -   sum €ach
             Ị     -   insignificant (vectorises) (abs(z)<=1 - for our purposes it's really just used for z==1 since only positive integers are possible)
              Ḅ    -   convert from binary (in the end we want (one of) the longest result with all-ones - this is a short cut for that)
                 Ṫ - tail (the last one is one of the maximal results)
                   - implicit print
Source Link
Jonathan Allan
  • 110.2k
  • 7
  • 65
  • 282

Jelly, 25 bytes

ṫi¥³ḣi
L2ṗŒ!瀵ạ2\S€ỊḄµÞṪ

A full program taking the bit-strings using 1 and 2* as lists. The arguments are from and to. The program prints a list of lists of the same.

* 0 and 1 may be used instead at the cost of a byte (add between L2ṗ and Œ!ç€... to decrement).

Try it online!