Skip to main content
Rollback to Revision 3
Source Link
manatwork
  • 20.6k
  • 5
  • 51
  • 81

Ruby, 41 35 34 3234 characters

(40 34 33 3133 characters code + 1 character command line option)

gsub(/(.*?)#/){putc$1.size%127}
gsub(/.*?#/){putc$&.count ?;%127}

Thanks to:

  • Jordan for suggesting to use putc to not need explicit conversion with .chr (6 characters)
  • Kirill L. for finding the unnecessary parenthesis (1 character)
  • Jordan for using captured group to be able to change from .count to .size (2 characters)

Sample run:

bash-54.1$4$ ruby -ne 'gsub(/(.*?)#/){putc$1putc$&.size%127count ?;%127}' < '2d{.;#' | od -tad1
0000000    2   fsetb    d  nul  nul  etxnul  sohnul  stx  stx{  nul  nul  nul
          50   2823  100    0    0    3  0  1  0  2123    20    0    0
0000013

Try it online!Try it online!

Ruby, 41 35 34 32 characters

(40 34 33 31 characters code + 1 character command line option)

gsub(/(.*?)#/){putc$1.size%127}

Thanks to:

  • Jordan for suggesting to use putc to not need explicit conversion with .chr (6 characters)
  • Kirill L. for finding the unnecessary parenthesis (1 character)
  • Jordan for using captured group to be able to change from .count to .size (2 characters)

Sample run:

bash-5.1$ ruby -ne 'gsub(/(.*?)#/){putc$1.size%127}' < '2d{.;#' | od -tad1
0000000    2   fs    d  nul  nul  etx  soh  stx  stx  nul  nul
          50   28  100    0    0    3    1    2    2    0    0
0000013

Try it online!

Ruby, 41 35 34 characters

(40 34 33 characters code + 1 character command line option)

gsub(/.*?#/){putc$&.count ?;%127}

Thanks to:

  • Jordan for suggesting to use putc to not need explicit conversion with .chr (6 characters)
  • Kirill L. for finding the unnecessary parenthesis (1 character)

Sample run:

bash-4.4$ ruby -ne 'gsub(/.*?#/){putc$&.count ?;%127}' < '2d{.;#' | od -tad1
0000000    2  etb    d  nul  nul  nul  nul    {  nul  nul  nul
          50   23  100    0    0    0    0  123    0    0    0
0000013

Try it online!

added 136 characters in body
Source Link
manatwork
  • 20.6k
  • 5
  • 51
  • 81

Ruby, 41 35 3434 32 characters

(40 34 3333 31 characters code + 1 character command line option)

gsub(/.*?#/){putc$&.count ?;%127}
gsub(/(.*?)#/){putc$1.size%127}

Thanks to:

  • Jordan for suggesting to use putc to not need explicit conversion with .chr (6 characters)
  • Kirill L. for finding the unnecessary parenthesis (1 character)
  • Jordan for using captured group to be able to change from .count to .size (2 characters)

Sample run:

bash-45.4$1$ ruby -ne 'gsub(/(.*?)#/){putc$&putc$1.count ?;%127size%127}' < '2d{.;#' | od -tad1
0000000    2  etb  fs  d  nuld  nul  nul  nuletx  soh  {stx  nulstx  nul  nul
          50   2328  100    0    0    03    01  123  2  0  2    0    0
0000013

Try it online!Try it online!

Ruby, 41 35 34 characters

(40 34 33 characters code + 1 character command line option)

gsub(/.*?#/){putc$&.count ?;%127}

Thanks to:

  • Jordan for suggesting to use putc to not need explicit conversion with .chr (6 characters)
  • Kirill L. for finding the unnecessary parenthesis (1 character)

Sample run:

bash-4.4$ ruby -ne 'gsub(/.*?#/){putc$&.count ?;%127}' < '2d{.;#' | od -tad1
0000000    2  etb    d  nul  nul  nul  nul    {  nul  nul  nul
          50   23  100    0    0    0    0  123    0    0    0
0000013

Try it online!

Ruby, 41 35 34 32 characters

(40 34 33 31 characters code + 1 character command line option)

gsub(/(.*?)#/){putc$1.size%127}

Thanks to:

  • Jordan for suggesting to use putc to not need explicit conversion with .chr (6 characters)
  • Kirill L. for finding the unnecessary parenthesis (1 character)
  • Jordan for using captured group to be able to change from .count to .size (2 characters)

Sample run:

bash-5.1$ ruby -ne 'gsub(/(.*?)#/){putc$1.size%127}' < '2d{.;#' | od -tad1
0000000    2   fs    d  nul  nul  etx  soh  stx  stx  nul  nul
          50   28  100    0    0    3    1    2    2    0    0
0000013

Try it online!

thanks, Kirill L.
Source Link
manatwork
  • 20.6k
  • 5
  • 51
  • 81

Ruby, 41 3535 34 characters

(40 3434 33 characters code + 1 character command line option)

gsub(/.*?#/){putc$&.count( ?;)%127;%127}

Thanks to:

  • Jordan for suggesting to use putc to not need explicit conversion with .chr (6 characters)
  • Kirill L. for finding the unnecessary parenthesis (1 character)

Sample run:

bash-4.4$ ruby -ne 'gsub(/.*?#/){putc$&.count( ?;)%127;%127}' < '2d{.;#' | od -tad1
0000000    2  etb    d  nul  nul  nul  nul    {  nul  nul  nul
          50   23  100    0    0    0    0  123    0    0    0
0000013

Try it online!Try it online!

Ruby, 41 35 characters

(40 34 characters code + 1 character command line option)

gsub(/.*?#/){putc$&.count(?;)%127}

Thanks to:

  • Jordan for suggesting to use putc to not need explicit conversion with .chr (6 characters)

Sample run:

bash-4.4$ ruby -ne 'gsub(/.*?#/){putc$&.count(?;)%127}' < '2d{.;#' | od -tad1
0000000    2  etb    d  nul  nul  nul  nul    {  nul  nul  nul
          50   23  100    0    0    0    0  123    0    0    0
0000013

Try it online!

Ruby, 41 35 34 characters

(40 34 33 characters code + 1 character command line option)

gsub(/.*?#/){putc$&.count ?;%127}

Thanks to:

  • Jordan for suggesting to use putc to not need explicit conversion with .chr (6 characters)
  • Kirill L. for finding the unnecessary parenthesis (1 character)

Sample run:

bash-4.4$ ruby -ne 'gsub(/.*?#/){putc$&.count ?;%127}' < '2d{.;#' | od -tad1
0000000    2  etb    d  nul  nul  nul  nul    {  nul  nul  nul
          50   23  100    0    0    0    0  123    0    0    0
0000013

Try it online!

added 174 characters in body
Source Link
manatwork
  • 20.6k
  • 5
  • 51
  • 81
Loading
Source Link
manatwork
  • 20.6k
  • 5
  • 51
  • 81
Loading