I have some of val
that should randomly coming to list of result. Here's the code:
def motivation(name:String, score:Int){
val quote1 = "You're not lost. You're locationally challenged." //score=10
val quote2 = "Time is the most valuable thing a man can spend." //score=20
val quote3 = "At times one remains faithful to a cause." //score=10
val quote4 = "Only because its opponents do not cease to be insipid." //score=10
val quote5 = "Life can be complicated." //score=20
case Some(score) => val quoteRes = shufle(????)
}
- How do I marked score of each quotes so it will be able to calculated.
- How do I randomly pick the quotes based of
score
of name and do theshuffle
the order also?
for example if John(name) has 40(score) the result could be quotes2+quotes3+quotes4 or quotes4+quotes5 or quotes1+quotes2+quotes5
I guess I'd be likely to start with all the quotes and their respective scores.
Then combine them in as many ways as possible.
Turn that into a
Map
keyed by their respective score sums.Now you call look up all the quotes that, when combined, sum to a given amount.
As for presenting the results in a random order, since you've already asked about that twice already, and gotten good answers, I'll assume that's not going to be a problem.