-
-
Notifications
You must be signed in to change notification settings - Fork 27
Add line-up
#362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add line-up
#362
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # Instructions | ||
|
|
||
| Given a name and a number, your task is to produce a sentence using that name and that number as an [ordinal numeral][ordinal-numeral]. | ||
| Yaʻqūb expects to use numbers from 1 up to 999. | ||
|
|
||
| Rules: | ||
|
|
||
| - Numbers ending in 1 (except for 11) → `"st"` | ||
| - Numbers ending in 2 (except for 12) → `"nd"` | ||
| - Numbers ending in 3 (except for 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!"` | ||
|
|
||
| [ordinal-numeral]: https://en.wikipedia.org/wiki/Ordinal_numeral |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| { | ||
| "authors": [ | ||
| "BNAndras" | ||
| ], | ||
| "files": { | ||
| "solution": [ | ||
| "line_up.vim" | ||
| ], | ||
| "test": [ | ||
| "line_up.vader" | ||
| ], | ||
| "example": [ | ||
| ".meta/example.vim" | ||
| ] | ||
| }, | ||
| "blurb": "Help lining up customers at Yaʻqūb's Deli.", | ||
| "source": "mk-mxp, based on previous work from Exercism contributors codedge and neenjaw", | ||
| "source_url": "https://forum.exercism.org/t/new-exercise-ordinal-numbers/19147" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| function! Format(name, number) abort | ||
| let l:suffix = s:Suffix(a:number) | ||
| return printf('%s, you are the %d%s customer we serve today. Thank you!', a:name, a:number, l:suffix) | ||
| endfunction | ||
|
|
||
| function! s:Suffix(number) abort | ||
| let l:mod10 = a:number % 10 | ||
| let l:mod100 = a:number % 100 | ||
|
|
||
| if l:mod10 == 1 && l:mod100 != 11 | ||
| return 'st' | ||
| elseif l:mod10 == 2 && l:mod100 != 12 | ||
| return 'nd' | ||
| elseif l:mod10 == 3 && l:mod100 != 13 | ||
| return 'rd' | ||
| endif | ||
| return 'th' | ||
| endfunction | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| # This is an auto-generated file. | ||
| # | ||
| # Regenerating this file via `configlet sync` will: | ||
| # - Recreate every `description` key/value pair | ||
| # - Recreate every `reimplements` key/value pair, where they exist in problem-specifications | ||
| # - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) | ||
| # - Preserve any other key/value pair | ||
| # | ||
| # As user-added comments (using the # character) will be removed when this file | ||
| # is regenerated, comments can be added via a `comment` key. | ||
|
|
||
| [7760d1b8-4864-4db4-953b-0fa7c047dbc0] | ||
| description = "format smallest non-exceptional ordinal numeral 4" | ||
|
|
||
| [e8b7c715-6baa-4f7b-8fb3-2fa48044ab7a] | ||
| description = "format greatest single digit non-exceptional ordinal numeral 9" | ||
|
|
||
| [f370aae9-7ae7-4247-90ce-e8ff8c6934df] | ||
| description = "format non-exceptional ordinal numeral 5" | ||
|
|
||
| [37f10dea-42a2-49de-bb92-0b690b677908] | ||
| description = "format non-exceptional ordinal numeral 6" | ||
|
|
||
| [d8dfb9a2-3a1f-4fee-9dae-01af3600054e] | ||
| description = "format non-exceptional ordinal numeral 7" | ||
|
|
||
| [505ec372-1803-42b1-9377-6934890fd055] | ||
| description = "format non-exceptional ordinal numeral 8" | ||
|
|
||
| [8267072d-be1f-4f70-b34a-76b7557a47b9] | ||
| description = "format exceptional ordinal numeral 1" | ||
|
|
||
| [4d8753cb-0364-4b29-84b8-4374a4fa2e3f] | ||
| description = "format exceptional ordinal numeral 2" | ||
|
|
||
| [8d44c223-3a7e-4f48-a0ca-78e67bf98aa7] | ||
| description = "format exceptional ordinal numeral 3" | ||
|
|
||
| [6c4f6c88-b306-4f40-bc78-97cdd583c21a] | ||
| description = "format smallest two digit non-exceptional ordinal numeral 10" | ||
|
|
||
| [e257a43f-d2b1-457a-97df-25f0923fc62a] | ||
| description = "format non-exceptional ordinal numeral 11" | ||
|
|
||
| [bb1db695-4d64-457f-81b8-4f5a2107e3f4] | ||
| description = "format non-exceptional ordinal numeral 12" | ||
|
|
||
| [60a3187c-9403-4835-97de-4f10ebfd63e2] | ||
| description = "format non-exceptional ordinal numeral 13" | ||
|
|
||
| [2bdcebc5-c029-4874-b6cc-e9bec80d603a] | ||
| description = "format exceptional ordinal numeral 21" | ||
|
|
||
| [74ee2317-0295-49d2-baf0-d56bcefa14e3] | ||
| description = "format exceptional ordinal numeral 62" | ||
|
|
||
| [b37c332d-7f68-40e3-8503-e43cbd67a0c4] | ||
| description = "format exceptional ordinal numeral 100" | ||
|
|
||
| [0375f250-ce92-4195-9555-00e28ccc4d99] | ||
| description = "format exceptional ordinal numeral 101" | ||
|
|
||
| [0d8a4974-9a8a-45a4-aca7-a9fb473c9836] | ||
| description = "format non-exceptional ordinal numeral 112" | ||
|
|
||
| [06b62efe-199e-4ce7-970d-4bf73945713f] | ||
| description = "format exceptional ordinal numeral 123" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
|
|
||
| Execute (format smallest non-exceptional ordinal numeral 4): | ||
| let g:name = "Gianna" | ||
| let g:number = 4 | ||
| let g:expected = "Gianna, you are the 4th customer we serve today. Thank you!" | ||
| AssertEqual g:expected, Format(g:name, g:number) | ||
|
|
||
| Execute (format greatest single digit non-exceptional ordinal numeral 9): | ||
| let g:name = "Maarten" | ||
| let g:number = 9 | ||
| let g:expected = "Maarten, you are the 9th customer we serve today. Thank you!" | ||
| AssertEqual g:expected, Format(g:name, g:number) | ||
|
|
||
| Execute (format non-exceptional ordinal numeral 5): | ||
| let g:name = "Petronila" | ||
| let g:number = 5 | ||
| let g:expected = "Petronila, you are the 5th customer we serve today. Thank you!" | ||
| AssertEqual g:expected, Format(g:name, g:number) | ||
|
|
||
| Execute (format non-exceptional ordinal numeral 6): | ||
| let g:name = "Attakullakulla" | ||
| let g:number = 6 | ||
| let g:expected = "Attakullakulla, you are the 6th customer we serve today. Thank you!" | ||
| AssertEqual g:expected, Format(g:name, g:number) | ||
|
|
||
| Execute (format non-exceptional ordinal numeral 7): | ||
| let g:name = "Kate" | ||
| let g:number = 7 | ||
| let g:expected = "Kate, you are the 7th customer we serve today. Thank you!" | ||
| AssertEqual g:expected, Format(g:name, g:number) | ||
|
|
||
| Execute (format non-exceptional ordinal numeral 8): | ||
| let g:name = "Maximiliano" | ||
| let g:number = 8 | ||
| let g:expected = "Maximiliano, you are the 8th customer we serve today. Thank you!" | ||
| AssertEqual g:expected, Format(g:name, g:number) | ||
|
|
||
| Execute (format exceptional ordinal numeral 1): | ||
| let g:name = "Mary" | ||
| let g:number = 1 | ||
| let g:expected = "Mary, you are the 1st customer we serve today. Thank you!" | ||
| AssertEqual g:expected, Format(g:name, g:number) | ||
|
|
||
| Execute (format exceptional ordinal numeral 2): | ||
| let g:name = "Haruto" | ||
| let g:number = 2 | ||
| let g:expected = "Haruto, you are the 2nd customer we serve today. Thank you!" | ||
| AssertEqual g:expected, Format(g:name, g:number) | ||
|
|
||
| Execute (format exceptional ordinal numeral 3): | ||
| let g:name = "Henriette" | ||
| let g:number = 3 | ||
| let g:expected = "Henriette, you are the 3rd customer we serve today. Thank you!" | ||
| AssertEqual g:expected, Format(g:name, g:number) | ||
|
|
||
| Execute (format smallest two digit non-exceptional ordinal numeral 10): | ||
| let g:name = "Alvarez" | ||
| let g:number = 10 | ||
| let g:expected = "Alvarez, you are the 10th customer we serve today. Thank you!" | ||
| AssertEqual g:expected, Format(g:name, g:number) | ||
|
|
||
| Execute (format non-exceptional ordinal numeral 11): | ||
| let g:name = "Jacqueline" | ||
| let g:number = 11 | ||
| let g:expected = "Jacqueline, you are the 11th customer we serve today. Thank you!" | ||
| AssertEqual g:expected, Format(g:name, g:number) | ||
|
|
||
| Execute (format non-exceptional ordinal numeral 12): | ||
| let g:name = "Juan" | ||
| let g:number = 12 | ||
| let g:expected = "Juan, you are the 12th customer we serve today. Thank you!" | ||
| AssertEqual g:expected, Format(g:name, g:number) | ||
|
|
||
| Execute (format non-exceptional ordinal numeral 13): | ||
| let g:name = "Patricia" | ||
| let g:number = 13 | ||
| let g:expected = "Patricia, you are the 13th customer we serve today. Thank you!" | ||
| AssertEqual g:expected, Format(g:name, g:number) | ||
|
|
||
| Execute (format exceptional ordinal numeral 21): | ||
| let g:name = "Washi" | ||
| let g:number = 21 | ||
| let g:expected = "Washi, you are the 21st customer we serve today. Thank you!" | ||
| AssertEqual g:expected, Format(g:name, g:number) | ||
|
|
||
| Execute (format exceptional ordinal numeral 62): | ||
| let g:name = "Nayra" | ||
| let g:number = 62 | ||
| let g:expected = "Nayra, you are the 62nd customer we serve today. Thank you!" | ||
| AssertEqual g:expected, Format(g:name, g:number) | ||
|
|
||
| Execute (format exceptional ordinal numeral 100): | ||
| let g:name = "John" | ||
| let g:number = 100 | ||
| let g:expected = "John, you are the 100th customer we serve today. Thank you!" | ||
| AssertEqual g:expected, Format(g:name, g:number) | ||
|
|
||
| Execute (format exceptional ordinal numeral 101): | ||
| let g:name = "Zeinab" | ||
| let g:number = 101 | ||
| let g:expected = "Zeinab, you are the 101st customer we serve today. Thank you!" | ||
| AssertEqual g:expected, Format(g:name, g:number) | ||
|
|
||
| Execute (format non-exceptional ordinal numeral 112): | ||
| let g:name = "Knud" | ||
| let g:number = 112 | ||
| let g:expected = "Knud, you are the 112th customer we serve today. Thank you!" | ||
| AssertEqual g:expected, Format(g:name, g:number) | ||
|
|
||
| Execute (format exceptional ordinal numeral 123): | ||
| let g:name = "Yma" | ||
| let g:number = 123 | ||
| let g:expected = "Yma, you are the 123rd customer we serve today. Thank you!" | ||
| AssertEqual g:expected, Format(g:name, g:number) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| " | ||
| " Given a customer ame and a ticket number, return a formatted ticket message. | ||
| " | ||
| " Example: | ||
| " | ||
| " :echo Format('Maarten', 9) | ||
| " Maarten, you are the 9th customer we serve today. Thank you! | ||
| " | ||
| function! Format(name, number) abort | ||
| " your code goes here | ||
| endfunction |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider continuing the if statement with an else as the default. The
return 'th'is otherwise an implicitelseand makes it seem like it is not related to the if statement.This is an example solution, though, so does not need to be exemplar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 17 is the happy path for most numbers so it's aligned to the left while the
if....elseifs are the special cases. Considering each branch returns, I could do away with theelseifand doiffor the three special cases, but I didn't want to bother adding the additionalendiflines.