-
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from wobh/difference-of-squares
xlisp #23: Difference of squares
- Loading branch information
Showing
4 changed files
with
59 additions
and
1 deletion.
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
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,33 @@ | ||
(ql:quickload "lisp-unit") | ||
|
||
(defpackage #:squares-test | ||
(:use #:cl #:lisp-unit)) | ||
|
||
(load "squares") | ||
|
||
(in-package #:squares-test) | ||
|
||
(define-test square-of-sums-to-5 | ||
(assert-equal 225 (squares:square-of-sums 5))) | ||
(define-test sum-of-squares-to-5 | ||
(assert-equal 55 (squares:sum-of-squares 5))) | ||
(define-test difference-of-sums-to-5 | ||
(assert-equal 170 (squares:difference 5))) | ||
|
||
(define-test square-of-sums-to-10 | ||
(assert-equal 3025 (squares:square-of-sums 10))) | ||
(define-test sum-of-squares-to-10 | ||
(assert-equal 385 (squares:sum-of-squares 10))) | ||
(define-test difference-of-sums-to-10 | ||
(assert-equal 2640 (squares:difference 10))) | ||
|
||
(define-test square-of-sums-to-100 | ||
(assert-equal 25502500 (squares:square-of-sums 100))) | ||
(define-test sum-of-squares-to-100 | ||
(assert-equal 338350 (squares:sum-of-squares 100))) | ||
(define-test difference-of-sums-to-100 | ||
(assert-equal 25164150 (squares:difference 100))) | ||
|
||
(let ((*print-errors* t) | ||
(*print-failures* t)) | ||
(run-tests :all :squares-test)) |
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,17 @@ | ||
(defpackage #:squares | ||
(:use #:cl) | ||
(:export #:sum-of-squares | ||
#:square-of-sums | ||
#:difference)) | ||
|
||
(in-package #:squares) | ||
|
||
(defun square-of-sums (n) | ||
(expt (* 1/2 n (1+ n)) 2)) | ||
|
||
(defun sum-of-squares (n) | ||
(* 1/6 n (1+ n) (1+ (* 2 n)))) | ||
|
||
(defun difference (n) | ||
(- (square-of-sums n) | ||
(sum-of-squares n))) |
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,7 @@ | ||
(defpackage #:squares | ||
(:use #:cl) | ||
(:export #:sum-of-squares | ||
#:square-of-sums | ||
#:difference)) | ||
|
||
(in-package #:squares) |