Week 5 Homework
Extra Credit: Watch the video at this link:
. Then download the Matlab file Kaprekars_operation.m from
Homework 5. Test this file with a few random four digit numbers. Note that this script won’t
work for values less than 1000.
Change this file to be a function file that would receive one input of four digits
number and would output two values - Output 1: the number the operation reaches
(should be Kaprekar’s constant); Output 2: the number of iterations it took to reach
You do not need to submit the function file, but you will need it for
your own reference in part b.
Write a script that tests the Kaprekar’s theory for initial values between
except for the values 1111, 2222, 3333, …., 8888. Your script should print the
Count of how many initial values were tested.
Count of how many values returned Kaprekar’s number 6174.
How many of these values took 1 iteration to reach Kaprekar’s
number, along with how many took 2 iterations, 3 iterations, 4
iterations, 5 iterations, 6 iterations, 7 iterations, and more than 8
Self-check: for (ii), all values should return 6174. For (iii), all values should take less than 8
Comments for grader/additional information (if any)
% Copy and paste your script here. Must be size 10, same as MATLAB font and
%Rick Rodey , 2.10.20, HW 5, Problem 5 extra credit, Kaprekars number
%This script uses a function file made from the given matlab script
%and then uses that function to test a large number of value for kaprekars
%Create an array of values between 1000 and 9998 except 1111,2222,etc
%test the values with kaperkar function