Use matlab please
Write a function mydicegame that takes an input vector d of 5 numbers (representing a roll of 5 dice) and generates the following score s for each roll as an output:
-50 points if all the dice are the same value
-30 points if they are all consecutive values (e.g. 1 2 3 4 5 or 2 3 4 5 6)
-5 points if two of the numbers are the same
-10 points if 3 of the numbers are the same
-20 points if 4 of the numbers are the same
Matlab function
============================================================================================
function mydicegame(d)
%initial arr to 0
for i=1:6
arr(i)=0;
end
for i=1:size(d,2)
arr(d(i))=arr(d(i))+1;
end
%check for consecutive values
f=1;
for i=1:size(d,2)-1
if(d(i+1)-d(i)~=1)
f=0;
break;
end
end
if f==1
score=30
else
%nested if elseif
if(find(arr==5))
score=50
elseif(find(arr==4))
score=20
elseif(find(arr==3))
score=10
elseif(find(arr==2))
score=5
end
end %end if else block
end
============================================================================================
Output
Use matlab please Write a function mydicegame that takes an input vector d of 5 numbers...
Matlab code 4) Write a function leadzero(v) which takes as input a vector v and as output, c, returns the number of zeros at the beginning of v (number of zero elements before any non-zero element). For example, for input (-5, 5, 11] the output would be 0. If the input is [0, 0, 3, 0, 0, 0], the output would be 2. If the input is [0, 0, 0, 0, 7, 4) the output would be 4. 5) Write...
6. Write a function integerdivision that takes two input numbers and divides the first one with the second one. Question 2 a) Create a vector A with all integers between 5 and 400. 4 Marks ) Given a matrix Z, how to access element of the matrix. c) What is the output of this MATLAB code? A [2,4,10,13;16,3,7,18, 8,4,9,25:3,12,15,17); length(A) size(A) Ans) Ans) 6. Write a function integerdivision that takes two input numbers and divides the first one with the...
PYTHON: Dice Rolling Write a script that takes input for the number of dice to roll and for the number of sides for the dice. Roll that many n-sided dice and store the values an array. Take the number of sides of the dice and the number of dice as typed inputs from the user. Output should be a comma separated list of the die numbers with no spaces like this: 6,4,1,3,1 Write a script that will simulate the roll...
This problem investigates how you can use random numbers to simulate a computer dice game write a function called twooice that simulates the rolling of two sik-sided dice. The function takes no inputs. Instead, it generates two random integers between 1 and 6, and output their sum. You may submit your work as many times as you want Try to get 100%) Your Function MATLAB Documentation Reset Code to call your function C Reset 1s-tuoDice ss-twoDice This problem investigates how...
MATLAB HELP PLEASE Write a Matlab function that evaluates a sum of sines at a set of points. The first term is just a constant (a coefficient with no sine term). Then, each sine term will have a coefficient before it and then an increasing multiple of the angle inside. For example, consider the sum 3 + 4 sin(9)-1.5 sin (20) 2 sin (40)3 sin (50) We recognize that this is the same as 344sin(101+-1.5 sin (20) + 0 sin...
Problem# 3 1. (10 points) Write a Matlab function called my fun that takes, x as input and generates output. You must use while follows. or iteration. The relationship between x and yisdees output. You must use while lo 50 2n
This code NEEDS TO BE DONE IN MATLAB!!!! Write a function that takes one input, an integer number n, and returns a matrix that is nxn, where the value of each number is the distance from the upper-left to bottom-right diagonal. (Use while loops if you can!) Numbers below the diagonal should be negative, and numbers above the diagonal should be positive. For example, if your input was 5, your output would be: 0 1 2 3 4 -1 0...
MATLAB: write a function that retuns logical true of vector or matrics or scaler is empty Write a function that retuns logical true of vector or matrics or scaler is empty %% P2: Check for an empty matrix % Write a function myIsEmpty which takes one input (scalar, vector, matrix, ...) % and returns logical true if the input is empty and false otherwise. % DO NOT USE MATLAB's isempty FUNCTION! % % Example: An input of [] should result...
Write the function compute_histogram, in Matlab, that takes a grayscale image as input and returns a length 256 vector h which is the normalized histogram of the values in the image. h should have values from 0 to 1 and its components should sum to 1.
How to write python code that is a dice rolling function that generates random numbers. The dice rolling function takes two arguments: the first argument is the number of sides on the dice and the second argument is the number of dice. The function returns the sum of the random dice rolls. For example, if I call roll dice(6,2) it might return 7, which is the sum of randomly chosen numbers 4 and 3. It somewhere along the lines of:...