Skip to main content
80 -> 74
Source Link
noodle person
  • 10.3k
  • 1
  • 22
  • 76

Ruby, 8080 74 bytes

->s>i,c{z=0;sa=0;(i=i.split( ?|).map{["" "*z+_1,z+=_1.size][0].ljust"*a+_1+" "*(1+s1+i.trjoin.size-(?|,"")a+=_1.size))+c}}

Attempt This Online!Attempt This Online!

I managed to golf a non-regex based solution to tie withbeat the other Ruby. There might still beThe solution previously tied but I found a coupleslightly different method that is 6 bytes to be golfed off. I’m still learning Ruby so it took a while to get it this shortshorter.

Explanation:

->s>i,c{…} Proc (lambda function) taking arguments si (code) and c (comment)

  • z=0;a=0; Assign variable za to zero

  • s(i=i.split( ?|) SplitAssign si to it split on |

  • .map{…} Map each _1 in the list to:

    • ["" "*z+_1,z+=_1.size][0] Return _1"*a with za spaces prepended, before adding the length of _1 to  

    • z+_1. Append the list item

    • .ljust+" "*(…) Append this many spaces until the length is equal to…:

      • 1+s1+i.tr(?|,"")join.size One more than the lengthThe size of si with | removed, plus one for the extra space
      • -(a+=_1.size) Add the size of the list item to a and subtract a from this.
    • +c Append the comment character to the end of the line.

Ruby, 80 bytes

->s,c{z=0;s.split(?|).map{[" "*z+_1,z+=_1.size][0].ljust(1+s.tr(?|,"").size)+c}}

Attempt This Online!

I managed to golf a non-regex based solution to tie with the other Ruby. There might still be a couple bytes to be golfed off. I’m still learning Ruby so it took a while to get it this short.

Explanation:

->s,c{…} Proc (lambda function) taking arguments s (code) and c (comment)

  • z=0; Assign variable z to zero

  • s.split(?|) Split s on |

  • .map{…} Map each _1 in the list to:

    • [" "*z+_1,z+=_1.size][0] Return _1 with z spaces prepended, before adding the length of _1 to z.

    • .ljust(…) Append spaces until the length is equal to…

      • 1+s.tr(?|,"").size One more than the length of s with | removed.
    • +c Append the comment character to the end of the line.

Ruby, 80 74 bytes

->i,c{a=0;(i=i.split ?|).map{" "*a+_1+" "*(1+i.join.size-(a+=_1.size))+c}}

Attempt This Online!

I managed to golf a non-regex based solution to beat the other Ruby. The solution previously tied but I found a slightly different method that is 6 bytes shorter.

Explanation:

->i,c{…} Proc (lambda function) taking arguments i (code) and c (comment)

  • a=0; Assign variable a to zero

  • (i=i.split ?|) Assign i to it split on |

  • .map{…} Map each _1 in the list to:

    • " "*a a spaces 

    • +_1 Append the list item

    • +" "*(…) Append this many spaces:

      • 1+i.join.size The size of i with | removed, plus one for the extra space
      • -(a+=_1.size) Add the size of the list item to a and subtract a from this.
    • +c Append the comment character to the end of the line.

Explain
Source Link
noodle person
  • 10.3k
  • 1
  • 22
  • 76

Ruby, 80 bytes

->s,c{z=0;s.split(?|).map{[" "*z+_1,z+=_1.size][0].ljust(1+s.tr(?|,"").size)+c}}

Attempt This Online!

I managed to golf a non-regex based solution to tie with the other Ruby. There might still be a couple bytes to be golfed off. I’m still learning Ruby so it took a while to get it this short.

Explanation:

->s,c{…} Proc (lambda function) taking arguments s (code) and c (comment)

  • z=0; Assign variable z to zero

  • s.split(?|) Split s on |

  • .map{…} Map each _1 in the list to:

    • [" "*z+_1,z+=_1.size][0] Return _1 with z spaces prepended, before adding the length of _1 to z.

    • .ljust(…) Append spaces until the length is equal to…

      • 1+s.tr(?|,"").size One more than the length of s with | removed.
    • +c Append the comment character to the end of the line.

Ruby, 80 bytes

->s,c{z=0;s.split(?|).map{[" "*z+_1,z+=_1.size][0].ljust(1+s.tr(?|,"").size)+c}}

Attempt This Online!

I managed to golf a non-regex based solution to tie with the other Ruby. There might still be a couple bytes to be golfed off. I’m still learning Ruby so it took a while to get it this short.

Ruby, 80 bytes

->s,c{z=0;s.split(?|).map{[" "*z+_1,z+=_1.size][0].ljust(1+s.tr(?|,"").size)+c}}

Attempt This Online!

I managed to golf a non-regex based solution to tie with the other Ruby. There might still be a couple bytes to be golfed off. I’m still learning Ruby so it took a while to get it this short.

Explanation:

->s,c{…} Proc (lambda function) taking arguments s (code) and c (comment)

  • z=0; Assign variable z to zero

  • s.split(?|) Split s on |

  • .map{…} Map each _1 in the list to:

    • [" "*z+_1,z+=_1.size][0] Return _1 with z spaces prepended, before adding the length of _1 to z.

    • .ljust(…) Append spaces until the length is equal to…

      • 1+s.tr(?|,"").size One more than the length of s with | removed.
    • +c Append the comment character to the end of the line.

Source Link
noodle person
  • 10.3k
  • 1
  • 22
  • 76

Ruby, 80 bytes

->s,c{z=0;s.split(?|).map{[" "*z+_1,z+=_1.size][0].ljust(1+s.tr(?|,"").size)+c}}

Attempt This Online!

I managed to golf a non-regex based solution to tie with the other Ruby. There might still be a couple bytes to be golfed off. I’m still learning Ruby so it took a while to get it this short.