Skip to main content
3 of 5
added 485 characters in body
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/,.+/,/
user41805
  • 13.2k
  • 6
  • 42
  • 88