There are 30 characters (26 Latin characters and numbers 1,2,3,4). It is necessary to form 30 sets of 6 characters each, satisfying the requirements:

  1. all characters are randomly distributed
  2. in one set of 6 characters all characters are unique (i.e. not repeated)
  3. for each set of 6 characters there is another set that matches only 1 character

How can this be implemented through js?

  • What have you tried to do? What exactly did not work out? - Dmitriy Simushev
  • @DmitriySimushev The problem is that I don’t know which way to approach this, where to start and how it is solved in principle - angelzzz
  • one
    If this is a learning task, then it is better to start with a consultation with a teacher. Otherwise, it is worth starting with the basics of combinatorics. - Dmitriy Simushev
  • @DmitriySimushev is not a learning task. This is a task that I set myself. Since there is no representation I turned to the community. - angelzzz
  • Read the book on combinatorics, really. Your question is not about programming. - VladD

1 answer 1

Somehow, for example:

var symbols = 'qwertyuiopasdfghjklzxcvbnm1234'; var symArr = []; for (var i = 0; i < symbols.length; i++) { symArr.push(symbols.charAt(i)); } symArr.sort(randSort); var savedPos = -1; var savedChar = ''; var prevRes = ''; for (var i = 0; i < 30; i++) { for (var res = '', j = 0; res.length < 6; j++) { if (savedPos == res.length) { res += savedChar; continue; } if (prevRes.indexOf(symArr[j]) > -1) { continue; } res += symArr[j]; } savedPos = Math.floor(Math.random() * 6); savedChar = res.charAt(savedPos); symArr.sort(randSort); prevRes = res; console.log(res); } function randSort() { return Math.random() - 0.5; }; 
  • No restrictions on the uniqueness of characters in the set - Dmitriy Simushev
  • Why not? There is. Characters in one set are guaranteed not to repeat. :) There is another problem, did not immediately notice that there must be a set that differs in exactly one character. - Yaant
  • It seems to you that the characters do not repeat. I execute in the FF console, for example, I get the following sequence: nncm4h . Or such a sesgk2 . Or such 2ilcec . etc. - Dmitriy Simushev
  • Hmm, yes, I understand what the problem is. Just corrected the code so that the third condition was fulfilled, now, as required, there is another one for any set (specifically, the next and previous ones in which exactly one character matches (however, other sets that match the same the number of characters, the condition does not prohibit it.) The problem of repetitions should be corrected along the way. - Yaant
  • @Yaant thanks. Apparently I didn’t correctly formulate the task: I get these options when executing your code: