Answer:
# Python program to shuffle a deck of card
# importing modules
import itertools, random
# make a deck of cards
deck = list(itertools.product(range(1,14),['Spade','Heart','Diamond','Club']))
# shuffle the cards
random.shuffle(deck)
# draw five cards
print("You got:")
for i in range(5):
print(deck[i][0], "of", deck[i][1])
Output
You got:
5 of Heart
1 of Heart
8 of Spade
12 of Spade
4 of Spade
Explanation:
Answer:
see below
Explanation:
The program of interest is the function "findMode[x, n]" in the attached. It is written the Wolfram Language of Mathematica.
The basic idea is that the data in the array is sorted. The sorted array is partitioned into sets of identical elements, and the number in each of those sets is counted. The maximum of those counts is the mode. The location of the maximum count corresponds to the location of the set having that count. We use that location information to pull out the mode value(s).
If there is more than one mode, all are reported.
__
An example data array is provided, along with the program output.
Answer:
Explanation:
Following are the Semaphores:
Customers: Counts waiting customers;
Barbers: Number of idle barbers (0 or 1)
mutex: Used for mutual exclusion.
Cutting: Ensures that the barber won’t cut another customer’s hair before the previous customer leaves
Shared data variable:
count_cust: Counts waiting customers. ------------copy of customers. As value of semaphores can’t access directly.
// shared data
semaphore customers = 0; semaphore barbers = 0; semaphore cutting = 0; semaphore mutex = 1;
int count_cust= 0;
void barber() {
while(true) { //shop is always open
wait(customers); //sleep when there are no waiting customers
wait(mutex); //mutex for accessing customers1
count_cust= count_cust-1; //customer left
signal(barbers);
signal(mutex);
cut_hair();
}
}
void customer() {
wait(mutex); //mutex for accessing count_cust
if (count_cust< n) {
count_cust= count_cust+1; //new customer
signal(customers); signal(mutex);
wait(barbers); //wait for available barbers get_haircut();
}
else { //do nothing (leave) when all chairs are used. signal(mutex);
}
}
cut_hair(){ waiting(cutting);
}
get_haircut(){
get hair cut for some time; signal(cutting);
}
Answer:
Explanation:
import java.util.Scanner;
import java.io.*;
public class ArrayProcessing
{
public static void main(String[] args) throws IOException
{
Scanner kb = new Scanner(System.in);
String fileName;
System.out.print("Enter input filename: ");
fileName = kb.nextLine();
File file = new File(fileName);
if(!file.exists())
{
System.out.println("There is no input file called : " + fileName);
return;
}
int[] numbers = inputData(file);
printArray(numbers);
}
public static int[] inputData(File file) throws IOException
{
Scanner inputFile = new Scanner(file);
int index = 1;
int size = inputFile.nextInt();
int[] values = new int[size];
while(inputFile.hasNextInt() && index < values.length)
{
values[index] = inputFile.nextInt();
index++;
}
inputFile.close();
return values;
}
public static void printArray(int[] array)
{
int count = 1;
for (int ndx = 1; ndx < array.length; ndx++)
{
System.out.printf("%5.f\n", array[ndx]);
count++;
}
if(count == 10)
System.out.println("");
}
}
Answer:
The analysis is presented throughout the section described, as per the given situation.
Explanation:
- Those requirements as well as agreements do not apply to something like the acquisition of the commodity. But perhaps the terms and agreements are all about the use of the name. This means that for illegal or immoral procedures, when and how to use the item and even the component shouldn't be used.
- The overall profitability certainly comes with either the commodity themselves as well as during implementation, trying to give one's authorization has always been about the service mostly with the supplier.
However, during implementation, the contract is something different from the place where you live throughout your purchase.