Skip to content

Commit

Permalink
vimscript/difference-of-squares: download exercise
Browse files Browse the repository at this point in the history
  • Loading branch information
vpayno committed Apr 16, 2024
1 parent 9641465 commit 783a342
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 0 deletions.
23 changes: 23 additions & 0 deletions vimscript/difference-of-squares/.exercism/config.json
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"
}
1 change: 1 addition & 0 deletions vimscript/difference-of-squares/.exercism/metadata.json
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}
52 changes: 52 additions & 0 deletions vimscript/difference-of-squares/HELP.md
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.
34 changes: 34 additions & 0 deletions vimscript/difference-of-squares/README.md
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 vimscript/difference-of-squares/difference_of_squares.vader
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)
24 changes: 24 additions & 0 deletions vimscript/difference-of-squares/difference_of_squares.vim
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

0 comments on commit 783a342

Please sign in to comment.