问:
Why is my marching cubes algorythm leaving holes behind?
I just made a marching cubes algorythm and after 2 days i saw some holes in the mesh.

```using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public class MarchinCubes : MonoBehaviour
{
    public int size = 1;
    public float surfaceValue = .5f;

    public int xOffset = 0;
    public int yOffset = 0;
    public int zOffset = 0;

    public float zoom = 1;
    public bool interpolation;
    public bool shading;
    public bool autoUpdate;

    public bool sphereValues;

    void Start()
    {
        xOffset = (int)transform.position.x;
        yOffset = (int)transform.position.y;
        zOffset = (int)transform.position.z;

        Starter();
    }

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.U) || autoUpdate)
        {
            xOffset = (int)transform.position.x;
            yOffset = (int)transform.position.y;
            zOffset = (int)transform.position.z;

            Starter();

            Vector3 position = transform.position;

            Vector3 newPosition = new Vector3(Mathf.Floor(position.x), Mathf.Floor(position.y), Mathf.Floor(position.z));

            transform.position = newPosition;
        }
    }

    void Starter()
    {
        int pointSize = size + 1;
        float[][][] values = sphereValues ? sphere(pointSize) : Perlin(pointSize);

        Mesh mesh = CreateMesh(values, pointSize - 1);

        mesh.RecalculateNormals();
        GetComponent<MeshFilter>().mesh = mesh;
    }

    float[][][] sphere(int size)
    {
        float[][][] values = initializeFloatArray(size);

        for (int x = 0; x < size; x++)
        {
            for (int y = 0; y < size; y++)
            {
                for (int z = 0; z < size; z++)
                {
                    values[x][y][z] = 10 - distance(x, y, z, size / 2, size / 2, size / 2);
                }
            }
        }

        return values;
    }

    float distance(float x, float y, float z, float xCenter, float yCenter, float zCenter)
    {
        return Mathf.Sqrt(Mathf.Pow(x - xCenter, 2) + Mathf.Pow(y - yCenter, 2) + Mathf.Pow(z - zCenter, 2));
    }

    float[][][] Perlin(int size)
    {
        float[][][] values = initializeFloatArray(size);

        for (int x = 0; x < size; x++)
        {
            for (int y = 0; y < size; y++)
            {
                for (int z = 0; z < size; z++)
                {
                    if (x == 0 || x == size - 1 || y == 0 || y == size - 1 ||z == 0 || z == size - 1)
                    {
                        values[x][y][z] = 0;
                    }
                    else
                    {
                        values[x][y][z] = (GetPerlin(x, y, z, 40f) + GetPerlin(x, y, z, 20f)) / 2;
                    }
                }
            }
        }

        return values;
    }

    float GetPerlin(int xInt, int yInt, int zInt, float divider)
    {
        float z = (zInt + zOffset) / divider;
        float y = (yInt + yOffset) / divider;
        float x = (xInt + xOffset) / divider;

        float zy = Mathf.PerlinNoise(x, y);
        float zx = Mathf.PerlinNoise(x, z);
        float yx = Mathf.PerlinNoise(y, z);
        float yz = Mathf.PerlinNoise(y, x);
        float xz = Mathf.PerlinNoise(z, x);
        float xy = Mathf.PerlinNoise(z, y);

        return (xy + xz + yz + yx + zx + zy) / 6;
    }

    float[][][] initializeFloatArray(int size)
    {
        float[][][] values = new float[size][][];

        for (int x = 0; x < size; x++)
        {
            values[x] = new float[size][];

            for (int i = 0; i < size; i++)
            {
                values[x][i] = new float[size];
            }
        }

        return values;
    }

    Mesh CreateMesh(float[][][] values, int size)
    {
        Vector3[] vertices = initializeVector3Array(size * 2 + 1, size * 2 + 1, size * 2 + 1);
        int[] triangles = new int[size * size * size * 3 * 2];
        Mesh mesh = new Mesh();

        int triangleCount = 0;

        for (int x = 0; x < size; x++)
        {
            for (int y = 0; y < size; y++)
            {
                for (int z = 0; z < size; z++)
                {
                    int[] triangleTable = table[getTriangleIndex(
                        new[] {
                            values[x][y][z],
                            values[x + 1][y][z],
                            values[x + 1][y][z + 1],
                            values[x][y][z + 1],
                            values[x][y + 1][z],
                            values[x + 1][y + 1][z],
                            values[x + 1][y + 1][z + 1],
                            values[x][y + 1][z + 1]
                        },
                        surfaceValue)];

                    int[] trianglesToAdd = new int[triangleTable.Length];

                    for (int i = 0; i < triangleTable.Length; i += 3)
                    {
                        trianglesToAdd[i] = getVertexIndex(x, y, z, triangleTable[i], size * 2 + 2);
                        trianglesToAdd[i + 1] = getVertexIndex(x, y, z, triangleTable[i + 1], size * 2 + 2);
                        trianglesToAdd[i + 2] = getVertexIndex(x, y, z, triangleTable[i + 2], size * 2 + 2);
                    }

                    for (int i = 0; i < trianglesToAdd.Length; i++)
                    {
                        triangles[triangleCount] = trianglesToAdd[i];
                        triangleCount++;
                    }
                }
            }
        }

        if (interpolation)
        {
            vertices = addIndterpolation(vertices, size * 2 + 2, values, surfaceValue);
        }

        vertices = ScaleVertices(vertices);

        if (shading == false)
        {
            RemakeMeshToDiscrete(vertices, triangles, out vertices, out triangles);
        }

        mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;

        mesh.vertices = vertices;
        mesh.triangles = triangles;

        return mesh;
    }

    Vector3[] ScaleVertices(Vector3[] vertices)
    {
        for (int i = 0; i < vertices.Length; i++)
        {
            vertices[i].x = vertices[i].x / transform.localScale.x;
            vertices[i].y = vertices[i].y / transform.localScale.y;
            vertices[i].z = vertices[i].z / transform.localScale.z;
        }
        return vertices;
    }

    void RemakeMeshToDiscrete(Vector3[] vert, int[] trig, out Vector3[] outVertices, out int[] outTriangles)
    {
        Vector3[] vertDiscrete = new Vector3[trig.Length];
        int[] trigDiscrete = new int[trig.Length];
        for (int i = 0; i < trig.Length; i++)
        {
            vertDiscrete[i] = vert[trig[i]];
            trigDiscrete[i] = i;
        }
        outVertices = vertDiscrete;
        outTriangles = trigDiscrete;
    }

    Vector3[] addIndterpolation(Vector3[] array, int sizeVertices, float[][][] values, float surfaceValue)
    {
        int sizeValues = values.Length;
        for (int x = 0; x < sizeValues - 1; x++)
        {
            for (int y = 0; y < sizeValues - 1; y++)
            {
                for (int z = 0; z < sizeValues - 1; z++)
                {
                    int arrayCords = z * 2 + y * sizeVertices * 2 + x * sizeVertices * sizeVertices * 2;

                    float value = values[x][y][z];
                    float valueZ = values[x + 1][y][z];
                    float valueY = values[x][y + 1][z];
                    float valueX = values[x][y][z + 1];

                    float interpolationValueX = Mathf.Abs(surfaceValue - value) / (Mathf.Abs(surfaceValue - value) + Mathf.Abs(surfaceValue - valueX));
                    float interpolationValueY = Mathf.Abs(surfaceValue - value) / (Mathf.Abs(surfaceValue - value) + Mathf.Abs(surfaceValue - valueY));
                    float interpolationValueZ = Mathf.Abs(surfaceValue - value) / (Mathf.Abs(surfaceValue - value) + Mathf.Abs(surfaceValue - valueZ));

                    array[arrayCords + 1] += new Vector3(0, 0, interpolationValueX - .5f);

                    array[arrayCords + sizeVertices] += new Vector3(0, interpolationValueY - .5f, 0);

                    array[arrayCords + sizeVertices * sizeVertices] += new Vector3(interpolationValueZ - .5f, 0, 0);
                }
            }
        }

        return array;
    }

    int getVertexIndex(int z, int y, int x, int cubeValue, int size)
    {
        int[][] vertecieValues = new[] {
            new []{1, 0, 0 },
            new []{2, 0, 1 },
            new []{1, 0, 2 },
            new []{0, 0, 1 },
            new []{1, 2, 0 },
            new []{2, 2, 1 },
            new []{1, 2, 2 },
            new []{0, 2, 1 },
            new []{0, 1, 0 },
            new []{2, 1, 0 },
            new []{2, 1, 2 },
            new []{0, 1, 2 }
        };

        int xReturn = z * 2 * size * size;
        int yReturn = y * 2 * size;
        int zReturn = x * 2;
        return xReturn + vertecieValues[cubeValue][0] * size * size + yReturn + vertecieValues[cubeValue][1] * size + zReturn + vertecieValues[cubeValue][2];
    }

    int getTriangleIndex(float[] values, float surfaceValue)
    {
        int index = 0;

        for (int i = 0; i < 8; i++)
        {
            if (values[i] > surfaceValue)
            {
                index |= 1 << i;
            }
        }
        return index;
    }

    Vector3[] initializeVector3Array(int Xsize, int Ysize, int Zsize)
    {
        Vector3[] array = new Vector3[(Xsize + 1) * (Ysize + 1) * (Zsize + 1)];
        int count = 0;
        for (int x = 0; x < Xsize + 1; x++)
        {
            for (int y = 0; y < Ysize + 1; y++)
            {
                for (int z = 0; z < Zsize + 1; z++)
                {
                    array[count] = new Vector3(x / 2f, y / 2f, z / 2f);
                    count++;
                }
            }
        }

        return array;
    }

    int[][] table = new int[][] {
        new int[] { },
        new int[] { 8, 3, 0},
        new int[] { 9, 0, 1},
        new int[] { 8, 3, 1, 8, 1, 9},
        new int[] {10, 1, 2},
        new int[] { 8, 3, 0, 1, 2,10},
        new int[] { 9, 0, 2, 9, 2,10},
        new int[] { 3, 2, 8, 2,10, 8, 8,10, 9},
        new int[] {11, 2, 3},
        new int[] {11, 2, 0,11, 0, 8},
        new int[] {11, 2, 3, 0, 1, 9},
        new int[] { 2, 1,11, 1, 9,11,11, 9, 8},
        new int[] {10, 1, 3,10, 3,11},
        new int[] { 1, 0,10, 0, 8,10,10, 8,11},
        new int[] { 0, 3, 9, 3,11, 9, 9,11,10},
        new int[] { 8,10, 9, 8,11,10},
        new int[] { 8, 4, 7},
        new int[] { 3, 0, 4, 3, 4, 7},
        new int[] { 1, 9, 0, 8, 4, 7},
        new int[] { 9, 4, 1, 4, 7, 1, 1, 7, 3},
        new int[] {10, 1, 2, 8, 4, 7},
        new int[] { 2,10, 1, 0, 4, 7, 0, 7, 3},
        new int[] { 4, 7, 8, 0, 2,10, 0,10, 9},
        new int[] { 2, 7, 3, 2, 9, 7, 7, 9, 4, 2,10, 9},
        new int[] { 2, 3,11, 7, 8, 4},
        new int[] { 7,11, 4,11, 2, 4, 4, 2, 0},
        new int[] { 3,11, 2, 4, 7, 8, 9, 0, 1},
        new int[] { 2, 7,11, 2, 1, 7, 1, 4, 7, 1, 9, 4},
        new int[] { 8, 4, 7,11,10, 1,11, 1, 3},
        new int[] {11, 4, 7, 1, 4,11, 1,11,10, 1, 0, 4},
        new int[] { 3, 8, 0, 7,11, 4,11, 9, 4,11,10, 9},
        new int[] { 7,11, 4, 4,11, 9,11,10, 9},
        new int[] { 9, 5, 4},
        new int[] { 3, 0, 8, 4, 9, 5},
        new int[] { 5, 4, 0, 5, 0, 1},
        new int[] { 4, 8, 5, 8, 3, 5, 5, 3, 1},
        new int[] { 2,10, 1, 9, 5, 4},
        new int[] { 0, 8, 3, 5, 4, 9,10, 1, 2},
        new int[] {10, 5, 2, 5, 4, 2, 2, 4, 0},
        new int[] { 3, 4, 8, 3, 2, 4, 2, 5, 4, 2,10, 5},
        new int[] {11, 2, 3, 9, 5, 4},
        new int[] { 9, 5, 4, 8,11, 2, 8, 2, 0},
        new int[] { 3,11, 2, 1, 5, 4, 1, 4, 0},
        new int[] { 8, 5, 4, 2, 5, 8, 2, 8,11, 2, 1, 5},
        new int[] { 5, 4, 9, 1, 3,11, 1,11,10},
        new int[] { 0, 9, 1, 4, 8, 5, 8,10, 5, 8,11,10},
        new int[] { 3, 4, 0, 3,10, 4, 4,10, 5, 3,11,10},
        new int[] { 4, 8, 5, 5, 8,10, 8,11,10},
        new int[] { 9, 5, 7, 9, 7, 8},
        new int[] { 0, 9, 3, 9, 5, 3, 3, 5, 7},
        new int[] { 8, 0, 7, 0, 1, 7, 7, 1, 5},
        new int[] { 1, 7, 3, 1, 5, 7},
        new int[] { 1, 2,10, 5, 7, 8, 5, 8, 9},
        new int[] { 9, 1, 0,10, 5, 2, 5, 3, 2, 5, 7, 3},
        new int[] { 5, 2,10, 8, 2, 5, 8, 5, 7, 8, 0, 2},
        new int[] {10, 5, 2, 2, 5, 3, 5, 7, 3},
        new int[] {11, 2, 3, 8, 9, 5, 8, 5, 7},
        new int[] { 9, 2, 0, 9, 7, 2, 2, 7,11, 9, 5, 7},
        new int[] { 0, 3, 8, 2, 1,11, 1, 7,11, 1, 5, 7},
        new int[] { 2, 1,11,11, 1, 7, 1, 5, 7},
        new int[] { 3, 9, 1, 3, 8, 9, 7,11,10, 7,10, 5},
        new int[] { 9, 1, 0,10, 7,11,10, 5, 7},
        new int[] { 3, 8, 0, 7,10, 5, 7,11,10},
        new int[] {11, 5, 7,11,10, 5},
        new int[] {10, 6, 5},
        new int[] { 8, 3, 0,10, 6, 5},
        new int[] { 0, 1, 9, 5,10, 6},
        new int[] {10, 6, 5, 9, 8, 3, 9, 3, 1},
        new int[] { 1, 2, 6, 1, 6, 5},
        new int[] { 0, 8, 3, 2, 6, 5, 2, 5, 1},
        new int[] { 5, 9, 6, 9, 0, 6, 6, 0, 2},
        new int[] { 9, 6, 5, 3, 6, 9, 3, 9, 8, 3, 2, 6},
        new int[] { 3,11, 2,10, 6, 5},
        new int[] { 6, 5,10, 2, 0, 8, 2, 8,11},
        new int[] { 1, 9, 0, 6, 5,10,11, 2, 3},
        new int[] { 1,10, 2, 5, 9, 6, 9,11, 6, 9, 8,11},
        new int[] {11, 6, 3, 6, 5, 3, 3, 5, 1},
        new int[] { 0, 5, 1, 0,11, 5, 5,11, 6, 0, 8,11},
        new int[] { 0, 5, 9, 0, 3, 5, 3, 6, 5, 3,11, 6},
        new int[] { 5, 9, 6, 6, 9,11, 9, 8,11},
        new int[] {10, 6, 5, 4, 7, 8},
        new int[] { 5,10, 6, 7, 3, 0, 7, 0, 4},
        new int[] { 5,10, 6, 0, 1, 9, 8, 4, 7},
        new int[] { 4, 5, 9, 6, 7,10, 7, 1,10, 7, 3, 1},
        new int[] { 7, 8, 4, 5, 1, 2, 5, 2, 6},
        new int[] { 4, 1, 0, 4, 5, 1, 6, 7, 3, 6, 3, 2},
        new int[] { 9, 4, 5, 8, 0, 7, 0, 6, 7, 0, 2, 6},
        new int[] { 4, 5, 9, 6, 3, 2, 6, 7, 3},
        new int[] { 7, 8, 4, 2, 3,11,10, 6, 5},
        new int[] {11, 6, 7,10, 2, 5, 2, 4, 5, 2, 0, 4},
        new int[] {11, 6, 7, 8, 0, 3, 1,10, 2, 9, 4, 5},
        new int[] { 6, 7,11, 1,10, 2, 9, 4, 5},
        new int[] { 6, 7,11, 4, 5, 8, 5, 3, 8, 5, 1, 3},
        new int[] { 6, 7,11, 4, 1, 0, 4, 5, 1},
        new int[] { 4, 5, 9, 3, 8, 0,11, 6, 7},
        new int[] { 9, 4, 5, 7,11, 6},
        new int[] {10, 6, 4,10, 4, 9},
        new int[] { 8, 3, 0, 9,10, 6, 9, 6, 4},
        new int[] { 1,10, 0,10, 6, 0, 0, 6, 4},
        new int[] { 8, 6, 4, 8, 1, 6, 6, 1,10, 8, 3, 1},
        new int[] { 9, 1, 4, 1, 2, 4, 4, 2, 6},
        new int[] { 1, 0, 9, 3, 2, 8, 2, 4, 8, 2, 6, 4},
        new int[] { 2, 4, 0, 2, 6, 4},
        new int[] { 3, 2, 8, 8, 2, 4, 2, 6, 4},
        new int[] { 2, 3,11, 6, 4, 9, 6, 9,10},
        new int[] { 0,10, 2, 0, 9,10, 4, 8,11, 4,11, 6},
        new int[] {10, 2, 1,11, 6, 3, 6, 0, 3, 6, 4, 0},
        new int[] {10, 2, 1,11, 4, 8,11, 6, 4},
        new int[] { 1, 4, 9,11, 4, 1,11, 1, 3,11, 6, 4},
        new int[] { 0, 9, 1, 4,11, 6, 4, 8,11},
        new int[] {11, 6, 3, 3, 6, 0, 6, 4, 0},
        new int[] { 8, 6, 4, 8,11, 6},
        new int[] { 6, 7,10, 7, 8,10,10, 8, 9},
        new int[] { 9, 3, 0, 6, 3, 9, 6, 9,10, 6, 7, 3},
        new int[] { 6, 1,10, 6, 7, 1, 7, 0, 1, 7, 8, 0},
        new int[] { 6, 7,10,10, 7, 1, 7, 3, 1},
        new int[] { 7, 2, 6, 7, 9, 2, 2, 9, 1, 7, 8, 9},
        new int[] { 1, 0, 9, 3, 6, 7, 3, 2, 6},
        new int[] { 8, 0, 7, 7, 0, 6, 0, 2, 6},
        new int[] { 2, 7, 3, 2, 6, 7},
        new int[] { 7,11, 6, 3, 8, 2, 8,10, 2, 8, 9,10},
        new int[] {11, 6, 7,10, 0, 9,10, 2, 0},
        new int[] { 2, 1,10, 7,11, 6, 8, 0, 3},
        new int[] { 1,10, 2, 6, 7,11},
        new int[] { 7,11, 6, 3, 9, 1, 3, 8, 9},
        new int[] { 9, 1, 0,11, 6, 7},
        new int[] { 0, 3, 8,11, 6, 7},
        new int[] {11, 6, 7},
        new int[] {11, 7, 6},
        new int[] { 0, 8, 3,11, 7, 6},
        new int[] { 9, 0, 1,11, 7, 6},
        new int[] { 7, 6,11, 3, 1, 9, 3, 9, 8},
        new int[] { 1, 2,10, 6,11, 7},
        new int[] { 2,10, 1, 7, 6,11, 8, 3, 0},
        new int[] {11, 7, 6,10, 9, 0,10, 0, 2},
        new int[] { 7, 6,11, 3, 2, 8, 8, 2,10, 8,10, 9},
        new int[] { 2, 3, 7, 2, 7, 6},
        new int[] { 8, 7, 0, 7, 6, 0, 0, 6, 2},
        new int[] { 1, 9, 0, 3, 7, 6, 3, 6, 2},
        new int[] { 7, 6, 2, 7, 2, 9, 2, 1, 9, 7, 9, 8},
        new int[] { 6,10, 7,10, 1, 7, 7, 1, 3},
        new int[] { 6,10, 1, 6, 1, 7, 7, 1, 0, 7, 0, 8},
        new int[] { 9, 0, 3, 6, 9, 3, 6,10, 9, 6, 3, 7},
        new int[] { 6,10, 7, 7,10, 8,10, 9, 8},
        new int[] { 8, 4, 6, 8, 6,11},
        new int[] {11, 3, 6, 3, 0, 6, 6, 0, 4},
        new int[] { 0, 1, 9, 4, 6,11, 4,11, 8},
        new int[] { 1, 9, 4,11, 1, 4,11, 3, 1,11, 4, 6},
        new int[] {10, 1, 2,11, 8, 4,11, 4, 6},
        new int[] {10, 1, 2,11, 3, 6, 6, 3, 0, 6, 0, 4},
        new int[] { 0, 2,10, 0,10, 9, 4,11, 8, 4, 6,11},
        new int[] { 2,11, 3, 6, 9, 4, 6,10, 9},
        new int[] { 3, 8, 2, 8, 4, 2, 2, 4, 6},
        new int[] { 2, 0, 4, 2, 4, 6},
        new int[] { 1, 9, 0, 3, 8, 2, 2, 8, 4, 2, 4, 6},
        new int[] { 9, 4, 1, 1, 4, 2, 4, 6, 2},
        new int[] { 8, 4, 6, 8, 6, 1, 6,10, 1, 8, 1, 3},
        new int[] { 1, 0,10,10, 0, 6, 0, 4, 6},
        new int[] { 8, 0, 3, 9, 6,10, 9, 4, 6},
        new int[] {10, 4, 6,10, 9, 4},
        new int[] { 9, 5, 4, 7, 6,11},
        new int[] { 4, 9, 5, 3, 0, 8,11, 7, 6},
        new int[] { 6,11, 7, 4, 0, 1, 4, 1, 5},
        new int[] { 6,11, 7, 4, 8, 5, 5, 8, 3, 5, 3, 1},
        new int[] { 6,11, 7, 1, 2,10, 9, 5, 4},
        new int[] {11, 7, 6, 8, 3, 0, 1, 2,10, 9, 5, 4},
        new int[] {11, 7, 6,10, 5, 2, 2, 5, 4, 2, 4, 0},
        new int[] { 7, 4, 8, 2,11, 3,10, 5, 6},
        new int[] { 4, 9, 5, 6, 2, 3, 6, 3, 7},
        new int[] { 9, 5, 4, 8, 7, 0, 0, 7, 6, 0, 6, 2},
        new int[] { 4, 0, 1, 4, 1, 5, 6, 3, 7, 6, 2, 3},
        new int[] { 7, 4, 8, 5, 2, 1, 5, 6, 2},
        new int[] { 4, 9, 5, 6,10, 7, 7,10, 1, 7, 1, 3},
        new int[] { 5, 6,10, 0, 9, 1, 8, 7, 4},
        new int[] { 5, 6,10, 7, 0, 3, 7, 4, 0},
        new int[] {10, 5, 6, 4, 8, 7},
        new int[] { 5, 6, 9, 6,11, 9, 9,11, 8},
        new int[] { 0, 9, 5, 0, 5, 3, 3, 5, 6, 3, 6,11},
        new int[] { 0, 1, 5, 0, 5,11, 5, 6,11, 0,11, 8},
        new int[] {11, 3, 6, 6, 3, 5, 3, 1, 5},
        new int[] { 1, 2,10, 5, 6, 9, 9, 6,11, 9,11, 8},
        new int[] { 1, 0, 9, 6,10, 5,11, 3, 2},
        new int[] { 6,10, 5, 2, 8, 0, 2,11, 8},
        new int[] { 3, 2,11,10, 5, 6},
        new int[] { 9, 5, 6, 3, 9, 6, 3, 8, 9, 3, 6, 2},
        new int[] { 5, 6, 9, 9, 6, 0, 6, 2, 0},
        new int[] { 0, 3, 8, 2, 5, 6, 2, 1, 5},
        new int[] { 1, 6, 2, 1, 5, 6},
        new int[] {10, 5, 6, 9, 3, 8, 9, 1, 3},
        new int[] { 0, 9, 1, 5, 6,10},
        new int[] { 8, 0, 3,10, 5, 6},
        new int[] {10, 5, 6},
        new int[] {11, 7, 5,11, 5,10},
        new int[] { 3, 0, 8, 7, 5,10, 7,10,11},
        new int[] { 9, 0, 1,10,11, 7,10, 7, 5},
        new int[] { 3, 1, 9, 3, 9, 8, 7,10,11, 7, 5,10},
        new int[] { 2,11, 1,11, 7, 1, 1, 7, 5},
        new int[] { 0, 8, 3, 2,11, 1, 1,11, 7, 1, 7, 5},
        new int[] { 9, 0, 2, 9, 2, 7, 2,11, 7, 9, 7, 5},
        new int[] {11, 3, 2, 8, 5, 9, 8, 7, 5},
        new int[] {10, 2, 5, 2, 3, 5, 5, 3, 7},
        new int[] { 5,10, 2, 8, 5, 2, 8, 7, 5, 8, 2, 0},
        new int[] { 9, 0, 1,10, 2, 5, 5, 2, 3, 5, 3, 7},
        new int[] { 1,10, 2, 5, 8, 7, 5, 9, 8},
        new int[] { 1, 3, 7, 1, 7, 5},
        new int[] { 8, 7, 0, 0, 7, 1, 7, 5, 1},
        new int[] { 0, 3, 9, 9, 3, 5, 3, 7, 5},
        new int[] { 9, 7, 5, 9, 8, 7},
        new int[] { 4, 5, 8, 5,10, 8, 8,10,11},
        new int[] { 3, 0, 4, 3, 4,10, 4, 5,10, 3,10,11},
        new int[] { 0, 1, 9, 4, 5, 8, 8, 5,10, 8,10,11},
        new int[] { 5, 9, 4, 1,11, 3, 1,10,11},
        new int[] { 8, 4, 5, 2, 8, 5, 2,11, 8, 2, 5, 1},
        new int[] { 3, 2,11, 1, 4, 5, 1, 0, 4},
        new int[] { 9, 4, 5, 8, 2,11, 8, 0, 2},
        new int[] {11, 3, 2, 9, 4, 5},
        new int[] { 3, 8, 4, 3, 4, 2, 2, 4, 5, 2, 5,10},
        new int[] {10, 2, 5, 5, 2, 4, 2, 0, 4},
        new int[] { 0, 3, 8, 5, 9, 4,10, 2, 1},
        new int[] { 2, 1,10, 9, 4, 5},
        new int[] { 4, 5, 8, 8, 5, 3, 5, 1, 3},
        new int[] { 5, 0, 4, 5, 1, 0},
        new int[] { 3, 8, 0, 4, 5, 9},
        new int[] { 9, 4, 5},
        new int[] { 7, 4,11, 4, 9,11,11, 9,10},
        new int[] { 3, 0, 8, 7, 4,11,11, 4, 9,11, 9,10},
        new int[] {11, 7, 4, 1,11, 4, 1,10,11, 1, 4, 0},
        new int[] { 8, 7, 4,11, 1,10,11, 3, 1},
        new int[] { 2,11, 7, 2, 7, 1, 1, 7, 4, 1, 4, 9},
        new int[] { 3, 2,11, 4, 8, 7, 9, 1, 0},
        new int[] { 7, 4,11,11, 4, 2, 4, 0, 2},
        new int[] { 2,11, 3, 7, 4, 8},
        new int[] { 2, 3, 7, 2, 7, 9, 7, 4, 9, 2, 9,10},
        new int[] { 4, 8, 7, 0,10, 2, 0, 9,10},
        new int[] { 2, 1,10, 0, 7, 4, 0, 3, 7},
        new int[] {10, 2, 1, 8, 7, 4},
        new int[] { 9, 1, 4, 4, 1, 7, 1, 3, 7},
        new int[] { 1, 0, 9, 8, 7, 4},
        new int[] { 3, 4, 0, 3, 7, 4},
        new int[] { 8, 7, 4},
        new int[] { 8, 9,10, 8,10,11},
        new int[] { 0, 9, 3, 3, 9,11, 9,10,11},
        new int[] { 1,10, 0, 0,10, 8,10,11, 8},
        new int[] {10, 3, 1,10,11, 3},
        new int[] { 2,11, 1, 1,11, 9,11, 8, 9},
        new int[] {11, 3, 2, 0, 9, 1},
        new int[] {11, 0, 2,11, 8, 0},
        new int[] {11, 3, 2},
        new int[] { 3, 8, 2, 2, 8,10, 8, 9,10},
        new int[] { 9, 2, 0, 9,10, 2},
        new int[] { 8, 0, 3, 1,10, 2},
        new int[] {10, 2, 1},
        new int[] { 8, 1, 3, 8, 9, 1},
        new int[] { 9, 1, 0},
        new int[] { 8, 0, 3},
        new int[] {}
    };
}
```

