(评论)
(comments)

原始链接: https://news.ycombinator.com/item?id=41217109

该用户分享了他们发现一个基于网络的文字游戏的经验,他们使用Python和二分搜索算法有效地解决了这个难题。 他们发现这款游戏很有趣,并决定与其他人分享。 此外,他们还回忆起大学期间在 Unix 计算机实验室遇到一位老妇人,她正在手工编写 C 代码,这表明年龄并不是学习技术或编程的障碍。 此外,他们还提到了一位 80 多岁的日本女士开发了一款涉及传统日本纸娃娃的移动应用程序的例子。 用户建议通过学习编码和编程来维持认知功能,可以有效地度过退休生活。 简而言之:用户发现了一个基于网络的文字游戏,使用Python和二分搜索算法解决了它,喜欢它,并鼓励其他人尝试; 还记得在 Unix 计算机实验室遇到一位老年程序员,并提到了一位老年妇女开发移动应用程序的另一个例子,这意味着人们即使在晚年也可以学习编码; 结论表明,对于那些希望保持精神活跃的退休人士来说,编码/编程可以成为一项有吸引力的活动。

相关文章

原文


yeh, based on their comment/submission history they're coding with chatgpt and now started claiming it's their grandma learning to code? or something? pretty uncool.



Must be lonely, even making up fake code comments:

> /* This makes the words flip over like in Wordle. Ask Gary if we can change it to letter by letter like wordle */



Caution: Spoilers in this comment!

Arriving a bit late to the party, but I couldn't resist crafting a quick binary search solution in Python.

  from urllib.request import urlopen, Request
  DICT_URL = "https://grandmasword.com/dictionary.js"
  response = urlopen(Request(DICT_URL, headers={"User-Agent": "Mozilla/5.0"}))
  words = [w.strip('"[];\n') for w in response.read().decode().split("[")[1].split(",")]
  lo, hi, answer = 0, len(words) - 1, ""
  while answer != "d":
      mid = lo + (hi - lo) // 2
      print(words[mid])
      answer = input("after/before/done? [abd] ")
      if answer == "a":
          lo = mid + 1
      elif answer == "b":
          hi = mid - 1
Took a total of 17 guesses to find the solution:
  MALPIGHIAS
  after/before/done? [abd] a
  RUBIFIES
  after/before/done? [abd] a
  TEARERS
  after/before/done? [abd] a
  UNMANLIEST
  after/before/done? [abd] a
  VORTICES
  after/before/done? [abd] b
  UTOPIANIZING
  after/before/done? [abd] a
  VERTICILLASTERS
  after/before/done? [abd] a
  VIROSE
  after/before/done? [abd] a
  VIZARD
  after/before/done? [abd] a
  VOLCANISE
  after/before/done? [abd] a
  VOLUMIZER
  after/before/done? [abd] b
  VOLPINOS
  after/before/done? [abd] b
  VOLITATE
  after/before/done? [abd] b
  VOLCANOLOGICAL
  after/before/done? [abd] b
  VOLCANIZATION
  after/before/done? [abd] a
  VOLCANIZES
  after/before/done? [abd] a
  VOLCANO
  after/before/done? [abd] d
Thanks for sharing this nice game on a fine Sunday evening! It was fun to play both manually as well as programmatically!


let l = 0; let h = dictionary.length - 1;

const textbox = document.querySelector("input");

while (l <= h) { const m = Math.floor((l + h) / 2); const guess = dictionary[m]; const textbox = document.querySelector("input"); console.log("Guessing:", guess);

  textbox.value = guess;
  guessWord();

  if (document.querySelector(".correct")) {
    console.log("Found the word:", guess);
    break;
  } else if (textbox.placeholder.includes("after")) {
    l = m + 1;
  } else {
    h = m - 1;
  }
}

Here's mine in JavaScript, you can paste it in the console.



Thanks! I should have realised that a solution for this could be implemented in JavaScript as well, allowing it to run directly in the web browser. Here is my translation of my earlier Python program to JavaScript:
  let lo = 0, hi = dictionary.length - 1
  const answer = document.getElementById('guess')
  while (document.getElementsByClassName('correct').length === 0) {
    const mid = Math.floor(lo + (hi - lo) / 2)
    answer.value = dictionary[mid]
    guessWord()
    if (answer.placeholder.indexOf('after') !== -1) {
      lo = mid + 1
    } else {
      hi = mid - 1
    }
  }
This solution is quite similar to yours. Thanks for this nice idea!


It seems the previous guess is always placed either one up or one down from the entry box. So if you're guessing "V" words, then type "apple", then "apple" will show after "vodka". So the list is not getting re-alphabatized.



Right. My word was before "wizard," and later I guessed "yesterday," which is after wizard. It put yesterday adjacent to the entry box, before wizard. Same is true for words before the word. Basically, if I make bad guesses, it doesn't list them in alpha order.



It's probably more akin to "my son's first book" being co-authored by both parents and each set of their parents, proofread by sister, and sent to a professional printing house to be sent back on thick glossy paperboard.

I'm just jealous to granma doesn't understand DNS



That is cool - it is nice and simple, but fun. The code is clearly from a beginner, but the saved game bit shows that she is a clever beginner - such a pragmatic way to continue a game. I hope she keeps learning and building more.



Cool game! I got it but it took a while.

Suggestions, limit to 5 chars and use a Wordle-like interface so your phone can’t suggest words.

I could see this being a legit NYT game.



In the spirit of helping a fellow programmer debug some things:

