Skip to main content
added 35 characters in body
Source Link
Neil
  • 177.2k
  • 12
  • 74
  • 281

RetinaRetina 0.8.2, 151134 bytes

.+
,$&,$&*$&$*
+`,(.)*,((_+1*?)((?=\3+$=\2+$)(?<=(?=(?<-1>(?=((_*1*)(?=\3\5+$=\2\5+$)_1)(\4*$))\6)+_$+1$)\3\2).*|(?<-1>(_+))(?<-1>\71>\2)+|(?<-1>_1>1)+(_*))$(?(1)_1)
_1,$.($3$7$8)2,$3$7$8$2
_1

Try it online!Try it online! Link includes faster test cases. Explanation:

.+
,$&,$&*$&$*

Create a working area consisting of the result (initially 0), the input, and the input converted to unary.

+`

Repeat until the input has been reduced to zero ...

,(.)*,(1*?)(

count the number of digits d in the value n, and then matchfind the smallest value that satisfies one of ...

(_+)(?=\3+$=\2+$)(?<=(?=(?<-1>(?=((_*1*)(?=\3\5+$=\2\5+$)_1)(\4*$))\6)+_$+1$)\3\2).*|

... theits dth root ofpower is n, if it exists, or ...

(?<-1>(_+))(?<-1>\71>\2)+|

... its product with n/d, if it exists is n, or ...

(?<-1>_1>1)+(_*))

... its sum with n-d is n, and ...

$(?(1)_1)

ensure that it was in fact d and not some smaller integer, and ...

_1,$.($3$7$8)2,$3$7$8$2

increment the output and replace n and its unary with whichever match produced athe result.

_1

Convert the output to decimal.

Retina, 151 bytes

.+
,$&,$&*
+`,(.)*,((_+)(?=\3+$)(?<=(?=(?<-1>(?=((_*)(?=\3\5+$)_)(\4*$))\6)+_$)\3).*|(?<-1>(_+))(?<-1>\7)+|(?<-1>_)+(_*))$(?(1)_)
_,$.($3$7$8),$3$7$8
_

Try it online! Link includes faster test cases. Explanation:

.+
,$&,$&*

Create a working area consisting of the result (initially 0), the input, and the input converted to unary.

+`

Repeat until the input has been reduced to zero ...

,(.)*,(

count the number of digits d in the value n, and then match one of ...

(_+)(?=\3+$)(?<=(?=(?<-1>(?=((_*)(?=\3\5+$)_)(\4*$))\6)+_$)\3).*|

... the dth root of n, if it exists, or ...

(?<-1>(_+))(?<-1>\7)+|

... n/d, if it exists, or ...

(?<-1>_)+(_*))

... n-d, and ...

$(?(1)_)

ensure that it was in fact d and not some smaller integer, and ...

_,$.($3$7$8),$3$7$8

increment the output and replace n and its unary with whichever match produced a result.

_

Convert the output to decimal.

Retina 0.8.2, 134 bytes

.+
,$&,$&$*
+`,(.)*,(1*?)((?=\2+$)(?<=(?=(?<-1>(?=((1*)(?=\2\5+$)1)(\4*$))\6)+1$)\2).*|(?<-1>)(?<-1>\2)+|(?<-1>1)+)$(?(1)1)
1,$.2,$2
1

Try it online! Link includes faster test cases. Explanation:

.+
,$&,$&$*

Create a working area consisting of the result (initially 0), the input, and the input converted to unary.

+`

Repeat until the input has been reduced to zero ...

,(.)*,(1*?)(

count the number of digits d in the value n, and then find the smallest value that satisfies one of ...

(?=\2+$)(?<=(?=(?<-1>(?=((1*)(?=\2\5+$)1)(\4*$))\6)+1$)\2).*|

... its dth power is n, or ...

(?<-1>)(?<-1>\2)+|

... its product with d is n, or ...

(?<-1>1)+)

... its sum with d is n, and ...

$(?(1)1)

ensure that it was in fact d and not some smaller integer, and ...

1,$.2,$2

increment the output and replace n and its unary with the result.

1

Convert the output to decimal.

Source Link
Neil
  • 177.2k
  • 12
  • 74
  • 281

Retina, 151 bytes

.+
,$&,$&*
+`,(.)*,((_+)(?=\3+$)(?<=(?=(?<-1>(?=((_*)(?=\3\5+$)_)(\4*$))\6)+_$)\3).*|(?<-1>(_+))(?<-1>\7)+|(?<-1>_)+(_*))$(?(1)_)
_,$.($3$7$8),$3$7$8
_

Try it online! Link includes faster test cases. Explanation:

.+
,$&,$&*

Create a working area consisting of the result (initially 0), the input, and the input converted to unary.

+`

Repeat until the input has been reduced to zero ...

,(.)*,(

count the number of digits d in the value n, and then match one of ...

(_+)(?=\3+$)(?<=(?=(?<-1>(?=((_*)(?=\3\5+$)_)(\4*$))\6)+_$)\3).*|

... the dth root of n, if it exists, or ...

(?<-1>(_+))(?<-1>\7)+|

... n/d, if it exists, or ...

(?<-1>_)+(_*))

... n-d, and ...

$(?(1)_)

ensure that it was in fact d and not some smaller integer, and ...

_,$.($3$7$8),$3$7$8

increment the output and replace n and its unary with whichever match produced a result.

_

Convert the output to decimal.