Skip to main content
deleted 395 characters in body
Source Link
Donat
  • 1.5k
  • 7
  • 10

Haskell, 157 143 136 134134 132 bytes

f z=minimum[sum[1|7<-v]|v<-foldr((<*>).(:[(7:)]).(:))[[]]z,e[v!!x+ve[sum$(v!!).(x+d(4-d)+v!!*x+).(x+d+dd*)|d<<$>l|d<-[1,3],x<-map((4-d)*)[0l]]
l=[0..2]]]2]
e(x:z)=all(x==)z

Try it online!Try it online!

Takes a flat list of nine numbers.

Shortened by 11 bytes thanks to ovs (143 should have been 147).

Shortened additionally by 24 bytes (replaced first map and modified second).

Explanation

  
f z=minimum[sum[1|7<-v]|              -- count 7s for all solutions and take minimum
  v<-foldr((<*>).(:[(7:)]).(:))[[]]z, -- generate squares with all possible substitutions
  e                                   -- all sums must be equal
    [v!!x+v!!(x+d)+v!!(x+d+d)|[sum$                             -- compute sums of rows and columns
      d<-[1,3],x<-map(v!!).((4-d)**x+).(d*)<$>l|      -- transform [0..2]]]2] to index list and apply to v
        d<-[1,3],x<-l]] make coordiantes             -- parameters for rowsindex andlists
l=[0..2] columns                             -- abbreviation, used in two places
e(x:z)=all(x==)z                      -- check whether all numbers in list are equal

Haskell, 157 143 136 134 bytes

f z=minimum[sum[1|7<-v]|v<-foldr((<*>).(:[(7:)]).(:))[[]]z,e[v!!x+v!!(x+d)+v!!(x+d+d)|d<-[1,3],x<-map((4-d)*)[0..2]]]
e(x:z)=all(x==)z

Try it online!

Takes a flat list of nine numbers.

Shortened by 11 bytes thanks to ovs (143 should have been 147).

Shortened additionally by 2 bytes (replaced first map and modified second).

Explanation

 
f z=minimum[sum[1|7<-v]|              -- count 7s for all solutions and take minimum
  v<-foldr((<*>).(:[(7:)]).(:))[[]]z, -- generate squares with all possible substitutions
  e                                   -- all sums must be equal
    [v!!x+v!!(x+d)+v!!(x+d+d)|        -- compute sums of rows and columns
      d<-[1,3],x<-map((4-d)*)[0..2]]] -- make coordiantes for rows and columns
e(x:z)=all(x==)z                      -- check whether all numbers in list are equal

Haskell, 157 143 136 134 132 bytes

f z=minimum[sum[1|7<-v]|v<-foldr((<*>).(:[(7:)]).(:))[[]]z,e[sum$(v!!).((4-d)*x+).(d*)<$>l|d<-[1,3],x<-l]]
l=[0..2]
e(x:z)=all(x==)z

Try it online!

Takes a flat list of nine numbers.

Shortened by 11 bytes thanks to ovs (143 should have been 147).

Shortened additionally by 4 bytes.

Explanation

 
f z=minimum[sum[1|7<-v]|              -- count 7s for all solutions and take minimum
  v<-foldr((<*>).(:[(7:)]).(:))[[]]z, -- generate squares with all possible substitutions
  e                                   -- all sums must be equal
    [sum$                             -- compute sums of rows and columns
      (v!!).((4-d)*x+).(d*)<$>l|      -- transform [0..2] to index list and apply to v
        d<-[1,3],x<-l]]               -- parameters for index lists
l=[0..2]                              -- abbreviation, used in two places
e(x:z)=all(x==)z                      -- check whether all numbers in list are equal
Rollback to Revision 11
Source Link
Donat
  • 1.5k
  • 7
  • 10

Haskell, 157 143 136 134 132134 bytes

