interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / train / omega-llm / tools / bench / tasks.om

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