代码如下
reduceDigit :: Int -> Int
reduceDigit n
| n > 9 = reduceDigit $ sum $ map (read . (:[])) $ show n
| otherwise = n
isLuckyNumber :: Integer -> Char
isLuckyNumber n
| sum (zipWith transform [0..] (map (read . (:[])) $ show n)) `mod` 8 == 0 = 'T'
| otherwise = 'F'
where
transform :: Int -> Int -> Int
transform i x
| even i = x
| otherwise = reduceDigit (x * 7)
main :: IO ()
main = do
n <- readLn :: IO Int
sequence_ [ readLn >>= putStrLn . (:[]) . isLuckyNumber | _ <- [1..n] ]