Skip to content

Commit

Permalink
exercises(isogram, nth-prime, pangram, sieve): examples: tweak comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ee7 committed Nov 12, 2023
1 parent 6d3151e commit 8df62a3
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion exercises/practice/isogram/.meta/example.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
func isIsogram*(s: string): bool =
result = true
var seen: array[26, bool] # Faster than array['a'..'z', bool] or set['a'..'z']
var seen: array[26, bool] # Faster than array['a'..'z', bool] or set['a'..'z'].
for c in s:
let i = if c in {'a'..'z'}: c.ord - 'a'.ord else: c.ord - 'A'.ord
if i in {0..seen.high}:
Expand Down
4 changes: 2 additions & 2 deletions exercises/practice/nth-prime/.meta/example.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ func eratosthenes(n: int): seq[bool] =
for odd in countup(3, n, 2):
result[odd] = true

for i in countup(3, n.float.sqrt.int, 2): # Optimisation: stop at sqrt(n)
for i in countup(3, n.float.sqrt.int, 2): # Optimization: stop at sqrt(n).
if result[i]:
for j in countup(i*i, n, 2*i): # Optimisation: start at i*i
for j in countup(i*i, n, 2*i): # Optimization: start at i*i.
result[j] = false

func primesUpTo(limit: int): seq[int] =
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/pangram/.meta/example.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
func isPangram*(s: string): bool =
var seen: array[26, bool] # Faster than array['a'..'z', bool] or set['a'..'z']
var seen: array[26, bool] # Faster than array['a'..'z', bool] or set['a'..'z'].
var count = 0
for c in s:
let i = if c in {'a'..'z'}: c.ord - 'a'.ord else: c.ord - 'A'.ord
Expand Down
4 changes: 2 additions & 2 deletions exercises/practice/sieve/.meta/example.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ func eratosthenes(n: int): seq[bool] =
for odd in countup(3, n, 2):
result[odd] = true

for i in countup(3, n.float.sqrt.int, 2): # Optimisation: stop at sqrt(n)
for i in countup(3, n.float.sqrt.int, 2): # Optimization: stop at sqrt(n).
if result[i]:
for j in countup(i*i, n, 2*i): # Optimisation: start at i*i
for j in countup(i*i, n, 2*i): # Optimization: start at i*i.
result[j] = false

func primes*(limit: int, sieveLimit: static int = 1000): seq[int] =
Expand Down

0 comments on commit 8df62a3

Please sign in to comment.