Added some alternative solutions using functions