cartesian

Generating all possible combinations of strings

前提是你 提交于 2019-12-04 12:43:46
I am trying to generate all possible combinations of a string. e.g. for the list below: a1q5z!H9, b1q5z!H9, c1q5z!H9, d1q5z!H9, a2q5z!H9 ... etc Rather than make lots of nested loops, I thought I would try something clever with MODULO ... but hit a wall. This is the Javascript I have come up with - any pointers to how I might go on? var c = [ ['a', 'b', 'c', 'd'], ['1', '2', '3', '4'], ['q', 'w', 'e', 'r'], ['5', '6', '7', '8'], ['z', 'x', 'c', 'v'], ['!', '"', '£', '$'], ['H', 'J', 'K', 'L'], ['9', '8', '7', '6'], ]; var o = document.getElementById('output'); var pw = ""; var chars = c.length

Quickly generate the cartesian product of a matrix

别等时光非礼了梦想. 提交于 2019-12-04 11:51:32
问题 Let's say I have a matrix x which contains 10 rows and 2 columns. I want to generate a new matrix M that contains each unique pair of rows from x - that is, a new matrix with 55 rows and 4 columns. E.g., x <- matrix (nrow=10, ncol=2, 1:20) M <- data.frame(matrix(ncol=4, nrow=55)) k <- 1 for (i in 1:nrow(x)) for (j in i:nrow(x)) { M[k,] <- unlist(cbind (x[i,], x[j,])) k <- k + 1 } So, x is: [,1] [,2] [1,] 1 11 [2,] 2 12 [3,] 3 13 [4,] 4 14 [5,] 5 15 [6,] 6 16 [7,] 7 17 [8,] 8 18 [9,] 9 19 [10,

Quickly generate the cartesian product of a matrix

风流意气都作罢 提交于 2019-12-03 07:20:19
Let's say I have a matrix x which contains 10 rows and 2 columns. I want to generate a new matrix M that contains each unique pair of rows from x - that is, a new matrix with 55 rows and 4 columns. E.g., x <- matrix (nrow=10, ncol=2, 1:20) M <- data.frame(matrix(ncol=4, nrow=55)) k <- 1 for (i in 1:nrow(x)) for (j in i:nrow(x)) { M[k,] <- unlist(cbind (x[i,], x[j,])) k <- k + 1 } So, x is: [,1] [,2] [1,] 1 11 [2,] 2 12 [3,] 3 13 [4,] 4 14 [5,] 5 15 [6,] 6 16 [7,] 7 17 [8,] 8 18 [9,] 9 19 [10,] 10 20 And then M has 4 columns, the first two are one row from x and the next 2 are another row from

Explicit sort in Cartesian transformation in Scala Spark

你。 提交于 2019-12-02 01:49:53
I am using Cartesian transformation in Spark Scala. If my input consists of 4 elements (could be numbers/characters/tuple) say var myRDD=sc.parallelize(Array("e1","e2","e3","e4")) myRDD.cartesian(myRDD) would yield all possible combination of pairs but not necessarily in order. What is a smart way to get those pairs in Order? i.e. Array((e1,e1), (e1,e2), (e1,e3), (e1,e4), (e2,e1), (e2,e2), (e2,e3), (e2,e4), (e3,e1), (e3,e2), (e3,e3), (e3,e4), (e4,e1), (e4,e2), (e4,e3), (e4,e4)) If what you need is to be able to identify each point (so you can determine the pair of points and their L2 distance)

is NATURAL JOIN any better than SELECT FROM WHERE in terms of performance? [duplicate]

徘徊边缘 提交于 2019-11-28 09:22:24
Possible Duplicate: Inner join vs Where Today I got into a debate with my project manager about Cartesian products. He says a 'natural join' is somehow much better than using 'select from where' because the later cause the db engine to internally perform a Cartesian product but the former uses another approach that prevents this. As far as I know, the natural join syntax is not any different in anyway than 'select from where' in terms of performance or meaning, I mean you can use either based on your taste. SELECT * FROM table1,table2 WHERE table1.id=table2.id SELECT * FROM table1 NATURAL JOIN

flip svg coordinate system

末鹿安然 提交于 2019-11-28 05:38:05
Is there a way to flip the SVG coordinate system so that [0,0] is in the lower left instead of the upper left? I have done a lot of experimentation, and the only logical method is as follows: <g transform="translate(0,400)"> <g transform="scale(1,-1)"> Where 400 is the height of the image. What this does it move everything down so that the top of the image is now and the bottom of the image, then the scale operation flips the Y coordinates, so that the bit that is now off the page/image is flipped back up to fill the space left behind. cchamberlain The best all around combo I've found for

is NATURAL JOIN any better than SELECT FROM WHERE in terms of performance? [duplicate]

旧时模样 提交于 2019-11-27 02:51:21
问题 Possible Duplicate: Inner join vs Where Today I got into a debate with my project manager about Cartesian products. He says a 'natural join' is somehow much better than using 'select from where' because the later cause the db engine to internally perform a Cartesian product but the former uses another approach that prevents this. As far as I know, the natural join syntax is not any different in anyway than 'select from where' in terms of performance or meaning, I mean you can use either based

Converting longitude/latitude to X/Y coordinate

老子叫甜甜 提交于 2019-11-26 23:46:08
I created a map using Google Maps API that highlights all Minnesota counties. Basically, I created the county polygons using a set of longitudes/latitudes coordinates. Here's a screenshot of the generated map:- One of the user requirements is to be able to have a similar map as an image so that they can embed it in their PowerPoint/keynote slides. I couldn't find any useful Google Maps API that allows me to save my custom map the way it is (if you know a way, let me know), so I figure I should just draw it with Graphics2D in Java. After reading about the formulas to convert the longitude

Converting longitude/latitude to X/Y coordinate

白昼怎懂夜的黑 提交于 2019-11-26 08:47:14
问题 I created a map using Google Maps API that highlights all Minnesota counties. Basically, I created the county polygons using a set of longitudes/latitudes coordinates. Here\'s a screenshot of the generated map:- One of the user requirements is to be able to have a similar map as an image so that they can embed it in their PowerPoint/keynote slides. I couldn\'t find any useful Google Maps API that allows me to save my custom map the way it is (if you know a way, let me know), so I figure I