Solving coin problems: Difference between revisions

→‎{{header|Perl}}: step 2: much terser output
(→‎{{header|Perl}}: step 1: limit to problems involving coins & bills, discard comments, move to DATA handle)
(→‎{{header|Perl}}: step 2: much terser output)
Line 740:
if($count && scalar @types){ push @eqns, "count = $trace"; }
 
printf "problem: %s\n", s/\n/ /gr; # condensed problem statement
print "original input: $orig\n";
 
# Prepare MAXIMA batch file
Line 747:
my $maxima_find = "[". join(", ", map {"n_$_"} @types) . "]";
my $maxima_script = "${maxima_vars}\$\nsolve(${maxima_eqns}, ${maxima_find});\n";
print $maxima_script;
if(scalar @eqns && scalar @vars) {
my $temp = time() . "_" . rand() . ".max";
Line 754:
close TEMP;
open(MAXIMA, "maxima -q -b $temp |") || die "Couldn't open maxima: $!\n";
while (<MAXIMA>) {
# filter outprint everything"solution: but$1\n" outputif line/\(\%o\d+\)\s+\[\[([^\]]+)\]\]/; # withonly thedisplay solution
if(/\(\%o\d+\)\s+\[\[([^\]]+)\]\]/) {
print "solution: $1\n";
}
}
close MAXIMA;
unlink $temp;
Line 765 ⟶ 761:
print "Couldn't deduce enough information to formulate equations.\n"
}
print "\n\n";
}
 
Line 816 ⟶ 812:
 
A person has 12 coins consisting of dimes and pennies. If the total amount of money is $0.30, how many of each coin are there?</lang>
{{out}}
 
<pre>problem: person 3 times as many quarter as dime and total amount money $ 5.95 , find number quarter and dime .
And this is the resulting '''output''' file. Each section contains a citation of the source of the input, the original input, the MAXIMA script as formulated by the perl script, and the solution extracted from the MAXIMA output:
<pre>
# Bluman, Allan G. Math word problems demystified. 2005. The McGraw-Hill Companies Inc. p. 112, problem 1
original input: If a person has three times as many quarters as dimes and the total amount of money is $5.95, find the number of quarters and dimes.
v_quarter: 25$
v_dime: 10$
total: 595$
solve([n_quarter = 3 * n_dime, total = n_quarter * v_quarter + n_dime * v_dime], [n_quarter, n_dime]);
solution: n_quarter = 21, n_dime = 7
 
problem: pile 18 coin consists penny and nickel . total amount coin 38 ¢ , find number penny and nickel .
# Ibid., p. 112, problem 2
original input: A pile of 18 coins consists of pennies and nickels. If the total amount of the coins is 38¢, find the number of pennies and nickels.
v_nickel: 5$
v_penny: 1$
count: 18$
total: 38$
solve([total = n_nickel * v_nickel + n_penny * v_penny, count = n_nickel + n_penny], [n_nickel, n_penny]);
solution: n_nickel = 5, n_penny = 13
 
problem: small child 6 more quarter than nickel . total amount coin $ 3.0 , find number nickel and quarter child .
# Ibid., p. 112, problem 3
original input: A small child has 6 more quarters than nickels. If the total amount of coins is $3.00, find the number of nickels and quarters the child has.
v_quarter: 25$
v_nickel: 5$
total: 300$
solve([n_quarter = n_nickel + 6, total = n_quarter * v_quarter + n_nickel * v_nickel], [n_quarter, n_nickel]);
solution: n_quarter = 11, n_nickel = 5
 
problem: child 's bank contains 32 coin consisting nickel and quarter . total amount money $ 3.80 , find number nickel and quarter in bank .
# Ibid., p. 112, problem 4
 
original input: A child's bank contains 32 coins consisting of nickels and quarters. If the total amount of money is $3.80, find the number of nickels and quarters in the bank.
v_quarter: 25$
v_nickel: 5$
count: 32$
total: 380$
solve([total = n_quarter * v_quarter + n_nickel * v_nickel, count = n_quarter + n_nickel], [n_quarter, n_nickel]);
solution: n_quarter = 11, n_nickel = 21
 
problem: person 2 times as many dime as penny and 3 more nickel than penny . total amount coin $ 1.97 , find numbers each type coin person .
# Ibid., p. 112, problem 5
original input: A person has twice as many dimes as she has pennies and three more nickels than pennies. If the total amount of the coins is $1.97, find the numbers of each type of coin the person has.
v_dime: 10$
v_nickel: 5$
v_penny: 1$
total: 197$
solve([n_dime = 2 * n_penny, n_nickel = n_penny + 3, total = n_dime * v_dime + n_nickel * v_nickel + n_penny * v_penny], [n_dime, n_nickel, n_penny]);
solution: n_dime = 14, n_nickel = 10, n_penny = 7
 
problem: in bank , 3 times as many quarter as half_dollar and 6 more dime than half_dollar . total amount money in bank $ 4.65 , find number each type coin in bank .
# Ibid., p. 112, problem 6
original input: In a bank, there are three times as many quarters as half dollars and 6 more dimes than half dollars. If the total amount of the money in the bank is $4.65, find the number of each type of coin in the bank.
v_half_dollar: 50$
v_quarter: 25$
v_dime: 10$
total: 465$
solve([n_quarter = 3 * n_half_dollar, n_dime = n_half_dollar + 6, total = n_half_dollar * v_half_dollar + n_quarter * v_quarter + n_dime * v_dime], [n_half_dollar, n_quarter, n_dime]);
solution: n_half_dollar = 3, n_quarter = 9, n_dime = 9
 
problem: clerk given $ 75 in bill put in cash drawer start workday . 2 times as many $ 1 bill as $ 5 bill and 1 less $ 10 bill than $ 5 bill . how many each type bill ?
# Ibid., p. 112, problem 7
original input: A person bought 12 stamps consisting of 37¢ stamps and 23¢ stamps. If the cost of the stamps is $3.74, find the number of each type of the stamps purchased.
count: 12$
v_37_stamp: 37$
v_23_stamp: 23$
total: 374$
solve([total = n_37_stamp * v_37_stamp + n_23_stamp * v_23_stamp, count = n_37_stamp + n_23_stamp], [n_37_stamp, n_23_stamp]);
solution: n_37_stamp = 7, n_23_stamp = 5
 
# Ibid., p. 112, problem 8
original input: A dairy store sold a total of 80 ice cream sandwiches and ice cream bars. If the sandwiches cost $0.69 each and the bars cost $0.75 each and the store made $58.08, find the number of each sold.
count: 80$
v_sandwiches: 69$
v_bars: 75$
total: 5880$
solve([total = n_sandwiches * v_sandwiches + n_bars * v_bars, count = n_sandwiches + n_bars], [n_sandwiches, n_bars]);
solution: n_sandwiches = 20, n_bars = 60
 
# Ibid., p. 112, problem 9
original input: An office supply store sells college-ruled notebook paper for $1.59 a ream and wide-ruled notebook paper for $2.29 a ream. If a student purchased 9 reams of notebook paper and paid $15.71, how many reams of each type of paper did the student purchase?
v_college_ruled_notebook_paper: 159$
v_wide_ruled_notebook_paper: 229$
count: 9$
total: 1571$
solve([total = n_college_ruled_notebook_paper * v_college_ruled_notebook_paper + n_wide_ruled_notebook_paper * v_wide_ruled_notebook_paper, count = n_college_ruled_notebook_paper + n_wide_ruled_notebook_paper], [n_college_ruled_notebook_paper, n_wide_ruled_notebook_paper]);
solution: n_college_ruled_notebook_paper = 7, n_wide_ruled_notebook_paper = 2
 
# Ibid., p. 112, problem 10
original input: A clerk is given $75 in bills to put in a cash drawer at the start of a workday. There are twice as many $1 bills as $5 bills and one less $10 bill than $5 bills. How many of each type of bill are there?
total: 7500$
v_1: 100$
v_5: 500$
v_10: 1000$
solve([n_1 = 2 * n_5, n_1 = 2 * n_5, n_10 = n_5 - 1, total = n_1 * v_1 + n_5 * v_5 + n_10 * v_10], [n_1, n_5, n_10, n_5]);
solution: n_1 = 10, n_10 = 4, n_5 = 5
 
problem: person 8 coin consisting quarter and dime . total amount change $ 1.25 , how many each kind coin ?
# Ibid., p. 109
original input: A person has 8 coins consisting of quarters and dimes. If the total amount of this change is $1.25, how many of each kind of coin are there?
v_quarter: 25$
v_dime: 10$
count: 8$
total: 125$
solve([total = n_quarter * v_quarter + n_dime * v_dime, count = n_quarter + n_dime], [n_quarter, n_dime]);
solution: n_quarter = 3, n_dime = 5
 
problem: person 3 times as many dime as nickel and 5 more penny than nickel . total amount these coin $ 1.13 , how many each kind coin ?
# Ibid., p. 110
original input: A person has 3 times as many dimes as he has nickels and 5 more pennies than nickels. If the total amount of these coins is $1.13, how many of each kind of coin does he have?
v_dime: 10$
v_nickel: 5$
v_penny: 1$
total: 113$
solve([n_dime = 3 * n_nickel, n_penny = n_nickel + 5, total = n_dime * v_dime + n_nickel * v_nickel + n_penny * v_penny], [n_dime, n_nickel, n_penny]);
solution: n_dime = 9, n_nickel = 3, n_penny = 8
 
problem: person 9 more dime than nickel . total amount money $ 1.20 , find number dime person .
# Ibid., p. 111
original input: A person bought ten greeting cards consisting of birthday cards costing $1.50 each and anniversary cards costing $2.00 each. If the total cost of the cards was $17.00, find the number of each kind of card the person bought.
count: 10$
total: 1700$
v_birthday_cards: 150$
v_anniversary_cards: 200$
solve([total = n_birthday_cards * v_birthday_cards + n_anniversary_cards * v_anniversary_cards, count = n_birthday_cards + n_anniversary_cards], [n_birthday_cards, n_anniversary_cards]);
solution: n_birthday_cards = 6, n_anniversary_cards = 4
 
# Ibid., p. 119, problem 8
original input: A person has 9 more dimes than nickels. If the total amount of money is $1.20, find the number of dimes the person has.
v_dime: 10$
v_nickel: 5$
total: 120$
solve([n_dime = n_nickel + 9, total = n_dime * v_dime + n_nickel * v_nickel], [n_dime, n_nickel]);
solution: n_dime = 11, n_nickel = 2
 
problem: person 20 bill consisting $ 1 bill and $ 2 bill . total amount money person $ 35 , find number $ 2 bill person .
# Ibid., p. 120, problem 9
original input: A person has 20 bills consisting of $1 bills and $2 bills. If the total amount of money the person has is $35, find the number of $2 bills the person has.
count: 20$
total: 3500$
v_1: 100$
v_2: 200$
solve([total = n_1 * v_1 + n_2 * v_2, count = n_1 + n_2], [n_1, n_2, n_2]);
solution: n_1 = 5, n_2 = 15
 
problem: bank contains 8 more penny than nickel and 3 more dime than nickel . total amount money in bank $ 3.10 , find number dime in bank .
# Ibid., p. 120, problem 10
original input: A bank contains 8 more pennies than nickels and 3 more dimes than nickels. If the total amount of money in the bank is $3.10, find the number of dimes in the bank.
v_dime: 10$
v_nickel: 5$
v_penny: 1$
total: 310$
solve([n_penny = n_nickel + 8, n_dime = n_nickel + 3, total = n_dime * v_dime + n_nickel * v_nickel + n_penny * v_penny], [n_dime, n_nickel, n_penny]);
solution: n_dime = 20, n_nickel = 17, n_penny = 25
 
problem: 26 coin in my pocket all dollar_coin and quarter , and add up $ 17 in value . how many each coin ?
# More test problems from around the web...
# Source: http://www.purplemath.com/modules/coinprob.htm
# Soln: 12 quarters, 14 dollar coins
original input: Your uncle walks in, jingling the coins in his pocket. He grins at you and tells you that you can have all the coins if you can figure out how many of each kind of coin he is carrying. You're not too interested until he tells you that he's been collecting those gold-tone one-dollar coins. The twenty-six coins in his pocket are all dollars and quarters, and they add up to seventeen dollars in value. How many of each coin does he have?
v_dollar_coin: 100$
v_quarter: 25$
count: 26$
total: 1700$
solve([total = n_dollar_coin * v_dollar_coin + n_quarter * v_quarter, count = n_dollar_coin + n_quarter], [n_dollar_coin, n_quarter]);
solution: n_dollar_coin = 14, n_quarter = 12
 
