HomeCALCULUSDiophantine Books Problem and...

Diophantine Books Problem and Circles Inscribed in Squares

TI-84 Plus CE Python: Diophantine Books
Problem and Circles Inscribed in Squares

Introduction

The
two programs presented today are Python versions from the Idea Book
(Ahl – see Source), where the original programs were posted in
BASIC designed for the Texas Instruments computers in the 1980s. The
Python versions were programmed with the TI-84 Plus CE Python (and
should work on the TI-83 Premium Python Edition). Unfortunately,
the Circle and Squares program may not work on the TI-82 Advanced
Python as that calculator does not have any graphics modules.

Diophantine
Books Problem

A
book store studies the sales of three popular books: A, B, and C,
each with prices PA, PB, and PC. We have the total books sold, the
sales amount, and the prices of the books. How many of each books
were sold?

The
program solve the Diophantine system of equations:

A +
B + C = N

PA *
A + PB * B + PC * C = S

N =
number of books sold

S =
total sales

A,
B, and C are positive integers

The
original BASIC program covered a specific case, where in this version
has the user enter the price of up to three books, total sales, and
number of books sold. The code in Python also counts the number of
solutions.

Code:
books.py

#
Math Calculations

from
math import *

#
Browns Books, pg 43

#
TI HOME IDEA BOOK, 1983

#
Translated to Python

print(“Browns
Books”,”\na+b+c=n”,”\npa*a+pb*b+pc*c=s”)

print(“books:
a, b, c”,”\nbook prices: pa, pb, pc”)

n=int(input(“#
books sold? “))

s=eval(input(“total
sales? “))

pa=eval(input(“price
of book a? “))

pb=eval(input(“price
of book b? “))

pc=eval(input(“price
of book c? “))

print(“Prices:
“,”\n”,pa,”\t\t”,pb,”\t\t”,pc)

print(“—————–“)

#
prices

i=0

for
a in range(1,n+1):

  for b in range(1,n+1):

    for c in range(1,n+1):

      if a+b+c==n and
pa*a+pb*b+pc*c==s:

      print(a,”\t\t”,b,”\t\t”,c)

      i+=1

print(“\n”,i,”
solutions”)

Diophantine Books Problem and Circles Inscribed in Squares


Circles
In Squares

The
program cirsqu.py calculates four areas:

The
area of a square with a side of length of 2 * r.

The
area of the inscribed circle with radius r.

The
trapped area, which is the area of the square not taken up by the
circle.

A
corner of the area of the square not taken up by the circle, which is
1 / 4 of the trapped area.

The
original program only printed the trapped area and the corner area.
In addition, this Python code uses TI-specific modules, ti_system and
ti_draw.

The
ti_system module is used to temporarily stop execution with the
disp_wait() command. Execution continues with by pressing the [
clear ] key.

The
ti_draw module is used to draw the square, the circle, and the axis.
Both the square and circle are centered at (0,0).

The
code uses a scaling routine based on the radius of the circle, so
that squares look like squares and circles look like circles. The
TI-84 Plus CE Python graphics screen is 320 x 220 pixels. Setting up
the window (xmin, xmax, ymin, and ymax) using the ratio will
accomplish this task. Here are sampling of viewing windows to try:

xmin
= -8, xmax = 8, ymin = -5.25, ymax = 5.25

xmin
= -16, xmax = 16, ymin = -10.5, ymax = 10.5

xmin
= -32, xmax = 32, ymin = -21, ymax = 21

About
the fill_rect and draw_rect commands. The syntax is (x, y, width,
height). The coordinates x and y are supposed to be the upper left
hand corner, however the manual is incorrect in practice. The
correct corner to use is the lower left hand corner.
The OS that was used is 5.8.1.0012 (same number for Python).

Code:
cirsqu.py

from
math import *

from
ti_system import *

from
ti_draw import *

print(“Math
Module Activated”)

print(“Circle
inside a Square”)

print(“circle
of radius r”)

print(“square
of side r”)

r=eval(input(“r?
“))

ac=pi*r**2

asq=(2*r)**2

ad=asq-ac

#
ti system

disp_clr()

print(“Radius:
“,r)

print(“Areas:
\nsquare:”,asq)

print(“circle:
“,ac)

print(“trapped:
“,ad)

print(“1/4
trapped: “,ad/4)

print(“\nPress
[clear] to contiue.”)

#
ti module ti_system

disp_wait()

#
use ti module ti_draw

clear()

#
text factor

f=1

#
window set up

if
r<=5.25:

  x=8

  y=5.25

else:

  y=5.25

  while y<r:

    y*=2

    f*=2

  x=y*8/5.25

set_window(-x,x,-y,y)

#
draw axis

set_color(235,235,235)

set_pen(“thin”,”dotted”)

draw_line(-x,0,x,0)

draw_line(0,-y,0,y)

#
draw shapes

set_color(25,125,255)

set_pen(“thin”,”solid”)

#
fill_rect anchors at the LOWER-left hand corner (manual error)

fill_rect(-r,-r,2*r,2*r)

set_color(230,130,0)

fill_circle(0,0,r)

set_color(0,0,0)

draw_text(-x,y-2*f,str(y))

draw_text(x-4*f,-y,str(x))

show_draw()

Source

Ahl,
David H. The Texas Instruments Home Computer Idea Book. Creative
Computing Press. Morris Plains, New Jersey. 1983. pg. 34-35,
105-106 ISBN 0-916688-51-8

Enjoy!

Eddie

All
original content copyright, © 2011-2024. Edward Shore.
Unauthorized use and/or unauthorized distribution for commercial
purposes without express and written permission from the author is
strictly prohibited. This blog entry may be distributed for
noncommercial purposes, provided that full credit is given to the
author.

Most Popular

More from Author

Google Forms for Formative Assessment in Math Class

Cheers to a new school year that will be unlike any...

2nd Grade Subtraction Worksheet | Subtraction of 2-Digit Numbers

In 2nd grade subtraction worksheet we will solve the problems on subtraction...

S01 overview – Intellectual Mathematics

Galileo is the most overrated figure in the history of science....

Digital SAT Math Problems and Solutions (Part

Problem 1 :Store A sells raspberries for $5.50 per pint and...

- A word from our sponsors -

Read Now

Google Forms for Formative Assessment in Math Class

Cheers to a new school year that will be unlike any school year before!I know that all of us are looking at new and different plans...hybrid/synchronous/asynchronous/ fully in person/fully remote...the list goes on.   I have spent a considerable amount of time trying to figure out how I...

2nd Grade Subtraction Worksheet | Subtraction of 2-Digit Numbers

In 2nd grade subtraction worksheet we will solve the problems on subtraction of 2-digit numbers (without Regrouping), subtraction of numbers with regrouping, subtracting 1-digit number from 2-digit number with regrouping, subtracting 2-digit number with regrouping, checking subtraction with addition, subtraction is reverse of addition, addition and subtraction together, estimating the difference and...

S01 overview – Intellectual Mathematics

Galileo is the most overrated figure in the history of science. That is the thesis of Season 1 of my podcast, which consists of the following 18 episodes. Galileo bad, Archimedes good Galileo’s bumbling attempts at determining the area of the cycloid suggests a radical new interpretation of...

Digital SAT Math Problems and Solutions (Part

Problem 1 :Store A sells raspberries for $5.50 per pint and blackberries for $3.00 per pint. Store B sells raspberries for $6.50 per pint and blackberries for $8.00 per pint. A certain purchase of raspberries and blackberries would cost $37.00 at store A or $66.00 at store B. How many...

How To Find The Factors Of 20: A Simple Way

The factors of 20 are the numbers 1, 2, 4, 5, 10, 20, -1, -2, -4, -5, -10, and -20. As you can see, the total number of factors 20 has is 12. Make the following observations!The numbers 1, 2, 4, 5, 10, 20 are called positive factors of...

Addition & Subtraction Together |Combination of addition & subtraction

We will solve the different types of problems involving addition and subtraction together. To show the problem involving both addition and subtraction, we first group all the numbers with ‘+’ and ‘-‘ signs. We find the sum of the numbers with ‘+’ sign and similarly the sum of all the...

Two Back to School Ideas for Digital Classrooms

 Yep, it's a school year like no other.  If you're like me, you have some very specific back to school routines...you buy the new school supplies, you get your kids a new backpack, you prepare your bulletin boards.  There are even back to school activities that I...

Digital SAT Math Problems and Solutions (Part

Problem 1 :Each face of a fair 14-sided die is labeled with a number from 1 through 14, with a different number appearing on each face. If the die is rolled one time, what is the probability of rolling a 2? Solution : https://www.youtube.com/watch?v=PC0RAjG6Zb8 Problem 2 :A printer produces posters...

Percent of Increase Word Problems

Hello and welcome! We're focusing today on a fascinating mathematical topic: percent of increase word problems. We've got some exciting scenarios to consider and we'll walk through these calculations together. It'll be as simple as counting 1, 2, 3. Let's start! Before we start, let's be clear on...

Societal role of geometry in early civilisations – Intellectual Mathematics

Podcast: DownloadIn ancient Mesopotamia and Egypt, mathematics meant law and order. Specialised mathematical technocrats were deployed to settle conflicts regarding taxes, trade contracts, and inheritance. Mathematics enabled states to develop civil branches of government instead of relying on force and violence. Mathematics enabled complex economies in which...

Sub Plans for High School Math Class – Webquests are Perfect!

Distance learning ... hybrid learning ... asynchronous learning ...   we're all learning different terms right now!  Here is a type of activity would be great in any of these settings...Webquests!I have used these types of activities in my classroom for a number of years.  I enjoy using...

Digital SAT Math Problems and Solutions (Part

Problem 1 :A neighborhood consists of a 2-hectare park and a 35-hectare residential area. The total number of trees in the neighborhood is 3,934. The equation 2x + 35y = 3,934 represents this situation. Which of the following is the best interpretation of x in this context? A) ...