Petals Around the Rose

Anyone heard of this famous riddle?

Does anyone have the code written out for it for java or have any suggestions for writing a program that rolls 5 dice at random and then asks the user to input a guess based on the numbers to try and solve the pattern seen......

NOTE: If you have no idea what this riddle is, see

http://crux.baker.edu/cdavis09/roses.html)

[391 byte] By [BrownManUPSa] at [2007-10-1 0:52:43]
# 1
Also a method to roll and a method to ask might be a good idea to solving this problem.
BrownManUPSa at 2007-7-8 1:08:07 > top of Java-index,Security,Event Handling...
# 2
For "random" numbers, use java.util.Random.For (simple) input and output, see System.out and System.in.~Cheers
Adeodatusa at 2007-7-8 1:08:07 > top of Java-index,Security,Event Handling...
# 3
Other than that, the phrase "Do your own homework" comes to mind.
warnerjaa at 2007-7-8 1:08:07 > top of Java-index,Security,Event Handling...
# 4
haha its not my homework i already did that....I was just wondering on how to write it becuase I'd like to stay ahead of the curve and plus its pretty cool riddle
BrownManUPSa at 2007-7-8 1:08:07 > top of Java-index,Security,Event Handling...
# 5
cool... test how fast we learning some stuff.
tyranta at 2007-7-8 1:08:07 > top of Java-index,Security,Event Handling...
# 6
What's the answer/soluction?
hiwaa at 2007-7-8 1:08:07 > top of Java-index,Security,Event Handling...
# 7

i can not say it directly to you. i answer you in code ;)

public int getAnswer(int[] dices) {

int petals = 0;

for (int i = 0; i < dices.length; i++) {

if (dices[i] == 3 || dices[i] == 5) petals += (dices[i] - 1);

}

}

the solution is very simple. you must figure out what means

petals around the rose

petals around the rose

petals around the rose

tyranta at 2007-7-8 1:08:07 > top of Java-index,Security,Event Handling...
# 8
oops.. forgotreturn petals;
tyranta at 2007-7-8 1:08:07 > top of Java-index,Security,Event Handling...
# 9

> What's the answer/soluction?

int solve(int[] dies) {

int result = 0;

for (int i = 0; i < dies.length; i++) {

if (dies[i] == 3) result += 2;

if (dies[i] == 5) result += 4;

}

return result;

}

vaskola at 2007-7-8 1:08:07 > top of Java-index,Security,Event Handling...
# 10

<quote>

public int getAnswer(int[] dices) {

int petals = 0;

for (int i = 0; i < dices.length; i++) {

if (dices[i] == 3 || dices[i] == 5) petals += (dices[i] - 1);

}

}

int solve(int[] dies) {

int result = 0;

for (int i = 0; i < dies.length; i++) {

if (dies[i] == 3) result += 2;

if (dies[i] == 5) result += 4;

}

return result;

}

</quote>

Still, I don't understand.

Wha's the sense of all that?

hiwaa at 2007-7-8 1:08:07 > top of Java-index,Security,Event Handling...
# 11
Just flashed.1 ... only a core, no petals2 ... no core, no flower3 ... a core and two petals4 ... no core, no flower5 ... a core and four petals6 ... no core, no flower
hiwaa at 2007-7-8 1:08:07 > top of Java-index,Security,Event Handling...
# 12
Bravo. Now quick and get this post buried before anyone sees.*angry eyes*
Adeodatusa at 2007-7-8 1:08:07 > top of Java-index,Security,Event Handling...
# 13

revision:

public int getAnswer(int[] dices) {

int petals = 0;

for (int i = 0; i < dices.length; i++) {

if (dices[i] % 2 != 0) petals += (dices[i] - 1); // only odd number pattern is a rose...

}

return petals

}

tyranta at 2007-7-8 1:08:07 > top of Java-index,Security,Event Handling...
# 14

I finally figured it out; and no, I didn't cheat; after I read the OPs question there

were no replies yet. It took me about two hours to figure it out; I feel stupid ;-)

I started off with a bunch of linear equations: to no avail. Then I used CPLEX

on a bunch of examples I found on the net with a piecewise linear cost function:

no avail either. The I used a transformation trying to map the words 'petals

around the rose' and tried my first two methods again: nothing.

When I was near giving up, I saw the light. And now I'm in the knowing too

(finally!), I promise not to tell anyone else about it ;-)

kind regards,

Jos

JosAHa at 2007-7-8 1:08:07 > top of Java-index,Security,Event Handling...
# 15

> I finally figured it out; and no, I didn't cheat;

> after I read the OPs question there

> were no replies yet. It took me about two hours to

> figure it out; I feel stupid ;-)

no need to feel stupid, i asked google fot solution, but it didn't direct me directly to one, so i had to read what it found, and on one page it was mentioned, that the smarter you are, the more complex that problem is to you.

but fortunatelly i fond some page where they said "pay attention to the name of problem: pedals around the rose"

... and the rest is history.

vaskola at 2007-7-20 1:55:20 > top of Java-index,Security,Event Handling...