CSES - Datatähti 2020 alku - Results
Submission details
Task:Ruudukko
Sender:PauliK
Submission time:2019-10-01 20:58:36 +0300
Language:Haskell
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED100
Test results
testverdicttime
#1ACCEPTED0.01 sdetails
#2ACCEPTED0.01 sdetails
#3ACCEPTED0.01 sdetails
#4ACCEPTED0.01 sdetails
#5ACCEPTED0.05 sdetails
#6ACCEPTED0.05 sdetails

Compiler report

input/code.hs:7:1: warning: [-Wmissing-signatures]
    Top-level binding with no type signature:
      splitToPairs :: Int -> [t] -> [[t]]

input/code.hs:9:1: warning: [-Wtabs]
    Tab character found here, and in 9 further locations.
    Please use spaces instead.

input/code.hs:12:1: warning: [-Wmissing-signatures]
    Top-level binding with no type signature:
      doRow :: Int -> [a] -> [a]

input/code.hs:14:1: warning: [-Wunused-top-binds]
    Defined but not used: `make4x4From'

input/code.hs:14:1: warning: [-Wmissing-signatures]
    Top-level binding with no type signature:
      make4x4From :: (Enum t, Num t) => t -> [[t]]

input/code.hs:21:1: warning: [-Wunused-top-binds]
    Defined but not used: `horizCat'

input/code.hs:21:1: warning: [-Wmissing-signatures]
    Top-level binding with no type signature:
      horizCat :: [[a]] -> [[a]] -> [[a]]

input/code.hs:22:1: warning: [-Wunused-top-binds]
    Defined but not used: `vertCat'

input/code.hs:22:1: warning: [-Wmissing-sig...

Code

import Data.Function
import Data.List
import Data.Monoid
import Data.Foldable
import Data.Bits

splitToPairs _ [] = []
splitToPairs n xs = pair : splitToPairs n rest
	where
	(pair, rest) = splitAt n xs

doRow n xs = splitToPairs n xs & map reverse & concat

make4x4From n =
	let a = [n .. n + 3] in
	let b = doRow 2 a in
	let c = doRow 4 b in
	let d = doRow 2 c in
	[a, b, c, d]

horizCat = zipWith (++)
vertCat xs ys = horizCat (transpose xs) (transpose ys) & transpose

doRows xs = fold ((Endo . doRow) <$> xs) & appEndo

nthInSeq n = -(-n `xor` n)

-- OEIS A171977
theSequence :: Int -> [Int]
theSequence n = [1..n] & map nthInSeq

rowFuncs n = theSequence (n - 1) & inits & map doRows

makeGrid n = rowFuncs n & map ($ [1..n])

trimGrid n xs = xs & map (take n) & take n

printGridLn xs = xs & map show & intercalate " " & putStrLn

printGrid xs = xs & map printGridLn & sequence_

main = do
	n <- readLn :: IO Int
	makeGrid 128 & trimGrid n & printGrid
	-- makeGrid 128 & trimGrid n & concat & sum & print

Test details

Test 1

Verdict: ACCEPTED

input
1

correct output

user output
1

Test 2

Verdict: ACCEPTED

input
2

correct output
1 2 
2 1 

user output
1 2
2 1

Test 3

Verdict: ACCEPTED

input
5

correct output
1 2 3 4 5 
2 1 4 3 6 
3 4 1 2 7 
4 3 2 1 8 
5 6 7 8 1 

user output
1 2 3 4 5
2 1 4 3 6
3 4 1 2 7
4 3 2 1 8
5 6 7 8 1

Test 4

Verdict: ACCEPTED

input
42

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...
Truncated

Test 5

Verdict: ACCEPTED

input
99

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...
Truncated

Test 6

Verdict: ACCEPTED

input
100

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...
Truncated