- 1
- 2
- 3
- 4
- 5
- 6
if (i == k)
return true;
else if (i != k)
return false;
else
return !true && !false;
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
Всего: 51
−21
if (i == k)
return true;
else if (i != k)
return false;
else
return !true && !false;
−48
{-# 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
−2
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/
0
breakPar :: (Token -> Bool) -> [Token] -> Either String ([Token], [Token])
breakPar _ [] = Right ([], [])
breakPar p xs@(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))
+5
WCT воскрес.
http://habrahabr.ru/post/271519/
+2
l =: 3 : 'LF,~":<./(*/,*/"1)(i.2){(\:~,./:~)t=.}.".y rplc LF,'' -_'''
l&.stdin ''
exit ''
+4
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
+143
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
+54
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);
}
−118
. ldd
Роняет bash