Skip to content

Instantly share code, notes, and snippets.

@DrunkenAlcoholic
Created May 14, 2024 04:05
Show Gist options
  • Save DrunkenAlcoholic/2b5db4c4803fc70cd0a9cee8545d2c2b to your computer and use it in GitHub Desktop.
Save DrunkenAlcoholic/2b5db4c4803fc70cd0a9cee8545d2c2b to your computer and use it in GitHub Desktop.
Anagram [Exercism - Nim]
import strutils
proc detectAnagrams*(word: string, candidates: openArray[string]): seq[string] =
for candidate in candidates:
if word.toLowerAscii == candidate.toLowerAscii or word.len != candidate.len : continue
for ch in candidate.toLowerAscii:
if not contains(word.toLowerAscii, ch) or cmp(count(word.toLowerAscii, ch), count(candidate.toLowerAscii, ch)) > 0: break
else:
result.add(candidate)
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment