shuffle

oneliner scramble program

…衆ロ難τιáo~ 提交于 2019-12-24 05:49:15
问题 It's that time of year again that programmers want to shuffle a list such that no element resides on its original position (at least in the Netherlands, we celebrate Sinterklaas and pick straws for deciding who writes who a poem). Does anyone have a nice Python single statement for that? So, input example: range(10) Output example: [2,8,4,1,3,7,5,9,6,0] Wrong output would be [2,8,4,1,3,5,7,9,6,0] because the 5 is at its original position. This would mean that person 5 must write a poem to

Shuffling a 2D array without using Collections

亡梦爱人 提交于 2019-12-24 00:45:21
问题 I don't know how to shuffle 2D array without duplicate elements. Can anyone help me to shuffle a 2D array? Here is what I have so far: public class Shuffle2DArray { public Shuffle2DArray () { } public static void Main(string[] args) { int[,] a = new int[3, 3] { { 1, 2, 3, }, { 6, 7, 8 }, { 11, 12, 13 } }; Shuffle2DArray shuffle = new Shuffle2DArray (); shuffle.getshuffle2D (a); } void getshuffle2D(int[,] arr) { Random ran = new Random (); for (int i = 0; i < arr.GetLength (0); i++) { for (int

How to randomly shuffle “tiles” in a numpy array

时光毁灭记忆、已成空白 提交于 2019-12-23 19:56:25
问题 I have an nxn numpy array, and I would like to divide it evenly into nxn tiles and randomly shuffle these, while retaining the pattern inside the tiles. For example, if I have an array that's size (200,200), I want to be able to divide this into say 16 arrays of size (50,50), or even 64 arrays of size (25,25), and randomly shuffle these, while retaining the same shape of the original array (200,200) and retaining the order of numbers inside of the smaller arrays. I have looked up specific

Is there a way to apply the Knuth shuffle to a Stack data structure?

浪子不回头ぞ 提交于 2019-12-23 14:37:11
问题 For a programming class I am creating a blackjack program for the first homework assignment. The professor has given us a sample Card class, which includes the method to add them to a deck. For her deck, she uses an ArrayList, which you can easily Knuth Shuffle with the Collections.shuffle() method. That method does not work for Stacks though (obviously), but I think a Stack structure would work best for this program because you may pop and push cards into and out of the deck. 回答1: Both java

Can I make a Deterministic Shuffle in clojure?

你离开我真会死。 提交于 2019-12-23 07:29:51
问题 I'd like to make some shuffles of sets which will be the same every time my program is run: This is one way to do it: (def colours ["red" "blue" "green" "yellow" "cyan" "magenta" "black" "white"]) (defn colour-shuffle [n] (let [cs (nth (clojure.math.combinatorics/permutations colours) n)] [(first cs) (drop 1 cs)])) ; use (rand-int 40320) to make up numbers, then hard code: (def colour-shuffle-39038 (colour-shuffle 39038)) (def colour-shuffle-28193 (colour-shuffle 28193)) (def colour-shuffle

Randomly Shuffle Keys and Values in Python DIctionary

Deadly 提交于 2019-12-23 03:12:13
问题 Is there a way to randomly shuffle what keys correspond to what values? I have found random.sample but I was wondering if there was a more pythonic/faster way of doing this. Example: a = {"one":1,"two":2,"three":3} Shuffled: a_shuffled = {"one":2,"two":3,"three":1} 回答1: sorry the only way to make it faster is by using numpy :/. No matter what you do it has to somehow scramble all the indices which takes time - so doing it in C will help slightly. Also the difference between sheer random and

Java Collections.shuffle() weird behaviour [closed]

风流意气都作罢 提交于 2019-12-23 01:59:49
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . I am experiencing something weird. I have a big ArrayList of Long numbers. It contains about 200k numbers in ascending order. These numbers are always distinct; they are not necessarily consecutive, but some groups of them usually are. I want to extract a sorted sample of 5k from this list, so basically this is my

Java Collections.shuffle() weird behaviour [closed]

笑着哭i 提交于 2019-12-23 01:59:03
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . I am experiencing something weird. I have a big ArrayList of Long numbers. It contains about 200k numbers in ascending order. These numbers are always distinct; they are not necessarily consecutive, but some groups of them usually are. I want to extract a sorted sample of 5k from this list, so basically this is my

How to merge 2 sorted listed into one shuffled list while keeping internal order in c#

廉价感情. 提交于 2019-12-22 14:06:18
问题 I want to generate a shuffled merged list that will keep the internal order of the lists. For example: list A: 11 22 33 list B: 6 7 8 valid result: 11 22 6 33 7 8 invalid result: 22 11 7 6 33 8 回答1: Original Answer: static IEnumerable<T> MergeShuffle<T>(IEnumerable<T> lista, IEnumerable<T> listb) { var first = lista.GetEnumerator(); var second = listb.GetEnumerator(); var rand = new Random(); bool exhaustedA = false; bool exhaustedB = false; while (!(exhaustedA && exhaustedB)) { bool found =

Fisher-Yates shuffle on a single string vs. using an equal length permutation?

依然范特西╮ 提交于 2019-12-22 14:02:42
问题 Right now I am working on a suite of word games as a means of teaching myself (and recreating some of my favorite word games!) With the help of an 'actual' studied programming friend, we have implemented a nice permutation method in one of my classes. It is finding all permutations from 3 letters and up and comparing them to Lists of strings I have containing what is essentially the Scrabble tournament word list. That's the background, here is my current issue: I now have all of the