Skip to main content
I am the globglogabgalag, I love sed and this site is a true treasure trove
Source Link
user41805
  • 13.2k
  • 6
  • 42
  • 88

sed -r, 13193 131 136 bytes

s/1+/&&&&&&&&&&/
s/$/;,/
:d
s/,.+/,/
:
s/^(1+)(1*;\1;1*;.*1*;\1;1*,)1{10}?/\21/
t
s/^1*1*/&&&&&&&&&&/
ta
:a
s/,1{10}/1,/
ta
s/^(1*;1*;)1/\1,/
td
s/.+,//

Try it online!Try it online!

(See output in decimal)

Takes input in unary and outputs in unary, and the program is 01-indexed (0 is shown in unary by an empty string). Thankfully, this challenge has already prepared me for this challengeone.

The concept is similar, both implement long division. Here, I perform long division x times, where x is the digit after the decimal place that I have to find. After each iteration, I discard the previous decimal places because they are no longer needed.

While doing division, the program is in the format dividend;divisor;x;dividend;divisor;x,result where .

s/$/,/ adds this comma, the comma is required to separate the "decimal place".result from everything else

###Explanation (more coming soon)Then follows the main program loop

Multiply the dividend by 10. Now the program can start at the decimal point so that it's easier to calculate the xth number after the decimal place. Then append the "decimal point", which is in reality a comma instead to save bytes.:d label d

s/1+/&&&&&&&&&&/
s/$/;,/
  • s/,.+/,/ remove everything after the comma

  • : empty label

    • s/(1+)(1*;\1;1*,)1{10}?/\21/ perform division, adding 1 to the result each iteration, whilst simultaneously removing blocks of 10 continuous 1s in the result
  • t branch to the empty label, in other words, loop until the dividend has been exhausted

  • s/1*/&&&&&&&&&&/ multiply the dividend by 10 to prepare for the next iteration

  • ta branch to label a

  • :a label a, this line and the line above are required to make td work

  • s/1,/,/ subtract 1 from x

Thentd conditional branch to d, this is triggered if there has been a successful substitution since the last conditional branch, since :ds/1*/&&&&&&&&&&/ denotes the step whereis always successful, td will always get triggered, but by introducing branch a, we dofix that so that it only depends on the division.previous substitution

We want to delete the digit afters/.+,// finally, remove everything but the decimal place after each iteration.result

s/,.+/,/

sed -r, 131 136 bytes

s/1+/&&&&&&&&&&/
s/$/;,/
:d
s/,.+/,/
:
s/^(1+)(1*;\1;1*;.*)/\21/
t
s/^1*/&&&&&&&&&&/
:a
s/,1{10}/1,/
ta
s/^(1*;1*;)1/\1/
td
s/.+,//

Try it online!

Takes input in unary and outputs in unary, and the program is 0-indexed (0 is shown in unary by an empty string). Thankfully, this challenge has already prepared me for this challenge.

The concept is similar, both implement long division. Here, I perform long division x times, where x is the digit after the decimal place that I have to find. After each iteration, I discard the previous decimal places because they are no longer needed.

While doing division, the program is in the dividend;divisor;x;,result where , is the "decimal place".

###Explanation (more coming soon)

Multiply the dividend by 10. Now the program can start at the decimal point so that it's easier to calculate the xth number after the decimal place. Then append the "decimal point", which is in reality a comma instead to save bytes.

s/1+/&&&&&&&&&&/
s/$/;,/

Then the :d denotes the step where we do the division.

We want to delete the digit after the decimal place after each iteration.

s/,.+/,/

sed -r, 93 131 136 bytes

s/$/,/
:d
s/,.+/,/
:
s/(1+)(1*;\1;1*,)1{10}?/\21/
t
s/1*/&&&&&&&&&&/
ta
:a
s/1,/,/
td
s/.+,//

Try it online!

(See output in decimal)

Takes input in unary and outputs in unary, and the program is 1-indexed. Thankfully, this challenge has already prepared me for this one.

The concept is similar, both implement long division. Here, I perform long division x times, where x is the digit after the decimal place that I have to find. After each iteration, I discard the previous decimal places because they are no longer needed.

While doing division, the program is in the format dividend;divisor;x,result.

s/$/,/ adds this comma, the comma is required to separate the result from everything else

