Santa has been told to expect some rough weather over the Pacific. This is pretty normal for this part of the journey. This year, Santa has decided to pre-programme his sleigh SatNav to so that is plots the perfect path. The SatNav needs to be given the correct data values. The trouble is, his data set is all over the place and there are some values that aren't even numbers! Each number in the data set points to another location in the data set. You will need to 'follow' these numbers until 50 locations in the data set have been visited. Once you land on the 50th number you will have your final value.
You may notice some string values, namely 'X' and 'Y'. We have been told that if you arrive on an 'X', you should look at the value in the previous index. If you land on a 'Y', look at the number in the next index.
You must start in the very middle of the list, rounding up might help here.
testData = [5, 'Y', 7, 2, 'X', 6, 1, 3]
For this example we will use 10 moves.
Find the middle index.
Length = 8
Middle = 4
Value at index 4 = "X"
Now for the moves:
After 10 moves, we end on index 3, where the value is:
2
satNavSettings = [3, 206, 95, 'Y', 112, 32, 'X', 161, 142, 189, 'Y', 189, 130, 53, 49, 83, 87, 131, 'Y', 1, 170, 'X', 46, 168, 227, 47, 60, 'Y', 234, 207, 31, 'X', 206, 172, 151, 235, 'Y', 43, 222, 39, 'Y', 88, 83, 16, 21, 205, 'X', 198, 56, 195, 160, 161, 198, 108, 'X', 94, 179, 39, 43, 'X', 53, 74, 24, 1, 169, 48, 240, 25, 193, 203, 118, 63, 'X', 96, 102, 147, 133, 'X', 'Y', 107, 18, 191, 160, 192, 229, 146, 138, 198, 205, 199, 94, 138, 162, 40, 182, 71, 176, 79, 68, 127, 68, 57, 236, 249, 240, 29, 49, 'X', 70, 231, 81, 20, 95, 11, 42, 210, 86, 4, 244, 203, 'Y', 222, 26, 149, 146, 41, 'Y', 220, 'X', 54, 169, 'Y', 'Y', 134, 137, 196, 42, 113, 170, 100, 209, 153, 121, 82, 205, 98, 15, 125, 'Y', 45, 14, 56, 118, 16, 232, 191, 99, 62, 'Y', 121, 'X', 'X', 239, 55, 188, 195, 50, 231, 144, 25, 61, 72, 95, 115, 144, 116, 'X', 'X', 8, 139, 'X', 103, 22, 29, 114, 145, 56, 249, 'X', 226, 205, 2, 185, 207, 'Y', 'X', 52, 78, 102, 240, 65, 236, 65, 'X', 39, 203, 'X', 55, 157, 131, 54, 236, 103, 164, 208, 144, 'Y', 138, 123, 'Y', 235, 231, 181, 231, 69, 228, 101, 100, 32, 59, 'Y', 118, 4, 216, 234, 42, 161, 111, 63, 221, 89, 128, 197, 222, 146, 77, 34, 178, 194, 105, 'Y', 131, 76, 153, 107, 25, 137, 182, 'Y', 'Y', 100, 17, 56, 87, 64, 158, 158, 'Y', 81, 149, 113, 81, 26, 75, 129, 136, 69, 66, 'X', 240, 37, 60, 12, 36, 37, 149, 45, 'Y', 133, 210, 192, 40, 207, 'X', 93, 55, 139, 19, 65, 142, 184, 7, 227, 'X', 176, 189, 240, 75, 133, 183, 52, 231, 'X', 44, 129, 170, 28, 106, 195, 115, 104, 34, 58, 190, 26, 72, 31, 170, 247, 151, 55, 80, 249, 'X', 158, 108, 27, 57, 90, 49, 'Y', 'X', 243, 'Y', 221, 54, 45, 212, 'X', 234, 'Y', 'X', 213, 245, 4, 150, 163, 4, 26, 250, 99, 'Y', 250, 169, 213, 219, 219, 176, 181, 'Y', 4, 31, 'Y', 211, 'X', 70, 52, 104, 143, 47, 69, 38, 98, 28, 105, 49, 108, 145, 70, 'X', 168, 239, 'Y', 114, 197, 170, 168, 195, 112, 231, 43, 113, 'Y', 8, 'Y', 'X', 88, 140, 163, 21, 64, 188, 138, 69, 207, 89, 'Y', 80, 137, 47, 27, 112, 246, 183, 110, 196, 91, 112, 244, 202, 91, 235, 195, 206, 171, 96, 161, 208, 174, 129, 52, 85, 88, 63, 239, 214, 59, 'X', 204, 'X', 194, 241, 247, 'Y', 120, 243, 59, 26, 223, 182, 153, 250, 'X', 131, 99, 51, 30, 46, 29, 32, 'Y', 88, 'X', 220, 196, 8, 125, 1, 'X', 'X', 169, 192, 182, 6, 153, 57, 'Y', 115, 10, 229, 'X', 145, 83, 109, 84, 5, 143, 'X', 78, 108, 223, 'Y', 193, 'X', 43, 95, 'Y', 'Y', 58, 194, 237, 228, 'Y', 210, 64, 236, 220, 'Y', 165, 156, 71, 175, 66, 232, 221, 140, 206, 183, 41, 79, 131, 'X', 203, 248, 234, 'X', 146, 20, 220, 43, 'Y', 'X', 15, 'Y', 212, 219, 55, 154, 180, 170, 179, 'X', 173, 7, 117, 1, 96, 8, 240, 114, 185, 124, 30, 'Y', 195, 102, 215, 96, 24, 89, 240, 178, 157, 5, 'Y', 105, 24, 69, 235, 174, 'X', 207, 99, 'X', 'Y', 156, 192, 222, 'Y', 134, 177, 'Y', 208, 193, 100, 73, 237, 30, 217, 194, 244, 64, 48, 168, 61, 98, 21, 68, 167, 54, 52, 'X', 114, 119, 221, 133, 186, 101, 162, 215, 30, 71, 167, 208, 110, 165, 'X', 'Y', 66, 6, 136, 74, 247, 44, 219, 194, 49, 150, 91, 114, 'X', 218, 133, 128, 224, 'Y', 218, 50, 187, 77, 207, 113, 'X', 22, 'Y', 237, 46, 33, 'Y', 23, 132, 192, 'X', 83, 235, 180, 98, 79, 'X', 66, 33, 'Y', 103, 230, 183, 15, 65, 243, 48, 112, 41, 209, 'Y', 242, 109, 121, 131, 157, 161, 25, 'X', 226, 249, 197, 202, 206, 'X', 191, 184, 167, 89, 144, 80, 54, 170, 242, 235, 211, 'Y', 44, 78, 38, 196, 193, 189, 13, 12, 139, 161, 103, 241, 80, 102, 'Y', 45, 133, 'X', 213, 83, 172, 13, 50, 152, 134, 114, 190, 124, 147, 49, 13, 169, 88, 171, 200, 10, 132, 197, 176, 244, 171, 241, 200, 15, 'X', 168, 81, 'X', 'X', 204, 48, 166, 223, 104, 'Y', 191, 211, 'X', 132, 68, 94, 186, 36, 248, 91, 120, 'Y', 'Y', 'Y', 21, 188, 'X', 38, 174, 144, 177, 96, 140, 220, 8, 111, 5, 71, 146, 'X', 34, 'Y', 189, 147, 99, 86, 'X', 'Y', 55, 171, 247, 161, 140, 'X', 41, 151, 1, 247, 189, 52, 162, 58, 156, 'X', 61, 37, 'Y', 211, 149, 92, 149, 197, 118, 94, 10, 'Y', 69, 58, 233, 116, 86, 59, 244, 12, 193, 96, 'X', 128, 235, 224, 52, 218, 241, 177, 145, 16, 93, 23, 81, 153, 1, 32, 206, 210, 140, 38, 36, 1, 215, 'X', 73, 132, 155, 85, 162, 116, 235, 38, 82, 18, 64, 3, 84, 28, 128, 101, 'Y', 20, 135, 64, 116, 38, 144, 149, 'X', 73, 30, 71, 123, 135, 70, 68, 'Y', 51, 80, 23, 67, 'X', 82, 121, 3, 246, 16, 'Y', 86, 102, 198, 64, 'X', 223, 71, 172, 6, 33, 167, 23, 246, 217, 35, 213, 217, 140, 167, 124, 239, 38, 151, 'X', 29, 'X', 111, 25, 30, 112, 179, 229, 209, 'X', 126, 220, 201, 52, 249, 28, 115, 185, 107, 'X', 142, 77, 83, 215, 40, 171, 'X', 126, 35, 'X', 'Y', 69, 29, 200, 139, 221, 82, 68, 150, 135, 147, 225, 210, 127, 232, 11, 20, 200, 223, 106, 180, 85, 'Y', 'Y', 201, 174, 'Y', 68, 89, 173, 236, 61, 'Y', 71, 'X', 'X', 81, 'X']
Your job is to start at the middle position of the list and then follow the instructions 50 times.
The rules are:
If the value you land on is a number, that number tells you the next index you must jump to.
If you land on 'X', you must instead move one index backwards.
If you land on 'Y', you must instead move one index forwards.
After completing 50 moves, the value you land on is the final answer Santa needs.
You may assume:
all numeric values are valid indices,
the list is long enough that you will not go out of range.