-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vimscript/difference-of-squares: download exercise
- Loading branch information
Showing
6 changed files
with
180 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,23 @@ | ||
{ | ||
"authors": [ | ||
"mhinz" | ||
], | ||
"contributors": [ | ||
"kotp", | ||
"kytrinyx" | ||
], | ||
"files": { | ||
"solution": [ | ||
"difference_of_squares.vim" | ||
], | ||
"test": [ | ||
"difference_of_squares.vader" | ||
], | ||
"example": [ | ||
".meta/example.vim" | ||
] | ||
}, | ||
"blurb": "Find the difference between the square of the sum and the sum of the squares of the first N natural numbers.", | ||
"source": "Problem 6 at Project Euler", | ||
"source_url": "https://projecteuler.net/problem=6" | ||
} |
This file contains 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 @@ | ||
{"track":"vimscript","exercise":"difference-of-squares","id":"ee357e1bcef04f968dbb32e557759484","url":"https://exercism.org/tracks/vimscript/exercises/difference-of-squares","handle":"vpayno","is_requester":true,"auto_approve":false} |
This file contains 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,52 @@ | ||
# Help | ||
|
||
## Running the tests | ||
|
||
Open your solution: | ||
|
||
```bash | ||
$ vim <exercise>.vim | ||
``` | ||
|
||
Source the current file to make its global functions available to Vim: | ||
|
||
``` | ||
:source % | ||
``` | ||
|
||
Run the tests: | ||
|
||
``` | ||
:Vader <exercise>.vader | ||
``` | ||
|
||
Replace `<exercise>` with your exercise's name. | ||
|
||
## Submitting your solution | ||
|
||
You can submit your solution using the `exercism submit difference_of_squares.vim` 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 [Vim script track's documentation](https://exercism.org/docs/tracks/vimscript) | ||
- The [Vim script track's programming category on the forum](https://forum.exercism.org/c/programming/vimscript) | ||
- [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. | ||
|
||
To get help if you're having trouble, you can use one of the following resources: | ||
|
||
- [Learn Vimscript the Hard Way](http://learnvimscriptthehardway.stevelosh.com) | ||
- [IBM DeveloperWorks: Scripting the Vim | ||
editor](http://www.ibm.com/developerworks/views/linux/libraryview.jsp?sort_order=asc&sort_by=Title&search_by=scripting+the+vim+editor) | ||
- [/r/vimscript](https://www.reddit.com/r/vimscript) is the Vimscript subreddit. | ||
- [StackOverflow](http://stackoverflow.com/) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions. |
This file contains 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,34 @@ | ||
# Difference of Squares | ||
|
||
Welcome to Difference of Squares on Exercism's Vim script Track. | ||
If you need help running the tests or submitting your code, check out `HELP.md`. | ||
|
||
## Instructions | ||
|
||
Find the difference between the square of the sum and the sum of the squares of the first N natural numbers. | ||
|
||
The square of the sum of the first ten natural numbers is | ||
(1 + 2 + ... + 10)² = 55² = 3025. | ||
|
||
The sum of the squares of the first ten natural numbers is | ||
1² + 2² + ... + 10² = 385. | ||
|
||
Hence the difference between the square of the sum of the first ten natural numbers and the sum of the squares of the first ten natural numbers is 3025 - 385 = 2640. | ||
|
||
You are not expected to discover an efficient solution to this yourself from first principles; research is allowed, indeed, encouraged. | ||
Finding the best algorithm for the problem is a key skill in software engineering. | ||
|
||
## Source | ||
|
||
### Created by | ||
|
||
- @mhinz | ||
|
||
### Contributed to by | ||
|
||
- @kotp | ||
- @kytrinyx | ||
|
||
### Based on | ||
|
||
Problem 6 at Project Euler - https://projecteuler.net/problem=6 |
46 changes: 46 additions & 0 deletions
46
vimscript/difference-of-squares/difference_of_squares.vader
This file contains 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,46 @@ | ||
" | ||
" Version: 1.2.0 | ||
" | ||
|
||
Execute (square of sum 1): | ||
let number = 1 | ||
let expected = 1 | ||
AssertEqual expected, SquareOfSum(number) | ||
|
||
Execute (square of sum 5): | ||
let number = 5 | ||
let expected = 225 | ||
AssertEqual expected, SquareOfSum(number) | ||
|
||
Execute (square of sum 100): | ||
let number = 100 | ||
let expected = 25502500 | ||
AssertEqual expected, SquareOfSum(number) | ||
Execute (sum of squares 1): | ||
let number = 1 | ||
let expected = 1 | ||
AssertEqual expected, SumOfSquares(number) | ||
|
||
Execute (sum of squares 5): | ||
let number = 5 | ||
let expected = 55 | ||
AssertEqual expected, SumOfSquares(number) | ||
|
||
Execute (sum of squares 100): | ||
let number = 100 | ||
let expected = 338350 | ||
AssertEqual expected, SumOfSquares(number) | ||
Execute (difference of squares 1): | ||
let number = 1 | ||
let expected = 0 | ||
AssertEqual expected, DifferenceOfSquares(number) | ||
|
||
Execute (difference of squares 5): | ||
let number = 5 | ||
let expected = 170 | ||
AssertEqual expected, DifferenceOfSquares(number) | ||
|
||
Execute (difference of squares 100): | ||
let number = 100 | ||
let expected = 25164150 | ||
AssertEqual expected, DifferenceOfSquares(number) |
This file contains 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,24 @@ | ||
" | ||
" Find the difference between the square of the sum and the sum of the squares | ||
" of the first N natural numbers. | ||
" | ||
" Examples: | ||
" | ||
" :echo SquareOfSum(3) | ||
" 36 | ||
" :echo SumOfSquares(3) | ||
" 14 | ||
" :echo DifferenceOfSquares(3) | ||
" 22 | ||
" | ||
function! DifferenceOfSquares(number) abort | ||
" your implementation goes here | ||
endfunction | ||
|
||
function! SquareOfSum(number) abort | ||
" your implementation goes here | ||
endfunction | ||
|
||
function! SumOfSquares(number) abort | ||
" your implementation goes here | ||
endfunction |