master-blaster
Matthew Butterick 8 years ago
parent efac3343b7
commit cea582d3c6

@ -46,7 +46,11 @@ Those wrinkles noted, we'll proceed as we did in @secref{Day_9}. We'll parse the
]
I'm in a math-jock mood, so let's make a performance optimization. It's unnecessary for this problem, but when we use @racket[in-permutations] — which can grow ludicrously huge — we should ask how we might prune the options. Notice that because our seating arrangement is circular, our permutations will include a lot of ``rotationally equivalent'' arrangements — e.g., @racket['(A B C ...)] is the same as @racket['(B C ... A)], @racket['(C ... A B)], etc. We can save time by only checking one of each set. How? By only looking at arrangements starting with a particular name. Doesn't matter which. This will work because every name has to appear in every arrangement. To do this, we could generate all the permtuations and use a @racket[#:when] clause to select the ones we want. But it's even more efficient to only permute @italic{n - 1} names, and then @racket[cons] our target name onto each partial arrangement, which will produce the same set of arrangements.
I'm in a math-jock mood, so let's make a performance optimization. It's unnecessary for this problem, but when we use @racket[in-permutations] — which can grow ludicrously huge — we should ask how we might prune the options.
Notice that because our seating arrangement is circular, our permutations will include a lot of ``rotationally equivalent'' arrangements — e.g., @racket['(A B C ...)] is the same as @racket['(B C ... A)], @racket['(C ... A B)], etc. If we have @racket[_n] elements, each distinct arrangement will have @racket[_n] rotationally equivalent arrangements. We can save time by only checking one of each set.
How? By only looking at arrangements starting with a particular name. Doesn't matter which. This will work because every name has to appear in every arrangement. To do this, we could generate all the permtuations and use a @racket[#:when] clause to select the ones we want. But it's even more efficient to only permute @racket[(sub1 _n)] names, and then @racket[cons] our target name onto each partial arrangement, which will produce the same set of arrangements.
@chunk[<day13-q1>