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

    Всего: 51

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

    −21

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    if (i == k)
            return true;
        else if (i != k)
            return false;
        else
            return !true && !false;

    Abbath, 03 Апреля 2017

    Комментарии (27)
  3. Haskell / Говнокод #19670

    −48

    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
    {-# LANGUAGE FlexibleInstances #-}
    module Connect where 
    
    import Data.List
    
    data Color = Black | White deriving (Show, Eq)
    
    data Start = Begin | End deriving (Show, Eq)
    
    data Tree a = Node a [Tree a] deriving  (Eq)
    
    instance Show (Tree (Int,Int)) where
        show = showTree 0
    
    showTree :: Int -> Tree (Int,Int) -> String
    showTree n (Node a s) = show a ++ "\n" ++ replicate n ' ' ++ concatMap (showTree (n+1)) s
    
    elemTree :: Eq a => a -> Tree a -> Bool
    elemTree e (Node a []) = if a == e then True else False
    elemTree e (Node a s) = if a == e then True else any (e `elemTree`) s 
        
    resultFor :: [String] -> Maybe Color
    resultFor = check
    
    charToColor :: Char -> Color
    charToColor 'X' = Black
    charToColor 'O' = White
    charToColor _ = error "Bad data!"
    
    check :: [[Char]] -> Maybe Color
    check s = if (null iob || null ioe) && (null ixb || null ixe) 
                then Nothing
                else let whb = any (\t -> any (`elemTree` t) ioe) $ map (go White Begin s []) iob 
                         whe = any (\t -> any (`elemTree` t) iob) $ map (go White End s []) ioe
                         blb = any (\t -> any (`elemTree` t) ixe) $ map (go Black Begin s []) ixb
                         ble = any (\t -> any (`elemTree` t) ixb) $ map (go Black End s []) ixe
                     in if whb || whe then Just White else if blb || ble then Just Black else Nothing
        where 
            iob = map (\y -> (0,y)) $ elemIndices 'O' (s !! 0)
            ioe = map (\y -> (length s,y)) $ elemIndices 'O' (last s)
            ixb = map (\x -> (x,0)) $ elemIndices 'X' (map head s)
            ixe = map (\x -> (x,length (s!!0))) $ elemIndices 'X' (map last s)
    
    search :: Foldable t =>
              Color
              -> [[Char]] -> t (Int, Int) -> (Int, Int) -> Maybe [(Int, Int)]
    search color arr from (cx, cy) = (\x -> if null x then Nothing else Just x) $ map fst $ filter snd $ concatMap 
        (\x -> map 
            (\y -> testCell color arr from (cx, cy) (x,y)) 
            (filter (\yy -> yy >= 0 && yy < length (arr!!0)) [cy-1, cy, cy+1])) 
        (filter (\xx -> xx >= 0 && xx < length arr) [cx-1,cx,cx+1])
    
    testCell :: Foldable t =>
                Color
                -> [[Char]]
                -> t (Int, Int)
                -> (Int, Int)
                -> (Int, Int)
                -> ((Int, Int), Bool)
    testCell color arr from (cx, cy) (x,y)
        |x == cx && y == cy = ((x,y),False)
        |cx - x == 1 && cy - y == 1 = ((x,y),False)
        |x - cx == 1 && y - cy == 1 = ((x,y),False)
        |(x,y) `elem` from = ((x,y),False) 
        |arr !! x !! y /= '.' && color == charToColor (arr !! x !! y) = ((x,y),True)
        |otherwise = ((x,y),False) 
    
    go :: Color
          -> Start
          -> [[Char]]
          -> [(Int, Int)]
          -> (Int, Int)
          -> Tree (Int, Int)
    go c s arr from (x,y) 
        |(c,s) == (White, Begin) && x == length arr - 1 = Node (x,y) []
        |(c,s) == (White, End) && x == 0 = Node (x,y) []
        |(c,s) == (Black, Begin) && y == length (arr !! 0) -1 = Node (x,y) []
        |(c,s) == (Black, End) && y == 0 = Node (x,y) []
        |otherwise = let f = search c arr from (x,y)
                     in case f of 
                             Nothing -> Node (x,y) []
                             Just r -> Node (x,y) $ map (go c s arr ((x,y):from)) r

    Abbath, 22 Марта 2016

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

    −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
    type Speaker interface {
        SayHello()
    }
    
    type Human struct {
        Greeting string
    }
    
    func (Human) SayHello() {
        fmt.Println("Hello")
    }
    ...
    var s Speaker
    s = Human{Greeting: "Hello"}
    s.SayHello()

    Отсюда: https://habrahabr.ru/post/276981/

    Abbath, 10 Февраля 2016

    Комментарии (14)
  5. Куча / Говнокод #19107

    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
    breakPar :: (Token -> Bool) -> [Token] -> Either String ([Token], [Token])
    breakPar _ []           = Right ([], [])
    breakPar p [email protected](x:xs')
               | x == TLPar = let t = takePar xs'
                              in case t of
                                Left err -> t
                                Right r -> let tt = breakPar p b
                                               (a,b) = r
                                           in case tt of
                                                Left err -> t
                                                Right rr -> let (y, z) = rr
                                                            in Right ([x] ++ a ++ y, z)
               | p x        = Right ([],xs)
               | otherwise  = checkEither (breakPar p xs') (first ((:) x))

    Abbath, 30 Ноября 2015

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

    +5

    1. 1
    2. 2
    WCT воскрес.
    http://habrahabr.ru/post/271519/

    Abbath, 24 Ноября 2015

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

    +2

    1. 1
    2. 2
    3. 3
    4. 4
    l =: 3 :  'LF,~":<./(*/,*/"1)(i.2){(\:~,./:~)t=.}.".y rplc LF,'' -_'''
    
    l&.stdin ''
    exit ''

    Abbath, 29 Октября 2015

    Комментарии (33)
  8. C++ / Говнокод #18751

    +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
    long long int Factorial(long long int m_nValue)
       {
           long long int result=m_nValue;
           long long int result_next;
           long long int pc = m_nValue;
           do
           {
               result_next = result*(pc-1);
               result = result_next;
               pc--;
           }while(pc>2);
           m_nValue = result;
           return m_nValue;
       }

    http://rosettacode.org/wiki/Factorial#C.2B.2B

    Abbath, 22 Сентября 2015

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

    +143

    1. 1
    2. 2
    3. 3
    4. 4
    n =: 50000
    f =: 3 : '(a=0 2)*.1=(?2){x{~a=:?3'
    x =: 1 1 0 0 1 0 $~ n, 3 2
    t%+/t=:+/f"2 x

    Abbath, 05 Июня 2015

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

    +54

    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
    std::pair<long double, long double> Calculator::leastsquares(const QVector<double> &x, const QVector<double> &yy) const
    {
        QVector<double> y = yy;
        for (int i = 0; i < y.size(); ++i) {
            y[i] += 1.0;
        }
        long double A, B, a = 0, b = 0, at = 0, tt = 0, bt = 0, tmp = 0;
        for (int i = 0; i < x.size(); ++i) {
            tmp += x[i] * x[i] * y[i];
        }
        
        a = tmp;
        tmp = 0;
        
        for (int i = 0; i < x.size(); ++i) {
            tmp += y[i] * log(y[i]);
        }
        
        a *= tmp;
        tmp = 0;
        
        for (int i = 0; i < x.size(); ++i) {
            tmp += y[i] * x[i];
        }
        
        at = tmp;
        tmp = 0;
        
        for (int i = 0; i < x.size(); ++i) {
            tmp += y[i] * x[i] * log(y[i]);
        }
        
        at *= tmp;
        tmp = 0;
        
        a -= at;
        
        for (int i = 0; i < x.size(); ++i) {
            tmp += y[i];
        }
        
        at = tmp;
        tmp = 0;
        
        for (int i = 0; i < x.size(); ++i) {
            tmp += x[i] * x[i] * y[i];
        }
        
        tt = at * tmp;
        tmp = 0;
        
        for (int i = 0; i < x.size(); ++i) {
            tmp += x[i] * y[i];
        }
        
        tt -= tmp * tmp;
        tmp = 0;
        
        a /= tt;
        
        A = exp(a);
        
        for (int i = 0; i < x.size(); ++i) {
            tmp += y[i];
        }
        
        b = tmp;
        tmp = 0;
        
        for (int i = 0; i < x.size(); ++i) {
            tmp += x[i] * y[i] * log(y[i]);
        }
        
        b *= tmp;
        tmp = 0;
        
        for (int i = 0; i < x.size(); ++i) {
            tmp += y[i] * x[i];
        }
        
        bt = tmp;
        tmp = 0;
        
        for (int i = 0; i < x.size(); ++i) {
            tmp += y[i] * log(y[i]);
        }
        
        bt *= tmp;
        tmp = 0;
        
        b -= bt;
        
        b /= tt;
        
        B = b;
        
        return std::make_pair(A, B);
    }

    Abbath, 28 Марта 2015

    Комментарии (0)
  11. bash / Говнокод #17624

    −118

    1. 1
    . ldd

    Роняет bash

    Abbath, 11 Февраля 2015

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