Credit Cards. Validating Credit Cards. Answers

Similar documents
Repeating Decimals and Fractions

Note: This activity is also available in a non-coding version, where students use existing programs to do a similar exploration

Physics. Light and Waves ID: 9462

Slope Fields & Differential Equations

ELEMENTARY NUMBER THEORY AND METHODS OF PROOF

ELEMENTARY NUMBER THEORY AND METHODS OF PROOF

Variables, Data Types, and Arithmetic Expressions Learning Objectives:

Activity Overview A basic introduction to the many features of the calculator function of the TI-Nspire

String Graphs Part 1 + 2

Building Concepts: Building Expressions

Modular Arithmetic. Marizza Bailey. December 14, 2015

Lecture 2 Algorithms with numbers

Homework #3 CS2255 Fall 2012

8/27/2016. ECE 120: Introduction to Computing. Graphical Illustration of Modular Arithmetic. Representations Must be Unambiguous

Sample some Pi Monte. Introduction. Creating the Simulation. Answers & Teacher Notes

1 GLUE INTRODUCTION 1

Irrational Thoughts. Aim. Equipment. Irrational Investigation: Student Activity

Name Student Activity

Exploring Transformations

Graphics calculator instructions

Operators in C. Staff Incharge: S.Sasirekha

Recursion and Induction: Haskell; Primitive Data Types; Writing Function Definitions

9/10/10. Arithmetic Operators. Today. Assigning floats to ints. Arithmetic Operators & Expressions. What do you think is the output?

Addition and Subtraction of. Rational Numbers Part 2. Name. Class. Student Activity. Open the TI-Nspire document Add_Sub_Rational_Numbers_Part2.tns.

What we will do today Explain and look at examples of. Programs that examine data. Data types. Topic 4. variables. expressions. assignment statements

Graphics calculator instructions

x= suppose we want to calculate these large values 1) x= ) x= ) x=3 100 * ) x= ) 7) x=100!

Building Concepts: Moving from Proportional Relationships to Linear Equations

1. Let n be a positive number. a. When we divide a decimal number, n, by 10, how are the numeral and the quotient related?

Module 10: Imperative Programming, Modularization, and The Future

Information Science 1

Building Concepts: Visualizing Equations Using Mobiles

Information Science 1

UEE1302(1066) F12: Introduction to Computers and Programming Function (II) - Parameter

Looping Subtasks. We will examine some basic algorithms that use the while and if constructs. These subtasks include

Lecture 8: Addition, Multiplication & Division

2018 Pummill Relay problem statement

Transformations: Translating Functions

Divisibility Rules and Their Explanations

Arrays: Higher Dimensional Arrays. CS0007: Introduction to Computer Programming

NUMB3RS Activity: Creating Codes. Episode: Backscatter

These are reserved words of the C language. For example int, float, if, else, for, while etc.

Cryptography Worksheet

CAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE

The Distributive Property and Expressions Understand how to use the Distributive Property to Clear Parenthesis

CHAPTER 17 INFORMATION SCIENCE. Binary and decimal numbers a short review: For decimal numbers we have 10 digits available (0, 1, 2, 3, 9) 4731 =

This tutorial will teach you about operators. Operators are symbols that are used to represent an actions used in programming.

COMPUTER SCIENCE Paper 2 (PRACTICAL)

Unit 3. Operators. School of Science and Technology INTRODUCTION

TImath.com. Geometry. Triangle Inequalities

TI-73, TI-80, TI-81, TI-82, TI-83, TI-85,

Getting Started with the TI- Nspire CX

NUMBER OPERATIONS. Mahdi Nazm Bojnordi. CS/ECE 3810: Computer Organization. Assistant Professor School of Computing University of Utah

Advanced Computer Architecture-CS501

Student Financials upay Portal User Guide

Ch 3.4 The Integers and Division

Building Java Programs. Chapter 2: Primitive Data and Definite Loops

Relational Database: The Relational Data Model; Operations on Database Relations

f( x ), or a solution to the equation f( x) 0. You are already familiar with ways of solving

Algebra Homework: Chapter 1 (Homework is listed by date assigned; homework is due the following class period) Day Date In-Class Homework

Exponential Notation

cd h: mkdir -p CS101 cd CS101 curl -O unzip zipfile cd CS101_Exam4

SYNOPSIS This pracnique explores an Ada program to apply Luhn s algorithm to verify credit card information.

Class 2: Variables and Memory. Laura Marik Spring 2012 C++ Course Notes (Provided by Jason Minski)

Computer System and programming in C

Chapter 3: Theory of Modular Arithmetic 1. Chapter 3: Theory of Modular Arithmetic

Chapter 2: Using Data

UNIT 3 OPERATORS. [Marks- 12]

Primality Testing! 1

TABLES AND HASHING. Chapter 13

Common Core State Standards Mathematics (Subset K-5 Counting and Cardinality, Operations and Algebraic Thinking, Number and Operations in Base 10)

Computer Programming CS F111

Basic Arithmetic Operations

Introduction to Programming, Aug-Dec 2008

The Further Mathematics Support Programme

Encryption à la Mod Name

Constructing Algorithms and Pseudocoding This document was originally developed by Professor John P. Russo

Unit 2: Accentuate the Negative Name:

Arithmetic Algorithms Taught in Schools

Exploring the Equation of a Circle

Graphics calculator instructions

The equation to any straight line can be expressed in the form:

Lecture Notes, CSE 232, Fall 2014 Semester

Building Java Programs

DEPARTMENT OF MATHS, MJ COLLEGE

Object-Oriented Programming

Learning Log Title: CHAPTER 3: ARITHMETIC PROPERTIES. Date: Lesson: Chapter 3: Arithmetic Properties

Excerpt from "Art of Problem Solving Volume 1: the Basics" 2014 AoPS Inc.

Programming in C++ 5. Integral data types

Orifice Flow Meter

Full file at C How to Program, 6/e Multiple Choice Test Bank

It is important that you show your work. There are 134 points available on this test.

Properties and Definitions

1 Computer arithmetic with unsigned integers

Notre Dame High School. Mathematics is the gateway to all college and career opportunities. As stated by the National Research Council:

The Design of C: A Rational Reconstruction

1. The keyword main in C language is used for

The Design of C: A Rational Reconstruction"

Groups of two-state devices are used to represent data in a computer. In general, we say the states are either: high/low, on/off, 1/0,...

Adaptive Cruise Control

Transcription:

Answers 7 8 9 10 11 12 TI-Nspire Coding Student 60 min Validating Credit Cards Imagine you are building a website that requires financial transactions to take place. Users need to enter their credit card details; however before they proceed you need to validate their credit card number, this can be done before submitting the details to the financial institution. Being part of a website, you would need to do this automatically using some basic computer code. Most credit cards contain a 16 digit number. The numbers however are not random. There is a relatively simple process to check if a credit card number is valid. 1 Your task is to write a program that will automatically check to see if a credit card number is valid or not. Step 1 The credit card number shown above is: 1 4 3 2 4 6 7 8 9 8 7 6 5 4 3 2 We start by extracting every second digit: 1 4 3 2 4 6 7 8 9 8 7 6 5 4 3 2 Calculate the sum of these digits: 1 + 3 + 4 + 7 + 9 + 7 + 5 + 3 = 39 Double this value: 2 x 39 = 78 [Answer 1] Step 2 Using every second digit, count the digits 5 1 4 3 2 4 6 7 8 9 8 7 6 5 4 3 2 There are 4 digits greater or equal to 5. [Answer 2] Step 3 Extract the alternate digits: 1 4 3 2 4 6 7 8 9 8 7 6 5 4 3 2 Find the sum of these digits: 1 4 + 2 + 6 + 8 + 8 + 6 + 4 + 2 = 30 [Answer 3] Step 4 Find the sum of these three answers: 39 + 4 + 30 = 73 The final result must be a multiple of 10 if the credit card number is valid. Invalid Credit Card! 1 Valid: Just because a credit card number is valid, doesn t mean it is real or attached to an existing account. Texas Instruments 2016. You may copy, communicate and modify this material for non-commercial educational purposes Author: P. Fox

2 Question: 1. Use the algorithm above to see if the following credit card number is valid: 9513 1081 5812 5353 9 + 1 + 1 + 8 + 5 + 1 + 5 + 5 = 35 2 x 35 = 70 5 numbers greater than = 5 5 5 + 3 + 0 + 1 + 8 + 2 + 3 + 3 = 25 25 Since 70 + 5 + 25 = 100 the last digit is a zero so it is a valid credit card number. Coding the Algorithm Mathematical procedures that are based on simple logic are relatively easy to code or program. In this case the user will put in their 16 digit number and the program will return the result Valid or Invalid. Instructions: Start a new document; insert a calculator application followed by a program. Call the program: ValidCredit Note that ValidCredit is one word as program names cannot contain spaces. Several variables will be used in this program, two things need to be done in order to use these variables consistently and without interfering with potential user variables. Declare the variables as local. Prevents them from appearing to users. Seed the variables. Set some of the variables to zero so they do not contain previous data. The credit card number needs to be entered by the user. The I/O (Input / Output) menu contains the Request command. Request Enter credit card number:, n The credit card number will be stored into n. The digits in the credit card need to be successively removed. In this example modular arithmetic will be used. Modular arithmetic can be thought of as remainder. Mod(25,10) = 5 since 25 10 = 2 rem 5. The integer command will also be used to remove unwanted decimal places. For example to extract the 100 s digit from 1234; Int(Mod(1234,1000)/100) = 2. Looking at this step by step: Mod(1234,100) = 34 since 1234 1000 = 1 rem 234 234 100 = 2.34 Int(2.34) = 2 since the part returned is the integer value only. Texas Instruments 2016. You may copy, communicate and modify this material for non-commercial educational purposes

3 A loop is required to separate all 16 digits. The digits will be removed one by one. The above integer and modular arithmetic commands will be used. The logic statements such as For and If Then can be obtained from the Control menu. For i, 1, 16 This starts a loop where i = 1, the first time through. The second time through the loop i = 2 until the last loop where i = 16. i mod n,10 d : int Successive digits stored in d. i1 10 Now that a digit has been collected from the credit card number, it needs to be determined whether the digit location is even or odd so that the appropriate step (or steps) can be executed. Enter the instructions shown opposite. Note that there is an IF statement embedded in another IF statement. The embedded IF statement is only acted upon if the first condition is satisfied. Read over steps 1 and 2 in the original instructions to help understand what the program is doing here. Variables a, b and c now hold parts of the answers in the original algorithm. If 2a + b + c is a multiple of 10, then the credit card number is valid, otherwise it is invalid. The program is now ready to be checked and stored, press Ctrl + B. To transfer control to the calculator application, press Ctrl + Tab to shift focus to the calculator application. Press the [VAR] key to locate your program and press Enter to select and then Enter to run the program. Test the program using the credit card number in Question 1. Question: 2. Use the program to test the following credit card numbers to see if they are valid. a) 4049 0876 3177 5451 (Valid) b) 5248 9255 1236 4153 (Invalid) c) 2158 2594 3168 2392 (Invalid) d) 4148 2955 2187 5253 (Valid) Question: 3. A digit on a credit card receipt appears to be missing 4049 521A 5437 1333. Determine the value of the missing digit. Texas Instruments 2016. You may copy, communicate and modify this material for non-commercial educational purposes

4 Step 1: 4 + 4 + 5 + 1 + 5 + 3 + 1 + 3 = 26. 26 x 2 = 52. Step 2: 2 digits 5. Step 3: 0 + 9 + 2 + A + 4 + 7 + 3 + 3 = 28 + A Step 4: 52 + 2 + 28 + A = 82 + A therefore A = 8 (Missing digit) Coding Questions These questions focus on an understanding of the coding used in this activity in addition to looking for modifications. Question: 4. The first IF statement includes the logic statement: mod(i,2)=0. In relation to the validation process what is this logic statement checking? When i is even this statement will be executed, this corresponds to every 2 nd digit, however these are read from the right, which corresponds to step 1 and step 2. Question: 5. With reference to the validation process, explain the statements: a:= a + d and c:= c + 1 a := a + d corresponds to progressively adding the digits together, in this case for Step 1 c := c + 1 corresponds to counting the quantity of digits greater than or equal to 5. Question: 6. Suppose all credit cards are changed to 20 digits. Identify the required changes to the program that would accommodate the new credit card changes. The For loop would go from 1 to 20, no other changes would be required. Question: 7. A new validation system requires the final sum to be a multiple of 17. Identify the necessary changes to the code. IF mod(2a + b + c,17) = 0 Then would be the only change required. Challenge Questions Question: 8. A digit is missing from a credit card receipt: X124 5132 4681 2552. Determine the value of missing digit. X + 2 + 5 + 3 + 4 + 8 + 2 + 5 = 29 + X 2 (29 + X) = 58 + 2X Two possibilities: If X < 5, then 5, 8, 5 => Count = 3 3 If X > 5, then X, 5, 8, 5 => Count = 4 4 1 + 4 + 1 + 2 + 6 + 1 + 5 + 2 = 22 22 Equations to solve: 83 + 2X = 90 (X < 5) non integer solution. 84 + 2X = 100 (X > 5) X = 8. (Note that 84 + 2X = 90 is not possible since X > 5) Texas Instruments 2016. You may copy, communicate and modify this material for non-commercial educational purposes

5 Question: 9. The first two digits are missing from a credit card receipt: XY24 5132 4681 2552. Determine the possible combinations for the two missing digits. Note: Check some of your answers using your program. X + 2 + 5 + 3 + 4 + 8 + 2 + 5 = 29 + X 2 (29 + X) = 58 + 2X As before Two possibilities: If X < 5, then 5, 8, 5 => Count = 3 3 If X > 5, then X, 5, 8, 5 => Count = 4 4 Y + 4 + 1 + 2 + 6 + 1 + 5 + 2 = 21 Y + 21 Equations to solve when X < 5: 82 + 2X + Y = 90 since 0 < X < 5 & 0 < Y < 10 no other equations possible. Solution set for 82 + 2X + Y = 90 {(0, 8), (1, 6), (2, 4), (3, 2), (4, 0)} Equations to solve when X 5 83 + 2X + Y = 100 since 5 X < 10 & 0 < Y < 10 no other equations possible. {(5, 7), (6, 5), (7, 3), (8, 1)} Texas Instruments 2016. You may copy, communicate and modify this material for non-commercial educational purposes