-
-
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
resistor-color-trio: add exercise #1551
Changes from 1 commit
3ac8c8e
53704f5
b0d6b45
25a7d23
0a96e2b
a7104fa
9cc8e61
d2f19d0
3f7032d
df1109f
3dd6a99
5a50a7b
3d23cd9
dca9af3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,35 +4,43 @@ | |
"cases": [ | ||
{ | ||
"description": "Orange and orange and black", | ||
"property": "description", | ||
"property": "value", | ||
"input": { | ||
"colors": ["orange", "orange", "black"] | ||
}, | ||
"expected": "This is a 33 Ohms resistor." | ||
"expected": 33 | ||
}, | ||
{ | ||
"description": "Blue and grey and brown", | ||
"property": "description", | ||
"description": "Green and brown and brown", | ||
"property": "value", | ||
"input": { | ||
"colors": ["blue", "grey", "brown"] | ||
"colors": ["green", "brown", "orange"] | ||
}, | ||
"expected": "This is a 680 Ohms resistor." | ||
"expected": 510 | ||
}, | ||
{ | ||
"description": "Red and black and red", | ||
"description": "Blue and grey and yellow", | ||
"property": "value", | ||
"input": { | ||
"colors": ["blue", "grey", "yellow"] | ||
}, | ||
"expected": 680000 | ||
}, | ||
{ | ||
"description": "Brown and black and black", | ||
"property": "description", | ||
"input": { | ||
"colors": ["red", "black", "red"] | ||
"colors": ["brown", "black", "black"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The inputs for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Except that the integers don't mean anything by themselves. "orange" "orange" "orange" would be [3, 3, 3].
Would be a readable solution. If we use integers, we are moving away from correct and optimal solutions that look like this:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @SleeplessByte can you expand on that objection? If I'm reading @coriolinus correctly he's suggesting that That said maybe we've got some people thinking:
Is preferable while others are assuming:
Is the natural form. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't mean to suggest a list of integers; I meant a single integer, the value in ohms. The intent is to get people to write one However, it would teach bad factorization to include both operations in a single function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah. I understand what you're (both, @coriolinus and @yawpitch) are saying. I think having I think having I don't agree with all the "this will lead to bad code" arguments. I understand what you're saying, but it's up to the student to recognise the two concerns or for the mentor to point them out. Purposefully crafting problem descriptions so a student can't do it wrongly is kinda forcing a certain implementation, which is something we don't want. I personally think that forcing description to take "ohms" is also a language-specific implementation details. Having a class object with a description property that doesn't take arguments is very reasonable in a lot of languages. Both your arguments are forcing a certain code style (that is functional). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See: #1551 (comment)
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'm not sure that it does; it's up to the track implementer to decide on function vs class as the organizing structure, and for instance in Python I might reasonably decide that this should be the excercise in which we introduce subclassing of immutables and implement this as: class ResistorValue(int):
def __new__(cls, color, *colors):
pass
@property
def description(self):
pass Now @cmccandless note to us, might be a thing to consider for this exercise, as lord knows we don't have anything that introduces properly subclassing immutable builtins. |
||
}, | ||
"expected": "This is a 2 kilo Ohms resistor." | ||
"expected": "This is a 1O Ohms resistor." | ||
}, | ||
{ | ||
"description": "Green and brown and orange", | ||
"description": "Red and black and red", | ||
"property": "description", | ||
"input": { | ||
"colors": ["green", "brown", "orange"] | ||
"colors": ["red", "black", "red"] | ||
}, | ||
"expected": "This is a 51 kilo Ohms resistor." | ||
"expected": "This is a 2 kilo Ohms resistor." | ||
}, | ||
{ | ||
"description": "Yellow and violet and yellow", | ||
|
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.
s/orange/brown to get 510