Line up

Line up

Medium

Introduction

Your friend Yaʻqūb works the counter at a deli in town, slicing, weighing, and wrapping orders for a line of hungry customers that gets longer every day. Waiting customers are starting to lose track of who is next, so he wants numbered tickets they can use to track the order in which they arrive.

To make the customers feel special, he does not want the ticket to have only a number on it. They shall get a proper English sentence with their name and number on it.

Instructions

Given a name and a number, your task is to produce a sentence using that name and that number as an ordinal numeral. Yaʻqūb expects to use numbers from 1 up to 999.

Rules:

  • Numbers ending in 1 (unless ending in 11) → "st"
  • Numbers ending in 2 (unless ending in 12) → "nd"
  • Numbers ending in 3 (unless ending in 13) → "rd"
  • All other numbers → "th"

Examples:

  • "Mary", 1 → "Mary, you are the 1st customer we serve today. Thank you!"
  • "John", 12 → "John, you are the 12th customer we serve today. Thank you!"
  • "Dahir", 162 → "Dahir, you are the 162nd customer we serve today. Thank you!"

Registers

Register Usage Type Description
$a0 input address null-terminated name string
$a1 input integer number
$a2 input/output address null-terminated result string
$t0-9 temporary any for temporary storage
Edit via GitHub The link opens in a new window or tab
MIPS Assembly Exercism

Ready to start Line up?

Sign up to Exercism to learn and master MIPS Assembly with 70 exercises, and real human mentoring, all for free.