[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[QUIZ] Micrrowave Numbers (#118

James Gray

3/30/2007 11:56:00 AM

The three rules of Ruby Quiz:

1. Please do not post any solutions or spoiler discussion for this quiz until
48 hours have passed from the time on this message.

2. Support Ruby Quiz by submitting ideas as often as you can:

http://www.rub...

3. Enjoy!

Suggestion: A [QUIZ] in the subject of emails about the problem helps everyone
on Ruby Talk follow the discussion. Please reply to the original quiz message,
if you can.

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

by Matthew Moss

Microwave ovens have had a significant impact on how we cook today. One report
from 1997 indicated that 90% of US households owned one. Assuming the promise of
faster cooking times, that's a lot of time saved.

But I imagine there are microwave users out there who know the trick to saving
even more time. Knowing that many microwave ovens recognize 90 seconds as the
same as 1 minute 30 seconds, finger-travel distance is saved. (Yes, it's rather
insignificant, but don't tell them... us... whatever.)

Your task is to write a function in Ruby that determines the optimal pattern of
buttons to hit based on this example button pad (where * is "Cook"):

+---+---+---+
| 1 | 2 | 3 |
+---+---+---+
| 4 | 5 | 6 |
+---+---+---+
| 7 | 8 | 9 |
+---+---+---+
| 0 | * |
+---+---+

Your function should accept an integral time value representing desired seconds
and should output an integer that indicates the buttons to press on the
microwave's input pad. The metric for determining what input is more efficient
is distance (not number of buttons hit). Distance to the Cook button must be
included in your efficiency calculation. For simplicity in distance
calculations, you may consider the shape of each button to be square.

Examples:

# 99 seconds is 1:39, but 99 is less movement than 139
microwave(99) => 99

# 71 seconds is only two keys, but entering 111 is far less movement.
microwave(71) => 111

# 120 seconds is 2 minutes, and 200 is slightly less movement than 120
microwave(120) => 200

# 123 seconds is 2:03, but 203 is a lot more distance
microwave(123) => 123

Once you've done the basic version, try modifying your code enough to handle
these:

1. We often don't care to be exact. 99 seconds, for example, is basically the
same as 95 seconds, but more efficient to enter. Modify your function to accept
a tolerance in seconds, and return answers that are within that tolerance of the
desired time. Try +-5 and +-10 seconds.

2. Try changing the efficiency metric, to something like number of buttons
pressed, or Manhattan distance.

3. Try changing the button dimensions... For example, what happens if each
button is twice as wide as it is high?

14 Answers

Karl von Laudermann

3/30/2007 2:09:00 PM

0

On Mar 30, 7:55 am, Ruby Quiz <j...@grayproductions.net> wrote:

> # 99 seconds is 1:39, but 99 is less movement than 139
> microwave(99) => 99
>
> # 71 seconds is only two keys, but entering 111 is far less movement.
> microwave(71) => 111
>
> # 120 seconds is 2 minutes, and 200 is slightly less movement than 120
> microwave(120) => 200
>
> # 123 seconds is 2:03, but 203 is a lot more distance
> microwave(123) => 123

Unless I'm missing something (and I usually am), the problem with the
last two examples is that the microwave will interpret "120" and "123"
as 1:20 and 1:23 when typed in, not as a raw number of seconds. How
the microwave interprets the number depends solely on whether the last
two digits exceed 59. If they do, it's a number of seconds, otherwise
it's minutes and seconds.

Maybe there should be an additional requirement of the quiz: the
program will never suggest the number of seconds representation, even
when that's more efficient than the minutes and seconds
representation, if the the number of seconds representation will be
misinterpreted (i.e. the last two digits are 60 or greater).

Actually, I'm not even convinced that a microwave would interpret e.g.
"170" as 170 seconds, or 2:50. Perhaps 170 would be interpreted as one
minute and 70 seconds? In other words, after counting down for 70
seconds, the display would read "1:00", and then proceed to 59 instead
of 99, not remembering the 70 that it started with.

Karl von Laudermann

3/30/2007 2:14:00 PM

0

On Mar 30, 10:08 am, "Karl von Laudermann" <doodpa...@mailinator.com>
wrote:

> misinterpreted (i.e. the last two digits are 60 or greater).

Clearly, I meant "the last two digits *aren't* 60 or greater".

James Gray

3/30/2007 2:19:00 PM

0

On Mar 30, 2007, at 9:10 AM, Karl von Laudermann wrote:

> Actually, I'm not even convinced that a microwave would interpret e.g.
> "170" as 170 seconds, or 2:50. Perhaps 170 would be interpreted as one
> minute and 70 seconds? In other words, after counting down for 70
> seconds, the display would read "1:00", and then proceed to 59 instead
> of 99, not remembering the 70 that it started with.

Yes, I just tested mine and this is how it behaved (1 minute and 70
seconds).

James Edward Gray II

Hans Fugal

3/30/2007 3:46:00 PM

0

My microwave will win in every case. It has a dial timer.

Ruby Quiz wrote:
> The three rules of Ruby Quiz:
>
> 1. Please do not post any solutions or spoiler discussion for this quiz until
> 48 hours have passed from the time on this message.
>
> 2. Support Ruby Quiz by submitting ideas as often as you can:
>
> http://www.rub...
>
> 3. Enjoy!
>
> Suggestion: A [QUIZ] in the subject of emails about the problem helps everyone
> on Ruby Talk follow the discussion. Please reply to the original quiz message,
> if you can.
>
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
>
> by Matthew Moss
>
> Microwave ovens have had a significant impact on how we cook today. One report
> from 1997 indicated that 90% of US households owned one. Assuming the promise of
> faster cooking times, that's a lot of time saved.
>
> But I imagine there are microwave users out there who know the trick to saving
> even more time. Knowing that many microwave ovens recognize 90 seconds as the
> same as 1 minute 30 seconds, finger-travel distance is saved. (Yes, it's rather
> insignificant, but don't tell them... us... whatever.)
>
> Your task is to write a function in Ruby that determines the optimal pattern of
> buttons to hit based on this example button pad (where * is "Cook"):
>
> +---+---+---+
> | 1 | 2 | 3 |
> +---+---+---+
> | 4 | 5 | 6 |
> +---+---+---+
> | 7 | 8 | 9 |
> +---+---+---+
> | 0 | * |
> +---+---+
>
> Your function should accept an integral time value representing desired seconds
> and should output an integer that indicates the buttons to press on the
> microwave's input pad. The metric for determining what input is more efficient
> is distance (not number of buttons hit). Distance to the Cook button must be
> included in your efficiency calculation. For simplicity in distance
> calculations, you may consider the shape of each button to be square.
>
> Examples:
>
> # 99 seconds is 1:39, but 99 is less movement than 139
> microwave(99) => 99
>
> # 71 seconds is only two keys, but entering 111 is far less movement.
> microwave(71) => 111
>
> # 120 seconds is 2 minutes, and 200 is slightly less movement than 120
> microwave(120) => 200
>
> # 123 seconds is 2:03, but 203 is a lot more distance
> microwave(123) => 123
>
> Once you've done the basic version, try modifying your code enough to handle
> these:
>
> 1. We often don't care to be exact. 99 seconds, for example, is basically the
> same as 95 seconds, but more efficient to enter. Modify your function to accept
> a tolerance in seconds, and return answers that are within that tolerance of the
> desired time. Try +-5 and +-10 seconds.
>
> 2. Try changing the efficiency metric, to something like number of buttons
> pressed, or Manhattan distance.
>
> 3. Try changing the button dimensions... For example, what happens if each
> button is twice as wide as it is high?
>

Ken Bloom

3/30/2007 6:38:00 PM

0

On Fri, 30 Mar 2007 20:55:46 +0900, Ruby Quiz wrote:

> The three rules of Ruby Quiz:
>
> 1. Please do not post any solutions or spoiler discussion for this quiz
> until 48 hours have passed from the time on this message.
>
> 2. Support Ruby Quiz by submitting ideas as often as you can:
>
> http://www.rub...
>
> 3. Enjoy!
>
> Suggestion: A [QUIZ] in the subject of emails about the problem helps
> everyone on Ruby Talk follow the discussion. Please reply to the
> original quiz message, if you can.
>
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
=-=-=-=-=
>
> by Matthew Moss
>
> Microwave ovens have had a significant impact on how we cook today. One
> report from 1997 indicated that 90% of US households owned one. Assuming
> the promise of faster cooking times, that's a lot of time saved.
>
> But I imagine there are microwave users out there who know the trick to
> saving even more time. Knowing that many microwave ovens recognize 90
> seconds as the same as 1 minute 30 seconds, finger-travel distance is
> saved. (Yes, it's rather insignificant, but don't tell them... us...
> whatever.)
>
> Your task is to write a function in Ruby that determines the optimal
> pattern of buttons to hit based on this example button pad (where * is
> "Cook"):
>
> +---+---+---+
> | 1 | 2 | 3 |
> +---+---+---+
> | 4 | 5 | 6 |
> +---+---+---+
> | 7 | 8 | 9 |
> +---+---+---+
> | 0 | * |
> +---+---+
>
> Your function should accept an integral time value representing desired
> seconds and should output an integer that indicates the buttons to press
> on the microwave's input pad. The metric for determining what input is
> more efficient is distance (not number of buttons hit). Distance to the
> Cook button must be included in your efficiency calculation. For
> simplicity in distance calculations, you may consider the shape of each
> button to be square.
>
> Examples:
>
> # 99 seconds is 1:39, but 99 is less movement than 139 microwave
(99) =>
> 99
>
> # 71 seconds is only two keys, but entering 111 is far less
movement.
> microwave(71) => 111
>
> # 120 seconds is 2 minutes, and 200 is slightly less movement
than 120
> microwave(120) => 200
>
> # 123 seconds is 2:03, but 203 is a lot more distance microwave
(123) =>
> 123
>
> Once you've done the basic version, try modifying your code enough to
> handle these:
>
> 1. We often don't care to be exact. 99 seconds, for example, is
> basically the same as 95 seconds, but more efficient to enter. Modify
> your function to accept a tolerance in seconds, and return answers that
> are within that tolerance of the desired time. Try +-5 and +-10 seconds.
>
> 2. Try changing the efficiency metric, to something like number of
> buttons pressed, or Manhattan distance.
>
> 3. Try changing the button dimensions... For example, what happens if
> each button is twice as wide as it is high?

Someone want to verify my answers?

For euclidian distance:
0 (0:00): 0*
1 (0:01): 1*
2 (0:02): 2*
3 (0:03): 3*
4 (0:04): 4*
5 (0:05): 5*
6 (0:06): 6*
7 (0:07): 7*
8 (0:08): 8*
9 (0:09): 9*
10 (0:10): 10*
11 (0:11): 11*
12 (0:12): 12*
13 (0:13): 13*
14 (0:14): 14*
15 (0:15): 15*
16 (0:16): 16*
17 (0:17): 17*
18 (0:18): 18*
19 (0:19): 19*
20 (0:20): 20*
21 (0:21): 21*
22 (0:22): 22*
23 (0:23): 23*
24 (0:24): 24*
25 (0:25): 25*
26 (0:26): 26*
27 (0:27): 27*
28 (0:28): 28*
29 (0:29): 29*
30 (0:30): 30*
31 (0:31): 31*
32 (0:32): 32*
33 (0:33): 33*
34 (0:34): 34*
35 (0:35): 35*
36 (0:36): 36*
37 (0:37): 37*
38 (0:38): 38*
39 (0:39): 39*
40 (0:40): 40*
41 (0:41): 41*
42 (0:42): 42*
43 (0:43): 43*
44 (0:44): 44*
45 (0:45): 45*
46 (0:46): 46*
47 (0:47): 47*
48 (0:48): 48*
49 (0:49): 49*
50 (0:50): 50*
51 (0:51): 51*
52 (0:52): 52*
53 (0:53): 53*
54 (0:54): 54*
55 (0:55): 55*
56 (0:56): 56*
57 (0:57): 57*
58 (0:58): 58*
59 (0:59): 59*
60 (1:00): 60*
61 (1:01): 61*
62 (1:02): 62*
63 (1:03): 63*
64 (1:04): 64*
65 (1:05): 65*
66 (1:06): 66*
67 (1:07): 67*
68 (1:08): 68*
69 (1:09): 69*
70 (1:10): 70*
71 (1:11): 111*
72 (1:12): 112*
73 (1:13): 113*
74 (1:14): 114*
75 (1:15): 115*
76 (1:16): 116*
77 (1:17): 77*
78 (1:18): 78*
79 (1:19): 79*
80 (1:20): 80*
81 (1:21): 121*
82 (1:22): 122*
83 (1:23): 123*
84 (1:24): 84*
85 (1:25): 85*
86 (1:26): 86*
87 (1:27): 87*
88 (1:28): 88*
89 (1:29): 89*
90 (1:30): 90*
91 (1:31): 91*
92 (1:32): 92*
93 (1:33): 133*
94 (1:34): 94*
95 (1:35): 95*
96 (1:36): 96*
97 (1:37): 97*
98 (1:38): 98*
99 (1:39): 99*

For Manhattan Distance:
0 (0:00): 0*
1 (0:01): 1*
2 (0:02): 2*
3 (0:03): 3*
4 (0:04): 4*
5 (0:05): 5*
6 (0:06): 6*
7 (0:07): 7*
8 (0:08): 8*
9 (0:09): 9*
10 (0:10): 10*
11 (0:11): 11*
12 (0:12): 12*
13 (0:13): 13*
14 (0:14): 14*
15 (0:15): 15*
16 (0:16): 16*
17 (0:17): 17*
18 (0:18): 18*
19 (0:19): 19*
20 (0:20): 20*
21 (0:21): 21*
22 (0:22): 22*
23 (0:23): 23*
24 (0:24): 24*
25 (0:25): 25*
26 (0:26): 26*
27 (0:27): 27*
28 (0:28): 28*
29 (0:29): 29*
30 (0:30): 30*
31 (0:31): 31*
32 (0:32): 32*
33 (0:33): 33*
34 (0:34): 34*
35 (0:35): 35*
36 (0:36): 36*
37 (0:37): 37*
38 (0:38): 38*
39 (0:39): 39*
40 (0:40): 40*
41 (0:41): 41*
42 (0:42): 42*
43 (0:43): 43*
44 (0:44): 44*
45 (0:45): 45*
46 (0:46): 46*
47 (0:47): 47*
48 (0:48): 48*
49 (0:49): 49*
50 (0:50): 50*
51 (0:51): 51*
52 (0:52): 52*
53 (0:53): 53*
54 (0:54): 54*
55 (0:55): 55*
56 (0:56): 56*
57 (0:57): 57*
58 (0:58): 58*
59 (0:59): 59*
60 (1:00): 60*
61 (1:01): 61*
62 (1:02): 62*
63 (1:03): 63*
64 (1:04): 64*
65 (1:05): 65*
66 (1:06): 66*
67 (1:07): 67*
68 (1:08): 68*
69 (1:09): 69*
70 (1:10): 70*
71 (1:11): 111*
72 (1:12): 112*
73 (1:13): 113*
74 (1:14): 114*
75 (1:15): 115*
76 (1:16): 116*
77 (1:17): 77*
78 (1:18): 78*
79 (1:19): 79*
80 (1:20): 80*
81 (1:21): 121*
82 (1:22): 122*
83 (1:23): 123*
84 (1:24): 84*
85 (1:25): 85*
86 (1:26): 86*
87 (1:27): 87*
88 (1:28): 88*
89 (1:29): 89*
90 (1:30): 90*
91 (1:31): 131*
92 (1:32): 132*
93 (1:33): 133*
94 (1:34): 94*
95 (1:35): 95*
96 (1:36): 96*
97 (1:37): 97*
98 (1:38): 98*
99 (1:39): 99*


--
Ken Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu...

Josef 'Jupp' Schugt

3/31/2007 1:21:00 AM

0

* Hans Fugal, 30.03.2007 17:50:
> My microwave will win in every case. It has a dial timer.

If it wins or not is not decided. Mine has a dial timer as well. As a
shootout we would have to compare degrees per minute :-)

Besides: I wonder why microwave ovens don't simply have an up and a
dow button (like those present on most mobile phones) to
increment/decrement the time setting(s).

A dial timer is quite imprecise (especially for short time intervals)
for mechanical reasons while a numerical pad is unnecessarily
complicated meaning that it has many parts that may fail. They won't
fail? Hmm, perhaps you compare it to your PC keyboard, but: In most
households the s/p probability density peaks near the microwave, and
not near the keyboard.

s/p: softdrink/pizza

Josef 'Jupp' Schugt, eagerly awaiting tomorrow's RFC :-)
--
Blog available at http://www.mynetcologne.de/~nc-schu...
PGP key with id 6CC6574F available at http://wwwkeys.d...

Bill Kelly

3/31/2007 1:34:00 AM

0

From: "Josef 'Jupp' Schugt" <jupp@gmx.de>
>
> Besides: I wonder why microwave ovens don't simply have an up and a
> dow button (like those present on most mobile phones) to
> increment/decrement the time setting(s).

Ours does. It has an "add a minute" button, but also +/- 10 seconds
buttons. (They can be used before or after pressing the "Start"
button.)

Semi-interestingly, the "add a minute" button includes an implicit
"Start" button press. :)

So I almost invariably choose "add a minute; add a minute" over
"2 0 0 <start>".

LOL


Regards,

Bill






Christian Neukirchen

3/31/2007 10:38:00 AM

0

Ken Bloom <kbloom@gmail.com> writes:

> 74 (1:14): 114*
> 75 (1:15): 115*
> 76 (1:16): 116*

I think 74* is faster, because it's one keypress less?

--
Christian Neukirchen <chneukirchen@gmail.com> http://chneuk...

Rick DeNatale

3/31/2007 4:07:00 PM

0

On 3/30/07, Josef 'Jupp' Schugt <jupp@gmx.de> wrote:
> * Hans Fugal, 30.03.2007 17:50:
> > My microwave will win in every case. It has a dial timer.
>
> If it wins or not is not decided. Mine has a dial timer as well. As a
> shootout we would have to compare degrees per minute :-)
>
> Besides: I wonder why microwave ovens don't simply have an up and a
> dow button (like those present on most mobile phones) to
> increment/decrement the time setting(s).
>
> A dial timer is quite imprecise (especially for short time intervals)
> for mechanical reasons while a numerical pad is unnecessarily
> complicated meaning that it has many parts that may fail. They won't
> fail? Hmm, perhaps you compare it to your PC keyboard, but: In most
> households the s/p probability density peaks near the microwave, and
> not near the keyboard.

Well our MW has a digital timer with a dial input. The dial works
like the dreaded BMW iDrive control, you can turn it AND push it.

To set the timer you hit the timer or cook time button, then twist the
dial to set the minutes which show up on the digital display. You
then push the dial in which shifts it to setting the seconds, a second
push on the dial completes the process.

And no, you can't enter seconds greater than 59 with this setup.


--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denh...

Robert Dober

3/31/2007 4:15:00 PM

0

On 3/31/07, Rick DeNatale <rick.denatale@gmail.com> wrote:
> On 3/30/07, Josef 'Jupp' Schugt <jupp@gmx.de> wrote:
> > * Hans Fugal, 30.03.2007 17:50:
> > > My microwave will win in every case. It has a dial timer.
> >
> > If it wins or not is not decided. Mine has a dial timer as well. As a
> > shootout we would have to compare degrees per minute :-)
> >
> > Besides: I wonder why microwave ovens don't simply have an up and a
> > dow button (like those present on most mobile phones) to
> > increment/decrement the time setting(s).
> >
> > A dial timer is quite imprecise (especially for short time intervals)
> > for mechanical reasons while a numerical pad is unnecessarily
> > complicated meaning that it has many parts that may fail. They won't
> > fail? Hmm, perhaps you compare it to your PC keyboard, but: In most
> > households the s/p probability density peaks near the microwave, and
> > not near the keyboard.
>
> Well our MW has a digital timer with a dial input. The dial works
> like the dreaded BMW iDrive control, you can turn it AND push it.
>
> To set the timer you hit the timer or cook time button, then twist the
> dial to set the minutes which show up on the digital display. You
> then push the dial in which shifts it to setting the seconds, a second
> push on the dial completes the process.
>
> And no, you can't enter seconds greater than 59 with this setup.
>
>
> --
> Rick DeNatale
>
> My blog on Ruby
> http://talklikeaduck.denh...
>
>
Wait I second guys my MW has a Ruby interpreter ;) [1.6 though, Matz
did you abandon the Microwave edition?]

Robert

--
You see things; and you say Why?
But I dream things that never were; and I say Why not?
-- George Bernard Shaw