Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-rosetta/blob/main/drafts/rosettacode/magic-squares-of-odd-order.wiki # omega-rosetta aien-dev/omega-rosetta Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-rosetta / drafts / rosettacode / magic-squares-of-odd-order.wiki` 122 lines ยท 2425 bytes Raw Blame History 1 =={{header|Omegese}}== 2 {{works with|omc|sha256 `2c824805`, aien-dev/omega-mv `e5b32567`, Linux AArch64}} 3 Omega has no imports, so the small output helpers (emit and friends) are part of the program. 4 5 om2 6 text nl "\n" 7 text sp " " 8 text minus "-" 9 text tconst "magic constant: " 10 global grid ulong 81 11 note emit writes every byte of a to stdout; a short write is retried, an error exits 1 12 fn emit a view uchar * to void 13 o = ulong 0 14 while lt o len a bound 4096 15 k = write 1 a o sub len a o 16 if le k 0 17 exit 1 18 end 19 o = add o ulong k 20 end 21 end 22 note emitu writes n in decimal; 20 digits hold every ulong 23 fn emitu n ulong to void 24 d = new uchar 20 0 25 i = ulong 20 26 v = n 27 while true bound 20 28 i = sub i 1 29 put d i uchar add rem v 10 48 30 v = div v 10 31 if eq v 0 32 break 33 end 34 end 35 emit part d i sub 20 i 36 end 37 note emitw writes n right-aligned in w columns (w at most 20; a wider number is not cut) 38 fn emitw n ulong w ulong to void 39 d = new uchar 20 32 40 i = ulong 20 41 v = n 42 while true bound 20 43 i = sub i 1 44 put d i uchar add rem v 10 48 45 v = div v 10 46 if eq v 0 47 break 48 end 49 end 50 if gt w sub 20 i 51 i = sub 20 w 52 end 53 emit part d i sub 20 i 54 end 55 note the Siamese method: 1 goes in the middle of the top row; each next number goes one up and one 56 note right (wrapping round), or straight down when that cell is taken, which happens every n numbers 57 fn siamese n ulong to void 58 for i ulong mul n n 59 put grid i 0 60 end 61 r = ulong 0 62 c = div n 2 63 for k ulong mul n n 64 put grid add mul r n c add k 1 65 ur = rem sub add r n 1 n 66 uc = rem add c 1 n 67 if eq get grid add mul ur n uc 0 68 r = ur 69 c = uc 70 else 71 r = rem add r 1 n 72 end 73 end 74 end 75 fn show n ulong to void 76 for i ulong n 77 for j ulong n 78 emitw get grid add mul i n j 4 79 end 80 emit nl 81 end 82 emit tconst 83 emitu div mul n add mul n n 1 2 84 emit nl 85 end 86 fn main to int 87 siamese 3 88 show 3 89 emit nl 90 siamese 5 91 show 5 92 emit nl 93 siamese 9 94 show 9 95 ret 0 96 end 97 98 {{out}} 99

100 8 1 6

101 3 5 7

102 4 9 2

103 magic constant: 15

104

105 17 24 1 8 15

106 23 5 7 14 16

107 4 6 13 20 22

108 10 12 19 21 3

109 11 18 25 2 9

110 magic constant: 65

111

112 47 58 69 80 1 12 23 34 45

113 57 68 79 9 11 22 33 44 46

114 67 78 8 10 21 32 43 54 56

115 77 7 18 20 31 42 53 55 66

116 6 17 19 30 41 52 63 65 76

117 16 27 29 40 51 62 64 75 5

118 26 28 39 50 61 72 74 4 15

119 36 38 49 60 71 73 3 14 25

120 37 48 59 70 81 2 13 24 35

121 magic constant: 369

122