1. Си / Говнокод #15628

    +136

    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
    #include <stdio.h>
    #include <inttypes.h>
    
    inline uint8_t mid_ch (uint8_t a, uint8_t b, uint8_t res)
    {
      if (b == 0){ if (a >= 2) return mid_ch (a-2, b  , res+1); else return res;}
      if (a == 0){ if (b >= 2) return mid_ch (a  , b-2, res+1); else return res;}
      return mid_ch (a-1, b-1, res+1);
    }
    
    uint64_t mid_0_ch (uint64_t a, uint64_t b)
    {
      return mid_ch(a, b, 0);
    }
    
    
    int main(void)
    {
      printf("%u %u", mid_0_ch (253, 123), (253+123)/2);
      return 0;
    }

    Нахождение среднего арифметического двух чисел через рекурсию. Сначала сделал для uint64_t чтобы это имело смысл, ведь сложение двух 64-битных чисел с записью результата в третье может привести к целочисленному переполнению (для 64-битных чисел, сложение которых может привести к переполнению, этот код работал чрезвычайно медленно, поэтому я ограничился 8-битными). При таком наркоманско-рекурсивном алгоритме этого переполнения не будет. 128-битные типы есть только как нестандартное расширение, но тогда еще возникает вопрос, как найди среднее арифметическое двух таких 128-битных чисел? А если есть 256-битные, то как тогда их них находить среднеарифметическое... ну и так далее.
    Можно эту проблему еще решать через битовые маски т.е. убрать из обеих чисел самые старшие биты (предварительно сохранив их), сложить эти два числа, поделить на два, потом уже эти сохраненные биты вида 10000... или 0000... оба поделить на 2(сдвинуть на один разряд) и прибавить. Наркоманство какое-то.
    Почему бы не сделать в С некий особый целочисленный тип, в котором любая фигня влезет, но который бы использовался только временно для промежуточных вычислений, чтобы не делать бэкапы битиков всяких?

    j123123, 31 Марта 2014

    Комментарии (22)
  2. Pascal / Говнокод #15627

    +81

    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
    program matr;
    uses
       crt;
    var
        mas:array [1..100] of integer;
        i,n,imin,imax,min,max,razn:integer;
    begin
    clrscr;
    imax:=1;
    imin:=1;
    randomize;
    write('Введите количество элементов: ');
    readln(n);
    for i:=1 to n do
     begin
      mas[i]:=random(10)-5;
      write(mas[i]:4);
      if mas[i]>mas[imax] then
      begin
      imax:=i;
      end
      else
      if (mas[i]<mas[imin]) then
      begin
      imin:=i;
      end;
      end;
    writeln;
    writeln('MAX[',imax,']:=',mas[imax]);
    writeln('MIN[',imin,']:=',mas[imin]);
    razn:=mas[imax]+mas[imin];
    writeln('Сумма MAX и MIN:=',razn);
     end.

    Написано by "ТАМБОВСКИЙ ВОЛК. Профессионал".
    Знатное говнецо нынче пишут "профессионалы".
    http://www.programmersforum.ru/showthread.php?t=98747

    gost, 31 Марта 2014

    Комментарии (37)
  3. Pascal / Говнокод #15626

    +78

    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
    DynArray = [1..2] of real;
    var
    A : ^DinArray;
    n, i : word;
    BEGIN
    write('Укажите размер массива:');
    readln(n);
    GetMem(A,n*6);
    . . .
    {$R-}
    for i:=1 to n do
    A[i]:=random;
    . . . {любые действия с элементами масссива}
    {$R+}
    FreeMem(A,n*6)
    END.

    Просто феерический говнокод на "Pascal".
    http://logi.cc/dinamicheskaya-pamyat-primer-23/

    gost, 31 Марта 2014

    Комментарии (3)
  4. Pascal / Говнокод #15625

    +88

    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
    var 
      s: string := '1 2 4 8 16 32 64 128 256 512';
      sum: integer;
      num,p: integer;
      numstr: string;
    begin
      sum := 0;
      while s.Length>0 do
      begin
        while s[1]=' ' do // Удаление лидирующих пробелов
          Delete(s,1,1);
        p := Pos(' ',s); // Поиск следующего пробела
        if p=0 then      // Если он не найден, то до конца строки находится последнее число
          p := s.Length;
        numstr := Copy(s,1,p);
        Delete(s,1,p);
        num := StrToInt(numstr);
        sum += num;
      end;
      writeln('Сумма чисел строки равна ',sum);
    end.

    "Pascal" не умеет в split?
    http://pascalabc.net/wiki/index.php/Строки_и_символы._Тексты_программ

    gost, 31 Марта 2014

    Комментарии (34)
  5. Java / Говнокод #15624

    +69

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    public void startApp() {
            StringItem si = new StringItem("Some label","Some text");
            try{
                Image img = Image.createImage("/res/path/to/image.gif");
                FORM.append(img);
            }catch (java.io.IOException ioe){
                ioe.printStackTrace();
            }
            FORM.append(si);
            DISPLAY.setCurrent(FORM);
        }

    Wtf?
    http://www.gfs-team.ru/articles/read/107

    gost, 31 Марта 2014

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

    +157

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    if (settings.bgType === 'pattern')
    {
        if (settings.bgPattern.pack === 'bg-dark') return App.Area.color.light;
        else return App.Area.color.dark;
    }
    else
    {
        return App.Area.color.invert;
        console.log('invert');
    }

    смотрю, что в консоли пусто, и думаю, почему не работает?

    Itareo, 31 Марта 2014

    Комментарии (6)
  7. ActionScript / Говнокод #15621

    −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
    protected function ignite(event:FlexEvent):void {
        imgCooser.dataProvider = new ArrayList([new ObjectProxy({w:Math.round(Math.random()*100+55),t:'0 one'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'1 two'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'2 three'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'3 four'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'4 five'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'5 six'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'6 seven'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'7 eight'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'8 nine'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'9 ten'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'10 eleven'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'11 twelve'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'12 one'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'13 two'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'14 three'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'2 three'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'3 four'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'4 five'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'5 six'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'6 seven'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'7 eight'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'8 nine'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'9 ten'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'10 eleven'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'11 twelve'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'12 one'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'13 two'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'14 three'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'1 two'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'2 three'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'3 four'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'4 five'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'5 six'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'6 seven'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'7 eight'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'8 nine'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'9 ten'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'10 eleven'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'11 twelve'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'12 one'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'13 two'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'14 three'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'2 three'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'3 four'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'4 five'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'5 six'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'6 seven'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'7 eight'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'8 nine'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'9 ten'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'10 eleven'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'11 twelve'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'12 one'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'13 two'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'14 three'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'15 four'})]);

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

    wvxvw, 30 Марта 2014

    Комментарии (1)
  8. PHP / Говнокод #15620

    +155

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    $uu=substr($d_users,-2);
    $ux1=array(2,3,4,22,23,24,32,33,34,42,43,44,52,53,54,62,63,64,72,73,74,82,83,84,92,93,94);
    $ux2=array(1,21,31,41,51,61,71,81,91);
    $ut='Участников';
    if(in_array($uu,$ux1)){ $ut='Участника'; }
    elseif(in_array($uu,$ux2)){ $ut='Участник'; }

    norvele, 30 Марта 2014

    Комментарии (4)
  9. ActionScript / Говнокод #15619

    −136

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    public function TweenMax(target:Object, duration:Number, vars:Object) {
    	super(target, duration, vars);
    	if (TweenLite.version < 11.2) {
    		throw new Error("TweenMax error! Please update your TweenLite class or try deleting your ASO files. TweenMax requires a more recent version. Download updates at http://www.TweenMax.com.");
    	}

    Тут нужно дополнительно подчеркнуть, что оба класса TweenMax и TweenLite распространяются вместе, и случайно получить несоответствующую версию очень тяжело (ее надо самому поменять).
    Но самое интересное в другом: ASO файлы - это артефакт механизма кеширования использовавшегося в AS2. В AS3 механизм кеширования другой, и об этих файлах давным-давно никто не слышал. Тем не менее, сообщение об ошибке по прежнему предлагает пользователям с ними побороться.

    wvxvw, 30 Марта 2014

    Комментарии (1)
  10. PHP / Говнокод #15618

    +141

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    if($ID==265265265)
    $peremen1 = "poo poo!"
    $whatdo = "Eat"
    $peremen2 = "da"
    echo "$whatdo "."$peremen2 " .$peremen1" //Вот это доставляет
    $var = $ID
    $ci = $var + $ID //Хмм... Объясните, ЗАЧЕМ?

    vk.com/im/
    2011г.
    Видимо они планировали регистрацию юзера с айди 265265265

    Getup1NEW, 30 Марта 2014

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