Program that produces random permutations of the no 1 to 10

Assignment Help Game Theory
Reference no: EM13944987

Write a program that produces random permutations of the numbers 1 to 10. To generate a random permutation, you need to fill an array with the numbers 1 to 10 so that no two entries of the array have the same contents. You could do it by brute force, by calling Random.nextInt until it produces a value that is not yet in the array. Instead, you should implement a smart method. Make a second array and fill it with the numbers 1 to 10. Then pick one of those at random, remove it, and append it to the permutation array. Repeat 10 times. Implement a class PermutationGenerator with a method

int[] nextPermutation

Use the following class as your main class:

/**
This class prints 5 permutations of the numbers 1 through 10.
*/
public class PermutationPrinter
{
public static void main(String[] args)
{
PermutationGenerator gen = new PermutationGenerator(10);

for (int i = 1; i <= 5; i++)
{
for (int n : gen.nextPermutation())
System.out.print(" " + n);
System.out.println();
}
}
}

Complete the following class in your solution:

import java.util.Random;

/**
This class generates permutations of a sequence of integers
1...length.
*/
public class PermutationGenerator
{
. . .

/**
Construct a PermutationGenerator object.
@param length the length of the permutations generated
by this generator.
*/
public PermutationGenerator(int length)
{
. . .
}

/**
Gets the next permutation.
@return the array containing the next permutation
*/
public int[] nextPermutation()
{
. . .
}
}

Reference no: EM13944987

Questions Cloud

The length of the wire segment ab : 1. In th ediagram below, wire segment AB is horizontal. The radius of loop is 6.00 inches. What is the length of the wire segment AB?
What is collateral on a loan that remains in the possession : What is collateral on a loan that remains in the possession of the borrower and not the bank?
Difference in payments : You buy a car today for $29,000. If you finance it with a 6% APR, 4 year loan, what is the difference in your payments if you agree to pay at the beginning of each month rather than at the end? Assume monthly compounding.
Discuss the rights and liabilities of the partners and lemon : Sophia and Ben did not know about this order until the films were delivered at their shop, with a bill for $8,000.00. Sophia and Ben were furious on learning of this transaction and contacted Lemon International Ltd to pick these goods from their par..
Program that produces random permutations of the no 1 to 10 : Write a program that produces random permutations of the numbers 1 to 10.
Average collection period and the average payment period : You know the following. ATO, ITO and FATO are 2, 6, and 2.5 respectively while for the industry they are 4.4, 19 and 4 respectively. The current ratio and quick ratio are 1 and 1.5 for the firm and 2.3 and 2.0 for the industry respectively. Net profi..
Discuss the research method needed to test : You can make suggestions for research hypotheses and discuss the research method needed to test them.
Preferred stock which pays-cops drops : We have a preferred stock which pays $ 8 per year. When we buy it, the cops is 8% .We keep it for 2 years and then sell it. At that time, cops drops to 4%. What is the price we sell it at? If the stock is called after 4 years at 120%, if the cops is ..
Average braking distance for a small car : It is advertised that the average braking distance for a small car traveling at 65 miles per hour is less than 120 feet. A transportation researcher wants to determine if the statement made in the advertisement is false. She randomly test drives 3..

Reviews

Write a Review

Game Theory Questions & Answers

  Use the best-response approach to find all nash equilibria

Player 1 has the following set of strategies {A1;A2;A3;A4}; player 2’s set of strategies are {B1;B2;B3;B4}. Use the best-response approach to find all Nash equilibria.

  A supplier and a buyer, who are both risk neutral

A supplier and a buyer, who are both risk neutral, play the following game,  The buyer’s payoff is q^'-s^', and the supplier’s payoff is s^'-C(q^'), where C() is a strictly convex cost function with C(0)=C’(0)=0. These payoffs are commonly known.

  Pertaining to the matrix game theory problem

Pertaining to the matrix need simple and short answers, Find  (a) the strategies of the firm (b) where will the firm end up in the matrix equilibrium (c) whether the firm face the prisoner’s dilemma.

  Nash equilibria

Consider the two-period repeated game in which this stage game is played twice and the repeated-game payo s are simply the sum of the payo s in each of the two periods.

  Find the nash equilibrium

Two players, Ben and Diana, can choose strategy X or Y. If both Ben and Diana choose strategy X, every earns a payoff of $1000.

  Construct the payoff matrix for the game

The market for olive oil in new York City is controlled by 2-families, Sopranos and Contraltos. Both families will ruthlessly eliminate any other family that attempts to enter New York City olive oil market.

  Question about nash equilibrium

Following is a payoff matrix for Intel and AMD. In each cell, 1st number refers to AMD's profit, while second is Intel's.

  Finding the nash equilibrium

Determine the solution to the given advertising decision game between Coke and Pepsi, assuming the companies act independently.

  Nash equilibria to determine the best strategy

Little Kona is a small coffee corporation that is planning entering a market dominated through Big Brew. Each corporation's profit depends on whether Little Kona enters and whether Big Brew sets a high price or a low price.

  Creating a payoff table

Suppose you and your classmate are assigned a project on which you will earn one combined grade. You each wish to receive a good grade, but you also want to avoid hard work.

  Determine the nash equilibrium for trade policy

Consider trade relations in the United State and Mexico. Suppose that leaders of two countries believe the payoffs to alternative trade policies are as follows:

  Find the nash equilibrium outcomes

Use the given payoff matrix for a simultaneous move one shot game to answer the accompanying questions.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd