Revision 9ee89d98-818a-4bb4-bec4-d15bf4f3ad2d - Code Golf Stack Exchange

# [Jelly], <s>&nbsp;13&nbsp;</s> 10 [bytes]

-3 bytes porting [Dominic van Essen's](https://codegolf.stackexchange.com/users/95126/dominic-van-essen) implementation of my approach.

 b3ḢḂȧ%3¬)S

**[Try it online!][1]** Or see the [test-suite][2].

#### How?

 b3ḢḂȧ%3¬)S - Link: non-negative integer, N
 ) - for each {I in [1..N] ([] if N==0)}:
 b3 - convert {I} to base three
 Ḣ - head of {that}
 Ḃ - {that} mod two -> L
 %3 - {I} mod three -> R
 ȧ - {L} logical AND {R}
 ¬ - logical NOT of {that}
 S - sum

(I sometimes wish there was a logical NAND dyad, or at least one that acts that way with zeros and ones.)


[1]: https://tio.run/##y0rNyan8/z/J@OGORQ93NJ1Yrmp8aI1m8P///w2Njc0B "Jelly – Try It Online"
[2]: https://tio.run/##y0rNyan8/z/J@OGORQ93NJ1Yrmp8aI1m8P/D7Y@a1vz/H22go2Coo2AERGZAbK6jYGoMxCZAUWNj81gA "Jelly – Try It Online"

---

### Original at 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 によって変換されたページ (->オリジナル) /