File tree Expand file tree Collapse file tree 4 files changed +29
-5
lines changed Expand file tree Collapse file tree 4 files changed +29
-5
lines changed Original file line number Diff line number Diff line change 1+ import std/ [strutils, sequtils, cmdline]
2+
3+ type InputArgumentError * = object of IOError
4+
5+ proc generatePermutations (a: var seq [char ], n: int ) =
6+ if n <= 0 :
7+ echo a.join (" " )
8+ else :
9+ for i in 0 ..< n:
10+ generatePermutations (a, n - 1 )
11+ let j = if n mod 2 == 0 : 0 else : i
12+ swap (a[j], a[n])
13+ generatePermutations (a, n - 1 )
14+
15+ when isMainModule :
16+ var args = commandLineParams ()
17+ if len (args) != 1 :
18+ raise newException (InputArgumentError , " ERROR: There must be exactly 1 argument." )
19+ var letters = toSeq (args[0 ].items)
20+ generatePermutations (letters, len (letters) - 1 )
Original file line number Diff line number Diff line change 11import std/ strformat
22
33for i in 0 .. 10 :
4- let t = (43200 * i + 21600 ) div 11
5- let h = t div 3600
6- let m = (t div 60 ) mod 60
7- let s = t mod 60
4+ let
5+ t = (43200 * i + 21600 ) div 11
6+ h = t div 3600
7+ m = (t div 60 ) mod 60
8+ s = t mod 60
89 echo & " { (if h == 0 : 12 else : h):02 } :{ m:02 } :{ s:02 } "
Original file line number Diff line number Diff line change 11import std/ [strutils, cmdline]
22
3- type InputArgumentError * = object of Exception
3+ type InputArgumentError * = object of IOError
44
55proc printPermutations (a: var seq [string ], n: int ) =
66 if n <= 0 :
Original file line number Diff line number Diff line change @@ -9,6 +9,9 @@ function Assert-MatchTests {
99}
1010
1111$Error.clear ()
12+ nim c " $PSScriptRoot \anagrams.nim" && . " $PSScriptRoot \anagrams.exe" rats |
13+ Compare-Object (Get-Content " $PSScriptRoot \..\test\rats_heap_expected" ) |
14+ Assert-MatchTests &&
1215nim c " $PSScriptRoot \clockhands.nim" && . " $PSScriptRoot \clockhands.exe" |
1316 Compare-Object (Get-Content " $PSScriptRoot \..\test\clockhands_expected" ) |
1417 Assert-MatchTests &&
You can’t perform that action at this time.
0 commit comments