combinatorics

Finding Strings Neighbors By Up To 2 Differing Positions

帅比萌擦擦* 提交于 2019-12-21 20:00:14
问题 Given a seed string, I want to find its neighbors with at most differ in 2 positions. All the digits involve in generating string are only four (i.e. 0,1,2,3). This is the example for what I mean: # In this example, 'first' column # are neighbors with only 1 position differ. # The rest of the columns are 2 positions differ Seed = 000 100 110 120 130 101 102 103 200 210 220 230 201 202 203 300 310 320 330 301 302 303 010 011 012 013 020 021 022 023 030 031 032 033 001 002 003 Seed = 001 101

How many ways to represent a number from a given set of numbers

若如初见. 提交于 2019-12-21 19:58:10
问题 I want to know in how many ways can we represent a number x as a sum of numbers from a given set of numbers {a1.a2,a3,...}. Each number can be taken more than once. For example, if x=4 and a1=1,a2=2, then the ways of representing x=4 are: 1+1+1+1 1+1+2 1+2+1 2+1+1 2+2 Thus the number of ways =5. I want to know if there exists a formula or some other fast method to do so. I can't brute force through it. I want to write code for it. Note: x can be as large as 10^18. The number of terms a1,a2,a3

Calculate possible permutations of an array of numbers

筅森魡賤 提交于 2019-12-21 17:39:27
问题 I have an NSArray with the numbers {0,1,2,3} Calculating the factorial of 4 (the count of the array), I have 24 possible permutations of 0,1,2,3 I would like to know if there is a way to calculate all of these possible permutations and place them in a separate array. For example, given the numbers above, {0,1,2,3}, the resulting permutations would be: 0123, 0132, 0213, 0231, 0312, 0321, 1023, 1032, 1203, 1230, 1302, 1320, 2013, 2031, 2103, 2130, 2301, 2310, 3012, 3021, 3102, 3120, 3201, 3210

Algorithm for Grouping

孤人 提交于 2019-12-21 17:28:52
问题 I am trying to help someone write a program that I thought would be easy, but of course it never is :) I am trying to take a class roster (usually between 10-20 students) and effectivly uniquely pair off each classmate to another to make unique groups. Therefore in a class of 10 people, you can have 9 groups. It needs to be able to handle odd number of students too, adding to my confusion. I was looking at doing this in Java, but that is flexible. Any ideas on an algorithmic way to guarantee

bin packing with overlapping objects

杀马特。学长 韩版系。学妹 提交于 2019-12-21 02:59:08
问题 I have some bins with different capacities and some objects with specified size. The goal is to pack these objects in the bins. Until now it is similar to the bin-packing problem. But the twist is that each object has a partial overlap with another. So while object 1 and 2 has sizes s1 and s2, when I put them in the same bin the filled space is less than s1+s2. Supposing that I know this overlapping value for each pair of objects, is there any approximation algorithm like the ones for

In R, how do I get all possible combinations of the values of some vectors?

♀尐吖头ヾ 提交于 2019-12-20 20:31:15
问题 The background: I have a function which takes some parameters. I want to have the result of the function for all possible parameter combinations. A simplified example: f <- function(x, y) { return paste(x, y, sep=",")} colors = c("red", "green", "blue") days = c("Monday", "Tuesday") I want my result to look like color day f [1,] "red" "Monday" "red,Monday" [2,] "red" "Tuesday" "red,Tuesday" [3,] "green" "Monday" "green,Monday" [4,] "green" "Tuesday" "green,Tuesday" [5,] "blue" "Monday" "blue

List all possible combinations of k integers between 1…n (n choose k)

回眸只為那壹抹淺笑 提交于 2019-12-20 12:29:23
问题 Out of no particular reason I decided to look for an algorithm that produces all possible choices of k integers between 1...n, where the order amongst the k integer doesn't matter (the n choose k thingy). From the exact same reason, which is no reason at all, I also implemented it in C#. My question is: Do you see any mistake in my algorithm or code? And, more importantly, can you suggest a better algorithm? Please pay more attention to the algorithm than the code itself. It's not the

Combinatorial Optimization Matching in SQL

半腔热情 提交于 2019-12-20 11:31:22
问题 I am having trouble developing a matching algorithm in SQL. I have one table subjects . Each of these needs to be matched to the same number of rows in the table controls (for the sake of this question let's say two rows or controls need to be selected for each subject). The location of the selected controls must match exactly, and the controls selected should have a value in match_field that is as close as possible to the subjects. Here is some sample data: Table subjects: id location match

Calculate the number of ways to roll a certain number

十年热恋 提交于 2019-12-20 09:36:43
问题 I'm a high school Computer Science student, and today I was given a problem to: Program Description: There is a belief among dice players that in throwing three dice a ten is easier to get than a nine. Can you write a program that proves or disproves this belief? Have the computer compute all the possible ways three dice can be thrown: 1 + 1 + 1, 1 + 1 + 2, 1 + 1 + 3, etc. Add up each of these possibilities and see how many give nine as the result and how many give ten. If more give ten, then

Pair combinations of elements in dictionary without repetition

大兔子大兔子 提交于 2019-12-20 04:22:11
问题 In python, I have a dictionary like this... pleio = {'firstLine': {'enf1': ['54', 'set'], 'enf2': ['48', 'free'], 'enf3': ['34', 'set'], 'enf4': ['12', 'free']} 'secondLine':{'enf5': ['56','bgb'] 'enf6': ['67','kiol'] 'enf7': ['11','dewd'] 'enf8': ['464','cona']}} I would like to make paired combinations with no repetition of the elements in the inner dictionary, to end up with a result like this... {'enf3': ['34', 'set'], 'enf2': ['48', 'free']} {'enf3': ['34', 'set'], 'enf1': ['54', 'set']}