If you guess a word that isn’t in the dictionary, the text box looks like it’s cleared but my phone’s (iPhone) keyboard’s autocomplete either didn’t pick that up or there’s still some hidden content in the box.

It would be nice if the list was always sorted in totality.



Reading the code is a joy. I love seeing different approaches to what we all take as givens, such as design.css rather than style.css, or the usage of an `else if (1 == 1)` compared to `else` or even `else if (true)`.

(So I guess, thanks for not teaching her about bundlers and minifiers yet :))



One reason programmers do this is so that they can make a one character change, e.g. "else if (1 === 1)" -> "else if (1 === 2)" in order to change the logic there. For C programers you see a lot of '#if 0' '#if 1' for this same purpose. Though, given that it's used everywhere, I'm not sure if it's really for that purpose.



I enjoyed the dichotomic search.

It's a very interesting concept as I'm sure you can extract some interesting insight about the profile of a user from the list of 12+ words they'll come up with. (When looking back at most of mine, they're words that came up in this week's conversations or lyrics of my Spotify playlists)

Like, it might be a fascinating little add-on to have a "Rorschach" LLM-based module attached which looks at the vocabulary you used and tries to sketch out a cold reading about you.



This was fun, I found the word manually in 12 guesses. I have been a SWE for over a decade now, but have not done enough frontend to know how to make this!



I got completely stuck, tries various word solvers, but they seemed to be for cross words or anagrams, but they were no help. But an actual dictionary / word list unlocked it. Not sure if using a dictionary goes against the spirit of the game or is expected. Without it it seems incredibly difficult.



This is a fun game and it's harder than it looks! I'm impressed! She should produce a random word from the dictionary instead of hard coding it, and keep it going!



Amazing game. I felt in some scenarios the alphabetical order was incorrect (in my example I got Victory before Very), but very enjoyable!



Please don't show your grandma this but
  secretWords = ['test', 'test', 'test', 'horse', 'chocolate', 'garden', 'volcano', 'orange', 'elephant', 'star', 'violin', 'egg', 'pencil', 'forest', 'lamp', 'island', 'potato', 'happy', 'toilet', 'shell'];


Great job! Got in 12 :-)

Feature request - colour code incorrect guesses by distance from the solution. You could look up 'Hamming distance' for one approach to that.



I like it, pretty simple concept, good execution. I have to admit though, narrowing down a word purely by alphabetization can take a good while. Perhaps letting the player know the length of the target word would help.

Congrats to your grandma for making a game!



I like it, it's surprisingly fun to play. When played in groups (with changing words), this game would be well suited for non-natives learning English.



Would adding an indicator of how many letters I've gotten correct / "locked in" be fun? I don't know if I'm supposed to be trying a new 2nd or 3rd letter after V.



The view-source shows the comments on the code and it's really cute. Congratulations to your grandma (and to you, if you have anything to do with it!)



Took me 13 guesses but it is a great game for a few reasons:

- It can work for multiple age ranges by varying word lengths - It has good replay-ability - It can be adapted for offline play - It can be adapted for learners of new languages as well



Good gameplay! The one strong suggestion I have is to limit the word list to a category that uses common words. I had to resort to look at the word list dictionary in the console to see the possible words, and many of the words were extremely obscure.

I would come up with categories of increasing difficulty. "Colors", "Advanced Colors", "Common Fruit", "All Fruit", etc.

The game mechanic is great and worked flawlessly though!



One time when I was in the Unix computer lab in college, testing my C skills on a Sun workstation, an old lady sat down at the workstation next to me. She must've been between about 70 and 80 years old, maybe older, and she had a notebook which, as it lay open, I saw C++ code hand-written in it in her spidery, old-lady hand. I thought, huh, well it's never too late to start learning this stuff!

There's also the case of the 80-some-year-old Japanese lady who wrote her own iPhone app, a game about arranging traditional Japanese paper dolls: https://social-innovation.hitachi/en/article/colors-wakamiya...

If you're retired, bored, and have a lot of time on your hands, learning tech proficiency and programming seems a good way to pass the time and help keep your mind sharp. Just as it was for us bored kids back in the day.



Not to be negative or anything but a look through the source and it shows some interesting stuff (more info in the reddit post also created and posted by this never used account) but then whois shows that the website is setup to use cloudflare.

Maybe the grandchild is helping her but my mind goes straight to think that it's just a masked self-promotion. Just putting it out there.

About the game: somewhat fun but if you don't know the word, that's it. No really any way to figure out in a rewarding way.



I don’t understand why any of that indicates that a 70 year old couldn’t have created this, unless you think 70 year old people aren’t capable of doing that.



The age isn't really the inconsistency, it's the "only just learning to code" aspect. My first ever webpage was certainly not hosted behind Cloudflare. (I'd also expect beginner resources to point to something like GitHub Pages instead)



> About the game: somewhat fun but if you don't know the word, that's it. No really any way to figure out in a rewarding way.

What does this mean? You could say the same thing about Wordle.



I guessed many words I didn't know on Wordle (not a native English speaker), if you are able to reduce enough the letters search space there's going to be only a few options that e.g. make sense phonetically.



I actually misread the original comment but I guess my question is still somewhat relevant so leaving it as it is. You're right that it's easier to just bruteforce it in Wordle.



This was my problem too. If there was a scoring system, it might make sense to buy letters against your score, to help you forward once you're stuck. I got stuck. What the heck goes between Volatile and Vole?



Pasting the