TABLICZKA MNOŻENIA
x=11:20
y=matrix(0,10,10)
for (i in x) {
for (j in x) {
y[i-10,j-10]=i*j
}
}
n_w=paste(x,"*",sep=""); n_k=paste("*",x,sep="")
colnames(y)=n_k; rownames(y)=n_w
print(y)
######################################
x=11:20
y=matrix(x,10,10)
z=y*t(y)
n_w=paste(x,"*",sep=""); n_k=paste("*",x,sep="")
colnames(z)=n_k; rownames(z)=n_w
print(z)
######################################
x=matrix(11:20,10,1)
y=x%*%t(x)
n_w=paste(x,"*",sep=""); n_k=paste("*",x,sep="")
colnames(y)=n_k; rownames(y)=n_w
print(y)
ZADANIE 1. Mamy 3 koła na każdym z nich…
1) kolo=c(0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,6,6,6,7,7,8,8,9)
for (i1 in 1:32) {
for (i2 in 1:32) {
for (i3 in 1:32) {
print (paste(kolo[i1],kolo[i2],kolo[i3]))
}}}
2) kolo=c(0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,6,6,6,7,7,8,8,9)
w=c(rep(1,5),rep(2,16),rep(5,6),rep(10,4),50)
for (i1 in 1:32) {
for (i2 in 1:32) {
for (i3 in 1:32) {
print(paste(kolo[i1],kolo[i2],kolo[i3]))
}}}
>w
…
>length(w)
…
3) kolo=c(0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,6,6,6,7,7,8,8,9)
w=c(rep(1,5),rep(2,16),rep(5,6),rep(10,4),50)
iw=0
sw=0
for (i1 in 1:32) {
for (i2 in 1:32) {
for (i3 in 1:32) {
print(paste(kolo[i1],kolo[i2],kolo[i3]))
}}}
print(iw/32^3)
print(sw/32^3)
4) kolo=c(0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,6,6,6,7,7,8,8,9)
w=c(rep(1,5),rep(2,16),rep(5,6),rep(10,4),50)
iw=0
sw=0
for (i1 in 1:32) {
for (i2 in 1:32) {
for (i3 in 1:32) {
wygr=c(kolo[i1]==kolo[i2],kolo[i2]==kolo[i3],kolo[i1]==kolo[i3])
if (sum(wygr)>0) {
iw=iw+1
if(sum(wygr)==3){
sw=sw+w[i1]*3
}else {
sw=sw+sum(wygr*c(w[i1],w[i2],w[i3]))
}
}
}}}
print(iw/32^3)
print(sw/32^3)