Here are the rules (Halite 3):
At each turn, you have to take one decision for your ship. You can either move right, move left, move up, move down or stay still (and gather ressoureces).
Moving your ship cost your ship 10% of current's cell available ressources.
Staying still cost you nothing and you pick 25% of current cell available ressources. If a ship doesn't have enought ressources to pay the 10% to move, he is pinned on the cell for this turn (can't go negative).
My goal: The ship starts at the center (0) and should return at this point with atleast (X amount of ressources) in the less turn possible.
How can I compute the most efficient path (round wise) that my ship should take to achieve my goal ?
Here is some code to compute a random map (the map is random every game) :
import random
how_Big = 11
center_Pos = int(how_Big/2) #how_Big must be even
game_Map = [[random.randint(1,500) for i in range(how_Big)] for x in range(how_Big)]
game_Map[center_Pos][center_Pos] = 0
for y in range(how_Big):
print(game_Map[y])
[110, 179, 97, 467, 347, 336, 368, 298, 107, 84, 123]
[415, 86, 12, 75, 354, 74, 250, 221, 51, 254, 252]
[368, 235, 389, 1, 155, 186, 149, 135, 458, 243, 344]
[391, 480, 485, 358, 416, 479, 270, 354, 203, 436, 146]
[62, 132, 490, 33, 445, 172, 127, 274, 130, 77, 356]
[239, 11, 459, 245, 214, 0, 324, 162, 58, 394, 202]
[241, 395, 46, 78, 191, 384, 203, 191, 56, 474, 237]
[85, 480, 181, 98, 122, 482, 90, 351, 257, 266, 182]
[398, 125, 195, 423, 219, 290, 140, 166, 413, 499, 428]
[213, 367, 142, 471, 141, 407, 382, 229, 332, 455, 53]
[207, 12, 319, 54, 246, 274, 474, 312, 170, 374, 188]
I am not really sure how to start. Is there any known algorithm for this ?
Thanks
Additionnal informations :
The matrix is the available ressources at the beginning on each cell.
Ship begins with 0 ressources.
Ship gains ressources by staying still for a round on a cell
(collecting 25% of the cell's ressources).
Ship spends ressources (of his own cargo) by moving (the cost is 10%
of current cell's available ressources).
The path can be returned in anyway, for example (moves = ["up",
"still", "still", "up", "still", "still", "down", "down"]).
BruteForcing it would be acceptable.
X would be the minimum ammount I want my ship's cargo to have when
returning to center.
Map always has a center Cell
Ressources collected or used are always rounded to nearest Int
Ressources collected by a ship are removed from the cell
Here is an example of what can happen :
move_Dict = {
"up": [-1, 0],
"down": [1, 0],
"right": [0, 1],
"left": [0, -1],
"still": [0, 0],
}
moves = ["up", "still", "still", "up", "still", "still", "down", "down"]
position = [5, 5]
cargo = 0
print("initial map :")
for y in range(how_Big):
print(game_Map[y])
for move in moves:
if move == "still":
ressources_Collected = round(game_Map[position[0]][position[1]] * 0.25)
cargo += ressources_Collected
game_Map[position[0]][position[1]] -= ressources_Collected
else:
ressources_Used = round(game_Map[position[0]][position[1]] * 0.10)
cargo -= ressources_Used
position = [position[0]+move_Dict[move][0], position[1]+move_Dict[move][1]]
print(f"ship is at position {position}, cargo = {cargo}")
for y in range(how_Big):
print(game_Map[y])
Output:
initial map :
[110, 179, 97, 467, 347, 336, 368, 298, 107, 84, 123]
[415, 86, 12, 75, 354, 74, 250, 221, 51, 254, 252]
[368, 235, 389, 1, 155, 186, 149, 135, 458, 243, 344]
[391, 480, 485, 358, 416, 479, 270, 354, 203, 436, 146]
[62, 132, 490, 33, 445, 172, 127, 274, 130, 77, 356]
[239, 11, 459, 245, 214, 0, 324, 162, 58, 394, 202]
[241, 395, 46, 78, 191, 384, 203, 191, 56, 474, 237]
[85, 480, 181, 98, 122, 482, 90, 351, 257, 266, 182]
[398, 125, 195, 423, 219, 290, 140, 166, 413, 499, 428]
[213, 367, 142, 471, 141, 407, 382, 229, 332, 455, 53]
[207, 12, 319, 54, 246, 274, 474, 312, 170, 374, 188]
ship is at position [4, 5], cargo = 0
[110, 179, 97, 467, 347, 336, 368, 298, 107, 84, 123]
[415, 86, 12, 75, 354, 74, 250, 221, 51, 254, 252]
[368, 235, 389, 1, 155, 186, 149, 135, 458, 243, 344]
[391, 480, 485, 358, 416, 479, 270, 354, 203, 436, 146]
[62, 132, 490, 33, 445, 172, 127, 274, 130, 77, 356]
[239, 11, 459, 245, 214, 0, 324, 162, 58, 394, 202]
[241, 395, 46, 78, 191, 384, 203, 191, 56, 474, 237]
[85, 480, 181, 98, 122, 482, 90, 351, 257, 266, 182]
[398, 125, 195, 423, 219, 290, 140, 166, 413, 499, 428]
[213, 367, 142, 471, 141, 407, 382, 229, 332, 455, 53]
[207, 12, 319, 54, 246, 274, 474, 312, 170, 374, 188]
ship is at position [4, 5], cargo = 43
[110, 179, 97, 467, 347, 336, 368, 298, 107, 84, 123]
[415, 86, 12, 75, 354, 74, 250, 221, 51, 254, 252]
[368, 235, 389, 1, 155, 186, 149, 135, 458, 243, 344]
[391, 480, 485, 358, 416, 479, 270, 354, 203, 436, 146]
[62, 132, 490, 33, 445, 129, 127, 274, 130, 77, 356]
[239, 11, 459, 245, 214, 0, 324, 162, 58, 394, 202]
[241, 395, 46, 78, 191, 384, 203, 191, 56, 474, 237]
[85, 480, 181, 98, 122, 482, 90, 351, 257, 266, 182]
[398, 125, 195, 423, 219, 290, 140, 166, 413, 499, 428]
[213, 367, 142, 471, 141, 407, 382, 229, 332, 455, 53]
[207, 12, 319, 54, 246, 274, 474, 312, 170, 374, 188]
ship is at position [4, 5], cargo = 75
[110, 179, 97, 467, 347, 336, 368, 298, 107, 84, 123]
[415, 86, 12, 75, 354, 74, 250, 221, 51, 254, 252]
[368, 235, 389, 1, 155, 186, 149, 135, 458, 243, 344]
[391, 480, 485, 358, 416, 479, 270, 354, 203, 436, 146]
[62, 132, 490, 33, 445, 97, 127, 274, 130, 77, 356]
[239, 11, 459, 245, 214, 0, 324, 162, 58, 394, 202]
[241, 395, 46, 78, 191, 384, 203, 191, 56, 474, 237]
[85, 480, 181, 98, 122, 482, 90, 351, 257, 266, 182]
[398, 125, 195, 423, 219, 290, 140, 166, 413, 499, 428]
[213, 367, 142, 471, 141, 407, 382, 229, 332, 455, 53]
[207, 12, 319, 54, 246, 274, 474, 312, 170, 374, 188]
ship is at position [3, 5], cargo = 65
[110, 179, 97, 467, 347, 336, 368, 298, 107, 84, 123]
[415, 86, 12, 75, 354, 74, 250, 221, 51, 254, 252]
[368, 235, 389, 1, 155, 186, 149, 135, 458, 243, 344]
[391, 480, 485, 358, 416, 479, 270, 354, 203, 436, 146]
[62, 132, 490, 33, 445, 97, 127, 274, 130, 77, 356]
[239, 11, 459, 245, 214, 0, 324, 162, 58, 394, 202]
[241, 395, 46, 78, 191, 384, 203, 191, 56, 474, 237]
[85, 480, 181, 98, 122, 482, 90, 351, 257, 266, 182]
[398, 125, 195, 423, 219, 290, 140, 166, 413, 499, 428]
[213, 367, 142, 471, 141, 407, 382, 229, 332, 455, 53]
[207, 12, 319, 54, 246, 274, 474, 312, 170, 374, 188]
ship is at position [3, 5], cargo = 185
[110, 179, 97, 467, 347, 336, 368, 298, 107, 84, 123]
[415, 86, 12, 75, 354, 74, 250, 221, 51, 254, 252]
[368, 235, 389, 1, 155, 186, 149, 135, 458, 243, 344]
[391, 480, 485, 358, 416, 359, 270, 354, 203, 436, 146]
[62, 132, 490, 33, 445, 97, 127, 274, 130, 77, 356]
[239, 11, 459, 245, 214, 0, 324, 162, 58, 394, 202]
[241, 395, 46, 78, 191, 384, 203, 191, 56, 474, 237]
[85, 480, 181, 98, 122, 482, 90, 351, 257, 266, 182]
[398, 125, 195, 423, 219, 290, 140, 166, 413, 499, 428]
[213, 367, 142, 471, 141, 407, 382, 229, 332, 455, 53]
[207, 12, 319, 54, 246, 274, 474, 312, 170, 374, 188]
ship is at position [3, 5], cargo = 275
[110, 179, 97, 467, 347, 336, 368, 298, 107, 84, 123]
[415, 86, 12, 75, 354, 74, 250, 221, 51, 254, 252]
[368, 235, 389, 1, 155, 186, 149, 135, 458, 243, 344]
[391, 480, 485, 358, 416, 269, 270, 354, 203, 436, 146]
[62, 132, 490, 33, 445, 97, 127, 274, 130, 77, 356]
[239, 11, 459, 245, 214, 0, 324, 162, 58, 394, 202]
[241, 395, 46, 78, 191, 384, 203, 191, 56, 474, 237]
[85, 480, 181, 98, 122, 482, 90, 351, 257, 266, 182]
[398, 125, 195, 423, 219, 290, 140, 166, 413, 499, 428]
[213, 367, 142, 471, 141, 407, 382, 229, 332, 455, 53]
[207, 12, 319, 54, 246, 274, 474, 312, 170, 374, 188]
ship is at position [4, 5], cargo = 248
[110, 179, 97, 467, 347, 336, 368, 298, 107, 84, 123]
[415, 86, 12, 75, 354, 74, 250, 221, 51, 254, 252]
[368, 235, 389, 1, 155, 186, 149, 135, 458, 243, 344]
[391, 480, 485, 358, 416, 269, 270, 354, 203, 436, 146]
[62, 132, 490, 33, 445, 97, 127, 274, 130, 77, 356]
[239, 11, 459, 245, 214, 0, 324, 162, 58, 394, 202]
[241, 395, 46, 78, 191, 384, 203, 191, 56, 474, 237]
[85, 480, 181, 98, 122, 482, 90, 351, 257, 266, 182]
[398, 125, 195, 423, 219, 290, 140, 166, 413, 499, 428]
[213, 367, 142, 471, 141, 407, 382, 229, 332, 455, 53]
[207, 12, 319, 54, 246, 274, 474, 312, 170, 374, 188]
ship is at position [5, 5], cargo = 238
[110, 179, 97, 467, 347, 336, 368, 298, 107, 84, 123]
[415, 86, 12, 75, 354, 74, 250, 221, 51, 254, 252]
[368, 235, 389, 1, 155, 186, 149, 135, 458, 243, 344]
[391, 480, 485, 358, 416, 269, 270, 354, 203, 436, 146]
[62, 132, 490, 33, 445, 97, 127, 274, 130, 77, 356]
[239, 11, 459, 245, 214, 0, 324, 162, 58, 394, 202]
[241, 395, 46, 78, 191, 384, 203, 191, 56, 474, 237]
[85, 480, 181, 98, 122, 482, 90, 351, 257, 266, 182]
[398, 125, 195, 423, 219, 290, 140, 166, 413, 499, 428]
[213, 367, 142, 471, 141, 407, 382, 229, 332, 455, 53]
[207, 12, 319, 54, 246, 274, 474, 312, 170, 374, 188]
[Finished in 0.1s]
Related
I'm trying to create a custom filter for the FabricJS library. I got it in parts, because when the filter is used without WebGl it is possible to get the desired result, but when I try to run it with the active resource, I can't get the result. I have no knowledge about this language used to make the filter work with WebGl active.
I've made numerous attempts to write the code for the fragmentSource, but to no avail.
Can anyone help me out with this?
Below is the custom filter code:
fabric.Image.filters.MyFilter = fabric.util.createClass(fabric.Image.filters.BaseFilter, {
type: 'MyFilter',
/**
* Fragment source for the redify program
*/
fragmentSource: 'precision highp float;\n' +
'uniform sampler2D uTexture;\n' +
'uniform float uAlpha;\n' +
'uniform vec4 uFilter;\n' +
'varying vec2 vTexCoord;\n' +
'void main() {\n' +
'vec4 color = texture2D(uTexture, vTexCoord);\n' +
'color.rgb += uAlpha;\n' +
'gl_FragColor = color;\n' +
'}',
alpha: 1,
filter: null,
mainParameter: 'filter',
getUniformLocations: function (gl, program) {
return {
uAlpha: gl.getUniformLocation(program, 'uAlpha'),
uFilter: gl.getUniformLocation(program, 'uFilter'),
};
},
sendUniformData: function (gl, uniformLocations) {
gl.uniform1f(uniformLocations.uAlpha, this.alpha);
gl.uniform1f(uniformLocations.uFilter, this.filter);
},
applyTo2d: function (options) {
const filter = this.filter
const alpha = this.alpha
let imageData = options.imageData,
data = imageData.data,
i, len = data.length;
for (let i = 0; i < len; i += 4) {
data[i] = filter.r[data[i]] * alpha + data[i] * (1 - alpha);
data[i + 1] = filter.g[data[i + 1]] * alpha + data[i + 1] * (1 - alpha);
data[i + 2] = filter.b[data[i + 2]] * alpha + data[i + 2] * (1 - alpha);
}
},
toObject: function () {
return {
filter: this.filter,
alpha: this.alpha
};
}
});
fabric.Image.filters.MyFilter.fromObject = fabric.Image.filters.BaseFilter.fromObject;
The data to load in the filter would be in this format:
{
"r": [28, 29, 29, 30, 30, 31, 31, 32, 32, 32, 33, 33, 34, 34, 35, 35, 36, 36, 36, 37, 37, 38, 38, 39, 40, 40, 41, 42, 42, 44, 44, 44, 45, 46, 46, 47, 49, 50, 51, 51, 51, 52, 53, 55, 56, 57, 58, 59, 59, 60, 62, 64, 65, 66, 67, 68, 69, 72, 73, 74, 74, 76, 77, 78, 80, 82, 84, 85, 86, 88, 89, 91, 94, 94, 95, 97, 98, 100, 101, 103, 104, 106, 109, 111, 112, 114, 115, 117, 119, 119, 120, 122, 124, 127, 129, 130, 132, 134, 136, 137, 139, 141, 142, 144, 146, 148, 149, 153, 155, 156, 158, 160, 160, 161, 163, 165, 167, 168, 170, 172, 173, 175, 177, 178, 180, 181, 183, 185, 186, 188, 189, 191, 193, 194, 196, 197, 198, 200, 201, 203, 204, 205, 207, 208, 209, 211, 212, 212, 213, 214, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 226, 227, 227, 228, 229, 230, 230, 231, 232, 232, 233, 233, 234, 234, 235, 235, 236, 236, 237, 237, 237, 238, 238, 238, 239, 239, 239, 239, 240, 240, 240, 240, 240, 241, 241, 241, 241, 241, 241, 241, 241, 241, 241, 242, 242, 242, 242, 242, 242, 242, 242, 241, 241, 241, 241, 241, 241, 241, 241, 241, 241, 241, 241, 240, 240, 240, 240, 240, 240, 239, 239, 239, 239, 239, 239, 238, 238, 238, 238, 237, 237, 237, 237, 237, 236, 236, 236, 236, 235, 235, 235, 235, 235, 234, 234],
"g": [27, 28, 29, 29, 30, 30, 31, 32, 32, 32, 32, 32, 33, 34, 34, 34, 35, 35, 36, 36, 36, 37, 37, 38, 39, 39, 40, 40, 41, 41, 42, 42, 43, 44, 45, 46, 46, 47, 48, 48, 49, 50, 51, 51, 52, 53, 54, 55, 55, 57, 58, 59, 60, 61, 62, 64, 65, 66, 67, 67, 68, 69, 71, 72, 73, 74, 76, 77, 78, 80, 81, 82, 84, 84, 85, 86, 88, 89, 91, 92, 94, 95, 97, 98, 100, 100, 101, 103, 104, 104, 106, 107, 109, 111, 112, 114, 115, 117, 119, 120, 120, 122, 124, 125, 127, 129, 130, 132, 134, 134, 136, 136, 137, 139, 141, 142, 144, 146, 148, 148, 149, 151, 153, 155, 156, 158, 160, 160, 161, 163, 165, 167, 168, 170, 172, 172, 173, 175, 177, 178, 180, 181, 183, 183, 185, 186, 188, 189, 191, 193, 194, 194, 196, 197, 198, 200, 201, 203, 204, 204, 205, 207, 207, 208, 209, 211, 212, 213, 214, 216, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 227, 228, 229, 230, 230, 231, 232, 232, 233, 234, 234, 235, 235, 236, 236, 237, 237, 238, 238, 238, 239, 239, 239, 240, 240, 240, 240, 240, 241, 241, 241, 241, 241, 241, 241, 242, 242, 242, 242, 242, 242, 242, 241, 241, 241, 241, 241, 241, 241, 241, 241, 240, 240, 240, 240, 239, 239, 239, 239, 238, 238, 238, 237, 237, 237, 237, 236, 236, 236, 235, 235, 235, 234, 234],
"b": [29, 30, 31, 31, 31, 31, 32, 32, 33, 33, 33, 33, 34, 34, 34, 35, 35, 35, 36, 36, 36, 36, 36, 37, 37, 38, 38, 39, 39, 40, 40, 40, 40, 41, 42, 42, 42, 43, 44, 44, 44, 44, 45, 46, 46, 46, 47, 48, 48, 49, 49, 50, 51, 51, 51, 52, 53, 54, 54, 55, 55, 56, 57, 57, 58, 59, 59, 60, 61, 62, 62, 64, 65, 65, 65, 66, 67, 68, 68, 69, 71, 71, 72, 73, 73, 74, 76, 76, 77, 77, 78, 78, 80, 81, 81, 82, 84, 84, 85, 86, 86, 88, 88, 89, 91, 91, 92, 94, 94, 95, 95, 97, 97, 98, 98, 100, 101, 101, 103, 104, 104, 106, 106, 107, 109, 109, 111, 112, 112, 114, 115, 115, 117, 119, 119, 120, 122, 122, 124, 125, 125, 127, 129, 130, 130, 132, 134, 136, 136, 137, 139, 141, 141, 142, 144, 146, 146, 148, 149, 151, 153, 155, 155, 156, 158, 160, 161, 163, 165, 167, 168, 170, 172, 172, 173, 175, 177, 178, 180, 181, 183, 186, 188, 189, 191, 193, 194, 196, 197, 198, 201, 203, 204, 205, 207, 209, 211, 212, 213, 216, 217, 218, 220, 221, 222, 224, 225, 227, 227, 228, 230, 230, 232, 232, 234, 234, 235, 236, 237, 238, 238, 239, 239, 240, 240, 240, 241, 241, 241, 241, 241, 242, 242, 242, 242, 241, 241, 241, 241, 241, 240, 240, 240, 239, 239, 239, 238, 238, 237, 237, 237, 236, 235, 235, 235, 234],
"a": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255]
}
Sorry for any mistakes. I'm using the translator.
I am trying to find the solution to this problem.
Given a list of numbers:
numbers = [27, 24, 33, 52, 54, 53, 61, 71, 57, 163, 182, 196, 228, 270, 302, 501, 440, 771, 601, 582, 658, 954, 1154, 1175, 1459, 1786, 1667, 2186, 2558, 2774, 3388, 3448, 4070, 4785, 6060, 4268, 5642, 5236, 4774, 5849, 5966, 6361, 6198, 6411, 5841, 7099, 7933, 9623, 10633, 10581, 10102, 10559, 11231, 10699, 10817, 11012, 11656, 10899, 10028, 9974, 10598, 9200, 9709, 8926, 9263, 8764, 8849, 8894, 9434, 8599, 8946, 8915, 8338, 8371, 8572, 8952, 9268, 8485, 8858, 8529, 8823, 8718, 8846, 8971, 8970, 8587, 8393, 8777, 8961, 8697, 8809, 8217, 8241, 7824, 7772, 7971, 7870, 7717, 7586, 7413, 7165, 7105, 6788, 6843, 6784, 6683, 6683, 6550, 6752, 6710, 6623, 6719, 6569, 6363, 6534, 6491, 6623, 6586, 6587, 6511, 6240, 6410, 6415, 6389, 6214, 6096, 5901, 5828, 5850, 5830, 5779, 5833, 5741, 5607, 5380, 5449, 5484, 5468, 5429, 5387, 5364, 5121, 5186, 5239, 5191, 5185, 5155, 5081, 4892, 5054, 5017, 5016, 5030, 4911, 4839, 4718, 4790, 4767, 4838, 4860, 4797, 4688, 4639, 4642, 4675, 4758, 4843, 4897, 4932, 4670, 4893, 4958, 5064, 5144, 5097, 5106, 5020, 5172, 5310, 5421, 5406, 5361, 5414, 5435, 5612, 5667, 5803, 5960, 6043, 6090, 6109, 6330, 6489, 7112, 7421, 7764, 8026, 8129, 8371, 8835, 9294, 9735, 10376, 10757, 11481, 10981, 11345, 11969, 12673, 13442, 13406, 13690, 14041, 13556, 14937, 14703, 14804, 15843, 16108, 15444, 15704, 17077, 16260, 16392, 17148, 16342, 15886, 17418, 17987, 17834, 18381, 18017, 18431, 19483, 19116, 20368, 20109, 20248, 21577, 20765, 19583, 21333, 21717, 22441, 22313, 22562, 22201, 20717, 23337, 24059, 24538, 24295, 24891, 24087, 23393, 25195, 27267, 26809, 26390, 26046, 26126, 25043, 27829, 27078, 28450, 28701, 27798, 25752, 25838, 27562, 28206, 27729, 27651, 26902, 26265, 26074, 27787, 28116, 27772, 28510, 28917, 28340, 26814, 29499, 28595, 28833, 27849, 27363, 26588, 26095, 27329, 26613, 25938, 23845, 23015, 23955, 23902, 23218, 23330, 23012, 22540]
and a nested list of indices:
nested_list = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45], [46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76], [77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106], [107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137], [138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168], [169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198], [199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229], [230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259], [260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290], [291, 292, 293, 294, 295, 296, 297, 298, 299, 300]]
using the nested list of indices I need to return the values of the items in the list.
example output would be:
[[27, 24, 33, 52, 54, 53, 61, 71, 57, 163, 182, 196, 228, 270, 302, 501],[440, 771, 601, 582, 658, 954, 1154, 1175, 1459, 1786, 1667, 2186, 2558, 2774, 3388, 3448, 4070, 4785, 6060, 4268, 5642, 5236, 4774, 5849, 5966, 6361, 6198, 6411, 5841, 7099], etc....
The current piece of code I have is
values_from_list = []
for i in nested_list:
values_from_list.append([numbers[i] for i in nested_list[0]])
print(values_from_list)
which is only returning the set of values i require repeated for i in nested_list
output i am currently getting:
[[27, 24, 33, 52, 54, 53, 61, 71, 57, 163, 182, 196, 228, 270, 302, 501], [27, 24, 33, 52, 54, 53, 61, 71, 57, 163, 182, 196, 228, 270, 302, 501], [27, 24, 33, 52, 54, 53, 61, 71, 57, 163, 182, 196, 228, 270, 302, 501], [27, 24, 33, 52, 54, 53, 61, 71, 57, 163, 182, 196, 228, 270, 302, 501], [27, 24, 33, 52, 54, 53, 61, 71, 57, 163, 182, 196, 228, 270, 302, 501], [27, 24, 33, 52, 54, 53, 61, 71, 57, 163, 182, 196, 228, 270, 302, 501], [27, 24, 33, 52, 54, 53, 61, 71, 57, 163, 182, 196, 228, 270, 302, 501], [27, 24, 33, 52, 54, 53, 61, 71, 57, 163, 182, 196, 228, 270, 302, 501], [27, 24, 33, 52, 54, 53, 61, 71, 57, 163, 182, 196, 228, 270, 302, 501], [27, 24, 33, 52, 54, 53, 61, 71, 57, 163, 182, 196, 228, 270, 302, 501], [27, 24, 33, 52, 54, 53, 61, 71, 57, 163, 182, 196, 228, 270, 302, 501]]
I hope my question can be understood,
Many Thanks!
Where you are using nested_list[0] you should use i; and then you should use another variable where you use i in the comprehension. Many errors hide in unclear variable naming; one should strive to make sure variable names always correctly identify their purpose. I would rewrite as follows:
values_from_list = []
for sublist in nested_list:
values_from_list.append([numbers[index] for index in sublist])
print(values_from_list)
or, more succintly,
values_from_list = [
[numbers[index] for index in sublist]
for sublist in nested_list
]
I'm a Python3 newcomer, and I recently get a strange behavior when printing a set of random integers.
I sometimes get a perfectly sorted set, and sometimes not!
Does somebody know the reason why?
Here is my Python3 code:
import random
n=random.randint(30,90)
print("n=",n)
ens=set()
while len(ens)!=n:
ens.add(random.randint(100,199))
print("len(ens)=",len(ens))
print("ens=",str(ens))
car=input("...?")
Here is one non-sorted resulting text:
n= 84
len(ens)= 84
ens= {128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 147, 148, 150, 151, 152, 154, 156, 157, 158, 160, 161, 162, 163, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 177, 178, 179, 181, 182, 183, 185, 186, 188, 189, 190, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 110, 111, 112, 113, 114, 116, 117, 118, 119, 121, 123, 124, 125, 126, 127}
...?
And another sorted resulting text:
n= 86
len(ens)= 86
ens= {100, 102, 103, 104, 105, 106, 107, 108, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 128, 129, 130, 131, 132, 133, 134, 136, 137, 138, 139, 140, 141, 142, 143, 144, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 168, 169, 170, 171, 173, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 186, 188, 189, 191, 192, 195, 196, 197, 198, 199}
...?
I know Python sets are unordered collection of items, but then, why do some of my outputs appear to be perfectly sorted, and some are not?
Just in case it is convincing, I either use Geany IDE, Thonny IDE, or directly Python 3.8 (under Win7 32bit).
Sets are unordered, so when you print your set, python doesn't know what order to print the items, so it prints them in sorted order.
>>> s = {5, 2, 3, 4, 6}
>>> print(s)
{2, 3, 4, 5, 6}
If you want to have the items ordered, use a list.
>>> l = [5, 2, 3, 4, 6]
>>> print(l)
[5, 2, 3, 4, 6]
I want solve a vehicle routing problem with ORTools, both distance and duration matrix will be used.
but the problem is when I change the matrix , it wouldn't give me any solutions anymore!
there are 2 groups of matrixes. with the commented matrixes there is solution, but with the other group, there is not. do you have any idea why this is happening:
from __future__ import print_function
from ortools.constraint_solver import routing_enums_pb2
from ortools.constraint_solver import pywrapcp
def create_data_model():
"""Stores the data for the problem."""
data = {}
#data['distance_matrix']=[[0, 329, 146, 157, 318, 528, 457, 242, 491, 335, 471, 456, 391, 128, 461, 555, 460], [329, 0, 399, 384, 544, 493, 339, 378, 108, 243, 125, 394, 136, 561, 505, 315, 447], [146, 399, 0, 262, 471, 316, 297, 227, 548, 377, 267, 430, 383, 154, 234, 188, 400], [157, 384, 262, 0, 440, 271, 383, 525, 223, 367, 511, 354, 112, 539, 159, 152, 373], [318, 544, 471, 440, 0, 423, 112, 381, 346, 512, 161, 239, 581, 291, 284, 145, 143], [528, 493, 316, 271, 423, 0, 380, 196, 409, 212, 199, 277, 387, 515, 391, 261, 318], [457, 339, 297, 383, 112, 380, 0, 379, 298, 267, 482, 247, 462, 256, 296, 533, 200], [242, 378, 227, 525, 381, 196, 379, 0, 156, 230, 551, 555, 338, 372, 403, 358, 506], [491, 108, 548, 223, 346, 409, 298, 156, 0, 140, 532, 405, 531, 129, 220, 482, 222], [335, 243, 377, 367, 512, 212, 267, 230, 140, 0, 418, 440, 526, 255, 455, 296, 430], [471, 125, 267, 511, 161, 199, 482, 551, 532, 418, 0, 439, 285, 181, 254, 208, 304], [456, 394, 430, 354, 239, 277, 247, 555, 405, 440, 439, 0, 397, 229, 121, 385, 147], [391, 136, 383, 112, 581, 387, 462, 338, 531, 526, 285, 397, 0, 544, 205, 197, 226], [128, 561, 154, 539, 291, 515, 256, 372, 129, 255, 181, 229, 544, 0, 150, 204, 516], [461, 505, 234, 159, 284, 391, 296, 403, 220, 455, 254, 121, 205, 150, 0, 192, 544], [555, 315, 188, 152, 145, 261, 533, 358, 482, 296, 208, 385, 197, 204, 192, 0, 138], [460, 447, 400, 373, 143, 318, 200, 506, 222, 430, 304, 147, 226, 516, 544, 138, 0]]
data['distance_matrix']=[[0, 228, 299, 301, 235, 208, 405, 447, 144, 579], [228, 0, 343, 288, 357, 426, 530, 510, 122, 490], [299, 343, 0, 236, 228, 523, 274, 377, 397, 530], [301, 288, 236, 0, 594, 523, 289, 397, 154, 380], [235, 357, 228, 594, 0, 558, 370, 444, 173, 558], [208, 426, 523, 523, 558, 0, 219, 278, 504, 507], [405, 530, 274, 289, 370, 219, 0, 195, 283, 257], [447, 510, 377, 397, 444, 278, 195, 0, 407, 417], [144, 122, 397, 154, 173, 504, 283, 407, 0, 273], [579, 490, 530, 380, 558, 507, 257, 417, 273, 0]]
data['time_matrix']=[[0, 205, 519, 308, 428, 574, 399, 138, 573, 541], [205, 0, 447, 578, 296, 536, 135, 345, 198, 315], [519, 447, 0, 209, 438, 174, 231, 382, 104, 522], [308, 578, 209, 0, 235, 264, 492, 305, 134, 538], [428, 296, 438, 235, 0, 600, 177, 435, 204, 556], [574, 536, 174, 264, 600, 0, 476, 119, 183, 476], [399, 135, 231, 492, 177, 476, 0, 497, 208, 167], [138, 345, 382, 305, 435, 119, 497, 0, 344, 454], [573, 198, 104, 134, 204, 183, 208, 344, 0, 422], [541, 315, 522, 538, 556, 476, 167, 454, 422, 0]]
data['cost_matrix']=[[0, 160, 135, 433, 581, 453, 336, 329, 343, 237], [160, 0, 313, 596, 576, 458, 264, 380, 348, 354], [135, 313, 0, 591, 391, 211, 561, 236, 304, 414], [433, 596, 591, 0, 539, 253, 427, 300, 214, 118], [581, 576, 391, 539, 0, 243, 521, 499, 560, 255], [453, 458, 211, 253, 243, 0, 571, 216, 121, 314], [336, 264, 561, 427, 521, 571, 0, 425, 271, 165], [329, 380, 236, 300, 499, 216, 425, 0, 425, 549], [343, 348, 304, 214, 560, 121, 271, 425, 0, 176], [237, 354, 414, 118, 255, 314, 165, 549, 176, 0]]
data['num_vehicles'] = 4
data['depot'] = 0
return data
def print_solution(data, manager, routing, assignment):
"""Prints assignment on console."""
total_cost ,total_distance,total_time= 0,0,0
print('Objective: {}'.format(assignment.ObjectiveValue()))
distance_dimension=routing.GetDimensionOrDie('Distance')
time_dimension=routing.GetDimensionOrDie('Time')
for vehicle_id in range(data['num_vehicles']):
index = routing.Start(vehicle_id)
plan_output = 'Route for vehicle {}:\n'.format(vehicle_id)
route_cost = 0
route_distance = 0
route_time = 0
while not routing.IsEnd(index):
plan_output += ' {} -> '.format(manager.IndexToNode(index))
distance_var=distance_dimension.CumulVar(index)
time_var=time_dimension.CumulVar(index)
previous_index = index
index = assignment.Value(routing.NextVar(index))
route_cost += routing.GetArcCostForVehicle(previous_index, index, vehicle_id)
route_distance+=assignment.Value(distance_var)
route_time+=assignment.Value(time_var)
plan_output += '{}\n'.format(manager.IndexToNode(index))
plan_output += 'Cost of the route: {0}\nDistance of the route: {1}m\nTime of route: {2}\n'.format(
route_cost,
route_distance,
route_time)
print(plan_output)
total_cost += route_cost
total_time+=route_time
total_distance+=route_distance
print('Total Cost of all routes: {}\nTotal Distance of all routes: {}\nTotal Time of all routes: {}\n'.format(total_cost,total_distance,total_time))
def get_routes(manager, routing, solution, num_routes):
"""Get vehicle routes from a solution and store them in an array."""
# Get vehicle routes and store them in a two dimensional array whose
# i,j entry is the jth location visited by vehicle i along its route.
routes = []
for route_nbr in range(num_routes):
index = routing.Start(route_nbr)
route = [manager.IndexToNode(index)]
while not routing.IsEnd(index):
index = solution.Value(routing.NextVar(index))
route.append(manager.IndexToNode(index))
routes.append(route)
return routes
def main():
# Instantiate the data problem.
data = create_data_model()
# Create the routing index manager.
manager = pywrapcp.RoutingIndexManager(len(data['cost_matrix']), data['num_vehicles'], data['depot'])
# Create Routing Model.
routing = pywrapcp.RoutingModel(manager)
# Create and register a transit callback.
def cost_callback(from_index, to_index):
"""Returns the distance between the two nodes."""
# Convert from routing variable Index to distance matrix NodeIndex.
from_node = manager.IndexToNode(from_index)
to_node = manager.IndexToNode(to_index)
return data['cost_matrix'][from_node][to_node]
transit_callback_index = routing.RegisterTransitCallback(cost_callback)
routing.SetArcCostEvaluatorOfAllVehicles(transit_callback_index)
# Add Cost constraint.
routing.AddDimension(
transit_callback_index,
0, # no slack
3000, # vehicle maximum travel distance
False, # start cumul to zero
'Cost')
cost_dimension = routing.GetDimensionOrDie('Cost')
cost_dimension.SetGlobalSpanCostCoefficient(1000)
#Add Distance constraint.
def distance_callback(from_index,to_index):
from_node = manager.IndexToNode(from_index)
to_node = manager.IndexToNode(to_index)
return data['distance_matrix'][from_node][to_node]
distance_callback_index=routing.RegisterTransitCallback(distance_callback)
routing.AddDimension(
distance_callback_index,
0,
3000,
False,
'Distance')
distance_dimension=routing.GetDimensionOrDie('Distance')
#Add Time constraint.
def time_callback(from_index,to_index):
from_node = manager.IndexToNode(from_index)
to_node = manager.IndexToNode(to_index)
return data['time_matrix'][from_node][to_node]
time_callback_index=routing.RegisterTransitCallback(time_callback)
routing.AddDimension(
time_callback_index,
0,
300,
False,
'Time')
time_dimension=routing.GetDimensionOrDie('Time')
# Setting first solution heuristic.
search_parameters = pywrapcp.DefaultRoutingSearchParameters()
search_parameters.first_solution_strategy = (routing_enums_pb2.FirstSolutionStrategy.PATH_CHEAPEST_ARC)
search_parameters.solution_limit = 100
search_parameters.time_limit.seconds = 3
# Solve the problem.
assignment = routing.SolveWithParameters(search_parameters)
# Print solution on console.
if assignment:
print_solution(data, manager, routing, assignment)
routes = get_routes(manager, routing, assignment, data['num_vehicles'])
# Display the routes.
for i, route in enumerate(routes):
print('Route', i, route)
if __name__ == '__main__':
main()
None could mean that it did not find a solution. Most likely your limits are too low
by increasing the limits, it works fine.
but for better understanding, it's better to check solver status. time limit errors mostly refer to the low limitations.
in this example we have many value more than 300 in time matrix but the maximum time for every vehicle is 300.so there is not a feasible solution for this problem.
I have a binary string in Elixir that's composed of compressed bytes that I want to deflate and extract the "real data" from:
iex(93)> data
<<31, 139, 8, 0, 0, 0, 0, 0, 0, 0, 109, 80, 203, 110, 218, 64, 0, 76, 171, 70, 141, 68, 78, 105, 213, 67, 171, 74, 168, 7, 212, 86, 50, 172, 189, 94, 236, 69, 66, 173, 49, 40, 56, 96, 76, 130, 31, 196, 23, 226, 216, 11, 44, 216, 94, 227, 117, 13, 238, 199, 244, 208, 207, 234, 23, 244, 23, 122, 43, 137, 218, 91, 110, 243, 208, 204, 72, 83, 187, 56, 61, 59, 169, 255, 126, 121, 245, 227, 69, 237, 226, 125, 41, 117, 66, 150, 52, 105, 146, 241, 42, 92, 179, 230, 61, 99, 69, 148, 51, 26, 117, 196, 14, 122, 251, 170, 119, 164, 245, 254, 3, 175, 127, 188, 33, 15, 230, 167, 15, 53, 109, 58, 29, 27, 186, 102, 27, 214, 228, 243, 155, 167, 211, 210, 159, 231, 235, 162, 200, 120, 167, 213, 10, 210, 71, 165, 25, 198, 148, 164, 5, 111, 174, 24, 91, 197, 164, 121, 204, 181, 146, 32, 223, 146, 162, 21, 177, 125, 26, 179, 32, 106, 245, 255, 129, 47, 89, 16, 110, 131, 21, 153, 4, 9, 233, 62, 61, 208, 40, 73, 206, 41, 75, 117, 22, 145, 46, 106, 112, 30, 119, 197, 70, 193, 182, 36, 237, 106, 150, 173, 39, 192, 22, 151, 188, 93, 85, 75, 52, 2, 78, 110, 136, 90, 101, 17, 228, 43, 179, 126, 24, 109, 122, 217, 72, 231, 238, 140, 248, 83, 205, 229, 73, 79, 77, 101, 129, 162, 148, 135, 246, 88, 95, 32, 107, 39, 229, 153, 155, 219, 250, 118, 236, 196, 14, 104, 187, 150, 228, 91, 154, 194, 132, 188, 7, 29, 65, 25, 122, 201, 236, 90, 91, 78, 50, 49, 191, 180, 190, 29, 59, 146, 91, 213, 50, 23, 43, 92, 84, 36, 240, 124, 103, 98, 198, 90, 60, 47, 231, 133, 105, 175, 16, 173, 42, 67, 217, 5, 222, 149, 61, 208, 92, 115, 70, 215, 166, 158, 89, 17, 112, 239, 105, 168, 30, 134, 91, 60, 242, 6, 163, 18, 122, 202, 94, 42, 47, 157, 104, 176, 151, 199, 223, 5, 225, 154, 223, 82, 52, 104, 251, 150, 195, 131, 74, 223, 249, 169, 13, 54, 96, 108, 26, 195, 249, 46, 94, 192, 233, 58, 106, 252, 255, 203, 136, 186, 2, 148, 85, 36, 73, 176, 141, 17, 84, 177, 36, 42, 50, 132, 157, 119, 101, 146, 2, 44, 28, 82, 153, 142, 124, 111, 7, 5, 97, 64, 151, 192, 62, 32, 112, 195, 191, 254, 252, 101, 78, 79, 230, 207, 238, 78, 55, 103, 230, 227, 253, 125, 45, 127, 13, 48, 22, 177, 164, 96, 5, 41, 80, 145, 219, 0, 171, 16, 159, 159, 255, 5, 242, 139, 137, 38, 42, 2, 0, 0>>
I'm not sure how to unzip this data. So far, I've:
Looked through Official Elixir Docs
Tried using Erlang's :zip and :zlib modules but had no success. Both of them throw errors:
iex(100)> :zlib.uncompress(data)
** (ErlangError) erlang error: :data_error
:zlib.call/3
:zlib.inflate/2
:zlib.uncompress/1
iex(101)> :zip.unzip data
{:error,
{:EXIT,
{{:badmatch,
<<31, 139, 8, 0, 0, 0, 0, 0, 0, 0, 109, 80, 203, 110, 218, 64, 0, 76, 171, 70, 141, 68, 78, 105, 213, 67, 171, 74, 168, 7, 212, 86, 50, 172, 189, 94, 236, 69, 66, 173, 49, 40, 56, 96, 76, 130, ...>>},
[{:zip, :binary_io, 2, [file: 'zip.erl', line: 1726]},
{:zip, :get_end_of_central_dir, 3, [file: 'zip.erl', line: 1313]},
{:zip, :get_central_dir, 3, [file: 'zip.erl', line: 1269]},
{:zip, :do_unzip, 2, [file: 'zip.erl', line: 380]},
{:zip, :unzip, 2, [file: 'zip.erl', line: 370]},
{:erl_eval, :do_apply, 6, [file: 'erl_eval.erl', line: 670]},
{:elixir, :erl_eval, 3, [file: 'src/elixir.erl', line: 215]},
{:elixir, :eval_forms, 4, [file: 'src/elixir.erl', line: 203]}]}}}
I know for a fact that the data is correct, I was able to extract information from the same bytes in Javascript using JXG.Util.Unzip(). But, how do I unzip this data in Elixir?
Your data was gzip compressed data according to the file command, so I tried :zlib.gunzip and it worked:
iex(1)> data = <<31, 139, 8, 0, 0, 0, 0, 0, 0, 0, 109, 80, 203, 110, 218, 64, 0, 76, 171, 70, 141, 68, 78, 105, 213, 67, 171, 74, 168, 7, 212, 86, 50, 172, 189, 94, 236, 69, 66, 173, 49, 40, 56, 96, 76, 130, 31, 196, 23, 226, 216, 11, 44, 216, 94, 227, 117, 13, 238, 199, 244, 208, 207, 234, 23, 244, 23, 122, 43, 137, 218, 91, 110, 243, 208, 204, 72, 83, 187, 56, 61, 59, 169, 255, 126, 121, 245, 227, 69, 237, 226, 125, 41, 117, 66, 150, 52, 105, 146, 241, 42, 92, 179, 230, 61, 99, 69, 148, 51, 26, 117, 196, 14, 122, 251, 170, 119, 164, 245, 254, 3, 175, 127, 188, 33, 15, 230, 167, 15, 53, 109, 58, 29, 27, 186, 102, 27, 214, 228, 243, 155, 167, 211, 210, 159, 231, 235, 162, 200, 120, 167, 213, 10, 210, 71, 165, 25, 198, 148, 164, 5, 111, 174, 24, 91, 197, 164, 121, 204, 181, 146, 32, 223, 146, 162, 21, 177, 125, 26, 179, 32, 106, 245, 255, 129, 47, 89, 16, 110, 131, 21, 153, 4, 9, 233, 62, 61, 208, 40, 73, 206, 41, 75, 117, 22, 145, 46, 106, 112, 30, 119, 197, 70, 193, 182, 36, 237, 106, 150, 173, 39, 192, 22, 151, 188, 93, 85, 75, 52, 2, 78, 110, 136, 90, 101, 17, 228, 43, 179, 126, 24, 109, 122, 217, 72, 231, 238, 140, 248, 83, 205, 229, 73, 79, 77, 101, 129, 162, 148, 135, 246, 88, 95, 32, 107, 39, 229, 153, 155, 219, 250, 118, 236, 196, 14, 104, 187, 150, 228, 91, 154, 194, 132, 188, 7, 29, 65, 25, 122, 201, 236, 90, 91, 78, 50, 49, 191, 180, 190, 29, 59, 146, 91, 213, 50, 23, 43, 92, 84, 36, 240, 124, 103, 98, 198, 90, 60, 47, 231, 133, 105, 175, 16, 173, 42, 67, 217, 5, 222, 149, 61, 208, 92, 115, 70, 215, 166, 158, 89, 17, 112, 239, 105, 168, 30, 134, 91, 60, 242, 6, 163, 18, 122, 202, 94, 42, 47, 157, 104, 176, 151, 199, 223, 5, 225, 154, 223, 82, 52, 104, 251, 150, 195, 131, 74, 223, 249, 169, 13, 54, 96, 108, 26, 195, 249, 46, 94, 192, 233, 58, 106, 252, 255, 203, 136, 186, 2, 148, 85, 36, 73, 176, 141, 17, 84, 177, 36, 42, 50, 132, 157, 119, 101, 146, 2, 44, 28, 82, 153, 142, 124, 111, 7, 5, 97, 64, 151, 192, 62, 32, 112, 195, 191, 254, 252, 101, 78, 79, 230, 207, 238, 78, 55, 103, 230, 227, 253, 125, 45, 127, 13, 48, 22, 177, 164, 96, 5, 41, 80, 145, 219, 0, 171, 16, 159, 159, 255, 5, 242, 139, 137, 38, 42, 2, 0, 0>>
<<31, 139, 8, 0, 0, 0, 0, 0, 0, 0, 109, 80, 203, 110, 218, 64, 0, 76, 171, 70, 141, 68, 78, 105, 213, 67, 171, 74, 168, 7, 212, 86, 50, 172, 189, 94, 236, 69, 66, 173, 49, 40, 56, 96, 76, 130, 31, 196, 23, 226, ...>>
iex(2)> :zlib.gunzip(data)
<<11, 18, 5, 8, 0, 32, 232, 7, 74, 158, 4, 11, 18, 29, 118, 50, 58, 99, 111, 109, 46, 105, 109, 112, 115, 121, 99, 104, 111, 46, 98, 111, 111, 116, 100, 114, 111, 105, 100, 58, 49, 58, 53, 26, 19, 66, 111, 111, 116, 32, ...>>
From the docs.
gunzip(Data) -> Decompressed
Types:
Data = iodata()
Decompressed = binary()
Uncompress data (with gz headers and checksum).