Created
May 14, 2024 04:05
-
-
Save DrunkenAlcoholic/2b5db4c4803fc70cd0a9cee8545d2c2b to your computer and use it in GitHub Desktop.
Anagram [Exercism - Nim]
This file contains hidden or 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
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