1. Ruby / Говнокод #27327

    +2

    1. 1
    page < records.total_pages ? next_page_exist = true : next_page_exist = false

    очевидное должно быть очевидны

    AlexKlim, 29 Марта 2021

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

    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
    99. 99
    class MyString
    {
    public:
    	MyString(const char* str)
    	{
    		symbol = strlen(str);
    		this->str = new char[symbol + 1];
    		for (int i = 0; i < symbol; i++)
    		{
    			this->str[i] = str[i];
    		}
    		this->str[symbol] = '\0';
    	}
    	int Size()
    	{
    		return symbol;
    	}
    	MyString()
    	{
    		str = nullptr;
    		symbol = 0;
    	}
    	~MyString()
    	{
    		delete[] str;
    	}
    	MyString(const MyString& objct)
    	{
    		symbol = strlen(objct.str);
    		this->str = new char[symbol + 1];
    		for (int i = 0; i < symbol; i++)
    		{
    			this->str[i] = objct.str[i];
    		}
    		this->str[symbol] = '\0';
    	}
    	MyString operator ()(const char* objct)
    	{
    		if (this->str != nullptr)
    		{
    			delete[] this->str;
    		}
    		symbol = strlen(objct);
    		this->str = new char[symbol + 1];
    		for (int i = 0; i < symbol; i++)
    		{
    			this->str[i] = objct[i];
    		}
    		this->str[symbol] = '\0';
    		return *this;
    	}
    	MyString& operator =(MyString& objct)
    	{
    		if (this->str != nullptr)
    		{
    			delete[] str;
    		}
    		symbol = strlen(objct.str);
    		this->str = new char[symbol + 1];
    		for (int i = 0; i < symbol; i++)
    		{
    			this->str[i] = objct.str[i];
    		}
    		this->str[symbol] = '\0';
    		return *this;
    	}
    	MyString operator +(MyString& objct)//конкатенация строк
    	{
    		MyString NEWString;
    		symbol = strlen(this->str);
    		Ssymbol = strlen(objct.str);
    		NEWString.str = new char[symbol + Ssymbol + 1];
    		int i = 0;
    		NEWString.symbol = symbol + Ssymbol;
    		for (; i < symbol; i++)
    		{
    			NEWString.str[i] = this->str[i];
    		}
    		for (int j = 0; j < Ssymbol; j++, i++)
    		{
    			NEWString.str[i] = objct.str[j];
    		}
    		NEWString.str[symbol + Ssymbol] = '\0';
    		return NEWString;
    	}
    	//перегруженные операторы........
     int main()
    {
    	MyString asd = "Go";
    	MyString aa = "God";
    	if (asd >= aa)
    	{
    		cout << "Первая переменная больше по символам чем вторая." << endl;
    	}
    	else
    	{
    		cout << "Первая переменная меньше по символам чем вторая." << endl;
    	}
    }

    Свой класс строк. Что можно поправить для лучшей оптимизации?

    1337, 28 Марта 2021

    Комментарии (78)
  3. Java / Говнокод #27325

    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
    public static boolean isMagicSquare(int[][] a) {
        boolean isMagic = true;
        boolean isSquare = true;
        
        //square? checking here.
        for(int i = 0; i < a.length; i++) {
                if(a.length != a[i].length) {
                        isSquare = false;
                }
        }
        
        if(isSquare) {
            int sum = 0;
            int nextSum = 0;
            
            //first row
            for(int i = 0; i < a.length; i++) {
                    sum += a[0][i]; 
            }
            
            
            //rows
            for(int i = 1; i < a.length; i++) {
                    for(int j = 0; j < a.length; j++) {
                            nextSum += a[i][j];
                    }
                
                    if(nextSum != sum) {
                            isMagic = false;
                            break;
                    } else {
                            nextSum = 0;
                    }
            }
            
            //columns
            if(isMagic) {
                    for(int i = 0; i < a.length; i++) {
                            for(int j = 0; j < a.length; j++) {
                                    nextSum += a[j][i];
                            }
                        
                            if(nextSum != sum) {
                                    isMagic = false;
                                    break;
                            } else {
                                    nextSum = 0;
                            }
                    }
                
                    //diagonals
                    if(isMagic) {
                            for(int i = 0; i < a.length; i++) {
                                    nextSum += a[i][i];
                            }
                            
                            if(nextSum != sum) {
                                    isMagic = false;
                            } else {
                                    nextSum = 0;
                            }
                        
                            if(isMagic) {
                                    int j = a.length - 1;
                                
                                    for(int i = 0; i < a.length; i++) {
                                            nextSum += a[i][j];
                                            
                                            if(j > 0) {
                                                    j--;
                                            }
                                    }
                                
                                    if(nextSum != sum) {
                                            isMagic = false;
                                    }
                            }
                    }
            }
            
        } else {
                isMagic = false;
        }
    
        return isMagic;
    }

    Write a method called isMagicSquare that accepts a two-dimensional array of integers as a parameter and returns true if it is a magic square. A square matrix is a magic square if it is square in shape (same number of rows as columns, and every row the same length), and all of its row, column, and diagonal sums are equal. For example, [[2, 7, 6], [9, 5, 1], [4, 3, 8]] is a magic square because all eight of the sums are exactly 15.

    (https://practiceit.cs.washington.edu/problem/view/bjp3/chapter7/e20%2DisMagicSquare)

    Работает, но код нечитаемый. Как сократить? Понятия не имею.

    imrnccc, 28 Марта 2021

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

    +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
    21. 21
    22. 22
    23. 23
    program square;
    
    var sep, input: string;
      i, j, n, m : integer;
      
    
    begin
      write('sep:');
      readln(sep);
      
      write('str:');
      readln(input);
      
      for i:=1 to length(input) do write(input[i], ' ');
      writeln();
      for i:=2 to length(input)-1 do begin
        write(input[i]);
        for j:=1 to length(input)*2-3 do write (sep);
        writeln(input[length(input) - i + 1]);
      end;
      for i:=0 to length(input)-1 do 
        write(input[length(input)-i], ' ');
    end.

    Написала на скучной лекции программку на телефоне, чтобы распечатывать

    Х У Й
    У У
    Й У Х


    и прочие интересности UwU

    Пользуйтесь на здоровье, лицензия GNU GPL V3!

    KoWe4Ka_l7porpaMMep, 28 Марта 2021

    Комментарии (18)
  5. PHP / Говнокод #27323

    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
    function isRegEx($test)
    {
        $notThisLine = error_get_last();
        $notThisLine = isset($notThisLine['line']) ? $notThisLine['line'] + 0 : 0;
        while (($lines = rand(1, 100)) == $notThisLine);
        eval(
            str_repeat("\n", $lines) . 
            '@preg_match(\'' . addslashes($test) . '\', \'\');'
        );
        $check = error_get_last();
        $check = isset($check['line']) ? $check['line'] + 0 : 0;
        return $check == $notThisLine;
    }

    "Test if a regular expression is a valid one in PHP"
    https://stackoverflow.com/a/15143479/6702274

    kezzyhko, 28 Марта 2021

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

    0

    1. 1
    Пиздец-оффтоп #15

    #1: https://govnokod.ru/26503 https://govnokod.xyz/_26503
    #2: https://govnokod.ru/26541 https://govnokod.xyz/_26541
    #3: https://govnokod.ru/26583 https://govnokod.xyz/_26583
    #4: https://govnokod.ru/26689 https://govnokod.xyz/_26689
    #5: https://govnokod.ru/26784 https://govnokod.xyz/_26784
    #5: https://govnokod.ru/26839 https://govnokod.xyz/_26839
    #6: https://govnokod.ru/26986 https://govnokod.xyz/_26986
    #7: https://govnokod.ru/27007 https://govnokod.xyz/_27007
    #8: https://govnokod.ru/27023 https://govnokod.xyz/_27023
    #9: https://govnokod.ru/27098 https://govnokod.xyz/_27098
    #10: https://govnokod.ru/27125 https://govnokod.xyz/_27125
    #11: https://govnokod.ru/27129 https://govnokod.xyz/_27129
    #12: https://govnokod.ru/27184 https://govnokod.xyz/_27184
    #13: https://govnokod.ru/27286 https://govnokod.xyz/_27286
    #14: https://govnokod.ru/27298 https://govnokod.xyz/_27298

    nepeKamHblu_nemyx, 27 Марта 2021

    Комментарии (3610)
  7. Python / Говнокод #27321

    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
    def luhn(self):
            all_sum = 0
            self.__card_number = str(self.__card_number)
            self.__card_number = list(self.__card_number)
            for element in range(len(self.__card_number)):
                if element % 2 == 0:
                    self.__card_number[element] = int(self.__card_number[element]) * 2
                    if self.__card_number[element] > 9:
                        number = self.__card_number[element]
                        self.__card_number[element] = number // 100 + number // 10 % 10 + number % 10  # sum digits of number
                self.__card_number[element] = int(self.__card_number[element])
                all_sum += self.__card_number[element]
            checksum = 0
            while checksum < 10:
                if all_sum % 10 == 0:
                    checksum = str(checksum)
                    break
                else:
                    all_sum += 1
                    checksum += 1
            self.i = str(self.i)
            self.i = list(self.i)
            self.i.append(checksum)
            self.__card_number = self.i
     
            self.__card_number = "".join(self.__card_number)

    Для преокта нужен был алгоритм луна, чтобы создать в конце контрольную сумму. При написании проебался, что мне card_number нужно просто добавить 1 цифру, а не менять его и по этому просто добавил костыль в виде i.

    warzon131, 27 Марта 2021

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

    +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
    $query = "
    	SELECT
    		`version`, `mods`, `plugins`, `keywords`
    	WHERE
    		`version` = {$version}";
    foreach (explode(",", $mods) as $mod)
    {
    	$query += "AND `mods` LIKE '{$mod}' OR `mods` LIKE '{$mod},%' OR `mods` LIKE '%,{$mod},%' OR `mods` LIKE '%,{$mod}'";
    }
    foreach (explode(",", $plugins) as $plugin)
    {
    	$query += "AND `plugins` LIKE '{$plugin}' OR `plugins` LIKE '{$plugin},%' OR `plugins` LIKE '%,{$plugin},%' OR `plugins` LIKE '%,{$plugin}'";
    }

    Говнокод чтобы прогнать массив с id записей внутри varchar по массиву с id записей из переменной (id,id,id)

    Dev1lroot, 27 Марта 2021

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

    +1

    1. 1
    Просто оффтоп #17

    #1: https://govnokod.ru/20162 https://govnokod.xyz/_20162
    #2: https://govnokod.ru/25329 https://govnokod.xyz/_25329
    #3: https://govnokod.ru/25415 https://govnokod.xyz/_25415
    #4: (vanished) https://govnokod.xyz/_25472
    #5: https://govnokod.ru/25693 https://govnokod.xyz/_25693
    #6: (vanished) https://govnokod.xyz/_26649
    #7: https://govnokod.ru/26672 https://govnokod.xyz/_26672
    #8: https://govnokod.ru/26924 https://govnokod.xyz/_26924
    #9: https://govnokod.ru/27072 https://govnokod.xyz/_27072
    #10: https://govnokod.ru/27086 https://govnokod.xyz/_27086
    #11: https://govnokod.ru/27122 https://govnokod.xyz/_27122
    #12: https://govnokod.ru/27153 https://govnokod.xyz/_27153
    #13: https://govnokod.ru/27159 https://govnokod.xyz/_27159
    #14: https://govnokod.ru/27200 https://govnokod.xyz/_27200
    #15: https://govnokod.ru/27237 https://govnokod.xyz/_27237
    #16: https://govnokod.ru/27282 https://govnokod.xyz/_27282

    nepeKamHblu_nemyx, 26 Марта 2021

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

    +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
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    using System.Device.Gpio;
    using System;
    using System.Threading;
    
    namespace Blinky
    {
    	public class Program
        {
            private static GpioController s_GpioController;
            public static void Main()
            {
                s_GpioController = new GpioController();
    
                // ESP32 DevKit: 4 is a valid GPIO pin in, some boards like Xiuxin ESP32 may require GPIO Pin 2 instead.
                GpioPin led = s_GpioController.OpenPin(4,PinMode.Output);
                led.Write(PinValue.Low);
    
                while (true)
                {
                    led.Toggle();
                    Thread.Sleep(125);
                    led.Toggle();
                    Thread.Sleep(125);
                    led.Toggle();
                    Thread.Sleep(125);
                    led.Toggle();
                    Thread.Sleep(525);
                }
            }        
        }
    }

    https://habr.com/ru/post/549012/: «.NET nanoFramework — платформа для разработки приложений на C# для микроконтроллеров».

    Ну все, последний оплот сишки пал, можно ее закапывать.

    PolinaAksenova, 25 Марта 2021

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