Skip to main content
3 of 5
edited body
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382

Octave, 62 bytes

@(n)sum(arrayfun(@(t)any(strfind(dec2bin(n),dec2bin(t))),1:n))

Try it online!

###Explanation

For input n, the code tests all numbers from 1 to n to see if their binary representation is a substring of the binary representation of the input.

@(n)                                                           % Anonymous function of n
        arrayfun(                                       ,1:n)  % Map over range 1:n
                 @(t)                                          % Anonymous function of t
                         strfind(          ,           )       % Indices of ...
                                            dec2bin(t)         % t as binary string ...
                                 dec2bin(n)                    % within n as binary string
                     any(                              )       % True if contains nonzero
    sum(                                                     ) % Sum of array
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382