omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / train / omega-llm / tools / bench / tasks.om
| 1 | note SPDX-License-Identifier: AGPL-3.0-only |
| 2 | note tasks.om: the tasks of the Omega coding benchmark (bench.om reads this file; it is also Omega |
| 3 | note source, so every reference is compiled). One behaviour per task: `bench check` fails when two |
| 4 | note tasks of a shape agree on every shared input. Frozen: a change here changes expect.txt, and a |
| 5 | note score is only comparable with scores from the same two files. |
| 6 | note The shared inputs stay below 2^41 so that sums and the products asked for do not wrap except |
| 7 | note where a task multiplies large values, which wraps the same way in every implementation. |
| 8 | |
| 9 | note in1 0 |
| 10 | note in1 1 |
| 11 | note in1 2 |
| 12 | note in1 3 |
| 13 | note in1 4 |
| 14 | note in1 5 |
| 15 | note in1 6 |
| 16 | note in1 7 |
| 17 | note in1 8 |
| 18 | note in1 9 |
| 19 | note in1 10 |
| 20 | note in1 11 |
| 21 | note in1 12 |
| 22 | note in1 15 |
| 23 | note in1 16 |
| 24 | note in1 17 |
| 25 | note in1 20 |
| 26 | note in1 25 |
| 27 | note in1 31 |
| 28 | note in1 32 |
| 29 | note in1 36 |
| 30 | note in1 49 |
| 31 | note in1 64 |
| 32 | note in1 97 |
| 33 | note in1 100 |
| 34 | note in1 121 |
| 35 | note in1 127 |
| 36 | note in1 128 |
| 37 | note in1 255 |
| 38 | note in1 256 |
| 39 | note in1 360 |
| 40 | note in1 1000 |
| 41 | note in1 1023 |
| 42 | note in1 1024 |
| 43 | note in1 4096 |
| 44 | note in1 12321 |
| 45 | note in1 65535 |
| 46 | note in1 65536 |
| 47 | note in1 99999 |
| 48 | note in1 1000000 |
| 49 | note in1 123456789 |
| 50 | note in1 4294967295 |
| 51 | note in1 4294967296 |
| 52 | note in1 1000000000000 |
| 53 | |
| 54 | note in2 0 0 |
| 55 | note in2 1 0 |
| 56 | note in2 0 1 |
| 57 | note in2 1 1 |
| 58 | note in2 1 2 |
| 59 | note in2 2 1 |
| 60 | note in2 2 3 |
| 61 | note in2 3 2 |
| 62 | note in2 7 7 |
| 63 | note in2 0 9 |
| 64 | note in2 9 0 |
| 65 | note in2 12 10 |
| 66 | note in2 10 12 |
| 67 | note in2 25 6 |
| 68 | note in2 6 25 |
| 69 | note in2 21 10 |
| 70 | note in2 10 21 |
| 71 | note in2 48 18 |
| 72 | note in2 18 48 |
| 73 | note in2 64 64 |
| 74 | note in2 51 49 |
| 75 | note in2 49 51 |
| 76 | note in2 100 7 |
| 77 | note in2 7 100 |
| 78 | note in2 255 16 |
| 79 | note in2 16 255 |
| 80 | note in2 1000 999 |
| 81 | note in2 999 1000 |
| 82 | note in2 65536 3 |
| 83 | note in2 3 65536 |
| 84 | note in2 4294967296 5 |
| 85 | note in2 5 4294967296 |
| 86 | note in2 123456789 987654321 |
| 87 | |
| 88 | note in3 0 0 0 |
| 89 | note in3 1 2 3 |
| 90 | note in3 3 2 1 |
| 91 | note in3 2 3 1 |
| 92 | note in3 2 1 3 |
| 93 | note in3 1 3 2 |
| 94 | note in3 3 1 2 |
| 95 | note in3 5 5 5 |
| 96 | note in3 5 5 7 |
| 97 | note in3 7 5 5 |
| 98 | note in3 5 7 5 |
| 99 | note in3 10 20 30 |
| 100 | note in3 30 20 10 |
| 101 | note in3 0 1 0 |
| 102 | note in3 1 0 1 |
| 103 | note in3 100 1 50 |
| 104 | note in3 7 3 2 |
| 105 | note in3 2 7 3 |
| 106 | note in3 255 15 240 |
| 107 | note in3 1000 10 3 |
| 108 | note in3 6 4 2 |
| 109 | note in3 9 0 9 |
| 110 | note in3 0 0 5 |
| 111 | note in3 12 12 1 |
| 112 | note in3 4294967296 1 2 |
| 113 | note in3 8 2 64 |
| 114 | note in3 17 5 3 |
| 115 | note in3 6 6 9 |
| 116 | note in3 4 9 4 |
| 117 | note in3 3 4 5 |
| 118 | |
| 119 | note arr 0 3 5 0 12 7 1 0 |
| 120 | note arr 9 8 7 6 5 4 3 2 |
| 121 | note arr 1 2 3 4 5 6 7 8 |
| 122 | note arr 4 4 4 4 4 4 4 4 |
| 123 | note arr 0 0 0 0 0 0 0 0 |
| 124 | note arr 10 1 10 1 10 1 10 1 |
| 125 | note arr 255 16 1024 3 65536 7 100 4294967296 |
| 126 | note arr 2 7 1 8 2 8 1 8 |
| 127 | note arr 0 1 2 3 3 3 6 6 |
| 128 | |
| 129 | note cnt 0 |
| 130 | note cnt 1 |
| 131 | note cnt 2 |
| 132 | note cnt 3 |
| 133 | note cnt 5 |
| 134 | note cnt 8 |
| 135 | |
| 136 | note ======== one argument |
| 137 | |
| 138 | note task u-001 arith |
| 139 | note say return the argument squared plus one |
| 140 | fn t001 a ulong to ulong |
| 141 | ret add mul a a 1 |
| 142 | end |
| 143 | |
| 144 | note task u-002 arith |
| 145 | note say return the cube of the argument |
| 146 | fn t002 a ulong to ulong |
| 147 | ret mul a mul a a |
| 148 | end |
| 149 | |
| 150 | note task u-003 arith |
| 151 | note say return three times the argument minus half the argument rounded down |
| 152 | fn t003 a ulong to ulong |
| 153 | ret sub mul 3 a div a 2 |
| 154 | end |
| 155 | |
| 156 | note task u-004 branch |
| 157 | note say return half the argument when it is even, otherwise three times the argument plus one |
| 158 | fn t004 a ulong to ulong |
| 159 | if eq rem a 2 0 |
| 160 | ret div a 2 |
| 161 | end |
| 162 | ret add mul 3 a 1 |
| 163 | end |
| 164 | |
| 165 | note task u-005 loop |
| 166 | note say return how many times the argument can be halved, rounding down, before it becomes zero |
| 167 | fn t005 a ulong to ulong |
| 168 | c = ulong 0 |
| 169 | x = a |
| 170 | while gt x 0 bound 64 |
| 171 | x = div x 2 |
| 172 | c = add c 1 |
| 173 | end |
| 174 | ret c |
| 175 | end |
| 176 | |
| 177 | note task u-006 bits |
| 178 | note say return the number of one bits in the argument |
| 179 | fn t006 a ulong to ulong |
| 180 | c = ulong 0 |
| 181 | x = a |
| 182 | while gt x 0 bound 64 |
| 183 | c = add c rem x 2 |
| 184 | x = div x 2 |
| 185 | end |
| 186 | ret c |
| 187 | end |
| 188 | |
| 189 | note task u-007 digits |
| 190 | note say return the sum of the decimal digits of the argument |
| 191 | fn t007 a ulong to ulong |
| 192 | s = ulong 0 |
| 193 | x = a |
| 194 | while gt x 0 bound 20 |
| 195 | s = add s rem x 10 |
| 196 | x = div x 10 |
| 197 | end |
| 198 | ret s |
| 199 | end |
| 200 | |
| 201 | note task u-008 digits |
| 202 | note say return the number of decimal digits of the argument, counting zero as one digit |
| 203 | fn t008 a ulong to ulong |
| 204 | c = ulong 1 |
| 205 | x = a |
| 206 | while ge x 10 bound 20 |
| 207 | x = div x 10 |
| 208 | c = add c 1 |
| 209 | end |
| 210 | ret c |
| 211 | end |
| 212 | |
| 213 | note task u-009 digits |
| 214 | note say return the argument with its decimal digits in reverse order |
| 215 | fn t009 a ulong to ulong |
| 216 | r = ulong 0 |
| 217 | x = a |
| 218 | while gt x 0 bound 20 |
| 219 | r = add mul r 10 rem x 10 |
| 220 | x = div x 10 |
| 221 | end |
| 222 | ret r |
| 223 | end |
| 224 | |
| 225 | note task u-010 digits |
| 226 | note say return the leading decimal digit of the argument |
| 227 | fn t010 a ulong to ulong |
| 228 | x = a |
| 229 | while ge x 10 bound 20 |
| 230 | x = div x 10 |
| 231 | end |
| 232 | ret x |
| 233 | end |
| 234 | |
| 235 | note task u-011 branch |
| 236 | note say return 1 when the argument is a multiple of 3 or of 5, otherwise 0 |
| 237 | fn t011 a ulong to ulong |
| 238 | if eq rem a 3 0 |
| 239 | ret 1 |
| 240 | end |
| 241 | if eq rem a 5 0 |
| 242 | ret 1 |
| 243 | end |
| 244 | ret 0 |
| 245 | end |
| 246 | |
| 247 | note task u-012 arith |
| 248 | note say return the argument rounded down to a multiple of 10 |
| 249 | fn t012 a ulong to ulong |
| 250 | ret mul div a 10 10 |
| 251 | end |
| 252 | |
| 253 | note task u-013 branch |
| 254 | note say return the distance between the argument and 100 |
| 255 | fn t013 a ulong to ulong |
| 256 | if lt a 100 |
| 257 | ret sub 100 a |
| 258 | end |
| 259 | ret sub a 100 |
| 260 | end |
| 261 | |
| 262 | note task u-014 bits |
| 263 | note say return the argument with its lowest one bit cleared |
| 264 | fn t014 a ulong to ulong |
| 265 | ret and a sub a 1 |
| 266 | end |
| 267 | |
| 268 | note task u-015 bits |
| 269 | note say return the lowest one bit of the argument, or zero for zero |
| 270 | fn t015 a ulong to ulong |
| 271 | ret and a sub 0 a |
| 272 | end |
| 273 | |
| 274 | note task u-016 loop |
| 275 | note say return the number of zero bits below the lowest one bit of the argument, or 64 for zero |
| 276 | fn t016 a ulong to ulong |
| 277 | if eq a 0 |
| 278 | ret 64 |
| 279 | end |
| 280 | c = ulong 0 |
| 281 | x = a |
| 282 | while eq rem x 2 0 bound 64 |
| 283 | x = div x 2 |
| 284 | c = add c 1 |
| 285 | end |
| 286 | ret c |
| 287 | end |
| 288 | |
| 289 | note task u-017 loop |
| 290 | note say return the largest power of two that is not above the argument, or zero for zero |
| 291 | fn t017 a ulong to ulong |
| 292 | if eq a 0 |
| 293 | ret 0 |
| 294 | end |
| 295 | p = ulong 1 |
| 296 | while le mul p 2 a bound 64 |
| 297 | p = mul p 2 |
| 298 | end |
| 299 | ret p |
| 300 | end |
| 301 | |
| 302 | note task u-018 loop |
| 303 | note say return the largest whole number whose square is not above the argument |
| 304 | fn t018 a ulong to ulong |
| 305 | r = ulong 0 |
| 306 | while le mul add r 1 add r 1 a bound 4294967296 |
| 307 | r = add r 1 |
| 308 | end |
| 309 | ret r |
| 310 | end |
| 311 | |
| 312 | note task u-019 loop |
| 313 | note say count the steps until the argument reaches 1 when an even value is halved and an odd value is tripled and increased by one; return zero for 0 and 1 |
| 314 | fn t019 a ulong to ulong |
| 315 | c = ulong 0 |
| 316 | x = a |
| 317 | while gt x 1 bound 100000 |
| 318 | if eq rem x 2 0 |
| 319 | x = div x 2 |
| 320 | else |
| 321 | x = add mul 3 x 1 |
| 322 | end |
| 323 | c = add c 1 |
| 324 | end |
| 325 | ret c |
| 326 | end |
| 327 | |
| 328 | note task u-020 loop |
| 329 | note say return the smallest divisor of the argument that is above 1, or the argument itself when it is below 2 |
| 330 | fn t020 a ulong to ulong |
| 331 | if lt a 2 |
| 332 | ret a |
| 333 | end |
| 334 | d = ulong 2 |
| 335 | while le mul d d a bound 4294967296 |
| 336 | if eq rem a d 0 |
| 337 | ret d |
| 338 | end |
| 339 | d = add d 1 |
| 340 | end |
| 341 | ret a |
| 342 | end |
| 343 | |
| 344 | note task u-021 loop |
| 345 | note say return 1 when the argument is a prime number, otherwise 0 |
| 346 | fn t021 a ulong to ulong |
| 347 | if lt a 2 |
| 348 | ret 0 |
| 349 | end |
| 350 | d = ulong 2 |
| 351 | while le mul d d a bound 4294967296 |
| 352 | if eq rem a d 0 |
| 353 | ret 0 |
| 354 | end |
| 355 | d = add d 1 |
| 356 | end |
| 357 | ret 1 |
| 358 | end |
| 359 | |
| 360 | note task u-022 arith |
| 361 | note say return the remainder of the argument divided by 7, times its remainder divided by 11 |
| 362 | fn t022 a ulong to ulong |
| 363 | ret mul rem a 7 rem a 11 |
| 364 | end |
| 365 | |
| 366 | note task u-023 bits |
| 367 | note say return the low two bytes of the argument with their order exchanged |
| 368 | fn t023 a ulong to ulong |
| 369 | ret or shl and a 255 8 and shr a 8 255 |
| 370 | end |
| 371 | |
| 372 | note task u-024 bits |
| 373 | note say return the low 16 bits of the argument with every one of them inverted |
| 374 | fn t024 a ulong to ulong |
| 375 | ret and xor a 65535 65535 |
| 376 | end |
| 377 | |
| 378 | note task u-025 loop |
| 379 | note say return the binary digits of the argument in reverse order, without leading zeros |
| 380 | fn t025 a ulong to ulong |
| 381 | r = ulong 0 |
| 382 | x = a |
| 383 | while gt x 0 bound 64 |
| 384 | r = add mul r 2 rem x 2 |
| 385 | x = div x 2 |
| 386 | end |
| 387 | ret r |
| 388 | end |
| 389 | |
| 390 | note task u-026 digits |
| 391 | note say return 1 when the decimal digits of the argument read the same in both directions, otherwise 0 |
| 392 | fn t026 a ulong to ulong |
| 393 | r = ulong 0 |
| 394 | x = a |
| 395 | while gt x 0 bound 20 |
| 396 | r = add mul r 10 rem x 10 |
| 397 | x = div x 10 |
| 398 | end |
| 399 | if eq r a |
| 400 | ret 1 |
| 401 | end |
| 402 | ret 0 |
| 403 | end |
| 404 | |
| 405 | note task u-027 loop |
| 406 | note say return the factorial of the argument when it is below 13, otherwise 0 |
| 407 | fn t027 a ulong to ulong |
| 408 | if ge a 13 |
| 409 | ret 0 |
| 410 | end |
| 411 | f = ulong 1 |
| 412 | for i ulong a |
| 413 | f = mul f add i 1 |
| 414 | end |
| 415 | ret f |
| 416 | end |
| 417 | |
| 418 | note task u-028 loop |
| 419 | note say return the Fibonacci number with the argument as its index, where index 0 gives 0 and index 1 gives 1, or 0 when the argument is 50 or more |
| 420 | fn t028 a ulong to ulong |
| 421 | if ge a 50 |
| 422 | ret 0 |
| 423 | end |
| 424 | x = ulong 0 |
| 425 | y = ulong 1 |
| 426 | for i ulong a |
| 427 | t = add x y |
| 428 | x = y |
| 429 | y = t |
| 430 | end |
| 431 | ret x |
| 432 | end |
| 433 | |
| 434 | note task u-029 branch |
| 435 | note say return 0 for arguments below 10, 1 for arguments below 100, 2 for arguments below 1000 and 3 otherwise |
| 436 | fn t029 a ulong to ulong |
| 437 | if lt a 10 |
| 438 | ret 0 |
| 439 | end |
| 440 | if lt a 100 |
| 441 | ret 1 |
| 442 | end |
| 443 | if lt a 1000 |
| 444 | ret 2 |
| 445 | end |
| 446 | ret 3 |
| 447 | end |
| 448 | |
| 449 | note task u-030 arith |
| 450 | note say return the smallest multiple of 8 that is not below the argument |
| 451 | fn t030 a ulong to ulong |
| 452 | ret mul div add a 7 8 8 |
| 453 | end |
| 454 | |
| 455 | note task u-031 digits |
| 456 | note say return the product of the decimal digits of the argument, with 1 for zero |
| 457 | fn t031 a ulong to ulong |
| 458 | p = ulong 1 |
| 459 | x = a |
| 460 | while gt x 0 bound 20 |
| 461 | p = mul p rem x 10 |
| 462 | x = div x 10 |
| 463 | end |
| 464 | ret p |
| 465 | end |
| 466 | |
| 467 | note task u-032 bits |
| 468 | note say return 1 when the argument is a power of two, otherwise 0 |
| 469 | fn t032 a ulong to ulong |
| 470 | if eq a 0 |
| 471 | ret 0 |
| 472 | end |
| 473 | if eq and a sub a 1 0 |
| 474 | ret 1 |
| 475 | end |
| 476 | ret 0 |
| 477 | end |
| 478 | |
| 479 | note task u-033 loop |
| 480 | note say return the greatest common divisor of the argument and 360 |
| 481 | fn t033 a ulong to ulong |
| 482 | x = a |
| 483 | y = ulong 360 |
| 484 | while ne y 0 bound 64 |
| 485 | t = rem x y |
| 486 | x = y |
| 487 | y = t |
| 488 | end |
| 489 | ret x |
| 490 | end |
| 491 | |
| 492 | note task u-034 digits |
| 493 | note say return the hundreds digit of the argument |
| 494 | fn t034 a ulong to ulong |
| 495 | ret rem div a 100 10 |
| 496 | end |
| 497 | |
| 498 | note task u-035 digits |
| 499 | note say return how many decimal digits of the argument are even, with none for zero |
| 500 | fn t035 a ulong to ulong |
| 501 | c = ulong 0 |
| 502 | x = a |
| 503 | while gt x 0 bound 20 |
| 504 | if eq rem rem x 10 2 0 |
| 505 | c = add c 1 |
| 506 | end |
| 507 | x = div x 10 |
| 508 | end |
| 509 | ret c |
| 510 | end |
| 511 | |
| 512 | note ======== two arguments |
| 513 | |
| 514 | note task p-001 arith |
| 515 | note say return the product of the arguments plus their sum |
| 516 | fn t036 a ulong b ulong to ulong |
| 517 | ret add mul a b add a b |
| 518 | end |
| 519 | |
| 520 | note task p-002 arith |
| 521 | note say return the square of the sum of the arguments |
| 522 | fn t037 a ulong b ulong to ulong |
| 523 | s = add a b |
| 524 | ret mul s s |
| 525 | end |
| 526 | |
| 527 | note task p-003 branch |
| 528 | note say return the square of the distance between the arguments |
| 529 | fn t038 a ulong b ulong to ulong |
| 530 | d = sub a b |
| 531 | if lt a b |
| 532 | d = sub b a |
| 533 | end |
| 534 | ret mul d d |
| 535 | end |
| 536 | |
| 537 | note task p-004 branch |
| 538 | note say return a divided by b rounded down, or zero when b is zero |
| 539 | fn t039 a ulong b ulong to ulong |
| 540 | if eq b 0 |
| 541 | ret 0 |
| 542 | end |
| 543 | ret div a b |
| 544 | end |
| 545 | |
| 546 | note task p-005 branch |
| 547 | note say return the remainder of a divided by b, or a itself when b is zero |
| 548 | fn t040 a ulong b ulong to ulong |
| 549 | if eq b 0 |
| 550 | ret a |
| 551 | end |
| 552 | ret rem a b |
| 553 | end |
| 554 | |
| 555 | note task p-006 loop |
| 556 | note say return the greatest common divisor of the arguments, which is the other argument when one of them is zero |
| 557 | fn t041 a ulong b ulong to ulong |
| 558 | x = a |
| 559 | y = b |
| 560 | while ne y 0 bound 200 |
| 561 | t = rem x y |
| 562 | x = y |
| 563 | y = t |
| 564 | end |
| 565 | ret x |
| 566 | end |
| 567 | |
| 568 | note task p-007 arith |
| 569 | note say return the sum of the squares of the arguments |
| 570 | fn t042 a ulong b ulong to ulong |
| 571 | ret add mul a a mul b b |
| 572 | end |
| 573 | |
| 574 | note task p-008 branch |
| 575 | note say return 1 when the arguments are equal, 2 when a is larger and 3 when b is larger |
| 576 | fn t043 a ulong b ulong to ulong |
| 577 | if eq a b |
| 578 | ret 1 |
| 579 | end |
| 580 | if gt a b |
| 581 | ret 2 |
| 582 | end |
| 583 | ret 3 |
| 584 | end |
| 585 | |
| 586 | note task p-009 bits |
| 587 | note say return the bits that are one in a and zero in b |
| 588 | fn t044 a ulong b ulong to ulong |
| 589 | ret sub a and a b |
| 590 | end |
| 591 | |
| 592 | note task p-010 loop |
| 593 | note say return the number of bit positions in which the arguments differ |
| 594 | fn t045 a ulong b ulong to ulong |
| 595 | c = ulong 0 |
| 596 | x = xor a b |
| 597 | while gt x 0 bound 64 |
| 598 | c = add c rem x 2 |
| 599 | x = div x 2 |
| 600 | end |
| 601 | ret c |
| 602 | end |
| 603 | |
| 604 | note task p-011 arith |
| 605 | note say return twice a plus three times b |
| 606 | fn t046 a ulong b ulong to ulong |
| 607 | ret add mul 2 a mul 3 b |
| 608 | end |
| 609 | |
| 610 | note task p-012 branch |
| 611 | note say return the smaller argument times the last decimal digit of the larger argument |
| 612 | fn t047 a ulong b ulong to ulong |
| 613 | lo = a |
| 614 | hi = b |
| 615 | if gt a b |
| 616 | lo = b |
| 617 | hi = a |
| 618 | end |
| 619 | ret mul lo rem hi 10 |
| 620 | end |
| 621 | |
| 622 | note task p-013 loop |
| 623 | note say return a raised to the power b when b is below 5, otherwise 0 |
| 624 | fn t048 a ulong b ulong to ulong |
| 625 | if ge b 5 |
| 626 | ret 0 |
| 627 | end |
| 628 | r = ulong 1 |
| 629 | for i ulong b |
| 630 | r = mul r a |
| 631 | end |
| 632 | ret r |
| 633 | end |
| 634 | |
| 635 | note task p-014 branch |
| 636 | note say return a divided by b rounded down but never more than 100, or zero when b is zero |
| 637 | fn t049 a ulong b ulong to ulong |
| 638 | if eq b 0 |
| 639 | ret 0 |
| 640 | end |
| 641 | q = div a b |
| 642 | if gt q 100 |
| 643 | ret 100 |
| 644 | end |
| 645 | ret q |
| 646 | end |
| 647 | |
| 648 | note task p-015 arith |
| 649 | note say return the average of the arguments rounded down |
| 650 | fn t050 a ulong b ulong to ulong |
| 651 | ret div add a b 2 |
| 652 | end |
| 653 | |
| 654 | note task p-016 branch |
| 655 | note say return the argument that is closer to 50, and a when both are equally close |
| 656 | fn t051 a ulong b ulong to ulong |
| 657 | da = sub a 50 |
| 658 | if lt a 50 |
| 659 | da = sub 50 a |
| 660 | end |
| 661 | db = sub b 50 |
| 662 | if lt b 50 |
| 663 | db = sub 50 b |
| 664 | end |
| 665 | if lt db da |
| 666 | ret b |
| 667 | end |
| 668 | ret a |
| 669 | end |
| 670 | |
| 671 | note task p-017 branch |
| 672 | note say return a when a is even and b when a is odd |
| 673 | fn t052 a ulong b ulong to ulong |
| 674 | if eq rem a 2 0 |
| 675 | ret a |
| 676 | end |
| 677 | ret b |
| 678 | end |
| 679 | |
| 680 | note task p-018 bits |
| 681 | note say return the bits that are one in both arguments, moved one position to the left |
| 682 | fn t053 a ulong b ulong to ulong |
| 683 | ret shl and a b 1 |
| 684 | end |
| 685 | |
| 686 | note task p-019 bits |
| 687 | note say return a 16-bit value whose high byte is the low byte of a and whose low byte is the low byte of b |
| 688 | fn t054 a ulong b ulong to ulong |
| 689 | ret or shl and a 255 8 and b 255 |
| 690 | end |
| 691 | |
| 692 | note task p-020 loop |
| 693 | note say return the least common multiple of the arguments, or zero when either is zero |
| 694 | fn t055 a ulong b ulong to ulong |
| 695 | if eq a 0 |
| 696 | ret 0 |
| 697 | end |
| 698 | if eq b 0 |
| 699 | ret 0 |
| 700 | end |
| 701 | x = a |
| 702 | y = b |
| 703 | while ne y 0 bound 200 |
| 704 | t = rem x y |
| 705 | x = y |
| 706 | y = t |
| 707 | end |
| 708 | ret mul div a x b |
| 709 | end |
| 710 | |
| 711 | note task p-021 branch |
| 712 | note say return the sum of the arguments when it is below 100, otherwise 100 |
| 713 | fn t056 a ulong b ulong to ulong |
| 714 | s = add a b |
| 715 | if lt s 100 |
| 716 | ret s |
| 717 | end |
| 718 | ret 100 |
| 719 | end |
| 720 | |
| 721 | note task p-022 branch |
| 722 | note say return a minus b when a is at least b, otherwise zero |
| 723 | fn t057 a ulong b ulong to ulong |
| 724 | if ge a b |
| 725 | ret sub a b |
| 726 | end |
| 727 | ret 0 |
| 728 | end |
| 729 | |
| 730 | note task p-023 digits |
| 731 | note say return the two-digit number made of the last decimal digit of a followed by the last decimal digit of b |
| 732 | fn t058 a ulong b ulong to ulong |
| 733 | ret add mul rem a 10 10 rem b 10 |
| 734 | end |
| 735 | |
| 736 | note task p-024 digits |
| 737 | note say return the sum of the decimal digits of both arguments |
| 738 | fn t059 a ulong b ulong to ulong |
| 739 | s = ulong 0 |
| 740 | x = a |
| 741 | while gt x 0 bound 20 |
| 742 | s = add s rem x 10 |
| 743 | x = div x 10 |
| 744 | end |
| 745 | x = b |
| 746 | while gt x 0 bound 20 |
| 747 | s = add s rem x 10 |
| 748 | x = div x 10 |
| 749 | end |
| 750 | ret s |
| 751 | end |
| 752 | |
| 753 | note task p-025 branch |
| 754 | note say return 1 when exactly one of the arguments is zero, otherwise 0 |
| 755 | fn t060 a ulong b ulong to ulong |
| 756 | if eq a 0 |
| 757 | if ne b 0 |
| 758 | ret 1 |
| 759 | end |
| 760 | ret 0 |
| 761 | end |
| 762 | if eq b 0 |
| 763 | ret 1 |
| 764 | end |
| 765 | ret 0 |
| 766 | end |
| 767 | |
| 768 | note task p-026 branch |
| 769 | note say return 1 when a is not zero and b is a multiple of a, otherwise 0 |
| 770 | fn t061 a ulong b ulong to ulong |
| 771 | if eq a 0 |
| 772 | ret 0 |
| 773 | end |
| 774 | if eq rem b a 0 |
| 775 | ret 1 |
| 776 | end |
| 777 | ret 0 |
| 778 | end |
| 779 | |
| 780 | note task p-027 branch |
| 781 | note say return the square of the larger argument minus the square of the smaller argument |
| 782 | fn t062 a ulong b ulong to ulong |
| 783 | x = mul a a |
| 784 | y = mul b b |
| 785 | if ge a b |
| 786 | ret sub x y |
| 787 | end |
| 788 | ret sub y x |
| 789 | end |
| 790 | |
| 791 | note task p-028 bits |
| 792 | note say return the low four bits of the positions where exactly one argument has a one |
| 793 | fn t063 a ulong b ulong to ulong |
| 794 | ret and xor a b 15 |
| 795 | end |
| 796 | |
| 797 | note task p-029 branch |
| 798 | note say return the larger argument when both arguments are odd, otherwise the smaller argument |
| 799 | fn t064 a ulong b ulong to ulong |
| 800 | lo = a |
| 801 | hi = b |
| 802 | if gt a b |
| 803 | lo = b |
| 804 | hi = a |
| 805 | end |
| 806 | if eq rem a 2 1 |
| 807 | if eq rem b 2 1 |
| 808 | ret hi |
| 809 | end |
| 810 | end |
| 811 | ret lo |
| 812 | end |
| 813 | |
| 814 | note task p-030 digits |
| 815 | note say return how many decimal digits the two arguments have together, counting zero as one digit |
| 816 | fn t065 a ulong b ulong to ulong |
| 817 | c = ulong 2 |
| 818 | x = a |
| 819 | while ge x 10 bound 20 |
| 820 | x = div x 10 |
| 821 | c = add c 1 |
| 822 | end |
| 823 | x = b |
| 824 | while ge x 10 bound 20 |
| 825 | x = div x 10 |
| 826 | c = add c 1 |
| 827 | end |
| 828 | ret c |
| 829 | end |
| 830 | |
| 831 | note task p-031 arith |
| 832 | note say return the remainder of the sum of the arguments divided by 9 |
| 833 | fn t066 a ulong b ulong to ulong |
| 834 | ret rem add a b 9 |
| 835 | end |
| 836 | |
| 837 | note task p-032 branch |
| 838 | note say return the middle value of a, b and 10 |
| 839 | fn t067 a ulong b ulong to ulong |
| 840 | lo = a |
| 841 | hi = b |
| 842 | if gt a b |
| 843 | lo = b |
| 844 | hi = a |
| 845 | end |
| 846 | if lt 10 lo |
| 847 | ret lo |
| 848 | end |
| 849 | if gt 10 hi |
| 850 | ret hi |
| 851 | end |
| 852 | ret 10 |
| 853 | end |
| 854 | |
| 855 | note task p-033 bits |
| 856 | note say return a with one more bit set: the bit whose number is the remainder of b divided by 8 |
| 857 | fn t068 a ulong b ulong to ulong |
| 858 | ret or a shl 1 rem b 8 |
| 859 | end |
| 860 | |
| 861 | note task p-034 bits |
| 862 | note say return the bit of a whose number is the remainder of b divided by 8, as 0 or 1 |
| 863 | fn t069 a ulong b ulong to ulong |
| 864 | ret and shr a rem b 8 1 |
| 865 | end |
| 866 | |
| 867 | note ======== three arguments |
| 868 | |
| 869 | note task t-001 arith |
| 870 | note say return a times b plus c |
| 871 | fn t070 a ulong b ulong c ulong to ulong |
| 872 | ret add mul a b c |
| 873 | end |
| 874 | |
| 875 | note task t-002 branch |
| 876 | note say return the largest of the three arguments |
| 877 | fn t071 a ulong b ulong c ulong to ulong |
| 878 | m = a |
| 879 | if gt b m |
| 880 | m = b |
| 881 | end |
| 882 | if gt c m |
| 883 | m = c |
| 884 | end |
| 885 | ret m |
| 886 | end |
| 887 | |
| 888 | note task t-003 branch |
| 889 | note say return the smallest of the three arguments |
| 890 | fn t072 a ulong b ulong c ulong to ulong |
| 891 | m = a |
| 892 | if lt b m |
| 893 | m = b |
| 894 | end |
| 895 | if lt c m |
| 896 | m = c |
| 897 | end |
| 898 | ret m |
| 899 | end |
| 900 | |
| 901 | note task t-004 branch |
| 902 | note say return the middle value of the three arguments |
| 903 | fn t073 a ulong b ulong c ulong to ulong |
| 904 | if gt a b |
| 905 | if gt b c |
| 906 | ret b |
| 907 | end |
| 908 | if gt a c |
| 909 | ret c |
| 910 | end |
| 911 | ret a |
| 912 | end |
| 913 | if gt a c |
| 914 | ret a |
| 915 | end |
| 916 | if gt b c |
| 917 | ret c |
| 918 | end |
| 919 | ret b |
| 920 | end |
| 921 | |
| 922 | note task t-005 arith |
| 923 | note say return the sum of the three arguments |
| 924 | fn t074 a ulong b ulong c ulong to ulong |
| 925 | ret add add a b c |
| 926 | end |
| 927 | |
| 928 | note task t-006 branch |
| 929 | note say return how many of the three arguments equal the first one, counting the first itself |
| 930 | fn t075 a ulong b ulong c ulong to ulong |
| 931 | k = ulong 1 |
| 932 | if eq b a |
| 933 | k = add k 1 |
| 934 | end |
| 935 | if eq c a |
| 936 | k = add k 1 |
| 937 | end |
| 938 | ret k |
| 939 | end |
| 940 | |
| 941 | note task t-007 branch |
| 942 | note say return 1 when a is not above b and b is not above c, otherwise 0 |
| 943 | fn t076 a ulong b ulong c ulong to ulong |
| 944 | if gt a b |
| 945 | ret 0 |
| 946 | end |
| 947 | if gt b c |
| 948 | ret 0 |
| 949 | end |
| 950 | ret 1 |
| 951 | end |
| 952 | |
| 953 | note task t-008 branch |
| 954 | note say return a when c is zero, otherwise b |
| 955 | fn t077 a ulong b ulong c ulong to ulong |
| 956 | if eq c 0 |
| 957 | ret a |
| 958 | end |
| 959 | ret b |
| 960 | end |
| 961 | |
| 962 | note task t-009 branch |
| 963 | note say return the sum of the two largest arguments |
| 964 | fn t078 a ulong b ulong c ulong to ulong |
| 965 | m = a |
| 966 | if lt b m |
| 967 | m = b |
| 968 | end |
| 969 | if lt c m |
| 970 | m = c |
| 971 | end |
| 972 | ret sub add add a b c m |
| 973 | end |
| 974 | |
| 975 | note task t-010 branch |
| 976 | note say return the largest argument minus the smallest argument |
| 977 | fn t079 a ulong b ulong c ulong to ulong |
| 978 | lo = a |
| 979 | hi = a |
| 980 | if lt b lo |
| 981 | lo = b |
| 982 | end |
| 983 | if lt c lo |
| 984 | lo = c |
| 985 | end |
| 986 | if gt b hi |
| 987 | hi = b |
| 988 | end |
| 989 | if gt c hi |
| 990 | hi = c |
| 991 | end |
| 992 | ret sub hi lo |
| 993 | end |
| 994 | |
| 995 | note task t-011 branch |
| 996 | note say return b unchanged when a is above c; otherwise return a when b is below a, c when b is above c, and b in between |
| 997 | fn t080 a ulong b ulong c ulong to ulong |
| 998 | if gt a c |
| 999 | ret b |
| 1000 | end |
| 1001 | if lt b a |
| 1002 | ret a |
| 1003 | end |
| 1004 | if gt b c |
| 1005 | ret c |
| 1006 | end |
| 1007 | ret b |
| 1008 | end |
| 1009 | |
| 1010 | note task t-012 arith |
| 1011 | note say return the product of the three arguments |
| 1012 | fn t081 a ulong b ulong c ulong to ulong |
| 1013 | ret mul mul a b c |
| 1014 | end |
| 1015 | |
| 1016 | note task t-013 branch |
| 1017 | note say return the number of different values among the three arguments |
| 1018 | fn t082 a ulong b ulong c ulong to ulong |
| 1019 | if eq a b |
| 1020 | if eq b c |
| 1021 | ret 1 |
| 1022 | end |
| 1023 | ret 2 |
| 1024 | end |
| 1025 | if eq a c |
| 1026 | ret 2 |
| 1027 | end |
| 1028 | if eq b c |
| 1029 | ret 2 |
| 1030 | end |
| 1031 | ret 3 |
| 1032 | end |
| 1033 | |
| 1034 | note task t-014 branch |
| 1035 | note say return 1 when each argument is smaller than the sum of the other two, otherwise 0 |
| 1036 | fn t083 a ulong b ulong c ulong to ulong |
| 1037 | if ge a add b c |
| 1038 | ret 0 |
| 1039 | end |
| 1040 | if ge b add a c |
| 1041 | ret 0 |
| 1042 | end |
| 1043 | if ge c add a b |
| 1044 | ret 0 |
| 1045 | end |
| 1046 | ret 1 |
| 1047 | end |
| 1048 | |
| 1049 | note task t-015 branch |
| 1050 | note say return a plus b when c is even and a times b when c is odd |
| 1051 | fn t084 a ulong b ulong c ulong to ulong |
| 1052 | if eq rem c 2 0 |
| 1053 | ret add a b |
| 1054 | end |
| 1055 | ret mul a b |
| 1056 | end |
| 1057 | |
| 1058 | note task t-016 arith |
| 1059 | note say return b plus a times the remainder of c divided by 5 |
| 1060 | fn t085 a ulong b ulong c ulong to ulong |
| 1061 | ret add b mul a rem c 5 |
| 1062 | end |
| 1063 | |
| 1064 | note task t-017 arith |
| 1065 | note say return how many of the three arguments are odd |
| 1066 | fn t086 a ulong b ulong c ulong to ulong |
| 1067 | ret add add rem a 2 rem b 2 rem c 2 |
| 1068 | end |
| 1069 | |
| 1070 | note task t-018 bits |
| 1071 | note say return the bits that are one in at least two of the three arguments |
| 1072 | fn t087 a ulong b ulong c ulong to ulong |
| 1073 | ret or or and a b and a c and b c |
| 1074 | end |
| 1075 | |
| 1076 | note task t-019 bits |
| 1077 | note say return the bits that are one in an odd number of the three arguments |
| 1078 | fn t088 a ulong b ulong c ulong to ulong |
| 1079 | ret xor xor a b c |
| 1080 | end |
| 1081 | |
| 1082 | note task t-020 branch |
| 1083 | note say return 1 when b lies strictly between a and c, whichever of them is larger, otherwise 0 |
| 1084 | fn t089 a ulong b ulong c ulong to ulong |
| 1085 | if lt a b |
| 1086 | if lt b c |
| 1087 | ret 1 |
| 1088 | end |
| 1089 | end |
| 1090 | if gt a b |
| 1091 | if gt b c |
| 1092 | ret 1 |
| 1093 | end |
| 1094 | end |
| 1095 | ret 0 |
| 1096 | end |
| 1097 | |
| 1098 | note task t-021 arith |
| 1099 | note say return the average of the three arguments rounded down |
| 1100 | fn t090 a ulong b ulong c ulong to ulong |
| 1101 | ret div add add a b c 3 |
| 1102 | end |
| 1103 | |
| 1104 | note task t-022 branch |
| 1105 | note say return the value that occurs at least twice among the arguments, or zero when all three differ |
| 1106 | fn t091 a ulong b ulong c ulong to ulong |
| 1107 | if eq a b |
| 1108 | ret a |
| 1109 | end |
| 1110 | if eq a c |
| 1111 | ret a |
| 1112 | end |
| 1113 | if eq b c |
| 1114 | ret b |
| 1115 | end |
| 1116 | ret 0 |
| 1117 | end |
| 1118 | |
| 1119 | note task t-023 branch |
| 1120 | note say return a squared plus b squared minus c, or zero when c is larger than a squared plus b squared |
| 1121 | fn t092 a ulong b ulong c ulong to ulong |
| 1122 | s = add mul a a mul b b |
| 1123 | if gt c s |
| 1124 | ret 0 |
| 1125 | end |
| 1126 | ret sub s c |
| 1127 | end |
| 1128 | |
| 1129 | note task t-024 loop |
| 1130 | note say return the greatest common divisor of the three arguments, ignoring arguments that are zero and returning zero when all are zero |
| 1131 | fn t093 a ulong b ulong c ulong to ulong |
| 1132 | x = a |
| 1133 | y = b |
| 1134 | while ne y 0 bound 200 |
| 1135 | t = rem x y |
| 1136 | x = y |
| 1137 | y = t |
| 1138 | end |
| 1139 | y = c |
| 1140 | while ne y 0 bound 200 |
| 1141 | t = rem x y |
| 1142 | x = y |
| 1143 | y = t |
| 1144 | end |
| 1145 | ret x |
| 1146 | end |
| 1147 | |
| 1148 | note task t-025 branch |
| 1149 | note say return c when a equals b, otherwise b when a equals c, otherwise a |
| 1150 | fn t094 a ulong b ulong c ulong to ulong |
| 1151 | if eq a b |
| 1152 | ret c |
| 1153 | end |
| 1154 | if eq a c |
| 1155 | ret b |
| 1156 | end |
| 1157 | ret a |
| 1158 | end |
| 1159 | |
| 1160 | note task t-026 arith |
| 1161 | note say return a times 100 plus b times 10 plus c |
| 1162 | fn t095 a ulong b ulong c ulong to ulong |
| 1163 | ret add add mul a 100 mul b 10 c |
| 1164 | end |
| 1165 | |
| 1166 | note task t-027 branch |
| 1167 | note say return the product of the two smallest arguments |
| 1168 | fn t096 a ulong b ulong c ulong to ulong |
| 1169 | hi = a |
| 1170 | if gt b hi |
| 1171 | hi = b |
| 1172 | end |
| 1173 | if gt c hi |
| 1174 | hi = c |
| 1175 | end |
| 1176 | if eq hi a |
| 1177 | ret mul b c |
| 1178 | end |
| 1179 | if eq hi b |
| 1180 | ret mul a c |
| 1181 | end |
| 1182 | ret mul a b |
| 1183 | end |
| 1184 | |
| 1185 | note task t-028 branch |
| 1186 | note say return how many of the three arguments are above 5 |
| 1187 | fn t097 a ulong b ulong c ulong to ulong |
| 1188 | k = ulong 0 |
| 1189 | if gt a 5 |
| 1190 | k = add k 1 |
| 1191 | end |
| 1192 | if gt b 5 |
| 1193 | k = add k 1 |
| 1194 | end |
| 1195 | if gt c 5 |
| 1196 | k = add k 1 |
| 1197 | end |
| 1198 | ret k |
| 1199 | end |
| 1200 | |
| 1201 | note task t-029 arith |
| 1202 | note say return the last decimal digit of the sum of the three arguments |
| 1203 | fn t098 a ulong b ulong c ulong to ulong |
| 1204 | ret rem add add a b c 10 |
| 1205 | end |
| 1206 | |
| 1207 | note task t-030 branch |
| 1208 | note say return a when a is at least as large as both other arguments, otherwise the sum of b and c |
| 1209 | fn t099 a ulong b ulong c ulong to ulong |
| 1210 | if ge a b |
| 1211 | if ge a c |
| 1212 | ret a |
| 1213 | end |
| 1214 | end |
| 1215 | ret add b c |
| 1216 | end |
| 1217 | |
| 1218 | note task t-031 bits |
| 1219 | note say return, bit by bit, the bit of a where c has a one and the bit of b where c has a zero |
| 1220 | fn t100 a ulong b ulong c ulong to ulong |
| 1221 | ret or and a c and b xor c 18446744073709551615 |
| 1222 | end |
| 1223 | |
| 1224 | note task t-032 branch |
| 1225 | note say return zero when any argument is zero, otherwise the largest argument |
| 1226 | fn t101 a ulong b ulong c ulong to ulong |
| 1227 | if eq a 0 |
| 1228 | ret 0 |
| 1229 | end |
| 1230 | if eq b 0 |
| 1231 | ret 0 |
| 1232 | end |
| 1233 | if eq c 0 |
| 1234 | ret 0 |
| 1235 | end |
| 1236 | m = a |
| 1237 | if gt b m |
| 1238 | m = b |
| 1239 | end |
| 1240 | if gt c m |
| 1241 | m = c |
| 1242 | end |
| 1243 | ret m |
| 1244 | end |
| 1245 | |
| 1246 | note ======== the first n items of an array, read only |
| 1247 | |
| 1248 | note task r-001 fold |
| 1249 | note say return the product of the first n items, with 1 when n is zero |
| 1250 | fn t102 a view ulong 8 n ulong to ulong |
| 1251 | p = ulong 1 |
| 1252 | for i ulong n |
| 1253 | p = mul p get a i |
| 1254 | end |
| 1255 | ret p |
| 1256 | end |
| 1257 | |
| 1258 | note task r-002 select |
| 1259 | note say return the smallest of the first n items, or zero when n is zero |
| 1260 | fn t103 a view ulong 8 n ulong to ulong |
| 1261 | if eq n 0 |
| 1262 | ret 0 |
| 1263 | end |
| 1264 | m = get a 0 |
| 1265 | for i ulong n |
| 1266 | if lt get a i m |
| 1267 | m = get a i |
| 1268 | end |
| 1269 | end |
| 1270 | ret m |
| 1271 | end |
| 1272 | |
| 1273 | note task r-003 count |
| 1274 | note say return how many of the first n items are odd |
| 1275 | fn t104 a view ulong 8 n ulong to ulong |
| 1276 | c = ulong 0 |
| 1277 | for i ulong n |
| 1278 | c = add c rem get a i 2 |
| 1279 | end |
| 1280 | ret c |
| 1281 | end |
| 1282 | |
| 1283 | note task r-004 count |
| 1284 | note say return how many of the first n items are greater than 4 |
| 1285 | fn t105 a view ulong 8 n ulong to ulong |
| 1286 | c = ulong 0 |
| 1287 | for i ulong n |
| 1288 | if gt get a i 4 |
| 1289 | c = add c 1 |
| 1290 | end |
| 1291 | end |
| 1292 | ret c |
| 1293 | end |
| 1294 | |
| 1295 | note task r-005 scan |
| 1296 | note say return the index of the first zero among the first n items, or n when none of them is zero |
| 1297 | fn t106 a view ulong 8 n ulong to ulong |
| 1298 | for i ulong n |
| 1299 | if eq get a i 0 |
| 1300 | ret i |
| 1301 | end |
| 1302 | end |
| 1303 | ret n |
| 1304 | end |
| 1305 | |
| 1306 | note task r-006 scan |
| 1307 | note say return the index of the largest of the first n items, the lowest such index when it occurs more than once, or zero when n is zero |
| 1308 | fn t107 a view ulong 8 n ulong to ulong |
| 1309 | k = ulong 0 |
| 1310 | for i ulong n |
| 1311 | if gt get a i get a k |
| 1312 | k = i |
| 1313 | end |
| 1314 | end |
| 1315 | ret k |
| 1316 | end |
| 1317 | |
| 1318 | note task r-007 fold |
| 1319 | note say return the sum of the squares of the first n items |
| 1320 | fn t108 a view ulong 8 n ulong to ulong |
| 1321 | s = ulong 0 |
| 1322 | for i ulong n |
| 1323 | x = get a i |
| 1324 | s = add s mul x x |
| 1325 | end |
| 1326 | ret s |
| 1327 | end |
| 1328 | |
| 1329 | note task r-008 fold |
| 1330 | note say return the sum of the items at even indexes among the first n items |
| 1331 | fn t109 a view ulong 8 n ulong to ulong |
| 1332 | s = ulong 0 |
| 1333 | for i ulong n |
| 1334 | if eq rem i 2 0 |
| 1335 | s = add s get a i |
| 1336 | end |
| 1337 | end |
| 1338 | ret s |
| 1339 | end |
| 1340 | |
| 1341 | note task r-009 fold |
| 1342 | note say return the largest minus the smallest of the first n items, or zero when n is zero |
| 1343 | fn t110 a view ulong 8 n ulong to ulong |
| 1344 | if eq n 0 |
| 1345 | ret 0 |
| 1346 | end |
| 1347 | lo = get a 0 |
| 1348 | hi = get a 0 |
| 1349 | for i ulong n |
| 1350 | x = get a i |
| 1351 | if lt x lo |
| 1352 | lo = x |
| 1353 | end |
| 1354 | if gt x hi |
| 1355 | hi = x |
| 1356 | end |
| 1357 | end |
| 1358 | ret sub hi lo |
| 1359 | end |
| 1360 | |
| 1361 | note task r-010 count |
| 1362 | note say return how many of the first n items are greater than the item just before them |
| 1363 | fn t111 a view ulong 8 n ulong to ulong |
| 1364 | c = ulong 0 |
| 1365 | for i ulong n |
| 1366 | if gt i 0 |
| 1367 | if gt get a i get a sub i 1 |
| 1368 | c = add c 1 |
| 1369 | end |
| 1370 | end |
| 1371 | end |
| 1372 | ret c |
| 1373 | end |
| 1374 | |
| 1375 | note task r-011 scan |
| 1376 | note say return 1 when none of the first n items is smaller than the item just before it, otherwise 0 |
| 1377 | fn t112 a view ulong 8 n ulong to ulong |
| 1378 | for i ulong n |
| 1379 | if gt i 0 |
| 1380 | if lt get a i get a sub i 1 |
| 1381 | ret 0 |
| 1382 | end |
| 1383 | end |
| 1384 | end |
| 1385 | ret 1 |
| 1386 | end |
| 1387 | |
| 1388 | note task r-012 count |
| 1389 | note say return how many of the first n items equal the first item, counting the first item itself |
| 1390 | fn t113 a view ulong 8 n ulong to ulong |
| 1391 | c = ulong 0 |
| 1392 | for i ulong n |
| 1393 | if eq get a i get a 0 |
| 1394 | c = add c 1 |
| 1395 | end |
| 1396 | end |
| 1397 | ret c |
| 1398 | end |
| 1399 | |
| 1400 | note task r-013 fold |
| 1401 | note say return the bits that are one in every one of the first n items, or zero when n is zero |
| 1402 | fn t114 a view ulong 8 n ulong to ulong |
| 1403 | if eq n 0 |
| 1404 | ret 0 |
| 1405 | end |
| 1406 | x = get a 0 |
| 1407 | for i ulong n |
| 1408 | x = and x get a i |
| 1409 | end |
| 1410 | ret x |
| 1411 | end |
| 1412 | |
| 1413 | note task r-014 select |
| 1414 | note say return the item at index n minus one, or zero when n is zero |
| 1415 | fn t115 a view ulong 8 n ulong to ulong |
| 1416 | if eq n 0 |
| 1417 | ret 0 |
| 1418 | end |
| 1419 | ret get a sub n 1 |
| 1420 | end |
| 1421 | |
| 1422 | note task r-015 count |
| 1423 | note say return the number of different values among the first n items |
| 1424 | fn t116 a view ulong 8 n ulong to ulong |
| 1425 | c = ulong 0 |
| 1426 | for i ulong n |
| 1427 | old = false |
| 1428 | for j ulong i |
| 1429 | if eq get a j get a i |
| 1430 | old = true |
| 1431 | end |
| 1432 | end |
| 1433 | if not old |
| 1434 | c = add c 1 |
| 1435 | end |
| 1436 | end |
| 1437 | ret c |
| 1438 | end |
| 1439 | |
| 1440 | note task r-016 fold |
| 1441 | note say return the sum of the first n items after multiplying each by its index |
| 1442 | fn t117 a view ulong 8 n ulong to ulong |
| 1443 | s = ulong 0 |
| 1444 | for i ulong n |
| 1445 | s = add s mul i get a i |
| 1446 | end |
| 1447 | ret s |
| 1448 | end |
| 1449 | |
| 1450 | note task r-017 scan |
| 1451 | note say return the length of the longest run of equal neighbouring items among the first n items, or zero when n is zero |
| 1452 | fn t118 a view ulong 8 n ulong to ulong |
| 1453 | if eq n 0 |
| 1454 | ret 0 |
| 1455 | end |
| 1456 | best = ulong 1 |
| 1457 | cur = ulong 1 |
| 1458 | for i ulong n |
| 1459 | if gt i 0 |
| 1460 | if eq get a i get a sub i 1 |
| 1461 | cur = add cur 1 |
| 1462 | else |
| 1463 | cur = 1 |
| 1464 | end |
| 1465 | if gt cur best |
| 1466 | best = cur |
| 1467 | end |
| 1468 | end |
| 1469 | end |
| 1470 | ret best |
| 1471 | end |
| 1472 | |
| 1473 | note task r-018 select |
| 1474 | note say return the second largest of the first n items, which equals the largest when the largest occurs twice, or zero when n is below 2 |
| 1475 | fn t119 a view ulong 8 n ulong to ulong |
| 1476 | if lt n 2 |
| 1477 | ret 0 |
| 1478 | end |
| 1479 | m1 = get a 0 |
| 1480 | m2 = get a 1 |
| 1481 | if lt m1 m2 |
| 1482 | m1 = get a 1 |
| 1483 | m2 = get a 0 |
| 1484 | end |
| 1485 | for i ulong n |
| 1486 | if ge i 2 |
| 1487 | x = get a i |
| 1488 | if gt x m1 |
| 1489 | m2 = m1 |
| 1490 | m1 = x |
| 1491 | else |
| 1492 | if gt x m2 |
| 1493 | m2 = x |
| 1494 | end |
| 1495 | end |
| 1496 | end |
| 1497 | end |
| 1498 | ret m2 |
| 1499 | end |
| 1500 | |
| 1501 | note task r-019 fold |
| 1502 | note say return the first item minus the second plus the third and so on over the first n items, with wrapping arithmetic |
| 1503 | fn t120 a view ulong 8 n ulong to ulong |
| 1504 | s = ulong 0 |
| 1505 | for i ulong n |
| 1506 | if eq rem i 2 0 |
| 1507 | s = add s get a i |
| 1508 | else |
| 1509 | s = sub s get a i |
| 1510 | end |
| 1511 | end |
| 1512 | ret s |
| 1513 | end |
| 1514 | |
| 1515 | note task r-020 count |
| 1516 | note say return how many of the first n items are smaller than the first item |
| 1517 | fn t121 a view ulong 8 n ulong to ulong |
| 1518 | c = ulong 0 |
| 1519 | for i ulong n |
| 1520 | if lt get a i get a 0 |
| 1521 | c = add c 1 |
| 1522 | end |
| 1523 | end |
| 1524 | ret c |
| 1525 | end |
| 1526 | |
| 1527 | note task r-021 scan |
| 1528 | note say return the index of the last odd item among the first n items, or n when none of them is odd |
| 1529 | fn t122 a view ulong 8 n ulong to ulong |
| 1530 | k = n |
| 1531 | for i ulong n |
| 1532 | if eq rem get a i 2 1 |
| 1533 | k = i |
| 1534 | end |
| 1535 | end |
| 1536 | ret k |
| 1537 | end |
| 1538 | |
| 1539 | note task r-022 fold |
| 1540 | note say return the sum of those of the first n items that are even |
| 1541 | fn t123 a view ulong 8 n ulong to ulong |
| 1542 | s = ulong 0 |
| 1543 | for i ulong n |
| 1544 | x = get a i |
| 1545 | if eq rem x 2 0 |
| 1546 | s = add s x |
| 1547 | end |
| 1548 | end |
| 1549 | ret s |
| 1550 | end |
| 1551 | |
| 1552 | note task r-023 fold |
| 1553 | note say return the largest sum of two neighbouring items among the first n items, or zero when n is below 2 |
| 1554 | fn t124 a view ulong 8 n ulong to ulong |
| 1555 | m = ulong 0 |
| 1556 | for i ulong n |
| 1557 | if gt i 0 |
| 1558 | s = add get a i get a sub i 1 |
| 1559 | if gt s m |
| 1560 | m = s |
| 1561 | end |
| 1562 | end |
| 1563 | end |
| 1564 | ret m |
| 1565 | end |
| 1566 | |
| 1567 | note task r-024 scan |
| 1568 | note say return 1 when some value occurs more than once among the first n items, otherwise 0 |
| 1569 | fn t125 a view ulong 8 n ulong to ulong |
| 1570 | for i ulong n |
| 1571 | for j ulong i |
| 1572 | if eq get a j get a i |
| 1573 | ret 1 |
| 1574 | end |
| 1575 | end |
| 1576 | end |
| 1577 | ret 0 |
| 1578 | end |
| 1579 | |
| 1580 | note task r-025 fold |
| 1581 | note say return the remainder of the sum of the first n items divided by 7 |
| 1582 | fn t126 a view ulong 8 n ulong to ulong |
| 1583 | s = ulong 0 |
| 1584 | for i ulong n |
| 1585 | s = add s get a i |
| 1586 | end |
| 1587 | ret rem s 7 |
| 1588 | end |
| 1589 | |
| 1590 | note task r-026 count |
| 1591 | note say return how many of the first n items are equal to their own index |
| 1592 | fn t127 a view ulong 8 n ulong to ulong |
| 1593 | c = ulong 0 |
| 1594 | for i ulong n |
| 1595 | if eq get a i i |
| 1596 | c = add c 1 |
| 1597 | end |
| 1598 | end |
| 1599 | ret c |
| 1600 | end |
| 1601 | |
| 1602 | note task r-027 select |
| 1603 | note say return the smallest item that is not zero among the first n items, or zero when all of them are zero |
| 1604 | fn t128 a view ulong 8 n ulong to ulong |
| 1605 | m = ulong 0 |
| 1606 | for i ulong n |
| 1607 | x = get a i |
| 1608 | if ne x 0 |
| 1609 | if eq m 0 |
| 1610 | m = x |
| 1611 | end |
| 1612 | if lt x m |
| 1613 | m = x |
| 1614 | end |
| 1615 | end |
| 1616 | end |
| 1617 | ret m |
| 1618 | end |
| 1619 | |
| 1620 | note task r-028 fold |
| 1621 | note say return the greatest common divisor of the first n items, ignoring zeros, or zero when there is nothing but zeros |
| 1622 | fn t129 a view ulong 8 n ulong to ulong |
| 1623 | g = ulong 0 |
| 1624 | for i ulong n |
| 1625 | y = get a i |
| 1626 | while ne y 0 bound 200 |
| 1627 | t = rem g y |
| 1628 | g = y |
| 1629 | y = t |
| 1630 | end |
| 1631 | end |
| 1632 | ret g |
| 1633 | end |
| 1634 | |
| 1635 | note task r-029 count |
| 1636 | note say return how many of the first n items are multiples of 3, zero included |
| 1637 | fn t130 a view ulong 8 n ulong to ulong |
| 1638 | c = ulong 0 |
| 1639 | for i ulong n |
| 1640 | if eq rem get a i 3 0 |
| 1641 | c = add c 1 |
| 1642 | end |
| 1643 | end |
| 1644 | ret c |
| 1645 | end |
| 1646 | |
| 1647 | note task r-030 fold |
| 1648 | note say return the sum of the items at even indexes minus the sum of the items at odd indexes among the first n items, or zero when the odd sum is larger |
| 1649 | fn t131 a view ulong 8 n ulong to ulong |
| 1650 | e = ulong 0 |
| 1651 | o = ulong 0 |
| 1652 | for i ulong n |
| 1653 | if eq rem i 2 0 |
| 1654 | e = add e get a i |
| 1655 | else |
| 1656 | o = add o get a i |
| 1657 | end |
| 1658 | end |
| 1659 | if gt o e |
| 1660 | ret 0 |
| 1661 | end |
| 1662 | ret sub e o |
| 1663 | end |
| 1664 | |
| 1665 | note task r-031 scan |
| 1666 | note say return the first of the first n items that is greater than 5, or zero when none is |
| 1667 | fn t132 a view ulong 8 n ulong to ulong |
| 1668 | for i ulong n |
| 1669 | if gt get a i 5 |
| 1670 | ret get a i |
| 1671 | end |
| 1672 | end |
| 1673 | ret 0 |
| 1674 | end |
| 1675 | |
| 1676 | note task r-032 fold |
| 1677 | note say return the largest of the first n items multiplied by n |
| 1678 | fn t133 a view ulong 8 n ulong to ulong |
| 1679 | m = ulong 0 |
| 1680 | for i ulong n |
| 1681 | if gt get a i m |
| 1682 | m = get a i |
| 1683 | end |
| 1684 | end |
| 1685 | ret mul m n |
| 1686 | end |
| 1687 | |
| 1688 | note ======== the first n items of an array, changed in place |
| 1689 | |
| 1690 | note task w-001 rewrite |
| 1691 | note say reverse the order of the first n items |
| 1692 | fn t134 a edit ulong 8 n ulong to void |
| 1693 | i = ulong 0 |
| 1694 | j = n |
| 1695 | while lt add i 1 j bound 8 |
| 1696 | j = sub j 1 |
| 1697 | x = get a i |
| 1698 | put a i get a j |
| 1699 | put a j x |
| 1700 | i = add i 1 |
| 1701 | end |
| 1702 | end |
| 1703 | |
| 1704 | note task w-002 rewrite |
| 1705 | note say replace each of the first n items with its square |
| 1706 | fn t135 a edit ulong 8 n ulong to void |
| 1707 | for i ulong n |
| 1708 | x = get a i |
| 1709 | put a i mul x x |
| 1710 | end |
| 1711 | end |
| 1712 | |
| 1713 | note task w-003 rewrite |
| 1714 | note say replace each of the first n items with its index |
| 1715 | fn t136 a edit ulong 8 n ulong to void |
| 1716 | for i ulong n |
| 1717 | put a i i |
| 1718 | end |
| 1719 | end |
| 1720 | |
| 1721 | note task w-004 rewrite |
| 1722 | note say replace each of the first n items with the sum of all items up to and including it |
| 1723 | fn t137 a edit ulong 8 n ulong to void |
| 1724 | s = ulong 0 |
| 1725 | for i ulong n |
| 1726 | s = add s get a i |
| 1727 | put a i s |
| 1728 | end |
| 1729 | end |
| 1730 | |
| 1731 | note task w-005 rewrite |
| 1732 | note say exchange the first item with the second, the third with the fourth and so on within the first n items, leaving an unpaired last item alone |
| 1733 | fn t138 a edit ulong 8 n ulong to void |
| 1734 | i = ulong 0 |
| 1735 | while lt add i 1 n bound 8 |
| 1736 | x = get a i |
| 1737 | put a i get a add i 1 |
| 1738 | put a add i 1 x |
| 1739 | i = add i 2 |
| 1740 | end |
| 1741 | end |
| 1742 | |
| 1743 | note task w-006 rewrite |
| 1744 | note say replace every zero among the first n items with 9 |
| 1745 | fn t139 a edit ulong 8 n ulong to void |
| 1746 | for i ulong n |
| 1747 | if eq get a i 0 |
| 1748 | put a i 9 |
| 1749 | end |
| 1750 | end |
| 1751 | end |
| 1752 | |
| 1753 | note task w-007 rewrite |
| 1754 | note say sort the first n items into ascending order |
| 1755 | fn t140 a edit ulong 8 n ulong to void |
| 1756 | for i ulong n |
| 1757 | for j ulong n |
| 1758 | if gt j 0 |
| 1759 | x = get a sub j 1 |
| 1760 | y = get a j |
| 1761 | if gt x y |
| 1762 | put a sub j 1 y |
| 1763 | put a j x |
| 1764 | end |
| 1765 | end |
| 1766 | end |
| 1767 | end |
| 1768 | end |
| 1769 | |
| 1770 | note task w-008 rewrite |
| 1771 | note say move each of the first n items one place towards the front and put the first item at index n minus one |
| 1772 | fn t141 a edit ulong 8 n ulong to void |
| 1773 | if lt n 2 |
| 1774 | ret |
| 1775 | end |
| 1776 | f = get a 0 |
| 1777 | for i ulong n |
| 1778 | if gt i 0 |
| 1779 | put a sub i 1 get a i |
| 1780 | end |
| 1781 | end |
| 1782 | put a sub n 1 f |
| 1783 | end |
| 1784 | |
| 1785 | note task w-009 rewrite |
| 1786 | note say move each of the first n items one place towards the back and put the item from index n minus one at the front |
| 1787 | fn t142 a edit ulong 8 n ulong to void |
| 1788 | if lt n 2 |
| 1789 | ret |
| 1790 | end |
| 1791 | l = get a sub n 1 |
| 1792 | i = sub n 1 |
| 1793 | while gt i 0 bound 8 |
| 1794 | put a i get a sub i 1 |
| 1795 | i = sub i 1 |
| 1796 | end |
| 1797 | put a 0 l |
| 1798 | end |
| 1799 | |
| 1800 | note task w-010 rewrite |
| 1801 | note say replace each of the first n items with the largest item from the start up to and including it |
| 1802 | fn t143 a edit ulong 8 n ulong to void |
| 1803 | m = ulong 0 |
| 1804 | for i ulong n |
| 1805 | if gt get a i m |
| 1806 | m = get a i |
| 1807 | end |
| 1808 | put a i m |
| 1809 | end |
| 1810 | end |
| 1811 | |
| 1812 | note task w-011 rewrite |
| 1813 | note say replace every odd item among the first n items with zero |
| 1814 | fn t144 a edit ulong 8 n ulong to void |
| 1815 | for i ulong n |
| 1816 | if eq rem get a i 2 1 |
| 1817 | put a i 0 |
| 1818 | end |
| 1819 | end |
| 1820 | end |
| 1821 | |
| 1822 | note task w-012 rewrite |
| 1823 | note say replace each of the first n items except the first with itself minus the original value of the item before it, with wrapping arithmetic |
| 1824 | fn t145 a edit ulong 8 n ulong to void |
| 1825 | p = ulong 0 |
| 1826 | for i ulong n |
| 1827 | x = get a i |
| 1828 | if gt i 0 |
| 1829 | put a i sub x p |
| 1830 | end |
| 1831 | p = x |
| 1832 | end |
| 1833 | end |
| 1834 | |
| 1835 | note task w-013 rewrite |
| 1836 | note say set each of the first n items to the value of the first item |
| 1837 | fn t146 a edit ulong 8 n ulong to void |
| 1838 | for i ulong n |
| 1839 | put a i get a 0 |
| 1840 | end |
| 1841 | end |
| 1842 | |
| 1843 | note task w-014 rewrite |
| 1844 | note say replace each of the first n items with n minus its index |
| 1845 | fn t147 a edit ulong 8 n ulong to void |
| 1846 | for i ulong n |
| 1847 | put a i sub n i |
| 1848 | end |
| 1849 | end |
| 1850 | |
| 1851 | note task w-015 rewrite |
| 1852 | note say halve every even item among the first n items and leave the odd items alone |
| 1853 | fn t148 a edit ulong 8 n ulong to void |
| 1854 | for i ulong n |
| 1855 | x = get a i |
| 1856 | if eq rem x 2 0 |
| 1857 | put a i div x 2 |
| 1858 | end |
| 1859 | end |
| 1860 | end |
| 1861 | |
| 1862 | note task w-016 rewrite |
| 1863 | note say replace every item above 5 among the first n items with 5 |
| 1864 | fn t149 a edit ulong 8 n ulong to void |
| 1865 | for i ulong n |
| 1866 | if gt get a i 5 |
| 1867 | put a i 5 |
| 1868 | end |
| 1869 | end |
| 1870 | end |
| 1871 | |
| 1872 | note task w-017 rewrite |
| 1873 | note say sort the first n items into descending order |
| 1874 | fn t150 a edit ulong 8 n ulong to void |
| 1875 | for i ulong n |
| 1876 | for j ulong n |
| 1877 | if gt j 0 |
| 1878 | x = get a sub j 1 |
| 1879 | y = get a j |
| 1880 | if lt x y |
| 1881 | put a sub j 1 y |
| 1882 | put a j x |
| 1883 | end |
| 1884 | end |
| 1885 | end |
| 1886 | end |
| 1887 | end |
| 1888 | |
| 1889 | note task w-018 rewrite |
| 1890 | note say move every zero among the first n items to the end of those n items, keeping the other items in their order |
| 1891 | fn t151 a edit ulong 8 n ulong to void |
| 1892 | k = ulong 0 |
| 1893 | for i ulong n |
| 1894 | x = get a i |
| 1895 | if ne x 0 |
| 1896 | put a k x |
| 1897 | k = add k 1 |
| 1898 | end |
| 1899 | end |
| 1900 | while lt k n bound 8 |
| 1901 | put a k 0 |
| 1902 | k = add k 1 |
| 1903 | end |
| 1904 | end |
| 1905 | |
| 1906 | note task w-019 rewrite |
| 1907 | note say replace each of the first n items with the number of items before it whose original value is smaller than its own |
| 1908 | fn t152 a edit ulong 8 n ulong to void |
| 1909 | i = n |
| 1910 | while gt i 0 bound 8 |
| 1911 | i = sub i 1 |
| 1912 | c = ulong 0 |
| 1913 | for j ulong i |
| 1914 | if lt get a j get a i |
| 1915 | c = add c 1 |
| 1916 | end |
| 1917 | end |
| 1918 | put a i c |
| 1919 | end |
| 1920 | end |
| 1921 | |
| 1922 | note task w-020 rewrite |
| 1923 | note say copy the first item into every even index among the first n items |
| 1924 | fn t153 a edit ulong 8 n ulong to void |
| 1925 | for i ulong n |
| 1926 | if eq rem i 2 0 |
| 1927 | put a i get a 0 |
| 1928 | end |
| 1929 | end |
| 1930 | end |
| 1931 | |
| 1932 | note task w-021 rewrite |
| 1933 | note say add its own index to each of the first n items |
| 1934 | fn t154 a edit ulong 8 n ulong to void |
| 1935 | for i ulong n |
| 1936 | put a i add get a i i |
| 1937 | end |
| 1938 | end |
| 1939 | |
| 1940 | note task w-022 rewrite |
| 1941 | note say replace every item that is not zero among the first n items with 1 |
| 1942 | fn t155 a edit ulong 8 n ulong to void |
| 1943 | for i ulong n |
| 1944 | if ne get a i 0 |
| 1945 | put a i 1 |
| 1946 | end |
| 1947 | end |
| 1948 | end |
| 1949 | |
| 1950 | note task w-023 rewrite |
| 1951 | note say exchange the first item with the item at index n minus one and leave everything else alone |
| 1952 | fn t156 a edit ulong 8 n ulong to void |
| 1953 | if lt n 2 |
| 1954 | ret |
| 1955 | end |
| 1956 | x = get a 0 |
| 1957 | put a 0 get a sub n 1 |
| 1958 | put a sub n 1 x |
| 1959 | end |
| 1960 | |
| 1961 | note task w-024 rewrite |
| 1962 | note say add to each of the first n items except the last of them the original value of the item after it |
| 1963 | fn t157 a edit ulong 8 n ulong to void |
| 1964 | for i ulong n |
| 1965 | if lt add i 1 n |
| 1966 | put a i add get a i get a add i 1 |
| 1967 | end |
| 1968 | end |
| 1969 | end |
| 1970 | |
| 1971 | note task w-025 rewrite |
| 1972 | note say multiply each of the first n items by the original value of the first item |
| 1973 | fn t158 a edit ulong 8 n ulong to void |
| 1974 | if eq n 0 |
| 1975 | ret |
| 1976 | end |
| 1977 | f = get a 0 |
| 1978 | for i ulong n |
| 1979 | put a i mul get a i f |
| 1980 | end |
| 1981 | end |
| 1982 | |
| 1983 | note task w-026 rewrite |
| 1984 | note say replace each of the first n items with its remainder when divided by 4 |
| 1985 | fn t159 a edit ulong 8 n ulong to void |
| 1986 | for i ulong n |
| 1987 | put a i rem get a i 4 |
| 1988 | end |
| 1989 | end |
| 1990 | |
| 1991 | note task w-027 rewrite |
| 1992 | note say replace each of the first n items with the smallest item from the start up to and including it |
| 1993 | fn t160 a edit ulong 8 n ulong to void |
| 1994 | if eq n 0 |
| 1995 | ret |
| 1996 | end |
| 1997 | m = get a 0 |
| 1998 | for i ulong n |
| 1999 | if lt get a i m |
| 2000 | m = get a i |
| 2001 | end |
| 2002 | put a i m |
| 2003 | end |
| 2004 | end |
| 2005 | |
| 2006 | note task w-028 rewrite |
| 2007 | note say set the first n items to 1, 2, 4, 8 and so on, each twice the one before |
| 2008 | fn t161 a edit ulong 8 n ulong to void |
| 2009 | p = ulong 1 |
| 2010 | for i ulong n |
| 2011 | put a i p |
| 2012 | p = mul p 2 |
| 2013 | end |
| 2014 | end |
| 2015 | |
| 2016 | note task w-029 rewrite |
| 2017 | note say replace every item among the first n that is larger than the first item with the value of the first item |
| 2018 | fn t162 a edit ulong 8 n ulong to void |
| 2019 | if eq n 0 |
| 2020 | ret |
| 2021 | end |
| 2022 | f = get a 0 |
| 2023 | for i ulong n |
| 2024 | if gt get a i f |
| 2025 | put a i f |
| 2026 | end |
| 2027 | end |
| 2028 | end |
| 2029 | |
| 2030 | note task w-030 rewrite |
| 2031 | note say replace each of the first n items with the number of items among the original first n that have the same value as it |
| 2032 | fn t163 a edit ulong 8 n ulong to void |
| 2033 | t = new ulong 8 0 |
| 2034 | for i ulong n |
| 2035 | c = ulong 0 |
| 2036 | for j ulong n |
| 2037 | if eq get a j get a i |
| 2038 | c = add c 1 |
| 2039 | end |
| 2040 | end |
| 2041 | put t i c |
| 2042 | end |
| 2043 | for k ulong n |
| 2044 | put a k get t k |
| 2045 | end |
| 2046 | end |
| 2047 | |
| 2048 | note task w-031 rewrite |
| 2049 | note say exchange the smallest and the largest of the first n items, taking the lowest index when a value occurs more than once |
| 2050 | fn t164 a edit ulong 8 n ulong to void |
| 2051 | if eq n 0 |
| 2052 | ret |
| 2053 | end |
| 2054 | lo = ulong 0 |
| 2055 | hi = ulong 0 |
| 2056 | for i ulong n |
| 2057 | if lt get a i get a lo |
| 2058 | lo = i |
| 2059 | end |
| 2060 | if gt get a i get a hi |
| 2061 | hi = i |
| 2062 | end |
| 2063 | end |
| 2064 | x = get a lo |
| 2065 | put a lo get a hi |
| 2066 | put a hi x |
| 2067 | end |
| 2068 | |
| 2069 | note task w-032 rewrite |
| 2070 | note say add to each of the first n items the original value of the item mirrored across the middle of those n items, so the first gets the last, the second the one before the last, and a middle item is doubled |
| 2071 | fn t165 a edit ulong 8 n ulong to void |
| 2072 | i = ulong 0 |
| 2073 | j = n |
| 2074 | while lt i j bound 8 |
| 2075 | j = sub j 1 |
| 2076 | s = add get a i get a j |
| 2077 | put a i s |
| 2078 | put a j s |
| 2079 | i = add i 1 |
| 2080 | end |
| 2081 | end |