Revision ffec0d14-e897-46a3-b975-14d0df6b6c2f - Code Golf Stack Exchange

# [Jelly], 13 [bytes]

 æḟ©3Ḥạ+⁺_®)»ċ

A monadic Link that accepts a non-negative integer, \$N\,ドル and yields the value of \$f(n)\$.

**[Try it online!][TIO-lzrbfq91]** Or see the [test-suite].

#### How?

Outputs the number of terms less than or equal to \$N\$ in another sequence - the unique, strictly increasing sequence of non-negative integers, \$a\,ドル such that \$a(a(n)) = 3n\$. This is [A003605](https://oeis.org/A003605 "OEIS"), which gives the indices at which an increase occurs in \$f\$.

 æḟ©3Ḥạ+⁺_®)»ċ - Link: non-negative integer, N
 ) - for each {I in [1..N] ([] if N==0)}:
 æḟ 3 - floor to the nearest power of three
 © - (and copy this to the register)
 Ḥ - double {that}
 ạ - {that} absolute difference {I}
 ⁺ - do this twice:
 + - add {I}
 _® - subtract the value stored in the register
 » - maximum with {N} (vectorises)
 ċ - count occurrences of {N}


[Jelly]: https://github.com/DennisMitchell/jelly
[bytes]: https://github.com/DennisMitchell/jelly/wiki/Code-page

[TIO-lzrbfq91]: https://tio.run/##ASgA1/9qZWxsef//w6bhuJ/CqTPhuKThuqEr4oG6X8KuKcK7xIv///8xMzM3 "Jelly – Try It Online"

[test-suite]: https://tio.run/##y0rNyan8///wsoc75h9aafxwx5KHuxZqP2rcFX9oneah3Ue6/x9uf9S05v//aAMdBUMdBSMgMgNicx0FU2MgNgGKGhubxwIA "Jelly – Try It Online"

AltStyle によって変換されたページ (->オリジナル) /