I know the code is really messy but the problem probably is in the CreateMesh method or in the triangulation table.

Does someone know why the hole is appearing there?
I have the triangulation table from the internet.

Thanks.

答: I got it fixed with a new triangulation table. Thanks for your help.</p>

Body:
I just made a marching cubes algorythm and after 2 days i saw some holes in the mesh.

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public class MarchinCubes : MonoBehaviour
{
    public int size = 1;
    public float surfaceValue = .5f;

    public int xOffset = 0;
    public int yOffset = 0;
    public int zOffset = 0;

    public float zoom = 1;
    public bool interpolation;
    public bool shading;
    public bool autoUpdate;

    public bool sphereValues;

    void Start()
    {
        xOffset = (int)transform.position.x;
        yOffset = (int)transform.position.y;
        zOffset = (int)transform.position.z;

        Starter();
    }

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.U) || autoUpdate)
        {
            xOffset = (int)transform.position.x;
            yOffset = (int)transform.position.y;
            zOffset = (int)transform.position.z;

            Starter();

            Vector3 position = transform.position;

            Vector3 newPosition = new Vector3(Mathf.Floor(position.x), Mathf.Floor(position.y), Mathf.Floor(position.z));

            transform.position = newPosition;
        }
    }

    void Starter()
    {
        int pointSize = size + 1;
        float[][][] values = sphereValues ? sphere(pointSize) : Perlin(pointSize);

        Mesh mesh = CreateMesh(values, pointSize - 1);

        mesh.RecalculateNormals();
        GetComponent<MeshFilter>().mesh = mesh;
    }

    float[][][] sphere(int size)
    {
        float[][][] values = initializeFloatArray(size);

        for (int x = 0; x < size; x++)
        {
            for (int y = 0; y < size; y++)
            {
                for (int z = 0; z < size; z++)
                {
                    values[x][y][z] = 10 - distance(x, y, z, size / 2, size / 2, size / 2);
                }
            }
        }

        return values;
    }

    float distance(float x, float y, float z, float xCenter, float yCenter, float zCenter)
    {
        return Mathf.Sqrt(Mathf.Pow(x - xCenter, 2) + Mathf.Pow(y - yCenter, 2) + Mathf.Pow(z - zCenter, 2));
    }

    float[][][] Perlin(int size)
    {
        float[][][] values = initializeFloatArray(size);

        for (int x = 0; x < size; x++)
        {
            for (int y = 0; y < size; y++)
            {
                for (int z = 0; z < size; z++)
                {
                    if (x == 0 || x == size - 1 || y == 0 || y == size - 1 ||z == 0 || z == size - 1)
                    {
                        values[x][y][z] = 0;
                    }
                    else
                    {
                        values[x][y][z] = (GetPerlin(x, y, z, 40f) + GetPerlin(x, y, z, 20f)) / 2;
                    }
                }
            }
        }

        return values;
    }

    float GetPerlin(int xInt, int yInt, int zInt, float divider)
    {
        float z = (zInt + zOffset) / divider;
        float y = (yInt + yOffset) / divider;
        float x = (xInt + xOffset) / divider;

        float zy = Mathf.PerlinNoise(x, y);
        float zx = Mathf.PerlinNoise(x, z);
        float yx = Mathf.PerlinNoise(y, z);
        float yz = Mathf.PerlinNoise(y, x);
        float xz = Mathf.PerlinNoise(z, x);
        float xy = Mathf.PerlinNoise(z, y);

        return (xy + xz + yz + yx + zx + zy) / 6;
    }

    float[][][] initializeFloatArray(int size)
    {
        float[][][] values = new float[size][][];

        for (int x = 0; x < size; x++)
        {
            values[x] = new float[size][];

            for (int i = 0; i < size; i++)
            {
                values[x][i] = new float[size];
            }
        }

        return values;
    }

    Mesh CreateMesh(float[][][] values, int size)
    {
        Vector3[] vertices = initializeVector3Array(size * 2 + 1, size * 2 + 1, size * 2 + 1);
        int[] triangles = new int[size * size * size * 3 * 2];
        Mesh mesh = new Mesh();

        int triangleCount = 0;

        for (int x = 0; x < size; x++)
        {
            for (int y = 0; y < size; y++)
            {
                for (int z = 0; z < size; z++)
                {
                    int[] triangleTable = table[getTriangleIndex(
                        new[] {
                            values[x][y][z],
                            values[x + 1][y][z],
                            values[x + 1][y][z + 1],
                            values[x][y][z + 1],
                            values[x][y + 1][z],
                            values[x + 1][y + 1][z],
                            values[x + 1][y + 1][z + 1],
                            values[x][y + 1][z + 1]
                        },
                        surfaceValue)];

                    int[] trianglesToAdd = new int[triangleTable.Length];

                    for (int i = 0; i < triangleTable.Length; i += 3)
                    {
                        trianglesToAdd[i] = getVertexIndex(x, y, z, triangleTable[i], size * 2 + 2);
                        trianglesToAdd[i + 1] = getVertexIndex(x, y, z, triangleTable[i + 1], size * 2 + 2);
                        trianglesToAdd[i + 2] = getVertexIndex(x, y, z, triangleTable[i + 2], size * 2 + 2);
                    }

                    for (int i = 0; i < trianglesToAdd.Length; i++)
                    {
                        triangles[triangleCount] = trianglesToAdd[i];
                        triangleCount++;
                    }
                }
            }
        }

        if (interpolation)
        {
            vertices = addIndterpolation(vertices, size * 2 + 2, values, surfaceValue);
        }

        vertices = ScaleVertices(vertices);

        if (shading == false)
        {
            RemakeMeshToDiscrete(vertices, triangles, out vertices, out triangles);
        }

        mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;

        mesh.vertices = vertices;
        mesh.triangles = triangles;

        return mesh;
    }

    Vector3[] ScaleVertices(Vector3[] vertices)
    {
        for (int i = 0; i < vertices.Length; i++)
        {
            vertices[i].x = vertices[i].x / transform.localScale.x;
            vertices[i].y = vertices[i].y / transform.localScale.y;
            vertices[i].z = vertices[i].z / transform.localScale.z;
        }
        return vertices;
    }

    void RemakeMeshToDiscrete(Vector3[] vert, int[] trig, out Vector3[] outVertices, out int[] outTriangles)
    {
        Vector3[] vertDiscrete = new Vector3[trig.Length];
        int[] trigDiscrete = new int[trig.Length];
        for (int i = 0; i < trig.Length; i++)
        {
            vertDiscrete[i] = vert[trig[i]];
            trigDiscrete[i] = i;
        }
        outVertices = vertDiscrete;
        outTriangles = trigDiscrete;
    }

    Vector3[] addIndterpolation(Vector3[] array, int sizeVertices, float[][][] values, float surfaceValue)
    {
        int sizeValues = values.Length;
        for (int x = 0; x < sizeValues - 1; x++)
        {
            for (int y = 0; y < sizeValues - 1; y++)
            {
                for (int z = 0; z < sizeValues - 1; z++)
                {
                    int arrayCords = z * 2 + y * sizeVertices * 2 + x * sizeVertices * sizeVertices * 2;

                    float value = values[x][y][z];
                    float valueZ = values[x + 1][y][z];
                    float valueY = values[x][y + 1][z];
                    float valueX = values[x][y][z + 1];

                    float interpolationValueX = Mathf.Abs(surfaceValue - value) / (Mathf.Abs(surfaceValue - value) + Mathf.Abs(surfaceValue - valueX));
                    float interpolationValueY = Mathf.Abs(surfaceValue - value) / (Mathf.Abs(surfaceValue - value) + Mathf.Abs(surfaceValue - valueY));
                    float interpolationValueZ = Mathf.Abs(surfaceValue - value) / (Mathf.Abs(surfaceValue - value) + Mathf.Abs(surfaceValue - valueZ));

                    array[arrayCords + 1] += new Vector3(0, 0, interpolationValueX - .5f);

                    array[arrayCords + sizeVertices] += new Vector3(0, interpolationValueY - .5f, 0);

                    array[arrayCords + sizeVertices * sizeVertices] += new Vector3(interpolationValueZ - .5f, 0, 0);
                }
            }
        }

        return array;
    }

    int getVertexIndex(int z, int y, int x, int cubeValue, int size)
    {
        int[][] vertecieValues = new[] {
            new []{1, 0, 0 },
            new []{2, 0, 1 },
            new []{1, 0, 2 },
            new []{0, 0, 1 },
            new []{1, 2, 0 },
            new []{2, 2, 1 },
            new []{1, 2, 2 },
            new []{0, 2, 1 },
            new []{0, 1, 0 },
            new []{2, 1, 0 },
            new []{2, 1, 2 },
            new []{0, 1, 2 }
        };

        int xReturn = z * 2 * size * size;
        int yReturn = y * 2 * size;
        int zReturn = x * 2;
        return xReturn + vertecieValues[cubeValue][0] * size * size + yReturn + vertecieValues[cubeValue][1] * size + zReturn + vertecieValues[cubeValue][2];
    }

    int getTriangleIndex(float[] values, float surfaceValue)
    {
        int index = 0;

        for (int i = 0; i < 8; i++)
        {
            if (values[i] > surfaceValue)
            {
                index |= 1 << i;
            }
        }
        return index;
    }

    Vector3[] initializeVector3Array(int Xsize, int Ysize, int Zsize)
    {
        Vector3[] array = new Vector3[(Xsize + 1) * (Ysize + 1) * (Zsize + 1)];
        int count = 0;
        for (int x = 0; x < Xsize + 1; x++)
        {
            for (int y = 0; y < Ysize + 1; y++)
            {
                for (int z = 0; z < Zsize + 1; z++)
                {
                    array[count] = new Vector3(x / 2f, y / 2f, z / 2f);
                    count++;
                }
            }
        }

        return array;
    }

    int[][] table = new int[][] {
        new int[] { },
        new int[] { 8, 3, 0},
        new int[] { 9, 0, 1},
        new int[] { 8, 3, 1, 8, 1, 9},
        new int[] {10, 1, 2},
        new int[] { 8, 3, 0, 1, 2,10},
        new int[] { 9, 0, 2, 9, 2,10},
        new int[] { 3, 2, 8, 2,10, 8, 8,10, 9},
        new int[] {11, 2, 3},
        new int[] {11, 2, 0,11, 0, 8},
        new int[] {11, 2, 3, 0, 1, 9},
        new int[] { 2, 1,11, 1, 9,11,11, 9, 8},
        new int[] {10, 1, 3,10, 3,11},
        new int[] { 1, 0,10, 0, 8,10,10, 8,11},
        new int[] { 0, 3, 9, 3,11, 9, 9,11,10},
        new int[] { 8,10, 9, 8,11,10},
        new int[] { 8, 4, 7},
        new int[] { 3, 0, 4, 3, 4, 7},
        new int[] { 1, 9, 0, 8, 4, 7},
        new int[] { 9, 4, 1, 4, 7, 1, 1, 7, 3},
        new int[] {10, 1, 2, 8, 4, 7},
        new int[] { 2,10, 1, 0, 4, 7, 0, 7, 3},
        new int[] { 4, 7, 8, 0, 2,10, 0,10, 9},
        new int[] { 2, 7, 3, 2, 9, 7, 7, 9, 4, 2,10, 9},
        new int[] { 2, 3,11, 7, 8, 4},
        new int[] { 7,11, 4,11, 2, 4, 4, 2, 0},
        new int[] { 3,11, 2, 4, 7, 8, 9, 0, 1},
        new int[] { 2, 7,11, 2, 1, 7, 1, 4, 7, 1, 9, 4},
        new int[] { 8, 4, 7,11,10, 1,11, 1, 3},
        new int[] {11, 4, 7, 1, 4,11, 1,11,10, 1, 0, 4},
        new int[] { 3, 8, 0, 7,11, 4,11, 9, 4,11,10, 9},
        new int[] { 7,11, 4, 4,11, 9,11,10, 9},
        new int[] { 9, 5, 4},
        new int[] { 3, 0, 8, 4, 9, 5},
        new int[] { 5, 4, 0, 5, 0, 1},
        new int[] { 4, 8, 5, 8, 3, 5, 5, 3, 1},
        new int[] { 2,10, 1, 9, 5, 4},
        new int[] { 0, 8, 3, 5, 4, 9,10, 1, 2},
        new int[] {10, 5, 2, 5, 4, 2, 2, 4, 0},
        new int[] { 3, 4, 8, 3, 2, 4, 2, 5, 4, 2,10, 5},
        new int[] {11, 2, 3, 9, 5, 4},
        new int[] { 9, 5, 4, 8,11, 2, 8, 2, 0},
        new int[] { 3,11, 2, 1, 5, 4, 1, 4, 0},
        new int[] { 8, 5, 4, 2, 5, 8, 2, 8,11, 2, 1, 5},
        new int[] { 5, 4, 9, 1, 3,11, 1,11,10},
        new int[] { 0, 9, 1, 4, 8, 5, 8,10, 5, 8,11,10},
        new int[] { 3, 4, 0, 3,10, 4, 4,10, 5, 3,11,10},
        new int[] { 4, 8, 5, 5, 8,10, 8,11,10},
        new int[] { 9, 5, 7, 9, 7, 8},
        new int[] { 0, 9, 3, 9, 5, 3, 3, 5, 7},
        new int[] { 8, 0, 7, 0, 1, 7, 7, 1, 5},
        new int[] { 1, 7, 3, 1, 5, 7},
        new int[] { 1, 2,10, 5, 7, 8, 5, 8, 9},
        new int[] { 9, 1, 0,10, 5, 2, 5, 3, 2, 5, 7, 3},
        new int[] { 5, 2,10, 8, 2, 5, 8, 5, 7, 8, 0, 2},
        new int[] {10, 5, 2, 2, 5, 3, 5, 7, 3},
        new int[] {11, 2, 3, 8, 9, 5, 8, 5, 7},
        new int[] { 9, 2, 0, 9, 7, 2, 2, 7,11, 9, 5, 7},
        new int[] { 0, 3, 8, 2, 1,11, 1, 7,11, 1, 5, 7},
        new int[] { 2, 1,11,11, 1, 7, 1, 5, 7},
        new int[] { 3, 9, 1, 3, 8, 9, 7,11,10, 7,10, 5},
        new int[] { 9, 1, 0,10, 7,11,10, 5, 7},
        new int[] { 3, 8, 0, 7,10, 5, 7,11,10},
        new int[] {11, 5, 7,11,10, 5},
        new int[] {10, 6, 5},
        new int[] { 8, 3, 0,10, 6, 5},
        new int[] { 0, 1, 9, 5,10, 6},
        new int[] {10, 6, 5, 9, 8, 3, 9, 3, 1},
        new int[] { 1, 2, 6, 1, 6, 5},
        new int[] { 0, 8, 3, 2, 6, 5, 2, 5, 1},
        new int[] { 5, 9, 6, 9, 0, 6, 6, 0, 2},
        new int[] { 9, 6, 5, 3, 6, 9, 3, 9, 8, 3, 2, 6},
        new int[] { 3,11, 2,10, 6, 5},
        new int[] { 6, 5,10, 2, 0, 8, 2, 8,11},
        new int[] { 1, 9, 0, 6, 5,10,11, 2, 3},
        new int[] { 1,10, 2, 5, 9, 6, 9,11, 6, 9, 8,11},
        new int[] {11, 6, 3, 6, 5, 3, 3, 5, 1},
        new int[] { 0, 5, 1, 0,11, 5, 5,11, 6, 0, 8,11},
        new int[] { 0, 5, 9, 0, 3, 5, 3, 6, 5, 3,11, 6},
        new int[] { 5, 9, 6, 6, 9,11, 9, 8,11},
        new int[] {10, 6, 5, 4, 7, 8},
        new int[] { 5,10, 6, 7, 3, 0, 7, 0, 4},
        new int[] { 5,10, 6, 0, 1, 9, 8, 4, 7},
        new int[] { 4, 5, 9, 6, 7,10, 7, 1,10, 7, 3, 1},
        new int[] { 7, 8, 4, 5, 1, 2, 5, 2, 6},
        new int[] { 4, 1, 0, 4, 5, 1, 6, 7, 3, 6, 3, 2},
        new int[] { 9, 4, 5, 8, 0, 7, 0, 6, 7, 0, 2, 6},
        new int[] { 4, 5, 9, 6, 3, 2, 6, 7, 3},
        new int[] { 7, 8, 4, 2, 3,11,10, 6, 5},
        new int[] {11, 6, 7,10, 2, 5, 2, 4, 5, 2, 0, 4},
        new int[] {11, 6, 7, 8, 0, 3, 1,10, 2, 9, 4, 5},
        new int[] { 6, 7,11, 1,10, 2, 9, 4, 5},
        new int[] { 6, 7,11, 4, 5, 8, 5, 3, 8, 5, 1, 3},
        new int[] { 6, 7,11, 4, 1, 0, 4, 5, 1},
        new int[] { 4, 5, 9, 3, 8, 0,11, 6, 7},
        new int[] { 9, 4, 5, 7,11, 6},
        new int[] {10, 6, 4,10, 4, 9},
        new int[] { 8, 3, 0, 9,10, 6, 9, 6, 4},
        new int[] { 1,10, 0,10, 6, 0, 0, 6, 4},
        new int[] { 8, 6, 4, 8, 1, 6, 6, 1,10, 8, 3, 1},
        new int[] { 9, 1, 4, 1, 2, 4, 4, 2, 6},
        new int[] { 1, 0, 9, 3, 2, 8, 2, 4, 8, 2, 6, 4},
        new int[] { 2, 4, 0, 2, 6, 4},
        new int[] { 3, 2, 8, 8, 2, 4, 2, 6, 4},
        new int[] { 2, 3,11, 6, 4, 9, 6, 9,10},
        new int[] { 0,10, 2, 0, 9,10, 4, 8,11, 4,11, 6},
        new int[] {10, 2, 1,11, 6, 3, 6, 0, 3, 6, 4, 0},
        new int[] {10, 2, 1,11, 4, 8,11, 6, 4},
        new int[] { 1, 4, 9,11, 4, 1,11, 1, 3,11, 6, 4},
        new int[] { 0, 9, 1, 4,11, 6, 4, 8,11},
        new int[] {11, 6, 3, 3, 6, 0, 6, 4, 0},
        new int[] { 8, 6, 4, 8,11, 6},
        new int[] { 6, 7,10, 7, 8,10,10, 8, 9},
        new int[] { 9, 3, 0, 6, 3, 9, 6, 9,10, 6, 7, 3},
        new int[] { 6, 1,10, 6, 7, 1, 7, 0, 1, 7, 8, 0},
        new int[] { 6, 7,10,10, 7, 1, 7, 3, 1},
        new int[] { 7, 2, 6, 7, 9, 2, 2, 9, 1, 7, 8, 9},
        new int[] { 1, 0, 9, 3, 6, 7, 3, 2, 6},
        new int[] { 8, 0, 7, 7, 0, 6, 0, 2, 6},
        new int[] { 2, 7, 3, 2, 6, 7},
        new int[] { 7,11, 6, 3, 8, 2, 8,10, 2, 8, 9,10},
        new int[] {11, 6, 7,10, 0, 9,10, 2, 0},
        new int[] { 2, 1,10, 7,11, 6, 8, 0, 3},
        new int[] { 1,10, 2, 6, 7,11},
        new int[] { 7,11, 6, 3, 9, 1, 3, 8, 9},
        new int[] { 9, 1, 0,11, 6, 7},
        new int[] { 0, 3, 8,11, 6, 7},
        new int[] {11, 6, 7},
        new int[] {11, 7, 6},
        new int[] { 0, 8, 3,11, 7, 6},
        new int[] { 9, 0, 1,11, 7, 6},
        new int[] { 7, 6,11, 3, 1, 9, 3, 9, 8},
        new int[] { 1, 2,10, 6,11, 7},
        new int[] { 2,10, 1, 7, 6,11, 8, 3, 0},
        new int[] {11, 7, 6,10, 9, 0,10, 0, 2},
        new int[] { 7, 6,11, 3, 2, 8, 8, 2,10, 8,10, 9},
        new int[] { 2, 3, 7, 2, 7, 6},
        new int[] { 8, 7, 0, 7, 6, 0, 0, 6, 2},
        new int[] { 1, 9, 0, 3, 7, 6, 3, 6, 2},
        new int[] { 7, 6, 2, 7, 2, 9, 2, 1, 9, 7, 9, 8},
        new int[] { 6,10, 7,10, 1, 7, 7, 1, 3},
        new int[] { 6,10, 1, 6, 1, 7, 7, 1, 0, 7, 0, 8},
        new int[] { 9, 0, 3, 6, 9, 3, 6,10, 9, 6, 3, 7},
        new int[] { 6,10, 7, 7,10, 8,10, 9, 8},
        new int[] { 8, 4, 6, 8, 6,11},
        new int[] {11, 3, 6, 3, 0, 6, 6, 0, 4},
        new int[] { 0, 1, 9, 4, 6,11, 4,11, 8},
        new int[] { 1, 9, 4,11, 1, 4,11, 3, 1,11, 4, 6},
        new int[] {10, 1, 2,11, 8, 4,11, 4, 6},
        new int[] {10, 1, 2,11, 3, 6, 6, 3, 0, 6, 0, 4},
        new int[] { 0, 2,10, 0,10, 9, 4,11, 8, 4, 6,11},
        new int[] { 2,11, 3, 6, 9, 4, 6,10, 9},
        new int[] { 3, 8, 2, 8, 4, 2, 2, 4, 6},
        new int[] { 2, 0, 4, 2, 4, 6},
        new int[] { 1, 9, 0, 3, 8, 2, 2, 8, 4, 2, 4, 6},
        new int[] { 9, 4, 1, 1, 4, 2, 4, 6, 2},
        new int[] { 8, 4, 6, 8, 6, 1, 6,10, 1, 8, 1, 3},
        new int[] { 1, 0,10,10, 0, 6, 0, 4, 6},
        new int[] { 8, 0, 3, 9, 6,10, 9, 4, 6},
        new int[] {10, 4, 6,10, 9, 4},
        new int[] { 9, 5, 4, 7, 6,11},
        new int[] { 4, 9, 5, 3, 0, 8,11, 7, 6},
        new int[] { 6,11, 7, 4, 0, 1, 4, 1, 5},
        new int[] { 6,11, 7, 4, 8, 5, 5, 8, 3, 5, 3, 1},
        new int[] { 6,11, 7, 1, 2,10, 9, 5, 4},
        new int[] {11, 7, 6, 8, 3, 0, 1, 2,10, 9, 5, 4},
        new int[] {11, 7, 6,10, 5, 2, 2, 5, 4, 2, 4, 0},
        new int[] { 7, 4, 8, 2,11, 3,10, 5, 6},
        new int[] { 4, 9, 5, 6, 2, 3, 6, 3, 7},
        new int[] { 9, 5, 4, 8, 7, 0, 0, 7, 6, 0, 6, 2},
        new int[] { 4, 0, 1, 4, 1, 5, 6, 3, 7, 6, 2, 3},
        new int[] { 7, 4, 8, 5, 2, 1, 5, 6, 2},
        new int[] { 4, 9, 5, 6,10, 7, 7,10, 1, 7, 1, 3},
        new int[] { 5, 6,10, 0, 9, 1, 8, 7, 4},
        new int[] { 5, 6,10, 7, 0, 3, 7, 4, 0},
        new int[] {10, 5, 6, 4, 8, 7},
        new int[] { 5, 6, 9, 6,11, 9, 9,11, 8},
        new int[] { 0, 9, 5, 0, 5, 3, 3, 5, 6, 3, 6,11},
        new int[] { 0, 1, 5, 0, 5,11, 5, 6,11, 0,11, 8},
        new int[] {11, 3, 6, 6, 3, 5, 3, 1, 5},
        new int[] { 1, 2,10, 5, 6, 9, 9, 6,11, 9,11, 8},
        new int[] { 1, 0, 9, 6,10, 5,11, 3, 2},
        new int[] { 6,10, 5, 2, 8, 0, 2,11, 8},
        new int[] { 3, 2,11,10, 5, 6},
        new int[] { 9, 5, 6, 3, 9, 6, 3, 8, 9, 3, 6, 2},
        new int[] { 5, 6, 9, 9, 6, 0, 6, 2, 0},
        new int[] { 0, 3, 8, 2, 5, 6, 2, 1, 5},
        new int[] { 1, 6, 2, 1, 5, 6},
        new int[] {10, 5, 6, 9, 3, 8, 9, 1, 3},
        new int[] { 0, 9, 1, 5, 6,10},
        new int[] { 8, 0, 3,10, 5, 6},
        new int[] {10, 5, 6},
        new int[] {11, 7, 5,11, 5,10},
        new int[] { 3, 0, 8, 7, 5,10, 7,10,11},
        new int[] { 9, 0, 1,10,11, 7,10, 7, 5},
        new int[] { 3, 1, 9, 3, 9, 8, 7,10,11, 7, 5,10},
        new int[] { 2,11, 1,11, 7, 1, 1, 7, 5},
        new int[] { 0, 8, 3, 2,11, 1, 1,11, 7, 1, 7, 5},
        new int[] { 9, 0, 2, 9, 2, 7, 2,11, 7, 9, 7, 5},
        new int[] {11, 3, 2, 8, 5, 9, 8, 7, 5},
        new int[] {10, 2, 5, 2, 3, 5, 5, 3, 7},
        new int[] { 5,10, 2, 8, 5, 2, 8, 7, 5, 8, 2, 0},
        new int[] { 9, 0, 1,10, 2, 5, 5, 2, 3, 5, 3, 7},
        new int[] { 1,10, 2, 5, 8, 7, 5, 9, 8},
        new int[] { 1, 3, 7, 1, 7, 5},
        new int[] { 8, 7, 0, 0, 7, 1, 7, 5, 1},
        new int[] { 0, 3, 9, 9, 3, 5, 3, 7, 5},
        new int[] { 9, 7, 5, 9, 8, 7},
        new int[] { 4, 5, 8, 5,10, 8, 8,10,11},
        new int[] { 3, 0, 4, 3, 4,10, 4, 5,10, 3,10,11},
        new int[] { 0, 1, 9, 4, 5, 8, 8, 5,10, 8,10,11},
        new int[] { 5, 9, 4, 1,11, 3, 1,10,11},
        new int[] { 8, 4, 5, 2, 8, 5, 2,11, 8, 2, 5, 1},
        new int[] { 3, 2,11, 1, 4, 5, 1, 0, 4},
        new int[] { 9, 4, 5, 8, 2,11, 8, 0, 2},
        new int[] {11, 3, 2, 9, 4, 5},
        new int[] { 3, 8, 4, 3, 4, 2, 2, 4, 5, 2, 5,10},
        new int[] {10, 2, 5, 5, 2, 4, 2, 0, 4},
        new int[] { 0, 3, 8, 5, 9, 4,10, 2, 1},
        new int[] { 2, 1,10, 9, 4, 5},
        new int[] { 4, 5, 8, 8, 5, 3, 5, 1, 3},
        new int[] { 5, 0, 4, 5, 1, 0},
        new int[] { 3, 8, 0, 4, 5, 9},
        new int[] { 9, 4, 5},
        new int[] { 7, 4,11, 4, 9,11,11, 9,10},
        new int[] { 3, 0, 8, 7, 4,11,11, 4, 9,11, 9,10},
        new int[] {11, 7, 4, 1,11, 4, 1,10,11, 1, 4, 0},
        new int[] { 8, 7, 4,11, 1,10,11, 3, 1},
        new int[] { 2,11, 7, 2, 7, 1, 1, 7, 4, 1, 4, 9},
        new int[] { 3, 2,11, 4, 8, 7, 9, 1, 0},
        new int[] { 7, 4,11,11, 4, 2, 4, 0, 2},
        new int[] { 2,11, 3, 7, 4, 8},
        new int[] { 2, 3, 7, 2, 7, 9, 7, 4, 9, 2, 9,10},
        new int[] { 4, 8, 7, 0,10, 2, 0, 9,10},
        new int[] { 2, 1,10, 0, 7, 4, 0, 3, 7},
        new int[] {10, 2, 1, 8, 7, 4},
        new int[] { 9, 1, 4, 4, 1, 7, 1, 3, 7},
        new int[] { 1, 0, 9, 8, 7, 4},
        new int[] { 3, 4, 0, 3, 7, 4},
        new int[] { 8, 7, 4},
        new int[] { 8, 9,10, 8,10,11},
        new int[] { 0, 9, 3, 3, 9,11, 9,10,11},
        new int[] { 1,10, 0, 0,10, 8,10,11, 8},
        new int[] {10, 3, 1,10,11, 3},
        new int[] { 2,11, 1, 1,11, 9,11, 8, 9},
        new int[] {11, 3, 2, 0, 9, 1},
        new int[] {11, 0, 2,11, 8, 0},
        new int[] {11, 3, 2},
        new int[] { 3, 8, 2, 2, 8,10, 8, 9,10},
        new int[] { 9, 2, 0, 9,10, 2},
        new int[] { 8, 0, 3, 1,10, 2},
        new int[] {10, 2, 1},
        new int[] { 8, 1, 3, 8, 9, 1},
        new int[] { 9, 1, 0},
        new int[] { 8, 0, 3},
        new int[] {}
    };
}

I know the code is really messy but the problem probably is in the CreateMesh method or in the triangulation table.

Does someone know why the hole is appearing there?
I have the triangulation table from the internet.

Thanks.


来源: stackexchange

问:
How to optimize the cleaning of Twitter texts?
How can I rewrite the text cleaning function and make it more efficient?

```<code>import com.ibm.icu.text.Normalizer2

// A whitespace character: [ \t\n\x0B\f\r]
private val whiteSpaceRegex = "\\p{Space}"
// Any except letter (subtraction)
private val exceptLetterRegex = "[^\\p{L}]"

val normalize = (str: String) => Normalizer2.getNFKCCasefoldInstance.normalize(str)

val cleanse = (str: String) => normalize(str) // 1
  .toLowerCase // 2
  .split(whiteSpaceRegex) // 3
  .filterNot( // 4
    p => p.startsWith("@") || p.startsWith("/") || p.startsWith("http") || p.startsWith("www")
  ).mkString(" ") // 5
  .replaceAll("-", "") // 6
  .replaceAll(exceptLetterRegex, " ") // 7
  .replaceAll("\\s{2,}", " ") // 8
  .trim // 9
</code>```

normalize letters in string

change string to lower case

split string to Array[String] by whitespaces

filter out Twitter-specific words: links, nicknames

make String again

glue words with a hyphen (like: ex-wife to exwife)

replace all except letters by space

replace multiple spaces with single

remove first and last space

Tests:

```<code>val strMultiLine =
  """RT @digger: Что-то пиддес52 :|
и так скучать( HERE_HTTP_T_DOT_CO_LINK что,я +100500 surf cвихнусь так D:"""

val res1 = "rt чтото пиддес и так скучать что я surf cвихнусь так d"

cleanse(strMultiLine) must equal(res1)

val strWithLineBreak =
  "Говорит: \"\"Кто то в углу сидит))) и погибает от голода!!! мы,хотя уже сидим из-за\"\" :DD …"

val res2 = "говорит кто то в углу сидит и погибает от голода мы хотя уже сидим изза dd"

cleanse(strWithLineBreak) must equal(res2)
</code>```

HERE_HTTP_T_DOT_CO_LINK — Stackoverflow asked me to remove the link from the text

答:
It looks like there is not much room for a lot of enhancements. I can recommend to shrunk the first part where you remove links or mentions and the non-letter removal into a single regex, but you need to remove hyphens beforehand then:

```<code>val cleanse2 = (str: String) => normalize(str)                  // Normalize
      .replace("-","")                                          // Remove -
      .replaceAll("""(?<!\S)(?:[@/]|http|www)\S*|\P{L}""", " ") // Remove entities
      .replaceAll("""\s{2,}""", " ")                            // Shrink whitespaces
      .trim                                                     // Trim the result
      .toLowerCase                                              // To lower case
</code>```

