-
-
Notifications
You must be signed in to change notification settings - Fork 546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
word-search: add canonical data #755
Conversation
"screeaumgr", | ||
"alxhpburyi", | ||
"jalaycalmp", | ||
"clojurermt" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell there's no way to share this repeated input between tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed - before the schema, we had repeated inputs forgrep
and pov
. The schema did not support that, so in #699 we discussed and decided not to add the support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, thanks for the link; given that discussion, I think the duplication here is acceptable.
9a39305
to
4dbf0d6
Compare
"elixir" | ||
], | ||
"expected": [ | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It occurs to me that the only indication that the first element in this array indicates the position of "clojure"
and the second that of "elixir"
is convention.
I'm sorry that I cannot speak for all tracks, but I know that in Go the tests at least arrange such that output is a map whose keys are strings and corresponding values are what we have here (start/end column/row).
So I would like to ask about that. It seems unclear to leave it up to convention.
Another interesting item is that it appears the Go track is the only track that asks for multiple words at once. It's true that that matches the description. If it has to be that way (rather than simply changing the description), I would like to make sure that interface is solid before proceeding
"ruby", | ||
"haskell" | ||
], | ||
"expected": -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it becomes the case that the output can allow easy identification of which start/end pair corresponds to which word, I didn't find it too necessary to error on the entire output if just a single word is missing.
@petertseng great observations! I'm at a conference right now, but I'll push some updates based on your suggestions over the weekend :o) |
4dbf0d6
to
127a97f
Compare
Not only does this canonical data better match the existing description, but the end result also better reflects what I would consider to be a general word search solver (I've never seen a word search puzzle that asks you to locate a single word 😄). That's the reason I elected to adjust the input structure in the data rather than adjust the problem description. ⚖️ |
Updated! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, verified with
require 'json'
require_relative '../../verify'
DIRS = [-1, 0, 1].product([-1, 0, 1]).tap { |x| x.delete([0, 0]) }.freeze
def find_word(grid, word, starts)
# one-index.
coord = ->(y, x) {{"row" => y + 1, "column" => x + 1}}
starts.product(DIRS).each { |(y, x), (dy, dx)|
next unless word.each_char.with_index.all? { |c, i|
cy = y + dy * i
cx = x + dx * i
next false if cy < 0 || cx < 0
next false unless (row = grid[cy])
row[cx] == c
}
d = word.size - 1
return {
"start" => coord[y, x],
"end" => coord[y + d * dy, x + d * dx],
}
}
nil
end
def find_words(grid, words)
starts = grid.flat_map.with_index { |row, y|
(0...row.size).map { |x| [y, x] }
}.group_by { |y, x| grid[y][x] }
words.zip(words.map { |word| find_word(grid, word, starts[word[0]]) }).to_h
end
json = JSON.parse(File.read(File.join(__dir__, 'canonical-data.json')))
verify(json['cases'], property: 'search') { |c|
find_words(c['grid'], c['wordsToSearchFor'])
}
😍 |
Thanks @stkent ❤️ |
Closes #591.
Notes/thoughts:
description.md
; Go track will need to update that to match this spec.Feedback welcome! 👂