Then follows the main program loop

:d label d

  • s/,.+/,/ remove everything after the comma

  • : empty label

    • s/(1+)(1*;\1;1*,)1{10}?/\21/ perform division, adding 1 to the result each iteration, whilst simultaneously removing blocks of 10 continuous 1s in the result
  • t branch to the empty label, in other words, loop until the dividend has been exhausted

  • s/1*/&&&&&&&&&&/ multiply the dividend by 10 to prepare for the next iteration

  • ta branch to label a

  • :a label a, this line and the line above are required to make td work

  • s/1,/,/ subtract 1 from x

td conditional branch to d, this is triggered if there has been a successful substitution since the last conditional branch, since s/1*/&&&&&&&&&&/ is always successful, td will always get triggered, but by introducing branch a, we fix that so that it only depends on the previous substitution

s/.+,// finally, remove everything but the result

uggh my sed used to be awful, there, shaved some of that verbosity
Source Link
user41805
  • 13.2k
  • 6
  • 42
  • 88

sed, 136 + 1 (-r flag) = 137, 131 136 bytes

s/1+/&&&&&&&&&&/
s/$/;,/
:d
s/,.+/,/
:
s/^(1+)(1*;\1;1*;.*)/\21/
t
s/^1*/&&&&&&&&&&/
:a
s/,1{10}/1,/
ta
s/^(\w*;\w*;)1/\1/
td
s/[;1]+,//
s/1+/&&&&&&&&&&/
s/$/;,/
:d
s/,.+/,/
:
s/^(1+)(1*;\1;1*;.*)/\21/
t
s/^1*/&&&&&&&&&&/
:a
s/,1{10}/1,/
ta
s/^(1*;1*;)1/\1/
td
s/.+,//

Try it online!Try it online!

Takes input in unary and outputs in unary, and the program is 0-indexed (0 is shown in unary by an empty string). Thankfully, this challenge has already prepared me for this challenge.

The concept is similar, both implement long division. Here, I perform long division x times, where x is the digit after the decimal place that I have to find. After each iteration, I discard the previous decimal places because they are no longer needed.

While doing division, the program is in the dividend;divisor;x;,result where , is the "decimal place".

###Explanation (more coming soon)

Multiply the dividend by 10. Now the program can start at the decimal point so that it's easier to calculate the xth number after the decimal place. Then append the "decimal point", which is in reality a comma instead to save bytes.

s/1+/&&&&&&&&&&/
s/$/;,/
s/1+/&&&&&&&&&&/
s/$/;,/

Then the :d denotes the step where we do the division.

We want to delete the digit after the decimal place after each iteration.

s/,.+/,/
s/,.+/,/

sed, 136 + 1 (-r flag) = 137 bytes

s/1+/&&&&&&&&&&/
s/$/;,/
:d
s/,.+/,/
:
s/^(1+)(1*;\1;1*;.*)/\21/
t
s/^1*/&&&&&&&&&&/
:a
s/,1{10}/1,/
ta
s/^(\w*;\w*;)1/\1/
td
s/[;1]+,//

Try it online!

Takes input in unary and outputs in unary, and the program is 0-indexed (0 is shown in unary by an empty string). Thankfully, this challenge has already prepared me for this challenge.

The concept is similar, both implement long division. Here, I perform long division x times, where x is the digit after the decimal place that I have to find. After each iteration, I discard the previous decimal places because they are no longer needed.

While doing division, the program is in the dividend;divisor;x;,result where , is the "decimal place".

###Explanation (more coming soon)

Multiply the dividend by 10. Now the program can start at the decimal point so that it's easier to calculate the xth number after the decimal place. Then append the "decimal point", which is in reality a comma instead to save bytes.

s/1+/&&&&&&&&&&/
s/$/;,/

Then the :d denotes the step where we do the division.

We want to delete the digit after the decimal place after each iteration.

s/,.+/,/

sed -r, 131 136 bytes

s/1+/&&&&&&&&&&/
s/$/;,/
:d
s/,.+/,/
:
s/^(1+)(1*;\1;1*;.*)/\21/
t
s/^1*/&&&&&&&&&&/
:a
s/,1{10}/1,/
ta
s/^(1*;1*;)1/\1/
td
s/.+,//

Try it online!

