Win a copy of liveProject: Build an ML Recommender System this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

Reactive Programming Course - Week2 Assignment: Calculator

 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I started with the Week2 assignments. I tried to run the WebUI from SBT as below:



I get the following error:



I just tried to then run the



to see what is wrong, but the stack trace provided me with no or little information as to what might have gone wrong!

 
Sheriff
Posts: 4977
319
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are all over these assignments! I haven't even watched the video material yet. Do you have a day job?
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Cooke wrote:You are all over these assignments! I haven't even watched the video material yet. Do you have a day job?



I'm on vacation until end of April. Yes, I did watch the videos today morning!
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tim: Did you by any chance work on the computeValues and eval functions in the Calculator? I'm not able to figure out which edge case is failing. Here is a link to the Coursera post:

https://class.coursera.org/reactive-002/forum/thread?thread_id=270

If in case, you have some idea, please suggest!
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I finally got my edge cases covers for the calculator assignment. It was very very tricky!

I do have to agree that there is very little co-relation to the video lectures for the week and their corresponding assignments.
 
Tim Cooke
Sheriff
Posts: 4977
319
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There does seem to be a little more cohesion between the video content and the assignment this week. Things are starting to sink in a bit now, which is quite exciting!

I'm working on the calculator assignment right now.
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would be tempted to give you a hint for the calculator assignment. Preventing cyclic dependencies is the key to getting it right, the references Map needs to be modified (minus operation) during recursion when evaluating references.
 
Saloon Keeper
Posts: 4387
163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just sent in my solution. That cyclic thing was indeed a nightmare to solve.
I kept having infinite loops, and testing is really hard. Such a scala worksheet
has only a very limited output.

But I did not change the reference map in any way. I made a function
def isCyclic(exp: Expr, references: Map[String, Signal[Expr]] : Boolean = {...}
in which I mapped exp to the expressions it contains, ad infinitum,
taking care of the expressions that I encountered.

Admittedly, I am lucky that there is no StyleChecker, since I used mutable
Sets here.

Actually, for this process, I was looking for a Stream, something like

def makeStream(y: Set[Exp]) : Stream[Exp] = {
y # :: makeStream (y map getExpressionsFromY)
}

and then something like:

val x = makeStream take 100 filter (_ contains(exp))

but as I do not normally work with Scala, I simply lack experience and knowledge.
And, as said, I was too busy eliminating these infinite loops.

Greetz,
Piet
 
Tim Cooke
Sheriff
Posts: 4977
319
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Holy Smokes! That was quite a tough one.

I had everything apparently working in the browser but received a score of 9.40 out of 10 apparently losing 3 points on some failing test. The description of the failing test is somewhat cryptic which doesn't help much:

I guess there's something iffy with my polynomial formula.... Back to the drawing board...

Oh, and Joe: The tip about modifying the map with a minus operation made no sense to me up until about half an hour ago, but now it makes perfect sense. So many thanks for that little nugget of gold.
 
Tim Cooke
Sheriff
Posts: 4977
319
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yessss! 10/10

Minor mishap in the "computeSolutions" function for computing polynomials. All sorted.

Joe, I think you got the balance just right to give a good hint without spoon feeding. Cow worthy! Thanks.
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Piet Souris wrote:Just sent in my solution. That cyclic thing was indeed a nightmare to solve.
I kept having infinite loops, and testing is really hard. Such a scala worksheet
has only a very limited output.

But I did not change the reference map in any way. I made a function
def isCyclic(exp: Expr, references: Map[String, Signal[Expr]] : Boolean = {...}
in which I mapped exp to the expressions it contains, ad infinitum,
taking care of the expressions that I encountered.

Admittedly, I am lucky that there is no StyleChecker, since I used mutable
Sets here.

Actually, for this process, I was looking for a Stream, something like

def makeStream(y: Set[Exp]) : Stream[Exp] = {
y # :: makeStream (y map getExpressionsFromY)
}

and then something like:

val x = makeStream take 100 filter (_ contains(exp))

but as I do not normally work with Scala, I simply lack experience and knowledge.
And, as said, I was too busy eliminating these infinite loops.

Greetz,
Piet



There seems to be only one solution (being immutable), 6 lines for eval, 1 line for computeSolutions. As I mentioned in my post above, when you are pattern matching Ref(...) in your even function, modify the Map (minus) by throwing away the already evaluated reference and pass this new reference back to the eval function for further recursion.
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Cooke wrote:Yessss! 10/10

Minor mishap in the "computeSolutions" function for computing polynomials. All sorted.

Joe, I think you got the balance just right to give a good hint without spoon feeding. Cow worthy! Thanks.



That's great! Even I made some formula mistakes by having wrong parenthesis, which got me confused with the test failures. But I had to admit that getting out of the infinite loop hell in the eval function was tricky!

Thanks for the cow!
 
Piet Souris
Saloon Keeper
Posts: 4387
163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joe Harry wrote:
There seems to be only one solution (being immutable), 6 lines for eval, 1 line for computeSolutions. As I mentioned in my post above, when you are pattern matching Ref(...) in your even function, modify the Map (minus) by throwing away the already evaluated reference and pass this new reference back to the eval function for further recursion.


Well, I got 10/10, so there seems to be more than one way.
What I did boils down to mapping an expression to the expressions (as a set)
contained within in, throwing out all literals, in a for-comprehension, until either
the resulting set becomes empty or contains the original expression. The nice
thing here was that I used a flatmap in this process, something I can't remember
ever having done on my own. It lead me to thinking about using a Stream for
this, with a Filter, but that remains for the future.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic