1. C# / Говнокод #19434

    +7

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    static int[] Compute(int[] array) 
    { 
    int count = array.Length; 
    int[] result = new int[count]; 
    
    for (int i = 0, j = 0, mul = 1; i < count; ++i, j = 0, mul = 1) 
    { 
    for (; j != i; ++j) 
    mul *= array[j]; 
    
    for (++j; j != count; ++j) 
    mul *= array[j]; 
    
    result[i] = mul; 
    } 
    return result; 
    }

    Ибо нефиг писать такие шарпи у for

    d_fomenok, 11 Февраля 2016

    Комментарии (28)
  2. C# / Говнокод #19430

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    class Program
        {
            static void Main(string[] args)
            {
                Cell[] cells = new Cell[15];
                cells[1] = new Cell(); //и ещё 14 подобных строк
                cells[1].AddAdjacentCell(cells[2], 1);
                cells[1].AddAdjacentCell(cells[5], 2); //и так для всех 15 ячеек
                Spore spore01 = new Spore(true, false, true, true, false, true);
                Spore spore02 = new Spore(true, true, true, true, true, true);
                for(Int16 i = 1; i <= 14; i++)
                    for (Int16 k = 1; k <= 14; k++)
                    {
                        if (i != k)
                        {
                            Console.Write("Trying " + i + " " + k + "... ");
                            cells[i].AddSpore(spore01);
                            cells[k].AddSpore(spore02);
                            bool badAttempt = false;
                            for(Int16 c = 1; c <= 14; c++)
                            {
                                if (cells[c].state == CellState.Empty)
                                {
                                    badAttempt = true;
                                    break;
                                }
                            }
                            Console.WriteLine(badAttempt.ToString());
                        }
                    }
    Console.ReadLine();
            }
        }
        class Cell
        {
            public CellState state;
            private Cell[] adjacentCells = new Cell[6];
            private Spore currentSpore = null;
            public Cell()
            {
                this.state = CellState.Empty;
                for (Int16 i = 0; i <= 5; i++)
                {
                    this.adjacentCells[i] = null;
                }
            }
            public void AddAdjacentCell(Cell cell, Int16 direction)
            {
                if (direction >= 6)
                    return;
    
                this.adjacentCells[direction] = cell;
            }
            public void Ray(Int16 direction)
            {
                if (this.adjacentCells[direction] == null)
                    return;
                if (this.adjacentCells[direction].state == CellState.Spore)
                    return;
                this.state = CellState.Light;
                this.adjacentCells[direction].Ray(direction);
            }
            public void AddSpore(Spore spore)
            {
                this.state = CellState.Spore;
                this.currentSpore = spore;
                for (Int16 i = 0; i <= 5; i++)
                {
                    if (this.currentSpore.directions[i] == true)
                        this.Ray(i);
                }
            }
            public void Reset()
            {
                this.state = CellState.Empty;
                this.currentSpore = null;
                for (Int16 i = 0; i <= 5; i++)
                {
                    this.adjacentCells[i] = null;
                }
            }
        }
        enum CellState
        {
            Empty,
            Light,
            Spore
        }
        class Spore
        {
            public bool[] directions = new bool[6];
            public Spore(params bool[] rays)
            {
                for (Int16 i = 0; i <= 5; i++)
                    this.directions[i] = rays[i];
            }
        }
    }

    (обсуждение программы для поиска решений для одной головоломки под Андроид)
    - Да щас напишем, хуль там делать то?
    (через 5 минут)
    - Ой, переполнение стека...
    - ...

    A1mighty, 11 Февраля 2016

    Комментарии (14)
  3. C# / Говнокод #19422

    +5

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    var pts = new Vector3[vCount];
    var r = new Random();
    
    for (var i = 0; i < pts.Length; i++)
    pts[i] = new Vector3(r.Next(-10000, 10000), r.Next(-600, 600), r.Next(-10000, 10000)) * 0.05f;
    /*for (var i = 0; i < pts.Length; i++)
    for (var j = 0; j < pts.Length; j++)
    if (pts[i].X > pts[j].X)
    {
    var tmp = pts[i];
    pts[i] = pts[j];
    pts[j] = tmp;
    }*/
    var vertices = new VertexPositionColor[vCount];
    var indices = new int[vCount * 6];
    //*
    for (var i = 0; i < vCount; i++)
    {
    vertices[i] = new VertexPositionColor(pts[i], new Color(new Vector3(r.Next(-100000, 100000), r.Next(-100000, 100000), r.Next(-100000, 100000)) * 0.00001f));
    indices[i * 6] = i;
    indices[i * 6 + 3] = i;
    var minDist = new float[] { 100000000, 100000000, 100000000 };
    var minId = new int[] { 0, 0, 0 };
    for (var j = 0; j < vCount; j++)
    {
    if (j == i) continue;
    var dist = Vector3.DistanceSquared(pts[i], pts[j]);
    if (dist < minDist[0])
    {
    minDist[2] = minDist[1]; minId[2] = minId[1];
    minDist[1] = minDist[0]; minId[1] = minId[0];
    minDist[0] = dist; minId[0] = j;
    }
    else if (dist < minDist[1])
    {
    minDist[2] = minDist[1]; minId[2] = minId[1];
    minDist[1] = dist; minId[1] = j;
    }
    else if (dist < minDist[2])
    {
    minDist[2] = dist;
    minId[2] = j;
    }
    }
    indices[i * 6 + 1] = minId[0];
    indices[i * 6 + 2] = minId[1];
    indices[i * 6 + 4] = minId[1];
    indices[i * 6 + 5] = minId[2];
    }//*/

    Антон, 20 лет.

    Особенно вставило

    indices[i * 6 + 1] = minId[0];
    indices[i * 6 + 2] = minId[1];
    indices[i * 6 + 4] = minId[1];
    indices[i * 6 + 5] = minId[2];

    d_fomenok, 09 Февраля 2016

    Комментарии (8)
  4. C# / Говнокод #19419

    −1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    public void SaveModels(IEnumerable<Activity> models)
     {
                if (models == null && models.Count() == 0) return;
                // step 1/3: remove empty models
                var empty = models.Where(m => !m.ForecastedValue.HasValue && !m.ActualValue.HasValue).ToList();
                if (empty != null)
                {
                    models = models.Except(empty);
                }
               .....
    }

    Зачем такая конструкция, если можно просто
    models = models.Where(m => m.ForecastedValue.HasValue && m.ActualValue.HasValue).ToList()
    К тому же проверка на null бесполезна - ни Where, ни ToList не могут вернуть null. Даже если в коллекции ничего не останется.

    sans, 08 Февраля 2016

    Комментарии (6)
  5. C# / Говнокод #19409

    +1

    1. 1
    bool isNoGoodCommentText = String.IsNullOrEmpty(this.txbxCommentCtrl.Text) || String.IsNullOrWhiteSpace(this.txbxCommentCtrl.Text);

    И действительно, is not good

    pipjaka, 05 Февраля 2016

    Комментарии (4)
  6. C# / Говнокод #19388

    −2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    float PriceByProductID(string product_id)
    	{
    		if(product_id == RUBY_PILE)
    			return 1.99f;
    		else if (product_id == RUBY_BAG)
    			return 4.99f;
    		else if (product_id == RUBY_SACK)
    			return 9.99f;
    		else if (product_id == RUBY_BOX)
    			return 19.99f;
    		else if (product_id == RUBY_CHEST)
    			return 39.99f;
    		else if (product_id == RUBY_TRUNK)
    			return 99.99f;
    		else if (product_id == GOLD_PILE)
    			return 0.99f;
    		else if (product_id == GOLD_BAG)
    			return 2.99f;
    		else if (product_id == GOLD_SACK)
    			return 7.99f;
    		else if (product_id == GOLD_BOX)
    			return 14.99f;
    		else if (product_id == GOLD_CHEST)
    			return 29.99f;
    		else if (product_id == GOLD_TRUNK)
    			return 79.99f;
    		return 0f;
    	}

    kschingiz, 03 Февраля 2016

    Комментарии (28)
  7. C# / Говнокод #19373

    −1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    mId = core.Material.Materials.FirstOrDefault(x => x.Value.article == m.article && x.Value.title == m.title && x.Value.category_id == m.category_id).Key;
    if (mId == 0)
    	mId = core.Material.Materials.FirstOrDefault(x => x.Value.article == m.article && x.Value.title == m.title).Key;
    if (mId == 0)
    	mId = core.Material.Materials.FirstOrDefault(x => x.Value.article == m.article && x.Value.category_id == m.category_id).Key;
    if (mId == 0)
    	mId = core.Material.Materials.FirstOrDefault(x => x.Value.title == m.title && x.Value.category_id == m.category_id).Key;
    if (mId == 0)
    	mId = core.Material.Materials.FirstOrDefault(x => x.Value.article == m.article).Key;
    if (mId == 0)
    	mId = core.Material.Materials.FirstOrDefault(x => x.Value.title == m.title).Key;

    Есть 3 поля.
    Поиск сначала по 3. Затем по 2, затем по 2 и еще по 2. И от безысходности по 1
    Реально ли это оптимизировать?

    yakov_255, 29 Января 2016

    Комментарии (13)
  8. C# / Говнокод #19371

    −1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    Func<int,int> fact = (int i_in) => i_in;
    
    fact = (int i_in) =>
    {
    	if (i_in>1) return (fact(i_in-1)*i_in);
    	else return (1);
    };

    tucvbif, 29 Января 2016

    Комментарии (10)
  9. C# / Говнокод #19364

    +2

    1. 1
    2. 2
    3. 3
    4. 4
    public ActionResult Exception()
    {
      throw new Exception("You better not to execute this!");
    }

    нашел говнокод, оставленный прошлым архитектором)

    govnokoder1488, 28 Января 2016

    Комментарии (3)
  10. C# / Говнокод #19363

    0

    1. 1
    <cms:CMSWebPartZone ZoneID="AnalZone" runat="server" />

    ASP.NET, аналитика

    taburetka, 28 Января 2016

    Комментарии (0)