0
how i can determine all the combination of words from a matrix of type char
...
23 ответов
+ 6
@Gordie - I was literally just thinking that you could address any cell of a square matrix (m, n) with a mod:
00 01 02 03
04 05 06 07
08 09 10 11
12 13 14 15
If I want the 0-based coordinates (m,n) of cell 7:
7 % 4 = 1 R 3 (m=1, n=3 ... or second row, fourth column)
15 % 4 = 3 R 3 (3,3 = last cell)
Seeing other ideas online, I knew it was possible to make it cleaner / shorter.
Nice to see your solution :)
+ 4
Also, could you clarify "apartire" ? -- the closest I found was an Italian phrase.
+ 4
Just wondering... are you allowed to flatten the matrix and iterate it like a string?
+ 4
Use Recursion. I will explain later, I am busy, a lot busy.
+ 4
I'm just showing that permutations (repeats or not) can be a depth-1 counting problem that neither needs to recurse nor depends on the matrix size (not wrong, just alternate approaches).
It generalize (abstracts) to any flattened input matrix, so you just need to specify min=2 and max=16 ("repeats ok" flag stays false).
9: ... minWordLength = 1;
10: ... maxWordLength = 2;
It won't finish on SoloLearn though due to resource limits.
+ 3
An example would be nice
+ 2
I asked if it was acceptable to flatten the matrix because when the entire output range is from "1 to wordlength", then it's a short leap from an array with 10 "symbols":
['0','1','2','3','4','5','6','7','8','9']
length 1 words: 0,1,2,3,4,5,6,7,8,9
length 2 words: 01, 02, 03, 04 ... 09, 10, 12 ... 98
...to an array with 16 symbols (whatever they are), with the only restriction being 'you cannot reuse a symbol slot to make a word'.
When each 'letter slot' can now hold 16 values, you have base-16 arithmetic.
This can be abstracted to a linear loop from 0 to max value in that base (like 10³ or 16³ for three-letter words) with base symbol lookup:
https://code.sololearn.com/cxkw1gQzBN55/?ref=app
Other ways to look at the problem:
If you set "slotRecyclingOK=true" this is a password string generator capable of hitting all passwords between (e.g.) "a" to "zzzzzzzz..."
Permutations with/without symbol repeat
+ 1
well
let's say that i had this matrix :
a e r t
d o i l
f q v n
s w u g
i want my output to be [a,ae,ar,at,,ad,ao,do,fd,ai.......sw,sg]
all the combinaition of characters in the matrix.
that mean ervery char[i][j] would be combained my the other's
#it's for finding valid word in the matrix
0
This would print all two letter combinations from a 4x4 matrix a.
for (int f1 = 0; f1 < 4; f1++)
for (int s1 = 0; s1 < 4; s1++)
for (int f2 = 0; f2 < 4; f2++)
for (int s2 = 0; s2 < 4; s2++)
System.out.println(a[f1][s1]+a[f2][s2]);
0
Mr Jhon .. what if i want to print all the combination .. it mean from 2 letters to 16 letters in that matrix .. what can i do .
thnx for answering
0
thanx .. i think using récursion would help better
0
yeah . but less lines of code that's what i ment
0
thnx but i thïnk you dont get my question cearly. i want all the combination . from lenght=2 to lenght =16 . (row*column). all what a matrix can handle
:)
0
your the best <3
0
well . let's move now one step forward .. what if i want all the adjast combination where lenght = > 3;
a b c d
e f g h
i j k l
c v o p
output : abc,afg,afk,aei.
Or we can just gives all the adjacet cell from each cell
output :a adjact to (b,f,e) b:adjast to(a,c,,e,f,g) k:adjast to(fghejlcvop)
0
matrix must be 4x4;
1-it must contain random alphabet
2-in one word you cant repeat the same letter twice
0
you've undertsand the task.
just for (B).3. when creating a word you pick a random cell .
-adjacent cells are 10.
for example : cell adjacent to M[3][3] are :
M [2][2]M[3][2] M [4][2]M [2][3]M [2][4] M [4][2]M[4][3] M [4][4].
-A word must not containe the same letter twice ;
0
let's say the user gives you a word .
you must assure tha this word is formed by letters exist in the matrix.
then letters that formed the word must be also adjacent.
example :
M[4][4];
b e t y
r g d j
u s i o
p v f x
the user gives you the word (bred) like an input
so b-r-e-d exist in the matrix.
b adjacent to r , r adjacent to e , e adjacent to d.
(you get it ??)
you have to assure existence of letters and then their adjacency .
0
i need help please it's for my courses in java
0
you know boggle game , it's my project working for.
am a biginner in oop programming so . i need just to know how to begin(what should i put in classes ..etc..)
otherwise i can handle my self with some of your help.
if you hade facebook we can contact .
thnx anyway