Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #14201
| From | Ray Koopman <koopman@sfu.ca> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Turning a Sequence into a List? |
| Date | 2013-04-16 08:21 +0000 |
| Message-ID | <kkj1m3$1v$1@smc.vnet.net> (permalink) |
| Organization | Time-Warner Telecom |
v = Range[24,30];
sol = Reduce[25q + 10d + 5n + p == # && 0 <= p < 5 && 0 <= n < 2 &&
0 <= d < 3 && 0 <= q < 4, {q,d,n,p}, Integers]& /@v
{q == 0 && d == 2 && n == 0 && p == 4,
(q == 0 && d == 2 && n == 1 && p == 0) || (q == 1 && d == 0 && n == 0 && p == 0),
(q == 0 && d == 2 && n == 1 && p == 1) || (q == 1 && d == 0 && n == 0 && p == 1),
(q == 0 && d == 2 && n == 1 && p == 2) || (q == 1 && d == 0 && n == 0 && p == 2),
(q == 0 && d == 2 && n == 1 && p == 3) || (q == 1 && d == 0 && n == 0 && p == 3),
(q == 0 && d == 2 && n == 1 && p == 4) || (q == 1 && d == 0 && n == 0 && p == 4),
q == 1 && d == 0 && n == 1 && p == 0}
ToRules@If[ Head@# === And, #, If[
Plus@@#[[1,All,2]] < Plus@@#[[2,All,2]], #[[1]], #[[2]] ] ]& /@ sol
{{q -> 0, d -> 2, n -> 0, p -> 4},
{q -> 1, d -> 0, n -> 0, p -> 0},
{q -> 1, d -> 0, n -> 0, p -> 1},
{q -> 1, d -> 0, n -> 0, p -> 2},
{q -> 1, d -> 0, n -> 0, p -> 3},
{q -> 1, d -> 0, n -> 0, p -> 4},
{q -> 1, d -> 0, n -> 1, p -> 0}}
On Mon, Apr 15, 2013 @ 09:35 PM, Rob <rob@piovere.com> wrote:
> Hello, I'm playing with a problem with minimum coins to make change.
> Here's a problem spot where I look at ways to make up 52 and 53 cents
> (later I'll use v = Range[1,99].
>
> v=Range[52,53];
> sol=(Reduce[25q+10d+5n+p==# &&0<=p<5 &&0<=n<2 &&0<=d<3
> &&0<=q<4,{q,d,n,p},Integers])& /@v
>
> (* which gives {(q == 1 && d == 2 && n == 1 && p == 2) || (q == 2 &&
> d == 0 && n == 0 && p == 2), (q == 1 && d == 2 && n == 1 &&
> p == 3) || (q == 2 && d == 0 && n == 0 && p == 3)} *)
>
> There are two cases for each coin and I need to pick the one with the
> smallest number of coins. But the only way I know to begin that is with
> a list of rules. I can get a Sequence for the first element of the List
> sol but I can't figure how to get the Sequence to a list.
>
> x = (sol[[1]]) // ToRules
> (* Sequence[{q -> 1, d -> 2, n -> 1, p -> 2}, {q -> 2, d -> 0, n -> 0,
> p -> 2}] *)
>
> I've always had problems figuring out what a Sequence is and the HELP
> doesn't really help me. Can someone please suggest how I can use this
> sequence to select the {q,d,n,p} set that has the minimum coin count?
> It's got me stumped. Thanks.
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: Turning a Sequence into a List? Ray Koopman <koopman@sfu.ca> - 2013-04-16 08:21 +0000
csiph-web