Skip to main content
added 1507 characters in body
Source Link
naffetS
  • 12.8k
  • 2
  • 20
  • 53

Try it Online!online or verify all test cases.

How?

k-»>xWƛo4ø₅=»b7ẇ:?hiN$2ẋΠv∩vvƒ-?S2l⌊İJfvO
k-                                         # Push [-1, 1] (will be used later)
  »>xWƛo4ø₅=»                              # Push compressed integer 1098931065668123279355
             b                             # Convert to binary as a list
              7ẇ                           # Split into chunks of size 7
                :                          # Duplicate
                 ?h                        # Push the first digit of the input
                   i                       # Index it into the list
                    N                      # Negate: replace all 1s with -1
                     $                     # Swap so the list of size-7 chunks are at the top again
                      2ẋΠ                  # Cartesian product with self
                         v∩                # For each, transpose
                           vvƒ-            # For each inner pair, reduce by subtraction
                               ?S          # Push stringified input
                                 2l        # Get all overlapping pairs
                                   ⌊       # Convert them to integers
                                    İ      # Index these into the other list
                                     J     # Join the two lists together
                                      f    # Flatten
                                       vO  # Count the number of -1s and 1s in this list

Try it online or verify all test cases.

How?

k-»>xWƛo4ø₅=»b7ẇ:?hiN$2ẋΠv∩vvƒ-?S2l⌊İJfvO
k-                                         # Push [-1, 1] (will be used later)
  »>xWƛo4ø₅=»                              # Push compressed integer 1098931065668123279355
             b                             # Convert to binary as a list
              7ẇ                           # Split into chunks of size 7
                :                          # Duplicate
                 ?h                        # Push the first digit of the input
                   i                       # Index it into the list
                    N                      # Negate: replace all 1s with -1
                     $                     # Swap so the list of size-7 chunks are at the top again
                      2ẋΠ                  # Cartesian product with self
                         v∩                # For each, transpose
                           vvƒ-            # For each inner pair, reduce by subtraction
                               ?S          # Push stringified input
                                 2l        # Get all overlapping pairs
                                   ⌊       # Convert them to integers
                                    İ      # Index these into the other list
                                     J     # Join the two lists together
                                      f    # Flatten
                                       vO  # Count the number of -1s and 1s in this list
Source Link
naffetS
  • 12.8k
  • 2
  • 20
  • 53

Vyxal, 41 bytes

k-»>xWƛo4ø₅=»b7ẇ:?hiN$2ẋΠv∩vvƒ-?S2l⌊İJfvO

Try it Online!