problem: collection 33 coin , consisting nickel , dime , and quarter , value $ 3.30 . 3 times as many nickel as quarter , and 0.5 as many dime as nickel , how many coin each kind ?
# Ibid.
# Soln: Then there are six quarters, and I can work backwards to figure out that there are 9 dimes and 18 nickels.
original input: A collection of 33 coins, consisting of nickels, dimes, and quarters, has a value of $3.30. If there are three times as many nickels as quarters, and one-half as many dimes as nickels, how many coins of each kind are there?
v_quarter: 25$
v_dime: 10$
v_nickel: 5$
count: 33$
total: 330$
solve([n_nickel = 3 * n_quarter, n_dime = 0.5 * n_nickel, total = n_quarter * v_quarter + n_dime * v_dime + n_nickel * v_nickel, count = n_quarter + n_dime + n_nickel], [n_quarter, n_dime, n_nickel]);
solution: n_quarter = 6, n_dime = 9, n_nickel = 18
 
problem: wallet contains same number penny , nickel , and dime . coin total $ 1.44 . how many each type coin wallet contain ?
# Ibid.
# Soln. There are nine of each type of coin in the wallet.
original input: A wallet contains the same number of pennies, nickels, and dimes. The coins total $1.44. How many of each type of coin does the wallet contain?
v_dime: 10$
v_nickel: 5$
v_penny: 1$
total: 144$
solve([n_penny = n_nickel, n_nickel = n_dime, total = n_dime * v_dime + n_nickel * v_nickel + n_penny * v_penny], [n_dime, n_nickel, n_penny]);
solution: n_dime = 9, n_nickel = 9, n_penny = 9
 
problem: suppose ken 25 coin in nickel and dime only and total $ 1.65 . how many each coin ?
# Source: http://www.algebralab.org/Word/Word.aspx?file=Algebra_CoinProblems.xml
# Soln: Ken has 17 nickels and 8 dimes.
original input: Suppose Ken has 25 coins in nickels and dimes only and has a total of $1.65. How many of each coin does he have?
v_dime: 10$
v_nickel: 5$
count: 25$
total: 165$
solve([total = n_dime * v_dime + n_nickel * v_nickel, count = n_dime + n_nickel], [n_dime, n_nickel]);
solution: n_dime = 8, n_nickel = 17
 
problem: terry 2 more quarter than dime and total $ 6.80 . number quarter and dime 38 . how many quarter and dime terry ?
# Ibid.
# Let's Practice
# Question #1
# Note: The original question had an inconsistency in it,
# namely "Terry has 7 more" should be "Terry has 2 more..."
# Soln: Terry has 18 dimes and 20 quarters.
original input: Terry has 2 more quarters than dimes and has a total of $6.80. The number of quarters and dimes is 38. How many quarters and dimes does Terry have?
v_quarter: 25$
v_dime: 10$
count: 38$
total: 680$
solve([n_quarter = n_dime + 2, total = n_quarter * v_quarter + n_dime * v_dime, count = n_quarter + n_dime], [n_quarter, n_dime]);
solution: n_quarter = 20, n_dime = 18
 
problem: in my wallet , $ 1 bill , $ 5 bill , and $ 10 bill . total amount in my wallet $ 43 . 4 times as many $ 1 bill as $ 10 bill . all together , 13 bill in my wallet . how many each bill ?
# Ibid.
# Question #2
# Soln: There are 2 ten-dollar bills, 8 one-dollar bills, and 3 five-dollar bills.
original input: In my wallet, I have one-dollar bills, five-dollar bills, and ten-dollar bills. The total amount in my wallet is $43. I have four times as many one-dollar bills as ten-dollar bills. All together, there are 13 bills in my wallet. How many of each bill do I have?
count: 13$
total: 4300$
v_1: 100$
v_5: 500$
v_10: 1000$
solve([n_1 = 4 * n_10, n_1 = 4 * n_10, total = n_1 * v_1 + n_5 * v_5 + n_10 * v_10, count = n_1 + n_5 + n_10], [n_1, n_5, n_10, n_1, n_10]);
solution: n_5 = 3, n_1 = 8, n_10 = 2
 
