Cody

Problem 44293. Write out numbers in words

Solution 1262133

Submitted on 4 Sep 2017
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
filetext = fileread('num2words.m'); assert(isempty(strfind(filetext, 'six hundred and seventy-nine'))) assert(isempty(strfind(filetext, 'one thousand, five hundred and twenty')))

2   Fail
x = 0; y_correct = 'zero'; assert(isequal(num2words(x),y_correct))

ans = 1×4 cell array {'zero thousand, zero hundred and zer…'} {'zero thousand, zero hundred and zer…'} {'zero thousand, zero hundred and zer…'} {'zero thousand, zero hundred and zer…'} ans = 1×4 cell array {'DELDELDELzero'} {'DELDELDELzero'} {'DELDELDELzero'} {'DELDELDELzero'} ans = 1×4 cell array {'zero'} {'zero'} {'zero'} {'zero'}

Assertion failed.

3   Fail
x = 1; y_correct = 'one'; assert(isequal(num2words(x),y_correct))

ans = 1×4 cell array {'zero thousand, zero hundred and zer…'} {'zero thousand, zero hundred and zer…'} {'zero thousand, zero hundred and zer…'} {'one thousand, one hundred and onety…'} ans = 1×4 cell array {'DELDELDELzero'} {'DELDELDELzero'} {'DELDELDELzero'} {'one thousand, one hundred and eleven'} ans = 1×4 cell array {'zero'} {'zero'} {'zero'} {'one thousand, one hundred and eleven'}

Assertion failed.

4   Fail
x = 56; y_correct = 'fifty-six' assert(isequal(num2words(x),y_correct))

y_correct = 'fifty-six' ans = 1×4 cell array {'zero thousand, zero hundred and zer…'} {'zero thousand, zero hundred and zer…'} {'five thousand, five hundred and fiv…'} {'six thousand, six hundred and sixty…'} ans = 1×4 cell array {'DELDELDELzero'} {'DELDELDELzero'} {'five thousand, five hundred and fif…'} {'six thousand, six hundred and sixty…'} ans = 1×4 cell array {'zero'} {'zero'} {'five thousand, five hundred and fif…'} {'six thousand, six hundred and sixty…'}

Assertion failed.

5   Fail
x = 100; y_correct = 'one hundred'; assert(isequal(num2words(x),y_correct))

ans = 1×4 cell array {'zero thousand, zero hundred and zer…'} {'one thousand, one hundred and onety…'} {'zero thousand, zero hundred and zer…'} {'zero thousand, zero hundred and zer…'} ans = 1×4 cell array {'DELDELDELzero'} {'one thousand, one hundred and eleven'} {'DELDELDELzero'} {'DELDELDELzero'} ans = 1×4 cell array {'zero'} {'one thousand, one hundred and eleven'} {'zero'} {'zero'}

Assertion failed.

6   Fail
x = 105; y_correct = 'one hundred and five'; assert(isequal(num2words(x),y_correct))

ans = 1×4 cell array {'zero thousand, zero hundred and zer…'} {'one thousand, one hundred and onety…'} {'zero thousand, zero hundred and zer…'} {'five thousand, five hundred and fiv…'} ans = 1×4 cell array {'DELDELDELzero'} {'one thousand, one hundred and eleven'} {'DELDELDELzero'} {'five thousand, five hundred and fif…'} ans = 1×4 cell array {'zero'} {'one thousand, one hundred and eleven'} {'zero'} {'five thousand, five hundred and fif…'}

Assertion failed.

7   Fail
x = 245; y_correct = 'two hundred and forty-five'; assert(isequal(num2words(x),y_correct))

ans = 1×4 cell array {'zero thousand, zero hundred and zer…'} {'two thousand, two hundred and twoty…'} {'four thousand, four hundred and fou…'} {'five thousand, five hundred and fiv…'} ans = 1×4 cell array {'DELDELDELzero'} {'two thousand, two hundred and twent…'} {'four thousand, four hundred and for…'} {'five thousand, five hundred and fif…'} ans = 1×4 cell array {'zero'} {'two thousand, two hundred and twent…'} {'four thousand, four hundred and for…'} {'five thousand, five hundred and fif…'}

Assertion failed.

8   Fail
x = 679; y_correct = 'six hundred and seventy-nine'; assert(isequal(num2words(x),y_correct))

ans = 1×4 cell array {'zero thousand, zero hundred and zer…'} {'six thousand, six hundred and sixty…'} {'seven thousand, seven hundred and s…'} {'nine thousand, nine hundred and nin…'} ans = 1×4 cell array {'DELDELDELzero'} {'six thousand, six hundred and sixty…'} {'seven thousand, seven hundred and s…'} {'nine thousand, nine hundred and nin…'} ans = 1×4 cell array {'zero'} {'six thousand, six hundred and sixty…'} {'seven thousand, seven hundred and s…'} {'nine thousand, nine hundred and nin…'}

Assertion failed.

9   Fail
x = 1520; y_correct = 'one thousand, five hundred and twenty'; assert(isequal(num2words(x),y_correct))

ans = 1×4 cell array {'one thousand, one hundred and onety…'} {'five thousand, five hundred and fiv…'} {'two thousand, two hundred and twoty…'} {'zero thousand, zero hundred and zer…'} ans = 1×4 cell array {'one thousand, one hundred and eleven'} {'five thousand, five hundred and fif…'} {'two thousand, two hundred and twent…'} {'DELDELDELzero'} ans = 1×4 cell array {'one thousand, one hundred and eleven'} {'five thousand, five hundred and fif…'} {'two thousand, two hundred and twent…'} {'zero'}

Assertion failed.

10   Fail
x = 9999; y_correct = 'nine thousand, nine hundred and ninety-nine'; assert(isequal(num2words(x),y_correct))

ans = 1×4 cell array {'nine thousand, nine hundred and nin…'} {'nine thousand, nine hundred and nin…'} {'nine thousand, nine hundred and nin…'} {'nine thousand, nine hundred and nin…'} ans = 1×4 cell array {'nine thousand, nine hundred and nin…'} {'nine thousand, nine hundred and nin…'} {'nine thousand, nine hundred and nin…'} {'nine thousand, nine hundred and nin…'} ans = 1×4 cell array {'nine thousand, nine hundred and nin…'} {'nine thousand, nine hundred and nin…'} {'nine thousand, nine hundred and nin…'} {'nine thousand, nine hundred and nin…'}

Assertion failed.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!