Skip to content

Commit

Permalink
Sync exercism-nim
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderploegsma committed Oct 12, 2023
1 parent 9b5b777 commit dff10a9
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 0 deletions.
38 changes: 38 additions & 0 deletions nim/hello-world/HELP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Help

## Running the tests

To compile and run the tests, just run the following in your exercise directory:

```shell
nim r test_exercise_name.nim
```

Replace `exercise_name` with the name of the exercise (e.g. `all_your_base`).

## Submitting your solution

You can submit your solution using the `exercism submit hello_world.nim` command.
This command will upload your solution to the Exercism website and print the solution page's URL.

It's possible to submit an incomplete solution which allows you to:

- See how others have completed the exercise
- Request help from a mentor

## Need to get help?

If you'd like help solving the exercise, check the following pages:

- The [Nim track's documentation](https://exercism.org/docs/tracks/nim)
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)

Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.

Need help? These guides should help you:

- [Installing Nim](https://exercism.org/tracks/nim/installation)
- [Running the Tests](https://exercism.org/tracks/nim/tests)
- [Learning Nim](https://exercism.org/tracks/nim/learning)
- [Useful Nim Resources](https://exercism.org/tracks/nim/resources)
35 changes: 35 additions & 0 deletions nim/hello-world/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Hello World

Welcome to Hello World on Exercism's Nim Track.
If you need help running the tests or submitting your code, check out `HELP.md`.

## Instructions

The classical introductory exercise.
Just say "Hello, World!".

["Hello, World!"][hello-world] is the traditional first program for beginning programming in a new language or environment.

The objectives are simple:

- Modify the provided code so that it produces the string "Hello, World!".
- Run the test suite and make sure that it succeeds.
- Submit your solution and check it at the website.

If everything goes well, you will be ready to fetch your first real exercise.

[hello-world]: https://en.wikipedia.org/wiki/%22Hello,_world!%22_program

## Source

### Created by

- @cmc333333

### Contributed to by

- @ee7

### Based on

This is an exercise to introduce users to using Exercism - https://en.wikipedia.org/wiki/%22Hello,_world!%22_program
2 changes: 2 additions & 0 deletions nim/hello-world/hello_world.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
proc hello*: string =
"Hello, World!"
6 changes: 6 additions & 0 deletions nim/hello-world/test_hello_world.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import unittest
import hello_world

suite "Hello World":
test "say hi!":
check hello() == "Hello, World!"
38 changes: 38 additions & 0 deletions nim/two-fer/HELP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Help

## Running the tests

To compile and run the tests, just run the following in your exercise directory:

```shell
nim r test_exercise_name.nim
```

Replace `exercise_name` with the name of the exercise (e.g. `all_your_base`).

## Submitting your solution

You can submit your solution using the `exercism submit two_fer.nim` command.
This command will upload your solution to the Exercism website and print the solution page's URL.

It's possible to submit an incomplete solution which allows you to:

- See how others have completed the exercise
- Request help from a mentor

## Need to get help?

If you'd like help solving the exercise, check the following pages:

- The [Nim track's documentation](https://exercism.org/docs/tracks/nim)
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)

Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.

Need help? These guides should help you:

- [Installing Nim](https://exercism.org/tracks/nim/installation)
- [Running the Tests](https://exercism.org/tracks/nim/tests)
- [Learning Nim](https://exercism.org/tracks/nim/learning)
- [Useful Nim Resources](https://exercism.org/tracks/nim/resources)
53 changes: 53 additions & 0 deletions nim/two-fer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Two Fer

Welcome to Two Fer on Exercism's Nim Track.
If you need help running the tests or submitting your code, check out `HELP.md`.

## 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 go for the offer and (very generously) decide to give the extra cookie to a friend.

## Instructions

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

If your friend likes cookies, and is named Do-yun, then you will say:

```text
One for Do-yun, one for me.
```

If your friend doesn't like cookies, you give the cookie to the next person in line at the bakery.
Since you don't know their name, you will say _you_ instead.

```text
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. |

## Source

### Created by

- @amscotti

### Contributed to by

- @ee7

### Based on

https://github.com/exercism/problem-specifications/issues/757
14 changes: 14 additions & 0 deletions nim/two-fer/test_two_fer.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import unittest
import two_fer

suite "Two Fer":
test "no name given":
check twoFer() == "One for you, one for me."

test "a name given":
let name = "Alice"
check twoFer(name) == "One for Alice, one for me."

test "another name given":
let name = "Bob"
check twoFer(name) == "One for Bob, one for me."
2 changes: 2 additions & 0 deletions nim/two-fer/two_fer.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
proc twoFer*(name = "you"): string =
"One for " & name & ", one for me."

0 comments on commit dff10a9

Please sign in to comment.