See the regex demo.

The (?<!\S)(?:[@/]|http|www)\S*|\P{L} pattern matches

(?<!\S) - a whitespace or start of string position must precede the current position immediately

(?:[@/]|http|www)\S* - @, /, http or www and then any 0+ non-whitespace chars

| - or

\P{L} - any non-letter char.

ContentLicense: CC BY-SA 4.0

Body:
How can I rewrite the text cleaning function and make it more efficient?

import com.ibm.icu.text.Normalizer2

// A whitespace character: [ \t\n\x0B\f\r]
private val whiteSpaceRegex = "\\p{Space}"
// Any except letter (subtraction)
private val exceptLetterRegex = "[^\\p{L}]"

val normalize = (str: String) => Normalizer2.getNFKCCasefoldInstance.normalize(str)

val cleanse = (str: String) => normalize(str) // 1
  .toLowerCase // 2
  .split(whiteSpaceRegex) // 3
  .filterNot( // 4
    p => p.startsWith("@") || p.startsWith("/") || p.startsWith("http") || p.startsWith("www")
  ).mkString(" ") // 5
  .replaceAll("-", "") // 6
  .replaceAll(exceptLetterRegex, " ") // 7
  .replaceAll("\\s{2,}", " ") // 8
  .trim // 9

normalize letters in string

change string to lower case

split string to Array[String] by whitespaces

filter out Twitter-specific words: links, nicknames

make String again

glue words with a hyphen (like: ex-wife to exwife)

replace all except letters by space

replace multiple spaces with single

remove first and last space

Tests:

val strMultiLine =
  """RT @digger: Что-то пиддес52 :|
и так скучать( HERE_HTTP_T_DOT_CO_LINK что,я +100500 surf cвихнусь так D:"""

val res1 = "rt чтото пиддес и так скучать что я surf cвихнусь так d"

cleanse(strMultiLine) must equal(res1)

val strWithLineBreak =
  "Говорит: \"\"Кто то в углу сидит))) и погибает от голода!!! мы,хотя уже сидим из-за\"\" :DD …"

val res2 = "говорит кто то в углу сидит и погибает от голода мы хотя уже сидим изза dd"

cleanse(strWithLineBreak) must equal(res2)

HERE_HTTP_T_DOT_CO_LINK — Stackoverflow asked me to remove the link from the text

Body:
It looks like there is not much room for a lot of enhancements. I can recommend to shrunk the first part where you remove links or mentions and the non-letter removal into a single regex, but you need to remove hyphens beforehand then:

val cleanse2 = (str: String) => normalize(str)                  // Normalize
      .replace("-","")                                          // Remove -
      .replaceAll("""(?<!\S)(?:[@/]|http|www)\S*|\P{L}""", " ") // Remove entities
      .replaceAll("""\s{2,}""", " ")                            // Shrink whitespaces
      .trim                                                     // Trim the result
      .toLowerCase                                              // To lower case

See the regex demo.

The (?<!\S)(?:[@/]|http|www)\S*|\P{L} pattern matches

(?<!\S) - a whitespace or start of string position must precede the current position immediately

(?:[@/]|http|www)\S* - @, /, http or www and then any 0+ non-whitespace chars

| - or

\P{L} - any non-letter char.


问:
OutputDataReceived (and ErrorDataReceived) has a slow firing rate and creates a large buffer
is there a way to increase the rate a Process object in .NET throws the OutputDataReceived event?  It creates a large buffer (I believe 1024 characters) that is dumped in bulk which makes the application not as fluid of a stream as I would of like it to be.

Thank you in advance!

答:
Process.OutputDataReceived event is fired only in following two conditions.

Newline is encountered in output

Complete data is received

So if and only if you have a newline character in your output stream event will get fired else it will wait for complete data then the event will get fired.

I just tested it till 968000 bytes. Event is raised only after entire data is received as I have not kept any newline character in the output.

ContentLicense: CC BY-SA 2.5

ContentLicense: CC BY-SA 3.0


