Skip to main content
typo
Source Link
xnor
  • 150k
  • 26
  • 290
  • 678

Haskell, 26 bytes

f l=10^foldl((+).(2*))0l-1

Try it online!

Input is a list of 0/1, output is a number like 9999999999 made of the digit 9.

Haskell is an interesting for this challenge because it lacks base-conversion built-ins without imports, so we have to do it ourselves. This answer folds the operation \n b->n*2+b over the list of bits to get a number k, then computes 10^k-1 to get a number made of k 9-digits. The 9's trick is shorter than more natural methods like replicate k 1 or 1<$[1..k] or take k[0,0..].

It's slightly longer to do the power-of-10 within the fold and decrement after:

27 bytes

pred.foldl(\n b->n^2*10^b)1

Try it online!

though if we bend the rules and represent bits as 1 or decimal 10, we can do

21 bytes

pred.foldl((*).(^2))1

Try it online!

Haskell, 26 bytes

foldl(\s b->s++s++[1|b])[]

Try it online!

Input is list of Booleans, output is a list of 1's. This iterates over the list of Booleans, each time doubling the current string then appending an additional 1 if the bit is True.

Haskell, 26 bytes

f l=10^foldl((+).(2*))0l-1

Try it online!

Input is a list of 0/1, output is a number like 9999999999 made of the digit 9.

Haskell is an interesting for this challenge because it lacks base-conversion built-ins without imports, so we have to do it ourselves. This answer folds the operation \n b->n*2+b over the list of bits to get a number k, then computes 10^k-1 to get a number made of k 9-digits. The 9's trick is shorter than more natural methods like replicate k 1 or 1<$[1..k] or take k[0,0..].

It's slightly longer to do the power-of-10 within the fold and decrement after:

27 bytes

pred.foldl(\n b->n^2*10^b)1

Try it online!

though if we bend the rules and represent bits as 1 or decimal 10, we can do

21 bytes

pred.foldl((*).(^2))1

Try it online!

Haskell, 26 bytes

foldl(\s b->s++s++[1|b])[]

Try it online!

Input is list of Booleans, output is a list of 1's. This iterates over the list of Booleans, each time doubling the current string then appending an additional 1 if the bit is True.

Haskell, 26 bytes

f l=10^foldl((+).(2*))0l-1

Try it online!

Input is a list of 0/1, output is a number like 9999999999 made of the digit 9.

Haskell is interesting for this challenge because it lacks base-conversion built-ins without imports, so we have to do it ourselves. This answer folds the operation \n b->n*2+b over the list of bits to get a number k, then computes 10^k-1 to get a number made of k 9-digits. The 9's trick is shorter than more natural methods like replicate k 1 or 1<$[1..k] or take k[0,0..].

It's slightly longer to do the power-of-10 within the fold and decrement after:

27 bytes

pred.foldl(\n b->n^2*10^b)1

Try it online!

though if we bend the rules and represent bits as 1 or decimal 10, we can do

21 bytes

pred.foldl((*).(^2))1

Try it online!

Haskell, 26 bytes

foldl(\s b->s++s++[1|b])[]

Try it online!

Input is list of Booleans, output is a list of 1's. This iterates over the list of Booleans, each time doubling the current string then appending an additional 1 if the bit is True.

Source Link
xnor
  • 150k
  • 26
  • 290
  • 678

Haskell, 26 bytes

f l=10^foldl((+).(2*))0l-1

Try it online!

Input is a list of 0/1, output is a number like 9999999999 made of the digit 9.

Haskell is an interesting for this challenge because it lacks base-conversion built-ins without imports, so we have to do it ourselves. This answer folds the operation \n b->n*2+b over the list of bits to get a number k, then computes 10^k-1 to get a number made of k 9-digits. The 9's trick is shorter than more natural methods like replicate k 1 or 1<$[1..k] or take k[0,0..].

It's slightly longer to do the power-of-10 within the fold and decrement after:

27 bytes

pred.foldl(\n b->n^2*10^b)1

Try it online!

though if we bend the rules and represent bits as 1 or decimal 10, we can do

21 bytes

pred.foldl((*).(^2))1

Try it online!

Haskell, 26 bytes

foldl(\s b->s++s++[1|b])[]

Try it online!

Input is list of Booleans, output is a list of 1's. This iterates over the list of Booleans, each time doubling the current string then appending an additional 1 if the bit is True.