f z=minimum[sum[1|7<-v]|v<-foldr((<*>).(:[(7:)]).(:))[[]]z,e[v!!(x-d)+v!!d+vx+v!!(x+d)|+v!!(d,xx+d+d)<|d<-zip[1,3,3[1,33],1]$9:[3x<-map((4-d)*)[0..]]]2]]]
e(x:z)=all(x==)z

Try it online!Try it online!

Takes a flat list of nine numbers.

Shortened by 11 bytes thanks to ovs (143 should have been 147).

Shortened additionally by 2 + 2 bytes (replaced first map and modified second).

Explanation

f z=minimum[sum[1|7<-v]|              -- count 7s for all solutions and take minimum
  v<-foldr((<*>).(:[(7:)]).(:))[[]]z, -- generate squares with all possible substitutions
  e                                   -- all sums must be equal
    [v!!x+v!!(x-dx+d)+v!!d+v!!(x+dx+d+d)|          -- compute sums of rows and columns
      (d,x)<d<-zip[1,3,3[1,33],1]$9:[3x<-map((4-d)*)[0..]]]2]]] -- make coordiante parameterscoordiantes for rows and columns
e(x:z)=all(x==)z                      -- check whether all numbers in list are equal

Haskell, 157 143 136 134 132 bytes

f z=minimum[sum[1|7<-v]|v<-foldr((<*>).(:[(7:)]).(:))[[]]z,e[v!!(x-d)+v!!d+v!!(x+d)|(d,x)<-zip[1,3,3,3,1]$9:[3..]]]
e(x:z)=all(x==)z

Try it online!

Takes a flat list of nine numbers.

Shortened by 11 bytes thanks to ovs (143 should have been 147).

Shortened additionally by 2 + 2 bytes.

Explanation

f z=minimum[sum[1|7<-v]|              -- count 7s for all solutions and take minimum
  v<-foldr((<*>).(:[(7:)]).(:))[[]]z, -- generate squares with all possible substitutions
  e                                   -- all sums must be equal
    [v!!(x-d)+v!!d+v!!(x+d)|          -- compute sums of rows and columns
      (d,x)<-zip[1,3,3,3,1]$9:[3..]]] -- make coordiante parameters for rows and columns
e(x:z)=all(x==)z                      -- check whether all numbers in list are equal

Haskell, 157 143 136 134 bytes

f z=minimum[sum[1|7<-v]|v<-foldr((<*>).(:[(7:)]).(:))[[]]z,e[v!!x+v!!(x+d)+v!!(x+d+d)|d<-[1,3],x<-map((4-d)*)[0..2]]]
e(x:z)=all(x==)z

Try it online!

Takes a flat list of nine numbers.

Shortened by 11 bytes thanks to ovs (143 should have been 147).

Shortened additionally by 2 bytes (replaced first map and modified second).

Explanation

f z=minimum[sum[1|7<-v]|              -- count 7s for all solutions and take minimum
  v<-foldr((<*>).(:[(7:)]).(:))[[]]z, -- generate squares with all possible substitutions
  e                                   -- all sums must be equal
    [v!!x+v!!(x+d)+v!!(x+d+d)|        -- compute sums of rows and columns
      d<-[1,3],x<-map((4-d)*)[0..2]]] -- make coordiantes for rows and columns
e(x:z)=all(x==)z                      -- check whether all numbers in list are equal
added 11 characters in body
Source Link
Donat
  • 1.5k
  • 7
  • 10

Haskell, 157 143 136 134134 132 bytes

f z=minimum[sum[1|7<-v]|v<-foldr((<*>).(:[(7:)]).(:))[[]]z,e[v!!x+v!!(x+dx-d)+v!!d+v!!(x+d+dx+d)|d<-[1,3],x<-map(|(4-d)*,x)[0<-zip[1,3,3,3,1]$9:[3..2]]]]]]
e(x:z)=all(x==)z

Try it online!Try it online!

Takes a flat list of nine numbers.

Shortened by 11 bytes thanks to ovs (143 should have been 147).

