A story for the change exercise

This exercise is known to be challenging for many. To make it more approachable, the introduction has been designed to explain the task using a simple, engaging story. As part of these revisions, the examples in the instructions have been adjusted to use generic coins with specific values, avoiding references to specific denominations like nickels or quarters.


Introduction

In the mystical village of Coinholt, you stand behind the counter of your bakery, arranging a fresh batch of pastries. The door creaks open, and in walks Denara, a skilled merchant with a keen eye for quality goods. After a quick meal, she slides a shimmering coin across the counter, representing a value of 100 units.

You smile, taking the coin, and glance at the total cost of the meal: 88 units. That means you need to return 12 units in change.

Denara holds out her hand expectantly. “Just give me the fewest coins,” she says with a smile. “My pouch is already full, and I don’t want to risk losing them on the road.”

You know you have a few options. “We have Lumis (worth 10 units), Viras (worth 5 units), and Zenth (worth 2 units) available for change.”

You quickly calculate the possibilities in your head:

  • one Lumis (1 × 10 units) + one Zenth (1 × 2 units) = 2 coins total
  • two Viras (2 × 5 units) + one Zenth (1 × 2 units) = 3 coins total
  • six Zenth (6 × 2 units) = 6 coins total

“The best choice is two coins: one Lumis and one Zenth,” you say, handing her the change.

Denara smiles, clearly impressed. “As always, you’ve got it right.”

Instructions

Correctly determine the fewest number of coins to be given to a customer such that the sum of the coins’ value would equal the correct amount of change.

Examples

  • An amount of 15 with available coin values [1, 5, 10, 25, 100] should return one coin of value 5 and one coin of value 10, or [5, 10].
  • An amount of 40 with available coin values [1, 5, 10, 25, 100] should return one coin of value 5, one coin of value 10, and one coin of value 25, or [5, 10, 25].

Edge cases

  • Does your algorithm work for any given set of coins?
  • Can you ask for negative change?
  • Can you ask for a change value smaller than the smallest coin value?
1 Like

Adding the example from the intro as an extra example in the instructions is also an option.

Thanks for approaching this exercise. Avoding specific currencies and their coin values might indeed help people with the exercise.

“Coin” seems like a problematic choice to describe other coins. “This coin is 100 coins, this coin is 2 coins”. I would use another base unit

I would advise against using “ledger”. Not everyone on exercism is proficient in English and might stumble upon that part. Try to make it easier to understand. Something like “total value of Denaras meal” is straighforward enough, isn’t it?

@vaeng Noted. I’ll see what I can do to address both issues, and I believe they can be resolved easily.

Edit: Used “unit” as the base value and changed “glance at the total on your ledger” to “glance at the total cost of the meal”

2 Likes

We generally don’t include edge cases in the prose; we rely on the tests to surface that. Do we want to deviate from that in this exercise?

Yeah, I’m not sure about the edge cases either. I’ve just copied them verbatim from the current description and only tweaked the wording in the examples.

Let’s omit them. These were in relation to track-specific tests from PHP, but those tests weren’t added to the problem specifications repo. From the wording, it’s unclear whether these are part of the tests going in or not so that adds confusion. As a general thought exercise, these edge cases might be better discussed within a mentoring discussion.

In the case of “ledger” it is a complete word, not a niche word, and is common anywhere accounting is used, but more importantly, the word can be looked up in any English dictionary I have seen.

I would not avoid using it. It also suggests a “sense of balance” for those that are already familiar with the word.

I think the point is to not have students look up words unnecessarily. We want to draw students in with an easily digestible framing narrative.

2 Likes

In retrospect, I believe this story suffers from the same issue as the one for the Collatz Conjecture. There are details in the story that could easily be moved to the instructions. However, I think this would make the exercise less engaging, as people tend to dislike reading instructions. What does everyone else think?

The rewarding is good. I would not necessarily go out of my way to avoid a real word that is easily looked up, though. Had it stayed in, I would have suggested expanding as an introduction of the word as “ledger, a book of accounts” maybe.

I am all about not using complex words, such as implement and implementation, as that is a very versatile word to the point where it is often hard which sense is being used. But ledger is not one of them.

More than avoiding complex words, I think there is value in trying to stick to common and simple words when feasible. I don’t think “ledger” needs to be here. I think simpler and more common words work equally well here.

I’m reminded of the Thing Explainer book where Randall Munroe explains complicated things using only the ten-hundred most common words. A word can be “simple” but still uncommon. If it’s not a word ESL speakers are likely to be familiar with, there is value in avoiding it. It is always nice when the exercises are easy to understand and less likely to need a dictionary.

3 Likes

That would be a good official guide, too. I am for that. It is also the reason I avoid contractions (they can be hard to understand, especially some regionally common ones).

@ErikSchierboom What do you think, are we again inconsistent with this story? The instructions remain largely unchanged, and the introduction explains the task through a simple story.

I think that is fine!

1 Like
1 Like