Anonymous user
Magic squares of doubly even order: Difference between revisions
Magic squares of doubly even order (view source)
Revision as of 10:46, 14 January 2018
, 6 years agoCorrected my existing code
(Added Go implementation) |
(Corrected my existing code) |
||
Line 898:
)
const
func
var output [][]int
return [][]int{}, fmt.Errorf("Square
for j := 0; j < width; j++ {▼
}▼
output = append(output, row)▼
output = append(output, array[len(array)-lastRowLen:])▼
▲ if width < 4 || width%4 != 0 {
▲ return []int{}, fmt.Errorf("Square width must be a positive number which is divisible by 4")
}
var bits uint = 0x9669 // 0b1001011001101001
for c := 0; c < d; i, c = i+1, c+1 {
} else {▼
bitPos := c/mult + (r/mult)*4
if (bits & (1 << uint(bitPos))) != 0 {
▲ } else {
▲ }
}
}
Line 942 ⟶ 931:
func main() {
data, err := setupMagicSquareData(
if err != nil {
log.Fatal(err)
}
▲ magicConstant := (squareWidth * (squareWidth*squareWidth + 1)) / 2
▲ for _, row := range rows {
fmt.Println(strings.Join(arrayItoa(row), " "))
}
fmt.Printf("\nMagic Constant: %d\n", magicConstant)
}
</lang>
Line 958 ⟶ 945:
<pre> 1 2 62 61 60 59 7 8
9 10 54 53 52 51 15 16
49 50 14 13 12 11 55 56
57 58 6 5 4 3 63 64
Magic Constant: 260
</pre>
=={{header|Haskell}}==
|