Guess my word
simbase.org
simbase.org
> val words = oxforddict.
filter{case s => s.exists(_.isLetter) && s.forall(Character.isUpperCase(_))}.
distinct.
map((_.toLowerCase,1))
> def lcp(a:String,b:String) = { a.zip(b).takeWhile(Function.tupled(_ == _)).map(_._1).mkString }
> implicit val wordOrdering = new Ordering[String] {
> override def compare(a:String, b:String) = { val lcpIdx = lcp(a,b).length; a.substring(lcpIdx).compareTo(b.substring(lcpIdx)) }
> }
> def nextGuess(lower:String,upper:String,g:Int) = { val candidates = words.filterByRange(lower,upper).map(_._1).collect.sorted(wordOrdering).toList; val mid = candidates.length / 2; candidates.slice(mid-g/2,mid+g/2+1) }
nextGuess: (lower: String, upper: String, g: Int)
> nextGuess("prejudice","promise",1)
res42: List[String] = List(primeness)
> nextGuess("prime","promise",10)
res47: List[String] = List(procris, procrustean, procrusteanize, procrustes, procrustesian, proctitis, proctocele, proctodaeum, proctor, proctorage, proctorial)
> nextGuess("proctor","promise",10)
res48: List[String] = List(profulgent, profundity, profuse, profusely, profuseness, profusion, profusive, prog, progenerate, progeneration, progenitor)
> nextGuess("profuse","promise",12)
ding ding!!
I love HN, and I love scala :D Thanks for posting OP. HN needs more great technical content like this and less opinion & news, in my opinion.The first thing that comes to mind is skipping past letters that don't appear very often at that point in a word with the current prefix--or to be more granular, you could change your counter (here g) to a float and somehow weight each letter by how rarely it occurs after the letters you've established so far. So if you've currently established that the first four letters are "pro," and "z" almost never occurs after those letters, "z" might be given a weight above 1 so the counter skips right past it.
https://jsfiddle.net/fsc5v4v0/9/embedded/result/
And here's the code: https://jsfiddle.net/fsc5v4v0/89/
I hope it's bug free. jQuery is really a pain to reason about, so much implicit state all over the place. I thought React might've been a bit too much, but halfway through it I started reconsidering my choice :P
Here are the correct URLs:
Once I started to narrow it down it became difficult to find words between my constraints. In one case I was making assumptions about what letters can come after other ones while trying to generate a new word (and being aware of this isn't enough to stop it.) And then, in the last case, when I had it narrowed between <xyz> and <xyz>ed (think jump and jumped, for example), my brain only wanted to search for words that were conceptually related to xyz. This was a mistake, the goal word started with xyz but was not related to it conceptually, but again, an awareness that my brain was favoring a search of the concept space rather than searching the dictionary alphabetically was not enough to remedy it.
I think more important than a word cloud of guesses would be the progression of words to see people's thought process (dictionary vs conceptual).
And I'm not ashamed at all that I started with "monkey" after all, M is the 13th letter. ;)
This is why we can't have nice things - remind me never to show HN anything that's just a bit of fun. Some people really will set the world on fire just to see if they can, and then just to watch it burn.
It's not what hacking used to be about. It used to be about making cool stuff, and people sharing and appreciating it. Now even the simplest of toys need to be bullet-proof and hardened.
I miss the old days.
I got up early in the morning, made a nice breakfast (today? roasted turkey legs seasoned with my own personal italian blend, with a carrot and rutabaga mash, and a glass of whatever white wine was open and in my fridge, wasn't bad for a $7 bottle), had a cup of coffee (fresh ground, brewed using the inverted Aeropress method), cleaned the catbox, fed the cat (even though he probably ate as much as I did off the turkey legs, fat bastard he is), did my morning strength training routine, and was just waiting for it to warm up more outside so I could go for my morning walk (September in Maine means it dips into the 40s at night and doesn't warm up into the 60s until 9am), and was otherwise doing work (just because its Saturday doesn't mean I'm off the clock)...
... and then I check HN and find this at the top. Now I know what I'm going to be doing for the next few hours.
* 3 tablespoons dried basil
* 3 tablespoons dried oregano
* 3 tablespoons dried parsley
* 1 tablespoon garlic powder
* 1 teaspoon onion powder
* 1 teaspoon dried thyme
* 1 teaspoon dried rosemary
* 1/4 teaspoon fine black pepper
* 1/4 teaspoon red pepper flakes(I got the first in 24 tries and the second in 22 with the help of a dictionary!)
lines = tuple(open('english_words.txt', 'r'))
min = 0;
max = len(lines)
while True :
index = min + (max-min)//2
print lines[index];
before = raw_input("Before? y/n")
if before == "y" :
max = index-1
elif before == "n" :
min = index+1
else :
break
english_words.txt can be downloaded here:
http://www.mieliestronk.com/corncob_lowercase.txtHey - That's straight from /usr/share/dict/words
3rd visible line on links: http://simbase.org/gmw/guess.cgi?by=joon&result=leaderboard http://simbase.org/simbase/leagues/simbasev3/gmw/guess.cgi?b...
console.log(answer)You could improve this method by finding out where the exact midpoint is in the list of words by alphabetical order, as I'm not certain it's actually halfway through the alphabet.
And I'd bet that some people here on HN could come up with even cleverer ways to cut down on guesses.
Also being the page just a half dozen of divs making it responsive would have been totally trivial, so why not bother?