Skip to main content
Grammar checks.
Source Link
Steadybox
  • 16.5k
  • 5
  • 41
  • 84

After lots of revising, I'm now very proud of this answer. I like the algorithm, and how nicenicely it can be expressed in brain-flak.

If the input is n digits long, the first digit will appear in the triangle n times, the second digit will appear n-1 times, and so on onto the last digit, which will appear once. We can take advantage of this, since it's really easy to calculate how many digits of input are left in brain-flak, namely

After lots of revising, I'm now very proud of this answer. I like the algorithm, and how nice it can be expressed in brain-flak.

If the input is n digits long, the first digit will appear in the triangle n times, the second digit will appear n-1 times, and so on onto the last digit, which will appear once. We can take advantage of this since it's really easy to calculate how many digits of input are left in brain-flak, namely

After lots of revising, I'm now very proud of this answer. I like the algorithm, and how nicely it can be expressed in brain-flak.

If the input is n digits long, the first digit will appear in the triangle n times, the second digit will appear n-1 times, and so on onto the last digit, which will appear once. We can take advantage of this, since it's really easy to calculate how many digits of input are left in brain-flak, namely

After lots of revising, I'm now very proud of this answer. I like the algorithm, and how nicelynice it can be expressed in brain-flak.

Most of the byte count comes formfrom handling 0's in the input. In fact, if we could assume there were no 0's in the input, it would be a beautifully short 20 byte-byte answer:

If the input is n digits long, the first digit will appear in the triangle n times, the second digit will appear n-1 times, and so on onto the last digit, which will appear once. We can take advantage of this, since it's really easy to calculate how many digits of input are left in brain-flak, namely

After lots of revising, I'm now very proud of this answer. I like the algorithm, and how nicely it can be expressed in brain-flak.

Most of the byte count comes form handling 0's in the input. In fact, if we could assume there were no 0's in the input, it would be a beautifully short 20 byte answer:

If the input is n digits long, the first digit will appear in the triangle n times, the second digit will appear n-1 times, and so on onto the last digit, which will appear once. We can take advantage of this, since it's really easy to calculate how many digits of input are left in brain-flak, namely

After lots of revising, I'm now very proud of this answer. I like the algorithm, and how nice it can be expressed in brain-flak.

Most of the byte count comes from handling 0's in the input. In fact, if we could assume there were no 0's in the input, it would be a beautifully short 20-byte answer:

If the input is n digits long, the first digit will appear in the triangle n times, the second digit will appear n-1 times, and so on onto the last digit, which will appear once. We can take advantage of this since it's really easy to calculate how many digits of input are left in brain-flak, namely

added 1422 characters in body
Source Link
DJMcMayhem
  • 59.6k
  • 17
  • 196
  • 348

Explanation

First, an observation of mine:

If the input is n digits long, the first digit will appear in the triangle n times, the second digit will appear n-1 times, and so on onto the last digit, which will appear once. We can take advantage of this, since it's really easy to calculate how many digits of input are left in brain-flak, namely

[]

So here's how the code works.

# Push the size of the input (to account for 0's)
([])

# Push...
(

    # While True
    {

        # Pop the stack height (evaluates to 0)
        <{}>

        # For each digit *D*...

        # While true
        {

            # Decrement the counter (the current digit we're evaluating), 
            # but evaluate to 0
            <({}[()])>

            # Evaluate the number of digits left in the input
            []

        # Endwhile
        }

        # This whole block evaluates to D * len(remaining_digits), but 
        # without affecting the stack

        # Since we looped D times, D is now 0 and there is one less digit.
        # Pop D (now 0)
        {}

        # Push the stack height (again, evaluating it as 0)
        <([])>

    # End while
    }

    # Pop a 0 off (handles edge case of 0)
    {}

# end push
)

Explanation

First, an observation of mine:

If the input is n digits long, the first digit will appear in the triangle n times, the second digit will appear n-1 times, and so on onto the last digit, which will appear once. We can take advantage of this, since it's really easy to calculate how many digits of input are left in brain-flak, namely

[]

So here's how the code works.

# Push the size of the input (to account for 0's)
([])

# Push...
(

    # While True
    {

        # Pop the stack height (evaluates to 0)
        <{}>

        # For each digit *D*...

        # While true
        {

            # Decrement the counter (the current digit we're evaluating), 
            # but evaluate to 0
            <({}[()])>

            # Evaluate the number of digits left in the input
            []

        # Endwhile
        }

        # This whole block evaluates to D * len(remaining_digits), but 
        # without affecting the stack

        # Since we looped D times, D is now 0 and there is one less digit.
        # Pop D (now 0)
        {}

        # Push the stack height (again, evaluating it as 0)
        <([])>

    # End while
    }

    # Pop a 0 off (handles edge case of 0)
    {}

# end push
)
added 335 characters in body
Source Link
DJMcMayhem
  • 59.6k
  • 17
  • 196
  • 348
Loading
added 335 characters in body
Source Link
DJMcMayhem
  • 59.6k
  • 17
  • 196
  • 348
Loading
deleted 43 characters in body
Source Link
DJMcMayhem
  • 59.6k
  • 17
  • 196
  • 348
Loading
deleted 12 characters in body
Source Link
DJMcMayhem
  • 59.6k
  • 17
  • 196
  • 348
Loading
Source Link
DJMcMayhem
  • 59.6k
  • 17
  • 196
  • 348
Loading