Takes input in unary and outputs in unary, and the program is 0-indexed (0 is shown in unary by an empty string). Thankfully, this challenge has already prepared me for this challenge.

The concept is similar, both implement long division. Here, I perform long division x times, where x is the digit after the decimal place that I have to find. After each iteration, I discard the previous decimal places because they are no longer needed.

While doing division, the program is in the dividend;divisor;x;,result where , is the "decimal place".

###Explanation (more coming soon)

Multiply the dividend by 10. Now the program can start at the decimal point so that it's easier to calculate the xth number after the decimal place. Then append the "decimal point", which is in reality a comma instead to save bytes.

s/1+/&&&&&&&&&&/
s/$/;,/

Then the :d denotes the step where we do the division.

We want to delete the digit after the decimal place after each iteration.

s/,.+/,/
added 485 characters in body
Source Link
user41805
  • 13.2k
  • 6
  • 42
  • 88

sed, 136 + 1 (-r flag) = 137 bytes

s/1+/&&&&&&&&&&/
s/$/;,/
:d
s/,.+/,/
:
s/^(1+)(1*;\1;1*;.*)/\21/
t
s/^1*/&&&&&&&&&&/
:a
s/,1{10}/1,/
ta
s/^(\w*;\w*;)1/\1/
td
s/[;1]+,//

Try it online!

Takes input in unary and outputs in unary, and the program is 0-indexed (0 is shown in unary by an empty string). Thankfully, this challenge has already prepared me for this challenge.

The concept is similar, both implement long division. Here, I perform long division x times, where x is the digit after the decimal place that I have to find. After each iteration, I discard the previous decimal places because they are no longer needed.

While doing division, the program is in the dividend;divisor;x;,result where , is the "decimal place".

###Explanation (more coming soon)

Multiply the dividend by 10. Now the program can start at the decimal point so that it's easier to calculate the xth number after the decimal place. Then append the "decimal point", which is in reality a comma instead to save bytes.

s/1+/&&&&&&&&&&/
s/$/;,/

Then the :d denotes the step where we do the division.

We want to delete the digit after the decimal place after each iteration.

s/,.+/,/

sed, 136 bytes

s/1+/&&&&&&&&&&/
s/$/;,/
:d
s/,.+/,/
:
s/^(1+)(1*;\1;1*;.*)/\21/
t
s/^1*/&&&&&&&&&&/
:a
s/,1{10}/1,/
ta
s/^(\w*;\w*;)1/\1/
td
s/[;1]+,//

Try it online!

Takes input in unary and outputs in unary, and the program is 0-indexed (0 is shown in unary by an empty string). Thankfully, this challenge has already prepared me for this challenge.

The concept is similar, both implement long division. Here, I perform long division x times, where x is the digit after the decimal place that I have to find. After each iteration, I discard the previous decimal places because they are no longer needed.

While doing division, the program is in the dividend;divisor;x;,result where , is the "decimal place".

sed, 136 + 1 (-r flag) = 137 bytes

s/1+/&&&&&&&&&&/
s/$/;,/
:d
s/,.+/,/
:
s/^(1+)(1*;\1;1*;.*)/\21/
t
s/^1*/&&&&&&&&&&/
:a
s/,1{10}/1,/
ta
s/^(\w*;\w*;)1/\1/
td
s/[;1]+,//

Try it online!

Takes input in unary and outputs in unary, and the program is 0-indexed (0 is shown in unary by an empty string). Thankfully, this challenge has already prepared me for this challenge.

The concept is similar, both implement long division. Here, I perform long division x times, where x is the digit after the decimal place that I have to find. After each iteration, I discard the previous decimal places because they are no longer needed.

While doing division, the program is in the dividend;divisor;x;,result where , is the "decimal place".

###Explanation (more coming soon)

Multiply the dividend by 10. Now the program can start at the decimal point so that it's easier to calculate the xth number after the decimal place. Then append the "decimal point", which is in reality a comma instead to save bytes.

s/1+/&&&&&&&&&&/
s/$/;,/

Then the :d denotes the step where we do the division.

We want to delete the digit after the decimal place after each iteration.

s/,.+/,/
colours!
Source Link
user41805
  • 13.2k
  • 6
  • 42
  • 88
Loading
Source Link
user41805
  • 13.2k
  • 6
  • 42
  • 88
Loading