Skip to main content
5 bytes removed thanks to @WheatWizard
Source Link

Haskell (126126121 bytes)

import Data.List
r o c(t:s)=r([t]:[t:x|x<-o])(o++c)s
r o c []=o++cc[]=o++c
f=length.nub.filter(/="">"").map(dropWhileEnd(=='0'<'1')).r [] []r[][]

(5 bytes improvement thanks to @WheatWizard's comment)

Defines a function "f" that accepts a binary string as input.

Ungolfed and commented:

import Data.List -- unfortunately we need some functions that aren't in Prelude

-- recursively generate all sublists of a given list (or string)
-- arguments are the list of sublists currently being worked with, 
--   a list of finished sublists, and list to examine
-- output is a list of reversed lists
rsubstrs :: [[t]]->[[t]]->[t]->[[t]]

rsubstrs open closed (t:ts) = rsubstrs ([t]:[t:o|o<-open]) (open++closed) ts
rsubstrs open closed [] = open++closed

-- count unique nonzero binary substrings, produced by composing a sequence of functions:
--   rsubstrs above (with two empty lists supplied to the first two curried arguments)
--   a map operation that removes any trailing sequences of zeros
--   filter to remove empty strings (which were zeros)
--   nub, which finds all unique items in a list
--   length, to count the results
countsubs = length . nub . filter (/="") . map (dropWhileEnd (=='0')) . rsubstrs [] []

Haskell (126 bytes)

import Data.List
r o c(t:s)=r([t]:[t:x|x<-o])(o++c)s
r o c []=o++c
f=length.nub.filter(/="").map(dropWhileEnd(=='0')).r [] []

Defines a function "f" that accepts a binary string as input.

Ungolfed and commented:

import Data.List -- unfortunately we need some functions that aren't in Prelude

-- recursively generate all sublists of a given list (or string)
-- arguments are the list of sublists currently being worked with, 
--   a list of finished sublists, and list to examine
-- output is a list of reversed lists
rsubstrs :: [[t]]->[[t]]->[t]->[[t]]

rsubstrs open closed (t:ts) = rsubstrs ([t]:[t:o|o<-open]) (open++closed) ts
rsubstrs open closed [] = open++closed

-- count unique nonzero binary substrings, produced by composing a sequence of functions:
--   rsubstrs above (with two empty lists supplied to the first two curried arguments)
--   a map operation that removes any trailing sequences of zeros
--   filter to remove empty strings (which were zeros)
--   nub, which finds all unique items in a list
--   length, to count the results
countsubs = length . nub . filter (/="") . map (dropWhileEnd (=='0')) . rsubstrs [] []

Haskell (126121 bytes)

import Data.List
r o c(t:s)=r([t]:[t:x|x<-o])(o++c)s
r o c[]=o++c
f=length.nub.filter(>"").map(dropWhileEnd(<'1')).r[][]

(5 bytes improvement thanks to @WheatWizard's comment)

Defines a function "f" that accepts a binary string as input.

Ungolfed and commented:

import Data.List -- unfortunately we need some functions that aren't in Prelude

-- recursively generate all sublists of a given list (or string)
-- arguments are the list of sublists currently being worked with, 
--   a list of finished sublists, and list to examine
-- output is a list of reversed lists
rsubstrs :: [[t]]->[[t]]->[t]->[[t]]

rsubstrs open closed (t:ts) = rsubstrs ([t]:[t:o|o<-open]) (open++closed) ts
rsubstrs open closed [] = open++closed

-- count unique nonzero binary substrings, produced by composing a sequence of functions:
--   rsubstrs above (with two empty lists supplied to the first two curried arguments)
--   a map operation that removes any trailing sequences of zeros
--   filter to remove empty strings (which were zeros)
--   nub, which finds all unique items in a list
--   length, to count the results
countsubs = length . nub . filter (/="") . map (dropWhileEnd (=='0')) . rsubstrs [] []
Source Link

Haskell (126 bytes)

import Data.List
r o c(t:s)=r([t]:[t:x|x<-o])(o++c)s
r o c []=o++c
f=length.nub.filter(/="").map(dropWhileEnd(=='0')).r [] []

Defines a function "f" that accepts a binary string as input.

Ungolfed and commented:

import Data.List -- unfortunately we need some functions that aren't in Prelude

-- recursively generate all sublists of a given list (or string)
-- arguments are the list of sublists currently being worked with, 
--   a list of finished sublists, and list to examine
-- output is a list of reversed lists
rsubstrs :: [[t]]->[[t]]->[t]->[[t]]

rsubstrs open closed (t:ts) = rsubstrs ([t]:[t:o|o<-open]) (open++closed) ts
rsubstrs open closed [] = open++closed

-- count unique nonzero binary substrings, produced by composing a sequence of functions:
--   rsubstrs above (with two empty lists supplied to the first two curried arguments)
--   a map operation that removes any trailing sequences of zeros
--   filter to remove empty strings (which were zeros)
--   nub, which finds all unique items in a list
--   length, to count the results
countsubs = length . nub . filter (/="") . map (dropWhileEnd (=='0')) . rsubstrs [] []