Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Well, if you're serious about teaching her logic skills ;) (I've ignored two dollar bills for simplicity. It should be trivial to add it)

#!/usr/bin/perl use strict; use warnings; use AI::Prolog; my @bills = qw(Fifties Twenties Tens Fives Ones); my $bills = join ',', @bills; # don't use $prolog->list because these +are vars my $program = <<"END_PROLOG"; change([ $bills ]) :- member(Fifties,[0,1,2]), member(Twenties,[0,1,2,3,4,5]), member(Tens,[0,1,2,3,4,5,6,7,8,9,10]), member(Fives,[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 +]), Total is 50*Fifties + 20*Twenties +10*Tens + 5*Fives, Total <= 100, Ones is 100 - Total. member(X, [X|_]). member(X, [_|Tail]) :- member(X, Tail). END_PROLOG my $prolog = AI::Prolog->new($program); $prolog->query("change([ $bills ])."); while (my $result = $prolog->results) { for my $i ( 0 .. $#bills ) { print "$result->[1][$i] $bills[$i]"; print ", " unless $i == $#bills; } print "\n"; } __END__ # Beginning of output: 0 Fifties, 0 Twenties, 0 Tens, 0 Fives, 100 Ones 0 Fifties, 0 Twenties, 0 Tens, 1 Fives, 95 Ones 0 Fifties, 0 Twenties, 0 Tens, 2 Fives, 90 Ones 0 Fifties, 0 Twenties, 0 Tens, 3 Fives, 85 Ones 0 Fifties, 0 Twenties, 0 Tens, 4 Fives, 80 Ones 0 Fifties, 0 Twenties, 0 Tens, 5 Fives, 75 Ones 0 Fifties, 0 Twenties, 0 Tens, 6 Fives, 70 Ones 0 Fifties, 0 Twenties, 0 Tens, 7 Fives, 65 Ones 0 Fifties, 0 Twenties, 0 Tens, 8 Fives, 60 Ones ...

Cheers,
Ovid

New address of my CGI Course.


In reply to Re: puzzle: how many ways to make $100 (with Prolog!) by Ovid
in thread puzzle: how many ways to make $100 by davidj

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (9)
    As of 2014-09-19 07:13 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (132 votes), past polls