Skip to content

Commit

Permalink
Add Rosetta Code Anagrams test
Browse files Browse the repository at this point in the history
  • Loading branch information
rrthomas committed Jul 21, 2024
1 parent 527a415 commit 1ede158
Show file tree
Hide file tree
Showing 4 changed files with 25,138 additions and 0 deletions.
1 change: 1 addition & 0 deletions rosettacode/Anagrams.result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
null
26 changes: 26 additions & 0 deletions rosettacode/Anagrams.ursa
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Rosetta Code version fetches the text from the internet
// let text = fetch("http://wiki.puzzlers.org/pub/wordlists/unixdict.txt").text()

// We fetch the text from a local file to make the tests easier to run
use jslib.fs
let text = fs.readFileSync(argv.get(1), "utf-8")

let words = text.split("\n")

let anagrams = {}
for word of words.iter() {
let sorted = word.split("").sorted().join("")
if anagrams.get(sorted) == null {
anagrams.set(sorted, [])
}
anagrams.get(sorted).push(word)
}

let most_anagrams = 0
for ana of anagrams.values() {
if ana.len() > most_anagrams {most_anagrams := ana.len()}
}

for ana of anagrams.values() {
if ana.len() == most_anagrams {print(ana)}
}
Loading

0 comments on commit 1ede158

Please sign in to comment.