Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Problem statement :
- A luminous portal at the far end of the vault draws your attention. That must be your final destination! Cross n... Oh, stop!
- Looks like the sine generator that powers the destination aligner is malfunctioned.
- You wouldn't want to be transported into deep space, would you?
- The signal from the sine generator appears to suffer from random interruptions. You can GET the generator output from http://challenge.five.agency/portal/generator. Fill in the missing values and POST it to the same endpoint in the same format. You have 3 seconds!
- My code :
- var all_n = [];
- var selection= [];
- var solution = [];
- var start = new Date().getTime();
- var end = 0;
- var req = $.ajax({
- url: "portal/generator",
- method: "GET",
- async: false,
- dataType: "text"
- });
- req.done(
- function(data){
- var d = data.split(",");
- for(var i=0;i<d.length;i++){
- if(d[i]!="x.xx"){
- if(selection.indexOf(Math.abs(parseFloat(d[i]))) == -1){
- if(Math.abs(parseFloat(d[i]))!=0.0){
- selection.push(parseFloat(d[i]))
- selection.push(-parseFloat(d[i]))
- }
- else{
- selection.push(0.0)
- }
- }
- }
- }
- selection.sort(function(a,b){return a-b});
- for(var i=0;i<d.length;i++){
- if(d[i]=="x.xx"){
- p = parseFloat(d[i-1]);
- n = parseFloat(d[i+1]);
- if(p==n){
- if(p>0){
- solution.push(parseFloat(selection[selection.length - 1]).toFixed(2));
- }else{
- solution.push(parseFloat(selection[0]).toFixed(2));
- }
- }else{
- solution.push(parseFloat(selection[(selection.indexOf(p) + selection.indexOf(n))/2]).toFixed(2));
- }
- }else{
- solution.push(parseFloat(d[i]).toFixed(2));
- }
- }
- var request = $.ajax({
- url: "portal/generator",
- method: "POST",
- async: false,
- data: { data : solution.join(",") },
- dataType: "text"
- });
- request.done(function( msg ) {
- console.log( msg );
- });
- end = new Date().getTime();
- console.log(end - start);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement