Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (2)
As of 2021-09-23 05:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?