1∘+⍣{('3'∊⍕⍺)<×3|⍺}
온라인으로 사용해보십시오!
Adám 덕분에 -6. ngn 덕분에 -8.
이전 설명 :
1-⍨g⍣((×3|⊢)>'3'∊⍕)∘(g←+∘1)
+∘1 ⍝ curry + with 1, gives the increment function
⍝ increments the left argument so we do not return the number itself
(g← ) ⍝ assign to "g"
∘ ⍝ compose g with the repeat
⍕ ⍝ does parsing the argument to a string...
'3'∊ ⍝ ...contain '3'?
3|⊢ ⍝ residue of a division by 3
(× ) ⍝ direction (0 if 0, 1 if greater, ¯1 is lower)
( > ) ⍝ and not (we want the left side to be 1, the right side 0)
g⍣ ⍝ repeat "g" (increment) until this function is true ^
1-⍨ ⍝ afterwards, decrement: inversed -
1∘+⍣(3(×⍤|>∊⍥⍕)⊣)
온라인으로 사용해보십시오!
Adám에게 감사합니다. ngn 덕분에 -6입니다.
이전 설명 :
0+⍣(3(×⍤|>∊⍥⍕)⊢)⍢(1+⊢)⊢
0 ⍝ the left argument (⍺)
+⍣(3(×⍤|>∊⍥⍕)⊢) ⍝ the left function (⍺⍺)
(1+⊢) ⍝ the right function (⍵⍵)
⍝ (increments its argument)
⊢ ⍝ the right argument (⍵)
⍝ (just returns the input)
⍢ ⍝ under:
⍝ calls (⍵⍵ ⍵) first, which increments the input
⍝ also (⍵⍵ ⍺) which gives 1
⍝ then calls (⍺incremented ⍺⍺ ⍵incremented)
⍝ afterwards, does the opposite of ⍵⍵, and decrements the result
⍣ ⍝ ⍣ fixpoint: repeats the left operation until the right side is truthy
+ ⍝ calls + with ⍺incremented and the input (so, 1+input)
(3(×⍤|>∊⍥⍕)⊢) ⍝ right operation
3 ⍝ on its left, "3"
⊢ ⍝ on its right, the current iteration
×⍤| ⍝ divisibility check: × atop |
| ⍝ starts with 3|⊢ (residue of ⊢/3)
× ⍝ then returns the direction (0 if 0, 1 if greater, ¯1 is lower)
∊⍥⍕ ⍝ contains 3:
⍕ ⍝ stringifies both its arguments (3 and ⊢)
∊⍥ ⍝ checks for membership
> ⍝ divisibility "and not" contains 3