lab 0 submission

This commit is contained in:
Nir Bhikhubhai Bavariya Bavariya 2021-08-16 04:40:55 +05:30
commit 2cd5e64c6e
3 changed files with 154 additions and 0 deletions

129
Code.java Normal file
View File

@ -0,0 +1,129 @@
import java.io.*;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.Scanner;
import java.lang.Math;
public class Code {
public static boolean toss(double probability) {
return (boolean) (Math.random() < probability);
}
public static void fill_value(int[][] arr , double probability ) {
for(int i = 0 ; i < 3 ; ++i) {
for(int j = 0 ; j < 3 ; ++j) {
if(toss(probability)) {
arr[i][j] = 1;
}else {
arr[i][j] = 0;
}
}
}
}
public static void main(String[] args) {
try {
// ==========================input ==================================
ArrayList <Integer> widths = new ArrayList(Arrays.asList(3 , 4 , 6 , 2 , 8));
ArrayList <Double> pr = new ArrayList(Arrays.asList(0.2 , 0.3 , 0.6 , 0.9 , 0.1) );
double ans[][] = new double[5][5];
for (int ii = 0; ii < widths.size(); ii++) {
for (int jj = 0; jj < pr.size(); jj++) {
double totaltime = 0;
for(int k = 0 ; k < 5 ; ++k) {
int arr[][] = new int[3][3];
int height = 1;
int time = 0;
boolean ok = false;
while(height <= widths.get(ii)) {
ok = false;
fill_value(arr , pr.get(jj));
for(int i = 0 ; i< 3 ; ++i) {
for(int j = 0 ;j < 3 ; ++j) {
if(i == 0 && arr[i][j] == 0) {
++height;
time += 10;
ok = true;
break;
}
if(i == 1 && arr[i][j] == 0) {
time += 10;
ok = true;
break;
}
}
if(ok)break;
}
}
totaltime += time;
}
totaltime /= 5.0;
ans[ii][jj] = totaltime;
//myWriter.write(widths.get(ii)+" "+pr.get(jj)+" "+totaltime);
System.out.println(pr.get(jj)+","+widths.get(ii)+","+totaltime);
}
}
FileWriter myWriter = new FileWriter("output.txt");
for(int i=0;i<widths.size();i++)
{
for(int j=0;j<pr.size();j++)
{
myWriter.write(pr.get(j)+" "+widths.get(i)+" "+ans[i][j]);
}
}
myWriter.close();
} catch (Exception e) {
System.out.println("An error occurred.");
}
}
}

BIN
Lab0_ca.pdf Normal file

Binary file not shown.

25
output.txt Normal file
View File

@ -0,0 +1,25 @@
0.2,3,30.0
0.3,3,30.0
0.6,3,38.0
0.9,3,58.0
0.1,3,30.0
0.2,4,40.0
0.3,4,42.0
0.6,4,44.0
0.9,4,50.0
0.1,4,40.0
0.2,6,60.0
0.3,6,60.0
0.6,6,72.0
0.9,6,112.0
0.1,6,60.0
0.2,2,20.0
0.3,2,20.0
0.6,2,26.0
0.9,2,32.0
0.1,2,20.0
0.2,8,80.0
0.3,8,84.0
0.6,8,98.0
0.9,8,134.0
0.1,8,80.0