From 63e38a1ab90594a9e0eda48a558a81e7f0c3d1c3 Mon Sep 17 00:00:00 2001 From: Angelika Tyborska Date: Sat, 9 Dec 2023 03:59:50 +0100 Subject: [PATCH] Stack underflow: specify 2 numbers are expected (#1395) --- exercises/concept/stack-underflow/.docs/instructions.md | 2 +- exercises/concept/stack-underflow/.meta/exemplar.ex | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/exercises/concept/stack-underflow/.docs/instructions.md b/exercises/concept/stack-underflow/.docs/instructions.md index 04ff219091..a9df3ba9f0 100644 --- a/exercises/concept/stack-underflow/.docs/instructions.md +++ b/exercises/concept/stack-underflow/.docs/instructions.md @@ -27,7 +27,7 @@ raise StackUnderflowError, "when dividing" ## 3. Write a dividing function -Implement the `divide/1` function which takes a stack _(list of numbers)_ and: +Implement the `divide/1` function which takes a stack _(a list of two numbers)_ and: - raises _stack underflow_ when the stack does not contain enough numbers - raises _division by zero_ when the divisor is 0 (note the stack of numbers is stored in the reverse order) diff --git a/exercises/concept/stack-underflow/.meta/exemplar.ex b/exercises/concept/stack-underflow/.meta/exemplar.ex index 93bd4ef7d7..18d65607d9 100644 --- a/exercises/concept/stack-underflow/.meta/exemplar.ex +++ b/exercises/concept/stack-underflow/.meta/exemplar.ex @@ -18,6 +18,6 @@ defmodule RPNCalculator.Exception do end def divide(stack) when length(stack) < 2, do: raise(StackUnderflowError, "when dividing") - def divide([divisor, _number | _]) when divisor == 0, do: raise(DivisionByZeroError) - def divide([divisor, number | _]), do: number / divisor + def divide([divisor, _number]) when divisor == 0, do: raise(DivisionByZeroError) + def divide([divisor, number]), do: number / divisor end