Julio Biason
3 years ago
6 changed files with 144 additions and 0 deletions
@ -0,0 +1,24 @@
|
||||
{ |
||||
"blurb": "Calculate the number of grains of wheat on a chessboard given that the number on each square doubles.", |
||||
"authors": [ |
||||
"arguello" |
||||
], |
||||
"contributors": [ |
||||
"mbertheau", |
||||
"PurityControl", |
||||
"yurrriq" |
||||
], |
||||
"files": { |
||||
"solution": [ |
||||
"grains.rkt" |
||||
], |
||||
"test": [ |
||||
"grains-test.rkt" |
||||
], |
||||
"example": [ |
||||
".meta/example.rkt" |
||||
] |
||||
}, |
||||
"source": "JavaRanch Cattle Drive, exercise 6", |
||||
"source_url": "http://www.javaranch.com/grains.jsp" |
||||
} |
@ -0,0 +1 @@
|
||||
{"track":"racket","exercise":"grains","id":"7dfea06643424904aa9efa5a44544efc","url":"https://exercism.org/tracks/racket/exercises/grains","handle":"JBiason","is_requester":true,"auto_approve":false} |
@ -0,0 +1,39 @@
|
||||
# Help |
||||
|
||||
## Running the tests |
||||
|
||||
To run the test through DrRacket, simply open the test file and click the 'Run' button in the upper right. |
||||
|
||||
To run the test from the command line, run the test from the exercise directory with the following command: |
||||
|
||||
``` |
||||
raco test <exercise>-test.rkt |
||||
``` |
||||
|
||||
where `<exercise>` should be replaced with the exercise's slug. |
||||
|
||||
## Submitting your solution |
||||
|
||||
You can submit your solution using the `exercism submit grains.rkt` 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 [Racket track's documentation](https://exercism.org/docs/tracks/racket) |
||||
- [Exercism's support channel on gitter](https://gitter.im/exercism/support) |
||||
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) |
||||
|
||||
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. |
||||
|
||||
To get help if you're having trouble, you can use one of the following resources: |
||||
|
||||
- [The Racket Reference](http://docs.racket-lang.org/reference/index.html) |
||||
- [/r/racket](https://www.reddit.com/r/racket) is the Racket subreddit. |
||||
- [StackOverflow](http://stackoverflow.com/questions/tagged/racket) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions. |
@ -0,0 +1,48 @@
|
||||
# Grains |
||||
|
||||
Welcome to Grains on Exercism's Racket Track. |
||||
If you need help running the tests or submitting your code, check out `HELP.md`. |
||||
|
||||
## Instructions |
||||
|
||||
Calculate the number of grains of wheat on a chessboard given that the number |
||||
on each square doubles. |
||||
|
||||
There once was a wise servant who saved the life of a prince. The king |
||||
promised to pay whatever the servant could dream up. Knowing that the |
||||
king loved chess, the servant told the king he would like to have grains |
||||
of wheat. One grain on the first square of a chess board, with the number |
||||
of grains doubling on each successive square. |
||||
|
||||
There are 64 squares on a chessboard (where square 1 has one grain, square 2 has two grains, and so on). |
||||
|
||||
Write code that shows: |
||||
- how many grains were on a given square, and |
||||
- the total number of grains on the chessboard |
||||
|
||||
## For bonus points |
||||
|
||||
Did you get the tests passing and the code clean? If you want to, these |
||||
are some additional things you could try: |
||||
|
||||
- Optimize for speed. |
||||
- Optimize for readability. |
||||
|
||||
Then please share your thoughts in a comment on the submission. Did this |
||||
experiment make the code better? Worse? Did you learn anything from it? |
||||
|
||||
## Source |
||||
|
||||
### Created by |
||||
|
||||
- @arguello |
||||
|
||||
### Contributed to by |
||||
|
||||
- @mbertheau |
||||
- @PurityControl |
||||
- @yurrriq |
||||
|
||||
### Based on |
||||
|
||||
JavaRanch Cattle Drive, exercise 6 - http://www.javaranch.com/grains.jsp |
@ -0,0 +1,21 @@
|
||||
#lang racket/base |
||||
|
||||
(require "grains.rkt") |
||||
|
||||
(module+ test |
||||
(require rackunit rackunit/text-ui) |
||||
|
||||
(define suite |
||||
(test-suite |
||||
"grains tests" |
||||
|
||||
(test-eqv? "square 1" (square 1) 1) |
||||
(test-eqv? "square 2" (square 2) 2) |
||||
(test-eqv? "square 3" (square 3) 4) |
||||
(test-eqv? "square 4" (square 4) 8) |
||||
(test-eqv? "square 16" (square 16) 32768) |
||||
(test-eqv? "square 32" (square 32) 2147483648) |
||||
(test-eqv? "square 64" (square 64) 9223372036854775808) |
||||
(test-eqv? "total grains" (total) 18446744073709551615))) |
||||
|
||||
(run-tests suite)) |
Loading…
Reference in new issue