问:
Load view component(table) after finish a service call who push an array with info for the table
I'm building a dynamic table to use in my application. I'm using @Input parameters to send info like header and elements for the table.

This is the input for the table component generic.

```<code>@Input()
public listaElementosTabla: any = [];

@Input()
public titulosCabecera = [];

@Input()
public cantidadMaximaRegistros: number;
</code>```

And I call the table component in the next way:

```<code><tabla-component [listaElementosTabla]="arrayElements"
[titulosCabecera]=headElementsArray cantidadMaximaRegistros=5></tabla-component>
</code>```

I have a service to query the information from BD to a specific data and I'm saving that information in the array "arrayElements". I call the service in the onInit page.

```<code>ngOnInit() {
     this.myService.queryInfoInBd().subscribe(
        (data: ObjectDTO[]) => {
            data.forEach((objectDTO: ObjectDTO) => {
                this.arrayElements.push(objectDTO);
            });
        },
        error => {
            console.log(error);
        }
    );
}
</code>```

The problem here is that the table component is loading first that the call of the service, so, when the component is trying to obtain info about arrayElements always is empty.

I know javascript is async, but I don't know how to do to wait until the service finish and the array loads the information and after of that load the table component.

答:
One trick is to set a "flag" which shows or hides the table element.

Something like this:

in your view (html)

```<code><div *ngIf="datosCargados">
   <!--Se mostrara el elemento dentro del div si esta bandera es True-->
   <tabla-component [listaElementosTabla]="arrayElements"
   [titulosCabecera]=headElementsArray [cantidadMaximaRegistros]=5></tabla-component>
</div>
</code>```

in your .ts

```<code>datosCargados: boolean = false; //Por defecto es false para no mostrarse
ngOnInit() {
     this.myService.queryInfoInBd().subscribe(
        (data: ObjectDTO[]) => {
            data.forEach((objectDTO: ObjectDTO) => {
                this.arrayElements.push(objectDTO);
            });
            this.datosCargados = true;
        },
        error => {
            console.log(error);
            this.datosCargados = false;
        }
    );
}
</code>```

Basically what it will do is, the datosCargos will always be false (will be hidden), until the http subscribes and fetchs the data.

Hope it helps.

Body:
I'm building a dynamic table to use in my application. I'm using @Input parameters to send info like header and elements for the table.

This is the input for the table component generic.

@Input()
public listaElementosTabla: any = [];

@Input()
public titulosCabecera = [];

@Input()
public cantidadMaximaRegistros: number;

And I call the table component in the next way:

<tabla-component [listaElementosTabla]="arrayElements"
[titulosCabecera]=headElementsArray cantidadMaximaRegistros=5></tabla-component>

I have a service to query the information from BD to a specific data and I'm saving that information in the array "arrayElements". I call the service in the onInit page.

ngOnInit() {
     this.myService.queryInfoInBd().subscribe(
        (data: ObjectDTO[]) => {
            data.forEach((objectDTO: ObjectDTO) => {
                this.arrayElements.push(objectDTO);
            });
        },
        error => {
            console.log(error);
        }
    );
}

The problem here is that the table component is loading first that the call of the service, so, when the component is trying to obtain info about arrayElements always is empty.

I know javascript is async, but I don't know how to do to wait until the service finish and the array loads the information and after of that load the table component.

Body:
One trick is to set a "flag" which shows or hides the table element.

Something like this:

in your view (html)

<div *ngIf="datosCargados">
   <!--Se mostrara el elemento dentro del div si esta bandera es True-->
   <tabla-component [listaElementosTabla]="arrayElements"
   [titulosCabecera]=headElementsArray [cantidadMaximaRegistros]=5></tabla-component>
</div>

in your .ts

datosCargados: boolean = false; //Por defecto es false para no mostrarse
ngOnInit() {
     this.myService.queryInfoInBd().subscribe(
        (data: ObjectDTO[]) => {
            data.forEach((objectDTO: ObjectDTO) => {
                this.arrayElements.push(objectDTO);
            });
            this.datosCargados = true;
        },
        error => {
            console.log(error);
            this.datosCargados = false;
        }
    );
}

Basically what it will do is, the datosCargos will always be false (will be hidden), until the http subscribes and fetchs the data.

Hope it helps.


问:
Restrict attribute on update, but not creation, but fail when update can't update
I read this post on

In Rails, how do I limit which attributes can be updated, without preventing them from being created?

They problem is that the u.save returns true, so it give the impression that all the values got updated. When they did not.

Is there a way to use attr-readonly, but on save return false if an attribute is read only?

```<code>class User < ActiveRecord::Base
  attr_accessible :name
  attr_readonly :name
end

> User.create(name: "lorem")
> u = User.first
=> #<User id: 1, name: "lorem">
> u.name = "ipsum"
=> "ipsum"
> u.save
=> true
> User.first.name
=> "lorem
</code>```

答:
You can use a validator method to write an error on changes detected to your read only field

```<code>Class User
  validate :name_not_changed

  private

  def name_not_changed
    return unless name_changed?

    errors.add(:name, 'Cannot change name of User')
  end
end
</code>```

Is this really necessary though? If you're making your attribute read-only, why are you still leaving the possibility for it to be changed and additionally need validation errors for that operation? Ideally, you shouldn't permit the name to ever be used when updating models and the story ends there, no validation errors needed.

Body:
I read this post on

In Rails, how do I limit which attributes can be updated, without preventing them from being created?

They problem is that the u.save returns true, so it give the impression that all the values got updated. When they did not.

Is there a way to use attr-readonly, but on save return false if an attribute is read only?

class User < ActiveRecord::Base
  attr_accessible :name
  attr_readonly :name
end

> User.create(name: "lorem")
> u = User.first
=> #<User id: 1, name: "lorem">
> u.name = "ipsum"
=> "ipsum"
> u.save
=> true
> User.first.name
=> "lorem

Body:
You can use a validator method to write an error on changes detected to your read only field

Class User
  validate :name_not_changed

  private

  def name_not_changed
    return unless name_changed?

    errors.add(:name, 'Cannot change name of User')
  end
end

Is this really necessary though? If you're making your attribute read-only, why are you still leaving the possibility for it to be changed and additionally need validation errors for that operation? Ideally, you shouldn't permit the name to ever be used when updating models and the story ends there, no validation errors needed.


问:
\r to update output not functioning as demonstrated
I'm trying to create a loading text that alternates between "Loading", "Loading.", "Loading..", "Loading...", and "Loading...." while updating the previous entry. I found similar situations online that use either sys.stdout or a \r end to the print function but have had no luck with either

The code i'm using is:

```<code>import time
tick = 0
while True:
    print("Loading" + "." * tick, end="\r")
    if tick < 4:
        tick += 1
        time.sleep(0.4)
    else:
        tick = 0
</code>```

The output I'm getting is:

```<code>LoadingLoading.Loading..Loading...Loading....LoadingLoading.Loading..Loading...
</code>```

until I force quit the execution. i haven't seen the problem mentioned in other threads but if anyone has any idea what might be causing the issue I'd be VERY grateful.

答:
Depending on your platform you need both a carriage return \r and a newline \n or just a newline. Generally, I have found you can just do \r\n

Also depending on if you want the entire screen to clear in between "loading"s you might have to call the system call (and this differs based on platform) to clear the screen in between "loading"s being printed. This would negate the need to call \r\n because each time you print it is to a fresh console window.

You can look here for how to do this.

Body:
I'm trying to create a loading text that alternates between "Loading", "Loading.", "Loading..", "Loading...", and "Loading...." while updating the previous entry. I found similar situations online that use either sys.stdout or a \r end to the print function but have had no luck with either

The code i'm using is:

import time
tick = 0
while True:
    print("Loading" + "." * tick, end="\r")
    if tick < 4:
        tick += 1
        time.sleep(0.4)
    else:
        tick = 0

The output I'm getting is:

LoadingLoading.Loading..Loading...Loading....LoadingLoading.Loading..Loading...

until I force quit the execution. i haven't seen the problem mentioned in other threads but if anyone has any idea what might be causing the issue I'd be VERY grateful.


问:
Best way to bin all x values within a range and then take the mean of all y values in each bin?
I have a list of x,y coordinates. The x values are close together but are not the same. I would like to bin x values together within a range and then take the mean value of the y values in each bin. I want the end results to be two 1-D arrays - one of binned x values and the other of the associated y mean values.

As an example, for list = ((1.0, 10.2), (1.3, 10.1), (1.6, 10.8), (2.3, 12.0), (2.4, 12.7)),

I would like the output to be: x = [1.0, 1.5, 2.0] and y = [10.15, 10.8, 12.35].

In the code below, I try scipy's stats.binned_statistic, but have not had success as I am unsure how to specify the bin size. In the code below I put 10 elements per bin to try to get it to work, but in reality I would like to specify a range such as all numbers within a range of 0.5 of each other be binned together.

I also looked at numpy.digitize but was not if that is what I'm looking for.

```<code>import numpy as np
from scipy import stats

x = [x_values]
y = [corresponding_y_values]
test = stats.binned_statistic(x, y, 'mean', bins=(len(x))/10)
plt.plot(test)
</code>```

答:
In case anyone else has the same question in the future, I got this to work:</p>

```<code>y,x,_=stats.binned_statistic(x,l,'mean',bins=np.arange(x[0],x[int(len(x)-1)],(x[int(len(x)-1)]-x[0])/((x[int(len(x)-1)]-x[0])*10)))
</code>```

Body:
I have a list of x,y coordinates. The x values are close together but are not the same. I would like to bin x values together within a range and then take the mean value of the y values in each bin. I want the end results to be two 1-D arrays - one of binned x values and the other of the associated y mean values.

As an example, for list = ((1.0, 10.2), (1.3, 10.1), (1.6, 10.8), (2.3, 12.0), (2.4, 12.7)),

I would like the output to be: x = [1.0, 1.5, 2.0] and y = [10.15, 10.8, 12.35].

In the code below, I try scipy's stats.binned_statistic, but have not had success as I am unsure how to specify the bin size. In the code below I put 10 elements per bin to try to get it to work, but in reality I would like to specify a range such as all numbers within a range of 0.5 of each other be binned together.

I also looked at numpy.digitize but was not if that is what I'm looking for.

import numpy as np
from scipy import stats

x = [x_values]
y = [corresponding_y_values]
test = stats.binned_statistic(x, y, 'mean', bins=(len(x))/10)
plt.plot(test)

Body:
In case anyone else has the same question in the future, I got this to work:

y,x,_=stats.binned_statistic(x,l,'mean',bins=np.arange(x[0],x[int(len(x)-1)],(x[int(len(x)-1)]-x[0])/((x[int(len(x)-1)]-x[0])*10)))


问:
create variable by matching variable value to object value?
I'm attempting to create a variable that contains the value of an object.
the variable eventDateValue below is what i'm struggling with. I'm trying to match the value of EventName to the object events2020 and if there's a match (must match the object name) pass the value of that match to the variable eventDateValue.

below is my code

```<code>function getPage(){
    let pageActual = window.location.href;
    console.log(pageActual);

    let pageName = /127(.*)/;
    let EventName = pageName.exec(pageActual);
    console.log(EventName[1]);

    const events2020 = {
        Event1 :'February 19, 2020',
        Event2 :'February 18, 2020',
        Event3 :'February 17, 2020',
        Event4 :'February 16, 2020',
        Event5 :'February 15, 2020',
        Event6 :'February 14, 2020'
    };

    let eventDateValue = Object.keys(events2020)

    [Object.values(events2020).indexOf(EventName)]

    console.log(eventDateValue);
}
</code>```

答: I think what you need is let eventDateValue = events2020[EventName]

Body:
I'm attempting to create a variable that contains the value of an object.
the variable eventDateValue below is what i'm struggling with. I'm trying to match the value of EventName to the object events2020 and if there's a match (must match the object name) pass the value of that match to the variable eventDateValue.

below is my code

function getPage(){
    let pageActual = window.location.href;
    console.log(pageActual);

    let pageName = /127(.*)/;
    let EventName = pageName.exec(pageActual);
    console.log(EventName[1]);

    const events2020 = {
        Event1 :'February 19, 2020',
        Event2 :'February 18, 2020',
        Event3 :'February 17, 2020',
        Event4 :'February 16, 2020',
        Event5 :'February 15, 2020',
        Event6 :'February 14, 2020'
    };

    let eventDateValue = Object.keys(events2020)

    [Object.values(events2020).indexOf(EventName)]

    console.log(eventDateValue);
}


问:
Downloading/Exporting sites Search Results by using Export button in Python
So I'm trying to use Python to scrape data from the following website (with sample query): https://par.nsf.gov/**search**/fulltext:NASA%20NOAA%20coral

However instead of scraping the search results, I realized that it would just be easier if I somehow click on the Save Results as "CSV" link in a programmatic way and work with that CSV data instead as it would free me from having to navigate all the pages of the search results.

I inspected the CSV link element and found it called an "exportSearch('csv') function.

By typing the function's name into the console I found that the CSV link is just setting window.location.href to: https://par.nsf.gov/export/format:csv/fulltext:NASA%20NOAA%20coral

If I follow that link in the same browser, the save prompt will open up with a csv to save.

