-
-
Notifications
You must be signed in to change notification settings - Fork 23
Clock #304
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
Conversation
Introduce comprehensive Bats tests to verify the clock's functionality, including time calculations, addition, subtraction, and comparisons. Also, add the required Bats support and assertion library for testing utilities.
The "largest-product" and "binary-search-tree" exercises were removed as they are no longer in use. This reduces clutter and ensures the configuration file stays lean and focused on current content.
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.
I'm wondering if there might be a more structured approach to the input data.
+cc @glennj for thoughts on that.
Added a newline at the end of the file to adhere to standard POSIX file formatting conventions. This helps maintain consistency and avoids potential issues with tools expecting a newline at EOF.
Added a newline at the end of the file to adhere to POSIX standards and maintain consistency with other files. This change improves compatibility and avoids potential issues with tools expecting proper file formatting.
Hi colleagues, How about to add |
In Bash track Since
In the program we can use only NF to distinguish between the different cases: BEGIN {
MinutesInHour = 60
MinutesInDay = MinutesInHour * 24
}
NF == 2 {
printClock(clock($1, $2))
}
NF == 3 {
printClock(clock($1, $2 + $3))
}
NF == 4 {
print clock($1, $2) == clock($3, $4) ? "true" : "false"
}
function clock(hours, minutes) {
return ((hours * MinutesInHour + minutes) % MinutesInDay + MinutesInDay) % MinutesInDay
}
function printClock(minutes) {
printf "%02d:%02d\n", int(minutes / MinutesInHour), minutes % MinutesInHour
} |
I'm thinking more along the lines of not having to depend on NF or empty fields. What if $1 always contained the operation? |
This thought also crossed my mind. So, input data can be like:
$1 like a function or property name. Compare with the current approach:
50%/50% for me :) |
I like the Do what you want to show and teach. |
We could also do something like have multi-line programs, though that breaks with the standard paradigm.
The |
The AWK for processing records and fields. Three options are equal from my point of view:
Let's keep this exercise simple. |
The "two lines" being "two records" and since we are already processing a variable number of fields in the records, this may not increase complexity, really. But think of lines (which may be the case, but the idea is fields and records) and that changes the problem.
Let's add the minimum complexity necessary. There is no reason that this exercise is inherently simple and must be constrained to that, but also, let's add only the minimal possible to make it "good". We have already introduced variable fields in a record, by suggestion of
The data suggested is adding complexity since there is no indication that the number of fields is fixed. So we must figure out what happens if we have only 3, what if there are 4, what must happen if there is 5? The 5 is the simplest case, really, as there is no less doubt as to what represents 0 for minutes or is that hours, and for which time?" |
Hi team, Do we agree on this format:
The exemplar solution will be: BEGIN {
MinutesInHour = 60
MinutesInDay = MinutesInHour * 24
}
$1 == "create" {
printClock(clock($2, $3))
}
$1 == "add" {
printClock(clock($2, $3 + $4))
}
$1 == "subtract" {
printClock(clock($2, $3 - $4))
}
$1 == "equal" {
print clock($2, $3) == clock($4, $5) ? "true" : "false"
}
function clock(hours, minutes) {
return ((hours * MinutesInHour + minutes) % MinutesInDay + MinutesInDay) % MinutesInDay
}
function printClock(minutes) {
printf "%02d:%02d\n", int(minutes / MinutesInHour), minutes % MinutesInHour
} |
Hi folks. I like the |
Updated test cases and example.awk to use explicit command keywords (create, add, subtract, equal) as input for better clarity and consistency. This improves readability and aligns the code with a more structured format for future extensibility.
I've changed the example solution and tests. For generating tests, I'm using a custom Gem (Gemini) |
@@ -0,0 +1,4 @@ | |||
BEGIN { | |||
print "Implement this solution" > "/dev/stderr" |
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 possible, I would use "Create this solution" or "Write this solution". The word "implement" means too many things, including having the meaning "Use this solution" which is confusing if this solution does not exist.
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.
We have too many people (like me) that uses a dictionary to figure out what people are saying, and having that many choices to choose from, and seeing people correctly use the word as it means, and in all the ways that this word means, is very confusing. Better to have a "English as a not first language" friendly statement is probably a good thing to aspire to.
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.
We have this exact line in every awk exercise. I'm all for discussing a change, and the change ought to apply to all exercises. But I'd prefer that discussion happen in a dedicated "discuss stub" discussion and not as part of the "implement clock exercise" discussion.
@@ -0,0 +1,4 @@ | |||
BEGIN { | |||
print "Implement this solution" > "/dev/stderr" |
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.
We have this exact line in every awk exercise. I'm all for discussing a change, and the change ought to apply to all exercises. But I'd prefer that discussion happen in a dedicated "discuss stub" discussion and not as part of the "implement clock exercise" discussion.
Co-authored-by: Isaac Good <IsaacG@users.noreply.github.com>
Corrected a misplaced closing brace in the config.json file. This fix ensures proper JSON structure and prevents parsing issues.
Closes #303