Skip to content

Commit

Permalink
tcl/difference-of-squares: 1st iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
vpayno committed Apr 16, 2024
1 parent 35dd198 commit 94142e3
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 7 deletions.
1 change: 1 addition & 0 deletions tcl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@
- [reverse-string](./reverse-string/README.md)
- [roman-numerals](./roman-numerals/README.md)
- [scrabble-score](./scrabble-score/README.md)
- [difference-of-squares](./difference-of-squares/README.md)
7 changes: 6 additions & 1 deletion tcl/difference-of-squares/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ Finding the best algorithm for the problem is a key skill in software engineerin

### Based on

Problem 6 at Project Euler - https://projecteuler.net/problem=6
Problem 6 at Project Euler - https://projecteuler.net/problem=6

### My Solution

- [difference-of-squares.tcl](./difference-of-squares.tcl)
- [run-tests](./run-tests-tcl.txt)
15 changes: 9 additions & 6 deletions tcl/difference-of-squares/difference-of-squares.tcl
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
proc squareOfSum {n} {
throw {NOT_IMPLEMENTED} "Implement this procedure."
proc squareOfSum {number} {
return [expr ($number * ($number + 1) / 2) ** 2]
}

proc sumOfSquares {n} {
throw {NOT_IMPLEMENTED} "Implement this procedure."
proc sumOfSquares {number} {
return [expr ($number * ($number + 1) * (2 * $number + 1) / 6)]
}

proc differenceOfSquares {n} {
throw {NOT_IMPLEMENTED} "Implement this procedure."
proc differenceOfSquares {number} {
set square [squareOfSum $number]
set sum [sumOfSquares $number]

return [expr {$square - $sum}]
}
68 changes: 68 additions & 0 deletions tcl/difference-of-squares/run-tests-tcl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
Running automated test file(s):


===============================================================================

Running: ttclcheck -scan /home/vpayno/git_vpayno/exercism-workspace/tcl/difference-of-squares
ttclcheck version: 0.18 Copyright 2013 Artur Trzewik
All Rights Reserved.

GPL licensed software
warn: pass shallow
warn: parsing /home/vpayno/git_vpayno/exercism-workspace/tcl/difference-of-squares/testHelpers.tcl
warn: parsing /home/vpayno/git_vpayno/exercism-workspace/tcl/difference-of-squares/difference-of-squares.tcl
warn: pass collect
warn: parsing /home/vpayno/git_vpayno/exercism-workspace/tcl/difference-of-squares/testHelpers.tcl
warn: parsing /home/vpayno/git_vpayno/exercism-workspace/tcl/difference-of-squares/difference-of-squares.tcl
warn: pass report
warn: parsing /home/vpayno/git_vpayno/exercism-workspace/tcl/difference-of-squares/testHelpers.tcl
/home/vpayno/git_vpayno/exercism-workspace/tcl/difference-of-squares/testHelpers.tcl: parsing file /home/vpayno/git_vpayno/exercism-workspace/tcl/difference-of-squares/testHelpers.tcl
/home/vpayno/git_vpayno/exercism-workspace/tcl/difference-of-squares/testHelpers.tcl:17: unknown variable ::tcltest::numTests <<$::tcltest::numTests>>
/home/vpayno/git_vpayno/exercism-workspace/tcl/difference-of-squares/testHelpers.tcl: errors file: 1
warn: parsing /home/vpayno/git_vpayno/exercism-workspace/tcl/difference-of-squares/difference-of-squares.tcl
/home/vpayno/git_vpayno/exercism-workspace/tcl/difference-of-squares/difference-of-squares.tcl: parsing file /home/vpayno/git_vpayno/exercism-workspace/tcl/difference-of-squares/difference-of-squares.tcl
/home/vpayno/git_vpayno/exercism-workspace/tcl/difference-of-squares/difference-of-squares.tcl:2: possible unintended double substitution for expr use {} <<($number>>
/home/vpayno/git_vpayno/exercism-workspace/tcl/difference-of-squares/difference-of-squares.tcl:6: possible unintended double substitution for expr use {} <<($number>>
/home/vpayno/git_vpayno/exercism-workspace/tcl/difference-of-squares/difference-of-squares.tcl:13: expect variable 'square' as 'numeric' but is 'string {}' <<$square>>
/home/vpayno/git_vpayno/exercism-workspace/tcl/difference-of-squares/difference-of-squares.tcl:13: expect variable 'sum' as 'numeric' but is 'string {}' <<$sum>>
/home/vpayno/git_vpayno/exercism-workspace/tcl/difference-of-squares/difference-of-squares.tcl: errors file: 4
errors all: 5 (13.89% lines)
lines: 36 in: 00:00:00 59 lines/sec: 610.17
commands: 5 variables: 1
signature params 9 unknown: 5 55.56% unknown variables 0.00%

real 0m0.127s
user 0m0.103s
sys 0m0.025s

===============================================================================

Running: nagelfar -s _ ./difference-of-squares.tcl
Checking file ./difference-of-squares.tcl
Line 2: W Expr without braces
Line 6: W Expr without braces

real 0m0.034s
user 0m0.026s
sys 0m0.007s

===============================================================================

Running: RUN_ALL=1 tclsh ./difference-of-squares.test
difference-of-squares.test: Total 9 Passed 9 Skipped 0 Failed 0

real 0m0.010s
user 0m0.008s
sys 0m0.002s


===============================================================================

Running: misspell .

real 0m0.019s
user 0m0.023s
sys 0m0.008s

===============================================================================

0 comments on commit 94142e3

Please sign in to comment.