Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Steve's Programming Challenge: Weights and Measures
#21
(08-16-2024, 03:18 AM)SMcNeill Wrote:
(08-16-2024, 02:17 AM)TerryRitchie Wrote: Well hell Steve, your example of 1/3rd in decimal made the light bulb finally go off in my head concerning this issue. It was as simple as relating the issue to a decimal equivalent. Heck, it's so simple now. You missed your calling as a teacher methinks.

I've always loved when that light bulb tics for people; you can just see it on their face, and it usually brightens up a room.  I've never been a *paid* teacher, but I've always tried to share and teach all I can freely.  

And, to be honest, I'm grateful I didn't become a teacher.  Back ages ago, I had an invite to work at Virginia Tech as a teacher for QBASIC/VISUAL BASIC.  Was "..." <-- THAT close to taking the job.

Had I taken it, I would've been right there, center stage, in Norris Hall as https://en.wikipedia.org/wiki/Virginia_Tech_shooting <-- THAT went down.

So I *love* to teach.  I just thank God I never actually became a teacher.  I was ".." close to that dark day!
Yikes.
There are two ways to write error-free programs; only the third one works.
QB64 Tutorial
Reply
#22
And, since it's not right to issue a challenge without also filling it, I'd like to share this solution, which highlights the problem perfectly:

Code: (Select All)
Color 15
_Define A-Z As _FLOAT
Dim TargetWeight(1 To 4), TargetWeight$(1 To 4), I, CompareWeight, Fraction
TargetWeight(1) = 3: TargetWeight$(1) = "3"
TargetWeight(2) = 3 / 8: TargetWeight$(2) = "3 / 8"
TargetWeight(3) = 11 / 32: TargetWeight$(3) = "11 / 32"
TargetWeight(4) = 1 / 10: TargetWeight$(4) = "1 / 10"



For I = 1 To 4
CompareWeight = 4: Fraction = 1
Print TargetWeight$(I); " =";
Do
If CompareWeight < 1 Then Fraction = Fraction * 2
If CompareWeight <= TargetWeight(I) Then
TargetWeight(I) = TargetWeight(I) - CompareWeight
If Fraction <= 1 Then
Print " + "; CompareWeight;
Else
Print " + ( 1 /"; Fraction; ")";
End If
End If
CompareWeight = CompareWeight / 2
Loop Until TargetWeight(I) = 0 Or CompareWeight < 0.0000000000001##
If TargetWeight(I) > 0 Then
Color 4
Print ; " + "; TargetWeight(I); "OFF"
End If
Color 15
Print: Print
Next


Note that I've deliberately set this up to go to a much lower level of precision than just the 1/256 weights which I asked for with the first post. This is to show that even if we keep going deeper and deeper down the rabbit hole, some rabbits just aren't at home to catch to begin with!!
Reply
#23
As a prudent merchant, I shall purchase a gram scale. Good day.

I know it's ancient times. I simply don't care. I've got a gram scale.
Tread on those who tread on you

Reply
#24
Fine, as long as you don't intend to pay for it with 1/10th pound of gold!

Pete

- Always on the lookout for the gram scheme of things.
Fake News + Phony Politicians = Real Problems

Reply




Users browsing this thread: 6 Guest(s)