-1

In a coding contest I have a programming task to find minimum or maximum from different arrays, and the final result to put it at the end of the URL (www.example.com/result).

I can't figure out what format are they expecting...

They gave this hint:

look at the resulting values and see if they could represent something familiar), at the end of the root of the URL of the page you're on (of course add a slash if needed)
Update
For the result of the problem, you need to figure out a way to convert those numbers to a "URL friendly form" value. For example, a URL friendly value means a string, so you need a 'standard' way to convert each number to a character and use the resulting string to go to the next problem.

I tried the following formats 1:2:3:4 , 1_2_3_4 no chance.

The numbers are 100,126,114,85,82,121,54 .

So I need them formatted in an url friendly form whatever that would mean.

This is the coding challenge :
You are given an input file containing:

On the first line a positive integer N
On the following N lines there will be arrays of integers, of variable length, each integer value separated by a white space from the next value
The start of each array will only contain one of the following possible numbers: 1 or -1
To get to the next step you will have to calculate the minimum (if start value is -1) or maximum (if start value is 1) of the arrays in the input file and then put the result, in a more human and URL friendly form (hint: look at the resulting values and see if they could represent somehting familiar), at the end of the root of the URL of the page you're on (of course add a slash if needed). Also keep the code used to solve this problem!

Here is your input data:

7

-1 156 198 171 134 197 120 149 177 130 100 103 126 169 115 199 188 119 168 151 161 167 141 111

-1 126 128 150 190 193 198 168 128 194 138 196 153 134 163 152 136 158 132 178 141 174 143 195 126 183 132 174 173 171 130 155 164 158

-1 178 115 166 161 164 134 130 164 147 114

1 73 78 81 66 77 0 26 42 48 42 12 24 33 4 54 31 50 34 78 13 21 37 29 85 56 68 12 79 81 82 25 7 16 44 32 82

1 62 35 54 82 30 7 28 78 74 34 12 80 40 16 5 39 29

-1 157 183 175 140 158 164 138 166 176 121 145 139 186 188 158 121 183 146 132 124 123 198 162 135 161 132 187 184 121 148 157 146 123 199 142 134 196 179

-1 70 74 81 105 121 129 148 91 160 76 146 94 64 154 54 102 142 68 62 88 63 144 143 138 118 117 148 166 146 159 162 130 183 184 156 172

aaaaaa
  • 3
  • 3
  • Welcome to SO. Please visit the [help] to see what and how to ask. HINT: Post effort and code. We are not a coding service – mplungjan Dec 02 '16 at 12:15
  • @mplungjan Wellcome to my question, first read the question text – aaaaaa Dec 02 '16 at 12:16
  • @mplungjan It's not coding, it's not code effort – aaaaaa Dec 02 '16 at 12:16
  • That is not how it works. I read the question and decided to help you understand why your question will otherwise be voted down and likely closed. It does not have enough information to help you. Show the arrays and what you expect as output – mplungjan Dec 02 '16 at 12:17
  • @mplungjan I don't need the minimum or the maximum from the arrays, I have the solution. I just dont know how to format the solution in an **url friendly form** . I will add the results – aaaaaa Dec 02 '16 at 12:20
  • The format of the URL is going to depend on what that URL is expecting. It is impossible for anyone to guess without more information. – ganzogo Dec 02 '16 at 12:23
  • @ganzogo That's my thought too, but they wont provide other information – aaaaaa Dec 02 '16 at 12:24
  • http://stackoverflow.com/questions/1856785/characters-allowed-in-a-url - so `arr.join("~")` – mplungjan Dec 02 '16 at 12:31
  • @mplungjan **www.example.com/challengeAccepted!** 100~126~114~85~82~121~54 not working – aaaaaa Dec 02 '16 at 12:49
  • Is this some kind of code quiz? – mplungjan Dec 02 '16 at 12:51
  • @mplungjan Yes it is, it's a coding contest. It annoys me that I get stuck on such problems, when the real problems should be the coding itself. – aaaaaa Dec 02 '16 at 12:52
  • How should we know? Sheez. Please give ALL important information in the question – mplungjan Dec 02 '16 at 12:53
  • @mplungjan I will edit the whole challenge in the question description, but it won't help more. – aaaaaa Dec 02 '16 at 12:54
  • see my update to the question. It is now more understandable – mplungjan Dec 02 '16 at 12:54
  • @mplungjan Thanks for the edit. Really understandable now – aaaaaa Dec 02 '16 at 13:12
  • Try alert(String.fromCharCode(100,126,114,85,82,121,54)) – mplungjan Dec 02 '16 at 13:16
  • @mplungjan cannot run the javascript, i just have to append my result to the url .. I added more informations which I received from them – aaaaaa Dec 02 '16 at 13:27

1 Answers1

0

Array.max = function( array ){
    return Math.max.apply( Math, array );
};
Array.min = function( array ){
    return Math.min.apply( Math, array );
};
function m(str) {
  var parts = str.split(" ");
  var what = parts.shift();
  if (what=="-1") return Array.min(parts);
  else return Array.max(parts);
}

var num=[];
num.push(7); // not sure about this one. Use the encode if yes

num.push(m("-1 156 198 171 134 197 120 149 177 130 100 103 126 169 115 199 188 119 168 151 161 167 141 111"))
num.push(m("-1 126 128 150 190 193 198 168 128 194 138 196 153 134 163 152 136 158 132 178 141 174 143 195 126 183 132 174 173 171 130 155 164 158"))
num.push(m("-1 178 115 166 161 164 134 130 164 147 114"))
num.push(m("1 1 73 78 81 66 77 0 26 42 48 42 12 24 33 4 54 31 50 34 78 13 21 37 29 85 56 68 12 79 81 82 25 7 16 44 32 82"))
num.push(m("1 62 35 54 82 30 7 28 78 74 34 12 80 40 16 5 39 29"))
num.push(m("-1 157 183 175 140 158 164 138 166 176 121 145 139 186 188 158 121 183 146 132 124 123 198 162 135 161 132 187 184 121 148 157 146 123 199 142 134 196 179"))
num.push(m("-1 70 74 81 105 121 129 148 91 160 76 146 94 64 154 54 102 142 68 62 88 63 144 143 138 118 117 148 166 146 159 162 130 183 184 156 172"))
var str = String.fromCharCode.apply(null, num);
console.log(num,str);
console.log(encodeURIComponent(str)); // if 7 is part of the numbers

// location = "http://www.example.com/"+str;
mplungjan
  • 169,008
  • 28
  • 173
  • 236