Skip to main content
replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link

Haskell, 102 100 96 91 87 bytes

c s=unlines.f$f.(#)where f=(<$>[1..s]);x#y|elem y[1,s,x]||elem x[1,s,s-y+1]='*'|1>0=' '
  • Saved 2 bytes, thanks to flawrflawr.
  • Saved 4 more bytes by using list comprehensions.
  • 5 bytes saved combining flawrflawr's improvement with any
  • 4 bytes saved by replacing any with elem

Ungolfed version:

cross :: Int -> String
cross s = unlines $ map line [1..s]
    where line y = map (pos y) [1..s]
          pos y x | x == y = '*'
                  | x == s - y + 1 = '*'
                  | y `elem` [1, s] = '*'
                  | x `elem` [1, s] = '*'
                  | otherwise = ' '

I'm sure this can still be improved, but this is what I've come up with for now.

Old version:

c s=unlines.f$f.(#)where f=(<$>[1..s]);x#y|any(==y)[1,s,x]||any(==x)[1,s,s-y+1]='*'|1>0=' '

Haskell, 102 100 96 91 87 bytes

c s=unlines.f$f.(#)where f=(<$>[1..s]);x#y|elem y[1,s,x]||elem x[1,s,s-y+1]='*'|1>0=' '
  • Saved 2 bytes, thanks to flawr.
  • Saved 4 more bytes by using list comprehensions.
  • 5 bytes saved combining flawr's improvement with any
  • 4 bytes saved by replacing any with elem

Ungolfed version:

cross :: Int -> String
cross s = unlines $ map line [1..s]
    where line y = map (pos y) [1..s]
          pos y x | x == y = '*'
                  | x == s - y + 1 = '*'
                  | y `elem` [1, s] = '*'
                  | x `elem` [1, s] = '*'
                  | otherwise = ' '

I'm sure this can still be improved, but this is what I've come up with for now.

Old version:

c s=unlines.f$f.(#)where f=(<$>[1..s]);x#y|any(==y)[1,s,x]||any(==x)[1,s,s-y+1]='*'|1>0=' '

Haskell, 102 100 96 91 87 bytes

c s=unlines.f$f.(#)where f=(<$>[1..s]);x#y|elem y[1,s,x]||elem x[1,s,s-y+1]='*'|1>0=' '
  • Saved 2 bytes, thanks to flawr.
  • Saved 4 more bytes by using list comprehensions.
  • 5 bytes saved combining flawr's improvement with any
  • 4 bytes saved by replacing any with elem

Ungolfed version:

cross :: Int -> String
cross s = unlines $ map line [1..s]
    where line y = map (pos y) [1..s]
          pos y x | x == y = '*'
                  | x == s - y + 1 = '*'
                  | y `elem` [1, s] = '*'
                  | x `elem` [1, s] = '*'
                  | otherwise = ' '

I'm sure this can still be improved, but this is what I've come up with for now.

Old version:

c s=unlines.f$f.(#)where f=(<$>[1..s]);x#y|any(==y)[1,s,x]||any(==x)[1,s,s-y+1]='*'|1>0=' '
Replace any with elem
Source Link
sudee
  • 581
  • 3
  • 7

Haskell, 102 100 96 9191 87 bytes

c s=unlines.f$f.(#)where f=(<$>[1..s]);x#y|any(==y)[1;x#y|elem y[1,s,x]||any(==x)[1x]||elem x[1,s,s-y+1]='*'|1>0=' '
  • Saved 2 bytes, thanks to flawr.
  • Saved 4 more bytes by using list comprehensions.
  • 5 bytes saved combining flawr's improvement with any
  • 4 bytes saved by replacing any with elem

Ungolfed version:

cross :: Int -> String
cross s = unlines $ map line [1..s]
    where line y = map (pos y) [1..s]
          pos y x | x == y = '*'
                  | x == s - y + 1 = '*'
                  | y `elem` [1, s] = '*'
                  | x `elem` [1, s] = '*'
                  | otherwise = ' '

I'm sure this can still be improved, but this is what I've come up with for now.

Old version:

c s=unlines[s=unlines.f$f.(#y#)<$>l|letwhere x#y|anyf=(<$>[1..s]);x#y|any(==y)[1,s,x]||any(==x)[1,s,s-y+1]='*'|1>0=' ';l=[1..s],y<-l]'

Haskell, 102 100 96 91 bytes

c s=unlines.f$f.(#)where f=(<$>[1..s]);x#y|any(==y)[1,s,x]||any(==x)[1,s,s-y+1]='*'|1>0=' '
  • Saved 2 bytes, thanks to flawr.
  • Saved 4 more bytes by using list comprehensions.
  • 5 bytes saved combining flawr's improvement with any

Ungolfed version:

cross :: Int -> String
cross s = unlines $ map line [1..s]
    where line y = map (pos y) [1..s]
          pos y x | x == y = '*'
                  | x == s - y + 1 = '*'
                  | y `elem` [1, s] = '*'
                  | x `elem` [1, s] = '*'
                  | otherwise = ' '

I'm sure this can still be improved, but this is what I've come up with for now.

Old version:

c s=unlines[(#y)<$>l|let x#y|any(==y)[1,s,x]||any(==x)[1,s,s-y+1]='*'|1>0=' ';l=[1..s],y<-l]

Haskell, 102 100 96 91 87 bytes

c s=unlines.f$f.(#)where f=(<$>[1..s]);x#y|elem y[1,s,x]||elem x[1,s,s-y+1]='*'|1>0=' '
  • Saved 2 bytes, thanks to flawr.
  • Saved 4 more bytes by using list comprehensions.
  • 5 bytes saved combining flawr's improvement with any
  • 4 bytes saved by replacing any with elem

Ungolfed version:

cross :: Int -> String
cross s = unlines $ map line [1..s]
    where line y = map (pos y) [1..s]
          pos y x | x == y = '*'
                  | x == s - y + 1 = '*'
                  | y `elem` [1, s] = '*'
                  | x `elem` [1, s] = '*'
                  | otherwise = ' '

I'm sure this can still be improved, but this is what I've come up with for now.

Old version:

c s=unlines.f$f.(#)where f=(<$>[1..s]);x#y|any(==y)[1,s,x]||any(==x)[1,s,s-y+1]='*'|1>0=' '
Bye list comprehension, hello any :)
Source Link
sudee
  • 581
  • 3
  • 7

Haskell, 102 100 9696 91 bytes

c s=unlines[s=unlines.f$f.(#y#)<$>l|letwhere x#y|orf=(<$>[1..s]);x#y|any(====y)<$>[x[1,y]<*>[1s,s]x]||any(==x)||x==y||x==s-y+1='*'|1>0=' ';l=[1..s][1,y<s,s-l]y+1]='*'|1>0=' '
  • Saved 2 bytes, thanks to flawr.
  • Saved 4 more bytes by using list comprehensions.
  • 5 bytes saved combining flawr's improvement with any

Ungolfed version:

cross :: Int -> String
cross s = unlines $ map line [1..s]
    where line my = map (pos my) [1..s]
          pos my nx | nx == my = '*'
                  | nx == s - my + 1 = '*'
                  | elemy m`elem` [1, s] = '*'
                  | elemx n`elem` [1, s] = '*'
                  | otherwise = ' '

I'm sure this can still be improved, but this is what I've come up with for now.

Old version:

c s=unlines$f(\m->fs=unlines[(m#)#y)where<$>l|let f=x#y|any(<$>[1..s]==y);m#n|or([1,s,x]||any(====x)<$>[n[1,m]<*>[1s,s])||n==m||n==ss-m+1='*'|1>0='y+1]='*'|1>0=' '';l=[1..s],y<-l]

I'm sure this can still be improved, but this is what I've come up with for now.

Haskell, 102 100 96 bytes

c s=unlines[(#y)<$>l|let x#y|or((==)<$>[x,y]<*>[1,s])||x==y||x==s-y+1='*'|1>0=' ';l=[1..s],y<-l]
  • Saved 2 bytes, thanks to flawr.
  • Saved 4 more bytes by using list comprehensions.

Ungolfed version:

cross :: Int -> String
cross s = unlines $ map line [1..s]
    where line m = map (pos m) [1..s]
          pos m n | n == m = '*'
                  | n == s - m + 1 = '*'
                  | elem m [1, s] = '*'
                  | elem n [1, s] = '*'
                  | otherwise = ' '

Old version:

c s=unlines$f(\m->f(m#))where f=(<$>[1..s]);m#n|or((==)<$>[n,m]<*>[1,s])||n==m||n==s-m+1='*'|1>0=' '

I'm sure this can still be improved, but this is what I've come up with for now.

Haskell, 102 100 96 91 bytes

c s=unlines.f$f.(#)where f=(<$>[1..s]);x#y|any(==y)[1,s,x]||any(==x)[1,s,s-y+1]='*'|1>0=' '
  • Saved 2 bytes, thanks to flawr.
  • Saved 4 more bytes by using list comprehensions.
  • 5 bytes saved combining flawr's improvement with any

Ungolfed version:

cross :: Int -> String
cross s = unlines $ map line [1..s]
    where line y = map (pos y) [1..s]
          pos y x | x == y = '*'
                  | x == s - y + 1 = '*'
                  | y `elem` [1, s] = '*'
                  | x `elem` [1, s] = '*'
                  | otherwise = ' '

I'm sure this can still be improved, but this is what I've come up with for now.

Old version:

c s=unlines[(#y)<$>l|let x#y|any(==y)[1,s,x]||any(==x)[1,s,s-y+1]='*'|1>0=' ';l=[1..s],y<-l]
List comprehensions to the rescue.
Source Link
sudee
  • 581
  • 3
  • 7
Loading
Giving credit where it's due.
Source Link
sudee
  • 581
  • 3
  • 7
Loading
Source Link
sudee
  • 581
  • 3
  • 7
Loading