You could utilize sin(), it goes from -1 to 1 as well as smoothly inbetween.
So you’d start with
Shift it over so when x=0 it will be 1
Next change it so it goes from -1 to 1 every 90 instead of 180.
You could also use cos() instead. It’s just 90 off from sin()
If you don’t want the smooth transitions inbetween you could utilize some rounding.
Hope that helps.