1. Список говнокодов пользователя j123123

    Всего: 331

  2. C# / Говнокод #25320

    +4

    1. 1
    2. 2
    Yandere Simulator
    https://f0ck.me/b/09d3f680.mp4

    j123123, 22 Января 2019

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

    +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
    // https://www.tutorialspoint.com/Read-a-character-from-standard-input-without-waiting-for-a-newline-in-Cplusplus
    
    
    
    // A portable solution doesn't exist for doing this. On windows, you can use the getch() function from the conio(Console I/O) library to get characters pressed. For example,
    
    #include<iostream>
    #include<conio.h>
    using namespace std;
    int main() {
        char c;
        while(1){ // infinite loop
            c = getch();
            cout << c;
        }
    }
    
    // This will output whatever character you input to the terminal. Note that this will only work on windows as the conio library exists only on windows. On UNIX, you can achieve this by entering in system raw mode. For example,
    
    #include<iostream>
    #include<stdio.h>
    int main() {
        char c;
       // Set the terminal to raw mode
        system("stty raw");
        while(1) {
            c = getchar(); 
            // terminate when "." is pressed
            if(c == '.') {
                system("stty cooked");
                exit(0);
            }  
            std::cout << c << " was pressed."<< std::endl;
        }
    }

    Вариант под UNIX еще и очень секурный, ЕВПОЧЯ

    j123123, 22 Января 2019

    Комментарии (39)
  4. Си / Говнокод #25307

    −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
    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
    void sort8(uint64_t a[8])
    {
      uint64_t a0;
      uint64_t a1;
      uint64_t a2;
      uint64_t a3;
      uint64_t a4;
      uint64_t a5;
      uint64_t a6;
      uint64_t a7;
     
      SORT2(a[0], a[1], a0, a1);
      SORT2(a[2], a[3], a2, a3);
      SORT2(a[4], a[5], a4, a5);
      SORT2(a[6], a[7], a6, a7);
    
      uint64_t a_tmp[8];
    
      MERGE_2_4(a0, a1, a2, a3, a_tmp[0], a_tmp[1], a_tmp[2], a_tmp[3]);
      MERGE_2_4(a4, a5, a6, a7, a_tmp[4], a_tmp[5], a_tmp[6], a_tmp[7]);
    
      uint64_t *ptra1 = &a_tmp[0];
      uint64_t *ptra2 = &a_tmp[4];
      
      for (size_t i = 0; i < 4; i++)
      {
        if (*ptra1 < *ptra2)
        {
          a[i] = *ptra1;
          ptra1++;
        }
        else
        {
          a[i] = *ptra2;
          ptra2++;
        }
      }
    
      for (size_t i = 4; i < 8; i++)
      {
        if (ptra1 == &a_tmp[4])
        {
          while (ptra2 != &a_tmp[8])
          {
            a[i++] = *ptra2;
            ptra2++;
          }
          break;
        }
        
        if (ptra2 == &a_tmp[8])
        {
          while (ptra1 != &a_tmp[4])
          {
            a[i++] = *ptra1;
            ptra1++;
          }
          break;
        }
    
    
        if (*ptra1 < *ptra2)
        {
          a[i] = *ptra1;
          ptra1++;
        }
        else
        {
          a[i] = *ptra2;
          ptra2++;
        }
    
      }
    }

    Мерж сорт, специализированный на 8 элементов. Вот доказательство корректности https://paste.debian.net/hidden/cce6d31a/

    j123123, 13 Января 2019

    Комментарии (137)
  5. Assembler / Говнокод #25239

    +2

    1. 1
    2. 2
    3. 3
    https://www.researchgate.net/publication/325358150_cQASM_v10_Towards_a_Common_Quantum_Assembly_Language
    
    cQASM v1.0: Towards a Common Quantum Assembly Language

    The quantum assembly language (QASM) is a popular intermediate representation used in many quantum compilation and simulation tools to describe quantum circuits. Currently, multiple different dialects of QASM are used in different quantum computing tools. This makes the interaction between those tools tedious and time-consuming due to the need for translators between theses different syntaxes. Beside requiring a multitude of translators, the translation process exposes the constant risk of loosing information due to the potential incompatibilities between the different dialects. Moreover, several tools introduce details of specific target hardware or qubit technologies within the QASM syntax and prevent porting the code to other hardwares. In this paper, we propose a common QASM syntax definition, named cQASM, which aims to abstract away qubit technology details and guarantee the interoperability between all the quantum compilation and simulation tools supporting this standard. Our vision is to enable an extensive quantum computing toolbox shared by all the quantum computing community.

    Вот это я понимаю, а то вон там мелкософт какие-то говношарпы придумывает очередные:

    https://docs.microsoft.com/en-us/quantum/language/?view=qsharp-preview


    Нахер ваши шарпы с вашим сраным дуднетом и прочей такой хуйней, даешь Assembler.

    j123123, 28 Декабря 2018

    Комментарии (187)
  6. Си / Говнокод #25229

    +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
    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
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    
    #define SQARESZ 3
    
    
    void rotateclockwise(char *ptra, size_t sz)
    {
        char (*a_ar)[sz] = (void *)ptra;
        char b_ar[sz][sz];
        for (size_t y = 0; y < sz; y++)
        {
            for (size_t x = 0; x < sz; x++)
            {
                b_ar[y][x] = a_ar[sz-1-x][y];
            }
        }
        memcpy(a_ar, b_ar, sz*sz);
    }
    
    void print_ar(char *ptra, size_t sz)
    {
        char (*a_ar)[sz] = (void *)ptra;
        for (size_t y = 0; y < sz; y++)
        {
            for (size_t x = 0; x < sz; x++)
            {
                printf("%i ", a_ar[y][x]);
            }
            printf("\n");
        }
    }
    
    int main()
    {
        char a[SQARESZ][SQARESZ] =
        {
          {1,2,3},
          {4,5,6},
          {7,8,9}
        };
        
        print_ar((char *)a, SQARESZ);
        printf("\n");
        rotateclockwise((char *)a, SQARESZ);
        
        print_ar((char *)a, SQARESZ);
        printf("\n");
        rotateclockwise((char *)a, SQARESZ);
        
        print_ar((char *)a, SQARESZ);
        printf("\n");
        rotateclockwise((char *)a, SQARESZ);
        
        print_ar((char *)a, SQARESZ);
        printf("\n");
        rotateclockwise((char *)a, SQARESZ);
        
        print_ar((char *)a, SQARESZ);
        printf("\n");
    
        return 0;
    }

    https://habr.com/post/317300/ В C++17 до сих пор нет нормальных многомерных массивов, которые были в Fortran начиная с Fortran 90

    > UPD от 2016-12-10 14:03. Посмотрел на этот коммент от @selgjos, поэкспериментировал с компилятором и понял, что с помощью C99 VLA всё-таки можно добиться нужного мне эффекта.
    > В общем, окей, в C есть нужные мне массивы. Как и в Fortran. А в C++ их по-прежнему нет.

    j123123, 26 Декабря 2018

    Комментарии (144)
  7. Assembler / Говнокод #25228

    +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
    /*
    x86-64 clang (trunk) -O3
    https://godbolt.org/z/t8NDGG
    
    #include <inttypes.h>
    
    uint32_t saturation_add(uint32_t a, uint32_t b)
    {
        const uint64_t tmp = (uint64_t)a + b;
        if (tmp > UINT32_MAX)
        {
            return UINT32_MAX;
        }
        return tmp;
    }
    */
    
    saturation_add:
            mov     edx, esi
            mov     eax, edi
            add     edi, esi
            add     rax, rdx
            mov     edx, 4294967295
            cmp     rax, rdx
            mov     eax, -1   // ЗАЧЕМ???
            cmovbe  eax, edi
            ret

    https://en.wikipedia.org/wiki/Saturation_arithmetic
    Почему компиляторы до сих пор такое говно

    j123123, 26 Декабря 2018

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

    +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
    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
    ;;; the toplevel operators of each equation in the system
    ;;; type : array[term]
    (defmacro match-acz-state-methods (state__) `(svref ,state__ 0))
    
    ;;; functional terms
    ;;; type : array[term]
    (defmacro match-acz-state-lhs-f (state__) `(svref ,state__ 1))
    
    ;;; variables on the LHS
    ;;; type : array[term]
    (defmacro match-acz-state-lhs-v (state__) `(svref ,state__ 2))
    
    ;;; contants on the RHS
    ;;; type : array[term]
    (defmacro match-acz-state-rhs-c (state__) `(svref ,state__ 3))
    
    ;;; functional terms on RHS
    ;;; type : array[term]
    (defmacro match-acz-state-rhs-f (state__) `(svref ,state__ 4))
    
    ;;; notes repeated functional terms of LHS
    ;;; type : array[bool]
    (defmacro match-acz-state-lhs-f-r (state__) `(svref ,state__ 5))
    
    ;;; notes repeated variables of LHS
    ;;; type : array[bool]
    (defmacro match-acz-state-lhs-v-r (state__) `(svref ,state__ 6))
    
    ;;; notes repeated constants of RHS
    ;;; type : array[bool]
    (defmacro match-acz-state-rhs-c-r (state__) `(svref ,state__ 7))
    
    ;;; notes repreated funcational terms of RHS
    ;;; type : array[bool]
    (defmacro match-acz-state-rhs-f-r (state__) `(svref ,state__ 8))
    
    ;;; variables and funs acocunted for by RHS-c-sol
    ;;; type : fixnum
    (defmacro match-acz-state-lhs-mask (state__)  `(svref ,state__ 9))
    
    ;;; funs accounted for by RHS-c-sol
    ;;; type : fixnum
    (defmacro match-acz-state-lhs-f-mask (state__) `(svref ,state__ 10))
    
    ;;; bit vector of all repeated (> 0) terms on LHS
    (defmacro match-acz-state-lhs-r-mask (state__)  `(svref ,state__ 11))
    
    ;;; solution matrix for constants
    ;;; type : array[fixnum]
    (defmacro match-acz-state-rhs-c-sol (state__) `(svref ,state__ 12 ))
    
    ;;; max value of elements of RHS-C-sol
    ;;; type : fixnum
    (defmacro match-acz-state-rhs-c-max (state__) `(svref ,state__ 13))
    
    ;;; solutions matrix; functional terms
    ;;; type : array[fixnum]
    (defmacro match-acz-state-rhs-f-sol (state__) `(svref ,state__ 14))
    
    ;;; max value of elements of RHS-f-sol
    ;;; type : fixnum
    (defmacro match-acz-state-rhs-f-max (state__) `(svref ,state__ 15))
    
    ;;; type : fixnum 11111 ... 1111
    (defmacro match-acz-state-rhs-full-bits (state__) `(svref ,state__ 16))
    
    ;;; array of compatibility bitvectors; constants
    ;;; type : array[fixnum]
    (defmacro match-acz-state-rhs-c-compat (state__) `(svref ,state__ 17))
    
    ;;; array of compatibility bitvectors; funcs
    ;;; type : array[fixnum]
    (defmacro match-acz-state-rhs-f-compat (state__) `(svref ,state__ 18))
    
    ;;; number of constants on LHS after simplification
    ;;; type : fixnum
    (defmacro match-acz-state-lhs-c-count (state__) `(svref ,state__ 19))
    
    ;;; number of functions on LHS after simplification
    ;;; type : fixnum
    (defmacro match-acz-state-lhs-f-count (state__) `(svref ,state__ 20))
    
    ;;; number of variables on LHS after simplification
    ;;; type : fixnum
    (defmacro match-acz-state-lhs-v-count (state__) `(svref ,state__ 21))
    
    ;;; number of constants on RHS after simplification
    ;;; type : fixnum
    (defmacro match-acz-state-rhs-c-count (state__)  `(svref ,state__ 22))
    
    ;;; number of functions on RHS after simplification
    ;;; type : fixnum
    (defmacro match-acz-state-rhs-f-count (state__) `(svref ,state__ 23))
    
    ;;; t iff all solutions have been reported.
    (defmacro match-acz-state-no-more (state__) `(svref ,state__ 24))

    https://github.com/CafeOBJ/cafeobj/blob/master/chaos/e-match/match-acz.lisp

    ГОМОИКОНЫ копипаст лиспе
    CafeOBJ is a most advanced formal specification language which inherits many advanced features (e.g. flexible mix-fix syntax, powerful and clear typing system with ordered sorts, parameteric modules and views for instantiating the parameters, and module expressions, etc.) from OBJ (or more exactly OBJ3) algebraic specification language.

    CafeOBJ is a language for writing formal (i.e. mathematical) specifications of models for wide varieties of software and systems, and verifying properties of them. CafeOBJ implements equational logic by rewriting and can be used as a powerful interactive theorem proving system. Specifiers can write proof scores also in CafeOBJ and doing proofs by executing the proof scores.

    CafeOBJ has state-of-art rigorous logical semantics based on institutions. The CafeOBJ cube shows the structure of the various logics underlying the combination of the various paradigms implemented by the language. Proof scores in CafeOBJ are also based on institution based rigorous semantics, and can be constructed using a complete set of proof rules

    j123123, 20 Декабря 2018

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

    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
    enum crap
    {
        shit = 0,
        fuck,
        dick,
        ass,
        turd,
        fart,
    };
    
    static char *crap_to_str(int crap)
    {
        switch (crap)
        {
            case shit:
            {
                return "shit";
            }
            case fuck:
            {
                return "fuck";
            }
            case dick:
            {
                return "dick";
            }
            case ass:
            {
                return "ass";
            }
            case turd:
            {
                return "turd";
            }
            case fart:
            {
                return "fart";
            }
            default:
            {
                return "!!!UNKNOWN CRAP!!!";
            }
        }
    }

    Есть ли возможность через какую-нибудь плюсовую метушню с шаблонами, констэспрами и препроцессором нагенерировать подобную хрень из готового определения структуры?

    j123123, 18 Декабря 2018

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

    +3

    1. 1
    2. 2
    3. 3
    4. 4
    Кстати, разные эпизоды из Зеленого слоника можно сопоставить с разными статьями
    о C++. Если статья про какие-то новые возможности, которые вводятся в
    каком-нибудь С++20, это когда братишке покушать принесли. Если статья о том,
    как можно метапрограммировать на шаблонах, то это когда вилкой говно чистить.

    Ну что ты! Я тебе сейчас расскажу, вот смотри, Я тебе хорошую сейчас расскажу! Смотри, я… вот у нас здесь копипаста много… ой-ой… копипаста много, понимаешь? Смотри, копипаст, они тебе код читать мешает. А я вот, давай я здесь напишу метушни на темплейтах и консэкспрах с препроцессором сишным, и весь копипаст сокращу слышишь? Ну что, писать?

    j123123, 15 Декабря 2018

    Комментарии (21)
  11. Си / Говнокод #25171

    +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
    #include <stdio.h>
    #include <inttypes.h>
    #include <stddef.h>
    
    void printuint64(const uint64_t state);
    uint64_t game_of_life8x8(const uint64_t old);
    uint8_t getbit(uint64_t in, uint8_t y, uint8_t x);
    
    uint8_t getbit(uint64_t in, uint8_t y, uint8_t x)
    {
      return !!((in) & (1ULL << ((y&0b111) + (x&0b111)*8)) );
    }
    
    uint64_t setbit(uint8_t y, uint8_t x, uint8_t bit)
    {
      if (bit)
      {
        return 1ULL << ((y&0b111) + (x&0b111)*8);
      }
      return 0;
    }
    
    uint64_t game_of_life8x8(const uint64_t old)
    {
      uint64_t new_state = 0;
      #define GETBIT(y,x,val) getbit(val, y, x)
      #define SETBIT(y,x,bit) setbit(y,x,bit)
      
      #define SUMAROUND(y,x,val) ( \
        GETBIT(y+1,x,val) + GETBIT(y-1,x,val) \
      + GETBIT(y,x+1,val) + GETBIT(y,x-1,val) \
      + GETBIT(y+1,x+1,val) + GETBIT(y+1,x-1,val) \
      + GETBIT(y-1,x+1,val) + GETBIT(y-1,x-1,val) \
      )
    
      #define CELLSTATE(y,x,val) \
      (GETBIT(y,x,old) == 1 ? \
        ( ((SUMAROUND(y,x,val) == 2 ) || ( SUMAROUND(y,x,val) == 3 )) ? 1 : 0) \
        : \
        ( ( SUMAROUND(y,x,val) == 3 ) ? 1 : 0 ) \
      )
    
      #define SETCELL_SH(y,x,val) SETBIT(y,x,CELLSTATE(y,x,val))
    
      #define FILL_LINE(y) \
        SETCELL_SH(y,7,old) | SETCELL_SH(y,6,old) | SETCELL_SH(y,5,old) | \
        SETCELL_SH(y,4,old) | SETCELL_SH(y,3,old) | SETCELL_SH(y,2,old) | \
        SETCELL_SH(y,1,old) | SETCELL_SH(y,0,old)
    
      new_state = FILL_LINE(7) | FILL_LINE(6) | FILL_LINE(5)
      |  FILL_LINE(4) | FILL_LINE(3) | FILL_LINE(2)
      |  FILL_LINE(1) | FILL_LINE(0);
    
      return new_state;
    }
    
    void printuint64(const uint64_t state)
    {
      for (size_t i = 7; i != SIZE_MAX; i--)
      {
        for (size_t j = 7; j != SIZE_MAX; j--)
        {
          printf("%u", !!((state >> (j+i*8)) & 1) );
        }
        printf("\n");
      }
    }
    
    int main(void)
    {
      // Glider
      uint64_t state =
      (( 0b01000000ULL ) << 8*7 ) |
      (( 0b00100000ULL ) << 8*6 ) |
      (( 0b11100000ULL ) << 8*5 ) |
      (( 0b00000000ULL ) << 8*4 ) |
      (( 0b00000000ULL ) << 8*3 ) |
      (( 0b00000000ULL ) << 8*2 ) |
      (( 0b00000000ULL ) << 8*1 ) |
      (( 0b00000000ULL ) << 8*0 );
    
      
      for (size_t i = 0; i < 50; i++)
      {
        printuint64(state);
        state = game_of_life8x8(state);
        printf("\n");
      }
      return 0;
    }

    Conway's game of life внутри uint64_t (8 на 8) с периодическими граничными условиями.

    j123123, 09 Декабря 2018

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