fork download
  1. import Data.List
  2.  
  3. reps m n = reverse [concat $ replicate m (show i) | i <- [1..n]]
  4.  
  5. res n = last $ take ((n-2)^2 + 1) $ iterate next (a0, b0) where
  6. a = concat $ [show $ n-1] ++ (reps (n-1) (n-1))
  7. a0 = concat $ reps 2 (n-1)
  8. b0 = a \\ a0
  9.  
  10. next (as, bs) = (as', bs') where
  11. as' = as ++ [b]
  12. bs' = bs \\ [b]
  13. b = findB as bs
  14.  
  15. findB as bs = b where
  16. b = if (ab `elem` digits) then (findB as (tail bs')) else (head bs')
  17. digits = zipWith (\x y -> [x] ++ [y]) (init as) (tail as)
  18. ab = [a] ++ [head bs']
  19. a = last as
  20. bs' = sort $ nub bs
  21.  
  22. answer n = inits ++ tens ++ "0" where -- n進数での解
  23. inits = fst $ res n
  24. tens = tail . concat . map show . concat $ zipWith (\x y -> [x] ++ [y]) [n-1,n-2..1] [0,0..]
  25.  
  26. main = print $ answer 10
Success #stdin #stdout 0s 4616KB
stdin
Standard input is empty
stdout
"9988776655443322112313414245152535616263646717273747578182838485868919293949596979080706050403020100"