• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Scala Coursera Week 7

 
chris webster
Bartender
Posts: 2407
33
Linux Oracle Postgres Database Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Materials not yet online - there's a warning of possible disruption due to the hurricane as the servers are in the USA.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34965
377
Eclipse IDE Java VI Editor
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a case study. Would that be the assignment for this week?
 
chris webster
Bartender
Posts: 2407
33
Linux Oracle Postgres Database Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joe Harry wrote:There is a case study. Would that be the assignment for this week?

Not as far as I can tell. The case study is a detailed look at implementing a solution for the so-called "Water pouring problem" using lazy evaluation, Streams etc.

There is a forum for the Week 7 assignment, but no sign of the assignment yet. I'm guessing it's going to be tough, though!
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chris webster wrote:
Joe Harry wrote:There is a case study. Would that be the assignment for this week?

Not as far as I can tell. The case study is a detailed look at implementing a solution for the so-called "Water pouring problem" using lazy evaluation, Streams etc.

There is a forum for the Week 7 assignment, but no sign of the assignment yet. I'm guessing it's going to be tough, though!


Week7 will be about Streams!
 
chris webster
Bartender
Posts: 2407
33
Linux Oracle Postgres Database Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joe Harry wrote:Week7 will be about Streams!

Have you looked at the assignment?
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chris webster wrote:Have you looked at the assignment?

Looks fun. Might have to wait till the weekend to have a proper crack at it, though.
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chris webster wrote:
Joe Harry wrote:Week7 will be about Streams!

Have you looked at the assignment?


Tomorrow I've got to get the combinations working correctly and after than I will take a look at Week7. We have time till 15th Nov for Week7 assignments.
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just took a look at the assignments for Week7. I definitely need some more hints. To start with: What is the terrainFunction doing? Could you guys give me additional explanation?
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joe Harry wrote:What is the terrainFunction doing? Could you guys give me additional explanation?


terrain, declared in GameDef, should be a function that returns true if you're within the terrain, and false otherwise.

StringParserTerrain lets you define this terrain by giving a String in a particular form. This is parsed into a Vector of Vectors of Chars, and then terrainFunction takes this and returns a function that can be used for terrain.
 
chris webster
Bartender
Posts: 2407
33
Linux Oracle Postgres Database Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, how's everybody doing with the Week 7 assignment? I'm just starting to look at the "from()" function and right now I can't make head() or tail() of it - I don't really understand what the input data actually represents. I think I need to review the "Water pouring" video to get some ideas.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Finished it a couple of days ago (currently working on my Compilers course assignment).

I found it relatively straightforward until I hit from(). I tried a few approaches there that didn't work (though I suspect that some of them would if I'd got it right). But I tried it before watching the water pouring video. I found that to be a huge help - the from() method in that solution works in a very similar way.
 
chris webster
Bartender
Posts: 2407
33
Linux Oracle Postgres Database Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew Brown wrote:Finished it a couple of days ago (currently working on my Compilers course assignment).

I found it relatively straightforward until I hit from(). I tried a few approaches there that didn't work (though I suspect that some of them would if I'd got it right). But I tried it before watching the water pouring video. I found that to be a huge help - the from() method in that solution works in a very similar way.

Excellent advice. I just finished, and the "water pouring" video was definitely the key to getting from() working (first time!).

Good luck with Compilers - I'm having a break from Coursera now to catch up with my OU course and Python. But I'll be back...
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34965
377
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it. I made "from" so much more complicated than it needed to be the first time around! It was an interesting meandering journey though!
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't looked at the assignment fully other that the first part. It was last Friday I had a look at them and only solved the first two tasks. I just gave me some time to relax as the deadline for this assignment is the 15th of this month. I will take a look at them tomorrow. Hope they are not as difficult as it was for Week6.
 
chris webster
Bartender
Posts: 2407
33
Linux Oracle Postgres Database Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joe Harry wrote:I haven't looked at the assignment fully other that the first part. It was last Friday I had a look at them and only solved the first two tasks. I just gave me some time to relax as the deadline for this assignment is the 15th of this month. I will take a look at them tomorrow. Hope they are not as difficult as it was for Week6.

If you pay close attention to the hints in the assignment and source code, then it's not too bad. The "from()" method is a bit more difficult, but the water-pouring example is very helpful there. I found one of the biggest challenges on this assignment was making sense of the data structures we're given, and I definitely wouldn't have come up with this solution (or probably any solution) to the problem on my own. I still have plenty to learn about FP and Scala!
 
chris webster
Bartender
Posts: 2407
33
Linux Oracle Postgres Database Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:I made "from" so much more complicated than it needed to be the first time around! It was an interesting meandering journey though!

