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

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

    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
    struct node
    {
        void *data;
    
        struct node *head;
        struct node *tail;
    };
    struct list
    {
        int size;
    
        struct node *head;
        struct node *tail;
    
        void *(*alloc_node)(size_t);
        void *(*alloc_data)(size_t);
        void (*free_node)(void *);
        void (*free_data)(void *);
    };
    
    typedef struct node node_t;
    typedef struct list list_t;
    
    void list_init(list_t *list)
    {
        list->size = 0;
    
        list->head = (node_t*)list;
        list->tail = (node_t*)list;
    
        list->alloc_node = &malloc;
        list->alloc_data = &malloc;
        list->free_node = &free;
        list->free_data = &free;
    }
    void list_link(struct node *head, struct node *tail)
    {
        head->tail = tail;
        tail->head = head;
    }
    void *push_head(list_t *list, node_t *head, size_t size)
    {
        node_t *node = list->alloc_node(sizeof(node_t));
        void   *data = list->alloc_data(size);
    
        node->data = data;
        list_link(node, head->tail);
        list_link(head, node);
    
        list->size++;
        return data;
    }
    void *push_tail(list_t *list, node_t *tail, size_t size)
    {
        node_t *node = list->alloc_node(sizeof(node_t));
        void   *data = list->alloc_data(size);
    
        node->data = data;
        list_link(tail->head, node);
        list_link(node, tail);
    
        list->size++;
        return data;
    }
    void pop(list_t *list, node_t *node)
    {
        list_link(node->head, node->tail);
        list->size--;
    
        void *data = node->data;
    
        list->free_node(node);
        list->free_data(data);
    }
    void print(struct list *list)
    {
        printf("\n====\n");
    
        printf("size: %ld \n", list->size);
    
        int i = 0;
    
        for(node_t *node = list->head; node != list; node = node->head)
        {
            printf("index: %ld number: %ld \n", i, *(int*)(node->data));
            i++;
        }
    }
    
    struct list lst;
    
        list_init(&lst);
    
        print(&lst);
    
        void *data;
        data = push_tail(&lst, lst.tail, 4);
        *(int*)data = 1;

    итак скажите про название функций про то каких функций не хватает + alloc и free поля не трогать это мне нужно ТОЛЬКО НЕ советуйте перейти на с++ и использовать чтото другое(std::list)

    CodeTux, 16 Июня 2023

    Комментарии (23)
  3. Куча / Говнокод #28616

    −9

    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
    govnokod.*##div.entry-comments div.entry-comment-wrapper:has(p.entry-info > strong.entry-author a[href$="/25947"])
    
    govnokod.*##div.entry-comments div.entry-comment-wrapper:has(p.entry-info > strong.entry-author a[href$="/26133"])
    govnokod.*##div.entry-comments div.entry-comment-wrapper:has(p.entry-info > strong.entry-author a[href$="/26134"])
    govnokod.*##div.entry-comments div.entry-comment-wrapper:has(p.entry-info > strong.entry-author a[href$="/26135"])
    govnokod.*##div.entry-comments div.entry-comment-wrapper:has(p.entry-info > strong.entry-author a[href$="/26137"])
    
    govnokod.*##div.entry-comments div.entry-comment-wrapper:has(p.entry-info > strong.entry-author a[href$="/67335"])
    
    govnokod.*##div.entry-comments div.entry-comment-wrapper:has(p.entry-info > strong.entry-author a[href$="/68057"])
    govnokod.*##div.entry-comments div.entry-comment-wrapper:has(p.entry-info > strong.entry-author a[href$="/68069"])
    
    govnokod.*##div.entry-comments div.entry-comment-wrapper:has(p.entry-info > strong.entry-author a[href$="/68120"])
    
    govnokod.*##div.entry-comments div.entry-comment-wrapper:has(p.entry-info > strong.entry-author a[href$="/68134"])
    govnokod.*##div.entry-comments div.entry-comment-wrapper:has(p.entry-info > strong.entry-author a[href$="/68139"])
    
    govnokod.*##div.entry-comments div.entry-comment-wrapper:has(p.entry-info > strong.entry-author a[href$="/68240"])
    govnokod.*##div.entry-comments div.entry-comment-wrapper:has(p.entry-info > strong.entry-author a[href$="/68257"])
    govnokod.*##div.entry-comments div.entry-comment-wrapper:has(p.entry-info > strong.entry-author a[href$="/68261"])
    
    govnokod.*##div.entry-comments div.entry-comment-wrapper:has(p.entry-info > strong.entry-author a[href$="/68335"])
    
    govnokod.*##div.entry-comments div.entry-comment-wrapper:has(p.entry-info > strong.entry-author a[href$="/68367"])
    govnokod.*##div.entry-comments div.entry-comment-wrapper:has(p.entry-info > strong.entry-author a[href$="/68368"])
    govnokod.*##div.entry-comments div.entry-comment-wrapper:has(p.entry-info > strong.entry-author a[href$="/68369"])
    govnokod.*##div.entry-comments div.entry-comment-wrapper:has(p.entry-info > strong.entry-author a[href$="/68371"])
    govnokod.*##div.entry-comments div.entry-comment-wrapper:has(p.entry-info > strong.entry-author a[href$="/68372"])
    govnokod.*##div.entry-comments div.entry-comment-wrapper:has(p.entry-info > strong.entry-author a[href$="/68373"])

    o6AMa_4MO, 27 Февраля 2023

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

    −1

    1. 1
    2. 2
    3. 3
    4. 4
    public bool IsTrueOrFalse(string value)
            {
                return (value.ToString().Length == 4  value.ToString().ToLower()=="true") ? true : (value.ToString().Length == 5  value.ToString().ToLower() == "false") ? false : true;
            }

    techlead_seneor_228, 21 Апреля 2022

    Комментарии (23)
  5. Си / Говнокод #28054

    −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
    typedef enum {
      FILE_NONE, FILE_C, FILE_ASM, FILE_OBJ, FILE_AR, FILE_DSO,
    } FileType;
    
    StringArray include_paths;
    bool opt_fcommon = true;
    bool opt_fpic;
    
    static FileType opt_x;
    static StringArray opt_include;
    static bool opt_E;
    static bool opt_M;
    static bool opt_MD;
    static bool opt_MMD;
    static bool opt_MP;
    static bool opt_S;
    static bool opt_c;
    static bool opt_cc1;
    static bool opt_hash_hash_hash;
    static bool opt_static;
    static bool opt_shared;
    static char *opt_MF;
    static char *opt_MT;
    static char *opt_o;
    
    static StringArray ld_extra_args;
    static StringArray std_include_paths;
    
    char *base_file;
    static char *output_file;
    
    static StringArray input_paths;
    static StringArray tmpfiles;

    благо поиск по проекту работает

    kcalbCube, 25 Февраля 2022

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    function main() {
        let arr = [1, 2, 3];
    
        for (const v of arr.map(x => x + 1)) print(v);
    
        print("done.");
    }

    Для тех кто не понял предыдущий пример.. я упростил для вас :)

    ASD_77, 11 Февраля 2022

    Комментарии (23)
  7. Куча / Говнокод #28000

    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
    %% Note: set and unset are not thread-safe.
    -spec set(key(), value()) -> ok.
    set(Key, Value) ->
        case ets:lookup(?status_tab, Key) of
            [{_, {set, _OldValue}}] ->
                ets:insert(?status_tab, {Key, {set, Value}});
            [{_, {unset, Pid}}] ->
                MRef = monitor(process, Pid),
                Pid ! {set, Value},
                receive
                    {'DOWN', MRef, _, _, _} -> ok
                end;
            [] ->
                case ets:insert_new(?status_tab, {Key, {set, Value}}) of
                    true  ->
                        ok;
                    false ->
                        set(Key, Value)
                end
        end,
        ok.
    
    -spec unset(key()) -> ok.
    unset(Key) ->
        case ets:lookup(?status_tab, Key) of
            [{_, {set, _OldValue}}] -> ets:delete(?status_tab, Key);
            _                       -> ok
        end,
        ok.
    
    -spec read(key()) -> value().
    read(Key) ->
        case read_or_wait(Key) of
            {set, Value} ->
                Value;
            {wait, MRef} ->
                receive
                    {'DOWN', MRef, _, _, {cvar_set, Value}} ->
                        Value;
                    {'DOWN', MRef, _, _, noproc} ->
                        read(Key)
                end
        end.
    
    -spec read_or_wait(key()) -> {set, value()} | {wait, reference()}.
    read_or_wait(Key) ->
        case ets:lookup(?status_tab, Key) of
            [] ->
                {Pid, MRef} = spawn_monitor(?MODULE, waker_entrypoint, [Key, self()]),
                receive
                    {Pid, proceed} ->
                        {wait, MRef};
                    {'DOWN', MRef, _, _, Reason} ->
                        cvar_retry = Reason,
                        read_or_wait(Key)
                end;
            [{_, {set, Val}}] ->
                {set, Val};
            [{_, {unset, Pid}}] ->
                {wait, monitor(process, Pid)}
        end.
    
    -spec waker_entrypoint(key(), pid()) -> no_return().
    waker_entrypoint(Key, Parent) ->
        case ets_insert_new({Key, {unset, self()}}) of
            false ->
                exit(cvar_retry);
            true ->
                Parent ! {self(), proceed},
                receive
                    {set, Value} ->
                        ets_insert({Key, {set, Value}}),
                        exit({cvar_set, Value})
                end
        end.

    CHayT, 08 Февраля 2022

    Комментарии (23)
  8. Python / Говнокод #27866

    −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
    #!/usr/bin/python
      
      import sys
      
      cache = {}
      
      def count(start, end):
          if start < end:
              if start not in cache:
                  cache[start] = count(start + 1, end) + count(start * 2, end) + count(start ** 2, end)
              return cache[start]
          elif start == end:
              return 1
          else:
              return 0
    
      print(count(int(sys.argv[1]), int(sys.argv[2])))

    Подсчитать количество путей из a в b с помощью прибавления единицы, умножения на 2 и возведения в квадрат

    Чем формально ограничены возможности преобразовать рекурсию в хвостовую? Вот такое ведь не преобразовать?

    vistefan, 11 Декабря 2021

    Комментарии (23)
  9. Java / Говнокод #27664

    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
    import java.util.Arrays;
    import java.util.Optional;
    
    public class AntiVirus{
      
      private int scanIntensity = 0;
      
      //this method is ready for you.
      public void setScanIntensity(int level){
        scanIntensity = level;
      }
      
      //write this method.
      public String scanFile(File file,VirusDB database){
        String[] signature = database.getSignatures(scanIntensity);
        String fileData = file.getData().toLowerCase();
        
         Optional<String> res = Arrays.stream(signature)
             .map(s -> s.toLowerCase())
             .filter(fileData::contains).findAny();
        
         String scan = " is safe";
        
         if(res.isPresent()) {
            System.out.println(res.get());
            System.out.println("scan: " + scan);
            scan = " is not safe";
            System.out.println("scan after: " + scan);
         }
        
        return file.getName() + scan;
      }
    }

    Не понимаю, почему не работает.

    Задача
    https://www.codewars.com/kata/5b13027eedd62c5216000001

    Test Results:
    AVTest
    checkRandomFiles
    Log
    dos
    scan: is safe
    scan after: is not safe
    dos
    scan: is safe
    scan after: is not safe
    dos
    scan: is safe
    scan after: is not safe
    dos
    scan: is safe
    scan after: is not safe
    dos
    scan: is safe
    scan after: is not safe
    dos
    scan: is safe
    scan after: is not safe
    dos
    scan: is safe
    scan after: is not safe
    dos
    scan: is safe
    scan after: is not safe
    dos
    scan: is safe
    scan after: is not safe
    expected:<f4wpzFoQD is [not ]safe> but was:<f4wpzFoQD is []safe>
    Stack Trace
    Completed in 476ms
    checkSameFilesWithDifferentIntensitySett ings
    Log
    virus
    scan: is safe
    scan after: is not safe
    expected:<file1 is [not ]safe> but was:<file1 is []safe>
    Stack Trace
    Completed in 1ms
    Completed in 496ms

    imrnccc, 14 Сентября 2021

    Комментарии (23)
  10. Куча / Говнокод #27547

    +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
    Ltac destruct_mint_ H := 
       match type of H with
          (MInt_ _ ?z ?t) =>
          lazymatch goal with
            |- ?GOAL =>
            refine (match H in (MInt_ _ z0 t0) return (z = z0 -> t = t0 -> GOAL) with
                    | mint_nil    _  =>
                      fun Heq_z Heq_tt_ =>
                        ltac:(destruct_mint_common Heq_tt_ Heq_z H)
                    | mint_cons   _ te rest l      r   t H =>
                      fun Heq_z Heq_tt_ =>
                        ltac:(destruct_mint_common Heq_tt_ Heq_z H)
                    | mint_cons_l _ te rest l r z t Hz H  =>
                      fun Heq_z Heq_tt_ =>
                        ltac:(destruct_mint_common Heq_tt_ Heq_z H)
                    | mint_cons_r _ te te' rest l r z t Hz Hcomm H =>
                      fun Heq_z Heq_tt_ =>
                        ltac:(destruct_mint_common Heq_tt_ Heq_z H)
                    end (eq_refl z) (eq_refl t))
          end
        end.

    Наебавшись с inversion в механизированным доказательстве, закрыл я очи.

    CHayT, 04 Августа 2021

    Комментарии (23)
  11. JavaScript / Говнокод #27505

    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
    class Animal {
        move(distanceInMeters = 0) {
            print(`Animal moved ${distanceInMeters}m.`);
        }
    }
    
    function main() {
        const dog = new Animal();
        dog.move(10);
    
        const dog2 = Animal();
        dog2.move(11);
    }

    Загадка дня... кто знает что первый вызов конструктора отличается от второго?

    ASD_77, 07 Июля 2021

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