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

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

    +137

    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
    ascdec proc near
    mov di,0
    mov si,0
    xor dx,dx
    mov bx,offset buf
    add bx,10
    mov cx,11
    lo0:
    dec bx
    dec cx
    jcxz ex0
    mov al,[bx]
    cmp al,255
    je lo0
    lo1:
    sub al,30h 
    push bx
    push cx
    mov bx,offset deci
    xor dx,dx
    mov cx,word ptr[bx+2]
    mov bx,word ptr[bx]
    mov ah,0
    call mult32 
    add di,ax
    adc si,dx
    mov bx,offset deci
    mov ax,[bx]
    mov dx,[bx+2]
    call multen
    mov bx,offset deci
    mov [bx],ax
    mov [bx+2],dx
    pop cx
    pop bx
    dec bx
    dec cx
    jcxz ex0
    mov al,[bx]
    jmp lo1
    ex0:
    mov ax,di
    mov dx,si
    test dx,8000h
    jz enda
    jmp error
    enda:
    cmp minus,2dh
    jne pl1
    call ccc
    pl1:
    ret
    ascdec endp
    multen proc near
    push bx
    push cx
    mov bx,10
    mov cx,0
    call mult32
    pop cx
    pop bx
    ret
    multen endp
    mult32 proc near 
    push si
    push di
    push dx
    push ax
    test dx,8000h 
    jz ml
    call ucc
    push dx
    push ax
    ml:
    mov dx,cx
    mov ax,bx
    test dx,8000h  
    jz ml0
    call ucc 
    mov bx,ax
    mov cx,dx
    ml0:
    pop ax
    pop dx
    mov si,0
    mov di,0
    mul bx ;AX*BX
    mov di,ax
    mov si,dx
    pop ax
    mul cx ;AX*CX
    add si,ax
    pop dx
    ucc proc near
    dec ax
    sbb dx,0
    not ax
    not dx
    ret
    ucc endp

    Превращение строки в число.

    Abbath, 27 Марта 2014

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

    +6

    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
    // функция квадрата расстояния на гексагональном поле
    Fixed SDist2 (Fixed dx, Fixed dy)
    {
    	return (dx*dx+dy*dy+dx*dy);
    }
    
    // а теперь типа находим ближайшее целое, ближайшее в гексагональном смысле
          const Fixed rx = int(rtx), ry = int(rty);
    			const Fixed 
    				d00 = SDist2(rx    -rtx, ry    -rty),
    				d10 = SDist2(rx+fx1-rtx, ry    -rty),
    				d01 = SDist2(rx    -rtx, ry+fx1-rty),
    				d11 = SDist2(rx+fx1-rtx, ry+fx1-rty);
    
    			int x,y;
    			if (d00<d10 && d00<d01 && d00<d11) 
    			{
    				x=int(rx); y=int(ry);
    			} else if (d10<d01 && d10<d11)
    			{
    				x=int(rx)+1; y=int(ry);
    			} else if (d01<d11)
    			{
    				x=int(rx); y=int(ry)+1;
    			} else
    			{
    				x=int(rx)+1; y=int(ry)+1;
    			}

    изящно не получилось

    TarasB, 18 Марта 2014

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

    +15

    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
    #include <iostream>
    #include <string>
    #include <vector>
    #include <list>
    #include <algorithm>
    #include <iterator>
    #include <sstream>
    #include <assert.h>
    using namespace std;
    template<class Container, class Iterator> 
    size_t position(Container&& c, Iterator pos){
        return size_t(distance(begin(c), pos));
    }
    template<class Container, class Iterator, class Iterator2> 
    string sposition(Container&& c, const pair<Iterator, Iterator2>& pos){
        ostringstream r;
        r << "(" << position(c, pos.first) << ", " << position(c, pos.second) << ")";
        return r.str();
    }
    template<class Container, class Value> 
    pair<typename remove_reference<Container>::type::iterator, typename remove_reference<Container>::type::iterator>
     binary_search(Container&& source, const Value& item){
        assert(is_sorted(begin(source), end(source)));
        const auto empty = make_pair(source.end(), source.end());
        auto l = begin(source), r=end(source), m=l;
        while(true){
            if(l==r)
                return empty;
            const auto lr = distance(l,r);
            m = next(l, lr/2);
            if(*m<item)
                l = m;
            if(*m>item)
                r = m;
            if(*m==item)
                break;
            if(l!=r && next(l)==r)
                return empty;
        }
        cout<<"part1"<<endl;
        auto l1=l, r1=m, l2=m, r2=r;
        while(true){
            const auto lr1 = distance(l1, r1);
            m = next(l1, lr1/2);
            if(*m<item)
                l1 = m;
            if(*m>=item)
                r1 = m;
            if(l1==r1 || (*l1<item && *r1>=item))
                break;
        }
        cout<<"part2"<<endl;
        while(true){
            const auto lr2 = distance(l2, r2);
            m = next(l2, lr2/2);
            if(*m<=item)
                l2 = m;
            if(*m>item)
                r2 = m;
            if(l2==r2 || (*l2>=item && (r==r2 || *r2>item)))
                break;
        }
        cout<<"part3"<<endl;
        return {r1, next(l2)};
    }
    int main(){
        vector<int> s{5,7,7,7,9,19,23};
        list<int> s2(s.begin()+1, s.end());
        cout<<sposition(s, binary_search(s, 7))<<endl;
        cout<<sposition(s2, binary_search(s2, 7))<<endl;
        cout<<sposition(s, binary_search(s, 9))<<endl;
        cout<<sposition(s, binary_search(s, 5))<<endl;
        cout<<sposition(s, binary_search(s, 23))<<endl;
        cout<<sposition(s, binary_search(s, 0))<<endl;
        vector<int> e;
        cout<<sposition(e, binary_search(e, 0))<<endl;
        cout<<sposition(s, binary_search(s, 25))<<endl;
        cout<<sposition(s, binary_search(s, 10))<<endl;
        return 0;
    }

    http://coliru.stacked-crooked.com/a/0f74a4661c06cd68
    Специально для @Пи, раз ему хачкель не нравится.

    LispGovno, 14 Марта 2014

    Комментарии (22)
  5. Куча / Говнокод #15472

    +122

    1. 1
    2. 2
    substractOneFromArgument = (-)1
    main = print $ substractOneFromArgument 4

    ПИШУ ФУНКЦИЮ ВЫЧИТАЮЩУЮ ЕДИНИЦУ ИЗ СВОЕГО АРГУМЕНТА
    @
    ПОЛУЧАЮ УПОРОТЫЙ РЕЗУЛЬТАТ
    http://ideone.com/I34iLA

    LispGovno, 14 Марта 2014

    Комментарии (22)
  6. bash / Говнокод #15373

    −117

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    (
       if [ ! -z "$UNIX95" ] ; then
          unset UNIX95
       fi
       ...
    )

    Продолжение темы "Java программисты пишут на шелле": в подшелле, убрать переменную, если поставлена.
    А то вдруг шелл какой NullPointerException бросит.

    Dummy00001, 06 Марта 2014

    Комментарии (22)
  7. PHP / Говнокод #14542

    +154

    1. 1
    /^(?!\s)[a-zA-Z0-9\x2d-\x2f\x7f-\xff_-\s]+(?!\s)$/

    Регулярочка из Modx. После обновления PCRE до последней версии перестала восприниматься как валидная. Недоумеваем, что имели в виду, задавая диапазон "_-\s" и как оно работало раньше.

    Lblss, 11 Февраля 2014

    Комментарии (22)
  8. Куча / Говнокод #14516

    +123

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    @echo off
    
    set PROGPATH="%ProgramFiles%\MyProg"
    
    rem И тут мы захотели проверить, существует ли наша папочка
    
    if not exists "%PROGPATH%" (
        mkdir "%PROGPATH%"
    )
    
    rem виндовый шелл как бы нам говорит "братюнь, погоди, не спеши"
    rem ""C:\Program was unexpected at this time.

    Патч:

    -set PROGPATH="%ProgramFiles%\MyProg"
    +set "PROGPATH=%ProgramFiles%\MyProg"


    http://stackoverflow.com/questions/535975/dealing-with-quotes-in-windows-batch-scripts

    Elvenfighter, 06 Февраля 2014

    Комментарии (22)
  9. PHP / Говнокод #14400

    +159

    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
    class CHTMLFormGenerator {
    
    	...
    
    	public $formName;
    	const formName = 'form';
    	
    	function GetFormName() {
    		if(isset($this) && $this -> formName)
    			return $this -> formName;
    		else
    			return self::formName;
    	}
    
    	...
    
    }

    clauclauclau, 23 Января 2014

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

    +133

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    public Normalizer(Int32 totalElementsCount)
    {
        _totalElementsCount = totalElementsCount;
        _delta = Int32.MaxValue / (2 * totalElementsCount);
        if (_delta == 0)
            throw new OverflowException("Too much normalizated records.");
    }

    Осталось от старых разработчиков. Долго не могли понять, почему кидается DivideByZeroException

    botinko, 05 Декабря 2013

    Комментарии (22)
  11. 1C / Говнокод #13951

    −167

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    Попытка
    	ДокументВозврата.Записать(РежимЗаписиДокумента.Проведение,РежимПроведенияДокумента.Неоперативный);
    Исключение
    	Попытка
    		ДокументВозврата.Записать(РежимЗаписиДокумента.Проведение,РежимПроведенияДокумента.Неоперативный);
    	Исключение
    		Сообщить("Не удалось записать/провести документ возврата в ИБ " + ДокументВозврата, СтатусСообщения.ОченьВажное);
    	КонецПопытки;
    	ДокументВозврата.Записать(РежимЗаписиДокумента.Запись);
    КонецПопытки;

    Что делать, если не получилось провести документ? Правильно! Попробовать еще раз!
    А потом еще и записать.
    Для надежности.

    zfilin, 15 Октября 2013

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