problem: marsha 3 times as many $ 1 bill as $ 5 bill . total $ 32 . how many each bill ?
# Ibid.
# Try These
# Question #1
original input: Marsha has three times as many one-dollar bills as she does five dollar bills. She has a total of $32. How many of each bill does she have?
total: 3200$
v_1: 100$
v_5: 500$
solve([n_1 = 3 * n_5, n_1 = 3 * n_5, total = n_1 * v_1 + n_5 * v_5], [n_1, n_5]);
solution: n_1 = 12, n_5 = 4
 
problem: vending machine $ 41.25 in . 255 coin total and machine only accepts nickel , dime and quarter . 2 times as many dime as nickel . how many each coin in machine .
# Ibid.
# Question #2
original input: A vending machine has $41.25 in it. There are 255 coins total and the machine only accepts nickels, dimes and quarters. There are twice as many dimes as nickels. How many of each coin are in the machine.
v_quarter: 25$
v_dime: 10$
v_nickel: 5$
count: 255$
total: 4125$
solve([n_dime = 2 * n_nickel, total = n_quarter * v_quarter + n_dime * v_dime + n_nickel * v_nickel, count = n_quarter + n_dime + n_nickel], [n_quarter, n_dime, n_nickel]);
solution: n_quarter = 120, n_dime = 90, n_nickel = 45
 
problem: michael had 27 coin in all , valuing $ 4.50 . had only quarter and dime , how many coin each kind ?
# Source: http://voices.yahoo.com/how-set-solve-coin-word-problems-algebra-1713709.html
# Sample Coin Word Problem 1:
# Soln: Michael has 15 dimes and 12 quarters.
original input: Michael had 27 coins in all, valuing $4.50. If he had only quarters and dimes, how many coins of each kind did he have?
v_quarter: 25$
v_dime: 10$
count: 27$
total: 450$
solve([total = n_quarter * v_quarter + n_dime * v_dime, count = n_quarter + n_dime], [n_quarter, n_dime]);
solution: n_quarter = 12, n_dime = 15
 
problem: lucille had $ 13.25 in nickel and quarter . had 165 coin in all , how many each type coin ?
# Ibid.
# Sample Coin Word Problem 2:
# Soln: Lucille has 25 quarters and 140 nickels.
original input: Lucille had $13.25 in nickels and quarters. If she had 165 coins in all, how many of each type of coin did she have?
v_quarter: 25$
v_nickel: 5$
count: 165$
total: 1325$
solve([total = n_quarter * v_quarter + n_nickel * v_nickel, count = n_quarter + n_nickel], [n_quarter, n_nickel]);
solution: n_quarter = 25, n_nickel = 140
 
problem: ben $ 45.25 in quarter and dime . 29 less quarter than dime , how many each type coin ?
# Ibid.
# Sample Coin Word Problem 3:
# Soln: Ben has 150 dimes and 121 quarters.
original input: Ben has $45.25 in quarters and dimes. If he has 29 less quarters than dimes, how many of each type of coin does he have?
v_quarter: 25$
v_dime: 10$
total: 4525$
solve([n_quarter = n_dime - 29, total = n_quarter * v_quarter + n_dime * v_dime], [n_quarter, n_dime]);
solution: n_quarter = 121, n_dime = 150
 
problem: person 12 coin consisting dime and penny . total amount money $ 0.30 , how many each coin ?
# Source: http://www.calculatorsoup.com/calculators/wordproblems/algebrawordproblem1.php
solution: n_dime = 2, n_penny = 10</pre>
original input: A person has 12 coins consisting of dimes and pennies. If the total amount of money is $0.30, how many of each coin are there?
v_dime: 10$
v_penny: 1$
count: 12$
total: 30$
solve([total = n_dime * v_dime + n_penny * v_penny, count = n_dime + n_penny], [n_dime, n_penny]);
solution: n_dime = 2, n_penny = 10
</pre>
 
=={{header|Phix}}==
2,392

edits