Skip to main content
Commonmark migration
Source Link

Octave, 62 61 bytes

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

Try it online!

###Explanation

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 ...
                                                 g(t)         % t as binary string ...
                                 (g=@dec2bin)(n)              % within n as binary string
                     any(                             )       % True if contains nonzero
    sum(                                                    ) % Sum of array

Octave, 62 61 bytes

@(n)sum(arrayfun(@(t)any(strfind((g=@dec2bin)(n),g(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 ...
                                                 g(t)         % t as binary string ...
                                 (g=@dec2bin)(n)              % within n as binary string
                     any(                             )       % True if contains nonzero
    sum(                                                    ) % Sum of array

Octave, 62 61 bytes

@(n)sum(arrayfun(@(t)any(strfind((g=@dec2bin)(n),g(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 ...
                                                 g(t)         % t as binary string ...
                                 (g=@dec2bin)(n)              % within n as binary string
                     any(                             )       % True if contains nonzero
    sum(                                                    ) % Sum of array
deleted 48 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382

Octave, 62 bytes62 61 bytes

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

Try it online!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     g(t)         % t as binary string ...
                                 dec2bin(g=@dec2bin)(n)                    % within n as binary string
                     any(                              )       % True if contains nonzero
    sum(                                                     ) % Sum of array

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

Octave, 62 61 bytes

@(n)sum(arrayfun(@(t)any(strfind((g=@dec2bin)(n),g(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 ...
                                                 g(t)         % t as binary string ...
                                 (g=@dec2bin)(n)              % within n as binary string
                     any(                             )       % True if contains nonzero
    sum(                                                    ) % Sum of array
edited body
Source Link
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(n)           dec2bin(t)         % nt as binary string ...
                                 dec2bin(n)           dec2bin(t)         % within tn as binary string
                     any(                              )       % True if contains nonzero
    sum(                                                     ) % Sum of array

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(n)                    % n as binary string ...
                                            dec2bin(t)         % within t as binary string
                     any(                              )       % True if contains nonzero
    sum(                                                     ) % Sum of array

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
added 971 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382
Loading
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382
Loading