Re: AFL solved



On Sat, 12 Sep 2009 02:33:37 +0000, Richard Heathfield
<rjh@xxxxxxxxxxxxxxx> wrote:

In <4aaad050.53519234@xxxxxxxxxxxxxxxxx>, Richard Harter wrote:

On Fri, 11 Sep 2009 02:44:53 -0700 (PDT), Albert
<albert.xtheunknown0@xxxxxxxxx> wrote:

Imagine the swap function has been implemented, making using
namespace std unecessary in this C99 code. And remember
http://groups.google.com.au/group/comp.lang.c/browse_thread/thread/6cf98ca39c45ce7b/124648c23bd40ace?hl=en&q=
? This scores 100%. It took me over the span of a year (coming back
to the problem every so often) to debug it from a 99% solution. How
could I have written _the code below_ so it would have taken less
time to debug?

The short answer is that you shouldn't have written this code.
:-)

To be fair, the specification is broken too. Let's say you have a
current occupancy as follows:

X-------------X-X

A customer books a single seat. The spec's rules call for you to
allocate the leftmost seat in the longest unbroken sequence of empty
seats:

XX------------X-X

completely ignoring the single-seat space near the right-hand end.
This means that you have to turn away the next customer, who wants 13
contiguous seats, whereas you *could* have accommodated the larger
order if you'd done the Right Thing with the first customer. (The
spec claims this never happens, but forgets to add "I hope...".)

You are quite right. In actual fact I glossed over that. My
bad. It doesn't really matter as far as my comments go, except
that I was picturing the wrong problem. With their requirement
our hapless programmer is right to use a heap, since he always
wants the longest interval at the top of the heap.

My apologies.

Where I went wrong is that I was thinking of the corresponding
storage allocation strategy, this problem being a thinly
disguised version of take from longest. The advantage of take
from longest is that you can have long runs of very cheap
allocations - just chop another bit off the old sausage. In the
long run, though, it does the nasty on fragmentation.

Given a correct reading of the requirement, the problem is
simpler than I had assumed. OP's code is still a mess, though.


Richard Harter, cri@xxxxxxxx
http://home.tiac.net/~cri, http://www.varinoma.com
Kafka wasn't an author;
Kafka was a prophet!
.



Relevant Pages

  • who expects thoughtfully, when Pervez examines the critical wisdom of the throne
    ... She may show pretty if Mustafa's customer isn't selective. ... Better keep lots now or Rashid will close allocate them in favour of you. ... proud entertainment won't specialise before I scatter it. ...
    (sci.crypt)
  • Re: Multiple concurrent isolated transactions on ADO Dataset
    ... and stacking them up for the final commit... ... wants to be allocated to seat 89... ... would be to deallocate from 171 and allocate to 89. ... it's not really possible to operate directly on the database ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Multiple concurrent isolated transactions on ADO Dataset
    ... you take out the data you need from the database change ... while you're in a business transaction. ... Person A want's to change the seat: ... > would be to deallocate from 171 and allocate to 89. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: AFL solved
    ... In, Richard Harter wrote: ... A customer books a single seat. ...
    (comp.lang.c)
  • Re: Turbo pricing available
    ... If you cannot see any time when a back seat would be useful you would be ... am going to be treated in the future as an EXISTING customer? ... DevCo apparently seem inclined to bend over backwards for new customers, ... just because you can't avoid paying for it to get something you don't ...
    (borland.public.delphi.non-technical)

Loading