How to resolve the algorithm Anagrams step by step in the Jsish programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Anagrams step by step in the Jsish programming language
Table of Contents
Problem Statement
When two or more words are composed of the same characters, but in a different order, they are called anagrams. Using the word list at http://wiki.puzzlers.org/pub/wordlists/unixdict.txt, find the sets of words that share the same characters that contain the most words in them.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Anagrams step by step in the Jsish programming language
Source code in the jsish programming language
/* Anagrams, in Jsish */
var datafile = 'unixdict.txt';
if (console.args[0] == '-more' && Interp.conf('maxArrayList') > 500000)
datafile = '/usr/share/dict/words';
var words = File.read(datafile).split('\n');
puts(words.length, 'words');
var i, item, max = 0, anagrams = {};
for (i = 0; i < words.length; i += 1) {
var key = words[i].split('').sort().join('');
if (!anagrams.hasOwnProperty(key)) {
anagrams[key] = [];
}
var count = anagrams[key].push(words[i]);
max = Math.max(count, max);
}
// display all arrays that match the maximum length
for (item in anagrams) {
if (anagrams.hasOwnProperty(item)) {
if (anagrams[item].length === max) {
puts(anagrams[item].join(' '));
}
}
}
/*
=!EXPECTSTART!=
25108 words
abel able bale bela elba
caret carte cater crate trace
angel angle galen glean lange
alger glare lager large regal
elan lane lean lena neal
evil levi live veil vile
=!EXPECTEND!=
*/
You may also check:How to resolve the algorithm Discordian date step by step in the jq programming language
You may also check:How to resolve the algorithm Reflection/List properties step by step in the Go programming language
You may also check:How to resolve the algorithm Y combinator step by step in the Verbexx programming language
You may also check:How to resolve the algorithm Semiprime step by step in the Forth programming language
You may also check:How to resolve the algorithm List comprehensions step by step in the Sidef programming language