Skip to main content
2 of 3
deleted 1198 characters in body
pxeger
  • 25.3k
  • 4
  • 59
  • 146

Zsh, 20 bytes

\$ f(x) = \lfloor \frac x 2 \rfloor \$

<<<$[$1/2]

Attempt This Online!

\$ g(x) = 2x \$

<<<$[$1*2]

Attempt This Online!

For even \$ x \$, \$ f(x) = \frac x 2 \$, so \$ g(f(x)) = x \$.

But for odd \$ x \$, /2 rounds downwards, so \$ f(x) = f(x-1) \$, so \$ g(f(x)) = x - 1 \ne x \$

\$ g(x) \$ is always even, so for all \$ x \$, \$ f(g(x)) = x \$.

Therefore, \$ f(g(x)) = g(f(x)) \$ if and only if \$ x \$ is even.

pxeger
  • 25.3k
  • 4
  • 59
  • 146