zu Kar-63
Spoiler anzeigen
32%
Die Wahrscheinlichkeit für einen Rest von Null ist bei 16 Zahlen gegeben.
16 Zahlen lassen sich entsprechend teilen, wobei 35 durch beide teilbar ist.
16/50*100 = 32%
Code
/*
Abt. KAR-63
========
Aus 50 Pingpongbällen, die von 1 bis 50 durchnumeriert sind,
wird einer zufällig gezogen.
Wie hoch ist die Wahrscheinlichkeit, daß seine Nummer durch 5
oder durch 7 oder durch 5 und 7 restlos teilbar ist?
*/
// KAR-63
cls
declare i%,j%, x5%,x7%,x57%,cnt%, s5$,s7$,s57$, s$
declare Bits%[50]
set("decimals",2)
WhileLoop 1,50
j% = 0
If (&Loop mod 5) = 0
j% = j% | 1
Inc x5%
'i% = Bits%[&Loop]
'i% = SetBit(i%,0,1)
'Bits%[&Loop] = i%
Bits%[&Loop] = SetBit(Bits%[&Loop],0,1)
EndIf
If (&Loop mod 7) = 0
j% = j% | 2
Inc x7%
'i% = Bits%[&Loop]
'i% = SetBit(i%,1,1)
'Bits%[&Loop] = i%
Bits%[&Loop] = SetBit(Bits%[&Loop],1,1)
EndIf
Case j% = 3 : Inc x57%
Case j% <> 0 : Inc cnt%
print &loop,j%
EndWhile
WhileLoop 1,50
case TestBit(Bits%[&Loop],0) : s5$ = s5$ + " " + str$(&Loop)
case TestBit(Bits%[&Loop],1) : s7$ = s7$ + " " + str$(&Loop)
case Bits%[&Loop] = 3 : s57$ = s57$ + " " + str$(&Loop)
case Bits%[&Loop] <> 0 : s$ = s$ + " " + str$(&Loop)
EndWhile
print " 5 :",s5$," (",str$(x5%),"x)"
print " 7 :",s7$," (",str$(x7%),"x)"
print "5 + 7:",s57$," (",str$(x57%),"x)"
print "\nalle Zahlen:",s$
print str$(cnt%),"Zahlen sind also entsprechend teilbar."
waitkey
end
Alles anzeigen