Strange numbers: Difference between revisions
Content added Content deleted
Not a robot (talk | contribs) (Add Draco) |
Not a robot (talk | contribs) (Add Cowgol) |
||
Line 750: | Line 750: | ||
496 |
496 |
||
497</pre> |
497</pre> |
||
=={{header|Cowgol}}== |
|||
<lang cowgol>include "cowgol.coh"; |
|||
sub abs(n: int8): (r: uint8) is |
|||
if n<0 then n := -n; end if; |
|||
r := n as uint8; |
|||
end sub; |
|||
sub strange(n: uint16): (s: uint8) is |
|||
s := 1; |
|||
while n >= 10 loop |
|||
var da: int8 := (n % 10) as int8; |
|||
n := n / 10; |
|||
var db: int8 := (n % 10) as int8; |
|||
var diff := abs(da-db); |
|||
if diff!=2 and diff!=3 and diff!=5 and diff!=7 then |
|||
s := 0; |
|||
return; |
|||
end if; |
|||
end loop; |
|||
end sub; |
|||
var n: uint16 := 100; |
|||
var col: uint8 := 0; |
|||
while n <= 500 loop |
|||
if strange(n) != 0 then |
|||
print_i16(n); |
|||
print_char(' '); |
|||
col := col + 1; |
|||
if col == 10 then |
|||
print_nl(); |
|||
col := 0; |
|||
end if; |
|||
end if; |
|||
n := n + 1; |
|||
end loop; |
|||
print_nl();</lang> |
|||
{{out}} |
|||
<pre>130 131 135 136 138 141 142 146 147 149 |
|||
161 163 164 168 169 181 183 185 186 202 |
|||
203 205 207 241 242 246 247 249 250 252 |
|||
253 257 258 270 272 274 275 279 292 294 |
|||
296 297 302 303 305 307 313 314 316 318 |
|||
350 352 353 357 358 361 363 364 368 369 |
|||
381 383 385 386 413 414 416 418 420 424 |
|||
425 427 429 461 463 464 468 469 470 472 |
|||
474 475 479 492 494 496 497</pre> |
|||
=={{header|Draco}}== |
=={{header|Draco}}== |