My issue starts when I want to do replicate this process using python. If I try to call the export link directly using the Requests library, the response is empty.

```<code>url = "https://par.nsf.gov/export/format:csv/fulltext:" + urllib.parse.quote("NASA NOAA coral")
print("URL: ", url)
response = requests.get(url)
print("Response: ", len(response.content))
</code>```

Can someone show me what I'm missing? I don't know how to first establish search results on the website's server that I can then access for export using Python.

答:
You can use the below to download the file in python using the urllib library.

```<code># Include your search term
url = "https://par.nsf.gov/export/format:csv//filter-results:F/term:" + urllib.parse.quote("NASA NOAA coral")
print("URL: ", url)

import urllib.request
urllib.request.urlretrieve(url)

# here you can also specify the path where you want to download the file like
urllib.request.urlretrieve(url,'/Users/Downloads/)

# Run this command only when you face an SSL certificate error, generally it occurs for Mac users with python 3.6 .
# Run this in jupyter notebook
!open /Applications/Python\ 3.6/Install\ Certificates.command

# On terminal just run
open /Applications/Python\ 3.6/Install\ Certificates.command

</code>```

Similarly you can also use wget to fetch your file:

```<code>url = "https://par.nsf.gov/export/format:csv//filter-results:F/term:" + urllib.parse.quote("NASA NOAA coral")
print("URL: ", url)

import wget
wget.download(url)
</code>```

Body:
So I'm trying to use Python to scrape data from the following website (with sample query): https://par.nsf.gov/**search**/fulltext:NASA%20NOAA%20coral

However instead of scraping the search results, I realized that it would just be easier if I somehow click on the Save Results as "CSV" link in a programmatic way and work with that CSV data instead as it would free me from having to navigate all the pages of the search results.

I inspected the CSV link element and found it called an "exportSearch('csv') function.

By typing the function's name into the console I found that the CSV link is just setting window.location.href to: https://par.nsf.gov/export/format:csv/fulltext:NASA%20NOAA%20coral

If I follow that link in the same browser, the save prompt will open up with a csv to save.

My issue starts when I want to do replicate this process using python. If I try to call the export link directly using the Requests library, the response is empty.

url = "https://par.nsf.gov/export/format:csv/fulltext:" + urllib.parse.quote("NASA NOAA coral")
print("URL: ", url)
response = requests.get(url)
print("Response: ", len(response.content))

Can someone show me what I'm missing? I don't know how to first establish search results on the website's server that I can then access for export using Python.

Body:
You can use the below to download the file in python using the urllib library.

# Include your search term
url = "https://par.nsf.gov/export/format:csv//filter-results:F/term:" + urllib.parse.quote("NASA NOAA coral")
print("URL: ", url)

import urllib.request
urllib.request.urlretrieve(url)

# here you can also specify the path where you want to download the file like
urllib.request.urlretrieve(url,'/Users/Downloads/)

# Run this command only when you face an SSL certificate error, generally it occurs for Mac users with python 3.6 .
# Run this in jupyter notebook
!open /Applications/Python\ 3.6/Install\ Certificates.command

# On terminal just run
open /Applications/Python\ 3.6/Install\ Certificates.command

Similarly you can also use wget to fetch your file:

url = "https://par.nsf.gov/export/format:csv//filter-results:F/term:" + urllib.parse.quote("NASA NOAA coral")
print("URL: ", url)

import wget
wget.download(url)


问:
How to install requests in python 3.7 on Mac
I have trying to install requests in python 3.7 on Mac. I already have python 2.7 installed.
I have read all the previous questions related to this and none of them could solve the issue. </p>

```<code> pip3.7 install requests
bash: pip3.7: command not found
python3.7 -m pip install requests
/usr/local/bin/python3.7: No module named pip
</code>```

<p>I am not able to understand the issue here. </p>

答:
There’s no “pip3.7”, just “pip3”. Try this:
pip3 install requests</p>

Body:
I have trying to install requests in python 3.7 on Mac. I already have python 2.7 installed.
I have read all the previous questions related to this and none of them could solve the issue.

 pip3.7 install requests
bash: pip3.7: command not found
python3.7 -m pip install requests
/usr/local/bin/python3.7: No module named pip

I am not able to understand the issue here.


问:
Handling an ASP.NET MVC FileResult returned in an (jQuery) Ajax call
Goal:

I want to let my users download a file on my webpage. I want a new window to open and the file to be either displayed or downloaded there.

My implementation:

This file however, first has to be generated on the server-side, which might take a while. When the user clicks the button to download the file, I do an ajax call and show a waiting animation until I get a response. The controller action that handles the call will generate the file (PDF) and return a FileResult. Now in the succes function of my ajax call back in javascript, I get the file data.

Problem: I have no Idea what I'm supposed to do with this data to get it to the user.

Workaround:

Right now I use a workaround where I do not return the file in the ajax call, but store it in session. In the succes function I do window.open("/controller/getPDFFromSession") which will download the file. However, I prefer not to use the session for these kind of things.

Thanks in advance.

答:
Problem: I have no Idea what I'm supposed to do with this data to get it to the user.

You shouldn't use AJAX for downloading files for this reason. You could do the following:

The user clicks on the download button

Using javascript you show some progress image informing him that he will have to wait

Using javascript you generate and inject a hidden iframe into the DOM having its src property pointing to the controller action supposed to generate the file

Once the iframe is loaded you could hide the progress image


问:
How to copy multiple (specific) selected sheets to new workbook
I have searched for hours but with no luck.
I want to copy multiple sheets from a file to a new workbook.  Not all sheets but just the ones that I have selected. My selection could be different each time I perform this exercise. The scenario is that I have a master reporting file with say 25 sheets each with a different report. I want to open the file and select reports to send to a user.  I will select say 5 specific reports e.g. sheets 1,10,15,18 and 20 I then want to copy them to a new workbook so I can email them to my customer. Ideally I would paste them into new workbook at values only to remove all formulas and links from reports being sent to customer. The following code works great for a single sheet:

```<code>ThisWorkbook.ActiveSheet.Copy _
Before:=Workbooks.Add.Worksheets(1)
</code>```

What I would like to do is to change the word 'ActiveSheet' to 'SelectedSheets' and keep all else the same.  This does not work. Am I missing something simple?

I have tried to:
a: change code as above
b: record a macro copying selected sheets and using the code (but it provides code for specific sheet names such as sheet2 and sheet3.  This will not work as I need to it be code that works with whatever sheets I select.
c: searched internet for hours. Generally provides as advice on working with all sheets, working with a pre-defined set of selected sheets, working with pre-defined selection using arrays, code to select sheets based on common characteristics e.g. select all sheets with name "R1" in it.

答:
You could use Window.SelectedSheets here:

Returns a Sheets collection that represents all the selected sheets in the specified window

 In testing, it seems like you need to loop through the SelectedSheets. A one-liner .Copy on the entire collection copied over all sheets, not just the selected one(s).

```<code>Sub Test()
    Dim wb As Workbook
    Set wb = Workbooks.Add

    Dim ws As Worksheet
    For Each ws In ThisWorkbook.Windows(1).SelectedSheets
        ws.Copy Before:=wb.Sheets(1)
    Next ws
End Sub
</code>```

EDIT: Re-tested and I couldn't reproduce the original issue of SelectedSheets.Copy copying all the sheets.

```<code>ThisWorkbook.Windows(1).SelectedSheets.Copy
Dim wb as Workbook
Set wb = ActiveWorkbook '<~ this is the new workbook with the copied sheets
</code>```

Body:
I have searched for hours but with no luck.
I want to copy multiple sheets from a file to a new workbook.  Not all sheets but just the ones that I have selected. My selection could be different each time I perform this exercise. The scenario is that I have a master reporting file with say 25 sheets each with a different report. I want to open the file and select reports to send to a user.  I will select say 5 specific reports e.g. sheets 1,10,15,18 and 20 I then want to copy them to a new workbook so I can email them to my customer. Ideally I would paste them into new workbook at values only to remove all formulas and links from reports being sent to customer. The following code works great for a single sheet:

ThisWorkbook.ActiveSheet.Copy _
Before:=Workbooks.Add.Worksheets(1)

What I would like to do is to change the word 'ActiveSheet' to 'SelectedSheets' and keep all else the same.  This does not work. Am I missing something simple?

I have tried to:
a: change code as above
b: record a macro copying selected sheets and using the code (but it provides code for specific sheet names such as sheet2 and sheet3.  This will not work as I need to it be code that works with whatever sheets I select.
c: searched internet for hours. Generally provides as advice on working with all sheets, working with a pre-defined set of selected sheets, working with pre-defined selection using arrays, code to select sheets based on common characteristics e.g. select all sheets with name "R1" in it.

Body:
You could use Window.SelectedSheets here:

Returns a Sheets collection that represents all the selected sheets in the specified window

 In testing, it seems like you need to loop through the SelectedSheets. A one-liner .Copy on the entire collection copied over all sheets, not just the selected one(s).

Sub Test()
    Dim wb As Workbook
    Set wb = Workbooks.Add

    Dim ws As Worksheet
    For Each ws In ThisWorkbook.Windows(1).SelectedSheets
        ws.Copy Before:=wb.Sheets(1)
    Next ws
End Sub

EDIT: Re-tested and I couldn't reproduce the original issue of SelectedSheets.Copy copying all the sheets.

ThisWorkbook.Windows(1).SelectedSheets.Copy
Dim wb as Workbook
Set wb = ActiveWorkbook '<~ this is the new workbook with the copied sheets


问:
C program terminates without any error after execution of scanf() and taking the input from user
Program terminates automatically after the execution of scanf() and taking input from the user.

This is a program to print perfect number in a given range

```<code>#include <stdio.h>

void main() {
    int i, n, j, sum;
    printf("enter the number \n ");
    scanf("%d", &n);
    for (i = 1; i <= n; i++) {
        sum = 0;
        for (j = 1; j <= i; j++) {
            if (n % j == 0) {
                sum += j;
            }
        }
        if (sum == n) {
            printf("%d", i);
        }
    }
}
</code>```

execution image

答:
The simple reason is that with input 100, sum never be 100 so there will be no printf execution.

If you were to print the sum at the end of the outer for loop you would see this:

```<code>enter the number
 100
sum:1
sum:3
sum:3
sum:7
sum:12
sum:12
sum:12
sum:12
sum:12
sum:22
sum:22
sum:22
sum:22
sum:22
sum:22
sum:22
sum:22
sum:22
sum:22
sum:42
sum:42
sum:42
sum:42
sum:42
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:217

</code>```

Body:
Program terminates automatically after the execution of scanf() and taking input from the user.

This is a program to print perfect number in a given range

#include <stdio.h>

void main() {
    int i, n, j, sum;
    printf("enter the number \n ");
    scanf("%d", &n);
    for (i = 1; i <= n; i++) {
        sum = 0;
        for (j = 1; j <= i; j++) {
            if (n % j == 0) {
                sum += j;
            }
        }
        if (sum == n) {
            printf("%d", i);
        }
    }
}

execution image

Body:
The simple reason is that with input 100, sum never be 100 so there will be no printf execution.

If you were to print the sum at the end of the outer for loop you would see this:

enter the number
 100
sum:1
sum:3
sum:3
sum:7
sum:12
sum:12
sum:12
sum:12
sum:12
sum:22
sum:22
sum:22
sum:22
sum:22
sum:22
sum:22
sum:22
sum:22
sum:22
sum:42
sum:42
sum:42
sum:42
sum:42
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:67
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:117
sum:217


问:
Loop for two codes and two functions in r
I have two codes to be done for all of my samples.

```<code>cr1 = MEDIPS.seqCoverage(file = "1.bam", pattern = "CG", BSgenome = BSgenome, extend = extend, shift = shift, uniq = uniq)
MEDIPS.plotSeqCoverage(seqCoverageObj=cr1, type="pie", cov.level = c(0, 5, 10, 20, 30), main="cr1")
</code>```

Then,

```<code>cr2 = MEDIPS.seqCoverage(file = "2.bam", pattern = "CG", BSgenome = BSgenome, extend = extend, shift = shift, uniq = uniq)
MEDIPS.plotSeqCoverage(seqCoverageObj=cr2, type="pie", cov.level = c(0, 5, 10, 20, 30), main="cr2")
</code>```

I don't want to repeat the code again and again for 100 times. I tried some for loops but they are not working because " File i.bam  not found in ...". Well, I am not good at it at all. Does anyone can help me out?

So my code look like this:

```<code>for(i in 1:100){
  cr[i] = MEDIPS.seqCoverage(file = paste0(as.character(i),".bam"),
                             pattern = "CG", BSgenome = BSgenome, extend = extend,
                             shift = shift, uniq = uniq)
  MEDIPS.plotSeqCoverage(seqCoverageObj=cr[i], type="pie",
                         cov.level = c(0, 5, 10, 20, 30), main="cr",paste0(as.character(i)))
}
</code>```

Reading bam alignment 1.bam

Total number of imported short reads: 17254741

Extending reads...

Creating GRange Object...

Keep at most one 1 read mapping to the same genomic location.

Number of remaining reads: 11148075

Loading chromosome lengths for BSgenome.Hsapiens.UCSC.hg19...

Get genomic sequence pattern positions...

Number of identified  CG  pattern:  26752702

Calculating sequence pattern coverage...

Error: object 'cr' not found

答:
I am not sure if this is the thing you are looking after, but you can still have a try, where the number similar actions is assumed as 100, i.e., </p>

```<code>list2env(setNames(lapply(paste0(seq(100),".bam"),
                         function(v) MEDIPS.seqCoverage(file = v, pattern = "CG", BSgenome = BSgenome, extend = extend, shift = shift, uniq = uniq)),
                  paste0("cr",seq(100))),
         envir = .GlobalEnv)

sapply(paste0("cr",seq(100)),function(v) MEDIPS.plotSeqCoverage(seqCoverageObj=get(v), type="pie", cov.level = c(0, 5, 10, 20, 30), main=v))
</code>```

Body:
I have two codes to be done for all of my samples.

cr1 = MEDIPS.seqCoverage(file = "1.bam", pattern = "CG", BSgenome = BSgenome, extend = extend, shift = shift, uniq = uniq)
MEDIPS.plotSeqCoverage(seqCoverageObj=cr1, type="pie", cov.level = c(0, 5, 10, 20, 30), main="cr1")

Then,

cr2 = MEDIPS.seqCoverage(file = "2.bam", pattern = "CG", BSgenome = BSgenome, extend = extend, shift = shift, uniq = uniq)
MEDIPS.plotSeqCoverage(seqCoverageObj=cr2, type="pie", cov.level = c(0, 5, 10, 20, 30), main="cr2")

I don't want to repeat the code again and again for 100 times. I tried some for loops but they are not working because " File i.bam  not found in ...". Well, I am not good at it at all. Does anyone can help me out?

So my code look like this:

for(i in 1:100){
  cr[i] = MEDIPS.seqCoverage(file = paste0(as.character(i),".bam"),
                             pattern = "CG", BSgenome = BSgenome, extend = extend,
                             shift = shift, uniq = uniq)
  MEDIPS.plotSeqCoverage(seqCoverageObj=cr[i], type="pie",
                         cov.level = c(0, 5, 10, 20, 30), main="cr",paste0(as.character(i)))
}

Reading bam alignment 1.bam

Total number of imported short reads: 17254741

Extending reads...

Creating GRange Object...

Keep at most one 1 read mapping to the same genomic location.

Number of remaining reads: 11148075

Loading chromosome lengths for BSgenome.Hsapiens.UCSC.hg19...

Get genomic sequence pattern positions...

Number of identified  CG  pattern:  26752702

Calculating sequence pattern coverage...

Error: object 'cr' not found

Body:
I am not sure if this is the thing you are looking after, but you can still have a try, where the number similar actions is assumed as 100, i.e.,

list2env(setNames(lapply(paste0(seq(100),".bam"),
                         function(v) MEDIPS.seqCoverage(file = v, pattern = "CG", BSgenome = BSgenome, extend = extend, shift = shift, uniq = uniq)),
                  paste0("cr",seq(100))),
         envir = .GlobalEnv)

sapply(paste0("cr",seq(100)),function(v) MEDIPS.plotSeqCoverage(seqCoverageObj=get(v), type="pie", cov.level = c(0, 5, 10, 20, 30), main=v))


问:
Group JSON array by key value
Please help to combine object keys values from json arrays by key.

    const input=[{
   "Date":"04/10/2019",
   "Time":"15:35",
   "Title":"Flight -\u00a0Group C",
   "Description":"Arrival 19:40"
},
{
   "Date":"04/10/2019",
   "Time":"Evening",
   "Title":"Welcome drinks",
   "Description":"In the bar at\u00a0"
},
{
   "Date":"05/10/2019",
   "Time":"Morning",
   "Title":"Breakfast",
   "Description":"At leisure"
},
{
   "Date":"05/10/2019",
   "Time":"10:00",
   "Title":"Something Else",
   "Description":"At leisure"
}];

console.log(
  Object.values(input.reduce((a, { Date }) => {
    if (!a[Date]) a[Date] = { Date, activities: [] };
    a[Date].activities.push();
    return a;
  }, {}))
);```
</div>
</div>
</p>

<p>I need a combined object keys values in javascript in the following way:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>[
   {
      "date":"04/10/2019",
      "activities":[
         {
            "Time":"15:35",
            "Title":"Flight -\u00a0Group C",
            "Description":"Arrival 19:40"
         },
         {
            "Time":"Evening",
            "Title":"Welcome drinks",
            "Description":"In the bar at\u00a0"
         }
      ]
   },
   {
      "date":"05/10/2019",
      "activities":[
         {
            "Time":"Morning",
            "Title":"Breakfast",
            "Description":"At leisure"
         }
      ]
   }
]</code>```

I am trying to get the result with my code but 'activities' are null...
I would highly appreciate your help.

Thank you in advance

答:
If you are using parameter destructuring you could use ... rest param to get other properties after you take out the date.

const input=[{"Date":"04/10/2019","Time":"15:35","Title":"Flight - Group C","Description":"Arrival 19:40"},{"Date":"04/10/2019","Time":"Evening","Title":"Welcome drinks","Description":"In the bar at "},{"Date":"05/10/2019","Time":"Morning","Title":"Breakfast","Description":"At leisure"},{"Date":"05/10/2019","Time":"10:00","Title":"Something Else","Description":"At leisure"}]

const object = input.reduce((r, { Date: date, ...rest}) => {
  if(!r[date]) r[date] = {date, activities: [rest]}
  else r[date].activities.push(rest)
  return r
}, {})

const result = Object.values(object)
console.log(result)```

Title: Group JSON array by key value

Body:
Please help to combine object keys values from json arrays by key.

    const input=[{
   "Date":"04/10/2019",
   "Time":"15:35",
   "Title":"Flight -\u00a0Group C",
   "Description":"Arrival 19:40"
},
{
   "Date":"04/10/2019",
   "Time":"Evening",
   "Title":"Welcome drinks",
   "Description":"In the bar at\u00a0"
},
{
   "Date":"05/10/2019",
   "Time":"Morning",
   "Title":"Breakfast",
   "Description":"At leisure"
},
{
   "Date":"05/10/2019",
   "Time":"10:00",
   "Title":"Something Else",
   "Description":"At leisure"
}];

console.log(
  Object.values(input.reduce((a, { Date }) => {
    if (!a[Date]) a[Date] = { Date, activities: [] };
    a[Date].activities.push();
    return a;
  }, {}))
);

I need a combined object keys values in javascript in the following way:

[
   {
      "date":"04/10/2019",
      "activities":[
         {
            "Time":"15:35",
            "Title":"Flight -\u00a0Group C",
            "Description":"Arrival 19:40"
         },
         {
            "Time":"Evening",
            "Title":"Welcome drinks",
            "Description":"In the bar at\u00a0"
         }
      ]
   },
   {
      "date":"05/10/2019",
      "activities":[
         {
            "Time":"Morning",
            "Title":"Breakfast",
            "Description":"At leisure"
         }
      ]
   }
]

I am trying to get the result with my code but 'activities' are null...
I would highly appreciate your help.

Thank you in advance


问:
How to initialize InMobi with MoPub? #withAdditionalNetwork
We used InMobi and switched to MoPub. InMobi is still supported with mediation by MoPub. InMobi provided a guide how to integrate this (https://support.inmobi.com/monetize/mediation-guidelines/mopub/android-mopub-guidelines). I followed the guide closely but unable to retrieve requests and impressions in InMobi. As I can see from the MoPubSDK I think I need to bind the InMobi to MoPub with #withAdditionalNetwork.</p>

答:
The most important step isn't very emphasised. It is

Step 3.2: Add the Custom Event

Add the custom events to your MoPub project. The custom events for different ad formats are also available as part of the sample code available here. The custom events are available under the relevant package structure. The code also has sample activities to illustrate how to mediate via MoPub SDK.

The content needed from the above linked archive is the following:

Copy this to your Android project. Then alter the MoPubSDK initialization process like this

```<code>SdkConfiguration sdkConfiguration = new SdkConfiguration.Builder("362da1882dfc49f3a33b92ea1708f3a5")
            .withAdditionalNetwork(InMobiAdapterConfiguration.class.getName())
            .build();

MoPub.initializeSdk(activity, sdkConfiguration, initSdkListener());
</code>```

Body:
The most important step isn't very emphasised. It is

Step 3.2: Add the Custom Event

Add the custom events to your MoPub project. The custom events for different ad formats are also available as part of the sample code available here. The custom events are available under the relevant package structure. The code also has sample activities to illustrate how to mediate via MoPub SDK.

The content needed from the above linked archive is the following:

Copy this to your Android project. Then alter the MoPubSDK initialization process like this

SdkConfiguration sdkConfiguration = new SdkConfiguration.Builder("362da1882dfc49f3a33b92ea1708f3a5")
            .withAdditionalNetwork(InMobiAdapterConfiguration.class.getName())
            .build();

MoPub.initializeSdk(activity, sdkConfiguration, initSdkListener());


问:
Golang - Discard as WriteCloser
I needed to create an equivalent of ioutil.Discard that can satisfy a "WriteCloser" interface. With a bit of Googling I came up with

```<code>package main

import (
    "io"
    "io/ioutil"
    "strings"
    "fmt"
)

type discardCloser struct {
    io.Writer
}

func (discardCloser) Close() error {
    return nil
}

func main() {
    src := strings.NewReader("Hello world")
    dst := discardCloser{Writer: ioutil.Discard}
    count, err := io.Copy(dst, src)
    fmt.Println(count, err)
    err = dst.Close()
    fmt.Println(err)
}
</code>```

Go playground link here

Is there a more idiomatic way of doing this?

Background: some standard library methods return a WriteCloser, such as net/smtp.Data. When implementing automated tests, it's nice to be able to exercise functions like this, while sending their output to Discard.

答:
I took bereal's tip and looked at NopCloser. The approach works nicely, and is useful in test functions built around the libraries that require a WriteCloser.

I renamed the type myWriteCloser as it can be used to promote "real" writers such as as &bytes.Buffer, as well as the special system discard writer.

```<code>type myWriteCloser struct {
    io.Writer
}

func (myWriteCloser) Close() error {
    return nil
}
</code>```

Title: Golang - Discard as WriteCloser

Body:
I needed to create an equivalent of ioutil.Discard that can satisfy a "WriteCloser" interface. With a bit of Googling I came up with

package main

import (
    "io"
    "io/ioutil"
    "strings"
    "fmt"
)

type discardCloser struct {
    io.Writer
}

func (discardCloser) Close() error {
    return nil
}

func main() {
    src := strings.NewReader("Hello world")
    dst := discardCloser{Writer: ioutil.Discard}
    count, err := io.Copy(dst, src)
    fmt.Println(count, err)
    err = dst.Close()
    fmt.Println(err)
}

Go playground link here

Is there a more idiomatic way of doing this?

Background: some standard library methods return a WriteCloser, such as net/smtp.Data. When implementing automated tests, it's nice to be able to exercise functions like this, while sending their output to Discard.

Body:
I took bereal's tip and looked at NopCloser. The approach works nicely, and is useful in test functions built around the libraries that require a WriteCloser.

I renamed the type myWriteCloser as it can be used to promote "real" writers such as as &bytes.Buffer, as well as the special system discard writer.

type myWriteCloser struct {
    io.Writer
}

func (myWriteCloser) Close() error {
    return nil
}


问:
Result given for and operator predicate (Prolog)
Someone is occupied and it is defined by if someone works two jobs.

Given the following descriptions

```<code>employe(tom,shopify).
employe(eva,shopify).
employe(eva,ibm).
employe(sam,cisco).
employe(sam,bridehead).
</code>```

I want to modify the following predicate to return the people who work two jobs.

```<code>occupe(X):- employe(X,C1), employe(X,C2).
</code>```

I don't understand why tom is given as a possible answer when he only works one job (i.e I don't get how the and operator , doesn't make sure that the employee works two separate jobs).

Additionally, I've tried adding ! at the beginning but it hasn't worked.

答:
The reason that this works is because C1 and C2 are not per se different. It thus unifies both C1 and C2 with shopify.

In order to determine people that work at two different jobs, you should specify that C1 and C2 should be different:

```<code>occupe(X):- employe(X,C1), employe(X,C2), <b>C1 \= C2</b>.</code>```

Body:
Someone is occupied and it is defined by if someone works two jobs.

Given the following descriptions

employe(tom,shopify).
employe(eva,shopify).
employe(eva,ibm).
employe(sam,cisco).
employe(sam,bridehead).

I want to modify the following predicate to return the people who work two jobs.

occupe(X):- employe(X,C1), employe(X,C2).

I don't understand why tom is given as a possible answer when he only works one job (i.e I don't get how the and operator , doesn't make sure that the employee works two separate jobs).

Additionally, I've tried adding ! at the beginning but it hasn't worked.

Body:
The reason that this works is because C1 and C2 are not per se different. It thus unifies both C1 and C2 with shopify.

In order to determine people that work at two different jobs, you should specify that C1 and C2 should be different:

occupe(X):- employe(X,C1), employe(X,C2), C1 \= C2.