-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
25,138 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
null |
This file contains 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
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)} | ||
} |
Oops, something went wrong.