Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var avg = prompt('¿Que calificación le pondría al profesor (0-100)?');
- var repre = prompt('¿Considera que el maestro toma represalias con los alumnos?\n1= Sí 2 3= No sé 4 5= No');
- var mySet = new Set();
- var aux = [];
- var cont= 0;
- var desfase= 5;
- var cont_ciclos= 0;
- var fDispersion= 1; /*(0-20), cambiara a los elementos asi de cercanos o lejanos*/
- avg = Number(avg);
- repre = Number(repre) - 1;
- if(Number.isNaN(avg) || Number.isNaN(repre))
- {
- alert('Error\nIngrese un número entero.');
- }
- else
- {
- for (var i = 0; i < 48; i++)
- {
- aux[i] = randomInt();
- }
- forzarPromedio();
- console.log(aux);
- $('input[type="radio"]').each(function(index)
- {
- if((index + 1) % 5 == 0)
- {
- mySet.add(this.name);
- }
- });
- for (var nm of mySet)
- {
- if (aux[cont] > 80)
- document['fPreguntas'][nm].item(0).checked = true;
- else if (aux[cont] > 60)
- document['fPreguntas'][nm].item(1).checked = true;
- else if (aux[cont] > 40)
- document['fPreguntas'][nm].item(2).checked = true;
- else if (aux[cont] > 20)
- document['fPreguntas'][nm].item(3).checked = true;
- else
- document['fPreguntas'][nm].item(4).checked = true;
- cont++;
- }
- document['fPreguntas'][Array.from(mySet)[25]].item(repre).checked = true;
- }
- function forzarPromedio()
- {
- cont_ciclos++;
- if(promedio() > (avg + desfase))
- aux.forEach(function(item, index)
- {
- (item + fDispersion * desfase) > avg ? aux[index]= randomInt( avg, item) : void(0)
- });
- else if(promedio() < (avg - desfase))
- aux.forEach(function(item, index)
- {
- (item - fDispersion * desfase) < avg ? aux[index]= randomInt( item, avg) : void(0)
- });
- if (promedio() > (avg + desfase) || promedio() < (avg - desfase))
- forzarPromedio();
- console.log('Vuelta ' + cont_ciclos + '\nPromedio: ' + promedio());
- }
- function randomInt(min= 0, max= 100)
- {
- return Math.round(Math.random() * (max-min)) + min;
- }
- function promedio()
- {
- return aux.reduce(function(acumulator, num, arr) { return acumulator + num; } ) / aux.length;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement