English: Your solution works, but you can do better.  Use functions to reduce the amount of repeated code.
Translation: Tifrat-ik tetteddu, maca tzemreḍ ad txedmeḍ ugar. Seqdec tiwuriwin akken ad tesneɣseḍ tasmekta n tengalt yettwalsen.