Blog Archive

so, a big part of why I have qbasic on my computer is that I can use it ot solve simple np complete problems, like this one:


By the way, this comic is from xkcd.com. I suspect that if we know each other in real life, you'd enjoy the comic. The rest of you? I bet you'll enjoy it too.
here's the code:

CLS
ms=4.2
mf=2.15
ff=2.75
ss=3.35
hw=3.55
fs=5.8
d=0

FOR u = 0 to 7
FOR v = 0 to 7
FOR w = 0 to 7
FOR x = 0 to 7
FOR y = 0 to 7
FOR z = 0 to 7

price = z * fs + y * hw + x * ss + w * ff + v * mf + u * ms

IF price = 15.05 THEN PRINT u; v; w; x; y; z
d = d+1

NEXT z
NEXT y
NEXT x
NEXT w
NEXT v
NEXT u

PRINT d
END

So the expected output is:
0 1 0 0 2 1
0 7 0 0 0 0
262114

meaning that the two solutions are
1 mf, 2 hw, and 1 fs
and
7 mf

the actual output is
0 1 0 0 2 1
262114

I've fiddled with the program and I had it display price after each individual set of numbers... the output at 0 7 0 0 0 0?
0 7 0 0 0 0 15.05
The program should identify that as a win. No idea why it isn't.
I want to scream. And learn a new language. And get a different computer.

Edit 11:00 AM 7/10/2007
The talented and lovely told me what I did wrong and how to fix it. Had a floating point error. QB apparently dislikes decimals. So I multiplied everything by 100 and everything worked. *headdesk*

It is also possible that qb dislikes 7. I seem to remember that being a problem years ago for something or another.

No comments: