You have been hired to write a script for a lottery system. In this lottery, a p
ID: 3807992 • Letter: Y
Question
You have been hired to write a script for a lottery system. In this lottery, a player can choose 6 non-repeated numbers between 1 and 49 when purchasing a ticket. The system records the sold ticket according to a unique ticket ID (a number between 1 and 10.000), and stores the 6 numbers printed on the ticket into adata file, called The file contains an Nx7 matrix variable called tickets, Each row corresponds to one sold ticket. The first column is the ticket ID, while the other 6 columns are the chosen numbers on the ticket. On Friday, the lottery corporation randomly draws 6 numbers from a range between 1 and 49 (non-repeating) as the winning numbers of the week. Then, the following rules are applied to determine the prizes for winners: Number of Matched Digits Prize Awarded 50.000 $25.000 4 $1000 100 0-2 Note that the number of matched digitals must be counted according to the order of the winning numbers. Also, the lottery corporation randomly draws 10 ticket IDs as 'extra' winners. Extra' winners each win $100 Now, write a MATLAB script that completes the following: Check to see if the data file ICE6Tic s .mat exists, and if it does load it. Otherwise, terminate your script gracefully by displaying the following message No data file available Suppose the winning numbers of the week is the following (ie, 6 non-repeating numbers between 1 and 49) Lucky numbers: 46 22 16 Randomly choose 10 distinct ticket IDs to award the extra prize. Hint: consider using function randi Display a message in the following format showing the selected ticket IDs (the actual values selected by your script wil be different) Lucky tickets 9510 5810 437 3863 2854 4673 8627 7819 2045 6463 Check each ticket saved in the data file and determine its prize value, including the extra prize if any (set to zero if the ticket is not qualified to any prize). Hint: function find might be useful to determine extra prize. Display a message for each ticket receiving a non-zero total prize in the following format (the actual values shown by your script will be different): Ticket 437: 0 matches, $0 $100 Ticket 2045 2 matches $0 $100 where the first dollar amount is regular prize based on the number of matched digits and the second amount is the extra prize Save the results in an Nx2 variable called prizes, in which the first column is the ticket ID and the second column is the prize amount. Then, store the variable prizes into a data file ICEwinners.matExplanation / Answer
Script for a lottery system-
style type="text/css">
div.lottery-panel {
background-color:#eee;
border:1px solid #437;
font-family:Verdana;
text-align:center;
width:200px;
}
span.lottery-panel-title {
border-bottom:1px solid green;
color:green;
font-family:Verdana;
font-size:14px;
}
span.lottery-panel-footer {
color:gray;
font-size:12px;
}
table {
margin:10px auto;
width:180px;
}
td {
background-color: orange;
border:1px solid #aaa;
border-radius:14px;
color:black;
font-size:16px;
height:28px;
text-align:center;
width:24px;
}
</style>
<div class="lottery-panel">
<span class="lottery-panel-title">Here's lucky numbers!</span>
<table border='0'>
<tr>
<?php
// Declare an array of numbers
$numbers = array();
for($n=0;$n<6;) {
// Generate a random number
$r = rand (1, 49);
// Checking if the number is not in the array
if(!in_array( $r, $numbers) ) :
$numbers[$n] = $r;
$n++;
endif;
}
// Order the array in ascending order
sort($numbers);
// Print the numbers drawn
for($n=0;$n<6;$n++) {
if($numbers[$n] == 0)
echo("<td>?</td>");
else
echo("<td>" . $numbers[$n] . "</td>");
}
?>
</tr>
</table>
<span class="lottery-panel-footer">Good luck ;-)</span>
</div>
Winning Lucky Number: 46, 22, 6, 9, 16, 5
We can write Lottery Code Optimization (matrix with all the lottery combinations. 6 numbers between 1 and 49.) below-
close all; clear all; clc
opt_a=zeros(0,49^6);
opt_b=zeros(0,49^6);
opt_c=zeros(0,49^6);
opt_d=zeros(0,49^6);
opt_e=zeros(0,49^6);
opt_f=zeros(0,49^6);
index=0;
for a=1:49
for b=1:49
for c=1:49
for d=1:49
for e=1:49
for f=1:49
index=index+1;
opt_a(index)=a;
opt_b(index)=b;
opt_c(index)=c;
opt_d(index)=d;
opt_e(index)=e;
opt_f(index)=f;
end
end
end
end
end
end
options=[opt_a' opt_b' opt_c' opt_d' opt_e' opt_f']
function [msg, x] = nalot(S, A)
%nalot picks lucky ticket numbers.
%nalot(S) uses your name to pick lucky ticket numbers.
%nalot(S, A) uses your name and age to pick lottery numbers.
tot = randperm(49);
tot = cat(2,tot,tot(1:6));
t=1;
d=0;
if nargin==0
d=1;
elseif (nargin==1 & ischar(S))
n=double(S);
t=ceil(49*randperm(sum(n))/sum(n));
d=2;
elseif (nargin==2 & ischar(S) & isnumeric(A))
n=A*double(S);
t=ceil(49*randperm(sum(n))/sum(n));
d=3;
end
x=tot(t(1):t(1)+5);
xn=num2str(x);
switch d
case 1
msg=['Your lucky tickets are: ', 9510];
case 2
msg=['Your lucky tickets are, ', 5810];
case 3
msg=['Your lucky tickets are, 3863];
case 4
msg=['Your lucky tickets are: ', 2854];
case 5
msg=['Your lucky tickets are, 4673];
case 6
msg=['Your lucky tickets are, 8627];
case 7
msg=['Your lucky tickets are, 7819];
case 8
msg=['Your lucky tickets are, 2045];
case 9
msg=['Your lucky tickets are, 6463];
otherwise
msg=['You cannot win the lucky tickets];
x=0;
end
So, from the above scripts, we can easily say that Lucky Numbers are : 46 22 6 9 16 5
And Lucky Tickets are 9510 5810 437 3863 2854 4673 8627 7819 2045 6463
style type="text/css">
div.lottery-panel {
background-color:#eee;
border:1px solid #437;
font-family:Verdana;
text-align:center;
width:200px;
}
span.lottery-panel-title {
border-bottom:1px solid green;
color:green;
font-family:Verdana;
font-size:14px;
}
span.lottery-panel-footer {
color:gray;
font-size:12px;
}
table {
margin:10px auto;
width:180px;
}
td {
background-color: orange;
border:1px solid #aaa;
border-radius:14px;
color:black;
font-size:16px;
height:28px;
text-align:center;
width:24px;
}
</style>
<div class="lottery-panel">
<span class="lottery-panel-title">Here's lucky numbers!</span>
<table border='0'>
<tr>
<?php
// Declare an array of numbers
$numbers = array();
for($n=0;$n<6;) {
// Generate a random number
$r = rand (1, 49);
// Checking if the number is not in the array
if(!in_array( $r, $numbers) ) :
$numbers[$n] = $r;
$n++;
endif;
}
// Order the array in ascending order
sort($numbers);
// Print the numbers drawn
for($n=0;$n<6;$n++) {
if($numbers[$n] == 0)
echo("<td>?</td>");
else
echo("<td>" . $numbers[$n] . "</td>");
}
?>
</tr>
</table>
<span class="lottery-panel-footer">Good luck ;-)</span>
</div>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.