필터 지우기
필터 지우기

lottery 6 out of 46

조회 수: 11 (최근 30일)
Raz134
Raz134 2020년 12월 5일
답변: Image Analyst 2020년 12월 6일
Hello i need to simulate specific number of games of lottery 6 out of 45 and compare if i get 1s 2s...6s and compare my winrate. I am not allowed to use functions designed specifically for matlab though.
How would i count my similarities between "tipps" and "lottozahl"? counts doesnt seem to work
clc
lottospiele = input ('´Wie oft wollen Sie Lotto spielen?');
while lottospiele > 0
if lottospiele > 0
tipps = randperm (45,6);
lottozahl = randperm(45,6);
disp (lottozahl)
disp(tipps)
counts=histc(tipps, 46:6)
lottospiele = lottospiele - 1;
end
end
  댓글 수: 4
Raz134
Raz134 2020년 12월 6일
The following functions/operators (input functions are all allowed) are allowed to be used:
- Arithmetic basic functions (+ - - :)
- Assignment (=)
- Comparison operators (< ≤ == ≥ >)
- Increment, decrement operators, bit operations
- min, max, sum, length of vectors
- modulo
- round (floor, ceil, round), abs
- Random function: 0-1 equally distributed, 1-n integer
- Trigonometric functions (sin, cos, tan)
- Constants (pi)
- Logic Operators
- Root
- Faculty
- logarithm
So i thought i can use "randperm" because its a random function. Im fairly limited and it makes stuff really hard. This makes it very hard to comeup with solutions to my problems
So im trying to simulate 6 out of 46 lottery and compare it to random tipps generated and compare my results of 1s 2s 3s... with theoretical results. Not sure how I am able to count these though with my limited options.
Rik
Rik 2020년 12월 6일
I would suggest a loop. Once you have generated the winning number and your choice you need to loop through either of them to count the number of elements that are shared.

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2020년 12월 6일
This might be instructive. Adapt as needed:
official = [1,3,32,19,4,21]
myPick = [2,4,19,25,32,40]
% Find the mismatches which are in the official but not in myPick
mismatches = setdiff(official, myPick)
% Find the mismatches which are in myPick but not in the official
mismatches = setdiff(myPick, official)
% Find out which numbers are in both myPick and in the official
[ia, ib] = ismember(myPick, official)
myMatches = myPick(ia)
You'll see:
official =
1 3 32 19 4 21
myPick =
2 4 19 25 32 40
mismatches =
1 3 21
mismatches =
2 25 40
ia =
1×6 logical array
0 1 1 0 1 0
ib =
0 5 4 0 3 0
myMatches =
4 19 32

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by