Solution:
import random
def genrate(items, isOut):
middleIndex=len(items)/2
riffledItems=[0]*len(items);
j=0;
for i in range(middleIndex): #indexes from 0 to
lenght/2
if(isOut):
riffledItems[j]=items[i] #maintain a indexing paramenter j and
assign values accordigly
j=j+1
riffledItems[j]=items[i+middleIndex] #for out riffling add len/2
value to i value for getting
j=j+1
else:
riffledItems[j]=items[i+middleIndex] #if it is false, do the
assignment in reverse order.
j=j+1
riffledItems[j]=items[i]
j=j+1
return riffledItems
def riffle_generator(seed):
items=[]
random.seed(seed)
for i in range(1000):
n = random.randint(0, 100)
items = [random.randint(0, 10**6)
for j in range(2 * n)]
#items=[1,2,3,4,5,6] Un comment this for testing
purpose
print "out riffle",genrate (items, True)
print "in riffle",genrate(items, False)
riffle_generator(2)
code refrence image:
![fe py import random Eder genrate (items, isout): 3 middle Index -len (items)/2 riffledItems-[0]*len (items); i-0; for i in ra](http://img.homeworklib.com/images/a172f4db-67b8-443b-a90d-35b2a3cb32e5.png?x-oss-process=image/resize,w_560)
output:
output with sample array:
![D:\SEGG>python riffle.py out riffle [1, 4, 2, 5, 3, 6] in riffle [4, 1, 5, 2, 6, 3] D:\SEGG>](http://img.homeworklib.com/images/f6df7330-ef90-4555-9670-36605caf0fd8.png?x-oss-process=image/resize,w_560)
Help with solution using Python test using def riffle_generator(seed): random.seed(seed) for i in range(1000): n =...
How to solve this Python problem?
Calling all units, B-and-E in progress def is..kerfectbeker(n): A positive integer n is said to be a perfect power if it can be expressed as the power b**e for some two integers band e that are both greater than one. (Any positive integer n can always be expressed as the trivial power n**1, so we don't care about that.) For example, the integers 32, 125 and 441 are perfect powers since they equal 2**5,5**3...
PYTHON: MUST NOT USE PYTHONS BUILT IN FUNCTIONS SUCH AS result.append MUST BE SOLVED OUT WITHOUT SUCH FUNCTIONS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 1. Write a function interleave(vals1, vals2) that takes as inputs two lists vals1 and vals2 and uses recursion to construct and return a new string that is formed by interleaving the elements in the lists vals1 and vals2 to create a single list. In other words, the new list should alternate elements from the two input lists: the first element from vals1,...
def selectionSortK(alist, k):
for i in range(0,len(alist) - 1):
min = i
for j in range(i + 1, len(alist)):
if alist[j] < alist[min]:
min = j
temp = alist[i]
alist[i] = alist[min]
alist[min] = temp
P3: Sanity Test: Is selectionSortK callable? ... ok
test_doNothing (__main__.TestProblem3)
P3: Does sorting the first k elements with k=0 do nothing? ...
ok
test_onePass (__main__.TestProblem3)
P3: Sorting a portion of a decreasing list ... FAIL
test_severalPasses (__main__.TestProblem3)
P3: Sorting a decreasing list in several stages...
I need a python 3 help. Please help me with this question Part 2. Linked Lists You start working with the class LinkNode that represents a single node of a linked list. It has two instance attributes: value and next. class LinkNode: def __init__(self,value,nxt=None): assert isinstance(nxt, LinkNode) or nxt is None self.value = value self.next = nxt Before you start with the coding questions, answer the following questions about the constructor Valid Constructor or Not? LinkNode(1, 3) LinkNode(1, None) LinkNode(1,...
*Java* Hi. I need some help with creating generic methods in Java. Write a program GenMethods that has the following generic methods: (1) Write the following method that returns a new ArrayList. The new list contains the nonduplicate (i.e., distinct) elements from the original list. public static ArrayList removeDuplicates(ArrayList list) (2) Write the following method that shuffles an ArrayList. It should do this specifically by swapping two indexes determined by the use of the random class (use Random rand =...
I really need help with this python programming assignment Program Requirements For part 2, i need the following functions • get floats(): It take a single integer argument and returns a list of floats. where it was something like this def get_floats(n): lst = [] for i in range(1,n+1): val = float(input('Enter float '+str(i)+': ')) lst.append(val) return lst • summer(): This non-void function takes a single list argument, and returns the sum of the list. However, it does not use...
*URGENT JAVA PROGRAMMING LAB* so I need to write some classes for my lab if someone could give me an outline or just how I should so it that would be awesom here is the questions please help ASAP A. A histogram is used to plot tabulated frequencies. Create a Histogram class that can be used to maintain and plot the frequencies of numbers that fall within a specified range. The Histogram class contain will an array of counters with...
Greeting! Kindly help me to solve my finals in PYTHON, I don't have a knowledge in PYTHON, new student. Please, please, I'm begging, Kindly answers all the questions. I'm hoping to grant my request. Thanks in advanced. 1.) What is the output of the following snippet? l1 = [1,2] for v in range(2): l1.insert(-1,l1[v]) print(l1) a.) [1, 2, 2, 2] b.) [1, 1, 1, 2] c.) [1, 2, 1, 2] d.) [1,...
Question A matrix of dimensions m × n (an m-by-n matrix) is an ordered collection of m × n elements. which are called eernents (or components). The elements of an (m × n)-dimensional matrix A are denoted as a,, where 1im and1 S, symbolically, written as, A-a(1,1) S (i.j) S(m, ). Written in the familiar notation: 01,1 am Gm,n A3×3matrix The horizontal and vertical lines of entries in a matrix are called rows and columns, respectively A matrix with the...
PYTHON! The Sieve of Eratosthenes THANKS FOR
HELP!
A prime integer is any integer greater than 1 that is evenly
divisible only by itself and 1. The Sieve of Eratosthenes is a
method of finding prime numbers. It operates as follows:
Create a list with all elements initialized to 1 (true). List
elements with prime indexes will remain 1. All other elements will
eventually be set to zero.
Starting with list element 2, every time a list element is found...