1. Лучший говнокод

    В номинации:
    За время:
  2. C++ / Говнокод #17569

    +131

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    std::string new_artifact()
    {
        if (one_in(2)) { // Generate a "tool" artifact
    
            it_artifact_tool *art = new it_artifact_tool();
            int form = rng(ARTTOOLFORM_NULL + 1, NUM_ARTTOOLFORMS - 1);
    
            artifact_tool_form_datum *info = &(artifact_tool_form_data[form]);
            art->create_name(info->name);
            art->color = info->color;
            art->sym = info->sym;
            art->materials.push_back(info->material);
            art->volume = rng(info->volume_min, info->volume_max);
            art->weight = rng(info->weight_min, info->weight_max);
            // Set up the basic weapon type
            artifact_weapon_datum *weapon = &(artifact_weapon_data[info->base_weapon]);
            art->melee_dam = rng(weapon->bash_min, weapon->bash_max);
            art->melee_cut = rng(weapon->cut_min, weapon->cut_max);
            art->m_to_hit = rng(weapon->to_hit_min, weapon->to_hit_max);
            if( weapon->tag != "" ) {
                art->item_tags.insert(weapon->tag);
            }
            // Add an extra weapon perhaps?
            if (one_in(2)) {
                int select = rng(0, 2);
                if (info->extra_weapons[select] != ARTWEAP_NULL) {
                    weapon = &(artifact_weapon_data[ info->extra_weapons[select] ]);
                    art->volume += weapon->volume;
                    art->weight += weapon->weight;
                    art->melee_dam += rng(weapon->bash_min, weapon->bash_max);
                    art->melee_cut += rng(weapon->cut_min, weapon->cut_max);
                    art->m_to_hit += rng(weapon->to_hit_min, weapon->to_hit_max);
                    if( weapon->tag != "" ) {
                        art->item_tags.insert(weapon->tag);
                    }
                    std::stringstream newname;
                    newname << weapon->adjective << " " << info->name;
                    art->create_name(newname.str());
                }
            }
            // CHOP is a sword, STAB is a dagger
            if( art->item_tags.count( "CHOP" ) > 0 ) {
                art->item_tags.insert( "SHEATH_SWORD" );
            }
            if( art->item_tags.count( "STAB" ) > 0 ) {
                art->item_tags.insert( "SHEATH_KNIFE" );
            }
            art->description = string_format(
                                   _("This is the %s.\nIt is the only one of its kind.\nIt may have unknown powers; try activating them."),
                                   art->nname(1).c_str());
    
            // Finally, pick some powers
            art_effect_passive passive_tmp = AEP_NULL;
            art_effect_active active_tmp = AEA_NULL;
            int num_good = 0, num_bad = 0, value = 0;
            std::vector<art_effect_passive> good_effects = fill_good_passive();
            std::vector<art_effect_passive> bad_effects = fill_bad_passive();
    
            // Wielded effects first
            while (!good_effects.empty() && !bad_effects.empty() &&
                   num_good < 3 && num_bad < 3 &&
                   (num_good < 1 || num_bad < 1 || one_in(num_good + 1) ||
                    one_in(num_bad + 1) || value > 1)) {
                if (value < 1 && one_in(2)) { // Good
                    int index = rng(0, good_effects.size() - 1);
                    passive_tmp = good_effects[index];
                    good_effects.erase(good_effects.begin() + index);
                    num_good++;
                } else if (!bad_effects.empty()) { // Bad effect
                    int index = rng(0, bad_effects.size() - 1);
                    passive_tmp = bad_effects[index];
                    bad_effects.erase(bad_effects.begin() + index);
                    num_bad++;
                }
                value += passive_effect_cost[passive_tmp];
                art->effects_wielded.push_back(passive_tmp);
            }
            // Next, carried effects; more likely to be just bad
            num_good = 0;
            num_bad = 0;
            value = 0;
            good_effects = fill_good_passive();
            bad_effects = fill_bad_passive();
            while (one_in(2) && !good_effects.empty() && !bad_effects.empty() &&
                   num_good < 3 && num_bad < 3 &&
                   ((num_good > 2 && one_in(num_good + 1)) || num_bad < 1 ||
                    one_in(num_bad + 1) || value > 1)) {
                if (value < 1 && one_in(3)) { // Good
                    int index = rng(0, good_effects.size() - 1);
                    passive_tmp = good_effects[index];
                    good_effects.erase(good_effects.begin() + index);
                    num_good++;
                } else { // Bad effect
                    int index = rng(0, bad_effects.size() - 1);
                    passive_tmp = bad_effects[index];
                    bad_effects.erase(bad_effects.begin() + index);
                    num_bad++;
                }
                value += passive_effect_cost[passive_tmp];
                art->effects_carried.push_back(passive_tmp);

    jangolare, 03 Февраля 2015

    Комментарии (6)
  3. Куча / Говнокод #17542

    +131

    1. 1
    2. 2
    3. 3
    <style>
    .newObjectHref #getNewObject_btn{font-size:18px}
    </style>

    clgs, 29 Января 2015

    Комментарии (1)
  4. Куча / Говнокод #17300

    +131

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    next_int() ->
      receive {next_int, N} -> 
        self() ! {next_int, N + 1}, 
        N
      after 0 ->
        self() ! {next_int, 0}, 
        0
      end.
    
    ...
    [{A, next_int()}|| A <- SomeList]

    Простейший способ пронумеровать элементы списка эрланге. Найдено в продакшне, ошибки сохранены.

    lesmugfrog, 12 Декабря 2014

    Комментарии (17)
  5. Си / Говнокод #17250

    +131

    1. 1
    2. 2
    // bg_pmove.c -- both games player movement code
    // takes a playerstate and a usercmd as input and returns a modifed playerstate

    Дальше идут 11 тысяч строк нечитаемого говна. Это вообще нормально?!

    gost, 03 Декабря 2014

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

    +131

    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
    double[] numbers1 = { 2.0, 2.1, 2.2, 2.3, 2.4, 2.5 };
                double[] numbers2 = { 2.2 };
    
                IEnumerable<double> onlyInFirstSet = numbers1.Except(numbers2);
    
                foreach (double number in onlyInFirstSet)
                    Console.WriteLine(number);
    
                /*
                 This code produces the following output:
    
                 2
                 2.1
                 2.3
                 2.4
                 2.5
                */

    Привет с msdn
    http://msdn.microsoft.com/en-us/library/bb300779%28v=vs.110%29.aspx

    LispGovno, 27 Ноября 2014

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

    +131

    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
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Text;
    namespace CA1
    {
        class Program
        {
            static void Main()
            {
                int buffer;
                int Cout = 0;
                string line;
                System.IO.StreamReader file = new System.IO.StreamReader("file.txt");
                while ((line = file.ReadLine()) != null)
                {
                    buffer = Convert.ToInt32(line);
                    if(buffer > 0)
                    {
                        if(buffer / 2 > 5 && buffer / 2 < 49.5)
                        {
                            Cout++;
                        }
                    }
    
                    if (buffer < 0)
                    {
                        if (buffer / 2 < - 5 && buffer / 2 > - 49.5)
                        {
                            Cout++;
                        }
                    }
                }
                Console.WriteLine(Cout);
                Console.ReadLine();
            }
        }
    }

    Вычисление количества цифр в числе

    LightningAtom, 20 Ноября 2014

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

    +131

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    Dictionary<string, string> Users = new Dictionary<string, string>();
    //somecode
    foreach (string key in Users.Keys)
    {
          string str = Users[key];
          m_LookUpProjectSupervisorFilter.Text = str;
          m_LookUpProjectSupervisorFilter.Value = key;
          break;
    }

    Такое часто в рабочем проекте.

    r1nk, 26 Октября 2014

    Комментарии (8)
  9. Си / Говнокод #16887

    +131

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    struct tm * localtime (const time_t * timer);
    
    A pointer to a tm structure with its members filled with the values
     that correspond to the local time representation of timer.
    
     The returned value points to an internal object whose validity or
     value may be altered by any subsequent call to gmtime or localtime.

    Я нуб, впервые вижу такой способ вернуть структуру.

    TarasB, 18 Октября 2014

    Комментарии (24)
  10. Си / Говнокод #16692

    +131

    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
    /*
     * Copyright (C) 2007-2012 Allwinner Technology Co., Ltd.
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License as
     * published by the Free Software Foundation; either version 2 of
     * the License, or (at your option) any later version.
     *
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
     * GNU General Public License for more details.
     *
     * You should have received a copy of the GNU General Public License
     * along with this program; if not, write to the Free Software
     * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
     * MA 02111-1307 USA
     */
    
    #ifndef __DISP_DISPLAY_I_H__
    #define __DISP_DISPLAY_I_H__
    
    #include "ebios_de.h"
    #include "ebios_lcdc_tve.h"
    #include "drv_disp_i.h" /* For DISP_XXXXXX status codes */
    
    #define DE_INF __inf
    #define DE_WRN __wrn
    
    #define OSAL_IRQ_RETURN IRQ_HANDLED
    
    #define HANDTOID(handle)  ((handle) - 100)
    #define IDTOHAND(ID)  ((ID) + 100)
    
    #define INTC_IRQNO_SCALER0  SW_INT_IRQNO_DEFEBE0
    #define INTC_IRQNO_SCALER1  SW_INT_IRQNO_DEFEBE1
    #define INTC_IRQNO_LCDC0    SW_INT_IRQNO_LCDCTRL0
    #define INTC_IRQNO_LCDC1    SW_INT_IRQNO_LCDCTRL1
    
    #define MAX_SPRITE_BLOCKS   32
    
    /*basic data information definition*/
    enum {
    	FALSE = 0,
    	TRUE
    };
    
    #define DIS_NULL 0
    
    #define BIT0    0x00000001
    #define BIT1	0x00000002
    #define BIT2	0x00000004
    #define BIT3	0x00000008
    #define BIT4	0x00000010
    #define BIT5	0x00000020
    #define BIT6	0x00000040
    #define BIT7	0x00000080
    #define BIT8	0x00000100
    #define BIT9	0x00000200
    #define BIT10	0x00000400
    #define BIT11	0x00000800
    #define BIT12	0x00001000
    #define BIT13	0x00002000
    #define BIT14	0x00004000
    #define BIT15	0x00008000
    #define BIT16	0x00010000
    #define BIT17	0x00020000
    #define BIT18	0x00040000
    #define BIT19	0x00080000
    #define BIT20	0x00100000
    #define BIT21	0x00200000
    #define BIT22	0x00400000
    #define BIT23	0x00800000
    #define BIT24	0x01000000
    #define BIT25	0x02000000
    #define BIT26	0x04000000
    #define BIT27	0x08000000
    #define BIT28	0x10000000
    #define BIT29	0x20000000
    #define BIT30	0x40000000
    #define BIT31	0x80000000
    
    
    #endif

    Нашёл в драйвере дисплея. Вместо 1<<N.

    mittorn, 13 Сентября 2014

    Комментарии (24)
  11. Куча / Говнокод #16581

    +131

    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
    module Main:
    	program factorial:
    		algorithm factorial:
    			description of the algorithm:
    				factorial of n is the algorithm that calculates the product of all the positive integers less than or equal to n.
    			end of description of the algorithm.
    			example of usage of the algorithm:
    				var1 is equal to call algorithm with parameter n which is equal to 5;
    					begin of a comment:
    						var1 is now1 120 = 5*4*3*2*1.
    						end of a comment.
    			end of example of usage of the algorithm.
    			description of author of the algorithm:
    				name: John.
    				surname: Smith.
    				date of writing of the algorithm: 2009.
    			end of description of author of the algorithm.
    			properties of the algorithm:
    				callable from other modules.
    				callable from this module.
    				can be used in expressions.
    			end of properties of the algorithm.
    			parameters of the algorithm:
    				data n: type is positive integer.
    			end of parameters of the algorithm.
    			variables of the algorithm:
    				data res: type is positive integer.
    				data now1: type is positive integer.
    			end of variables of the algorithm.
    			initialization of the variables of the algorithm:
    				res is equal to 1.
    				now1 is equal to n.
    			end of initialization of the variables of the algorithm.
    			begin of the algorithm:
    				cycle: while now1 is not 1, repeat:
    					res is equal to multiply res by now1.
    					now1 is equal to subtract 1 from now1.
    				end of cycle.
    				result of the algorithm is res
    		end of the algorithm.
    
    		algorithm main:
    			description of the algorithm:
    				main algorithm that shows the factorial of the inputted number.
    			end of description of the algorithm.
    			example of usage of the algorithm:
    			end of example of usage of the algorithm.
    			description of author of the algorithm:
    				name: John.
    				surname: Smith.
    				date of writing of the algorithm: 2009.
    			end of description of author of the algorithm.
    			properties of the algorithm:
    				callable from the system.
    			end of properties of the algorithm.
    			parameters of the algorithm:
    				data arguments: type is array of strings.
    			end of parameters of the algorithm.
    			variables of the algorithm:
    			end of variables of the algorithm.
    			initialization of the variables of the algorithm:
    			end of initialization of the variables of the algorithm.
    			begin of the algorithm:
    				call algorithm writeInteger with parameter str which is equal to
    					call algorithm factorial with parameter n which is equal to
    						call algorithm readInteger without parameters.
    				result of the algorithm is 0.
    		end of the algorithm.

    Небольшой ответ набирающему популярность WCT. Новый язык программирования LOOOONG:
    - Отступы обязательны.
    - Все блоки в функциях ("алгоритмах") обязательны.
    - блоки нужно записывать именно в таком порядке.
    - Имена параметров необходимо помнить, когда вызываешь "алгоритм".
    - Ключевых слов ОЧЕНЬ МНОГО.

    miscff, 22 Августа 2014

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