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

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

    +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
    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
    99. 99
    lea esi, cpu_name
        mov eax, 0
        mov mreg, eax
    
        ;[04/12] G
        mov eax, 0ffh
        and eax, ebx
        mov mreg, eax
        mov al, byte ptr [mreg]
        mov [esi], al
        inc esi
    
        ;[03/12] e
        mov eax, 0ff00h
        and eax, ebx
        mov mreg, eax
        mov al, byte ptr [mreg + 1]
        mov [esi], al
        inc esi
    
        ;[02/12] n
        mov eax, 0ff0000h
        and eax, ebx
        mov mreg, eax
        mov al, byte ptr [mreg + 2]
        mov [esi], al
        inc esi
    
        ;[01/12] u
        mov eax, 0ff000000h
        and eax, ebx
        mov mreg, eax
        mov al, byte ptr [mreg + 3]
        mov [esi], al
        inc esi
    
        ;[08/12] i
        mov eax, 0ffh
        and eax, edx
        mov mreg, eax
        mov al, byte ptr [mreg]
        mov [esi], al
        inc esi
    
        ;[07/12] n
        mov eax, 0ff00h
        and eax, edx
        mov mreg, eax
        mov al, byte ptr [mreg + 1]
        mov [esi], al
        inc esi
    
        ;[06/12] e
        mov eax, 0ff0000h
        and eax, edx
        mov mreg, eax
        mov al, byte ptr [mreg + 2]
        mov [esi], al
        inc esi
    
        ;[05/12] I
        mov eax, 0ff000000h
        and eax, edx
        mov mreg, eax
        mov al, byte ptr [mreg + 3]
        mov [esi], al
        inc esi
    
        ;[12/12] n
        mov eax, 0ffh
        and eax, ecx
        mov mreg, eax
        mov al, byte ptr [mreg]
        mov [esi], al
        inc esi
    
        ;[11/12] t
        mov eax, 0ff00h
        and eax, ecx
        mov mreg, eax
        mov al, byte ptr [mreg + 1]
        mov [esi], al
        inc esi
    
        ;[10/12] e
        mov eax, 0ff0000h
        and eax, ecx
        mov mreg, eax
        mov al, byte ptr [mreg + 2]
        mov [esi], al
        inc esi
    
        ;[09/12] l
        mov eax, 0ff000000h
        and eax, ecx
        mov mreg, eax
        mov al, byte ptr [mreg + 3]
        mov [esi], al
        inc esi

    oaoaoammm, 01 Сентября 2020

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

    −53

    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
    Законы де Моргана в 1С
    Казалось бы, при чем Булева Алгебра к 1С?
    
    
    
    Предположим, есть задача - отобрать действующие договора на некую дату проверки &Дата.
    
    При этом у договора есть дата начала и дата окончания, если дата окончания не задана, то договор действует до конца времен.
    
    Как решается задача? В лоб так:
    
    
    ВЫБРАТЬ Ссылка ИЗ Справочник.Договоры ГДЕ ДатаНачала <= &Дата И (ДатаОкончания >= &Дата ИЛИ ДатаОкончания = ДатаВремя(1,1,1))
    
    Но операция ИЛИ вызывает некоторые проблемы по скорости, поэтому есть желание обойтись без нее. Как это сделать? Тут приходит на помощь законы Де Моргана.
    
    Перепишем так:
    
    
    ВЫБРАТЬ Ссылка ИЗ Справочник.Договоры ГДЕ ДатаНачала <= &Дата И НЕ (ДатаОкончания < &Дата И ДатаОкончания <> ДатаВремя(1,1,1))
    
    И всё работает.
    
    Проверяем выделенную зеленым часть условия:
    
    1. Если дата окончания договора меньше даты проверки, то получим НЕ (ИСТИНА И ИСТИНА) = ЛОЖЬ
    
    2. Если дата окончания договора больше или равно даты проверки, то получим НЕ (ЛОЖЬ И ИСТИНА) = ИСТИНА
    
    3. Если дата окончания договора не заполнена, то получим НЕ (ЛОЖЬ) = истина.
    
    Торжество формальной логики! Причем некоторые товарщи пытаются оптимизировать этот запрос через запросы с объединением, а ларчик открывается просто!

    Немножко обо мне:
    Действующий пикапер. Честно соблазнил 174 женщин и купил 42 феи (на август 2015)
    Использует функциональную 5 бальную шкалу оценок женщин.
    Известный 1сник с кличкой Гений 1С. Получает от 120 тыщ.
    Изобрел фонд «Секс за ваши» - занимаюсь сексом с проститутками за счет пожертвований фанатов.
    Изобрел Религию Дембеля.

    Genius1C, 20 Июня 2016

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

    +12

    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
    #include <string>
    #include <sstream>
    #include <iostream>
    
    int main() {
        std::string str;
        std::stringstream s("");
        std::getline(s, str, '|');
        std::cout << "good=" << s.good() <<
            " bad=" << s.bad() <<
            " fail=" << s.fail() <<
            " eof=" << s.eof() << std::endl;
        return 0;
    }

    good=0 bad=0 fail=1 eof=1

    http://ideone.com/0Ceg8z

    У меня один вопрос: нахуй так жить?

    bormand, 30 Сентября 2013

    Комментарии (245)
  5. Python / Говнокод #27361

    +1

    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
    import cowsay
    cowsay.cow('Hello World')
    
    
      ___________
    < Hello World >
      ===========
                    \
                     \
                       ^__^
                       (oo)\_______
                       (__)\       )\/\
                           ||----w |
                           ||     ||

    3_dar, 15 Апреля 2021

    Комментарии (244)
  6. JavaScript / Говнокод #27177

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    let array = [-2, 4, -10, 8];
    let count = 0;
    for (let i = 0; i < array.length; i++) {
      if (!String(array[i]).startsWith("-")) {
         count += array[i]
      }
    }
    console.log(count) // 12

    Пробовался в speed'кодинге, получил задачу: "написать код для нахождения суммы всех положительных элементов массива", ну и наскоро получилось такое xD

    Alexandre, 25 Декабря 2020

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

    +4

    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
    // https://govnokod.ru/26890#comment571155
    // bormand 2 часа назад #
    // Можно брейнфак запилить на операторах. Как раз вроде унарных хватает.
    // & * - ~ ! -- + ++ --
    
    #include <array>
    #include <vector>
    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <limits>
    
    struct Brainfuck {
    public:
        using IPType = uint16_t;
        constexpr static size_t MAX_MEMORY = std::numeric_limits<IPType>::max();
    
        std::array<uint8_t, MAX_MEMORY> memory{};
        std::vector<char> app{};
        IPType ip = 0;
        IPType cell = 0;
    
        IPType find_matching_tag(IPType cur_ip, char open, char close, int ip_direction)
        {
            size_t stack_size = 0;
            do  {
                if (app[cur_ip] == close) {
                    --stack_size;
                }
                if (app[cur_ip] == open) {
                    ++stack_size;
                }
                cur_ip += ip_direction;
            } while (stack_size > 0);
            return cur_ip - ip_direction;
        }
    
        IPType find_matching_close_tag(IPType cur_ip)
        {
            return find_matching_tag(cur_ip, '[', ']', 1);
        }
    
        IPType find_matching_open_tag(IPType cur_ip)
        {
            return find_matching_tag(cur_ip, ']', '[', -1);
        }
    
        void loop_open()
        {
            if (memory[cell] == 0) {
                ip = find_matching_close_tag(ip);
            } else {
                ++ip;
            }
        }
    
        void loop_close()
        {
            if (memory[cell] != 0) {
                ip = find_matching_open_tag(ip);
            } else {
                ++ip;
            }
        }
    
        void exec(char op)
        {
            switch (op) {
                case '>': ++cell; break;
                case '<': --cell; break;
                case '+': ++memory[cell]; break;
                case '-': --memory[cell]; break;
                case '.': std::putchar(memory[cell]); break;
                case ',': memory[cell] = static_cast<uint8_t>(std::getchar()); break;
                case '[': loop_open(); return;   // no ip advancing
                case ']': loop_close(); return;  // no ip advancing
            }
            ip++;
        }
    
        void run()
        {
            while (ip < app.size()) {
                exec(app[ip]);
            }
        }
    
    public:
        Brainfuck & operator++() { app.push_back('>'); return *this; }
        Brainfuck & operator--() { app.push_back('<'); return *this; }
        Brainfuck & operator+() { app.push_back('+'); return *this; }
        Brainfuck & operator-() { app.push_back('-'); return *this; }
        Brainfuck & operator*() { app.push_back('.'); return *this; }
        Brainfuck & operator&() { app.push_back(','); return *this; }
        Brainfuck & operator!() { app.push_back('['); return *this; }
        Brainfuck & operator~() { app.push_back(']'); return *this; }
        Brainfuck & operator>>(const Brainfuck &) { run(); return *this; }
    };

    https://wandbox.org/permlink/XJUKGyb4YbnBVwOI

    Бонус («99 bottles of beer»): https://pastebin.com/s4sBK9nX (взято с https://github.com/fabianishere/brainfuck/blob/master/examples/bottles-1.bf).

    gost, 03 Сентября 2020

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

    +1

    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
    #include <iostream>
    #include <map>
    
    std::map<std::string, int> get_map()
    {
        return {
            { "hello", 1 },
            { "world", 2 },
            { "it's",  3 },
            { "me",    4 },
        };
    }
    
    int main()
    {
        for (auto&& [ k, v ] : get_map())
            std::cout << "k=" << k << " v=" << v << '\n';
    
        return 0;
    }

    govnokod3r, 15 Февраля 2020

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

    −3

    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
    // https://github.com/Qqwy/raii_with/blob/74e4c66a821fba6a483d62a8c583b3fab06e3443/raii/raii.h#L60
    
    /**
     * Custom Control Structure Macro to provide Resource Acquisition Is Initialization (and Resource Relinquishment is Destruction).
     *
     * Use this to run a block of code with `var_decl` initialized to `init`, where at the end of the block (or at an earlier `safe_return`),
     * the passed `destr`-function will automatically be called with the given resource.
     *
     * Gotcha's:
     * 1. Do not use `return` from within `raii_with`, but only `safe_return`, because otherwise the destructors will not be run.
     * 2. Do not perform pointer-swaps with `var_decl`; the destructor will still be run on the original structure, because `raii` keeps its own reference to the resource.
     */
    #define raii_with(var_decl, init, destr)                                \
      while(1) /* i.c.m. break on l.4, so we can jump past the user-supplied block */ \
        if(0)                                                               \
        raii_glue(__raii_with_finished, __LINE__):                              \
          break;                                                            \
        else                                                                \
          /* initialize _tmp lifetime list elem so replacement `raii_lifetime_list` can have previous one as tail. */ \
          for(struct raii_lifetime_list_t _tmp = {.elem.resource = init, .elem.destructor = destr, .next = raii_lifetime_list};;) \
            /* initialize user-supplied variable name */                    \
            for(var_decl = _tmp.elem.resource;;)                            \
              if (1) {                                                      \
                /* Fill `_tmp`'s tail before `raii_lifetime_list` is shadowed */ \
                _tmp.next = raii_lifetime_list;                             \
                goto raii_glue(__raii_with_setup, __LINE__);                    \
              } else                                                        \
              raii_glue(__raii_with_setup, __LINE__):                           \
                /* Shadow `raii_lifetime_list` with inner version */        \
                for(struct raii_lifetime_list_t *raii_lifetime_list = &_tmp;;) \
                  if(1){                                                    \
                    goto raii_glue(__raii_with_body, __LINE__);                 \
                  } else                                                    \
                    while (1) /* so break works as expected */              \
                      while (1) /*so continue works as expected */          \
                        if (1){                                             \
                          /*after the else-block (or break or continue), destruct and finish */ \
                          destruct_raii_lifetime(raii_lifetime_list->elem); \
                          goto raii_glue(__raii_with_finished, __LINE__);       \
                        } else                                              \
                        raii_glue(__raii_with_body, __LINE__):
    
    
    #endif // RAII_WITH_H

    raii

    A simple library to provide RAII in standard-compliant C99, using raii_with(resource, initializer, destructor) { ... }-syntax:

    j123123, 19 Июля 2018

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

    −1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    parallel_for(1, 6, [](int value) {
          wstringstream ss;
          ss << value << L' ';
          wcout << ss.str();
       });

    Вместо того чтобы заняться допиливанием С++11 для студии, макрософт решила написать своё параллельное апи и глупые примерчики к нему на тему вывести случайную перестановку элементов.

    LispGovno, 22 Августа 2013

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

    0

    1. 1
    Бесконечный оффтоп имени Гологуба #7

    #1: https://govnokod.ru/28992 https://govnokod.xyz/_28992
    #2: https://govnokod.ru/29053 https://govnokod.xyz/_29053
    #3: https://govnokod.ru/29075 https://govnokod.xyz/_29075
    #4: https://govnokod.ru/29110 https://govnokod.xyz/_29110
    #5: https://govnokod.ru/29127 https://govnokod.xyz/_29127
    #6: https://govnokod.ru/29140 https://govnokod.xyz/_29140

    nepeKamHblu_nemyx, 12 Августа 2025

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