8
0
I love /usr/share/dict/words
; it's so handy! I use it for all my programs, whenever I can! You're going to take advantage of this ever so useful file to use, by testing a word's individuality.
Input
- A word; defined in this challenge as any string of characters
/usr/share/dict/words
in some format; you may hard code it, read from disk, assume it as a second argument, whatever makes the most sense in your challenge
Output
- A words individuality (see below)
A word's individuality is derived from the following equation:
<the number of words for which it is a substring> / <length of the word>
Let's take a look at an example:
hello
. There are 12 words which have the substring hello
in them, divided by 5
(hello's length), and hello's individuality is 12/5
or 2.4
P.S. This is codegolf, so the lower the individuality score, the more individual
Because individuality is a long word, your program must be as short as possible
Good Luck!
Test Cases
You can use this convenient Node.js script, which fits the challenge requirements to fit your code. It is also how I generated the test cases:
var fs = require("fs");
var word = process.argv[2];
process.stdout.write("Reading file...")
fs.readFile("/usr/share/dict/words", function(err, contents) {
console.log("Done")
if (err) throw err;
words = contents.toString().split("\n");
var substrings = words.filter(w => w.indexOf(word) > -1).length;
var length = word.length;
console.log(`${word} => ${substrings} / ${length} = ${substrings / length}`)
})
Test Cases:
hello => 12 / 5 = 2.4
individuality => 1 / 13 = 0.07692307692307693
redic => 52 / 5 = 10.4
ulous => 200 / 5 = 40
challen => 15 / 7 = 2.142857142857143
ges => 293 / 3 = 97.66666666666667
hidden => 9 / 6 = 1.5
words => 12 / 5 = 2.4
aside => 8 / 5 = 1.6
Shouldn't it be the other way around? To make it more individual, have a higher individuality score? – Gabriel Benamy – 2016-11-23T02:21:03.453
2Probably, but making breaking changes to the challenge when people may have started golfing would be unwise – MayorMonty – 2016-11-23T02:22:40.333
Can we use other word lists instead? I think this one is easier to use (being a Windows user). The list is apparently not as long, so the individuality will be higher, but this doesn't alter the challenge the way I see it.
– Stewie Griffin – 2016-11-23T07:43:29.5871Is a word a substring of itself? – FlipTack – 2016-11-23T08:12:01.620
1I assume a case-insensitive match ? – zeppelin – 2016-11-23T08:58:17.997
In order to keep answers uniform, I request you use the same word list, but keep in mind that you can accept it in any way. Getting the word list is not part of the challenge – MayorMonty – 2016-11-23T17:06:14.327
@Flp.Tkc Yes, basically anything that can be grepped – MayorMonty – 2016-11-23T17:07:24.277
@zeppelin in most wordlists, all the entries are lowercase. Additionally you can assume that all input will be lowercase – MayorMonty – 2016-11-23T17:08:41.733
@MayorMonty Ok, great, I've asked as the /dict/words is not lowercase (at least not in my system). – zeppelin – 2016-11-23T18:22:49.730