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

    Всего: 2

  2. C++ / Говнокод #28280

    −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
    #include <iostream>
    
    // Truthiness
    struct true_type{static const bool value = true;};
    struct false_type{ static const bool value = false;};
    
    // Pick type based on bool value
    template <bool B, typename T, typename U>struct conditional{typedef T type;};
    template <typename T, typename U>struct conditional<false, T, U>{typedef U type;};
    
    // Compare two types
    template <typename T, typename U>struct is_same : public false_type{};
    template <typename T>struct is_same<T, T> : public true_type{};
    
    // Division predicate
    template <int a, int b>struct divides{static const bool value = (a % b == 0);};
    
    // Type traits
    template <typename T, int N = 0>
    struct fizzbuzz_traits{
    	typedef T type;
    	static const  int value = N;
    };
    
    template <> struct fizzbuzz_traits<char*, 0>{typedef char* type;};
    
    // fizzbuzz type initializers
    template <bool A, bool B> struct fizzbuzz{};
    
    template <> struct fizzbuzz<true, false> : public fizzbuzz_traits<char*> {static const char* value;};
    typedef fizzbuzz<true, false> fizz_type;
    const char* fizz_type::value = "fizz";      // static const char* can only be initialized out of line
    
    template <> struct fizzbuzz<true, true> : public fizzbuzz_traits<char*> {static const char* value;};
    typedef fizzbuzz<true, true> fizzbuzz_type;
    const char *fizzbuzz_type::value = "fizzbuzz"; 
    
    template <> struct fizzbuzz<false, true> : public fizzbuzz_traits<char*> {static const char* value;};
    typedef fizzbuzz<false, true> buzz_type;
    const char *buzz_type::value = "buzz";
    
    template <> struct fizzbuzz<false, false> : fizzbuzz_traits<void>{};
    
    
    // FizzBuzz solver
    template <int N>
    class FizzBuzz{
    private:
    	struct is_divisible : public true_type{
        
    		struct by3 : public divides<N, 3>{};
    		struct by5 : public divides<N, 5>{};
    	};
    public:
    	typedef fizzbuzz< is_divisible::by3::value, is_divisible::by5::value > solution_type; 
    	// stores string or 'false'
    	
    	typedef fizzbuzz_traits<int, N> non_divisible_type; 
    	// stores number
      
    	typedef typename conditional< !is_same<void, typename solution_type::type>::value,
    		solution_type, 
    		non_divisible_type>::type print_type;
    	// stores value to print
    };
    
    
    // Looping from N to M
    template <int N, int M>
    struct static_for{
    	static void value(){
    	std::cout << FizzBuzz<N>::print_type::value << std::endl;
    	static_for<N + 1, M>::value();
    	}
    };
    
    template <>
    struct static_for<101, 100>
    {
    	static void value(){};
    };
    
    int main(){
    	static_for<1, 100>::value();
    }

    Физзбазз на шаблонах без type_traits

    valo94, 17 Июля 2022

    Комментарии (39)
  3. Python / Говнокод #28164

    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
    import asyncio
    
    async def hello():
        return "hello"
    
    async def world():
        return "world"
    
    async def comma():
        return ","
    
    async def space():
        return " "
    
    async def excl():
        return "!"
    
    async def capitalize(coro):
        return (await coro).capitalize()
    
    async def main():
        print(''.join(await asyncio.gather(*[asyncio.create_task(task) for task in (capitalize(hello()), comma(), space(), capitalize(world()), excl())])))
    
    asyncio.run(main())

    Изучаем asyncio через говнокод

    valo94, 12 Мая 2022

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