SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
But the call to the sum method on the List still was accepted!
Marco Ehrentreich wrote:
But the call to the sum method on the List still was accepted!
Maybe it was just accepted because the sum() function was in the example assignment? But it was surely not one of the expected solutions![]()
Anyway, the recursive algorithm is quite simple as Matthew already described!
Marco
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
No more Blub for me, thank you, Vicar.
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Joe Harry wrote:Anone already working on the Week 2 assignments? I got the first question done. Kind of lost with the second assignment.
No more Blub for me, thank you, Vicar.
chris webster wrote:
Joe Harry wrote:Anone already working on the Week 2 assignments? I got the first question done. Kind of lost with the second assignment.
Just started today - currently looking at the filter() function. And I haven't figured out the test suite yet (so much for TDD...).
I'm scratching my head a bit with this stuff, as it's a long time since I looked at any maths - and it's only week 2! But I get the impression we can build up the required functionality for part 2 using the "atomic" functions we built in part 1, working with a defined set of integers between -1000 and +1000.
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Joe Harry wrote:I can give you a hint! The filter that I have looks more or less like the intersect!
No more Blub for me, thank you, Vicar.
Matthew Brown wrote:My background in maths helps a lot here. I found this set straightforward. Forcing myself to write a full set of tests was the only thing that made my first attempt take longer than 5 minutes...though I then did a bit of polishing.
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Matthew Brown wrote:Well, get forall working first. Once you're happy with that, ask yourself this. If forall returns false, what does that mean? See if you can phrase the answer using the word "exists".
Joe Harry wrote:With the forall I have, it returns false only if the bounds are exceeded!
Matthew Brown wrote:Well, get forall working first. Once you're happy with that, ask yourself this. If forall returns false, what does that mean? See if you can phrase the answer using the word "exists".
Matthew Brown wrote:I can see a flaw in that pseudocode (possibly more than one, but it depends on how you fix the first one). Where are you referring to s?
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Joe Harry wrote:The mistake that I did was I returned false if my bounds exceeded. I now return true if my bounds exceeded. I think I'm done with forall!
Joe Harry wrote:But how could that be possible as forall returns true for all set elements that conform to a given predicate and exists returns true if at least one of the element in the Set conforms to the predicate.
James Boswell wrote:Sorry to change the subject but am I right in thinking the hard deadline for the first assignment is Tuesday 2nd October?
Due Date: Fri 28 Sep 2012 8:00:00 AM BST
Hard Deadline: Tue 2 Oct 2012 8:00:00 AM BST
Matthew Brown wrote:
Joe Harry wrote:The mistake that I did was I returned false if my bounds exceeded. I now return true if my bounds exceeded. I think I'm done with forall!
Yes, that was the other mistake I was thinking about. What should forall return for an empty set?
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
No more Blub for me, thank you, Vicar.
Joe Harry wrote:I got the exists working as well, but I wrote them as different functions. The only difference would be the else if part where I return true if I hit a first match. But this cannot be accommodated in the forall as there I will have to iterate the entire bounds and the else if checks for any failures and returns false if any.
No more Blub for me, thank you, Vicar.
chris webster wrote:Assignment 2 - how was it for you?
I just submitted mine, but it was hard work - not sure if I agree with the "fun" element in the "funsets" project name...
Q1 was OK, but Q2 was hard, and I'm glad we had Matthew here to offer suggestions. The map() function was particularly tricky - I could see the logic easily enough, but I really struggled with the implementation. Of course, once you see the final one-line solution, it looks really simple. 20-20 hindsight as usual!
This is a good course and I'm finding it pretty challenging already (in Week 2), so I hope I'll be able to keep up until Week 7.
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Joe Harry wrote:Did you use the forall method to implement exists? Do you also have an iterator in exists?
No more Blub for me, thank you, Vicar.
chris webster wrote:
Joe Harry wrote:Did you use the forall method to implement exists? Do you also have an iterator in exists?
My forall() method was similar to the pseudo-code you posted earlier i.e. it uses an iterator.
Assuming my version is correct (I passed the assignment, so hopefully it is), then exists() doesn't need an iterator, because you can implement it by calling forall() in the appropriate way.
As you know, forall(s, p) returns "whether all bounded integers within `s` satisfy `p`".
In other words, with our given set of integers, forall() returns true if ALL elements in s pass test p, and it returns false if ANY elements in s do NOT pass test p.
So think about what happens if you play around with with true and false here to give you a function that does what exists() is supposed to do i.e. return true if "there exists a bounded integer within s that satisfies p".
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Joe Harry wrote:Moving on to the map assignment. So my understanding is given a Set (1,2,3,4), the map function should apply the function f: Int => Int to each elements in the set and return the applied Set. So for the given Set (1,2,3,4) and the function f: (x: Int) => x + x, map should return (2,4,6,8). Hope my understanding is correct!
No more Blub for me, thank you, Vicar.