Skip to main content
added 19 characters in body
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60

Husk, 1818 17 bytes

#oṗḋuż+m`:1oΘḣḋ¹ṫḋ#oṗḋużoJ1eḣḋ¹mtṫḋ

Try it online!Try it online!

Different approach to Razetime's Husk answer, saving 22 3 bytes.

How?

#oṗḋuż+m`:1oΘḣḋ¹ṫḋ#oṗḋużoJ1eḣḋ¹mtṫḋ
#o                      # how many
  ṗ                     # prime numbers
   ḋ                    # among numbers formed by binary digits of
    u                   # unique elements of
     ż+żo                 # zip together 2 lists:
 of lists,
     m`:1oΘḣḋ¹   J1e     # list 1:
       # joining each pair with the digit '1'
         # allḣḋ¹ prefixes of 
         # list 1:
    ḋ¹        # binary digits of input
       # all prefixes of  
           #ḋ¹ prefixed by an empty list
      # m`:1binary digits of input
          # with 1 addedmtṫḋ at the end of each  # list 2:
             mt   ṫḋ      # listremove 2:
first element from
        # all suffixes of
        # binary digits of input

Husk, 18 bytes

#oṗḋuż+m`:1oΘḣḋ¹ṫḋ

Try it online!

Different approach to Razetime's Husk answer, saving 2 bytes.

How?

#oṗḋuż+m`:1oΘḣḋ¹ṫḋ
#o                      # how many
  ṗ                     # prime numbers
   ḋ                    # among numbers formed by binary digits of
    u                   # unique elements of
     ż+                 # zip together 2 lists:
       m`:1oΘḣḋ¹        # list 1:
                       # all prefixes of 
               ḋ¹        # binary digits of input
                      # prefixed by an empty list
       m`:1             # with 1 added at the end of each    
                ṫḋ      # list 2:
                ṫ       # all suffixes of
                 ḋ      # binary digits of input

Husk, 18 17 bytes

#oṗḋużoJ1eḣḋ¹mtṫḋ

Try it online!

Different approach to Razetime's Husk answer, saving 2 3 bytes.

How?

#oṗḋużoJ1eḣḋ¹mtṫḋ
#o                      # how many
  ṗ                     # prime numbers
   ḋ                    # among numbers formed by binary digits of
    u                   # unique elements of
     żo                 # zip together 2 lists of lists,
       J1e              # joining each pair with the digit '1'
          ḣḋ¹           # list 1:
                       # all prefixes of  
           ḋ¹           # binary digits of input
             mtṫḋ       # list 2:
             mt         # remove first element from
        # all suffixes of
                ḋ       # binary digits of input
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60

Husk, 18 bytes

#oṗḋuż+m`:1oΘḣḋ¹ṫḋ

Try it online!

Different approach to Razetime's Husk answer, saving 2 bytes.

How?

#oṗḋuż+m`:1oΘḣḋ¹ṫḋ
#o                      # how many
  ṗ                     # prime numbers
   ḋ                    # among numbers formed by binary digits of
    u                   # unique elements of
     ż+                 # zip together 2 lists:
       m`:1oΘḣḋ¹        # list 1:
             ḣ          # all prefixes of 
              ḋ¹        # binary digits of input
           oΘ           # prefixed by an empty list
       m`:1             # with 1 added at the end of each    
                ṫḋ      # list 2:
                ṫ       # all suffixes of
                 ḋ      # binary digits of input