Shortened additionally by 2 + 2 bytes (replaced first map and modified second).

Explanation

f z=minimum[sum[1|7<-v]|              -- count 7s for all solutions and take minimum
  v<-foldr((<*>).(:[(7:)]).(:))[[]]z, -- generate squares with all possible substitutions
  e                                   -- all sums must be equal
    [v!!x+v!!(x+dx-d)+v!!d+v!!(x+d+dx+d)|          -- compute sums of rows and columns
      d<-[1,3],x<-map((4-d)*,x)[0<-zip[1,3,3,3,1]$9:[3..2]]]]]] -- make coordiantescoordiante parameters for rows and columns
e(x:z)=all(x==)z                      -- check whether all numbers in list are equal

Haskell, 157 143 136 134 bytes

f z=minimum[sum[1|7<-v]|v<-foldr((<*>).(:[(7:)]).(:))[[]]z,e[v!!x+v!!(x+d)+v!!(x+d+d)|d<-[1,3],x<-map((4-d)*)[0..2]]]
e(x:z)=all(x==)z

Try it online!

Takes a flat list of nine numbers.

Shortened by 11 bytes thanks to ovs (143 should have been 147).

Shortened additionally by 2 bytes (replaced first map and modified second).

Explanation

f z=minimum[sum[1|7<-v]|              -- count 7s for all solutions and take minimum
  v<-foldr((<*>).(:[(7:)]).(:))[[]]z, -- generate squares with all possible substitutions
  e                                   -- all sums must be equal
    [v!!x+v!!(x+d)+v!!(x+d+d)|        -- compute sums of rows and columns
      d<-[1,3],x<-map((4-d)*)[0..2]]] -- make coordiantes for rows and columns
e(x:z)=all(x==)z                      -- check whether all numbers in list are equal

Haskell, 157 143 136 134 132 bytes

f z=minimum[sum[1|7<-v]|v<-foldr((<*>).(:[(7:)]).(:))[[]]z,e[v!!(x-d)+v!!d+v!!(x+d)|(d,x)<-zip[1,3,3,3,1]$9:[3..]]]
e(x:z)=all(x==)z

Try it online!

Takes a flat list of nine numbers.

Shortened by 11 bytes thanks to ovs (143 should have been 147).

Shortened additionally by 2 + 2 bytes.

Explanation

f z=minimum[sum[1|7<-v]|              -- count 7s for all solutions and take minimum
  v<-foldr((<*>).(:[(7:)]).(:))[[]]z, -- generate squares with all possible substitutions
  e                                   -- all sums must be equal
    [v!!(x-d)+v!!d+v!!(x+d)|          -- compute sums of rows and columns
      (d,x)<-zip[1,3,3,3,1]$9:[3..]]] -- make coordiante parameters for rows and columns
e(x:z)=all(x==)z                      -- check whether all numbers in list are equal
added 54 characters in body
Source Link
Donat
  • 1.5k
  • 7
  • 10
Loading
added 4 characters in body
Source Link
Donat
  • 1.5k
  • 7
  • 10
Loading
deleted 3 characters in body
Source Link
Donat
  • 1.5k
  • 7
  • 10
Loading
deleted 3 characters in body
Source Link
Donat
  • 1.5k
  • 7
  • 10
Loading
added 28 characters in body
Source Link
Donat
  • 1.5k
  • 7
  • 10
Loading
added 399 characters in body
Source Link
Donat
  • 1.5k
  • 7
  • 10
Loading
added 6 characters in body
Source Link
Donat
  • 1.5k
  • 7
  • 10
Loading
Shortened by 14 bytes.
Source Link
Donat
  • 1.5k
  • 7
  • 10
Loading
added 596 characters in body
Source Link
Donat
  • 1.5k
  • 7
  • 10
Loading
added 5 characters in body
Source Link
Donat
  • 1.5k
  • 7
  • 10
Loading
Source Link
Donat
  • 1.5k
  • 7
  • 10
Loading