I'm a distance student and I have just listened to your first lecture and completed assignments 0 and 1. I am enjoying this course immensely so far. Damn good stuff.
Anyway, I wonder if we can't get you to post the next assignment up (Assignment 2) so I/we can spread our time out better? I'm not showing off here--at some point I will be slower than the others. So while I have a tiny advantage regarding time, it sure would be nice to get started on that command line application. Also, my motivation comes in spurts :)
jgn
· 1 year ago
Assignment 2 will be posted by Oct. 1.
MaureenB
· 1 year ago
Question about objects in memory: As I walked through these one-liners, I noticed I didn't understand intuitively when the object was being modified in memory and when I had a brand new one available. If you read the documentation, it will tell you which operations create a new instance of that object. Is this the only way to know for sure? Is there some rule of thumb I can use? In other languages, I explicitly copy the instance to a var and that's how I know I've got a brand new copy. With one-liners, such as
a.reverse
I don't understand why that is not modifying the instance.
jgn
· 1 year ago
Maureen,
Say a is an array:
a = [ 1, 2, 3 ]
Then
a.reverse
will return a new Array that is form of the elements of a in reverse order. In the typical case this is a good thing, though, arguably, wasteful of memory depending on what you are doing or what you want.
Here's the documentation on Array#reverse (I got this by typing: ri Array#reverse) (note below on ri):
---------------------------------------------------------- Array#reverse array.reverse -> an_array ------------------------------------------------------------------------ Returns a new array containing self's elements in reverse order.
Now, there are some Ruby methods that will change the object to which "a" refers. An example of this is: reverse!
Here's what you get when you type ri Array#reverse!
--------------------------------------------------------- Array#reverse! array.reverse! -> array ------------------------------------------------------------------------ Reverses self in place.
a = [ "a", "b", "c" ] a.reverse! #=> ["c", "b", "a"] a #=> ["c", "b", "a"]
Now, about ri:
When you call a method on an object instance in Ruby, such as calling reverse on a, you use dot notation:
a.reverse
However, the ri tool uses the # sign to show documentation for the instance methods. It uses a dot for class methods.
I will be going over this in lecture.
Morris
· 1 year ago
If you look at the beginning of Chapter 8 of the Pickaxe, ("More about Methods"), there's a little bit about naming conventions for methods. It seems that in general, methods don't modify the object which they're being called on. If a method is modifying its object, the method name should usually end with an exclamation point (!). So a.reverse gives you a new object, but a.reverse! modifies the original. There are quite a few examples, just in the Array and String classes, of pairs of methods, one of which returns a new object and the other modifies the original, each pair of method names differing just by the presence or absence of the ! at the end of the name.
jgn
· 1 year ago
All correct. Note that the ! is just a convention. Nothing enforces it.
philadelphia
· 1 year ago
Question about problem 2 in assignment 1.
If we are unable to change the array passed to the function (it is frozen), then I suppose we'll need to return another array, stored in the reverse order. I've been trying to use map, collect, inject, for, for_each_item, etc... to no joy. Maybe this will be covered in a bit more detail in Wednesday's lecture. But I'm pretty stuck. Any guidance would be mucho appreciated.
jgn
· 1 year ago
Why don't you try some of the other problems and come back to that one?
philadelphia
· 1 year ago
OK.. I think my main issue is not knowing how to handle a return of a variable without instantiating it in the function. For example, in the following problem, if I instantiate a Hash (defaulting to 0) then I can use it to add up the instances within the array. I'm not sure how to return the hash without creating it in the first place.
jgn
· 1 year ago
You can instantiate all the new objects you want; we only say that you can't create extra local VARIABLES.
Let me describe the general case of what you are coming up against in the hopes that you will discover a strategy in the Programming Ruby book.
Here's what you are trying to do:
You are trying to instantiate an object which will, essentially, "remember" the state as you iterate through the original Array.
It's as though I want to write:
Give me a new Array . . . now let me literate through the original Array, and as I encounter each element, do something to it and add it to the new Array . . . then return the new Array. Oh, and by the way, I don't want to explicitly name a new Array.
There are some great methods for jumping through an Array in "interesting" ways: push, pop, shift, unshift -- a lot of these are suggestive for use with other methods such as collect, map, inject . . .
One last thing:
When we say "don't create new variables," we are also not including block parameters (inslide the verical bars). You can use the block params all you want. I should tweak the assignment description above to make this explicit.
philadelphia
· 1 year ago
Makes more sense. Thanks.
jgn
· 1 year ago
I will discuss exactly this issue Wednesday night, so keep your ears open.
philadelphia
· 1 year ago
I got through that one and a couple more... learning as I go. I am having a tough time with one problem...
I'm using inject, and my memo keeps going to nil after the first iteration. Not sure what might be causing this. I'm assigning a value to it which I receive as a result of a divmod (I using the first element in the returned array). First time through it works. Subsequently, it forces the memo to nil.
Any ideas?
jgn
· 1 year ago
Post your code. If it's too close to an assignment solution, post something similar.
philadelphia
· 1 year ago
I saw the problem... in debugging, I had a p statement in the routine. This reset the variable to nil after execution. Removed the p and all is right with the world. They've certainly gotten easier after working on them for a day or so . Though, while I am able to make them work within the rules as outlined above, I've got to work on improving my solutions so that they are more concise (and readable).
vaughanatworld
· 1 year ago
On block parameters, for Enumerable#inject there is |memo, obj| . From the context of what you are saying above, is it possible to get memo1, memo2 ... ? I can force it with array of arrays etc but it would be nice to short circuit this with user created block parameters. Is this possible?
jgn
· 1 year ago
If you think you need more block parameters, then you should be writing the code that does the enumeration yourself -- you are probably no longer in the realm of using utility methods such as .inject, .map, etc.
I.e., write the method that does the yield.
vaughanatworld
· 1 year ago
I think I just had an epiphany.
jgn
· 1 year ago
There may be an over-the-counter medication that can help with that.
Morris
· 1 year ago
Problem 1 says to operate on "an English sentence (without whitespace ...". Can we take this to mean "without leading or trailing whitespace"? The example clearly has whitespace, separating the words. Also, is it legitimate for the result to have each pair of words separated by just one space character? Using regular expressions, one could preserve the exact form of the whitespace in the string, but my impression is that this is not the "Ruby-ish" kind of solution that's being looked for here.
jgn
· 1 year ago
I think I meant to say: with whitespace.
Here is the sample input and output:
# Example input: # # a = "This is a test of the emergency broadcast system" # # Expected result: "ThisIsATestOfTheEmergencyBroadcastSystem" #
You must certaining pass the sample data, which has no leading or trailing whitespace, and has a single space between words.
Ideally, your code should also be able to handle leading and trailing whitespace, and word separators that are whitespace (not just a single space).
You can do this elegantly without a regular expression.
Morris
· 1 year ago
My second question, about regular expressions, was based on a misreading of the specification. I was thinking of output like "This Is A Test Of ..." and wondering about preserving multiple whitespace. Removing all the whitespace is much easier.
jgn
· 1 year ago
Correct me if I'm wrong, but I don't think we have a problem where you must preserve whitespace. That would be a good one for a regular expression.
Morris
· 1 year ago
I agree. As I said, the question about regexps was based on my misreading (actually misremembering) the specification.
Morris
· 1 year ago
For these one-liners, can we assume that the input is valid, or do we need to take steps to do something reasonable with invalid input? I'm thinking specifically of problem 10. Is it okay to just fail if the input string doesn't have exactly one hyphen?
Morris
· 1 year ago
A followup question for problem 10: What can we assume about the input string, or what kinds of input should we be prepared to handle? Do we need to handle ranges with endpoints of types other than integer?
jgn
· 1 year ago
Good question.
Assume that the start and the end of the resultant Range are Fixnum.
So you can assume that the substrings before and after the dash will be something you can convert to a Fixnum. (I think the sample solution will also handle Bignum, but I'd have to experiment with it.)
jgn
· 1 year ago
Assume the input is valid.
Incidentally, if, for a problem, you want more sample cases for data and a result, let us know.
Morris
· 1 year ago
Problem 12 says, "the first element is a category, and the section element is an item ...". I believe that should be "second element", not "section element"
jgn
· 1 year ago
Yes -- thanks!
Student1
· 1 year ago
Hi, I am having a problem with 3. I do it similar to the way I do 2. In 2, I use inject - initializing an empty array. In 3, I try to do something similar - using an inject, initializing a Hash with a default return value of 0. Yet this does not work. Since 2 worked, I am wondering why 3 won't. In fact, ruby gave me some parsing error. Can I use Hash just as I use Array with inject ? and can the initialization looks like Hash.new(0). For problem 2, my initialiation was simply []
Thanks
jgn
· 1 year ago
Slow down, and review your own code very carefully. The way to debug these things is to try much simpler versions of your code, and then build up from those simpler versions.
You might want to think a bit about the terminology you're using. It's really quite different from the documentation. You write: "Initializing a Hash with a default return value of 0." I think you mean: Initializing a Hash where the default (or initial) value associated with a key is 0. Or, in the words of ri, an access by a key that doesn't correspond to a hash entry will return the value that is passed in as the first parameter. The more precision you can bring to your statement of a problem the better.
Try not to reveal too much your solutions.
Student1
· 1 year ago
Yes, that is what I meant. I tried the code outside of these 1 liners, it works. Without making it a 1 liner, I have to create a variable and initialize, and I have to return the local variable. I find irb quite cryptic when it complains. For example, it gives me the following: from (irb):40 from (irb):40:in `inject' from (irb):40:in `each' from (irb):40:in `inject' from (irb):40 from :0
It i unclear what this mean. So, am I more or less right in approaching problem 03 just like 02 ?
Everything seemed so reasonable and yet it doesn't work. I wonder if it is just different platform ? (In java with 1.6 on the MAC but not elsewhere) Thanks
jgn
· 1 year ago
At this point you should take it up with your section leader.
One thing that is tricky about inject is that the inside of the block must return the "memo" -- it happens sometimes that the code inside the block may evaluate a condition and perhaps return nil. Then the memo gets set to nil, and it can no longer be used to "accumulate" a value. I will talk about this tomorrow night, I hope.
Student1
· 1 year ago
Well, I think that my code is not returning the memo inside the block, and seems like my problem. Thanks for the hint.
Student1
· 1 year ago
It works now. Thanks for the hint.
Morris
· 1 year ago
For problem 4, can we assume that all the strings in the input array begin with uppercase letters?
Keith
· 1 year ago
Yes -- the tests will pass. But it is Ruby, so accounting for either case is trivial!
Morris
· 1 year ago
Trivial, yes, but less efficient. -- Morris Keesan -- keesan@alum.bu.edu
plu
· 1 year ago
The method each_slice and each_cons seem to be defined within the Enumerable. However, when I am invoking it, it tells me "NoMethodError: undefined method' - this occurs for both Array and Range. Even if I use the sample line from the documentation
e.g. (1..10).each_slice(3) {|a| p a}
It still throws an error. Are these methods not valid? Thanks!
Quotes from the website: "Rdoc is causing some serious confusion with libraries.
In core documentation, Enumerable defines each_slice method.
Extend this module into your class and each_slice is not defined.
Reason? each_slice is NOT in the core Enumerable module, but rather the Standard Library Enumerable::Enumerator class, even though the ruby-doc core class documents say otherwise.
You must
require 'enumerator'
to have each_slice is available as a method to your class."
jgn
· 1 year ago
Just FYI: Good solutions can be expressed for all of the assigned problems without using each_sice and each_cons.
plu
· 1 year ago
Yes. I know that. :)
I am just going through irb and trying out all the methods to see if my understandings of each method is valid - it was just part of the exercise that I came across these two methods.
Thanks!
swithin
· 1 year ago
Harvard has assigned me two ID #s, neither of which are named "student id number".
One is named "Harvard ID (HUID)", and the other is named just plain "ID Number", which starts with an "@" sign.
Which one should we use for the "student id number" on homework assignment 1?
def info_student_id "" end
jgn
· 1 year ago
We can definite correlate the "@" one, so use that.
akv
· 1 year ago
Hi,
When I replace the code int he pixaxe f
h = { "a" => 20, "b" => 30, "c" => 10 } h.sort {|a,b| a[1]<=>b[1]}
h.sort {|a,b| a[1]<=>b[1]} with code pertinent to problem 6, then some of the values in the hash get dropped? Can someone explain a little more what the folowing line does
akv
· 1 year ago
sorry, i am looking for a little frther clarification with the line h.sort {|a,b| a[1]<=>b[1]}
Also, if I use the following hash - h = { "a" => 20, "b" => 30, "c" => 10 } - then the hash does not get modified when I run the sort on the line above, but if I use the has in the hw problem, then 2 of the elements get dropped?
jgn
· 1 year ago
you should think very, very hard about what you are trying to do. What do you think "sorting a hash" means? Note that a hash has keys and values. Do you want to sort by the keys or the values? Also note that a hash is unordered. The result of "sorting" a hash is an array of arrays. Is that what you want?
I would recommend reassessing your basic strategy in light of the problem.
akv
· 1 year ago
Ok, I was trying to sort an array by val, then flatten it and to a diff with the hash values but my hash keeps getting re-written. Does that maake sense or should I rethink my strategy. I guess either way could you exmplain what the line is doing h.sort {|a,b| a[1]<=>b[1]} and why my pieces of my hash are getting gobbled up?
jgn
· 1 year ago
I am not sure what you mean by "swallowed up."
Notice:
h = {"hither"=>2, "baz"=>1, "foo"=>500} p h.sort {|a,b| puts b; a[1]<=>b[1]}
results in:
[["baz", 1], ["hither", 2], ["foo", 500]]
OK? I don't see anything getting "swallowed up."
If you like, e-mail your implementation of problem 6 to your TA/grader.
LanceB
· 1 year ago
I am sure this is probably ridiculously obvious but I am having a terrible time trying to get a counter started in a block so that I can execute an if statement based upon its value. Is there a way to pass the initial value without the inject method? I have tried something like this but the values never increase even though an array shows that it did indeed loop through the array:
collect means: Invokes block once for each element
So ONE element should get passed into the block. You have two block parameters, so that is not right.
The classic way to have some value "accrue" is with inject. E.g.,
>> [ 1, 2, 3 ].inject(5) { |m, e| m += e } => 11
Here I'm starting the memo (m) off at 5, and am adding each element (1, 2, 3) to the memo successively.
This might provide more clarity:
>> [ 1, 2, 3 ].inject(5) { |m, e| m += e; puts "total so far: #{m}"; m } total so far: 6 total so far: 8 total so far: 11 => 11
LanceB
· 1 year ago
Excellent. That is exactly what I was looking for!
rajatbaner
· 1 year ago
Regarding Grading, - If our code passes all the tests in the solution_set_test.rb, can we assume we'll get 100% ? - if there are extra tests with some weird cases we have not accounted for, we'll lose points. If so, can we turn in all 12, and the grader will drop the lowest two problems?
Thanks!
jgn
· 1 year ago
1. No. You cannot assume that if you pass all tests, you'll get 100%. Two reasons:
a. You may write a solution that ONLY passes the tests. You need to write code that satisfies the requirements, which we stated in words and sentences. The tests may help, but it is entirely possible that the data we use in the tests misses an edge case.
b. Code that passes the tests may be grossly inefficient, inelegant, relying on regular expressions, etc.
2. No. Pick your ten best and submit those. Comment out the solutions for the ones you don't want to submit.
If you solve all twelve, we will pick 10 according to any rule that pops into our heads at the moment (randomly; first 10; easiest to grade; whatever).
sa
· 1 year ago
I am having this output when i run the solution test.
C:\assn1-1.0.0\test\other>ruby solution_set_test.rb C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_re quire': C:/assn1-1.0.0/student_solution_set.rb:244: syntax error, unexpected $en d, expecting kEND (SyntaxError) from C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `re quire' from solution_set_test.rb:4
jgn
· 1 year ago
"syntax error, unexpected $end, expecting kEND"
Look at your code and verify that all blocks are ended correctly.
sa
· 1 year ago
I've lookded into that. Apparently all blocks are ended fine and I tried changing the location of solution to the 'other' folder, but the same error.
jgn
· 1 year ago
Review your code again. If you have to, try commenting out methods until it doesn't show the error.
Anyway, I wonder if we can't get you to post the next assignment up (Assignment 2) so I/we can spread our time out better? I'm not showing off here--at some point I will be slower than the others. So while I have a tiny advantage regarding time, it sure would be nice to get started on that command line application. Also, my motivation comes in spurts :)
a.reverse
I don't understand why that is not modifying the instance.
Say a is an array:
a = [ 1, 2, 3 ]
Then
a.reverse
will return a new Array that is form of the elements of a in reverse order. In the typical case this is a good thing, though, arguably, wasteful of memory depending on what you are doing or what you want.
Here's the documentation on Array#reverse (I got this by typing: ri Array#reverse) (note below on ri):
---------------------------------------------------------- Array#reverse
array.reverse -> an_array
------------------------------------------------------------------------
Returns a new array containing self's elements in reverse order.
[ "a", "b", "c" ].reverse #=> ["c", "b", "a"]
[ 1 ].reverse #=> [1]
Now, there are some Ruby methods that will change the object to which "a" refers. An example of this is: reverse!
Here's what you get when you type ri Array#reverse!
--------------------------------------------------------- Array#reverse!
array.reverse! -> array
------------------------------------------------------------------------
Reverses self in place.
a = [ "a", "b", "c" ]
a.reverse! #=> ["c", "b", "a"]
a #=> ["c", "b", "a"]
Now, about ri:
When you call a method on an object instance in Ruby, such as calling reverse on a, you use dot notation:
a.reverse
However, the ri tool uses the # sign to show documentation for the instance methods. It uses a dot for class methods.
I will be going over this in lecture.
It seems that in general, methods don't modify the object which they're being called on. If a method is modifying its object, the method name should usually end with an exclamation point (!). So a.reverse gives you a new object, but a.reverse! modifies the original. There are quite a few examples, just in the Array and String classes, of pairs of methods, one of which returns a new object and the other modifies the original, each pair of method names differing just by the presence or absence of the ! at the end of the name.
If we are unable to change the array passed to the function (it is frozen), then I suppose we'll need to return another array, stored in the reverse order. I've been trying to use map, collect, inject, for, for_each_item, etc... to no joy. Maybe this will be covered in a bit more detail in Wednesday's lecture. But I'm pretty stuck. Any guidance would be mucho appreciated.
Let me describe the general case of what you are coming up against in the hopes that you will discover a strategy in the Programming Ruby book.
Here's what you are trying to do:
You are trying to instantiate an object which will, essentially, "remember" the state as you iterate through the original Array.
It's as though I want to write:
Give me a new Array . . . now let me literate through the original Array, and as I encounter each element, do something to it and add it to the new Array . . . then return the new Array. Oh, and by the way, I don't want to explicitly name a new Array.
There are some great methods for jumping through an Array in "interesting" ways: push, pop, shift, unshift -- a lot of these are suggestive for use with other methods such as collect, map, inject . . .
One last thing:
When we say "don't create new variables," we are also not including block parameters (inslide the verical bars). You can use the block params all you want. I should tweak the assignment description above to make this explicit.
I'm using inject, and my memo keeps going to nil after the first iteration. Not sure what might be causing this. I'm assigning a value to it which I receive as a result of a divmod (I using the first element in the returned array). First time through it works. Subsequently, it forces the memo to nil.
Any ideas?
I.e., write the method that does the yield.
Also, is it legitimate for the result to have each pair of words separated by just one space character? Using regular expressions, one could preserve the exact form of the whitespace in the string, but my impression is that this is not the "Ruby-ish" kind of solution that's being looked for here.
Here is the sample input and output:
# Example input:
#
# a = "This is a test of the emergency broadcast system"
#
# Expected result: "ThisIsATestOfTheEmergencyBroadcastSystem"
#
You must certaining pass the sample data, which has no leading or trailing whitespace, and has a single space between words.
Ideally, your code should also be able to handle leading and trailing whitespace, and word separators that are whitespace (not just a single space).
You can do this elegantly without a regular expression.
"This Is A Test Of ..." and wondering about preserving multiple whitespace. Removing all the whitespace is much easier.
I'm thinking specifically of problem 10. Is it okay to just fail if the input string doesn't have exactly one hyphen?
Do we need to handle ranges with endpoints of types other than integer?
Assume that the start and the end of the resultant Range are Fixnum.
So you can assume that the substrings before and after the dash will be something you can convert to a Fixnum. (I think the sample solution will also handle Bignum, but I'd have to experiment with it.)
Incidentally, if, for a problem, you want more sample cases for data and a result, let us know.
I believe that should be "second element", not "section element"
I am having a problem with 3. I do it similar to the way I do 2. In 2, I use inject - initializing an empty array. In 3, I try to do something similar - using an inject, initializing a Hash with a default return value of 0. Yet this does not work. Since 2 worked, I am wondering why 3 won't. In fact, ruby gave me some parsing error. Can I use Hash just as I use Array with inject ? and can the initialization looks like Hash.new(0). For problem 2, my initialiation was simply []
Thanks
You might want to think a bit about the terminology you're using. It's really quite different from the documentation. You write: "Initializing a Hash with a default return value of 0." I think you mean: Initializing a Hash where the default (or initial) value associated with a key is 0. Or, in the words of ri, an access by a key that doesn't correspond to a hash entry will return the value that is passed in as the first parameter. The more precision you can bring to your statement of a problem the better.
Try not to reveal too much your solutions.
I tried the code outside of these 1 liners, it works. Without making it a 1 liner, I have to create a variable and initialize, and I have to return the local variable. I find irb quite cryptic when it complains. For example, it gives me the following:
from (irb):40
from (irb):40:in `inject'
from (irb):40:in `each'
from (irb):40:in `inject'
from (irb):40
from :0
It i unclear what this mean.
So, am I more or less right in approaching problem 03 just like 02 ?
Everything seemed so reasonable and yet it doesn't work. I wonder if it is just different platform ? (In java with 1.6 on the MAC but not elsewhere)
Thanks
One thing that is tricky about inject is that the inside of the block must return the "memo" -- it happens sometimes that the code inside the block may evaluate a condition and perhaps return nil. Then the memo gets set to nil, and it can no longer be used to "accumulate" a value. I will talk about this tomorrow night, I hope.
--
Morris Keesan -- keesan@alum.bu.edu
e.g.
(1..10).each_slice(3) {|a| p a}
It still throws an error. Are these methods not valid? Thanks!
require 'enumerator'
within irb. Why is this the case? Thanks!
Quotes from the website:
"Rdoc is causing some serious confusion with libraries.
In core documentation, Enumerable defines each_slice method.
Extend this module into your class and each_slice is not defined.
Reason? each_slice is NOT in the core Enumerable module, but rather the Standard Library Enumerable::Enumerator class, even though the ruby-doc core class documents say otherwise.
You must
require 'enumerator'
to have each_slice is available as a method to your class."
I am just going through irb and trying out all the methods to see if my understandings of each method is valid - it was just part of the exercise that I came across these two methods.
Thanks!
One is named "Harvard ID (HUID)", and the other is named just plain "ID Number", which starts with an "@" sign.
Which one should we use for the "student id number" on homework assignment 1?
def info_student_id
""
end
When I replace the code int he pixaxe f
h = { "a" => 20, "b" => 30, "c" => 10 }
h.sort {|a,b| a[1]<=>b[1]}
h.sort {|a,b| a[1]<=>b[1]}
with code pertinent to problem 6, then some of the values in the hash get dropped? Can someone explain a little more what the folowing line does
Also, if I use the following hash - h = { "a" => 20, "b" => 30, "c" => 10 } - then the hash does not get modified when I run the sort on the line above, but if I use the has in the hw problem, then 2 of the elements get dropped?
I would recommend reassessing your basic strategy in light of the problem.
Notice:
h = {"hither"=>2, "baz"=>1, "foo"=>500}
p h.sort {|a,b| puts b; a[1]<=>b[1]}
results in:
[["baz", 1], ["hither", 2], ["foo", 500]]
OK? I don't see anything getting "swallowed up."
If you like, e-mail your implementation of problem 6 to your TA/grader.
a.collect {|val, counter| counter += 1; print counter.to_s}
Help!
So ONE element should get passed into the block. You have two block parameters, so that is not right.
The classic way to have some value "accrue" is with inject. E.g.,
>> [ 1, 2, 3 ].inject(5) { |m, e| m += e }
=> 11
Here I'm starting the memo (m) off at 5, and am adding each element (1, 2, 3) to the memo successively.
This might provide more clarity:
>> [ 1, 2, 3 ].inject(5) { |m, e| m += e; puts "total so far: #{m}"; m }
total so far: 6
total so far: 8
total so far: 11
=> 11
- If our code passes all the tests in the solution_set_test.rb, can we assume we'll get 100% ?
- if there are extra tests with some weird cases we have not accounted for, we'll lose points. If so, can we turn in all 12, and the grader will drop the lowest two problems?
Thanks!
a. You may write a solution that ONLY passes the tests. You need to write code that satisfies the requirements, which we stated in words and sentences. The tests may help, but it is entirely possible that the data we use in the tests misses an edge case.
b. Code that passes the tests may be grossly inefficient, inelegant, relying on regular expressions, etc.
2. No. Pick your ten best and submit those. Comment out the solutions for the ones you don't want to submit.
If you solve all twelve, we will pick 10 according to any rule that pops into our heads at the moment (randomly; first 10; easiest to grade; whatever).
C:\assn1-1.0.0\test\other>ruby solution_set_test.rb
C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_re
quire': C:/assn1-1.0.0/student_solution_set.rb:244: syntax error, unexpected $en
d, expecting kEND (SyntaxError)
from C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `re
quire'
from solution_set_test.rb:4
Look at your code and verify that all blocks are ended correctly.