-
Notifications
You must be signed in to change notification settings - Fork 11
Good stuff #1
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
base: master
Are you sure you want to change the base?
Good stuff #1
Conversation
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.
Actually this is a little simpler than that 😉
If I have the three buckets, and I know that the labels are wrong, I should be able to get it in (at most) two tries. I'm going to use apples and oranges (I can't remember the example off the top of my head). Try thinking about it this way:
1 try:
Case: Pull an apple out of a bucket labeled 'apples'.
2 tries:
Case: Pull an orange out of a bucket labeled 'apples'.
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.
Right, I wasn't thinking about the wrong labels correlating to anything. If the labels can only be 'apples', 'oranges', or 'both apples and oranges', ( not labeled 'broccoli' for example ) and they are definitely wrong, then it should only take one or two tries. Taking an apple out of the 'apple' box means that it is the both box, and that the other boxes are 'apples' -> 'oranges', 'oranges' -> 'apples'. If you draw an orange out of the apple box, then you must draw out of the orange box. If you get an orange, it is the both box, if you get an apple, then the first box is the both box.
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.
Yup, you got it! This was an actual interview question I got, and I only got it when they reminded me that it was 'important that the labels are initially wrong.'
|
Interesting! I used to_a in irb without requiring anything, and in a .rb file with requiring anything, so I assumed it was just ruby. How do you tell when Rails extensions are being used in irb? Is there a way to disable it for testing? In any case, using ('a'..'z').to_a was simply for the convenience of making a large ordered string->array. Taking a string like 'cheesecake' assigned to reversing_string, I would do reversing_string.split("") to get each character into an array. |
|
Okay, so I tried it. will work because (...) is a Range object, which has The alternative to splitting the whole string is using the |
|
Ah, I see. I messed around with enumerables a bit using .collect, .cycle, etc. So this turns a string into an enumerable, which I can then use, say .collect on without ever turning it into an array. |
The classes relationship was an excellent exercise to tool around and figure out how ruby works. I feel like this alone should definitely be a prerequisite to the rails introduction.