клиенту, естественно, верить нельзя
let arr = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3];
var seed = 12837823631;
arr = arr.sort((a,b)=>rand() - rand());
function rand(){
seed = (45 * seed + 21) % 67;
return seed/67;
}
"абвгдежзийклмнопрстуфхцчшщъыьэюя яюэьыъщшчцхфутсрпонмлкйизжедгвба"
, то должен вернуться 0.function result(line) {
let arr = line.split(' ');
let word1 = arr[0].split('');
let word2 = arr[1].split('');
if (word1.length != word2.length)
return 0;
var abc = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя";
for (var i = 0; i < word1.length; i++)
if (!word1.every((e, j) => (e !== word1[i]) || (e == word1[i] && word2[j] == word2[i])))
return 0;
var i = 0;
while (word1.join("") != word2.join("")) {
if (word1[i] != word2[i]) {
var repS = word2[i];
if (word1.join("").indexOf(repS) != -1) {
var tempAbc = abc.split("").filter(w => word1.join("").indexOf(w) == -1);
if (tempAbc.length == 0)
return 0;
repS = tempAbc.pop();
}
word1 = word1.join("").replace(new RegExp(word1[i], "g"), repS).split("");
console.log(word1)
}
i = (i + 1) % word1.length;
}
return 1;
}
double getRand(){//возвращает рандом от 0 до 1
return (double)rand()/(double)RAND_MAX;
}
string ChanceItemDrop(){
string itemsRandom[] = {
"a", "b", "c", "d", "e"
};
float itemsChance[] = {
.30f, .80f, .50f, .30f, .40f //шансы от 0 до 1, 1 -100% , 0 - 0%
};
int arrLen = sizeof(itemsChance)/sizeof(*itemsChance);
double r;
int arrSize;
do{
r = getRand();
arrSize = 0;
for(int i=0;i < arrLen;i++)
arrSize += r <= itemsChance[i]?1:0;
}while(arrSize == 0);
int* inxs= new int[arrSize];
for(int i=0,p = 0;i < arrLen;i++)
if(r <= itemsChance[i])
inxs[p++] = i;
string result = itemsRandom[inxs[(int)floor(getRand()*arrSize)]];
free(inxs);
return result;
}
const firstNonRepeatingLetter = str => {
let charMap = {};
let strToLower = str.toLowerCase();
for (let char of strToLower) {
if (!charMap[char]) {
charMap[char] = 1;
} else {
charMap[char]++;
}
}
for (let char in charMap) {
if (charMap[char] === 1) {
var i = str.indexOf(char);
if( i == -1)
i = str.indexOf(char.toUpperCase())
else if(str.indexOf(char.toUpperCase()) != -1 && str.indexOf(char.toUpperCase()) < i)
i = str.indexOf(char.toUpperCase());
return str.charAt(i);
}
}
return '';
};
function firstNonRepeatingLetter(str) {
for(var i = 0 ; i < str.length;i++)
if((str.substring(0,i)+str.substring(i+1)).indexOf(str.charAt(i).toLowerCase()) == -1 && (str.substring(0,i)+ str.substring(i+1)).indexOf(str.charAt(i).toUpperCase()) == -1)
return str.charAt(i);
return '';
}