Skip to main content
added 11 characters in body
Source Link
smls
  • 4.5k
  • 15
  • 19

Perl 6, 52 bytes

->\n{(map {.comb[*-n]//|()},(5 X**1..*))[^(2**n/4)]}

Works for allarbitrarily high inputs, given enough RAMsufficient memory (i.e. doesn't useno logarithm approximation).
Returns a list of digits.

Try it online!

How it works

->\n{                                              }  # A lambda with argument n.
                            (5 X**1..*)               # The sequence 5, 25, 125, 625...
      map {               },                          # Transform each element as such:
           .comb[*-n]                                 #   Extract the n'th last digit,
                     //|()                            #   or skip it if that doesn't exist.
     (                                 )[^(2**n/4)]   # Return the first 2^(n-2) elements.

The "element skipping" part works like this:

  • Indexing a list at an illegal index returns a Failure, which counts as an "undefined" value.
  • // is the "defined or" operator.
  • |() returns an empty Slip, which dissolves into the outer list as 0 elements, essentially making sure that the current element is skipped.

The edge-case n=1 works out fine, because 2**n/4 becomes 0.5, and ^(0.5) means 0 ..^ 0.5 a.k.a. "integers between 0 (inclusive) and 0.5 (not inclusive)", i.e. a list with the single element 0.

Perl 6, 52 bytes

->\n{(map {.comb[*-n]//|()},(5 X**1..*))[^(2**n/4)]}

Works for all inputs, given enough RAM (i.e. doesn't use logarithm approximation).
Returns a list of digits.

Try it online!

How it works

->\n{                                              }  # A lambda with argument n.
                            (5 X**1..*)               # The sequence 5, 25, 125, 625...
      map {               },                          # Transform each element as such:
           .comb[*-n]                                 #   Extract the n'th last digit,
                     //|()                            #   or skip it if that doesn't exist.
     (                                 )[^(2**n/4)]   # Return the first 2^(n-2) elements.

The "element skipping" part works like this:

  • Indexing a list at an illegal index returns a Failure, which counts as an "undefined" value.
  • // is the "defined or" operator.
  • |() returns an empty Slip, which dissolves into the outer list as 0 elements, essentially making sure that the current element is skipped.

The edge-case n=1 works out fine, because 2**n/4 becomes 0.5, and ^(0.5) means 0 ..^ 0.5 a.k.a. "integers between 0 (inclusive) and 0.5 (not inclusive)", i.e. a list with the single element 0.

Perl 6, 52 bytes

->\n{(map {.comb[*-n]//|()},(5 X**1..*))[^(2**n/4)]}

Works for arbitrarily high inputs, given sufficient memory (i.e. no logarithm approximation).
Returns a list of digits.

Try it online!

How it works

->\n{                                              }  # A lambda with argument n.
                            (5 X**1..*)               # The sequence 5, 25, 125, 625...
      map {               },                          # Transform each element as such:
           .comb[*-n]                                 #   Extract the n'th last digit,
                     //|()                            #   or skip it if that doesn't exist.
     (                                 )[^(2**n/4)]   # Return the first 2^(n-2) elements.

The "element skipping" part works like this:

  • Indexing a list at an illegal index returns a Failure, which counts as an "undefined" value.
  • // is the "defined or" operator.
  • |() returns an empty Slip, which dissolves into the outer list as 0 elements, essentially making sure that the current element is skipped.

The edge-case n=1 works out fine, because 2**n/4 becomes 0.5, and ^(0.5) means 0 ..^ 0.5 a.k.a. "integers between 0 (inclusive) and 0.5 (not inclusive)", i.e. a list with the single element 0.

added 8 characters in body
Source Link
smls
  • 4.5k
  • 15
  • 19

Perl 6, 52 bytes

->\n{(map {.comb[*-n]//|()},(5 X**1..*))[^(2**n/4)]}

Works for all inputs, given enough RAM (i.e. doesn't use logarithm approximation).
Returns a list of digits.

Try it online!Try it online!

How it works

->\n{                                              }  # A lambda with argument n.
                            (5 X**1..*)               # The sequence 5, 25, 125, 625...
      map {               },                          # Transform each element as such:
           .comb[*-n]                                 #   Extract the n'th last digit,
                     //|()                            #   or skip it if that doesn't exist.
     (                                 )[^(2**n/4)]   # Return the first 2^(n-2) elements.

The "element skipping" part works like this:

  • Indexing a list at an illegal index returns a Failure, which counts as an "undefined" value.
  • // is the "defined or" operator.
  • |() returns an empty Slip, which dissolves into the outer list as 0 elements, essentially making sure that the current element is skipped.

The edge-case n=1 works out fine, because 2**n/4 becomes 0.5, and ^(0.5) means 0 ..^ 0.5 a.k.a. "integers between 0 (inclusive) and 0.5 (not inclusive)", i.e. a list with the single element 0.

Perl 6, 52 bytes

->\n{(map {.comb[*-n]//|()},(5 X**1..*))[^(2**n/4)]}

Works for all inputs, given enough RAM (i.e. doesn't use logarithm approximation).
Returns a list of digits.

Try it online!

How it works

->\n{                                              }  # A lambda with argument n.
                            (5 X**1..*)               # The sequence 5, 25, 125, 625...
      map {               },                          # Transform each element as such:
           .comb[*-n]                                 #   Extract the n'th last digit,
                     //|()                            #   or skip it if that doesn't exist.
     (                                 )[^(2**n/4)]   # Return the first 2^(n-2) elements.

The "element skipping" part works like this:

  • Indexing a list at an illegal index returns a Failure, which counts as an "undefined" value.
  • // is the "defined or" operator.
  • |() returns an empty Slip, which dissolves into the outer list as 0 elements, essentially making sure that the current element is skipped.

The edge-case n=1 works out fine, because 2**n/4 becomes 0.5, and ^(0.5) means 0 ..^ 0.5 a.k.a. "integers between 0 (inclusive) and 0.5 (not inclusive)", i.e. a list with the single element 0.

Perl 6, 52 bytes

->\n{(map {.comb[*-n]//|()},(5 X**1..*))[^(2**n/4)]}

Works for all inputs, given enough RAM (i.e. doesn't use logarithm approximation).
Returns a list of digits.

Try it online!

How it works

->\n{                                              }  # A lambda with argument n.
                            (5 X**1..*)               # The sequence 5, 25, 125, 625...
      map {               },                          # Transform each element as such:
           .comb[*-n]                                 #   Extract the n'th last digit,
                     //|()                            #   or skip it if that doesn't exist.
     (                                 )[^(2**n/4)]   # Return the first 2^(n-2) elements.

The "element skipping" part works like this:

  • Indexing a list at an illegal index returns a Failure, which counts as an "undefined" value.
  • // is the "defined or" operator.
  • |() returns an empty Slip, which dissolves into the outer list as 0 elements, essentially making sure that the current element is skipped.

The edge-case n=1 works out fine, because 2**n/4 becomes 0.5, and ^(0.5) means 0 ..^ 0.5 a.k.a. "integers between 0 (inclusive) and 0.5 (not inclusive)", i.e. a list with the single element 0.

added 11 characters in body
Source Link
smls
  • 4.5k
  • 15
  • 19

Perl 6, 52 bytes

->\n{(map {.comb[*-n]//|()},(5 X**1..*))[^(2**n/4)]}

Returns a list of digits.
WorksWorks for all inputs, given enough RAM (i.e. doesn't use logarithm approximation).
Returns a list of digits.

Try it online!

How it works

->\n{                                              }  # A lambda with argument n.
                            (5 X**1..*)               # The sequence 5, 25, 125, 625...
      map {               },                          # Transform each element as such:
           .comb[*-n]                                 #   Extract the n'th last digit,
                     //|()                            #   or skip it if that doesn't exist.
     (                                 )[^(2**n/4)]   # Return the first 2^(n-2) elements.

The "element skipping" part works like this:

  • Indexing a list at an illegal index returns a Failure, which counts as an "undefined" value.
  • // is the "defined or" operator.
  • |() returns an empty Slip, which dissolves into the outer list as 0 elements, essentially making sure that the current element is skipped.

The edge-case n=1 works out fine, because 2**n/4 becomes 0.5, and the ^0^(0.5) means 0 ..^ 0.5 a.k.a. "integers between 0 (inclusive) and 0.5 (not inclusive)", i.e. a list with the single element 0.

Perl 6, 52 bytes

->\n{(map {.comb[*-n]//|()},(5 X**1..*))[^(2**n/4)]}

Returns a list of digits.
Works for all inputs, given enough RAM (i.e. doesn't use logarithm approximation).

Try it online!

How it works

->\n{                                              }  # A lambda with argument n.
                            (5 X**1..*)               # The sequence 5, 25, 125, 625...
      map {               },                          # Transform each element as such:
           .comb[*-n]                                 #   Extract the n'th last digit,
                     //|()                            #   or skip it if that doesn't exist.
     (                                 )[^(2**n/4)]   # Return the first 2^(n-2) elements.

The "element skipping" part works like this:

  • Indexing a list at an illegal index returns a Failure, which counts as an "undefined" value.
  • // is the "defined or" operator.
  • |() returns an empty Slip, which dissolves into the outer list as 0 elements, essentially making sure that the current element is skipped.

The edge-case n=1 works out fine, because 2**n/4 becomes 0.5, and the ^0.5 means 0 ..^ 0.5 a.k.a. "integers between 0 (inclusive) and 0.5 (not inclusive)", i.e. 0.

Perl 6, 52 bytes

->\n{(map {.comb[*-n]//|()},(5 X**1..*))[^(2**n/4)]}

Works for all inputs, given enough RAM (i.e. doesn't use logarithm approximation).
Returns a list of digits.

Try it online!

How it works

->\n{                                              }  # A lambda with argument n.
                            (5 X**1..*)               # The sequence 5, 25, 125, 625...
      map {               },                          # Transform each element as such:
           .comb[*-n]                                 #   Extract the n'th last digit,
                     //|()                            #   or skip it if that doesn't exist.
     (                                 )[^(2**n/4)]   # Return the first 2^(n-2) elements.

The "element skipping" part works like this:

  • Indexing a list at an illegal index returns a Failure, which counts as an "undefined" value.
  • // is the "defined or" operator.
  • |() returns an empty Slip, which dissolves into the outer list as 0 elements, essentially making sure that the current element is skipped.

The edge-case n=1 works out fine, because 2**n/4 becomes 0.5, and ^(0.5) means 0 ..^ 0.5 a.k.a. "integers between 0 (inclusive) and 0.5 (not inclusive)", i.e. a list with the single element 0.

add explanation
Source Link
smls
  • 4.5k
  • 15
  • 19
Loading
add explanation
Source Link
smls
  • 4.5k
  • 15
  • 19
Loading
Post Undeleted by smls
work around am apparent Perl 6 bug
Source Link
smls
  • 4.5k
  • 15
  • 19
Loading
Post Deleted by smls
Source Link
smls
  • 4.5k
  • 15
  • 19
Loading