Two Fer

Two Fer

Easy

Introduction

In some English accents, when you say "two for" quickly, it sounds like "two fer". Two-for-one is a way of saying that if you buy one, you also get one for free. So the phrase "two-fer" often implies a two-for-one offer.

Imagine a bakery that has a holiday offer where you can buy two cookies for the price of one ("two-fer one!"). You take the offer and (very generously) decide to give the extra cookie to someone else in the queue.

Instructions

Your task is to determine what you will say as you give away the extra cookie.

If you know the person's name (e.g. if they're named Do-yun), then you will say:

One for Do-yun, one for me.

If you don't know the person's name, you will say you instead.

One for you, one for me.

Here are some examples:

Name Dialogue
Alice One for Alice, one for me.
Bohdan One for Bohdan, one for me.
One for you, one for me.
Zaphod One for Zaphod, one for me.

Track Specific Notes

One way to get optional arguments in scheme is by specifying the arguments as a list. Two ways to do that are: (define (two-fer . args) ...) or (define two-fer (lambda args ...)).

Running and testing your solutions

From the command line

Simply type make chez if you're using ChezScheme or make guile if you're using GNU Guile. Sometimes the name for the scheme binary on your system will differ from the defaults. When this is the case, you'll need to tell make by running make chez chez=your-chez-binary or make guile guile=your-guile-binary.

From a REPL

  • Enter (load "test.scm") at the repl prompt.
  • Develop your solution in two-fer.scm reloading as you go.
  • Run (test) to check your solution.

Failed Test Cases

If some of the test cases fail, you should see the failing input and the expected output. The failing input is presented as a list because the tests call your solution by (apply two-fer input-list). To learn more about apply see The Scheme Programming Language -- Chapter 5


Source

Explore the source of this exerciseThe link opens in a new window or tab.
Edit via GitHub The link opens in a new window or tab
Scheme Exercism

Ready to start Two Fer?

Sign up to Exercism to learn and master Scheme with 39 exercises, and real human mentoring, all for free.