That pretty much sums up my experience of the entire course!
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chris webster wrote:
Joe Harry wrote:I haven't looked at the assignment fully other that the first part. It was last Friday I had a look at them and only solved the first two tasks. I just gave me some time to relax as the deadline for this assignment is the 15th of this month. I will take a look at them tomorrow. Hope they are not as difficult as it was for Week6.

If you pay close attention to the hints in the assignment and source code, then it's not too bad. The "from()" method is a bit more difficult, but the water-pouring example is very helpful there. I found one of the biggest challenges on this assignment was making sense of the data structures we're given, and I definitely wouldn't have come up with this solution (or probably any solution) to the problem on my own. I still have plenty to learn about FP and Scala!


That was something even I was thinking about. How would I have implemented the complete Game as an assignment. I would have done it, but it wouldn't be as concise as it is given out in the course.

Thanks for the hints. I will spend some time tomorrow evening and get this thing done hopefully. But you guys are here in case I need some help!
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34965
377
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chris webster wrote:and I definitely wouldn't have come up with this solution (or probably any solution) to the problem on my own. I still have plenty to learn about FP and Scala!

Same here. It's like in any language that if someone spells out what to do, it isn't horribly difficult. But coming up with that design and decomposition requires more knowledge/experience.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15480
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew Brown wrote:I found it relatively straightforward until I hit from().

Me too. I've been busy with other things so I haven't had the time and concentrate on the from() method yet. I'm going to have a look at it this weekend.
 
Wen Tong Lin
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Guys. I was wondering if you can point me to the right direction with from() method. My solution is doing an infinite loop.

The flow is:
1) if "initial" is empty return Empty stream.
2) do a for comprehension with 2 generators.
a) generate from "initial" assigning it to x.
b) use x._1 and x._2 as parameter of neighborsWithHistory
c) use the value returned by b) as the first parameter of newNeighborsOnly, and second parameter is explored + h._1
d) assign c) to next, and yield it to a val more.
e) then return initial #:: from( more, explored) recursively

Any help will be greatly appreciated.

 
chris webster
Bartender
Posts: 2407
33
Linux Oracle Postgres Database Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wen Tong Lin wrote:hi Guys. I was wondering if you can point me to the right direction with from() method. My solution is doing an infinite loop.

The flow is:
1) if "initial" is empty return Empty stream.
2) do a for comprehension with 2 generators.
a) generate from "initial" assigning it to x.
b) use x._1 and x._2 as parameter of neighborsWithHistory
c) use the value returned by b) as the first parameter of newNeighborsOnly, and second parameter is explored + h._1
d) assign c) to next, and yield it to a val more.
e) then return initial #:: from( more, explored) recursively

Any help will be greatly appreciated.


I took the from() method in the "water pouring" exercise and used the same approach here. It looks like you're doing something very similar, but you may need to pay attention to exactly when/how you concatenate things onto your "initial" stream or onto the "explored" set.
HTH
 
Wen Tong Lin
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Chris. I revised it, and it still does not pass the test case. I think the idea is, you get the initial.head and use newNeighborsOnly() and neighborsWithHistory() with "explored" to generate the possible paths. Then return
h #:: from(initial.tail #::: more, explored + h._1 ) recursively. am I missing something? I can't seem to hit the goal ( Pos(4,7) ). My pathsFromStart does not include the goal. I'll keep pondering. I know im very close to solving this.
 
Wen Tong Lin
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, guys. in terrainFunction() is 'S' and 'T' considered valid? meaning it should return true?
 
Wen Tong Lin
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys. I got it now. My from() was right, after I got the tip from Chris (thank you Chris), and my problem was with terrainFunction() and neighborsWithHistory.
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I managed to complete the assignments. It was not so difficult as it was for Week6. Now the challenge is to keep up the gained knowledge and practice this daily. I do not work on Scala as part of my everyday job. I need to start using it in my private projects during my spare time.

Overall the course was really refreshing and I feel that I had leart Scala the proper way.
 
Wen Tong Lin
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't finish 2 assignments (Huffman and Anagram), but I learned a lot from this course. I am thinking of studying clojure or haskell though, to fully submerge myself with functional style. My mindset is still imperative. I agree that this course was really refreshing, and takes you out of your comfort zone (imperative OOD)
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15480
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm almost there with Bloxorz, but working with these potentially infinitely long streams feels scary sometimes. In my mind I see the block rolling off into infinity...

My solution almost works, but I think I've got something wrong with the order of the elements in the result of from() - it finds a solution, but not the shortest path.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15480
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Finally, done!! Scored 10 out of 10.
 
M Mistroni
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
i am stumbling across this few years later as part of another Coursera Scala course
i followed advices here as well as looking throuhg the Water Pouring problem, but somehow my code is spinning out of control as it seems to never end
Ideally, the from method should end when there are no more neighbours , correct?

So presumably the block representing Block(goal, goal) shold return no neighbours.... is that correct?

thanks in advance and regards
marco
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic