-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtrain_set.jsonl
More file actions
1134 lines (1134 loc) · 911 KB
/
train_set.jsonl
File metadata and controls
1134 lines (1134 loc) · 911 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc toUpperCase(s: ref[String]): String {\n\tdef result: String = \"\";\n def i: Int;\n\tdef c: Char;\n\tfor i = 0 , i < s.getLength() , i++ {\n\t\tif (s(i) >= 'a' && s(i) <= 'z') {\n\t\t\tc = s(i) - 'a' + 'A';\n\t\t}\n\t\telse {\n\t\t\tc = s(i);\n\t\t}\n\t\tresult += c;\n\t}\n\treturn result;\n}\n"}, {"role": "assistant", "content": "function toUpperCase(s) {\n let result = '';\n for(let i = 0; i < s.length; i++){\n let code = s.charCodeAt(i);\n if(code >= 97 && code <= 122){\n result += String.fromCharCode(code - 97 + 65);\n } else {\n result += s[i];\n }\n }\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/ريـاضيات\"؛\n\nاستخدم مـتم؛\n\n\nدالة طويلة_شعاع(شعاع: سند[مـصفوفة[عـائم[64]]]): عـائم[64] {\n\tعرف مجموع: عـائم[64] = 0؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < شعاع.هات_الطول() ، دليل++ {\n\t\tمجموع += شعاع(دليل) * شعاع(دليل)؛\n\t}\n\t\n\tارجع ريـاضيات.جذر(مجموع)؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"Srl/Math\";\n\nuse Srl;\n\n\nfunc vectorNorm(vector: ref[Array[Float[64]]]): Float[64] {\n def sum: Float[64] = 0;\n\n def i: Int;\n for i = 0 , i < vector.getLength() , i++ {\n sum += vector(i) * vector(i);\n }\n\n return Math.sqrt(sum);\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\n#include <stdlib.h>\n\nint* multiply(int** a, int* v, int rows, int cols) {\n int i, j;\n // Create a result vector dynamically\n int* result = (int*)malloc(rows * sizeof(int));\n\n // Initialize the result vector with 0\n for(i = 0; i < rows; i++) {\n result[i] = 0;\n }\n\n // Multiply the matrix by the vector\n for(i = 0; i < rows; i++) {\n for(j = 0; j < cols; j++) {\n result[i] += a[i][j] * v[j];\n }\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\ndef Matrix: alias Array[Array[Float[64]]];\ndef Vector: alias Array[Float[64]];\n\n\nfunc multiply(m: ref[Matrix], v: ref[Vector]): Vector {\n def rows: Int = m.getLength();\n def cols: Int = m(0).getLength();\n \n def result: Vector;\n\n def i: Int;\n def j: Int;\n for i = 0 , i < rows , i++ {\n result.add(0);\n for j = 0 , j < cols , j++ {\n result(i) += m(i)(j) * v(j);\n }\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\n#include <stdio.h>\n\n#define MAX 100\n\nint visited[MAX];\nint matrix[MAX][MAX];\n\nint DFS(int v, int parent, int n) {\n visited[v] = 1;\n for(int i = 0; i < n; i++) {\n if(matrix[v][i] == 1) {\n if(!visited[i]) {\n if(DFS(i, v, n)) {\n return 1;\n }\n } else if(i != parent) {\n return 1;\n }\n }\n }\n return 0;\n}\n\nint isTree(int n) {\n if(DFS(0, -1, n)) {\n return 0;\n }\n for(int i = 0; i < n; i++) {\n if(!visited[i]) {\n return 0;\n }\n }\n return 1;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\nfunc dfs(node: Int, parentNode: Int, visited: ref[Array[Bool]], graph: ref[Array[Array[Int]]]): Bool {\n visited(node) = true;\n\n def i: Int;\n for i = 0 , i < graph(node).getLength(), i++ {\n def childNode: Int = graph(node)(i);\n if !visited(childNode) {\n if dfs(childNode, node, visited, graph) {\n return true;\n }\n }\n else if childNode != parentNode {\n return true;\n }\n }\n return false;\n}\n\n\nfunc isTree(graph: ref[Array[Array[Int]]]): Bool {\n def visited: Array[Bool];\n def i: Int;\n for i = 0 , i < graph.getLength() , i++ {\n visited.add(false);\n }\n\n if dfs(0, -1, visited, graph) {\n return false;\n }\n\n for i = 0 , i < graph.getLength() , i++ {\n if !visited(i) {\n return false;\n }\n }\n\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc initializeArray(a: ref[Array[Int]], size: Int, val: Int) {\n def i: Int;\n for i = 0, i < size, i++ {\n a.add(val);\n }\n}\n"}, {"role": "assistant", "content": "void initializeArray(int* arr, int size, int value) {\n for(int i = 0; i < size; i++) {\n arr[i] = value;\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\n#include <math.h>\n\ndouble std(int data[], int n, float mean)\n{\n double variance = 0.0;\n\n for(int i=0; i<n; ++i)\n variance += (data[i] - mean) * (data[i] - mean);\n\n return sqrt(variance/n);\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/ريـاضيات\"؛\n\nاستخدم مـتم؛\n\n\nدالة انحراف_معياري(م: سند[مـصفوفة[صـحيح]]، متوسط: عـائم): عـائم {\n\tعرف حجم: صـحيح = م.هات_الطول()؛\n\tعرف تباين: عـائم = 0؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < حجم ، دليل++ {\n\t\tتباين += (م(دليل) - متوسط) * (م(دليل) - متوسط)؛\n\t}\n\t\n\tارجع ريـاضيات.جذر(تباين / حجم)؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Array\";\nimport \"Srl/Console\";\n\nuse Srl;\n\nfunc dfs(node: Int, visited: ref[Array[Bool]], graph: ref[Array[Array[Int]]]) {\n visited(node) = true;\n Console.print(\"%d \", node);\n\n def i: Int;\n for i = 0 , i < graph(node).getLength(), i++ {\n def childNode: Int = graph(node)(i);\n if !visited(childNode) {\n dfs(childNode, visited, graph);\n }\n }\n}\n"}, {"role": "assistant", "content": "function dfs(node, visited, G) {\n visited[node] = true;\n console.log(node);\n\n for(let i = 0; i < G[node].length; i++) {\n if(!visited[G[node][i]]) {\n dfs(G[node][i], visited, G);\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc starts_with(s: ref[String], prefix: ref[String]): Bool {\n\tif s.getLength() < prefix.getLength() {\n\t\treturn false;\n\t}\n\n def i: Int;\n\tfor i = 0 , i < prefix.getLength() , i++ {\n\t\tif (prefix(i) != s(i)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n"}, {"role": "assistant", "content": "check if a given string starts with another given string"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, تحقق فيما إذا كان بيان غير موجه معطى يمثل شجرة"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nدالة دفس(عقدة: صـحيح، العقدة_الأب: صـحيح، مزارة: سند[مـصفوفة[ثـنائي]]، بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]): ثـنائي {\n\tمزارة(عقدة) = صح؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان(عقدة).هات_الطول() ، دليل++ {\n\t\tعرف عقدة_ابن: صـحيح = بيان(عقدة)(دليل)؛\n\t\tإذا !مزارة(عقدة_ابن) {\n\t\t\tإذا دفس(عقدة_ابن، عقدة، مزارة، بيان) {\n\t\t\t\tارجع صح؛\n\t\t\t}\n\t\t}\n\t\tوإلا إذا عقدة_ابن != العقدة_الأب {\n\t\t\tارجع صح؛\n\t\t}\n\t}\n\tارجع خطأ؛\n}\n\n\nدالة هل_شجرة(بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]): ثـنائي {\n\tعرف مزارة: مـصفوفة[ثـنائي]؛\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان.هات_الطول() ، دليل++ {\n\t\tمزارة.أضف(خطأ)؛\n\t}\n\t\n\tإذا دفس(0، -1، مزارة، بيان) {\n\t\tارجع خطأ؛\n\t}\n\t\n\tعرف عدد_المكونات: صـحيح = 0؛\n\tلكل دليل = 0 ، دليل < بيان.هات_الطول() ، دليل++ {\n\t\tإذا !مزارة(دليل) {\n\t\t\tارجع خطأ؛\n\t\t}\n\t}\n\t\n\tارجع صح؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc slice(a: ref[Array[Int]], start: Int, end: Int, result: ref[Array[Int]]) {\n def i: Int;\n for i = start , i <= end , i++ {\n result.add(a(i));\n }\n}\n"}, {"role": "assistant", "content": "void slice(int arr[], int start, int end, int result[]) {\n int i;\n for(i = start; i <= end; i++) {\n result[i - start] = arr[i];\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction calculateMean(arr) {\n var sum = 0;\n for (var i = 0; i < arr.length; i++) {\n sum += arr[i];\n }\n return sum / arr.length;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"Srl/Math\";\n\n\nuse Srl;\n\n\nfunc mean(a: ref[Array[Int]]): Float {\n def size: Int = a.getLength();\n def sum: Int = 0;\n\n def i: Int;\n for i = 0 , i < size , i++ {\n sum += a(i);\n }\n\n return sum~cast[Float] / size;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة اعكس_نص(س: نـص): نـص {\n\tعرف طول: صـحيح = س.هات_الطول()؛\n\tعرف نتيجة: نـص = \"\"؛\n\n\tعرف دليل: صـحيح؛\n\tلكل دليل = طول - 1 ، دليل >= 0 ، دليل-- {\n\t\tنتيجة.ألحق(س(دليل))؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "اعكس السلسلة النصية المعطاة س و أرجع النتيجة"}]}
{"messages": [{"role": "user", "content": "Using c, Calculate the product of a given matrix, represented as 2D array, and a given vector, represented as an array, and return the result"}, {"role": "assistant", "content": "#include <stdlib.h>\n\nint* multiply(int** a, int* v, int rows, int cols) {\n int i, j;\n // Create a result vector dynamically\n int* result = (int*)malloc(rows * sizeof(int));\n\n // Initialize the result vector with 0\n for(i = 0; i < rows; i++) {\n result[i] = 0;\n }\n\n // Multiply the matrix by the vector\n for(i = 0; i < rows; i++) {\n for(j = 0; j < cols; j++) {\n result[i] += a[i][j] * v[j];\n }\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة لكل_عنصر(م: سند[مـصفوفة[صـحيح]]، د: مغلفة(عنصر: صـحيح): صـحيح) {\n\tعرف دليل: صـحيح؛\n\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tم(دليل) = د(م(دليل))؛\n\t}\n}\n"}, {"role": "assistant", "content": "void foreach(int a[], int n, int (*f)(int)) {\n for(int i = 0; i < n; i++) {\n a[i] = f(a[i]);\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\nvoid toUpperCase(char *s, char *result) {\n for(int i = 0; s[i]; i++){\n if(s[i] >= 'a' && s[i] <= 'z'){\n result[i] = s[i] - 'a' + 'A';\n }\n else {\n result[i] = s[i];\n }\n }\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة إلى_حالة_كبيرة(س: سند[نـص]): نـص {\n\tعرف نتيجة: نـص = \"\"؛\n\n\tعرف دليل: صـحيح؛\n\tعرف م: مـحرف؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) >= 'a' && س(دليل) <= 'z' {\n\t\t\tم = س(دليل) - 'a' + 'A'؛\n\t\t}\n\t\tوإلا {\n\t\t\tم = س(دليل)؛\n\t\t}\n\t\tنتيجة += م؛\n\t}\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc char_exists(s: ref[String], c: Char): Bool {\n def i: Int;\n\tfor i = 0 , i < s.getLength() , i++ {\n\t\tif (s(i) == c) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n"}, {"role": "assistant", "content": "check if a given string contains a given char"}]}
{"messages": [{"role": "user", "content": "What this code do?\n#include <stdbool.h>\n\nbool exists(int a[], int n, int val) {\n for (int i = 0; i < n; i++) {\n if (a[i] == val) {\n return true;\n }\n }\n return false;\n}\n"}, {"role": "assistant", "content": "check if a given array contains a given element"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Math\";\nimport \"Srl/Array\";\n\n\n\nuse Srl;\n\nclass Point {\n def x : Float;\n def y : Float;\n};\n\nfunc calculateDistance(a: Point, b: Point): Float {\n return Math.sqrt(Math.pow(b.x - a.x, 2.0) + Math.pow(b.y - a.y, 2.0));\n}\n\nfunc findClosestPoint(givenPoint: Point, points: ref[Array[Point]]): Point {\n def minDistance: Float = calculateDistance(givenPoint, points(0));\n def closestPoint: Point = points(0);\n\n def i: Int;\n for i = 1 , i < points.getLength() , i++ {\n def distance: Float = calculateDistance(givenPoint, points(i));\n if distance < minDistance {\n minDistance = distance;\n closestPoint = points(i);\n }\n }\n\n return closestPoint;\n}\n"}, {"role": "assistant", "content": "class Point {\n constructor(x, y) {\n this.x = x;\n this.y = y;\n }\n}\n\nfunction calculateDistance(a, b) {\n return Math.sqrt(Math.pow(b.x - a.x, 2) + Math.pow(b.y - a.y, 2));\n}\n\nfunction findClosestPoint(givenPoint, points) {\n let minDistance = calculateDistance(givenPoint, points[0]);\n let closestPoint = points[0];\n \n for(let i = 1; i < points.length; i++) {\n let distance = calculateDistance(givenPoint, points[i]);\n if(distance < minDistance) {\n minDistance = distance;\n closestPoint = points[i];\n }\n }\n \n return closestPoint;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, check if a given array contains a given element"}, {"role": "assistant", "content": "#include <stdbool.h>\n\nbool exists(int a[], int n, int val) {\n for (int i = 0; i < n; i++) {\n if (a[i] == val) {\n return true;\n }\n }\n return false;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\n#include <stdbool.h>\n\nbool isPrime(int num) {\n if (num <= 1) {\n return false;\n }\n for (int i = 2; i * i <= num; i++) {\n if (num % i == 0) {\n return false;\n }\n }\n return true;\n}\n"}, {"role": "assistant", "content": "Check whether a given number is prime or not and return that result"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc exists(a: ref[Array[Int]], val: Int): Bool {\n def i: Int;\n for i = 0, i < a.getLength(), i++ {\n if a(i) == val {\n return true;\n }\n }\n return false;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة موجود(م: سند[مـصفوفة[صـحيح]]، قيمة: صـحيح): ثـنائي {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا م(دليل) == قيمة {\n\t\t\tارجع صح؛\n\t\t}\n\t}\n\tارجع خطأ؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\n#include <stdbool.h>\n\nvoid filter(int a[], int size, int result[], int *newSize, bool (*condition)(int)) {\n *newSize = 0;\n for (int i = 0; i < size; i++) {\n if (condition(a[i])) {\n result[(*newSize)++] = a[i];\n }\n }\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة فلتر(م: سند[مـصفوفة[صـحيح]]، د: مغلفة(رقم: صـحيح): ثـنائي): مـصفوفة[صـحيح] {\n\tعرف نتيجة: مـصفوفة[صـحيح]؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا د(م(دليل)) {\n\t\t\tنتيجة.أضف(م(دليل))؛\n\t\t}\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/نـص\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جزئ(س: سند[نـص]، رمز: مـحرف): مـصفوفة[نـص] {\n\tعرف نتيجة: مـصفوفة[نـص]؛\n\t\n\tعرف مؤقت: نـص؛\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) != رمز {\n\t\t\tمؤقت.ألحق(س(دليل))؛\n\t\t}\n\t\tوإلا {\n\t\t\tنتيجة.أضف(مؤقت)؛\n\t\t\tمؤقت = \"\"؛\n\t\t}\n\t}\n\tنتيجة.أضف(مؤقت)؛\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "جزئ نص معطى إلى لائحة من النصوص بناء على محرف معطى"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Array\";\nimport \"closure\";\n\n\nuse Srl;\n\n\nfunc check_any(a: ref[Array[Int]], f: closure (num: Int): Bool): Bool {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if f(a(i)) {\n return true;\n }\n }\n\n return false;\n}\n"}, {"role": "assistant", "content": "#include <stdbool.h>\n\n// Criteria function that checks if a number is positive\nbool criteria(int num) {\n return num > 0;\n}\n\n// Function to check all elements in an array\nbool check_any(int arr[], int size) {\n for(int i = 0; i < size; i++) {\n if(criteria(arr[i])) {\n return true;\n }\n }\n return false;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة الترتيب_بالحشر(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف دليل1: صـحيح؛\n\tعرف مفتاح: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\t\n\tلكل دليل1 = 1 ، دليل1 < م.هات_الطول() ، دليل1++ {\n\t\tمفتاح = م(دليل1)؛\n\t\tدليل2 = دليل1 - 1؛\n\t\t\n\t\tبينما دليل2 >= 0 && م(دليل2) > مفتاح {\n\t\t\tم(دليل2 + 1) = م(دليل2)؛\n\t\t\tدليل2 = دليل2 - 1؛\n\t\t}\n\t\tم(دليل2 + 1) = مفتاح؛\n\t}\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\n\nfunc insertionSort(a: ref[Array[Int]]) {\n def i: Int;\n def key: Int;\n def j: Int;\n\n for i = 1 , i < a.getLength() , i++ {\n key = a(i);\n j = i - 1;\n\n while j >= 0 && a(j) > key {\n a(j + 1) = a(j);\n j = j - 1;\n }\n a(j + 1) = key;\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, calculate and return the mean of the given array"}, {"role": "assistant", "content": "function calculateMean(arr) {\n var sum = 0;\n for (var i = 0; i < arr.length; i++) {\n sum += arr[i];\n }\n return sum / arr.length;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, Check if any element in a given array satisfy a criteria defined by a function with boolean return value"}, {"role": "assistant", "content": "#include <stdbool.h>\n\n// Criteria function that checks if a number is positive\nbool criteria(int num) {\n return num > 0;\n}\n\n// Function to check all elements in an array\nbool check_any(int arr[], int size) {\n for(int i = 0; i < size; i++) {\n if(criteria(arr[i])) {\n return true;\n }\n }\n return false;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة اجتزئ(س: سند[نـص]، بداية: صـحيح، نهاية: صـحيح): نـص {\n\tعرف نتيجة: نـص = \"\"؛\n\n\tعرف دليل: صـحيح؛\n\tلكل دليل = بداية ، دليل <= نهاية ، دليل++ {\n\t\tنتيجة.ألحق(س(دليل))؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/String\";\n\nuse Srl;\n\nfunc slice(s: ref[String], start: Int, end: Int): String {\n def result: String = \"\";\n\n def i: Int;\n for i = start , i <= end , i++ {\n result.append(s(i));\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة موجود(م: سند[مـصفوفة[صـحيح]]، قيمة: صـحيح): ثـنائي {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا م(دليل) == قيمة {\n\t\t\tارجع صح؛\n\t\t}\n\t}\n\tارجع خطأ؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc exists(a: ref[Array[Int]], val: Int): Bool {\n def i: Int;\n for i = 0, i < a.getLength(), i++ {\n if a(i) == val {\n return true;\n }\n }\n return false;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, find and return the closest point to a given point from a given set of points"}, {"role": "assistant", "content": "class Point {\n constructor(x, y) {\n this.x = x;\n this.y = y;\n }\n}\n\nfunction calculateDistance(a, b) {\n return Math.sqrt(Math.pow(b.x - a.x, 2) + Math.pow(b.y - a.y, 2));\n}\n\nfunction findClosestPoint(givenPoint, points) {\n let minDistance = calculateDistance(givenPoint, points[0]);\n let closestPoint = points[0];\n \n for(let i = 1; i < points.length; i++) {\n let distance = calculateDistance(givenPoint, points[i]);\n if(distance < minDistance) {\n minDistance = distance;\n closestPoint = points[i];\n }\n }\n \n return closestPoint;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Array\";\nimport \"Srl/String\";\nimport \"closure\";\n\nuse Srl;\n\n\nfunc reduce(a: ref[Array[String]], f: closure(previousValue: ref[String], currentValue: ref[String])): String {\n def result: String = \"\";\n\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n f(result, a(i));\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "void reduce(char a[4][10], char result[50], void (*f)(char*, char*)) {\n for(int i = 0; i < 4; i++) {\n f(result, a[i]);\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/ريـاضيات\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nصنف نـقطة {\n\tعرف س: عـائم؛\n\tعرف ص: عـائم؛\n}\n\nدالة احسب_مسافة(ن1: نـقطة، ن2: نـقطة): عـائم {\n\tارجع ريـاضيات.جذر(ريـاضيات.ارفع(ن2.س - ن1.س، 2.0) + ريـاضيات.ارفع(ن2.ص - ن1.ص، 2.0))؛\n}\n\nدالة جد_أقرب_نقطة(ن: نـقطة، نقاط: سند[مـصفوفة[نـقطة]]): نـقطة {\n\tعرف أقرب_مسافة: عـائم = احسب_مسافة(ن، نقاط(0))؛\n\tعرف أقرب_نقطة: نـقطة = نقاط(0)؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 1 ، دليل < نقاط.هات_الطول() ، دليل++ {\n\t\tعرف مسافة: عـائم = احسب_مسافة(ن، نقاط(دليل))؛\n\t\tإذا مسافة < أقرب_مسافة {\n\t\t\tأقرب_مسافة = مسافة؛\n\t\t\tأقرب_نقطة = نقاط(دليل)؛\n\t\t}\n\t}\n\tارجع أقرب_نقطة؛\n}\n"}, {"role": "assistant", "content": "جد و أرجع أقرب نقطة من بين مجموعة من النقاط المعطاة عن نقطة معطاة"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة شذب(س: سند[نـص]) {\n\tعرف بداية: صـحيح = 0؛\n\tعرف نهاية: صـحيح = س.هات_الطول() - 1؛\n\t\n\tبينما (س(بداية) == ' ' || س(بداية) == '\\t' || س(بداية) == '\\n') {\n\t\tبداية++؛\n\t}\n\t\n\tبينما (س(نهاية) == ' ' || س(نهاية) == '\\t' || س(نهاية) == '\\n') {\n\t\tنهاية--؛\n\t}\n\t\n\tس = س.اجتزئ(بداية، نهاية - بداية + 1)؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc trim(s: ref[String]) {\n def start: Int = 0;\n def end: Int = s.getLength() - 1;\n\n while (s(start) == ' ' || s(start) == '\\t' || s(start) == '\\n') {\n start++;\n }\n\n while (s(end) == ' ' || s(end) == '\\t' || s(end) == '\\n') {\n end--;\n }\n\n s = s.slice(start, end - start + 1);\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction printArray(a, size) {\n var output = '';\n for(var i = 0; i < size; i++) {\n output += a[i] + ' ';\n }\n console.log(output);\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"Srl/Console\";\n\n\nuse Srl;\n\n\nfunc print(a: ref[Array[Int]]) {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n Console.print(\"%d \", a(i));\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, find and return the farthest point to a given point from a given set of points"}, {"role": "assistant", "content": "class Point {\n constructor(x, y) {\n this.x = x;\n this.y = y;\n }\n}\n\nfunction calculateDistance(a, b) {\n return Math.sqrt(Math.pow(b.x - a.x, 2) + Math.pow(b.y - a.y, 2));\n}\n\nfunction findFarthestPoint(givenPoint, points) {\n let maxDistance = 0;\n let farthestPoint;\n \n for(let i = 0; i < points.length; i++) {\n let distance = calculateDistance(givenPoint, points[i]);\n if(distance > maxDistance) {\n maxDistance = distance;\n farthestPoint = points[i];\n }\n }\n \n return farthestPoint;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nدالة هل_حلقي(عقدة: صـحيح، مزارة: سند[مـصفوفة[صـحيح]]، بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]): ثـنائي {\n\tإذا مزارة(عقدة) == 2 {\n\t\tارجع صح؛\n\t}\n\tمزارة(عقدة) = 1؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان(عقدة).هات_الطول() ، دليل++ {\n\t\tعرف عقدة_ابن: صـحيح = بيان(عقدة)(دليل)؛\n\t\tإذا مزارة(عقدة_ابن) == 1 {\n\t\t\tارجع صح؛\n\t\t}\n\t\tوإلا إذا مزارة(عقدة_ابن) == 0 && هل_حلقي(عقدة_ابن، مزارة، بيان) {\n\t\t\tارجع صح؛\n\t\t}\n\t}\n\tمزارة(عقدة) = 2؛\n\tارجع خطأ؛\n}\n\n\nدالة هل_داغ(بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]): ثـنائي {\n\tعرف مزارة: مـصفوفة[صـحيح]؛\n\t\n\tعرف دليل1: صـحيح؛\n\tعرف عدد_المكونات: صـحيح = 0؛\n\tلكل دليل1 = 0 ، دليل1 < بيان.هات_الطول() ، دليل1++ {\n\t\tعرف دليل2: صـحيح؛\n\t\tلكل دليل2 = 0 ، دليل2 < بيان.هات_الطول() ، دليل2++ {\n\t\t\tمزارة.أضف(0)؛\n\t\t}\n\n\t\tإذا هل_حلقي(دليل1، مزارة، بيان) {\n\t\t\tارجع خطأ؛\n\t\t}\n\t\tمزارة.فرغ()؛\n\t}\n\t\n\tارجع صح؛\n}\n"}, {"role": "assistant", "content": "let graph = [];\nlet visited = [];\nlet n;\n\nfunction isCyclic(i) {\n if (visited[i] === 2) {\n return true;\n }\n visited[i] = 1;\n for (let j = 0; j < graph[i].length; j++) {\n let node = graph[i][j];\n if (visited[node] === 1) return true;\n else if (visited[node] === 0 && isCyclic(node)) return true;\n }\n visited[i] = 2;\n return false;\n}\n\nfunction isDAG() {\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < n; j++) {\n visited[j] = 0;\n }\n if (isCyclic(i)) {\n return false;\n }\n }\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\nvoid dfs(int node, int visited[], int G[][N]) {\n visited[node] = 1;\n printf(\"%d \", node);\n\n for(int i = 0; i < N; i++) {\n if(G[node][i] == 1 && visited[i] == 0) {\n dfs(i, visited, G);\n }\n }\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/طـرفية\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nدالة دفس(عقدة: صـحيح، مزارة: سند[مـصفوفة[ثـنائي]]، بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]) {\n\tمزارة(عقدة) = صح؛\n\tطـرفية.اطبع(\"%d \"، عقدة)؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان(عقدة).هات_الطول() ، دليل++ {\n\t\tعرف عقدة_ابن: صـحيح = بيان(عقدة)(دليل)؛\n\t\tإذا !مزارة(عقدة_ابن) {\n\t\t\tدفس(عقدة_ابن، مزارة، بيان)؛\n\t\t}\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة الترتيب_بالاختيار(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tعرف مؤقت: صـحيح؛\n\tعرف أصغر_دليل: صـحيح؛\n\t\n\tلكل دليل1 = 0 ، دليل1 < م.هات_الطول() - 1 ، دليل1++ {\n\t\tأصغر_دليل = دليل1؛\n\t\t\n\t\tلكل دليل2 = دليل1 + 1 ، دليل2 < م.هات_الطول() ، دليل2++ {\n\t\t\tإذا م(دليل2) < م(أصغر_دليل) {\n\t\t\t\tأصغر_دليل = دليل2؛\n\t\t\t}\n\t\t}\n\t\t\n\t\tمؤقت = م(أصغر_دليل)؛\n\t\tم(أصغر_دليل) = م(دليل1)؛\n\t\tم(دليل1) = مؤقت؛\n\t}\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\n\nfunc selectionSort(a: ref[Array[Int]]) {\n def i: Int;\n def j: Int;\n def temp: Int;\n def min_idx: Int;\n\n for i = 0 , i < a.getLength() - 1 , i++ {\n min_idx = i;\n for j = i + 1 , j < a.getLength() , j++ {\n if a(j) < a(min_idx) {\n min_idx = j;\n }\n }\n\n temp = a(min_idx);\n a(min_idx) = a(i);\n a(i) = temp;\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, Initialize a given array with a given size by a given value"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc initializeArray(a: ref[Array[Int]], size: Int, val: Int) {\n def i: Int;\n for i = 0, i < size, i++ {\n a.add(val);\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/ريـاضيات\"؛\n\nاستخدم مـتم؛\n\n\nدالة جداء_نقطي(شعاع1: سند[مـصفوفة[عـائم[64]]]، شعاع2: سند[مـصفوفة[عـائم[64]]]): عـائم[64] {\n\tعرف نتيجة: عـائم[64] = 0؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < شعاع1.هات_الطول() ، دليل++ {\n\t\tنتيجة += شعاع1(دليل) * شعاع2(دليل)؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "double dot_product(double v1[], double v2[], int n) {\n double result = 0;\n for (int i = 0; i < n; i++) {\n result += v1[i] * v2[i];\n }\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Math\";\nimport \"Srl/Array\";\n\n\n\nuse Srl;\n\nclass Point {\n def x : Float;\n def y : Float;\n};\n\nfunc calculateDistance(a: Point, b: Point): Float {\n return Math.sqrt(Math.pow(b.x - a.x, 2.0) + Math.pow(b.y - a.y, 2.0));\n}\n\nfunc findClosestPoint(givenPoint: Point, points: ref[Array[Point]]): Point {\n def minDistance: Float = calculateDistance(givenPoint, points(0));\n def closestPoint: Point = points(0);\n\n def i: Int;\n for i = 1 , i < points.getLength() , i++ {\n def distance: Float = calculateDistance(givenPoint, points(i));\n if distance < minDistance {\n minDistance = distance;\n closestPoint = points(i);\n }\n }\n\n return closestPoint;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/ريـاضيات\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nصنف نـقطة {\n\tعرف س: عـائم؛\n\tعرف ص: عـائم؛\n}\n\nدالة احسب_مسافة(ن1: نـقطة، ن2: نـقطة): عـائم {\n\tارجع ريـاضيات.جذر(ريـاضيات.ارفع(ن2.س - ن1.س، 2.0) + ريـاضيات.ارفع(ن2.ص - ن1.ص، 2.0))؛\n}\n\nدالة جد_أقرب_نقطة(ن: نـقطة، نقاط: سند[مـصفوفة[نـقطة]]): نـقطة {\n\tعرف أقرب_مسافة: عـائم = احسب_مسافة(ن، نقاط(0))؛\n\tعرف أقرب_نقطة: نـقطة = نقاط(0)؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 1 ، دليل < نقاط.هات_الطول() ، دليل++ {\n\t\tعرف مسافة: عـائم = احسب_مسافة(ن، نقاط(دليل))؛\n\t\tإذا مسافة < أقرب_مسافة {\n\t\t\tأقرب_مسافة = مسافة؛\n\t\t\tأقرب_نقطة = نقاط(دليل)؛\n\t\t}\n\t}\n\tارجع أقرب_نقطة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Array\";\nimport \"Srl/String\";\nimport \"closure\";\n\nuse Srl;\n\n\nfunc reduce(a: ref[Array[String]], f: closure(previousValue: ref[String], currentValue: ref[String])): String {\n def result: String = \"\";\n\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n f(result, a(i));\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/نـص\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة اختصر(م: سند[مـصفوفة[نـص]]، د: مغلفة(قيمة_سابقة: سند[نـص]، قيمة_حالية: سند[نـص])): نـص {\n\tعرف نتيجة: نـص = \"\"؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tد(نتيجة، م(دليل))؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction initializeArray(arr, value) {\n for(let i = 0; i < arr.length; i++) {\n arr[i] = value;\n }\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة هيئ_مصفوفة(م: سند[مـصفوفة[صـحيح]]، حجم: صـحيح، قيمة: صـحيح) {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < حجم ، دليل++ {\n\t\tم.أضف(قيمة)؛\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة الترتيب_بالحشر(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف دليل1: صـحيح؛\n\tعرف مفتاح: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\t\n\tلكل دليل1 = 1 ، دليل1 < م.هات_الطول() ، دليل1++ {\n\t\tمفتاح = م(دليل1)؛\n\t\tدليل2 = دليل1 - 1؛\n\t\t\n\t\tبينما دليل2 >= 0 && م(دليل2) > مفتاح {\n\t\t\tم(دليل2 + 1) = م(دليل2)؛\n\t\t\tدليل2 = دليل2 - 1؛\n\t\t}\n\t\tم(دليل2 + 1) = مفتاح؛\n\t}\n}\n"}, {"role": "assistant", "content": "void insertionSort(int arr[], int n) {\n int i, key, j;\n for (i = 1; i < n; i++) {\n key = arr[i];\n j = i - 1;\n\n /* Move elements of arr[0..i-1], that are greater than key,\n to one position ahead of their current position */\n while (j >= 0 && arr[j] > key) {\n arr[j + 1] = arr[j];\n j = j - 1;\n }\n arr[j + 1] = key;\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\n// Function to check if arr2 is a permutation of arr1\nfunction is_permutation(arr1, arr2) {\n // If sizes are not equal, return false\n if(arr1.length !== arr2.length) {\n return false;\n }\n\n // Create an array to keep track of visited elements\n let visited = new Array(arr2.length).fill(false);\n\n // For each element in arr1\n for(let i = 0; i < arr1.length; i++) {\n let found = false;\n\n // For each element in arr2\n for(let j = 0; j < arr2.length; j++) {\n // If the element in arr1 is found in arr2 and it has not been visited\n if(arr1[i] === arr2[j] && !visited[j]) {\n found = true;\n visited[j] = true; // Mark the element in arr2 as visited\n break;\n }\n }\n\n // If the element in arr1 is not found in arr2, return false\n if(!found) {\n return false;\n }\n }\n\n // If we reach here, then arr2 is a permutation of arr1\n return true;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة هل_تباديل(م1: سند[مـصفوفة[صـحيح]]، م2: سند[مـصفوفة[صـحيح]]): ثـنائي {\n\tإذا م1.هات_الطول() != م2.هات_الطول() {\n\t\tارجع خطأ؛\n\t}\n\t\n\tعرف مزار: مـصفوفة[ثـنائي]؛\n\tعرف دليل1: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < م2.هات_الطول() ، دليل1++ {\n\t\tمزار.أضف(خطأ)؛\n\t}\n\t\n\tعرف دليل2: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < م1.هات_الطول() ، دليل1++ {\n\t\tعرف موجود: ثـنائي = خطأ؛\n\t\tلكل دليل2 = 0 ، دليل2 < م2.هات_الطول() ، دليل2++ {\n\t\t\tإذا م1(دليل1) == م2(دليل2) && !مزار(دليل2) {\n\t\t\t\tموجود = صح؛\n\t\t\t\tمزار(دليل2) = صح؛\n\t\t\t\tاقطع؛\n\t\t\t}\n\t\t}\n\t\tإذا !موجود {\n\t\t\tارجع خطأ؛\n\t\t}\n\t}\n\tارجع صح؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nدالة دفس(عقدة: صـحيح، مزارة: سند[مـصفوفة[ثـنائي]]، بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]) {\n\tمزارة(عقدة) = صح؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان(عقدة).هات_الطول() ، دليل++ {\n\t\tعرف عقدة_ابن: صـحيح = بيان(عقدة)(دليل)؛\n\t\tإذا !مزارة(عقدة_ابن) {\n\t\t\tدفس(عقدة_ابن، مزارة، بيان)؛\n\t\t}\n\t}\n}\n\n\nدالة عدد_المكونات_المترابطة(بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]): صـحيح {\n\tعرف مزارة: مـصفوفة[ثـنائي]؛\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان.هات_الطول() ، دليل++ {\n\t\tمزارة.أضف(خطأ)؛\n\t}\n\t\n\tعرف عدد_المكونات: صـحيح = 0؛\n\tلكل دليل = 0 ، دليل < بيان.هات_الطول() ، دليل++ {\n\t\tإذا !مزارة(دليل) {\n\t\t\tدفس(دليل، مزارة، بيان)؛\n\t\t\tعدد_المكونات++؛\n\t\t}\n\t}\n\t\n\tارجع عدد_المكونات؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\nfunc dfs(node: Int, visited: ref[Array[Bool]], graph: ref[Array[Array[Int]]]) {\n visited(node) = true;\n\n def i: Int;\n for i = 0 , i < graph(node).getLength(), i++ {\n def childNode: Int = graph(node)(i);\n if !visited(childNode) {\n dfs(childNode, visited, graph);\n }\n }\n}\n\n\nfunc numberOfConnectedComponents(graph: ref[Array[Array[Int]]]): Int {\n def visited: Array[Bool];\n def i: Int;\n for i = 0 , i < graph.getLength() , i++ {\n visited.add(false);\n }\n\n def components: Int = 0;\n for i = 0 , i < graph.getLength() , i++ {\n if !visited(i) {\n dfs(i, visited, graph);\n components++;\n }\n }\n\n return components;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/ريـاضيات\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nصنف نـقطة {\n\tعرف س: عـائم؛\n\tعرف ص: عـائم؛\n}\n\nدالة مساحة_مضلع(رؤوس: سند[مـصفوفة[نـقطة]]): عـائم {\n\tعرف مساحة: عـائم = 0؛\n\tعرف عدد_الرؤوس: صـحيح = رؤوس.هات_الطول()؛\n\tعرف دليل2: صـحيح = عدد_الرؤوس - 1؛\n\t\n\tعرف دليل1: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < عدد_الرؤوس ، دليل1++ {\n\t\tمساحة += (رؤوس(دليل1).س + رؤوس(دليل2).س) * (رؤوس(دليل1).ص - رؤوس(دليل2).ص)؛\n\t\tدليل2 = دليل1؛\n\t}\n\tارجع ريـاضيات.مطلق(مساحة / 2.0)؛\n}\n"}, {"role": "assistant", "content": "احسب و أرجع مساحة مضلع من إحداثيات رؤوسه"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, check if a given character is a digit"}, {"role": "assistant", "content": "use Srl;\n\n\nfunc is_digit(c: Char): Bool {\n return (c >= '0' && c <= '9');\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة هل_تباديل(م1: سند[مـصفوفة[صـحيح]]، م2: سند[مـصفوفة[صـحيح]]): ثـنائي {\n\tإذا م1.هات_الطول() != م2.هات_الطول() {\n\t\tارجع خطأ؛\n\t}\n\t\n\tعرف مزار: مـصفوفة[ثـنائي]؛\n\tعرف دليل1: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < م2.هات_الطول() ، دليل1++ {\n\t\tمزار.أضف(خطأ)؛\n\t}\n\t\n\tعرف دليل2: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < م1.هات_الطول() ، دليل1++ {\n\t\tعرف موجود: ثـنائي = خطأ؛\n\t\tلكل دليل2 = 0 ، دليل2 < م2.هات_الطول() ، دليل2++ {\n\t\t\tإذا م1(دليل1) == م2(دليل2) && !مزار(دليل2) {\n\t\t\t\tموجود = صح؛\n\t\t\t\tمزار(دليل2) = صح؛\n\t\t\t\tاقطع؛\n\t\t\t}\n\t\t}\n\t\tإذا !موجود {\n\t\t\tارجع خطأ؛\n\t\t}\n\t}\n\tارجع صح؛\n}\n"}, {"role": "assistant", "content": "#include <stdbool.h>\n\n// Function to check if arr2 is a permutation of arr1\nbool is_permutation(int arr1[], int size1, int arr2[], int size2) {\n // If sizes are not equal, return false\n if(size1 != size2) {\n return false;\n }\n\n // Create an array to keep track of visited elements\n bool visited[size2];\n for(int i = 0; i < size2; i++) {\n visited[i] = false;\n }\n\n // For each element in arr1\n for(int i = 0; i < size1; i++) {\n bool found = false;\n\n // For each element in arr2\n for(int j = 0; j < size2; j++) {\n // If the element in arr1 is found in arr2 and it has not been visited\n if(arr1[i] == arr2[j] && !visited[j]) {\n found = true;\n visited[j] = true; // Mark the element in arr2 as visited\n break;\n }\n }\n\n // If the element in arr1 is not found in arr2, return false\n if(!found) {\n return false;\n }\n }\n\n // If we reach here, then arr2 is a permutation of arr1\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc clip(a: ref[Array[Int]], lower: Int, upper: Int) {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if a(i) < lower {\n a(i) = lower;\n }\n else if a(i) > upper {\n a(i) = upper;\n }\n }\n}\n"}, {"role": "assistant", "content": "Clip the values of a given array within a given range"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Array\";\n\nuse Srl;\n\nfunc dfs(node: Int, parentNode: Int, visited: ref[Array[Bool]], graph: ref[Array[Array[Int]]]): Bool {\n visited(node) = true;\n\n def i: Int;\n for i = 0 , i < graph(node).getLength(), i++ {\n def childNode: Int = graph(node)(i);\n if !visited(childNode) {\n if dfs(childNode, node, visited, graph) {\n return true;\n }\n }\n else if childNode != parentNode {\n return true;\n }\n }\n return false;\n}\n\n\nfunc isTree(graph: ref[Array[Array[Int]]]): Bool {\n def visited: Array[Bool];\n def i: Int;\n for i = 0 , i < graph.getLength() , i++ {\n visited.add(false);\n }\n\n if dfs(0, -1, visited, graph) {\n return false;\n }\n\n for i = 0 , i < graph.getLength() , i++ {\n if !visited(i) {\n return false;\n }\n }\n\n return true;\n}\n"}, {"role": "assistant", "content": "Check if a given undirected graph is tree"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction accumulate(a, f) {\n for (let i = 0 ; i < a.length ; i++) {\n a[i] = f(a[i]);\n }\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة لكل_عنصر(م: سند[مـصفوفة[صـحيح]]، د: مغلفة(عنصر: صـحيح): صـحيح) {\n\tعرف دليل: صـحيح؛\n\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tم(دليل) = د(م(دليل))؛\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Array\";\nimport \"Srl/Console\";\n\nuse Srl;\n\nfunc dfs(node: Int, visited: ref[Array[Bool]], graph: ref[Array[Array[Int]]]) {\n visited(node) = true;\n Console.print(\"%d \", node);\n\n def i: Int;\n for i = 0 , i < graph(node).getLength(), i++ {\n def childNode: Int = graph(node)(i);\n if !visited(childNode) {\n dfs(childNode, visited, graph);\n }\n }\n}\n"}, {"role": "assistant", "content": "void dfs(int node, int visited[], int G[][N]) {\n visited[node] = 1;\n printf(\"%d \", node);\n\n for(int i = 0; i < N; i++) {\n if(G[node][i] == 1 && visited[i] == 0) {\n dfs(i, visited, G);\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\n#include <stdbool.h>\n\nbool isPrime(int num) {\n if (num <= 1) {\n return false;\n }\n for (int i = 2; i * i <= num; i++) {\n if (num % i == 0) {\n return false;\n }\n }\n return true;\n}\n"}, {"role": "assistant", "content": "use Srl;\n\nfunc isPrime(num: Int): Bool {\n if num <= 1 {\n return false;\n }\n\n def i: Int;\n for i = 2 , i * i <= num , i++ {\n if num % i == 0 {\n return false;\n }\n }\n \n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, check if three given points are collinear"}, {"role": "assistant", "content": "function Point(x, y) {\n this.x = x;\n this.y = y;\n}\n\nfunction areCollinear(p1, p2, p3) {\n // Calculate the slopes of the lines formed by (p1, p2) and (p1, p3)\n // If the slopes are equal, then p1, p2 and p3 are collinear\n return (p2.y - p1.y) * (p3.x - p1.x) === (p3.y - p1.y) * (p2.x - p1.x);\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\n#include <stdio.h>\n#include <stdlib.h>\n\n// Function to read the content of a file into a string\nchar* read_file(const char* file_path) {\n FILE* file = fopen(file_path, \"r\");\n if(file == NULL) {\n printf(\"Could not open file %s\\n\", file_path);\n return NULL;\n }\n\n // Get the size of the file\n fseek(file, 0, SEEK_END);\n long file_size = ftell(file);\n fseek(file, 0, SEEK_SET);\n\n // Allocate memory for the string\n char* str = malloc(file_size + 1);\n if(str == NULL) {\n printf(\"Could not allocate memory for the string\\n\");\n fclose(file);\n return NULL;\n }\n\n // Read the file into the string one character at a time\n for(long i = 0; i < file_size; i++) {\n fread(&str[i], sizeof(char), 1, file);\n }\n\n // Null-terminate the string\n str[file_size] = '\\0';\n\n fclose(file);\n return str;\n}\n"}, {"role": "assistant", "content": "Read the content of a text file given its path and return the result"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة استبدل(م: سند[مـصفوفة[صـحيح]]، ق1: صـحيح، ق2: صـحيح) {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا م(دليل) == ق1 {\n\t\t\tم(دليل) = ق2؛\n\t\t}\n\t}\n}\n"}, {"role": "assistant", "content": "void replace(int* arr, int len, int oldValue, int newValue) {\n for(int i = 0; i < len; i++) {\n if(arr[i] == oldValue) {\n arr[i] = newValue;\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nvoid invertArray(int a[], int n) {\n int start = 0;\n int end = n - 1;\n while (start < end) {\n int temp = a[start];\n a[start] = a[end];\n a[end] = temp;\n start++;\n end--;\n }\n}\n"}, {"role": "assistant", "content": "Invert the given array `a` and return the result"}]}
{"messages": [{"role": "user", "content": "Using js, Read the lines of a text file given its path into an array and return it"}, {"role": "assistant", "content": "const fs = require('fs');\n\nfunction readFileToArray(filename) {\n const data = fs.readFileSync(filename, 'utf8');\n let lines = [''];\n let j = 0;\n for (let i = 0; i < data.length; i++) {\n if (data[i] === '\\n') {\n lines.push('');\n j++;\n } else {\n lines[j] += data[i];\n }\n }\n return lines;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Array\";\n\nuse Srl;\n\nfunc dfs(node: Int, visited: ref[Array[Bool]], graph: ref[Array[Array[Int]]]) {\n visited(node) = true;\n\n def i: Int;\n for i = 0 , i < graph(node).getLength(), i++ {\n def childNode: Int = graph(node)(i);\n if !visited(childNode) {\n dfs(childNode, visited, graph);\n }\n }\n}\n\n\nfunc numberOfConnectedComponents(graph: ref[Array[Array[Int]]]): Int {\n def visited: Array[Bool];\n def i: Int;\n for i = 0 , i < graph.getLength() , i++ {\n visited.add(false);\n }\n\n def components: Int = 0;\n for i = 0 , i < graph.getLength() , i++ {\n if !visited(i) {\n dfs(i, visited, graph);\n components++;\n }\n }\n\n return components;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nدالة دفس(عقدة: صـحيح، مزارة: سند[مـصفوفة[ثـنائي]]، بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]) {\n\tمزارة(عقدة) = صح؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان(عقدة).هات_الطول() ، دليل++ {\n\t\tعرف عقدة_ابن: صـحيح = بيان(عقدة)(دليل)؛\n\t\tإذا !مزارة(عقدة_ابن) {\n\t\t\tدفس(عقدة_ابن، مزارة، بيان)؛\n\t\t}\n\t}\n}\n\n\nدالة عدد_المكونات_المترابطة(بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]): صـحيح {\n\tعرف مزارة: مـصفوفة[ثـنائي]؛\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان.هات_الطول() ، دليل++ {\n\t\tمزارة.أضف(خطأ)؛\n\t}\n\t\n\tعرف عدد_المكونات: صـحيح = 0؛\n\tلكل دليل = 0 ، دليل < بيان.هات_الطول() ، دليل++ {\n\t\tإذا !مزارة(دليل) {\n\t\t\tدفس(دليل، مزارة، بيان)؛\n\t\t\tعدد_المكونات++؛\n\t\t}\n\t}\n\t\n\tارجع عدد_المكونات؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جمع(م: سند[مـصفوفة[صـحيح]]): صـحيح {\n\tعرف نتيجة: صـحيح = 0؛\n\n\tعرف دليل: صـحيح؛\n\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n نتيجة += م(دليل)؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\nfunc sum(a: ref[Array[Int]]): Int {\n def sum: Int = 0;\n\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n sum += a(i);\n }\n\n return sum;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc char_exists(s: ref[String], c: Char): Bool {\n def i: Int;\n\tfor i = 0 , i < s.getLength() , i++ {\n\t\tif (s(i) == c) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n"}, {"role": "assistant", "content": "function char_exists(s, c) {\n for (let i = 0; i < s.length; i++) {\n if (s[i] === c) {\n return true;\n }\n }\n return false;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, Calculate the norm of a given vector which is represented by an array and return the result"}, {"role": "assistant", "content": "function vectorNorm(vector) {\n let sum = 0.0;\n for (let i = 0; i < vector.length; i++) {\n sum += vector[i] * vector[i];\n }\n return Math.sqrt(sum);\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction calculatePolygonArea(vertices) {\n let area = 0;\n let j = vertices.length - 1;\n\n for (let i = 0; i < vertices.length; i++) {\n area += (vertices[j].x + vertices[i].x) * (vertices[j].y - vertices[i].y);\n j = i;\n }\n\n return Math.abs(area / 2);\n}\n"}, {"role": "assistant", "content": "calculate and return the area of polygon given its vertices"}]}
{"messages": [{"role": "user", "content": "Using c, Initialize a given array with a given size by a given value"}, {"role": "assistant", "content": "void initializeArray(int* arr, int size, int value) {\n for(int i = 0; i < size; i++) {\n arr[i] = value;\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, Initialize a given array with a given size by a given value"}, {"role": "assistant", "content": "function initializeArray(arr, value) {\n for(let i = 0; i < arr.length; i++) {\n arr[i] = value;\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction toLowerCase(s) {\n let result = '';\n for(let i = 0; i < s.length; i++){\n let code = s.charCodeAt(i);\n if(code >= 65 && code <= 90){\n result += String.fromCharCode(code + 32);\n } else {\n result += s[i];\n }\n }\n return result;\n}\n"}, {"role": "assistant", "content": "import \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc toLowerCase(s: ref[String]): String {\n\tdef result: String = \"\";\n def i: Int;\n\tdef c: Char;\n\tfor i = 0 , i < s.getLength() , i++ {\n\t\tif (s(i) >= 'A' && s(i) <= 'Z') {\n\t\t\tc = s(i) - 'A' + 'a';\n\t\t}\n\t\telse {\n\t\t\tc = s(i);\n\t\t}\n\t\tresult += c;\n\t}\n\treturn result;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, Calculate the product of a given matrix, represented as 2D array, and a given scalar, and return the result"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\ndef Matrix: alias Array[Array[Float[64]]];\n\n\nfunc multiply(m: ref[Matrix], s: Float[64]): Matrix {\n def rows: Int = m.getLength();\n def cols: Int = m(0).getLength();\n \n def result: Matrix;\n\n def i: Int;\n def j: Int;\n for i = 0 , i < rows , i++ {\n result.add(Array[Float[64]]());\n for j = 0 , j < cols , j++ {\n result(i).add(m(i)(j)*s);\n }\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\n#include <stdlib.h>\n\ntypedef struct {\n double x;\n double y;\n} Point;\n\ndouble calculatePolygonArea(Point* vertices, int numVertices) {\n double area = 0.0;\n int j = numVertices - 1;\n\n for (int i = 0; i < numVertices; i++) {\n area += (vertices[j].x + vertices[i].x) * (vertices[j].y - vertices[i].y);\n j = i;\n }\n\n return abs(area / 2.0);\n}\n\n"}, {"role": "assistant", "content": "اشمل \"مـتم/ريـاضيات\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nصنف نـقطة {\n\tعرف س: عـائم؛\n\tعرف ص: عـائم؛\n}\n\nدالة مساحة_مضلع(رؤوس: سند[مـصفوفة[نـقطة]]): عـائم {\n\tعرف مساحة: عـائم = 0؛\n\tعرف عدد_الرؤوس: صـحيح = رؤوس.هات_الطول()؛\n\tعرف دليل2: صـحيح = عدد_الرؤوس - 1؛\n\t\n\tعرف دليل1: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < عدد_الرؤوس ، دليل1++ {\n\t\tمساحة += (رؤوس(دليل1).س + رؤوس(دليل2).س) * (رؤوس(دليل1).ص - رؤوس(دليل2).ص)؛\n\t\tدليل2 = دليل1؛\n\t}\n\tارجع ريـاضيات.مطلق(مساحة / 2.0)؛\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, جد و أرجع موقع محرف معطى ضمن سلسلة نصية معطاة"}, {"role": "assistant", "content": "اشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة جد_المحرف(س: سند[نـص]، م: مـحرف): صـحيح {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) == م {\n\t\t\tارجع دليل؛\n\t\t}\n\t}\n\tارجع -1؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\nint sum(int a[], int n) {\n int result = 0;\n for (int i = 0; i < n; i++) {\n result += a[i];\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\nfunc sum(a: ref[Array[Int]]): Int {\n def sum: Int = 0;\n\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n sum += a(i);\n }\n\n return sum;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction calculateMean(arr) {\n var sum = 0;\n for (var i = 0; i < arr.length; i++) {\n sum += arr[i];\n }\n return sum / arr.length;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة متوسط(م: سند[مـصفوفة[صـحيح]]): عـائم {\n\tعرف حجم: صـحيح = م.هات_الطول()؛\n\tعرف مجموع: صـحيح = 0؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < حجم ، دليل++ {\n\t\tمجموع += م(دليل)؛\n\t}\n\t\n\tارجع مجموع~مثل[عـائم] / حجم؛\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, Slice a given array within a given range"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc slice(a: ref[Array[Int]], start: Int, end: Int, result: ref[Array[Int]]) {\n def i: Int;\n for i = start , i <= end , i++ {\n result.add(a(i));\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاستخدم مـتم؛\n\n\nصنف نـقطة {\n\tعرف س: صـحيح؛\n\tعرف ص: صـحيح؛\n}\n\nدالة على_خط_مستقيم(ن1: نـقطة، ن2: نـقطة، ن3: نـقطة): ثـنائي {\n\tارجع (ن2.ص - ن1.ص) * (ن3.س - ن1.ص) == (ن3.ص - ن1.ص) * (ن2.س - ن1.س)؛\n}\n"}, {"role": "assistant", "content": "اختبر فيما إذا كانت 3 نقاط معطاة على استقامة واحدة"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, Read the content of a text file given its path and return the result"}, {"role": "assistant", "content": "import \"Srl/Fs\";\nimport \"Srl/String\";\n\nuse Srl;\n\n\nfunc read_file(file_path: ref[String]): String {\n def file: ptr[Fs.File] = Fs.openFile(file_path.buf, \"r\");\n def content: String;\n\n Fs.seek(file, 0, Fs.Seek.END);\n def size: Int = Fs.tell(file);\n Fs.seek(file, 0, Fs.Seek.SET);\n \n\n def i: Int;\n for i = 0 , i < size , i++ {\n def temp: Char;\n Fs.read(temp~ptr, 1, 1, file);\n content.append(temp);\n }\n\n return content;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, Find and return the position of a given element in the given array starting from its end"}, {"role": "assistant", "content": "function rfind(a, val) {\n for (let i = a.length - 1; i != 0 ; i--) {\n if (a[i] == val) {\n return i;\n }\n }\n return -1;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Fs\";\nimport \"Srl/String\";\nimport \"Srl/Array\";\n\nuse Srl;\n\n\nfunc readFileToArray(file_path: ref[String]): Array[String] {\n def file: ptr[Fs.File] = Fs.openFile(file_path.buf, \"r\");\n def content: Array[String];\n\n Fs.seek(file, 0, Fs.Seek.END);\n def size: Int = Fs.tell(file);\n Fs.seek(file, 0, Fs.Seek.SET);\n \n content.add(String());\n def i: Int;\n def j: Int = 0;\n for i = 0 , i < size , i++ {\n def temp: Char;\n Fs.read(temp~ptr, 1, 1, file);\n\n if temp == '\\n' {\n content.add(String());\n j++;\n }\n else {\n content(j).append(temp);\n }\n }\n\n return content;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/نـم\"؛\nاشمل \"مـتم/نـص\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة اقرأ_الملف_إلى_مصفوفة(مسار_الملف: سند[نـص]): مـصفوفة[نـص] {\n\tعرف ملف: مؤشر[نـم.مـلف] = نـم.افتح_ملف(مسار_الملف، \"r\")؛\n\tعرف المحتوى: مـصفوفة[نـص]؛\n\n\tنـم.انتقل(ملف، 0، نـم.انـتقال._نهاية_)؛\n\tعرف حجم: صـحيح = نـم.هات_الموقع(ملف)؛\n\tنـم.انتقل(ملف، 0، نـم.انـتقال._بداية_)؛\n\t\n\tالمحتوى.أضف(نـص())؛\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح = 0؛\n\tلكل دليل1 = 0 ، دليل1 < حجم ، دليل1++ {\n\t\tعرف مؤقت: مـحرف؛\n\t\tنـم.اقرأ(مؤقت~مؤشر، 1، 1، ملف)؛\n\t\t\n\t\tإذا مؤقت == '\\n' {\n\t\t\tالمحتوى.أضف(نـص())؛\n\t\t\tدليل2++؛\n\t\t}\n\t\tوإلا {\n\t\t\tالمحتوى(دليل2).ألحق(مؤقت)؛\n\t\t}\n\t}\n\t\n\tارجع المحتوى؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جد_بداية_الاختلاف(م1: سند[مـصفوفة[صـحيح]]، م2: سند[مـصفوفة[صـحيح]]): صـحيح {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م1.هات_الطول() ، دليل++ {\n\t\tإذا م1(دليل) != م2(دليل) {\n\t\t\tارجع دليل؛\n\t\t}\n\t}\n\tارجع -1؛\n}\n"}, {"role": "assistant", "content": "int find_diff_index(int arr1[], int arr2[], int n) {\n int i;\n for(i = 0; i < n; i++) {\n if(arr1[i] != arr2[i]) {\n return i;\n }\n }\n return -1; // return -1 if no difference is found\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction slice_string(str, start, end) {\n var result = \"\";\n for(var i = start; i <= end; i++) {\n result += str[i];\n }\n return result;\n}\n"}, {"role": "assistant", "content": "Slice a given string within a given range and return the result"}]}
{"messages": [{"role": "user", "content": "Using js, Find the first index at which the two given arrays differ, return -1 if not found"}, {"role": "assistant", "content": "function findDiffIndex(arr1, arr2) {\n for(let i = 0; i < arr1.length; i++) {\n if(arr1[i] !== arr2[i]) {\n return i;\n }\n }\n return -1; // return -1 if no difference is found\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, اختبر فيما إذا كان المحرف المعطى رقما بين 0 و 9"}, {"role": "assistant", "content": "استخدم مـتم؛\n\n\nدالة ينتمي_للأرقام(م: مـحرف): ثـنائي {\n\tارجع ( م <= '9' && م >= '0')؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة لكل_عنصر(م: سند[مـصفوفة[صـحيح]]، د: مغلفة(عنصر: صـحيح): صـحيح) {\n\tعرف دليل: صـحيح؛\n\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tم(دليل) = د(م(دليل))؛\n\t}\n}\n"}, {"role": "assistant", "content": "function accumulate(a, f) {\n for (let i = 0 ; i < a.length ; i++) {\n a[i] = f(a[i]);\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\nint sum(int a[], int n, int start, int end) {\n int result = 0;\n for (int i = start; i < end; i++) {\n result += a[i];\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جمع(م: سند[مـصفوفة[صـحيح]]، بداية: صـحيح، نهاية: صـحيح): صـحيح {\n\tعرف نتيجة: صـحيح = 0؛\n\n\tعرف دليل: صـحيح؛\n\n\tلكل دليل = بداية ، دليل < نهاية ، دليل++ {\n نتيجة += م(دليل)؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, Write Floyd Warshall algorithm for a given graph"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\nfunc floydWarshall(graph: ref[Array[Array[Int]]], dist: ref[Array[Array[Int]]]) {\n def n: Int = graph.getLength();\n def i: Int;\n def j: Int;\n def k: Int;\n\n for i = 0 , i < n , i++ {\n dist.add(graph(i));\n }\n\n for k = 0 , k < n , k++ {\n for i = 0 , i < n , i++ {\n for j = 0 , j < n , j++ {\n if dist(i)(k) + dist(k)(j) < dist(i)(j) {\n dist(i)(j) = dist(i)(k) + dist(k)(j);\n }\n }\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\n#define V 4\n\nvoid floydWarshall (int graph[V][V], int dist[V][V]) \n{ \n int i, j, k; \n \n for (i = 0; i < V; i++) \n for (j = 0; j < V; j++) \n dist[i][j] = graph[i][j]; \n \n for (k = 0; k < V; k++) \n { \n for (i = 0; i < V; i++) \n { \n for (j = 0; j < V; j++) \n { \n if (dist[i][k] + dist[k][j] < dist[i][j]) \n dist[i][j] = dist[i][k] + dist[k][j]; \n } \n } \n }\n} \n"}, {"role": "assistant", "content": "Write Floyd Warshall algorithm for a given graph"}]}
{"messages": [{"role": "user", "content": "Using c, Clip the values of a given array within a given range"}, {"role": "assistant", "content": "void clip(int arr[], int n, int lower, int upper) {\n for(int i = 0; i < n; i++) {\n if(arr[i] < lower) {\n arr[i] = lower;\n } else if(arr[i] > upper) {\n arr[i] = upper;\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction slice_string(str, start, end) {\n var result = \"\";\n for(var i = start; i <= end; i++) {\n result += str[i];\n }\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة اجتزئ(س: سند[نـص]، بداية: صـحيح، نهاية: صـحيح): نـص {\n\tعرف نتيجة: نـص = \"\"؛\n\n\tعرف دليل: صـحيح؛\n\tلكل دليل = بداية ، دليل <= نهاية ، دليل++ {\n\t\tنتيجة.ألحق(س(دليل))؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction calculateMean(arr) {\n var sum = 0;\n for (var i = 0; i < arr.length; i++) {\n sum += arr[i];\n }\n return sum / arr.length;\n}\n"}, {"role": "assistant", "content": "calculate and return the mean of the given array"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nlet visited = [];\n\nfunction DFS(v, parent, adjList) {\n visited[v] = true;\n for(let i = 0; i < adjList[v].length; i++) {\n if(!visited[adjList[v][i]]) {\n if(DFS(adjList[v][i], v, adjList)) {\n return true;\n }\n } else if(adjList[v][i] != parent) {\n return true;\n }\n }\n return false;\n}\n\nfunction isTree(adjList) {\n visited = new Array(adjList.length).fill(false);\n if(DFS(0, -1, adjList)) {\n return false;\n }\n for(let i = 0; i < adjList.length; i++) {\n if(!visited[i]) {\n return false;\n }\n }\n return true;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\nfunc dfs(node: Int, parentNode: Int, visited: ref[Array[Bool]], graph: ref[Array[Array[Int]]]): Bool {\n visited(node) = true;\n\n def i: Int;\n for i = 0 , i < graph(node).getLength(), i++ {\n def childNode: Int = graph(node)(i);\n if !visited(childNode) {\n if dfs(childNode, node, visited, graph) {\n return true;\n }\n }\n else if childNode != parentNode {\n return true;\n }\n }\n return false;\n}\n\n\nfunc isTree(graph: ref[Array[Array[Int]]]): Bool {\n def visited: Array[Bool];\n def i: Int;\n for i = 0 , i < graph.getLength() , i++ {\n visited.add(false);\n }\n\n if dfs(0, -1, visited, graph) {\n return false;\n }\n\n for i = 0 , i < graph.getLength() , i++ {\n if !visited(i) {\n return false;\n }\n }\n\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Array\";\n\nuse Srl;\n\nfunc dfs(node: Int, parentNode: Int, visited: ref[Array[Bool]], graph: ref[Array[Array[Int]]]): Bool {\n visited(node) = true;\n\n def i: Int;\n for i = 0 , i < graph(node).getLength(), i++ {\n def childNode: Int = graph(node)(i);\n if !visited(childNode) {\n if dfs(childNode, node, visited, graph) {\n return true;\n }\n }\n else if childNode != parentNode {\n return true;\n }\n }\n return false;\n}\n\n\nfunc isTree(graph: ref[Array[Array[Int]]]): Bool {\n def visited: Array[Bool];\n def i: Int;\n for i = 0 , i < graph.getLength() , i++ {\n visited.add(false);\n }\n\n if dfs(0, -1, visited, graph) {\n return false;\n }\n\n for i = 0 , i < graph.getLength() , i++ {\n if !visited(i) {\n return false;\n }\n }\n\n return true;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nدالة دفس(عقدة: صـحيح، العقدة_الأب: صـحيح، مزارة: سند[مـصفوفة[ثـنائي]]، بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]): ثـنائي {\n\tمزارة(عقدة) = صح؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان(عقدة).هات_الطول() ، دليل++ {\n\t\tعرف عقدة_ابن: صـحيح = بيان(عقدة)(دليل)؛\n\t\tإذا !مزارة(عقدة_ابن) {\n\t\t\tإذا دفس(عقدة_ابن، عقدة، مزارة، بيان) {\n\t\t\t\tارجع صح؛\n\t\t\t}\n\t\t}\n\t\tوإلا إذا عقدة_ابن != العقدة_الأب {\n\t\t\tارجع صح؛\n\t\t}\n\t}\n\tارجع خطأ؛\n}\n\n\nدالة هل_شجرة(بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]): ثـنائي {\n\tعرف مزارة: مـصفوفة[ثـنائي]؛\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان.هات_الطول() ، دليل++ {\n\t\tمزارة.أضف(خطأ)؛\n\t}\n\t\n\tإذا دفس(0، -1، مزارة، بيان) {\n\t\tارجع خطأ؛\n\t}\n\t\n\tعرف عدد_المكونات: صـحيح = 0؛\n\tلكل دليل = 0 ، دليل < بيان.هات_الطول() ، دليل++ {\n\t\tإذا !مزارة(دليل) {\n\t\t\tارجع خطأ؛\n\t\t}\n\t}\n\t\n\tارجع صح؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc replace(a: ref[Array[Int]], oldValue: Int, newValue: Int) {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if a(i) == oldValue {\n a(i) = newValue;\n }\n }\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة استبدل(م: سند[مـصفوفة[صـحيح]]، ق1: صـحيح، ق2: صـحيح) {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا م(دليل) == ق1 {\n\t\t\tم(دليل) = ق2؛\n\t\t}\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/نـص\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جزئ(س: سند[نـص]، رمز: مـحرف): مـصفوفة[نـص] {\n\tعرف نتيجة: مـصفوفة[نـص]؛\n\t\n\tعرف مؤقت: نـص؛\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) != رمز {\n\t\t\tمؤقت.ألحق(س(دليل))؛\n\t\t}\n\t\tوإلا {\n\t\t\tنتيجة.أضف(مؤقت)؛\n\t\t\tمؤقت = \"\"؛\n\t\t}\n\t}\n\tنتيجة.أضف(مؤقت)؛\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "function split(str, token) {\n let result = [];\n let temp = \"\";\n\n for(let i = 0; i < str.length; i++) {\n if(str[i] !== token) {\n temp += str[i];\n } else {\n result.push(temp);\n temp = \"\";\n }\n }\n\n // Push the last substring if it's not empty\n if(temp !== \"\") {\n result.push(temp);\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction multiply(matrix, scalar) {\n let rows = matrix.length, cols = matrix[0].length;\n let result = new Array(rows);\n\n for (let i = 0; i < rows; i++) {\n result[i] = new Array(cols);\n for (let j = 0; j < cols; j++) {\n result[i][j] = matrix[i][j] * scalar;\n }\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\ndef Matrix: alias Array[Array[Float[64]]];\n\n\nfunc multiply(m: ref[Matrix], s: Float[64]): Matrix {\n def rows: Int = m.getLength();\n def cols: Int = m(0).getLength();\n \n def result: Matrix;\n\n def i: Int;\n def j: Int;\n for i = 0 , i < rows , i++ {\n result.add(Array[Float[64]]());\n for j = 0 , j < cols , j++ {\n result(i).add(m(i)(j)*s);\n }\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Math\";\n\nuse Srl;\n\nclass Point {\n def x : Float;\n def y : Float;\n};\n\nfunc triangleArea(p1: Point, p2: Point, p3: Point): Float {\n return Math.abs(p1.x*(p2.y-p3.y) + p2.x*(p3.y-p1.y) + p3.x*(p1.y-p2.y)) / 2.0;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/ريـاضيات\"؛\n\nاستخدم مـتم؛\n\n\nصنف نـقطة {\n\tعرف س: عـائم؛\n\tعرف ص: عـائم؛\n}\n\nدالة مساحة_مثلث(ن1: نـقطة، ن2: نـقطة، ن3: نـقطة): عـائم {\n\tارجع ريـاضيات.مطلق(ن1.س*(ن2.ص - ن3.ص) + ن2.س*(ن3.ص - ن1.ص) + ن3.س*(ن1.ص - ن2.ص)) / 2.0؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction findDiffIndex(arr1, arr2) {\n for(let i = 0; i < arr1.length; i++) {\n if(arr1[i] !== arr2[i]) {\n return i;\n }\n }\n return -1; // return -1 if no difference is found\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جد_بداية_الاختلاف(م1: سند[مـصفوفة[صـحيح]]، م2: سند[مـصفوفة[صـحيح]]): صـحيح {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م1.هات_الطول() ، دليل++ {\n\t\tإذا م1(دليل) != م2(دليل) {\n\t\t\tارجع دليل؛\n\t\t}\n\t}\n\tارجع -1؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\n#include <stdio.h>\n\n#define MAX 100\n\nint visited[MAX];\nint matrix[MAX][MAX];\n\nvoid DFS(int v, int n) {\n visited[v] = 1;\n for(int i = 0; i < n; i++) {\n if(matrix[v][i] == 1 && visited[i] == 0) {\n DFS(i, n);\n }\n }\n}\n\nint numberOfConnectedComponents(int n) {\n int components = 0;\n for(int i = 0; i < n; i++) {\n if(visited[i] == 0) {\n DFS(i, n);\n components++;\n }\n }\n return components;\n}\n"}, {"role": "assistant", "content": "Find the number of connected components in a given undirected graph"}]}
{"messages": [{"role": "user", "content": "What this code do?\nlet graph = [];\nlet visited = [];\nlet n;\n\nfunction isCyclic(i) {\n if (visited[i] === 2) {\n return true;\n }\n visited[i] = 1;\n for (let j = 0; j < graph[i].length; j++) {\n let node = graph[i][j];\n if (visited[node] === 1) return true;\n else if (visited[node] === 0 && isCyclic(node)) return true;\n }\n visited[i] = 2;\n return false;\n}\n\nfunction isDAG() {\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < n; j++) {\n visited[j] = 0;\n }\n if (isCyclic(i)) {\n return false;\n }\n }\n return true;\n}\n"}, {"role": "assistant", "content": "Check if a given directed graph is a DAG"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction vectorNorm(vector) {\n let sum = 0.0;\n for (let i = 0; i < vector.length; i++) {\n sum += vector[i] * vector[i];\n }\n return Math.sqrt(sum);\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/ريـاضيات\"؛\n\nاستخدم مـتم؛\n\n\nدالة طويلة_شعاع(شعاع: سند[مـصفوفة[عـائم[64]]]): عـائم[64] {\n\tعرف مجموع: عـائم[64] = 0؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < شعاع.هات_الطول() ، دليل++ {\n\t\tمجموع += شعاع(دليل) * شعاع(دليل)؛\n\t}\n\t\n\tارجع ريـاضيات.جذر(مجموع)؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/نـص\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة اختصر(م: سند[مـصفوفة[نـص]]، د: مغلفة(قيمة_سابقة: سند[نـص]، قيمة_حالية: سند[نـص])): نـص {\n\tعرف نتيجة: نـص = \"\"؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tد(نتيجة، م(دليل))؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "function reduce(a, f) {\n let result = \"\";\n\n for (let i = 0; i < a.length; i++) {\n result = f(result, a[i]);\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/String\";\n\nuse Srl;\n\n\nfunction invertString(s) {\n def size: Int = s.getLength();\n def result: String = \"\";\n\n def i: Int;\n for i = size - 1 , i >= 0 , i-- {\n result += s(i);\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "function invert_string(str) {\n return str.split('').reverse().join('');\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, اكتب خوارزمية الفرز بالاختيار لمصفوفة معطاة"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة الترتيب_بالاختيار(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tعرف مؤقت: صـحيح؛\n\tعرف أصغر_دليل: صـحيح؛\n\t\n\tلكل دليل1 = 0 ، دليل1 < م.هات_الطول() - 1 ، دليل1++ {\n\t\tأصغر_دليل = دليل1؛\n\t\t\n\t\tلكل دليل2 = دليل1 + 1 ، دليل2 < م.هات_الطول() ، دليل2++ {\n\t\t\tإذا م(دليل2) < م(أصغر_دليل) {\n\t\t\t\tأصغر_دليل = دليل2؛\n\t\t\t}\n\t\t}\n\t\t\n\t\tمؤقت = م(أصغر_دليل)؛\n\t\tم(أصغر_دليل) = م(دليل1)؛\n\t\tم(دليل1) = مؤقت؛\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction std(data, n, mean) {\n let variance = 0.0;\n\n for(let i=0; i<n; ++i)\n variance += (data[i] - mean) * (data[i] - mean);\n\n return Math.sqrt(variance/n);\n}\n"}, {"role": "assistant", "content": "calculate and return the standard deviation of the given array"}]}
{"messages": [{"role": "user", "content": "Using js, Calculate the dot product of two given vectors each represented by an array and return the result"}, {"role": "assistant", "content": "function dot_product(v1, v2) {\n let result = 0;\n for (let i = 0; i < v1.length; i++) {\n result += v1[i] * v2[i];\n }\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Array\";\nimport \"closure\";\n\n\nuse Srl;\n\n\nfunc check_any(a: ref[Array[Int]], f: closure (num: Int): Bool): Bool {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if f(a(i)) {\n return true;\n }\n }\n\n return false;\n}\n"}, {"role": "assistant", "content": "Check if any element in a given array satisfy a criteria defined by a function with boolean return value"}]}
{"messages": [{"role": "user", "content": "Using c, write the merge sort algorithm for a given array"}, {"role": "assistant", "content": "#include <stdlib.h>\n\nvoid merge(int arr[], int l, int m, int r) {\n int i, j, k;\n int n1 = m - l + 1;\n int n2 = r - m;\n\n int L[n1], R[n2];\n\n for (i = 0; i < n1; i++)\n L[i] = arr[l + i];\n for (j = 0; j < n2; j++)\n R[j] = arr[m + 1 + j];\n\n i = 0;\n j = 0;\n k = l;\n while (i < n1 && j < n2) {\n if (L[i] <= R[j]) {\n arr[k] = L[i];\n i++;\n } else {\n arr[k] = R[j];\n j++;\n }\n k++;\n }\n\n while (i < n1) {\n arr[k] = L[i];\n i++;\n k++;\n }\n\n while (j < n2) {\n arr[k] = R[j];\n j++;\n k++;\n }\n}\n\nvoid mergeSort(int arr[], int l, int r) {\n if (l < r) {\n int m = l + (r - l) / 2;\n\n mergeSort(arr, l, m);\n mergeSort(arr, m + 1, r);\n\n merge(arr, l, m, r);\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/ريـاضيات\"؛\n\nاستخدم مـتم؛\n\n\nدالة جداء_نقطي(شعاع1: سند[مـصفوفة[عـائم[64]]]، شعاع2: سند[مـصفوفة[عـائم[64]]]): عـائم[64] {\n\tعرف نتيجة: عـائم[64] = 0؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < شعاع1.هات_الطول() ، دليل++ {\n\t\tنتيجة += شعاع1(دليل) * شعاع2(دليل)؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "function dot_product(v1, v2) {\n let result = 0;\n for (let i = 0; i < v1.length; i++) {\n result += v1[i] * v2[i];\n }\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction initializeArray(arr, value) {\n for(let i = 0; i < arr.length; i++) {\n arr[i] = value;\n }\n}\n"}, {"role": "assistant", "content": "Initialize a given array with a given size by a given value"}]}
{"messages": [{"role": "user", "content": "Using js, Find and return the maximum in the given array `a`"}, {"role": "assistant", "content": "function max(a) {\n let result = a[0];\n for (let i = 1 ; i < a.length ; i++) {\n if (result < a[i]) {\n result = a[i];\n }\n }\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة إلى_حالة_كبيرة(س: سند[نـص]): نـص {\n\tعرف نتيجة: نـص = \"\"؛\n\n\tعرف دليل: صـحيح؛\n\tعرف م: مـحرف؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) >= 'a' && س(دليل) <= 'z' {\n\t\t\tم = س(دليل) - 'a' + 'A'؛\n\t\t}\n\t\tوإلا {\n\t\t\tم = س(دليل)؛\n\t\t}\n\t\tنتيجة += م؛\n\t}\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "حول حالة محارف سلسلة نصية إلى أحرف كبيرة و أرجع النتيجة"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Array\";\n\nuse Srl;\n\nfunc isCyclic(node: Int, visited: ref[Array[Int]], graph: ref[Array[Array[Int]]]): Bool {\n if visited(node) == 2 {\n return true;\n }\n visited(node) = 1;\n\n def i: Int;\n for i = 0 , i < graph(node).getLength(), i++ {\n def childNode: Int = graph(node)(i);\n if visited(childNode) == 1 {\n return true;\n }\n else if visited(childNode) == 0 && isCyclic(childNode, visited, graph){\n return true;\n }\n }\n visited(node) = 2;\n return false;\n}\n\n\nfunc isDAG(graph: ref[Array[Array[Int]]]): Bool {\n def visited: Array[Int];\n def i: Int;\n\n for i = 0 , i < graph.getLength() , i++ {\n def j: Int;\n for j = 0 , j < graph.getLength() , j++ {\n visited.add(0);\n }\n if isCyclic(i, visited, graph) {\n return false;\n }\n visited.clear();\n }\n\n return true;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nدالة هل_حلقي(عقدة: صـحيح، مزارة: سند[مـصفوفة[صـحيح]]، بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]): ثـنائي {\n\tإذا مزارة(عقدة) == 2 {\n\t\tارجع صح؛\n\t}\n\tمزارة(عقدة) = 1؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان(عقدة).هات_الطول() ، دليل++ {\n\t\tعرف عقدة_ابن: صـحيح = بيان(عقدة)(دليل)؛\n\t\tإذا مزارة(عقدة_ابن) == 1 {\n\t\t\tارجع صح؛\n\t\t}\n\t\tوإلا إذا مزارة(عقدة_ابن) == 0 && هل_حلقي(عقدة_ابن، مزارة، بيان) {\n\t\t\tارجع صح؛\n\t\t}\n\t}\n\tمزارة(عقدة) = 2؛\n\tارجع خطأ؛\n}\n\n\nدالة هل_داغ(بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]): ثـنائي {\n\tعرف مزارة: مـصفوفة[صـحيح]؛\n\t\n\tعرف دليل1: صـحيح؛\n\tعرف عدد_المكونات: صـحيح = 0؛\n\tلكل دليل1 = 0 ، دليل1 < بيان.هات_الطول() ، دليل1++ {\n\t\tعرف دليل2: صـحيح؛\n\t\tلكل دليل2 = 0 ، دليل2 < بيان.هات_الطول() ، دليل2++ {\n\t\t\tمزارة.أضف(0)؛\n\t\t}\n\n\t\tإذا هل_حلقي(دليل1، مزارة، بيان) {\n\t\t\tارجع خطأ؛\n\t\t}\n\t\tمزارة.فرغ()؛\n\t}\n\t\n\tارجع صح؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction replace(arr, oldValue, newValue) {\n for(var i = 0; i < arr.length; i++) {\n if(arr[i] == oldValue) {\n arr[i] = newValue;\n }\n }\n}\n"}, {"role": "assistant", "content": "Replace a given value with another given value in a given array"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction invert_string(str) {\n return str.split('').reverse().join('');\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة اعكس_نص(س: نـص): نـص {\n\tعرف طول: صـحيح = س.هات_الطول()؛\n\tعرف نتيجة: نـص = \"\"؛\n\n\tعرف دليل: صـحيح؛\n\tلكل دليل = طول - 1 ، دليل >= 0 ، دليل-- {\n\t\tنتيجة.ألحق(س(دليل))؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Fs\";\nimport \"Srl/String\";\n\nuse Srl;\n\n\nfunc read_nth_line(file_path: ref[String], n: Int): String {\n def file: ptr[Fs.File] = Fs.openFile(file_path.buf, \"r\");\n\n def i: Int;\n def temp: Char = ' ';\n for i = 0 , i < n - 1 , i++ {\n temp = ' ';\n while temp != '\\n' {\n Fs.read(temp~ptr, 1, 1, file);\n }\n }\n\n def nth_line: String;\n temp = ' ';\n while temp != '\\n' {\n Fs.read(temp~ptr, 1, 1, file);\n nth_line.append(temp);\n }\n\n return nth_line;\n}\n"}, {"role": "assistant", "content": "#include <stdio.h>\n#include <stdlib.h>\n\n// Function to read the n-th line of a file\nchar* read_nth_line(const char* file_path, int n) {\n FILE* file = fopen(file_path, \"r\");\n if(file == NULL) {\n printf(\"Could not open file %s\\n\", file_path);\n return NULL;\n }\n\n char* line = NULL;\n size_t len = 0;\n ssize_t read;\n\n int current_line = 0;\n while((read = getline(&line, &len, file)) != -1) {\n current_line++;\n if(current_line == n) {\n fclose(file);\n return line;\n }\n }\n\n // If we reach here, then the file has less than n lines\n fclose(file);\n free(line);\n return NULL;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc trim(s: ref[String]) {\n def start: Int = 0;\n def end: Int = s.getLength() - 1;\n\n while (s(start) == ' ' || s(start) == '\\t' || s(start) == '\\n') {\n start++;\n }\n\n while (s(end) == ' ' || s(end) == '\\t' || s(end) == '\\n') {\n end--;\n }\n\n s = s.slice(start, end - start + 1);\n}\n"}, {"role": "assistant", "content": "function trim(str) {\n let start = 0, end = str.length - 1;\n\n // Trim leading white spaces\n while(str[start] === ' ' || str[start] === '\\t' || str[start] === '\\n') start++;\n\n // Trim trailing white spaces\n while(str[end] === ' ' || str[end] === '\\t' || str[end] === '\\n') end--;\n\n // Return the trimmed string\n return str.substring(start, end + 1);\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, print the given array"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"Srl/Console\";\n\n\nuse Srl;\n\n\nfunc print(a: ref[Array[Int]]) {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n Console.print(\"%d \", a(i));\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة يبدأ_ب(س: سند[نـص]، سابق: سند[نـص]): ثـنائي {\n\tإذا س.هات_الطول() < سابق.هات_الطول() {\n\t\tارجع خطأ؛\n\t}\n\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < سابق.هات_الطول() ، دليل++ {\n\t\tإذا سابق(دليل) != س(دليل) {\n\t\t\tارجع خطأ؛\n\t\t}\n\t}\n\tارجع صح؛\n}\n"}, {"role": "assistant", "content": "تحقق فيما إذا كانت سلسلة نصية معطاة تبدأ بسلسلة نصية أخرى معطاة"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\n#include <stdbool.h>\n\nbool is_digit(char c) {\n return (c >= '0' && c <= '9');\n}\n"}, {"role": "assistant", "content": "استخدم مـتم؛\n\n\nدالة ينتمي_للأرقام(م: مـحرف): ثـنائي {\n\tارجع ( م <= '9' && م >= '0')؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Array\";\n\nuse Srl;\n\n\nfunc merge(a: ref[Array[Int]], l: Int, m: Int, r: Int) {\n def i: Int;\n def j: Int;\n def k: Int;\n\n def n1: Int = m - l + 1;\n def n2: Int = r - m;\n\n def L: Array[Int];\n def R: Array[Int];\n\n for i = 0 , i < n1 , i++ {\n L.add(a(l+i));\n }\n for i = 0 , i < n2 , i++ {\n R.add(a(m + 1 + i));\n }\n\n i = 0;\n j = 0;\n k = l;\n while i < n1 && j < n2 {\n if L(i) <= R(j) {\n a(k) = L(i);\n i++;\n }\n else {\n a(k) = R(j);\n j++;\n }\n k++;\n }\n\n while i < n1 {\n a(k) = L(i);\n i++;\n k++;\n }\n\n while j < n2 {\n a(k) = R(j);\n j++;\n k++;\n }\n}\n\nfunc mergeSort(a: ref[Array[Int]], l: Int, r: Int) {\n if l < r {\n def m: Int = l + (r - l) / 2;\n\n mergeSort(a, l, m);\n mergeSort(a, m + 1, r);\n\n merge(a, l, m, r);\n }\n}\n"}, {"role": "assistant", "content": "#include <stdlib.h>\n\nvoid merge(int arr[], int l, int m, int r) {\n int i, j, k;\n int n1 = m - l + 1;\n int n2 = r - m;\n\n int L[n1], R[n2];\n\n for (i = 0; i < n1; i++)\n L[i] = arr[l + i];\n for (j = 0; j < n2; j++)\n R[j] = arr[m + 1 + j];\n\n i = 0;\n j = 0;\n k = l;\n while (i < n1 && j < n2) {\n if (L[i] <= R[j]) {\n arr[k] = L[i];\n i++;\n } else {\n arr[k] = R[j];\n j++;\n }\n k++;\n }\n\n while (i < n1) {\n arr[k] = L[i];\n i++;\n k++;\n }\n\n while (j < n2) {\n arr[k] = R[j];\n j++;\n k++;\n }\n}\n\nvoid mergeSort(int arr[], int l, int r) {\n if (l < r) {\n int m = l + (r - l) / 2;\n\n mergeSort(arr, l, m);\n mergeSort(arr, m + 1, r);\n\n merge(arr, l, m, r);\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nعرف مـصفوفة_ثنائية: لقب مـصفوفة[مـصفوفة[عـائم[64]]]؛\n\n\nدالة جداء(م: سند[مـصفوفة_ثنائية]، س: عـائم[64]): مـصفوفة_ثنائية {\n\tعرف أسطر: صـحيح = م.هات_الطول()؛\n\tعرف أعمدة: صـحيح = م(0).هات_الطول()؛\n\n\tعرف نتيجة: مـصفوفة_ثنائية؛\n\t\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < أسطر ، دليل1++ {\n\t\tنتيجة.أضف(مـصفوفة[عـائم[64]]())؛\n\t\tلكل دليل2 = 0 ، دليل2 < أعمدة ، دليل2++ {\n\t\t\t\tنتيجة(دليل1).أضف(م(دليل1)(دليل2)*س)؛\n\t\t}\n\t}\n\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\ndef Matrix: alias Array[Array[Float[64]]];\n\n\nfunc multiply(m: ref[Matrix], s: Float[64]): Matrix {\n def rows: Int = m.getLength();\n def cols: Int = m(0).getLength();\n \n def result: Matrix;\n\n def i: Int;\n def j: Int;\n for i = 0 , i < rows , i++ {\n result.add(Array[Float[64]]());\n for j = 0 , j < cols , j++ {\n result(i).add(m(i)(j)*s);\n }\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nدالة دفس(عقدة: صـحيح، العقدة_الأب: صـحيح، مزارة: سند[مـصفوفة[ثـنائي]]، بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]): ثـنائي {\n\tمزارة(عقدة) = صح؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان(عقدة).هات_الطول() ، دليل++ {\n\t\tعرف عقدة_ابن: صـحيح = بيان(عقدة)(دليل)؛\n\t\tإذا !مزارة(عقدة_ابن) {\n\t\t\tإذا دفس(عقدة_ابن، عقدة، مزارة، بيان) {\n\t\t\t\tارجع صح؛\n\t\t\t}\n\t\t}\n\t\tوإلا إذا عقدة_ابن != العقدة_الأب {\n\t\t\tارجع صح؛\n\t\t}\n\t}\n\tارجع خطأ؛\n}\n\n\nدالة هل_شجرة(بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]): ثـنائي {\n\tعرف مزارة: مـصفوفة[ثـنائي]؛\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان.هات_الطول() ، دليل++ {\n\t\tمزارة.أضف(خطأ)؛\n\t}\n\t\n\tإذا دفس(0، -1، مزارة، بيان) {\n\t\tارجع خطأ؛\n\t}\n\t\n\tعرف عدد_المكونات: صـحيح = 0؛\n\tلكل دليل = 0 ، دليل < بيان.هات_الطول() ، دليل++ {\n\t\tإذا !مزارة(دليل) {\n\t\t\tارجع خطأ؛\n\t\t}\n\t}\n\t\n\tارجع صح؛\n}\n"}, {"role": "assistant", "content": "let visited = [];\n\nfunction DFS(v, parent, adjList) {\n visited[v] = true;\n for(let i = 0; i < adjList[v].length; i++) {\n if(!visited[adjList[v][i]]) {\n if(DFS(adjList[v][i], v, adjList)) {\n return true;\n }\n } else if(adjList[v][i] != parent) {\n return true;\n }\n }\n return false;\n}\n\nfunction isTree(adjList) {\n visited = new Array(adjList.length).fill(false);\n if(DFS(0, -1, adjList)) {\n return false;\n }\n for(let i = 0; i < adjList.length; i++) {\n if(!visited[i]) {\n return false;\n }\n }\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جمع(م: سند[مـصفوفة[صـحيح]]، بداية: صـحيح، نهاية: صـحيح): صـحيح {\n\tعرف نتيجة: صـحيح = 0؛\n\n\tعرف دليل: صـحيح؛\n\n\tلكل دليل = بداية ، دليل < نهاية ، دليل++ {\n نتيجة += م(دليل)؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "int sum(int a[], int n, int start, int end) {\n int result = 0;\n for (int i = start; i < end; i++) {\n result += a[i];\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/ريـاضيات\"؛\n\nاستخدم مـتم؛\n\n\nدالة انحراف_معياري(م: سند[مـصفوفة[صـحيح]]، متوسط: عـائم): عـائم {\n\tعرف حجم: صـحيح = م.هات_الطول()؛\n\tعرف تباين: عـائم = 0؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < حجم ، دليل++ {\n\t\tتباين += (م(دليل) - متوسط) * (م(دليل) - متوسط)؛\n\t}\n\t\n\tارجع ريـاضيات.جذر(تباين / حجم)؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"Srl/Math\";\n\n\nuse Srl;\n\n\nfunc std(a: ref[Array[Int]], mean: Float): Float {\n def size: Int = a.getLength();\n def variance: Float = 0;\n\n def i: Int;\n for i = 0 , i < size , i++ {\n variance += (a(i) - mean) * ( a(i) - mean);\n }\n\n return Math.sqrt(variance / size);\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc rotate(a: ref[Array[Int]]) {\n def size: Int = a.getLength();\n\n def first_element: Int = a(0);\n\n def i: Int;\n for i = 0 , i < size - 1 , i++ {\n a(i) = a(i + 1);\n }\n\n a(size - 1) = first_element;\n}\n"}, {"role": "assistant", "content": "rotate the given array counterclockwise and return the result"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nconst V = 4;\n\nfunction floydWarshall(graph) {\n let dist = [];\n for (let i = 0; i < V; i++) {\n dist[i] = [];\n for (let j = 0; j < V; j++) {\n dist[i][j] = graph[i][j];\n }\n }\n\n for (let k = 0; k < V; k++) {\n for (let i = 0; i < V; i++) {\n for (let j = 0; j < V; j++) {\n if (dist[i][k] + dist[k][j] < dist[i][j]) {\n dist[i][j] = dist[i][k] + dist[k][j];\n }\n }\n }\n }\n\n return dist;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة فلويد_وارشال(بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]، مسافة: سند[مـصفوفة[مـصفوفة[صـحيح]]]) {\n\tعرف حجم: صـحيح = بيان.هات_الطول()؛\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tعرف دليل3: صـحيح؛\n\n\t\n\tلكل دليل1 = 0 ، دليل1 < حجم ، دليل1++ {\n\t\tمسافة.أضف(بيان(دليل1))؛\n\t}\n\t\n\tلكل دليل3 = 0 ، دليل3 < حجم ، دليل3++ {\n\t\tلكل دليل1 = 0 ، دليل1 < حجم ، دليل1++ {\n\t\t\tلكل دليل2 = 0 ، دليل2 < حجم ، دليل2++ {\n\t\t\t\tإذا مسافة(دليل1)(دليل3) + مسافة(دليل3)(دليل2) < مسافة(دليل1)(دليل2) {\n\t\t\t\t\tمسافة(دليل1)(دليل2) = مسافة(دليل1)(دليل3) + مسافة(دليل3)(دليل2)؛\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جد_أكثر_عنصر_مكرر(م: سند[مـصفوفة[صـحيح]]): صـحيح {\n\tعرف أكثر_تكرار: صـحيح = 0؛\n\tعرف نتيجة: صـحيح = -1؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tعرف عداد: صـحيح = 1؛\n\t\t\n\t\tعرف دليل2: صـحيح؛\n\t\tلكل دليل2 = دليل + 1 ، دليل2 < م.هات_الطول() ، دليل2++ {\n\t\t\tإذا م(دليل2) == م(دليل) {\n\t\t\t\tعداد++؛\n\t\t\t}\n\t\t}\n\t\t\n\t\tإذا عداد > أكثر_تكرار {\n\t\t\tأكثر_تكرار = عداد؛\n\t\t\tنتيجة = م(دليل)؛\n\t\t}\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "function findMostFrequent(arr) {\n var maxCount = 0, res = -1;\n\n for (var i = 0; i < arr.length; i++) {\n var count = 1;\n for (var j = i + 1; j < arr.length; j++)\n if (arr[i] == arr[j])\n count++;\n if (count > maxCount) {\n maxCount = count;\n res = arr[i];\n }\n }\n\n return res;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, Find the intersection point of two given lines (the line represented by three values `a`, `b`, `c` as ax + by + c = 0) and return it, in case of parallel line return null or empty array"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\nfunc findIntersection(a1: Float[64], b1: Float[64], c1: Float[64], a2: Float[64], b2: Float[64], c2: Float[64]): Array[Float[64]] {\n def result: Array[Float[64]];\n if a1*b2 - a2*b1 == 0 {\n return result;\n }\n\n result.add((b1*c2 - b2*c1) / (a1*b2 - a2*b1));\n result.add((a2*c1 - a1*c2) / (a1*b2 - a2*b1));\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Array\";\n\nuse Srl;\n\ndef Matrix: alias Array[Array[Float[64]]];\n\nfunc multiply(a: ref[Matrix], b: ref[Matrix]): Matrix {\n def rowsA: Int = a.getLength();\n def rowsB: Int = b.getLength();\n def colsA: Int = a(0).getLength();\n def colsB: Int = b(0).getLength();\n \n def result: Matrix;\n\n def i: Int;\n def j: Int;\n def k: Int;\n for i = 0 , i < rowsA , i++ {\n def row: Array[Float[64]];\n for j = 0 , j < colsB , j++ {\n row.add(0);\n for k = 0 , k < colsA , k++ {\n row(j) += a(i)(k) * b(k)(j);\n }\n }\n result.add(row);\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "#include <stdlib.h>\n\n// Function to multiply two matrices\nint** multiply(int** a, int** b, int r1, int c1, int r2, int c2) {\n int i, j, k;\n // Create a result matrix dynamically\n int** result = (int**)malloc(r1 * sizeof(int*));\n for(i = 0; i < r1; i++) {\n result[i] = (int*)malloc(c2 * sizeof(int));\n }\n\n // Initialize the result matrix with 0\n for(i = 0; i < r1; i++) {\n for(j = 0; j < c2; j++) {\n result[i][j] = 0;\n }\n }\n\n // Multiply the two matrices\n for(i = 0; i < r1; i++) {\n for(j = 0; j < c2; j++) {\n for(k = 0; k < c1; k++) {\n result[i][j] += a[i][k] * b[k][j];\n }\n }\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/ريـاضيات\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nصنف نـقطة {\n\tعرف س: عـائم؛\n\tعرف ص: عـائم؛\n}\n\nدالة احسب_مسافة(ن1: نـقطة، ن2: نـقطة): عـائم {\n\tارجع ريـاضيات.جذر(ريـاضيات.ارفع(ن2.س - ن1.س، 2.0) + ريـاضيات.ارفع(ن2.ص - ن1.ص، 2.0))؛\n}\n\nدالة جد_أبعد_نقطة(ن: نـقطة، نقاط: سند[مـصفوفة[نـقطة]]): نـقطة {\n\tعرف أبعد_مسافة: عـائم = 0؛\n\tعرف أبعد_نقطة: نـقطة؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < نقاط.هات_الطول() ، دليل++ {\n\t\tعرف مسافة: عـائم = احسب_مسافة(ن، نقاط(دليل))؛\n\t\tإذا مسافة > أبعد_مسافة {\n\t\t\tأبعد_مسافة = مسافة؛\n\t\t\tأبعد_نقطة = نقاط(دليل)؛\n\t\t}\n\t}\n\tارجع أبعد_نقطة؛\n}\n"}, {"role": "assistant", "content": "#include <math.h>\n\ntypedef struct {\n double x;\n double y;\n} Point;\n\ndouble calculateDistance(Point a, Point b) {\n return sqrt(pow(b.x - a.x, 2) + pow(b.y - a.y, 2));\n}\n\nPoint findFarthestPoint(Point givenPoint, Point points[], int size) {\n double maxDistance = 0;\n Point farthestPoint;\n \n for(int i = 0; i < size; i++) {\n double distance = calculateDistance(givenPoint, points[i]);\n if(distance > maxDistance) {\n maxDistance = distance;\n farthestPoint = points[i];\n }\n }\n \n return farthestPoint;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة اقتطع(م: سند[مـصفوفة[صـحيح]]، أدنى: صـحيح، أعلى: صـحيح) {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا م(دليل) < أدنى {\n\t\t\tم(دليل) = أدنى؛\n\t\t}\n\t\tوإلا إذا م(دليل) > أعلى {\n\t\t\tم(دليل) = أعلى؛\n\t\t}\n\t}\n}\n"}, {"role": "assistant", "content": "void clip(int arr[], int n, int lower, int upper) {\n for(int i = 0; i < n; i++) {\n if(arr[i] < lower) {\n arr[i] = lower;\n } else if(arr[i] > upper) {\n arr[i] = upper;\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, جد و أرجع أبعد نقطة من بين مجموعة من النقاط المعطاة عن نقطة معطاة"}, {"role": "assistant", "content": "اشمل \"مـتم/ريـاضيات\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nصنف نـقطة {\n\tعرف س: عـائم؛\n\tعرف ص: عـائم؛\n}\n\nدالة احسب_مسافة(ن1: نـقطة، ن2: نـقطة): عـائم {\n\tارجع ريـاضيات.جذر(ريـاضيات.ارفع(ن2.س - ن1.س، 2.0) + ريـاضيات.ارفع(ن2.ص - ن1.ص، 2.0))؛\n}\n\nدالة جد_أبعد_نقطة(ن: نـقطة، نقاط: سند[مـصفوفة[نـقطة]]): نـقطة {\n\tعرف أبعد_مسافة: عـائم = 0؛\n\tعرف أبعد_نقطة: نـقطة؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < نقاط.هات_الطول() ، دليل++ {\n\t\tعرف مسافة: عـائم = احسب_مسافة(ن، نقاط(دليل))؛\n\t\tإذا مسافة > أبعد_مسافة {\n\t\t\tأبعد_مسافة = مسافة؛\n\t\t\tأبعد_نقطة = نقاط(دليل)؛\n\t\t}\n\t}\n\tارجع أبعد_نقطة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\n#include <stdlib.h>\n\ntypedef struct {\n double x;\n double y;\n} Point;\n\ndouble calculatePolygonArea(Point* vertices, int numVertices) {\n double area = 0.0;\n int j = numVertices - 1;\n\n for (int i = 0; i < numVertices; i++) {\n area += (vertices[j].x + vertices[i].x) * (vertices[j].y - vertices[i].y);\n j = i;\n }\n\n return abs(area / 2.0);\n}\n\n"}, {"role": "assistant", "content": "import \"Srl/Math\";\nimport \"Srl/Array\";\n\nuse Srl;\n\nclass Point {\n def x : Float;\n def y : Float;\n};\n\nfunc calculatePolygonArea(vertices: ref[Array[Point]]): Float {\n def area: Float = 0;\n def numVertices: Int = vertices.getLength();\n def j: Int = numVertices - 1;\n\n def i: Int;\n for i = 0 , i < numVertices , i++ {\n area += (vertices(j).x + vertices(i).x) * (vertices(j).y - vertices(i).y);\n j = i;\n }\n return Math.abs(area / 2.0);\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/String\";\n\nuse Srl;\n\nfunc slice(s: ref[String], start: Int, end: Int): String {\n def result: String = \"\";\n\n def i: Int;\n for i = start , i <= end , i++ {\n result.append(s(i));\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "Slice a given string within a given range and return the result"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Array\";\nimport \"closure\";\n\n\nuse Srl;\n\n\nfunc check_any(a: ref[Array[Int]], f: closure (num: Int): Bool): Bool {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if f(a(i)) {\n return true;\n }\n }\n\n return false;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة تفحص_أي(م: سند[مـصفوفة[صـحيح]]، د: مغلفة(رقم: صـحيح): ثـنائي): ثـنائي {\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا د(م(دليل)) {\n\t\t\tارجع صح؛\n\t\t}\n\t}\n\n\tارجع خطأ؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة جد_المحرف(س: سند[نـص]، م: مـحرف): صـحيح {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) == م {\n\t\t\tارجع دليل؛\n\t\t}\n\t}\n\tارجع -1؛\n}\n"}, {"role": "assistant", "content": "function find_char(s, c) {\n for (let i = 0; i < s.length; i++) {\n if (s[i] === c) {\n return i;\n }\n }\n return -1;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction is_digit(c) {\n return (c >= '0' && c <= '9');\n}\n"}, {"role": "assistant", "content": "use Srl;\n\n\nfunc is_digit(c: Char): Bool {\n return (c >= '0' && c <= '9');\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\n#include <stdio.h>\n\n#define MAX 100\n\nint visited[MAX];\nint matrix[MAX][MAX];\n\nint DFS(int v, int parent, int n) {\n visited[v] = 1;\n for(int i = 0; i < n; i++) {\n if(matrix[v][i] == 1) {\n if(!visited[i]) {\n if(DFS(i, v, n)) {\n return 1;\n }\n } else if(i != parent) {\n return 1;\n }\n }\n }\n return 0;\n}\n\nint isTree(int n) {\n if(DFS(0, -1, n)) {\n return 0;\n }\n for(int i = 0; i < n; i++) {\n if(!visited[i]) {\n return 0;\n }\n }\n return 1;\n}\n"}, {"role": "assistant", "content": "Check if a given undirected graph is tree"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, أزل أي محرف فراغ من كلتا نهايتي سلسلة نصية معطاة"}, {"role": "assistant", "content": "اشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة شذب(س: سند[نـص]) {\n\tعرف بداية: صـحيح = 0؛\n\tعرف نهاية: صـحيح = س.هات_الطول() - 1؛\n\t\n\tبينما (س(بداية) == ' ' || س(بداية) == '\\t' || س(بداية) == '\\n') {\n\t\tبداية++؛\n\t}\n\t\n\tبينما (س(نهاية) == ' ' || س(نهاية) == '\\t' || س(نهاية) == '\\n') {\n\t\tنهاية--؛\n\t}\n\t\n\tس = س.اجتزئ(بداية، نهاية - بداية + 1)؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة موجود(م: سند[مـصفوفة[صـحيح]]، قيمة: صـحيح): ثـنائي {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا م(دليل) == قيمة {\n\t\t\tارجع صح؛\n\t\t}\n\t}\n\tارجع خطأ؛\n}\n"}, {"role": "assistant", "content": "اختبر فيما إذا كانت مصفوفة معطاة تحتوي على عنصر معطى"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Array\";\nimport \"closure\";\n\n\nuse Srl;\n\n\nfunc accumulate(a: ref[Array[Int]], f: closure (previousValue: Int, currentValue: Int): Int): Array[Int] {\n def size: Int = a.getLength();\n def result: Array[Int];\n\n def i: Int;\n result.add(a(0));\n for i = 1 , i < a.getLength() , i++ {\n result.add(f(result(i-1), a(i)));\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "function accumulate(a, f) {\n let result = [];\n result[0] = a[0];\n for(let i = 1; i < a.length; i++) {\n result[i] = f(result[i-1], a[i]);\n }\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nconst fs = require('fs');\n\n// Function to read the content of a file into a string one character at a time\nfunction read_file(file_path) {\n const fileDescriptor = fs.openSync(file_path, 'r');\n let file_content = '';\n let buffer = Buffer.alloc(1);\n\n // Read the file one character at a time\n while(fs.readSync(fileDescriptor, buffer, 0, 1)) {\n file_content += buffer.toString();\n }\n\n fs.closeSync(fileDescriptor);\n return file_content;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Fs\";\nimport \"Srl/String\";\n\nuse Srl;\n\n\nfunc read_file(file_path: ref[String]): String {\n def file: ptr[Fs.File] = Fs.openFile(file_path.buf, \"r\");\n def content: String;\n\n Fs.seek(file, 0, Fs.Seek.END);\n def size: Int = Fs.tell(file);\n Fs.seek(file, 0, Fs.Seek.SET);\n \n\n def i: Int;\n for i = 0 , i < size , i++ {\n def temp: Char;\n Fs.read(temp~ptr, 1, 1, file);\n content.append(temp);\n }\n\n return content;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, Calculate the product of two given matrices represented by a 2D array and return the result"}, {"role": "assistant", "content": "#include <stdlib.h>\n\n// Function to multiply two matrices\nint** multiply(int** a, int** b, int r1, int c1, int r2, int c2) {\n int i, j, k;\n // Create a result matrix dynamically\n int** result = (int**)malloc(r1 * sizeof(int*));\n for(i = 0; i < r1; i++) {\n result[i] = (int*)malloc(c2 * sizeof(int));\n }\n\n // Initialize the result matrix with 0\n for(i = 0; i < r1; i++) {\n for(j = 0; j < c2; j++) {\n result[i][j] = 0;\n }\n }\n\n // Multiply the two matrices\n for(i = 0; i < r1; i++) {\n for(j = 0; j < c2; j++) {\n for(k = 0; k < c1; k++) {\n result[i][j] += a[i][k] * b[k][j];\n }\n }\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جد_أكثر_عنصر_مكرر(م: سند[مـصفوفة[صـحيح]]): صـحيح {\n\tعرف أكثر_تكرار: صـحيح = 0؛\n\tعرف نتيجة: صـحيح = -1؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tعرف عداد: صـحيح = 1؛\n\t\t\n\t\tعرف دليل2: صـحيح؛\n\t\tلكل دليل2 = دليل + 1 ، دليل2 < م.هات_الطول() ، دليل2++ {\n\t\t\tإذا م(دليل2) == م(دليل) {\n\t\t\t\tعداد++؛\n\t\t\t}\n\t\t}\n\t\t\n\t\tإذا عداد > أكثر_تكرار {\n\t\t\tأكثر_تكرار = عداد؛\n\t\t\tنتيجة = م(دليل)؛\n\t\t}\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc find_most_frequent(a: ref[Array[Int]]): Int {\n def max_count: Int = 0;\n def res: Int = -1;\n\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n def count: Int = 1;\n \n def j: Int;\n for j = i + 1 , j < a.getLength() , j++ {\n if a(j) == a(i) {\n count++;\n }\n }\n\n if count > max_count {\n max_count = count;\n res = a(i);\n }\n }\n\n return res;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/طـرفية\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nدالة دفس(عقدة: صـحيح، مزارة: سند[مـصفوفة[ثـنائي]]، بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]) {\n\tمزارة(عقدة) = صح؛\n\tطـرفية.اطبع(\"%d \"، عقدة)؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان(عقدة).هات_الطول() ، دليل++ {\n\t\tعرف عقدة_ابن: صـحيح = بيان(عقدة)(دليل)؛\n\t\tإذا !مزارة(عقدة_ابن) {\n\t\t\tدفس(عقدة_ابن، مزارة، بيان)؛\n\t\t}\n\t}\n}\n"}, {"role": "assistant", "content": "function dfs(node, visited, G) {\n visited[node] = true;\n console.log(node);\n\n for(let i = 0; i < G[node].length; i++) {\n if(!visited[G[node][i]]) {\n dfs(G[node][i], visited, G);\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction toLowerCase(s) {\n let result = '';\n for(let i = 0; i < s.length; i++){\n let code = s.charCodeAt(i);\n if(code >= 65 && code <= 90){\n result += String.fromCharCode(code + 32);\n } else {\n result += s[i];\n }\n }\n return result;\n}\n"}, {"role": "assistant", "content": "convert string to lowercase and return the result"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة فلويد_وارشال(بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]، مسافة: سند[مـصفوفة[مـصفوفة[صـحيح]]]) {\n\tعرف حجم: صـحيح = بيان.هات_الطول()؛\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tعرف دليل3: صـحيح؛\n\n\t\n\tلكل دليل1 = 0 ، دليل1 < حجم ، دليل1++ {\n\t\tمسافة.أضف(بيان(دليل1))؛\n\t}\n\t\n\tلكل دليل3 = 0 ، دليل3 < حجم ، دليل3++ {\n\t\tلكل دليل1 = 0 ، دليل1 < حجم ، دليل1++ {\n\t\t\tلكل دليل2 = 0 ، دليل2 < حجم ، دليل2++ {\n\t\t\t\tإذا مسافة(دليل1)(دليل3) + مسافة(دليل3)(دليل2) < مسافة(دليل1)(دليل2) {\n\t\t\t\t\tمسافة(دليل1)(دليل2) = مسافة(دليل1)(دليل3) + مسافة(دليل3)(دليل2)؛\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\n}\n"}, {"role": "assistant", "content": "#define V 4\n\nvoid floydWarshall (int graph[V][V], int dist[V][V]) \n{ \n int i, j, k; \n \n for (i = 0; i < V; i++) \n for (j = 0; j < V; j++) \n dist[i][j] = graph[i][j]; \n \n for (k = 0; k < V; k++) \n { \n for (i = 0; i < V; i++) \n { \n for (j = 0; j < V; j++) \n { \n if (dist[i][k] + dist[k][j] < dist[i][j]) \n dist[i][j] = dist[i][k] + dist[k][j]; \n } \n } \n }\n} \n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Array\";\n\nuse Srl;\n\n\nfunc invertArray(a: ref[Array[Int]]) {\n def start: Int = 0;\n def end: Int = a.getLength() - 1;\n\n while start < end {\n def temp: Int = a(start);\n a(start) = a(end);\n a(end) = temp;\n start++;\n end--;\n }\n}\n"}, {"role": "assistant", "content": "void invertArray(int a[], int n) {\n int start = 0;\n int end = n - 1;\n while (start < end) {\n int temp = a[start];\n a[start] = a[end];\n a[end] = temp;\n start++;\n end--;\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nint find_char(char s[], int n, char c) {\n for (int i = 0; i < n; i++) {\n if (s[i] == c) {\n return i;\n }\n }\n return -1;\n}\n"}, {"role": "assistant", "content": "find and return the position of a given char in a given string"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc exists(a: ref[Array[Int]], val: Int): Bool {\n def i: Int;\n for i = 0, i < a.getLength(), i++ {\n if a(i) == val {\n return true;\n }\n }\n return false;\n}\n"}, {"role": "assistant", "content": "check if a given array contains a given element"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/نـص\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة اختصر(م: سند[مـصفوفة[نـص]]، د: مغلفة(قيمة_سابقة: سند[نـص]، قيمة_حالية: سند[نـص])): نـص {\n\tعرف نتيجة: نـص = \"\"؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tد(نتيجة، م(دليل))؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"Srl/String\";\nimport \"closure\";\n\nuse Srl;\n\n\nfunc reduce(a: ref[Array[String]], f: closure(previousValue: ref[String], currentValue: ref[String])): String {\n def result: String = \"\";\n\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n f(result, a(i));\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, Find the number of connected components in a given undirected graph"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\nfunc dfs(node: Int, visited: ref[Array[Bool]], graph: ref[Array[Array[Int]]]) {\n visited(node) = true;\n\n def i: Int;\n for i = 0 , i < graph(node).getLength(), i++ {\n def childNode: Int = graph(node)(i);\n if !visited(childNode) {\n dfs(childNode, visited, graph);\n }\n }\n}\n\n\nfunc numberOfConnectedComponents(graph: ref[Array[Array[Int]]]): Int {\n def visited: Array[Bool];\n def i: Int;\n for i = 0 , i < graph.getLength() , i++ {\n visited.add(false);\n }\n\n def components: Int = 0;\n for i = 0 , i < graph.getLength() , i++ {\n if !visited(i) {\n dfs(i, visited, graph);\n components++;\n }\n }\n\n return components;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction slice(arr, start, end) {\n let result = [];\n for(let i = start; i <= end; i++) {\n result.push(arr[i]);\n }\n return result;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc slice(a: ref[Array[Int]], start: Int, end: Int, result: ref[Array[Int]]) {\n def i: Int;\n for i = start , i <= end , i++ {\n result.add(a(i));\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\nvoid toLowerCase(char *s, char *result) {\n for(int i = 0; s[i]; i++){\n if(s[i] >= 'A' && s[i] <= 'Z'){\n result[i] = s[i] - 'A' + 'a';\n }\n else {\n result[i] = s[i];\n }\n }\n}\n"}, {"role": "assistant", "content": "import \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc toLowerCase(s: ref[String]): String {\n\tdef result: String = \"\";\n def i: Int;\n\tdef c: Char;\n\tfor i = 0 , i < s.getLength() , i++ {\n\t\tif (s(i) >= 'A' && s(i) <= 'Z') {\n\t\t\tc = s(i) - 'A' + 'a';\n\t\t}\n\t\telse {\n\t\t\tc = s(i);\n\t\t}\n\t\tresult += c;\n\t}\n\treturn result;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاستخدم مـتم؛\n\n\nدالة ينتمي_للأبجدية(م: مـحرف): ثـنائي {\n\tارجع ( م <= 'Z' && م >= 'A') || ( م <= 'z' && م >= 'a')؛\n}\n"}, {"role": "assistant", "content": "اختبر فيما إذا كان محرف معطى من الأبجدية"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, اكتب خوارزمية الفرز بالدمج لمصفوفة معطاة"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة ادمج(م: سند[مـصفوفة[صـحيح]]، يسار: صـحيح، وسط: صـحيح، يمين: صـحيح) {\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tعرف دليل3: صـحيح؛\n\t\n\tعرف حجم1: صـحيح = وسط - يسار + 1؛\n\tعرف حجم2: صـحيح = يمين - وسط؛\n\t\n\tعرف م_يسار: مـصفوفة[صـحيح]؛\n\tعرف م_يمين: مـصفوفة[صـحيح]؛\n\t\n\tلكل دليل1 = 0 ، دليل1 < حجم1 ، دليل1++ {\n\t\tم_يسار.أضف(م(يسار+دليل1))؛\n\t}\n\tلكل دليل1 = 0 ، دليل1 < حجم2 ، دليل1++ {\n\t\tم_يمين.أضف(م(وسط + 1 + دليل1))؛\n\t}\n\t\n\tدليل1 = 0؛\n\tدليل2 = 0؛\n\tدليل3 = يسار؛\n\t\n\tبينما دليل1 < حجم1 && دليل2 < حجم2 {\n\t\tإذا م_يسار(دليل1) <= م_يمين(دليل2) {\n\t\t\tم(دليل3) = م_يسار(دليل1)؛\n\t\t\tدليل1++؛\n\t\t}\n\t\tوإلا {\n\t\t\tم(دليل3) = م_يمين(دليل2)؛\n\t\t\tدليل2++؛\n\t\t}\n\t\tدليل3++؛\n\t}\n\t\n\tبينما دليل1 < حجم1 {\n\t\tم(دليل3) = م_يسار(دليل1)؛\n\t\tدليل1++؛\n\t\tدليل3++؛\n\t}\n\t\n\tبينما دليل2 < حجم2 {\n\t\tم(دليل3) = م_يمين(دليل2)؛\n\t\tدليل2++؛\n\t\tدليل3++؛\n\t}\n}\n\n\nدالة ترتيب_بالدمج(م: سند[مـصفوفة[صـحيح]]، يسار: صـحيح، يمين: صـحيح) {\n\tإذا يسار < يمين {\n\t\tعرف وسط: صـحيح = يسار + (يمين - يسار) / 2؛\n\t\t\n\t\tترتيب_بالدمج(م، يسار، وسط)؛\n\t\tترتيب_بالدمج(م، وسط + 1، يمين)؛\n\t\t\n\t\tادمج(م، يسار، وسط، يمين)؛\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, Find and return the maximum in the given array `a`"}, {"role": "assistant", "content": "int findMax(int* a, int n) {\n int max = a[0];\n for(int i = 1; i < n; i++) {\n if(a[i] > max) {\n max = a[i];\n }\n }\n return max;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جمع(م: سند[مـصفوفة[صـحيح]]): صـحيح {\n\tعرف نتيجة: صـحيح = 0؛\n\n\tعرف دليل: صـحيح؛\n\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n نتيجة += م(دليل)؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "int sum(int a[], int n) {\n int result = 0;\n for (int i = 0; i < n; i++) {\n result += a[i];\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة متوسط(م: سند[مـصفوفة[صـحيح]]): عـائم {\n\tعرف حجم: صـحيح = م.هات_الطول()؛\n\tعرف مجموع: صـحيح = 0؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < حجم ، دليل++ {\n\t\tمجموع += م(دليل)؛\n\t}\n\t\n\tارجع مجموع~مثل[عـائم] / حجم؛\n}\n"}, {"role": "assistant", "content": "احسب و أرجع المتوسط الحسابي للمصفوفة المعطاة"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Fs\";\nimport \"Srl/String\";\n\nuse Srl;\n\n\nfunc read_nth_line(file_path: ref[String], n: Int): String {\n def file: ptr[Fs.File] = Fs.openFile(file_path.buf, \"r\");\n\n def i: Int;\n def temp: Char = ' ';\n for i = 0 , i < n - 1 , i++ {\n temp = ' ';\n while temp != '\\n' {\n Fs.read(temp~ptr, 1, 1, file);\n }\n }\n\n def nth_line: String;\n temp = ' ';\n while temp != '\\n' {\n Fs.read(temp~ptr, 1, 1, file);\n nth_line.append(temp);\n }\n\n return nth_line;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/نـم\"؛\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة اقرأ_السطر_ن(مسار_الملف: سند[نـص]، ن: صـحيح): نـص {\n\tعرف ملف: مؤشر[نـم.مـلف] = نـم.افتح_ملف(مسار_الملف، \"r\")؛\n\t\n\tعرف دليل: صـحيح؛\n\tعرف مؤقت: مـحرف = ' '؛\n\tلكل دليل = 0 ، دليل < ن - 1 ، دليل++ {\n\t\tمؤقت = ' '؛\n\t\tبينما مؤقت != '\\n' {\n\t\t\tنـم.اقرأ(مؤقت~مؤشر، 1، 1، ملف)؛\n\t\t}\n\t}\n\t\n\tعرف السطر_ن: نـص؛\n\tمؤقت = ' '؛\n\tبينما مؤقت != '\\n' {\n\t\tنـم.اقرأ(مؤقت~مؤشر، 1، 1، ملف)؛\n\t\tالسطر_ن.ألحق(مؤقت)؛\n\t}\n\t\n\tارجع السطر_ن؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Array\";\n\nuse Srl;\n\nfunc dfs(node: Int, visited: ref[Array[Bool]], graph: ref[Array[Array[Int]]]) {\n visited(node) = true;\n\n def i: Int;\n for i = 0 , i < graph(node).getLength(), i++ {\n def childNode: Int = graph(node)(i);\n if !visited(childNode) {\n dfs(childNode, visited, graph);\n }\n }\n}\n\n\nfunc numberOfConnectedComponents(graph: ref[Array[Array[Int]]]): Int {\n def visited: Array[Bool];\n def i: Int;\n for i = 0 , i < graph.getLength() , i++ {\n visited.add(false);\n }\n\n def components: Int = 0;\n for i = 0 , i < graph.getLength() , i++ {\n if !visited(i) {\n dfs(i, visited, graph);\n components++;\n }\n }\n\n return components;\n}\n"}, {"role": "assistant", "content": "Find the number of connected components in a given undirected graph"}]}
{"messages": [{"role": "user", "content": "What this code do?\n#include <stdbool.h>\n\ntypedef struct {\n int x;\n int y;\n} Point;\n\nbool areCollinear(Point p1, Point p2, Point p3) {\n // Calculate the slopes of the lines formed by (p1, p2) and (p1, p3)\n // If the slopes are equal, then p1, p2 and p3 are collinear\n return (p2.y - p1.y) * (p3.x - p1.x) == (p3.y - p1.y) * (p2.x - p1.x);\n}\n"}, {"role": "assistant", "content": "check if three given points are collinear"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/String\";\n\nuse Srl;\n\nfunc slice(s: ref[String], start: Int, end: Int): String {\n def result: String = \"\";\n\n def i: Int;\n for i = start , i <= end , i++ {\n result.append(s(i));\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "function slice_string(str, start, end) {\n var result = \"\";\n for(var i = start; i <= end; i++) {\n result += str[i];\n }\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\n#include <math.h>\n\ntypedef struct {\n double x;\n double y;\n} Point;\n\ndouble calculateDistance(Point a, Point b) {\n return sqrt(pow(b.x - a.x, 2) + pow(b.y - a.y, 2));\n}\n\nPoint findFarthestPoint(Point givenPoint, Point points[], int size) {\n double maxDistance = 0;\n Point farthestPoint;\n \n for(int i = 0; i < size; i++) {\n double distance = calculateDistance(givenPoint, points[i]);\n if(distance > maxDistance) {\n maxDistance = distance;\n farthestPoint = points[i];\n }\n }\n \n return farthestPoint;\n}\n"}, {"role": "assistant", "content": "find and return the farthest point to a given point from a given set of points"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاستخدم مـتم؛\n\n\nدالة ينتمي_للأبجدية(م: مـحرف): ثـنائي {\n\tارجع ( م <= 'Z' && م >= 'A') || ( م <= 'z' && م >= 'a')؛\n}\n"}, {"role": "assistant", "content": "#include <stdbool.h>\n\nbool is_alphabet(char c) {\n return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة هيئ_مصفوفة(م: سند[مـصفوفة[صـحيح]]، حجم: صـحيح، قيمة: صـحيح) {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < حجم ، دليل++ {\n\t\tم.أضف(قيمة)؛\n\t}\n}\n"}, {"role": "assistant", "content": "هيئ مصفوفة معطاة لها حجم معطى بقيمة معطاة"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction findMostFrequent(arr) {\n var maxCount = 0, res = -1;\n\n for (var i = 0; i < arr.length; i++) {\n var count = 1;\n for (var j = i + 1; j < arr.length; j++)\n if (arr[i] == arr[j])\n count++;\n if (count > maxCount) {\n maxCount = count;\n res = arr[i];\n }\n }\n\n return res;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc find_most_frequent(a: ref[Array[Int]]): Int {\n def max_count: Int = 0;\n def res: Int = -1;\n\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n def count: Int = 1;\n \n def j: Int;\n for j = i + 1 , j < a.getLength() , j++ {\n if a(j) == a(i) {\n count++;\n }\n }\n\n if count > max_count {\n max_count = count;\n res = a(i);\n }\n }\n\n return res;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Array\";\n\nuse Srl;\n\nfunc sum(a: ref[Array[Int]]): Int {\n def sum: Int = 0;\n\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n sum += a(i);\n }\n\n return sum;\n}\n"}, {"role": "assistant", "content": "int sum(int a[], int n) {\n int result = 0;\n for (int i = 0; i < n; i++) {\n result += a[i];\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, ألحق سجل إلى ملف معطى مساره"}, {"role": "assistant", "content": "اشمل \"مـتم/نـم\"؛\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة ألحق_سجل(مسار_الملف: سند[نـص]، سجل: سند[نـص]) {\n\tعرف ملف: مؤشر[نـم.مـلف] = نـم.افتح_ملف(مسار_الملف، \"a\")؛\n\t\n\tنـم.اكتب(سجل.صوان، 1، سجل.هات_الطول()، ملف)؛\n\tنـم.اكتب(\"\\ج\"، 1، 1، ملف)؛\n\tنـم.اغلق_ملف(ملف)؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\n#include <stdbool.h>\n\nvoid filter(int a[], int size, int result[], int *newSize, bool (*condition)(int)) {\n *newSize = 0;\n for (int i = 0; i < size; i++) {\n if (condition(a[i])) {\n result[(*newSize)++] = a[i];\n }\n }\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"closure\";\n\n\nuse Srl;\n\n\nfunc filter(a: ref[Array[Int]], f: closure (num: Int): Bool): Array[Int] {\n def result: Array[Int];\n\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if f(a(i)) {\n result.add(a(i));\n }\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/نـم\"؛\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة اقرأ_السطر_ن(مسار_الملف: سند[نـص]، ن: صـحيح): نـص {\n\tعرف ملف: مؤشر[نـم.مـلف] = نـم.افتح_ملف(مسار_الملف، \"r\")؛\n\t\n\tعرف دليل: صـحيح؛\n\tعرف مؤقت: مـحرف = ' '؛\n\tلكل دليل = 0 ، دليل < ن - 1 ، دليل++ {\n\t\tمؤقت = ' '؛\n\t\tبينما مؤقت != '\\n' {\n\t\t\tنـم.اقرأ(مؤقت~مؤشر، 1، 1، ملف)؛\n\t\t}\n\t}\n\t\n\tعرف السطر_ن: نـص؛\n\tمؤقت = ' '؛\n\tبينما مؤقت != '\\n' {\n\t\tنـم.اقرأ(مؤقت~مؤشر، 1، 1، ملف)؛\n\t\tالسطر_ن.ألحق(مؤقت)؛\n\t}\n\t\n\tارجع السطر_ن؛\n}\n"}, {"role": "assistant", "content": "اقرأ السطر ن لملف نصي معطى مساره و ارجع النتيجة"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, Read the nth line of a text file given its path and return the result"}, {"role": "assistant", "content": "import \"Srl/Fs\";\nimport \"Srl/String\";\n\nuse Srl;\n\n\nfunc read_nth_line(file_path: ref[String], n: Int): String {\n def file: ptr[Fs.File] = Fs.openFile(file_path.buf, \"r\");\n\n def i: Int;\n def temp: Char = ' ';\n for i = 0 , i < n - 1 , i++ {\n temp = ' ';\n while temp != '\\n' {\n Fs.read(temp~ptr, 1, 1, file);\n }\n }\n\n def nth_line: String;\n temp = ' ';\n while temp != '\\n' {\n Fs.read(temp~ptr, 1, 1, file);\n nth_line.append(temp);\n }\n\n return nth_line;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, calculate and return the area of polygon given its vertices"}, {"role": "assistant", "content": "function calculatePolygonArea(vertices) {\n let area = 0;\n let j = vertices.length - 1;\n\n for (let i = 0; i < vertices.length; i++) {\n area += (vertices[j].x + vertices[i].x) * (vertices[j].y - vertices[i].y);\n j = i;\n }\n\n return Math.abs(area / 2);\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\nvoid insert(int a[], int n, int pos, int x) {\n // Shift elements to right\n for (int i = n; i > pos; i--)\n a[i] = a[i - 1];\n\n // Insert x at pos\n a[pos] = x;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة احشر(م: سند[مـصفوفة[صـحيح]]، موقع: صـحيح، قيمة: صـحيح) {\n\tعرف حجم: صـحيح = م.هات_الطول()؛\n\tم.أضف(0)؛ // لزيادة الحجم بمقدار 1\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = حجم ، دليل > موقع ، دليل-- {\n\t\tم(دليل) = م(دليل - 1)؛\n\t}\n\t\n\tم(موقع) = قيمة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, write the counting sort algorithm for a given array"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\n\ndef MAX_VALUE: Int = 100000;\n\nfunc countingSort(a: ref[Array[Int]]) {\n def i: Int;\n def j: Int;\n def idx: Int;\n\n def count: Array[Int];\n for i = 0 , i < MAX_VALUE , i++ {\n count.add(0);\n }\n\n for i = 0 , i < a.getLength() , i++ {\n count(a(i))++;\n }\n\n for i = 0 , i < MAX_VALUE , i++ {\n for j = 0 , j < count(i) , j++ {\n a(idx++) = i;\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/نـص\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جزئ(س: سند[نـص]، رمز: مـحرف): مـصفوفة[نـص] {\n\tعرف نتيجة: مـصفوفة[نـص]؛\n\t\n\tعرف مؤقت: نـص؛\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) != رمز {\n\t\t\tمؤقت.ألحق(س(دليل))؛\n\t\t}\n\t\tوإلا {\n\t\t\tنتيجة.أضف(مؤقت)؛\n\t\t\tمؤقت = \"\"؛\n\t\t}\n\t}\n\tنتيجة.أضف(مؤقت)؛\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/String\";\nimport \"Srl/Array\"\n\nuse Srl;\n\n\nfunc split(s: ref[String], token: Char): Array[String] {\n def result: Array[String];\n\n def temp: String;\n def i: Int;\n for i = 0 , i < s.getLength() , i++ {\n if (s(i) != token) {\n temp.append(s(i));\n }\n else {\n result.add(temp);\n temp = \"\";\n }\n }\n result.add(temp);\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاستخدم مـتم؛\n\nدالة هل_أولي (عدد: صـحيح): ثـنائي {\n\tإذا عدد <= 1 {\n\t\tارجع خطأ؛\n\t}\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 2 ، دليل * دليل <= عدد ، دليل++ {\n\t\tإذا عدد % دليل == 0 {\n\t\t\tارجع خطأ؛\n\t\t}\n\t}\n\t\n\tارجع صح؛\n}\n"}, {"role": "assistant", "content": "تحقق فيما إذا كان عدد معطى أولي أم لا و ارجع تلك النتيجة"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Array\";\n\nuse Srl;\n\nfunc sum(a: ref[Array[Int]], start: Int, end: Int): Int {\n def sum: Int = 0;\n\n def i: Int;\n for i = start , i < end , i++ {\n sum += a(i);\n }\n\n return sum;\n}\n"}, {"role": "assistant", "content": "int sum(int a[], int n, int start, int end) {\n int result = 0;\n for (int i = start; i < end; i++) {\n result += a[i];\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\n#include <stdio.h>\n\nvoid printArray(int a[], int size) {\n int i;\n for(i = 0; i < size; i++) {\n printf(\"%d \", a[i]);\n }\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/طـرفية\"؛\n\nاستخدم مـتم؛\n\n\nدالة اطبع(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tطـرفية.اطبع(\"%d \"، م(دليل))؛\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\n#include <stdbool.h>\n\nbool is_digit(char c) {\n return (c >= '0' && c <= '9');\n}\n"}, {"role": "assistant", "content": "check if a given character is a digit"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc replace(s: ref[String], oldChar: Char, newChar: Char): String {\n def result: String;\n\n def i: Int;\n for i = 0 , i < s.getLength() , i++ {\n if (s(i) == oldChar) {\n result.append(newChar);\n }\n else {\n result.append(s(i));\n }\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "#include <stdlib.h>\n#include <string.h>\n\nchar* replace(char* str, char oldChar, char newChar) {\n int len = strlen(str);\n char* result = (char*)malloc(sizeof(char) * (len + 1));\n int i;\n\n for(i = 0; i < len; i++) {\n if(str[i] == oldChar) {\n result[i] = newChar;\n } else {\n result[i] = str[i];\n }\n }\n result[i] = '\\0';\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Array\";\n\nuse Srl;\n\n\nfunc invertArray(a: ref[Array[Int]]) {\n def start: Int = 0;\n def end: Int = a.getLength() - 1;\n\n while start < end {\n def temp: Int = a(start);\n a(start) = a(end);\n a(end) = temp;\n start++;\n end--;\n }\n}\n"}, {"role": "assistant", "content": "function reverseArray(a) {\n let start = 0;\n let end = a.length - 1;\n\n while (start < end) {\n let temp = a[start];\n a[start] = a[end];\n a[end] = temp;\n\n start++;\n end--;\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction replace(arr, oldValue, newValue) {\n for(var i = 0; i < arr.length; i++) {\n if(arr[i] == oldValue) {\n arr[i] = newValue;\n }\n }\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc replace(a: ref[Array[Int]], oldValue: Int, newValue: Int) {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if a(i) == oldValue {\n a(i) = newValue;\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, حول حالة محارف سلسلة نصية إلى أحرف صغيرة و أرجع النتيجة"}, {"role": "assistant", "content": "اشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة إلى_حالة_صغيرة(س: سند[نـص]): نـص {\n\tعرف نتيجة: نـص = \"\"؛\n\n\tعرف دليل: صـحيح؛\n\tعرف م: مـحرف؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) >= 'A' && س(دليل) <= 'Z' {\n\t\t\tم = س(دليل) - 'A' + 'a'؛\n\t\t}\n\t\tوإلا {\n\t\t\tم = س(دليل)؛\n\t\t}\n\t\tنتيجة += م؛\n\t}\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, calculate and return the standard deviation of the given array"}, {"role": "assistant", "content": "function std(data, n, mean) {\n let variance = 0.0;\n\n for(let i=0; i<n; ++i)\n variance += (data[i] - mean) * (data[i] - mean);\n\n return Math.sqrt(variance/n);\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, Insert an element at a given position in the given array"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc insert(a: ref[Array[Int]], pos: Int, val: Int) {\n def size: Int = a.getLength();\n\ta.add(0); // increase the size by 1\n\n def i: Int;\n for i = size , i > pos , i-- {\n a(i) = a(i - 1);\n }\n\n a(pos) = val;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\n#include <stdlib.h>\n\n// Function to multiply two matrices\nint** multiply(int** a, int** b, int r1, int c1, int r2, int c2) {\n int i, j, k;\n // Create a result matrix dynamically\n int** result = (int**)malloc(r1 * sizeof(int*));\n for(i = 0; i < r1; i++) {\n result[i] = (int*)malloc(c2 * sizeof(int));\n }\n\n // Initialize the result matrix with 0\n for(i = 0; i < r1; i++) {\n for(j = 0; j < c2; j++) {\n result[i][j] = 0;\n }\n }\n\n // Multiply the two matrices\n for(i = 0; i < r1; i++) {\n for(j = 0; j < c2; j++) {\n for(k = 0; k < c1; k++) {\n result[i][j] += a[i][k] * b[k][j];\n }\n }\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "Calculate the product of two given matrices represented by a 2D array and return the result"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc toUpperCase(s: ref[String]): String {\n\tdef result: String = \"\";\n def i: Int;\n\tdef c: Char;\n\tfor i = 0 , i < s.getLength() , i++ {\n\t\tif (s(i) >= 'a' && s(i) <= 'z') {\n\t\t\tc = s(i) - 'a' + 'A';\n\t\t}\n\t\telse {\n\t\t\tc = s(i);\n\t\t}\n\t\tresult += c;\n\t}\n\treturn result;\n}\n"}, {"role": "assistant", "content": "void toUpperCase(char *s, char *result) {\n for(int i = 0; s[i]; i++){\n if(s[i] >= 'a' && s[i] <= 'z'){\n result[i] = s[i] - 'a' + 'A';\n }\n else {\n result[i] = s[i];\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/طـرفية\"؛\n\nاستخدم مـتم؛\n\n\nدالة اطبع(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tطـرفية.اطبع(\"%d \"، م(دليل))؛\n\t}\n}\n"}, {"role": "assistant", "content": "#include <stdio.h>\n\nvoid printArray(int a[], int size) {\n int i;\n for(i = 0; i < size; i++) {\n printf(\"%d \", a[i]);\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc rotate(a: ref[Array[Int]]) {\n def size: Int = a.getLength();\n\n def first_element: Int = a(0);\n\n def i: Int;\n for i = 0 , i < size - 1 , i++ {\n a(i) = a(i + 1);\n }\n\n a(size - 1) = first_element;\n}\n"}, {"role": "assistant", "content": "function rotate(a) {\n const n = a.length;\n\n let first_element = a[0];\n\n for (let i = 0; i < n - 1; i++) {\n a[i] = a[i + 1];\n }\n\n a[n - 1] = first_element;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\n#include <stdio.h>\n#include <stdlib.h>\n\n// Function to read the n-th line of a file\nchar* read_nth_line(const char* file_path, int n) {\n FILE* file = fopen(file_path, \"r\");\n if(file == NULL) {\n printf(\"Could not open file %s\\n\", file_path);\n return NULL;\n }\n\n char* line = NULL;\n size_t len = 0;\n ssize_t read;\n\n int current_line = 0;\n while((read = getline(&line, &len, file)) != -1) {\n current_line++;\n if(current_line == n) {\n fclose(file);\n return line;\n }\n }\n\n // If we reach here, then the file has less than n lines\n fclose(file);\n free(line);\n return NULL;\n}\n"}, {"role": "assistant", "content": "Read the nth line of a text file given its path and return the result"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, convert string to uppercase and return the result"}, {"role": "assistant", "content": "import \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc toUpperCase(s: ref[String]): String {\n\tdef result: String = \"\";\n def i: Int;\n\tdef c: Char;\n\tfor i = 0 , i < s.getLength() , i++ {\n\t\tif (s(i) >= 'a' && s(i) <= 'z') {\n\t\t\tc = s(i) - 'a' + 'A';\n\t\t}\n\t\telse {\n\t\t\tc = s(i);\n\t\t}\n\t\tresult += c;\n\t}\n\treturn result;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nvoid erase(int a[], int n, int pos) {\n // Shift elements to left\n for (int i = pos; i < n - 1; i++)\n a[i] = a[i + 1];\n}\n"}, {"role": "assistant", "content": "Delete an element at a given position in the given array"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\nvoid toUpperCase(char *s, char *result) {\n for(int i = 0; s[i]; i++){\n if(s[i] >= 'a' && s[i] <= 'z'){\n result[i] = s[i] - 'a' + 'A';\n }\n else {\n result[i] = s[i];\n }\n }\n}\n"}, {"role": "assistant", "content": "import \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc toUpperCase(s: ref[String]): String {\n\tdef result: String = \"\";\n def i: Int;\n\tdef c: Char;\n\tfor i = 0 , i < s.getLength() , i++ {\n\t\tif (s(i) >= 'a' && s(i) <= 'z') {\n\t\t\tc = s(i) - 'a' + 'A';\n\t\t}\n\t\telse {\n\t\t\tc = s(i);\n\t\t}\n\t\tresult += c;\n\t}\n\treturn result;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Math\";\nimport \"Srl/Array\";\n\nuse Srl;\n\nclass Point {\n def x : Float;\n def y : Float;\n};\n\nfunc calculatePolygonArea(vertices: ref[Array[Point]]): Float {\n def area: Float = 0;\n def numVertices: Int = vertices.getLength();\n def j: Int = numVertices - 1;\n\n def i: Int;\n for i = 0 , i < numVertices , i++ {\n area += (vertices(j).x + vertices(i).x) * (vertices(j).y - vertices(i).y);\n j = i;\n }\n return Math.abs(area / 2.0);\n}\n"}, {"role": "assistant", "content": "calculate and return the area of polygon given its vertices"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction erase(a, n, pos) {\n // Shift elements to left\n for (let i = pos; i < n - 1; i++)\n a[i] = a[i + 1];\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة أزل(م: سند[مـصفوفة[صـحيح]]، موقع: صـحيح) {\n\tعرف حجم: صـحيح = م.هات_الطول()؛\n\n\tعرف دليل: صـحيح؛\n\tلكل دليل = موقع ، دليل < حجم - 1 ، دليل++ {\n\t\tم(دليل) = م(دليل + 1)؛\n\t}\n\tم.أزل(حجم - 1)؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction split(str, token) {\n let result = [];\n let temp = \"\";\n\n for(let i = 0; i < str.length; i++) {\n if(str[i] !== token) {\n temp += str[i];\n } else {\n result.push(temp);\n temp = \"\";\n }\n }\n\n // Push the last substring if it's not empty\n if(temp !== \"\") {\n result.push(temp);\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "Split a given string into a list of strings based on a given character"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Array\";\nimport \"closure\";\n\n\nuse Srl;\n\n\nfunc check_all(a: ref[Array[Int]], f: closure (num: Int): Bool): Bool {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if !f(a(i)) {\n return false;\n }\n }\n\n return true;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة تفحص_الكل(م: سند[مـصفوفة[صـحيح]]، د: مغلفة(رقم: صـحيح): ثـنائي): ثـنائي {\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا !د(م(دليل)) {\n\t\t\tارجع خطأ؛\n\t\t}\n\t}\n\t\n\tارجع صح؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Array\";\n\nuse Srl;\n\ndef Matrix: alias Array[Array[Float[64]]];\n\n\nfunc multiply(m: ref[Matrix], s: Float[64]): Matrix {\n def rows: Int = m.getLength();\n def cols: Int = m(0).getLength();\n \n def result: Matrix;\n\n def i: Int;\n def j: Int;\n for i = 0 , i < rows , i++ {\n result.add(Array[Float[64]]());\n for j = 0 , j < cols , j++ {\n result(i).add(m(i)(j)*s);\n }\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "#include <stdlib.h>\n\nint** multiply(int** a, int scalar, int rows, int cols) {\n int i, j;\n // Create a result matrix dynamically\n int** result = (int**)malloc(rows * sizeof(int*));\n for(i = 0; i < rows; i++) {\n result[i] = (int*)malloc(cols * sizeof(int));\n }\n\n // Multiply the matrix by the scalar\n for(i = 0; i < rows; i++) {\n for(j = 0; j < cols; j++) {\n result[i][j] = a[i][j] * scalar;\n }\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc toLowerCase(s: ref[String]): String {\n\tdef result: String = \"\";\n def i: Int;\n\tdef c: Char;\n\tfor i = 0 , i < s.getLength() , i++ {\n\t\tif (s(i) >= 'A' && s(i) <= 'Z') {\n\t\t\tc = s(i) - 'A' + 'a';\n\t\t}\n\t\telse {\n\t\t\tc = s(i);\n\t\t}\n\t\tresult += c;\n\t}\n\treturn result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة إلى_حالة_صغيرة(س: سند[نـص]): نـص {\n\tعرف نتيجة: نـص = \"\"؛\n\n\tعرف دليل: صـحيح؛\n\tعرف م: مـحرف؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) >= 'A' && س(دليل) <= 'Z' {\n\t\t\tم = س(دليل) - 'A' + 'a'؛\n\t\t}\n\t\tوإلا {\n\t\t\tم = س(دليل)؛\n\t\t}\n\t\tنتيجة += م؛\n\t}\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, calculate and return the sum of the given array in a given range"}, {"role": "assistant", "content": "function sum(a, start, end) {\n let result = 0;\n\n for (let i = start; i < end; i++) {\n result += a[i];\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, Slice a given string within a given range and return the result"}, {"role": "assistant", "content": "function slice_string(str, start, end) {\n var result = \"\";\n for(var i = start; i <= end; i++) {\n result += str[i];\n }\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\nint find_char(char s[], int n, char c) {\n for (int i = 0; i < n; i++) {\n if (s[i] == c) {\n return i;\n }\n }\n return -1;\n}\n"}, {"role": "assistant", "content": "import \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc find_char(s: ref[String], c: Char): Int {\n def i: Int;\n\tfor i = 0 , i < s.getLength() , i++ {\n\t\tif (s(i) == c) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, convert string to uppercase and return the result"}, {"role": "assistant", "content": "function toUpperCase(s) {\n let result = '';\n for(let i = 0; i < s.length; i++){\n let code = s.charCodeAt(i);\n if(code >= 97 && code <= 122){\n result += String.fromCharCode(code - 97 + 65);\n } else {\n result += s[i];\n }\n }\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc is_permutation(a1: ref[Array[Int]], a2: ref[Array[Int]]): Bool {\n if a1.getLength() != a2.getLength() {\n return false;\n }\n\n def visited: Array[Bool];\n def i: Int;\n for i = 0 , i < a2.getLength() , i++ {\n visited.add(false);\n }\n\n def j: Int;\n for i = 0 , i < a1.getLength() , i++ {\n def found: Bool = false;\n for j = 0 , j < a2.getLength() , j++ {\n if a1(i) == a2(j) && !visited(j) {\n found = true;\n visited(j) = true;\n break;\n }\n }\n if !found {\n return false;\n }\n }\n\n return true;\n}\n"}, {"role": "assistant", "content": "#include <stdbool.h>\n\n// Function to check if arr2 is a permutation of arr1\nbool is_permutation(int arr1[], int size1, int arr2[], int size2) {\n // If sizes are not equal, return false\n if(size1 != size2) {\n return false;\n }\n\n // Create an array to keep track of visited elements\n bool visited[size2];\n for(int i = 0; i < size2; i++) {\n visited[i] = false;\n }\n\n // For each element in arr1\n for(int i = 0; i < size1; i++) {\n bool found = false;\n\n // For each element in arr2\n for(int j = 0; j < size2; j++) {\n // If the element in arr1 is found in arr2 and it has not been visited\n if(arr1[i] == arr2[j] && !visited[j]) {\n found = true;\n visited[j] = true; // Mark the element in arr2 as visited\n break;\n }\n }\n\n // If the element in arr1 is not found in arr2, return false\n if(!found) {\n return false;\n }\n }\n\n // If we reach here, then arr2 is a permutation of arr1\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Array\";\n\nuse Srl;\n\nfunc findIntersection(a1: Float[64], b1: Float[64], c1: Float[64], a2: Float[64], b2: Float[64], c2: Float[64]): Array[Float[64]] {\n def result: Array[Float[64]];\n if a1*b2 - a2*b1 == 0 {\n return result;\n }\n\n result.add((b1*c2 - b2*c1) / (a1*b2 - a2*b1));\n result.add((a2*c1 - a1*c2) / (a1*b2 - a2*b1));\n\n return result;\n}\n"}, {"role": "assistant", "content": "Find the intersection point of two given lines (the line represented by three values `a`, `b`, `c` as ax + by + c = 0) and return it, in case of parallel line return null or empty array"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة اقتطع(م: سند[مـصفوفة[صـحيح]]، أدنى: صـحيح، أعلى: صـحيح) {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا م(دليل) < أدنى {\n\t\t\tم(دليل) = أدنى؛\n\t\t}\n\t\tوإلا إذا م(دليل) > أعلى {\n\t\t\tم(دليل) = أعلى؛\n\t\t}\n\t}\n}\n"}, {"role": "assistant", "content": "اقتطع قيم مصفوفة معطاة ضمن مجال معطى"}]}
{"messages": [{"role": "user", "content": "What this code do?\nint find_diff_index(int arr1[], int arr2[], int n) {\n int i;\n for(i = 0; i < n; i++) {\n if(arr1[i] != arr2[i]) {\n return i;\n }\n }\n return -1; // return -1 if no difference is found\n}\n"}, {"role": "assistant", "content": "Find the first index at which the two given arrays differ, return -1 if not found"}]}
{"messages": [{"role": "user", "content": "What this code do?\nvoid toLowerCase(char *s, char *result) {\n for(int i = 0; s[i]; i++){\n if(s[i] >= 'A' && s[i] <= 'Z'){\n result[i] = s[i] - 'A' + 'a';\n }\n else {\n result[i] = s[i];\n }\n }\n}\n"}, {"role": "assistant", "content": "convert string to lowercase and return the result"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاستخدم مـتم؛\n\n\nصنف نـقطة {\n\tعرف س: صـحيح؛\n\tعرف ص: صـحيح؛\n}\n\nدالة على_خط_مستقيم(ن1: نـقطة، ن2: نـقطة، ن3: نـقطة): ثـنائي {\n\tارجع (ن2.ص - ن1.ص) * (ن3.س - ن1.ص) == (ن3.ص - ن1.ص) * (ن2.س - ن1.س)؛\n}\n"}, {"role": "assistant", "content": "use Srl;\n\nclass Point {\n def x : Int;\n def y : Int;\n};\n\nfunc areCollinear(p1: Point, p2: Point, p3: Point): Bool {\n return (p2.y - p1.y) * (p3.x - p1.x) == (p3.y - p1.y) * (p2.x - p1.x);\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, find and return the position of a given char in a given string"}, {"role": "assistant", "content": "function find_char(s, c) {\n for (let i = 0; i < s.length; i++) {\n if (s[i] === c) {\n return i;\n }\n }\n return -1;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\ndouble dot_product(double v1[], double v2[], int n) {\n double result = 0;\n for (int i = 0; i < n; i++) {\n result += v1[i] * v2[i];\n }\n return result;\n}\n"}, {"role": "assistant", "content": "Calculate the dot product of two given vectors each represented by an array and return the result"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/ريـاضيات\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nصنف نـقطة {\n\tعرف س: عـائم؛\n\tعرف ص: عـائم؛\n}\n\nدالة احسب_مسافة(ن1: نـقطة، ن2: نـقطة): عـائم {\n\tارجع ريـاضيات.جذر(ريـاضيات.ارفع(ن2.س - ن1.س، 2.0) + ريـاضيات.ارفع(ن2.ص - ن1.ص، 2.0))؛\n}\n\nدالة جد_أقرب_نقطة(ن: نـقطة، نقاط: سند[مـصفوفة[نـقطة]]): نـقطة {\n\tعرف أقرب_مسافة: عـائم = احسب_مسافة(ن، نقاط(0))؛\n\tعرف أقرب_نقطة: نـقطة = نقاط(0)؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 1 ، دليل < نقاط.هات_الطول() ، دليل++ {\n\t\tعرف مسافة: عـائم = احسب_مسافة(ن، نقاط(دليل))؛\n\t\tإذا مسافة < أقرب_مسافة {\n\t\t\tأقرب_مسافة = مسافة؛\n\t\t\tأقرب_نقطة = نقاط(دليل)؛\n\t\t}\n\t}\n\tارجع أقرب_نقطة؛\n}\n"}, {"role": "assistant", "content": "#include <math.h>\n\ntypedef struct {\n double x;\n double y;\n} Point;\n\ndouble calculateDistance(Point a, Point b) {\n return sqrt(pow(b.x - a.x, 2) + pow(b.y - a.y, 2));\n}\n\nPoint findClosestPoint(Point givenPoint, Point points[], int size) {\n double minDistance = calculateDistance(givenPoint, points[0]);\n Point closestPoint = points[0];\n\n for(int i = 1; i < size; i++) {\n double distance = calculateDistance(givenPoint, points[i]);\n if(distance < minDistance) {\n minDistance = distance;\n closestPoint = points[i];\n }\n }\n\n return closestPoint;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/String\";\nimport \"Srl/Array\"\n\nuse Srl;\n\n\nfunc split(s: ref[String], token: Char): Array[String] {\n def result: Array[String];\n\n def temp: String;\n def i: Int;\n for i = 0 , i < s.getLength() , i++ {\n if (s(i) != token) {\n temp.append(s(i));\n }\n else {\n result.add(temp);\n temp = \"\";\n }\n }\n result.add(temp);\n return result;\n}\n"}, {"role": "assistant", "content": "function split(str, token) {\n let result = [];\n let temp = \"\";\n\n for(let i = 0; i < str.length; i++) {\n if(str[i] !== token) {\n temp += str[i];\n } else {\n result.push(temp);\n temp = \"\";\n }\n }\n\n // Push the last substring if it's not empty\n if(temp !== \"\") {\n result.push(temp);\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction sum(a) {\n let result = 0;\n\n for (let i = 0; i < a.length; i++) {\n result += a[i];\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "Find and return the sum of the given array `a`"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة ادمج(م: سند[مـصفوفة[صـحيح]]، يسار: صـحيح، وسط: صـحيح، يمين: صـحيح) {\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tعرف دليل3: صـحيح؛\n\t\n\tعرف حجم1: صـحيح = وسط - يسار + 1؛\n\tعرف حجم2: صـحيح = يمين - وسط؛\n\t\n\tعرف م_يسار: مـصفوفة[صـحيح]؛\n\tعرف م_يمين: مـصفوفة[صـحيح]؛\n\t\n\tلكل دليل1 = 0 ، دليل1 < حجم1 ، دليل1++ {\n\t\tم_يسار.أضف(م(يسار+دليل1))؛\n\t}\n\tلكل دليل1 = 0 ، دليل1 < حجم2 ، دليل1++ {\n\t\tم_يمين.أضف(م(وسط + 1 + دليل1))؛\n\t}\n\t\n\tدليل1 = 0؛\n\tدليل2 = 0؛\n\tدليل3 = يسار؛\n\t\n\tبينما دليل1 < حجم1 && دليل2 < حجم2 {\n\t\tإذا م_يسار(دليل1) <= م_يمين(دليل2) {\n\t\t\tم(دليل3) = م_يسار(دليل1)؛\n\t\t\tدليل1++؛\n\t\t}\n\t\tوإلا {\n\t\t\tم(دليل3) = م_يمين(دليل2)؛\n\t\t\tدليل2++؛\n\t\t}\n\t\tدليل3++؛\n\t}\n\t\n\tبينما دليل1 < حجم1 {\n\t\tم(دليل3) = م_يسار(دليل1)؛\n\t\tدليل1++؛\n\t\tدليل3++؛\n\t}\n\t\n\tبينما دليل2 < حجم2 {\n\t\tم(دليل3) = م_يمين(دليل2)؛\n\t\tدليل2++؛\n\t\tدليل3++؛\n\t}\n}\n\n\nدالة ترتيب_بالدمج(م: سند[مـصفوفة[صـحيح]]، يسار: صـحيح، يمين: صـحيح) {\n\tإذا يسار < يمين {\n\t\tعرف وسط: صـحيح = يسار + (يمين - يسار) / 2؛\n\t\t\n\t\tترتيب_بالدمج(م، يسار، وسط)؛\n\t\tترتيب_بالدمج(م، وسط + 1، يمين)؛\n\t\t\n\t\tادمج(م، يسار، وسط، يمين)؛\n\t}\n}\n"}, {"role": "assistant", "content": "function mergeSort(arr) {\n if (arr.length < 2)\n return arr;\n\n let mid = Math.floor(arr.length / 2);\n let left = arr.slice(0, mid);\n let right = arr.slice(mid);\n\n return merge(mergeSort(left), mergeSort(right));\n}\n\nfunction merge(left, right) {\n let result = [];\n let i = 0;\n let j = 0;\n\n while (i < left.length && j < right.length) {\n if (left[i] < right[j]) {\n result.push(left[i]);\n i++;\n } else {\n result.push(right[j]);\n j++;\n }\n }\n\n return result.concat(left.slice(i)).concat(right.slice(j));\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة المحرف_متواجد(س: سند[نـص]، م: مـحرف): ثـنائي {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) == م {\n\t\t\tارجع صح؛\n\t\t}\n\t}\n\tارجع خطأ؛\n}\n"}, {"role": "assistant", "content": "function char_exists(s, c) {\n for (let i = 0; i < s.length; i++) {\n if (s[i] === c) {\n return true;\n }\n }\n return false;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة أزل(م: سند[مـصفوفة[صـحيح]]، موقع: صـحيح) {\n\tعرف حجم: صـحيح = م.هات_الطول()؛\n\n\tعرف دليل: صـحيح؛\n\tلكل دليل = موقع ، دليل < حجم - 1 ، دليل++ {\n\t\tم(دليل) = م(دليل + 1)؛\n\t}\n\tم.أزل(حجم - 1)؛\n}\n"}, {"role": "assistant", "content": "احذف عنصرا من موقع معطى ضمن المصفوفة المعطى"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc erase(a: ref[Array[Int]], pos: Int) {\n def size: Int = a.getLength();\n\n def i: Int;\n for i = pos , i < size - 1 , i++ {\n a(i) = a(i + 1);\n }\n a.remove(size - 1);\n}\n"}, {"role": "assistant", "content": "Delete an element at a given position in the given array"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Array\";\n\nuse Srl;\n\nfunc sum(a: ref[Array[Int]]): Int {\n def sum: Int = 0;\n\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n sum += a(i);\n }\n\n return sum;\n}\n"}, {"role": "assistant", "content": "function sum(a) {\n let result = 0;\n\n for (let i = 0; i < a.length; i++) {\n result += a[i];\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, احسب الجداء الخارجي لشعاعين معطيين كل منهما ممثل على شكل مصفوفة و ارجع النتيجة"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جداء_خارجي(شعاع1: سند[مـصفوفة[عـائم[64]]]، شعاع2: سند[مـصفوفة[عـائم[64]]]): مـصفوفة[مـصفوفة[عـائم[64]]] {\n\tعرف نتيجة: مـصفوفة[مـصفوفة[عـائم[64]]]؛\n\t\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < شعاع1.هات_الطول() ، دليل1++ {\n\t\tعرف سطر: مـصفوفة[عـائم[64]]؛\n\t\tلكل دليل2 = 0 ، دليل2 < شعاع2.هات_الطول() ، دليل2++ {\n\t\t\tسطر.أضف(شعاع1(دليل1)*شعاع2(دليل2))؛\n\t\t}\n\t\tنتيجة.أضف(سطر)؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction sum(a, start, end) {\n let result = 0;\n\n for (let i = start; i < end; i++) {\n result += a[i];\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "calculate and return the sum of the given array in a given range"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جد_التقاطع(أ1: عـائم[64]، ب1: عـائم[64]، ج1: عـائم[64]، أ2: عـائم[64]، ب2: عـائم[64]، ج2: عـائم[64]): مـصفوفة[عـائم[64]] {\n\tعرف نتيجة: مـصفوفة[عـائم[64]]؛\n\tإذا أ1 * ب2 - أ2 * ب1 == 0 {\n\t\tارجع نتيجة؛\n\t}\n\t\n\tنتيجة.أضف((ب1*ج2 - ب2*ج1) / (أ1 * ب2 - أ2 * ب1))؛\n\tنتيجة.أضف((أ2*ج1 - أ1*ج2) / (أ1 * ب2 - أ2 * ب1))؛\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "#include <stdlib.h>\n\n// Function to find the intersection point of two lines\ndouble* findIntersection(double a1, double b1, double c1, double a2, double b2, double c2) {\n // Check if the lines are parallel\n if(a1*b2 - a2*b1 == 0) {\n return NULL;\n }\n\n double* result = (double*)malloc(2 * sizeof(double));\n result[0] = (b1*c2 - b2*c1) / (a1*b2 - a2*b1);\n result[1] = (a2*c1 - a1*c2) / (a1*b2 - a2*b1);\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nدالة دفس(عقدة: صـحيح، مزارة: سند[مـصفوفة[ثـنائي]]، بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]) {\n\tمزارة(عقدة) = صح؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان(عقدة).هات_الطول() ، دليل++ {\n\t\tعرف عقدة_ابن: صـحيح = بيان(عقدة)(دليل)؛\n\t\tإذا !مزارة(عقدة_ابن) {\n\t\t\tدفس(عقدة_ابن، مزارة، بيان)؛\n\t\t}\n\t}\n}\n\n\nدالة عدد_المكونات_المترابطة(بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]): صـحيح {\n\tعرف مزارة: مـصفوفة[ثـنائي]؛\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان.هات_الطول() ، دليل++ {\n\t\tمزارة.أضف(خطأ)؛\n\t}\n\t\n\tعرف عدد_المكونات: صـحيح = 0؛\n\tلكل دليل = 0 ، دليل < بيان.هات_الطول() ، دليل++ {\n\t\tإذا !مزارة(دليل) {\n\t\t\tدفس(دليل، مزارة، بيان)؛\n\t\t\tعدد_المكونات++؛\n\t\t}\n\t}\n\t\n\tارجع عدد_المكونات؛\n}\n"}, {"role": "assistant", "content": "let visited = [];\n\nfunction DFS(v, adjList) {\n visited[v] = true;\n for(let i = 0; i < adjList[v].length; i++) {\n if(!visited[adjList[v][i]]) {\n DFS(adjList[v][i], adjList);\n }\n }\n}\n\nfunction numberOfConnectedComponents(adjList) {\n let components = 0;\n for(let i = 0; i < adjList.length; i++) {\n if(!visited[i]) {\n DFS(i, adjList);\n components++;\n }\n }\n return components;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاستخدم مـتم؛\n\n\nدالة ينتمي_للأبجدية(م: مـحرف): ثـنائي {\n\tارجع ( م <= 'Z' && م >= 'A') || ( م <= 'z' && م >= 'a')؛\n}\n"}, {"role": "assistant", "content": "use Srl;\n\n\nfunc is_alpha(c: Char): Bool {\n return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, write the counting sort algorithm for a given array"}, {"role": "assistant", "content": "const MAX_VALUE = 100000;\n\nfunction countingSort(arr) {\n let i, j;\n let count = new Array(MAX_VALUE + 1).fill(0);\n let output = [];\n\n // Count the occurrence of each number\n for(i = 0; i < arr.length; i++) {\n count[arr[i]]++;\n }\n\n // Reconstruct the sorted array\n for(i = 0; i <= MAX_VALUE; i++) {\n for(j = 0; j < count[i]; j++) {\n output.push(i);\n }\n }\n\n return output;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, Write DFS algorithm for the given graph"}, {"role": "assistant", "content": "void dfs(int node, int visited[], int G[][N]) {\n visited[node] = 1;\n printf(\"%d \", node);\n\n for(int i = 0; i < N; i++) {\n if(G[node][i] == 1 && visited[i] == 0) {\n dfs(i, visited, G);\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nconst V = 4;\n\nfunction floydWarshall(graph) {\n let dist = [];\n for (let i = 0; i < V; i++) {\n dist[i] = [];\n for (let j = 0; j < V; j++) {\n dist[i][j] = graph[i][j];\n }\n }\n\n for (let k = 0; k < V; k++) {\n for (let i = 0; i < V; i++) {\n for (let j = 0; j < V; j++) {\n if (dist[i][k] + dist[k][j] < dist[i][j]) {\n dist[i][j] = dist[i][k] + dist[k][j];\n }\n }\n }\n }\n\n return dist;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\nfunc floydWarshall(graph: ref[Array[Array[Int]]], dist: ref[Array[Array[Int]]]) {\n def n: Int = graph.getLength();\n def i: Int;\n def j: Int;\n def k: Int;\n\n for i = 0 , i < n , i++ {\n dist.add(graph(i));\n }\n\n for k = 0 , k < n , k++ {\n for i = 0 , i < n , i++ {\n for j = 0 , j < n , j++ {\n if dist(i)(k) + dist(k)(j) < dist(i)(j) {\n dist(i)(j) = dist(i)(k) + dist(k)(j);\n }\n }\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc initializeArray(a: ref[Array[Int]], size: Int, val: Int) {\n def i: Int;\n for i = 0, i < size, i++ {\n a.add(val);\n }\n}\n"}, {"role": "assistant", "content": "function initializeArray(arr, value) {\n for(let i = 0; i < arr.length; i++) {\n arr[i] = value;\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة يبدأ_ب(س: سند[نـص]، سابق: سند[نـص]): ثـنائي {\n\tإذا س.هات_الطول() < سابق.هات_الطول() {\n\t\tارجع خطأ؛\n\t}\n\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < سابق.هات_الطول() ، دليل++ {\n\t\tإذا سابق(دليل) != س(دليل) {\n\t\t\tارجع خطأ؛\n\t\t}\n\t}\n\tارجع صح؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc starts_with(s: ref[String], prefix: ref[String]): Bool {\n\tif s.getLength() < prefix.getLength() {\n\t\treturn false;\n\t}\n\n def i: Int;\n\tfor i = 0 , i < prefix.getLength() , i++ {\n\t\tif (prefix(i) != s(i)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة احشر(م: سند[مـصفوفة[صـحيح]]، موقع: صـحيح، قيمة: صـحيح) {\n\tعرف حجم: صـحيح = م.هات_الطول()؛\n\tم.أضف(0)؛ // لزيادة الحجم بمقدار 1\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = حجم ، دليل > موقع ، دليل-- {\n\t\tم(دليل) = م(دليل - 1)؛\n\t}\n\t\n\tم(موقع) = قيمة؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc insert(a: ref[Array[Int]], pos: Int, val: Int) {\n def size: Int = a.getLength();\n\ta.add(0); // increase the size by 1\n\n def i: Int;\n for i = size , i > pos , i-- {\n a(i) = a(i - 1);\n }\n\n a(pos) = val;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction invert_string(str) {\n return str.split('').reverse().join('');\n}\n"}, {"role": "assistant", "content": "import \"Srl/String\";\n\nuse Srl;\n\n\nfunction invertString(s) {\n def size: Int = s.getLength();\n def result: String = \"\";\n\n def i: Int;\n for i = size - 1 , i >= 0 , i-- {\n result += s(i);\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc clip(a: ref[Array[Int]], lower: Int, upper: Int) {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if a(i) < lower {\n a(i) = lower;\n }\n else if a(i) > upper {\n a(i) = upper;\n }\n }\n}\n"}, {"role": "assistant", "content": "function clip(arr, lower, upper) {\n for(let i = 0; i < arr.length; i++) {\n if(arr[i] < lower) {\n arr[i] = lower;\n } else if(arr[i] > upper) {\n arr[i] = upper;\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\n#include <stdlib.h>\n#include <string.h>\n\nchar* replace(char* str, char oldChar, char newChar) {\n int len = strlen(str);\n char* result = (char*)malloc(sizeof(char) * (len + 1));\n int i;\n\n for(i = 0; i < len; i++) {\n if(str[i] == oldChar) {\n result[i] = newChar;\n } else {\n result[i] = str[i];\n }\n }\n result[i] = '\\0';\n\n return result;\n}\n"}, {"role": "assistant", "content": "Replace a given char with another given char in a given string and return the new string"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة ادمج(م: سند[مـصفوفة[صـحيح]]، يسار: صـحيح، وسط: صـحيح، يمين: صـحيح) {\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tعرف دليل3: صـحيح؛\n\t\n\tعرف حجم1: صـحيح = وسط - يسار + 1؛\n\tعرف حجم2: صـحيح = يمين - وسط؛\n\t\n\tعرف م_يسار: مـصفوفة[صـحيح]؛\n\tعرف م_يمين: مـصفوفة[صـحيح]؛\n\t\n\tلكل دليل1 = 0 ، دليل1 < حجم1 ، دليل1++ {\n\t\tم_يسار.أضف(م(يسار+دليل1))؛\n\t}\n\tلكل دليل1 = 0 ، دليل1 < حجم2 ، دليل1++ {\n\t\tم_يمين.أضف(م(وسط + 1 + دليل1))؛\n\t}\n\t\n\tدليل1 = 0؛\n\tدليل2 = 0؛\n\tدليل3 = يسار؛\n\t\n\tبينما دليل1 < حجم1 && دليل2 < حجم2 {\n\t\tإذا م_يسار(دليل1) <= م_يمين(دليل2) {\n\t\t\tم(دليل3) = م_يسار(دليل1)؛\n\t\t\tدليل1++؛\n\t\t}\n\t\tوإلا {\n\t\t\tم(دليل3) = م_يمين(دليل2)؛\n\t\t\tدليل2++؛\n\t\t}\n\t\tدليل3++؛\n\t}\n\t\n\tبينما دليل1 < حجم1 {\n\t\tم(دليل3) = م_يسار(دليل1)؛\n\t\tدليل1++؛\n\t\tدليل3++؛\n\t}\n\t\n\tبينما دليل2 < حجم2 {\n\t\tم(دليل3) = م_يمين(دليل2)؛\n\t\tدليل2++؛\n\t\tدليل3++؛\n\t}\n}\n\n\nدالة ترتيب_بالدمج(م: سند[مـصفوفة[صـحيح]]، يسار: صـحيح، يمين: صـحيح) {\n\tإذا يسار < يمين {\n\t\tعرف وسط: صـحيح = يسار + (يمين - يسار) / 2؛\n\t\t\n\t\tترتيب_بالدمج(م، يسار، وسط)؛\n\t\tترتيب_بالدمج(م، وسط + 1، يمين)؛\n\t\t\n\t\tادمج(م، يسار، وسط، يمين)؛\n\t}\n}\n"}, {"role": "assistant", "content": "#include <stdlib.h>\n\nvoid merge(int arr[], int l, int m, int r) {\n int i, j, k;\n int n1 = m - l + 1;\n int n2 = r - m;\n\n int L[n1], R[n2];\n\n for (i = 0; i < n1; i++)\n L[i] = arr[l + i];\n for (j = 0; j < n2; j++)\n R[j] = arr[m + 1 + j];\n\n i = 0;\n j = 0;\n k = l;\n while (i < n1 && j < n2) {\n if (L[i] <= R[j]) {\n arr[k] = L[i];\n i++;\n } else {\n arr[k] = R[j];\n j++;\n }\n k++;\n }\n\n while (i < n1) {\n arr[k] = L[i];\n i++;\n k++;\n }\n\n while (j < n2) {\n arr[k] = R[j];\n j++;\n k++;\n }\n}\n\nvoid mergeSort(int arr[], int l, int r) {\n if (l < r) {\n int m = l + (r - l) / 2;\n\n mergeSort(arr, l, m);\n mergeSort(arr, m + 1, r);\n\n merge(arr, l, m, r);\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\n#include <stdbool.h>\n\n// Criteria function that checks if a number is positive\nbool criteria(int num) {\n return num > 0;\n}\n\n// Function to check all elements in an array\nbool check_all(int arr[], int size) {\n for(int i = 0; i < size; i++) {\n if(!criteria(arr[i])) {\n return false;\n }\n }\n return true;\n}\n"}, {"role": "assistant", "content": "Check if all elements in a given array satisfy a criteria defined by a function with boolean return value"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, calculate and return the mean of the given array"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"Srl/Math\";\n\n\nuse Srl;\n\n\nfunc mean(a: ref[Array[Int]]): Float {\n def size: Int = a.getLength();\n def sum: Int = 0;\n\n def i: Int;\n for i = 0 , i < size , i++ {\n sum += a(i);\n }\n\n return sum~cast[Float] / size;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\nint sum(int a[], int n, int start, int end) {\n int result = 0;\n for (int i = start; i < end; i++) {\n result += a[i];\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\nfunc sum(a: ref[Array[Int]], start: Int, end: Int): Int {\n def sum: Int = 0;\n\n def i: Int;\n for i = start , i < end , i++ {\n sum += a(i);\n }\n\n return sum;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nuse Srl;\n\nclass Point {\n def x : Int;\n def y : Int;\n};\n\nfunc areCollinear(p1: Point, p2: Point, p3: Point): Bool {\n return (p2.y - p1.y) * (p3.x - p1.x) == (p3.y - p1.y) * (p2.x - p1.x);\n}\n"}, {"role": "assistant", "content": "#include <stdbool.h>\n\ntypedef struct {\n int x;\n int y;\n} Point;\n\nbool areCollinear(Point p1, Point p2, Point p3) {\n // Calculate the slopes of the lines formed by (p1, p2) and (p1, p3)\n // If the slopes are equal, then p1, p2 and p3 are collinear\n return (p2.y - p1.y) * (p3.x - p1.x) == (p3.y - p1.y) * (p2.x - p1.x);\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, اكتب خوارزمية Floyd Warshall لبيان معطى"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة فلويد_وارشال(بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]، مسافة: سند[مـصفوفة[مـصفوفة[صـحيح]]]) {\n\tعرف حجم: صـحيح = بيان.هات_الطول()؛\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tعرف دليل3: صـحيح؛\n\n\t\n\tلكل دليل1 = 0 ، دليل1 < حجم ، دليل1++ {\n\t\tمسافة.أضف(بيان(دليل1))؛\n\t}\n\t\n\tلكل دليل3 = 0 ، دليل3 < حجم ، دليل3++ {\n\t\tلكل دليل1 = 0 ، دليل1 < حجم ، دليل1++ {\n\t\t\tلكل دليل2 = 0 ، دليل2 < حجم ، دليل2++ {\n\t\t\t\tإذا مسافة(دليل1)(دليل3) + مسافة(دليل3)(دليل2) < مسافة(دليل1)(دليل2) {\n\t\t\t\t\tمسافة(دليل1)(دليل2) = مسافة(دليل1)(دليل3) + مسافة(دليل3)(دليل2)؛\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة تفحص_أي(م: سند[مـصفوفة[صـحيح]]، د: مغلفة(رقم: صـحيح): ثـنائي): ثـنائي {\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا د(م(دليل)) {\n\t\t\tارجع صح؛\n\t\t}\n\t}\n\n\tارجع خطأ؛\n}\n"}, {"role": "assistant", "content": "#include <stdbool.h>\n\n// Criteria function that checks if a number is positive\nbool criteria(int num) {\n return num > 0;\n}\n\n// Function to check all elements in an array\nbool check_any(int arr[], int size) {\n for(int i = 0; i < size; i++) {\n if(criteria(arr[i])) {\n return true;\n }\n }\n return false;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة جد_المحرف(س: سند[نـص]، م: مـحرف): صـحيح {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) == م {\n\t\t\tارجع دليل؛\n\t\t}\n\t}\n\tارجع -1؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc find_char(s: ref[String], c: Char): Int {\n def i: Int;\n\tfor i = 0 , i < s.getLength() , i++ {\n\t\tif (s(i) == c) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة تفحص_أي(م: سند[مـصفوفة[صـحيح]]، د: مغلفة(رقم: صـحيح): ثـنائي): ثـنائي {\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا د(م(دليل)) {\n\t\t\tارجع صح؛\n\t\t}\n\t}\n\n\tارجع خطأ؛\n}\n"}, {"role": "assistant", "content": "تفحص فيما إذا كان أي عنصر في مصفوفة معطاة يحقق معيارًا معرفًا بدالة تعيد قيمة ثـنائية"}]}
{"messages": [{"role": "user", "content": "What this code do?\n#include <string.h>\n\nvoid trim(char *str) {\n int start = 0, end = strlen(str) - 1;\n\n // Trim leading white spaces\n while(str[start] == ' ' || str[start] == '\\t' || str[start] == '\\n') start++;\n\n // Trim trailing white spaces\n while(str[end] == ' ' || str[end] == '\\t' || str[end] == '\\n') end--;\n\n // Shift characters\n memmove(str, str + start, end - start + 1);\n\n // Null terminate the string\n str[end - start + 1] = '\\0';\n}\n"}, {"role": "assistant", "content": "Remove any whitespace character from both ends of a given string"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة ادمج(م: سند[مـصفوفة[صـحيح]]، يسار: صـحيح، وسط: صـحيح، يمين: صـحيح) {\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tعرف دليل3: صـحيح؛\n\t\n\tعرف حجم1: صـحيح = وسط - يسار + 1؛\n\tعرف حجم2: صـحيح = يمين - وسط؛\n\t\n\tعرف م_يسار: مـصفوفة[صـحيح]؛\n\tعرف م_يمين: مـصفوفة[صـحيح]؛\n\t\n\tلكل دليل1 = 0 ، دليل1 < حجم1 ، دليل1++ {\n\t\tم_يسار.أضف(م(يسار+دليل1))؛\n\t}\n\tلكل دليل1 = 0 ، دليل1 < حجم2 ، دليل1++ {\n\t\tم_يمين.أضف(م(وسط + 1 + دليل1))؛\n\t}\n\t\n\tدليل1 = 0؛\n\tدليل2 = 0؛\n\tدليل3 = يسار؛\n\t\n\tبينما دليل1 < حجم1 && دليل2 < حجم2 {\n\t\tإذا م_يسار(دليل1) <= م_يمين(دليل2) {\n\t\t\tم(دليل3) = م_يسار(دليل1)؛\n\t\t\tدليل1++؛\n\t\t}\n\t\tوإلا {\n\t\t\tم(دليل3) = م_يمين(دليل2)؛\n\t\t\tدليل2++؛\n\t\t}\n\t\tدليل3++؛\n\t}\n\t\n\tبينما دليل1 < حجم1 {\n\t\tم(دليل3) = م_يسار(دليل1)؛\n\t\tدليل1++؛\n\t\tدليل3++؛\n\t}\n\t\n\tبينما دليل2 < حجم2 {\n\t\tم(دليل3) = م_يمين(دليل2)؛\n\t\tدليل2++؛\n\t\tدليل3++؛\n\t}\n}\n\n\nدالة ترتيب_بالدمج(م: سند[مـصفوفة[صـحيح]]، يسار: صـحيح، يمين: صـحيح) {\n\tإذا يسار < يمين {\n\t\tعرف وسط: صـحيح = يسار + (يمين - يسار) / 2؛\n\t\t\n\t\tترتيب_بالدمج(م، يسار، وسط)؛\n\t\tترتيب_بالدمج(م، وسط + 1، يمين)؛\n\t\t\n\t\tادمج(م، يسار، وسط، يمين)؛\n\t}\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\n\nfunc merge(a: ref[Array[Int]], l: Int, m: Int, r: Int) {\n def i: Int;\n def j: Int;\n def k: Int;\n\n def n1: Int = m - l + 1;\n def n2: Int = r - m;\n\n def L: Array[Int];\n def R: Array[Int];\n\n for i = 0 , i < n1 , i++ {\n L.add(a(l+i));\n }\n for i = 0 , i < n2 , i++ {\n R.add(a(m + 1 + i));\n }\n\n i = 0;\n j = 0;\n k = l;\n while i < n1 && j < n2 {\n if L(i) <= R(j) {\n a(k) = L(i);\n i++;\n }\n else {\n a(k) = R(j);\n j++;\n }\n k++;\n }\n\n while i < n1 {\n a(k) = L(i);\n i++;\n k++;\n }\n\n while j < n2 {\n a(k) = R(j);\n j++;\n k++;\n }\n}\n\nfunc mergeSort(a: ref[Array[Int]], l: Int, r: Int) {\n if l < r {\n def m: Int = l + (r - l) / 2;\n\n mergeSort(a, l, m);\n mergeSort(a, m + 1, r);\n\n merge(a, l, m, r);\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc toUpperCase(s: ref[String]): String {\n\tdef result: String = \"\";\n def i: Int;\n\tdef c: Char;\n\tfor i = 0 , i < s.getLength() , i++ {\n\t\tif (s(i) >= 'a' && s(i) <= 'z') {\n\t\t\tc = s(i) - 'a' + 'A';\n\t\t}\n\t\telse {\n\t\t\tc = s(i);\n\t\t}\n\t\tresult += c;\n\t}\n\treturn result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة إلى_حالة_كبيرة(س: سند[نـص]): نـص {\n\tعرف نتيجة: نـص = \"\"؛\n\n\tعرف دليل: صـحيح؛\n\tعرف م: مـحرف؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) >= 'a' && س(دليل) <= 'z' {\n\t\t\tم = س(دليل) - 'a' + 'A'؛\n\t\t}\n\t\tوإلا {\n\t\t\tم = س(دليل)؛\n\t\t}\n\t\tنتيجة += م؛\n\t}\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, calculate and return the standard deviation of the given array"}, {"role": "assistant", "content": "#include <math.h>\n\ndouble std(int data[], int n, float mean)\n{\n double variance = 0.0;\n\n for(int i=0; i<n; ++i)\n variance += (data[i] - mean) * (data[i] - mean);\n\n return sqrt(variance/n);\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc insert(a: ref[Array[Int]], pos: Int, val: Int) {\n def size: Int = a.getLength();\n\ta.add(0); // increase the size by 1\n\n def i: Int;\n for i = size , i > pos , i-- {\n a(i) = a(i - 1);\n }\n\n a(pos) = val;\n}\n"}, {"role": "assistant", "content": "Insert an element at a given position in the given array"}]}
{"messages": [{"role": "user", "content": "Using js, Find the number of connected components in a given undirected graph"}, {"role": "assistant", "content": "let visited = [];\n\nfunction DFS(v, adjList) {\n visited[v] = true;\n for(let i = 0; i < adjList[v].length; i++) {\n if(!visited[adjList[v][i]]) {\n DFS(adjList[v][i], adjList);\n }\n }\n}\n\nfunction numberOfConnectedComponents(adjList) {\n let components = 0;\n for(let i = 0; i < adjList.length; i++) {\n if(!visited[i]) {\n DFS(i, adjList);\n components++;\n }\n }\n return components;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\n#include <stdlib.h>\n\nint** multiply(int** a, int scalar, int rows, int cols) {\n int i, j;\n // Create a result matrix dynamically\n int** result = (int**)malloc(rows * sizeof(int*));\n for(i = 0; i < rows; i++) {\n result[i] = (int*)malloc(cols * sizeof(int));\n }\n\n // Multiply the matrix by the scalar\n for(i = 0; i < rows; i++) {\n for(j = 0; j < cols; j++) {\n result[i][j] = a[i][j] * scalar;\n }\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "Calculate the product of a given matrix, represented as 2D array, and a given scalar, and return the result"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/ريـاضيات\"؛\n\nاستخدم مـتم؛\n\n\nدالة طويلة_شعاع(شعاع: سند[مـصفوفة[عـائم[64]]]): عـائم[64] {\n\tعرف مجموع: عـائم[64] = 0؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < شعاع.هات_الطول() ، دليل++ {\n\t\tمجموع += شعاع(دليل) * شعاع(دليل)؛\n\t}\n\t\n\tارجع ريـاضيات.جذر(مجموع)؛\n}\n"}, {"role": "assistant", "content": "function vectorNorm(vector) {\n let sum = 0.0;\n for (let i = 0; i < vector.length; i++) {\n sum += vector[i] * vector[i];\n }\n return Math.sqrt(sum);\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nuse Srl;\n\n\nfunc is_digit(c: Char): Bool {\n return (c >= '0' && c <= '9');\n}\n"}, {"role": "assistant", "content": "#include <stdbool.h>\n\nbool is_digit(char c) {\n return (c >= '0' && c <= '9');\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\n#include <stdbool.h>\n\n// Criteria function that checks if a number is positive\nbool criteria(int num) {\n return num > 0;\n}\n\n// Function to check all elements in an array\nbool check_any(int arr[], int size) {\n for(int i = 0; i < size; i++) {\n if(criteria(arr[i])) {\n return true;\n }\n }\n return false;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"closure\";\n\n\nuse Srl;\n\n\nfunc check_any(a: ref[Array[Int]], f: closure (num: Int): Bool): Bool {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if f(a(i)) {\n return true;\n }\n }\n\n return false;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Math\";\nimport \"Srl/Array\";\n\n\n\nuse Srl;\n\nclass Point {\n def x : Float;\n def y : Float;\n};\n\nfunc calculateDistance(a: Point, b: Point): Float {\n return Math.sqrt(Math.pow(b.x - a.x, 2.0) + Math.pow(b.y - a.y, 2.0));\n}\n\nfunc findFarthestPoint(givenPoint: Point, points: ref[Array[Point]]): Point {\n def maxDistance: Float = 0;\n def farthestPoint: Point;\n\n def i: Int;\n for i = 0 , i < points.getLength() , i++ {\n def distance: Float = calculateDistance(givenPoint, points(i));\n if distance > maxDistance {\n maxDistance = distance;\n farthestPoint = points(i);\n }\n }\n\n return farthestPoint;\n}\n"}, {"role": "assistant", "content": "find and return the farthest point to a given point from a given set of points"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction findMostFrequent(arr) {\n var maxCount = 0, res = -1;\n\n for (var i = 0; i < arr.length; i++) {\n var count = 1;\n for (var j = i + 1; j < arr.length; j++)\n if (arr[i] == arr[j])\n count++;\n if (count > maxCount) {\n maxCount = count;\n res = arr[i];\n }\n }\n\n return res;\n}\n"}, {"role": "assistant", "content": "find and return the most frequent item in a given array"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, check if three given points are collinear"}, {"role": "assistant", "content": "use Srl;\n\nclass Point {\n def x : Int;\n def y : Int;\n};\n\nfunc areCollinear(p1: Point, p2: Point, p3: Point): Bool {\n return (p2.y - p1.y) * (p3.x - p1.x) == (p3.y - p1.y) * (p2.x - p1.x);\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, Check if all elements in a given array satisfy a criteria defined by a function with boolean return value"}, {"role": "assistant", "content": "#include <stdbool.h>\n\n// Criteria function that checks if a number is positive\nbool criteria(int num) {\n return num > 0;\n}\n\n// Function to check all elements in an array\nbool check_all(int arr[], int size) {\n for(int i = 0; i < size; i++) {\n if(!criteria(arr[i])) {\n return false;\n }\n }\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc clip(a: ref[Array[Int]], lower: Int, upper: Int) {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if a(i) < lower {\n a(i) = lower;\n }\n else if a(i) > upper {\n a(i) = upper;\n }\n }\n}\n"}, {"role": "assistant", "content": "void clip(int arr[], int n, int lower, int upper) {\n for(int i = 0; i < n; i++) {\n if(arr[i] < lower) {\n arr[i] = lower;\n } else if(arr[i] > upper) {\n arr[i] = upper;\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc initializeArray(a: ref[Array[Int]], size: Int, val: Int) {\n def i: Int;\n for i = 0, i < size, i++ {\n a.add(val);\n }\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة هيئ_مصفوفة(م: سند[مـصفوفة[صـحيح]]، حجم: صـحيح، قيمة: صـحيح) {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < حجم ، دليل++ {\n\t\tم.أضف(قيمة)؛\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, اجتزئ سلسلة نصية معطاة ضمن مجال معطى و ارجع النتيجة"}, {"role": "assistant", "content": "اشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة اجتزئ(س: سند[نـص]، بداية: صـحيح، نهاية: صـحيح): نـص {\n\tعرف نتيجة: نـص = \"\"؛\n\n\tعرف دليل: صـحيح؛\n\tلكل دليل = بداية ، دليل <= نهاية ، دليل++ {\n\t\tنتيجة.ألحق(س(دليل))؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, apply the given function `f` on each element of the given array `a` and return the result"}, {"role": "assistant", "content": "void foreach(int a[], int n, int (*f)(int)) {\n for(int i = 0; i < n; i++) {\n a[i] = f(a[i]);\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction insert(a, n, pos, x) {\n // Shift elements to right\n for (let i = n; i > pos; i--)\n a[i] = a[i - 1];\n\n // Insert x at pos\n a[pos] = x;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc insert(a: ref[Array[Int]], pos: Int, val: Int) {\n def size: Int = a.getLength();\n\ta.add(0); // increase the size by 1\n\n def i: Int;\n for i = size , i > pos , i-- {\n a(i) = a(i - 1);\n }\n\n a(pos) = val;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Array\";\nimport \"Srl/Math\";\n\nuse Srl;\n\n\nfunc dot_product(v1: ref[Array[Float[64]]], v2: ref[Array[Float[64]]]): Float[64] {\n def result: Float[64] = 0;\n\n def i: Int;\n for i = 0 , i < v1.getLength() , i++ {\n result += v1(i) * v2(i);\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "Calculate the dot product of two given vectors each represented by an array and return the result"}]}
{"messages": [{"role": "user", "content": "What this code do?\nvoid foreach(int a[], int n, int (*f)(int)) {\n for(int i = 0; i < n; i++) {\n a[i] = f(a[i]);\n }\n}\n"}, {"role": "assistant", "content": "apply the given function `f` on each element of the given array `a` and return the result"}]}
{"messages": [{"role": "user", "content": "What this code do?\n#include <stdlib.h>\n\n// Function to find the intersection point of two lines\ndouble* findIntersection(double a1, double b1, double c1, double a2, double b2, double c2) {\n // Check if the lines are parallel\n if(a1*b2 - a2*b1 == 0) {\n return NULL;\n }\n\n double* result = (double*)malloc(2 * sizeof(double));\n result[0] = (b1*c2 - b2*c1) / (a1*b2 - a2*b1);\n result[1] = (a2*c1 - a1*c2) / (a1*b2 - a2*b1);\n return result;\n}\n"}, {"role": "assistant", "content": "Find the intersection point of two given lines (the line represented by three values `a`, `b`, `c` as ax + by + c = 0) and return it, in case of parallel line return null or empty array"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\nint find_diff_index(int arr1[], int arr2[], int n) {\n int i;\n for(i = 0; i < n; i++) {\n if(arr1[i] != arr2[i]) {\n return i;\n }\n }\n return -1; // return -1 if no difference is found\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc find_diff_index(a1: ref[Array[Int]], a2: ref[Array[Int]]): Int {\n def i: Int;\n for i = 0 , i < a1.getLength() , i++ {\n if a1(i) != a2(i) {\n return i;\n }\n }\n return -1;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة هل_تباديل(م1: سند[مـصفوفة[صـحيح]]، م2: سند[مـصفوفة[صـحيح]]): ثـنائي {\n\tإذا م1.هات_الطول() != م2.هات_الطول() {\n\t\tارجع خطأ؛\n\t}\n\t\n\tعرف مزار: مـصفوفة[ثـنائي]؛\n\tعرف دليل1: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < م2.هات_الطول() ، دليل1++ {\n\t\tمزار.أضف(خطأ)؛\n\t}\n\t\n\tعرف دليل2: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < م1.هات_الطول() ، دليل1++ {\n\t\tعرف موجود: ثـنائي = خطأ؛\n\t\tلكل دليل2 = 0 ، دليل2 < م2.هات_الطول() ، دليل2++ {\n\t\t\tإذا م1(دليل1) == م2(دليل2) && !مزار(دليل2) {\n\t\t\t\tموجود = صح؛\n\t\t\t\tمزار(دليل2) = صح؛\n\t\t\t\tاقطع؛\n\t\t\t}\n\t\t}\n\t\tإذا !موجود {\n\t\t\tارجع خطأ؛\n\t\t}\n\t}\n\tارجع صح؛\n}\n"}, {"role": "assistant", "content": "// Function to check if arr2 is a permutation of arr1\nfunction is_permutation(arr1, arr2) {\n // If sizes are not equal, return false\n if(arr1.length !== arr2.length) {\n return false;\n }\n\n // Create an array to keep track of visited elements\n let visited = new Array(arr2.length).fill(false);\n\n // For each element in arr1\n for(let i = 0; i < arr1.length; i++) {\n let found = false;\n\n // For each element in arr2\n for(let j = 0; j < arr2.length; j++) {\n // If the element in arr1 is found in arr2 and it has not been visited\n if(arr1[i] === arr2[j] && !visited[j]) {\n found = true;\n visited[j] = true; // Mark the element in arr2 as visited\n break;\n }\n }\n\n // If the element in arr1 is not found in arr2, return false\n if(!found) {\n return false;\n }\n }\n\n // If we reach here, then arr2 is a permutation of arr1\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction rfind(a, val) {\n for (let i = a.length - 1; i != 0 ; i--) {\n if (a[i] == val) {\n return i;\n }\n }\n return -1;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جد_من_الخلف(م: سند[مـصفوفة[صـحيح]]، قيمة: صـحيح): صحيح {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = م.هات_الطول() - 1 ، دليل != 0 ، دليل-- {\n\t\tإذا م(دليل) == قيمة {\n\t\t\tارجع دليل؛\n\t\t}\n\t}\n\tارجع -1؛\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, check if a given string contains a given char"}, {"role": "assistant", "content": "import \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc char_exists(s: ref[String], c: Char): Bool {\n def i: Int;\n\tfor i = 0 , i < s.getLength() , i++ {\n\t\tif (s(i) == c) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\n#include <stdbool.h>\n\nbool is_alphabet(char c) {\n return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');\n}\n"}, {"role": "assistant", "content": "check if a given character is from the alphabet"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nعرف مـصفوفة_ثنائية: لقب مـصفوفة[مـصفوفة[عـائم[64]]]؛\nعرف شـعاع: لقب مـصفوفة[عـائم[64]]؛\n\n\nدالة جداء(م: سند[مـصفوفة_ثنائية]، ش: سند[شـعاع]): شـعاع {\n\tعرف أسطر: صـحيح = م.هات_الطول()؛\n\tعرف أعمدة: صـحيح = م(0).هات_الطول()؛\n\n\tعرف نتيجة: شـعاع؛\n\t\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < أسطر ، دليل1++ {\n\t\tنتيجة.أضف(0)؛\n\t\tلكل دليل2 = 0 ، دليل2 < أعمدة ، دليل2++ {\n\t\t\t\tنتيجة(دليل1) += م(دليل1)(دليل2) * ش(دليل2)؛\n\t\t}\n\t}\n\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "function multiply(matrix, vector) {\n let rows = matrix.length, cols = matrix[0].length;\n let result = new Array(rows);\n\n for (let i = 0; i < rows; i++) {\n result[i] = 0;\n for (let j = 0; j < cols; j++) {\n result[i] += matrix[i][j] * vector[j];\n }\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nvoid insert(int a[], int n, int pos, int x) {\n // Shift elements to right\n for (int i = n; i > pos; i--)\n a[i] = a[i - 1];\n\n // Insert x at pos\n a[pos] = x;\n}\n"}, {"role": "assistant", "content": "Insert an element at a given position in the given array"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction isPrime(num) {\n if (num <= 1) {\n return false;\n }\n for (let i = 2; i * i <= num; i++) {\n if (num % i === 0) {\n return false;\n }\n }\n return true;\n}\n"}, {"role": "assistant", "content": "Check whether a given number is prime or not and return that result"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction find_char(s, c) {\n for (let i = 0; i < s.length; i++) {\n if (s[i] === c) {\n return i;\n }\n }\n return -1;\n}\n"}, {"role": "assistant", "content": "find and return the position of a given char in a given string"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nuse Srl;\n\n\nfunc is_digit(c: Char): Bool {\n return (c >= '0' && c <= '9');\n}\n"}, {"role": "assistant", "content": "استخدم مـتم؛\n\n\nدالة ينتمي_للأرقام(م: مـحرف): ثـنائي {\n\tارجع ( م <= '9' && م >= '0')؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Array\";\n\nuse Srl;\n\n\nfunc merge(a: ref[Array[Int]], l: Int, m: Int, r: Int) {\n def i: Int;\n def j: Int;\n def k: Int;\n\n def n1: Int = m - l + 1;\n def n2: Int = r - m;\n\n def L: Array[Int];\n def R: Array[Int];\n\n for i = 0 , i < n1 , i++ {\n L.add(a(l+i));\n }\n for i = 0 , i < n2 , i++ {\n R.add(a(m + 1 + i));\n }\n\n i = 0;\n j = 0;\n k = l;\n while i < n1 && j < n2 {\n if L(i) <= R(j) {\n a(k) = L(i);\n i++;\n }\n else {\n a(k) = R(j);\n j++;\n }\n k++;\n }\n\n while i < n1 {\n a(k) = L(i);\n i++;\n k++;\n }\n\n while j < n2 {\n a(k) = R(j);\n j++;\n k++;\n }\n}\n\nfunc mergeSort(a: ref[Array[Int]], l: Int, r: Int) {\n if l < r {\n def m: Int = l + (r - l) / 2;\n\n mergeSort(a, l, m);\n mergeSort(a, m + 1, r);\n\n merge(a, l, m, r);\n }\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة ادمج(م: سند[مـصفوفة[صـحيح]]، يسار: صـحيح، وسط: صـحيح، يمين: صـحيح) {\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tعرف دليل3: صـحيح؛\n\t\n\tعرف حجم1: صـحيح = وسط - يسار + 1؛\n\tعرف حجم2: صـحيح = يمين - وسط؛\n\t\n\tعرف م_يسار: مـصفوفة[صـحيح]؛\n\tعرف م_يمين: مـصفوفة[صـحيح]؛\n\t\n\tلكل دليل1 = 0 ، دليل1 < حجم1 ، دليل1++ {\n\t\tم_يسار.أضف(م(يسار+دليل1))؛\n\t}\n\tلكل دليل1 = 0 ، دليل1 < حجم2 ، دليل1++ {\n\t\tم_يمين.أضف(م(وسط + 1 + دليل1))؛\n\t}\n\t\n\tدليل1 = 0؛\n\tدليل2 = 0؛\n\tدليل3 = يسار؛\n\t\n\tبينما دليل1 < حجم1 && دليل2 < حجم2 {\n\t\tإذا م_يسار(دليل1) <= م_يمين(دليل2) {\n\t\t\tم(دليل3) = م_يسار(دليل1)؛\n\t\t\tدليل1++؛\n\t\t}\n\t\tوإلا {\n\t\t\tم(دليل3) = م_يمين(دليل2)؛\n\t\t\tدليل2++؛\n\t\t}\n\t\tدليل3++؛\n\t}\n\t\n\tبينما دليل1 < حجم1 {\n\t\tم(دليل3) = م_يسار(دليل1)؛\n\t\tدليل1++؛\n\t\tدليل3++؛\n\t}\n\t\n\tبينما دليل2 < حجم2 {\n\t\tم(دليل3) = م_يمين(دليل2)؛\n\t\tدليل2++؛\n\t\tدليل3++؛\n\t}\n}\n\n\nدالة ترتيب_بالدمج(م: سند[مـصفوفة[صـحيح]]، يسار: صـحيح، يمين: صـحيح) {\n\tإذا يسار < يمين {\n\t\tعرف وسط: صـحيح = يسار + (يمين - يسار) / 2؛\n\t\t\n\t\tترتيب_بالدمج(م، يسار، وسط)؛\n\t\tترتيب_بالدمج(م، وسط + 1، يمين)؛\n\t\t\n\t\tادمج(م، يسار، وسط، يمين)؛\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, Replace a given value with another given value in a given array"}, {"role": "assistant", "content": "function replace(arr, oldValue, newValue) {\n for(var i = 0; i < arr.length; i++) {\n if(arr[i] == oldValue) {\n arr[i] = newValue;\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\n#include <stdio.h>\n#define MAX 100\n\nint graph[MAX][MAX];\nint visited[MAX];\nint n;\n\nint isCyclic(int i) {\n if (visited[i] == 2) {\n return 1;\n }\n visited[i] = 1;\n for (int j = 0; j < n; j++) {\n if (graph[i][j]) {\n if (visited[j] == 1) return 1;\n else if (visited[j] == 0 && isCyclic(j)) return 1;\n }\n }\n visited[i] = 2;\n return 0;\n}\n\nint isDAG() {\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n visited[j] = 0;\n }\n if (isCyclic(i)) {\n return 0;\n }\n }\n return 1;\n}\n"}, {"role": "assistant", "content": "Check if a given directed graph is a DAG"}]}
{"messages": [{"role": "user", "content": "Using c, calculate and return the area of polygon given its vertices"}, {"role": "assistant", "content": "#include <stdlib.h>\n\ntypedef struct {\n double x;\n double y;\n} Point;\n\ndouble calculatePolygonArea(Point* vertices, int numVertices) {\n double area = 0.0;\n int j = numVertices - 1;\n\n for (int i = 0; i < numVertices; i++) {\n area += (vertices[j].x + vertices[i].x) * (vertices[j].y - vertices[i].y);\n j = i;\n }\n\n return abs(area / 2.0);\n}\n\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة المحرف_متواجد(س: سند[نـص]، م: مـحرف): ثـنائي {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) == م {\n\t\t\tارجع صح؛\n\t\t}\n\t}\n\tارجع خطأ؛\n}\n"}, {"role": "assistant", "content": "#include <stdbool.h>\n\nbool char_exists(char s[], int n, char c) {\n for (int i = 0; i < n; i++) {\n if (s[i] == c) {\n return true;\n }\n }\n return false;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, Read the nth line of a text file given its path and return the result"}, {"role": "assistant", "content": "#include <stdio.h>\n#include <stdlib.h>\n\n// Function to read the n-th line of a file\nchar* read_nth_line(const char* file_path, int n) {\n FILE* file = fopen(file_path, \"r\");\n if(file == NULL) {\n printf(\"Could not open file %s\\n\", file_path);\n return NULL;\n }\n\n char* line = NULL;\n size_t len = 0;\n ssize_t read;\n\n int current_line = 0;\n while((read = getline(&line, &len, file)) != -1) {\n current_line++;\n if(current_line == n) {\n fclose(file);\n return line;\n }\n }\n\n // If we reach here, then the file has less than n lines\n fclose(file);\n free(line);\n return NULL;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction findIntersection(a1, b1, c1, a2, b2, c2) {\n // Check if the lines are parallel\n if(a1*b2 - a2*b1 === 0) {\n return null;\n }\n\n let result = [];\n result[0] = (b1*c2 - b2*c1) / (a1*b2 - a2*b1);\n result[1] = (a2*c1 - a1*c2) / (a1*b2 - a2*b1);\n return result;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\nfunc findIntersection(a1: Float[64], b1: Float[64], c1: Float[64], a2: Float[64], b2: Float[64], c2: Float[64]): Array[Float[64]] {\n def result: Array[Float[64]];\n if a1*b2 - a2*b1 == 0 {\n return result;\n }\n\n result.add((b1*c2 - b2*c1) / (a1*b2 - a2*b1));\n result.add((a2*c1 - a1*c2) / (a1*b2 - a2*b1));\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/نـص\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جزئ(س: سند[نـص]، رمز: مـحرف): مـصفوفة[نـص] {\n\tعرف نتيجة: مـصفوفة[نـص]؛\n\t\n\tعرف مؤقت: نـص؛\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) != رمز {\n\t\t\tمؤقت.ألحق(س(دليل))؛\n\t\t}\n\t\tوإلا {\n\t\t\tنتيجة.أضف(مؤقت)؛\n\t\t\tمؤقت = \"\"؛\n\t\t}\n\t}\n\tنتيجة.أضف(مؤقت)؛\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "#include <stdlib.h>\n\n#define MAX_STRINGS 100\n#define MAX_STRING_LEN 100\n\nchar** split(char* str, char token) {\n char** result = (char**) malloc(MAX_STRINGS * sizeof(char*));\n for(int i = 0; i < MAX_STRINGS; i++) {\n result[i] = (char*) malloc(MAX_STRING_LEN * sizeof(char));\n }\n\n int i = 0, j = 0, k = 0;\n while(str[i] != '\\0') {\n if(str[i] != token) {\n result[j][k] = str[i];\n k++;\n } else {\n result[j][k] = '\\0';\n j++;\n k = 0;\n }\n i++;\n }\n result[j][k] = '\\0';\n result[j+1] = NULL; // End of strings\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, Read the lines of a text file given its path into an array and return it"}, {"role": "assistant", "content": "import \"Srl/Fs\";\nimport \"Srl/String\";\nimport \"Srl/Array\";\n\nuse Srl;\n\n\nfunc readFileToArray(file_path: ref[String]): Array[String] {\n def file: ptr[Fs.File] = Fs.openFile(file_path.buf, \"r\");\n def content: Array[String];\n\n Fs.seek(file, 0, Fs.Seek.END);\n def size: Int = Fs.tell(file);\n Fs.seek(file, 0, Fs.Seek.SET);\n \n content.add(String());\n def i: Int;\n def j: Int = 0;\n for i = 0 , i < size , i++ {\n def temp: Char;\n Fs.read(temp~ptr, 1, 1, file);\n\n if temp == '\\n' {\n content.add(String());\n j++;\n }\n else {\n content(j).append(temp);\n }\n }\n\n return content;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\n#include <stdbool.h>\n\nbool exists(int a[], int n, int val) {\n for (int i = 0; i < n; i++) {\n if (a[i] == val) {\n return true;\n }\n }\n return false;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc exists(a: ref[Array[Int]], val: Int): Bool {\n def i: Int;\n for i = 0, i < a.getLength(), i++ {\n if a(i) == val {\n return true;\n }\n }\n return false;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, find and return the most frequent item in a given array"}, {"role": "assistant", "content": "function findMostFrequent(arr) {\n var maxCount = 0, res = -1;\n\n for (var i = 0; i < arr.length; i++) {\n var count = 1;\n for (var j = i + 1; j < arr.length; j++)\n if (arr[i] == arr[j])\n count++;\n if (count > maxCount) {\n maxCount = count;\n res = arr[i];\n }\n }\n\n return res;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\nvoid reduce(char a[4][10], char result[50], void (*f)(char*, char*)) {\n for(int i = 0; i < 4; i++) {\n f(result, a[i]);\n }\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"Srl/String\";\nimport \"closure\";\n\nuse Srl;\n\n\nfunc reduce(a: ref[Array[String]], f: closure(previousValue: ref[String], currentValue: ref[String])): String {\n def result: String = \"\";\n\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n f(result, a(i));\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة استبدل(س: سند[نـص]، م1: مـحرف، م2: مـحرف): نـص {\n\tعرف نتيجة: نـص؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) == م1 {\n\t\t\tنتيجة.ألحق(م2)؛\n\t\t}\n\t\tوإلا {\n\t\t\tنتيجة.ألحق(س(دليل))؛\n\t\t}\n\t}\n\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "function replace(str, oldChar, newChar) {\n var result = \"\";\n for(var i = 0; i < str.length; i++) {\n if(str[i] == oldChar) {\n result += newChar;\n } else {\n result += str[i];\n }\n }\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nclass Point {\n constructor(x, y) {\n this.x = x;\n this.y = y;\n }\n}\n\nfunction calculateDistance(a, b) {\n return Math.sqrt(Math.pow(b.x - a.x, 2) + Math.pow(b.y - a.y, 2));\n}\n\nfunction findClosestPoint(givenPoint, points) {\n let minDistance = calculateDistance(givenPoint, points[0]);\n let closestPoint = points[0];\n \n for(let i = 1; i < points.length; i++) {\n let distance = calculateDistance(givenPoint, points[i]);\n if(distance < minDistance) {\n minDistance = distance;\n closestPoint = points[i];\n }\n }\n \n return closestPoint;\n}\n"}, {"role": "assistant", "content": "find and return the closest point to a given point from a given set of points"}]}
{"messages": [{"role": "user", "content": "What this code do?\nuse Srl;\n\n\nfunc is_digit(c: Char): Bool {\n return (c >= '0' && c <= '9');\n}\n"}, {"role": "assistant", "content": "check if a given character is a digit"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction printArray(a, size) {\n var output = '';\n for(var i = 0; i < size; i++) {\n output += a[i] + ' ';\n }\n console.log(output);\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/طـرفية\"؛\n\nاستخدم مـتم؛\n\n\nدالة اطبع(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tطـرفية.اطبع(\"%d \"، م(دليل))؛\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction printArray(a, size) {\n var output = '';\n for(var i = 0; i < size; i++) {\n output += a[i] + ' ';\n }\n console.log(output);\n}\n"}, {"role": "assistant", "content": "print the given array"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة اجتزئ(م: سند[مـصفوفة[صـحيح]]، بداية: صـحيح، نهاية: صـحيح، نتيجة: سند[مـصفوفة[صـحيح]]) {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = بداية ، دليل <= نهاية ، دليل++ {\n\t\tنتيجة.أضف(م(دليل))؛\n\t}\n}\n"}, {"role": "assistant", "content": "void slice(int arr[], int start, int end, int result[]) {\n int i;\n for(i = start; i <= end; i++) {\n result[i - start] = arr[i];\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nuse Srl;\n\nfunc isPrime(num: Int): Bool {\n if num <= 1 {\n return false;\n }\n\n def i: Int;\n for i = 2 , i * i <= num , i++ {\n if num % i == 0 {\n return false;\n }\n }\n \n return true;\n}\n"}, {"role": "assistant", "content": "استخدم مـتم؛\n\nدالة هل_أولي (عدد: صـحيح): ثـنائي {\n\tإذا عدد <= 1 {\n\t\tارجع خطأ؛\n\t}\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 2 ، دليل * دليل <= عدد ، دليل++ {\n\t\tإذا عدد % دليل == 0 {\n\t\t\tارجع خطأ؛\n\t\t}\n\t}\n\t\n\tارجع صح؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nعرف قيمة_عظمى: صـحيح = 100000؛\n\nدالة الترتيب_بالعد(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tعرف دليل: صـحيح؛\n\t\n\tعرف عداد: مـصفوفة[صـحيح]؛\n\tلكل دليل1 = 0 ، دليل1 < قيمة_عظمى ، دليل1++ {\n\t\tعداد.أضف(0)؛\n\t}\n\t\n\tلكل دليل1 = 0 ، دليل1 < م.هات_الطول() ، دليل1++ {\n\t\tعداد(م(دليل1))++؛\n\t}\n\t\n\tلكل دليل1 = 0 ، دليل1 < قيمة_عظمى ، دليل1++ {\n\t\tلكل دليل2 = 0 ، دليل2 < عداد(دليل1) ، دليل2++ {\n\t\t\tم(دليل++) = دليل1؛\n\t\t}\n\t}\n}\n"}, {"role": "assistant", "content": "const MAX_VALUE = 100000;\n\nfunction countingSort(arr) {\n let i, j;\n let count = new Array(MAX_VALUE + 1).fill(0);\n let output = [];\n\n // Count the occurrence of each number\n for(i = 0; i < arr.length; i++) {\n count[arr[i]]++;\n }\n\n // Reconstruct the sorted array\n for(i = 0; i <= MAX_VALUE; i++) {\n for(j = 0; j < count[i]; j++) {\n output.push(i);\n }\n }\n\n return output;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, filter the given array based on the given function `f` and return the result"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"closure\";\n\n\nuse Srl;\n\n\nfunc filter(a: ref[Array[Int]], f: closure (num: Int): Bool): Array[Int] {\n def result: Array[Int];\n\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if f(a(i)) {\n result.add(a(i));\n }\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc find_char(s: ref[String], c: Char): Int {\n def i: Int;\n\tfor i = 0 , i < s.getLength() , i++ {\n\t\tif (s(i) == c) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n"}, {"role": "assistant", "content": "function find_char(s, c) {\n for (let i = 0; i < s.length; i++) {\n if (s[i] === c) {\n return i;\n }\n }\n return -1;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, write the selection sort algorithm for a given array"}, {"role": "assistant", "content": "void selectionSort(int arr[], int n) {\n int i, j, min_idx, temp;\n\n // One by one move boundary of unsorted subarray\n for (i = 0; i < n-1; i++) {\n // Find the minimum element in unsorted array\n min_idx = i;\n for (j = i+1; j < n; j++)\n if (arr[j] < arr[min_idx])\n min_idx = j;\n\n // Swap the found minimum element with the first element\n temp = arr[min_idx];\n arr[min_idx] = arr[i];\n arr[i] = temp;\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc starts_with(s: ref[String], prefix: ref[String]): Bool {\n\tif s.getLength() < prefix.getLength() {\n\t\treturn false;\n\t}\n\n def i: Int;\n\tfor i = 0 , i < prefix.getLength() , i++ {\n\t\tif (prefix(i) != s(i)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n"}, {"role": "assistant", "content": "function startsWith(str, prefix) {\n for(let i = 0; i < prefix.length; i++) {\n if(str[i] !== prefix[i])\n return false;\n }\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة أزل(م: سند[مـصفوفة[صـحيح]]، موقع: صـحيح) {\n\tعرف حجم: صـحيح = م.هات_الطول()؛\n\n\tعرف دليل: صـحيح؛\n\tلكل دليل = موقع ، دليل < حجم - 1 ، دليل++ {\n\t\tم(دليل) = م(دليل + 1)؛\n\t}\n\tم.أزل(حجم - 1)؛\n}\n"}, {"role": "assistant", "content": "void erase(int a[], int n, int pos) {\n // Shift elements to left\n for (int i = pos; i < n - 1; i++)\n a[i] = a[i + 1];\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Array\";\n\nuse Srl;\n\n\ndef MAX_VALUE: Int = 100000;\n\nfunc countingSort(a: ref[Array[Int]]) {\n def i: Int;\n def j: Int;\n def idx: Int;\n\n def count: Array[Int];\n for i = 0 , i < MAX_VALUE , i++ {\n count.add(0);\n }\n\n for i = 0 , i < a.getLength() , i++ {\n count(a(i))++;\n }\n\n for i = 0 , i < MAX_VALUE , i++ {\n for j = 0 , j < count(i) , j++ {\n a(idx++) = i;\n }\n }\n}\n"}, {"role": "assistant", "content": "write the counting sort algorithm for a given array"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc replace(s: ref[String], oldChar: Char, newChar: Char): String {\n def result: String;\n\n def i: Int;\n for i = 0 , i < s.getLength() , i++ {\n if (s(i) == oldChar) {\n result.append(newChar);\n }\n else {\n result.append(s(i));\n }\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "Replace a given char with another given char in a given string and return the new string"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, Calculate the norm of a given vector which is represented by an array and return the result"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"Srl/Math\";\n\nuse Srl;\n\n\nfunc vectorNorm(vector: ref[Array[Float[64]]]): Float[64] {\n def sum: Float[64] = 0;\n\n def i: Int;\n for i = 0 , i < vector.getLength() , i++ {\n sum += vector(i) * vector(i);\n }\n\n return Math.sqrt(sum);\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\nvoid clip(int arr[], int n, int lower, int upper) {\n for(int i = 0; i < n; i++) {\n if(arr[i] < lower) {\n arr[i] = lower;\n } else if(arr[i] > upper) {\n arr[i] = upper;\n }\n }\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc clip(a: ref[Array[Int]], lower: Int, upper: Int) {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if a(i) < lower {\n a(i) = lower;\n }\n else if a(i) > upper {\n a(i) = upper;\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Array\";\n\nuse Srl;\n\n\nfunc insertionSort(a: ref[Array[Int]]) {\n def i: Int;\n def key: Int;\n def j: Int;\n\n for i = 1 , i < a.getLength() , i++ {\n key = a(i);\n j = i - 1;\n\n while j >= 0 && a(j) > key {\n a(j + 1) = a(j);\n j = j - 1;\n }\n a(j + 1) = key;\n }\n}\n"}, {"role": "assistant", "content": "write the insertion sort algorithm for a given array"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\nint find_char(char s[], int n, char c) {\n for (int i = 0; i < n; i++) {\n if (s[i] == c) {\n return i;\n }\n }\n return -1;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة جد_المحرف(س: سند[نـص]، م: مـحرف): صـحيح {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) == م {\n\t\t\tارجع دليل؛\n\t\t}\n\t}\n\tارجع -1؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nconst fs = require('fs');\n\nfunction appendLogEntry(filename, logEntry) {\n let stream = fs.createWriteStream(filename, {flags:'a'});\n stream.write(logEntry + '\\n');\n stream.end();\n}\n"}, {"role": "assistant", "content": "Append a given log entry to a file given its path"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\nvoid initializeArray(int* arr, int size, int value) {\n for(int i = 0; i < size; i++) {\n arr[i] = value;\n }\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc initializeArray(a: ref[Array[Int]], size: Int, val: Int) {\n def i: Int;\n for i = 0, i < size, i++ {\n a.add(val);\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Array\";\n\nuse Srl;\n\ndef Matrix: alias Array[Array[Float[64]]];\n\nfunc multiply(a: ref[Matrix], b: ref[Matrix]): Matrix {\n def rowsA: Int = a.getLength();\n def rowsB: Int = b.getLength();\n def colsA: Int = a(0).getLength();\n def colsB: Int = b(0).getLength();\n \n def result: Matrix;\n\n def i: Int;\n def j: Int;\n def k: Int;\n for i = 0 , i < rowsA , i++ {\n def row: Array[Float[64]];\n for j = 0 , j < colsB , j++ {\n row.add(0);\n for k = 0 , k < colsA , k++ {\n row(j) += a(i)(k) * b(k)(j);\n }\n }\n result.add(row);\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nعرف مـصفوفة_ثنائية: لقب مـصفوفة[مـصفوفة[عـائم[64]]]؛\n\n\nدالة جداء(م1: سند[مـصفوفة_ثنائية]، م2: سند[مـصفوفة_ثنائية]): مـصفوفة_ثنائية {\n\tعرف أسطر_م1: صـحيح = م1.هات_الطول()؛\n\tعرف أسطر_م2: صـحيح = م2.هات_الطول()؛\n\tعرف أعمدة_م1: صـحيح = م1(0).هات_الطول()؛\n\tعرف أعمدة_م2: صـحيح = م2(0).هات_الطول()؛\n\n\tعرف نتيجة: مـصفوفة_ثنائية؛\n\t\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tعرف دليل3: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < أسطر_م1 ، دليل1++ {\n\t\tعرف سطر: مـصفوفة[عـائم[64]]؛\n\t\tلكل دليل2 = 0 ، دليل2 < أعمدة_م2 ، دليل2++ {\n\t\t\tسطر.أضف(0)؛\n\t\t\tلكل دليل3 = 0 ، دليل3 < أعمدة_م1 ، دليل3++ {\n\t\t\t\tسطر(دليل2) += م1(دليل1)(دليل3) * م2(دليل3)(دليل2)؛\n\t\t\t}\n\t\t}\n\t\tنتيجة.أضف(سطر)؛\n\t}\n\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction multiply(matrix, scalar) {\n let rows = matrix.length, cols = matrix[0].length;\n let result = new Array(rows);\n\n for (let i = 0; i < rows; i++) {\n result[i] = new Array(cols);\n for (let j = 0; j < cols; j++) {\n result[i][j] = matrix[i][j] * scalar;\n }\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "Calculate the product of a given matrix, represented as 2D array, and a given scalar, and return the result"}]}
{"messages": [{"role": "user", "content": "Using js, Write DFS algorithm for the given graph"}, {"role": "assistant", "content": "function dfs(node, visited, G) {\n visited[node] = true;\n console.log(node);\n\n for(let i = 0; i < G[node].length; i++) {\n if(!visited[G[node][i]]) {\n dfs(G[node][i], visited, G);\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nconst fs = require('fs');\n\nfunction appendLogEntry(filename, logEntry) {\n let stream = fs.createWriteStream(filename, {flags:'a'});\n stream.write(logEntry + '\\n');\n stream.end();\n}\n"}, {"role": "assistant", "content": "import \"Srl/Fs\";\nimport \"Srl/String\";\n\nuse Srl;\n\n\nfunc appendLogEntry(file_path: ref[String], logEntry: ref[String]) {\n def file: ptr[Fs.File] = Fs.openFile(file_path.buf, \"a\");\n\n Fs.write(logEntry.buf, 1, logEntry.getLength(), file);\n Fs.write(\"\\n\", 1, 1, file);\n Fs.closeFile(file);\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, Find and return the sum of the given array `a`"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\nfunc sum(a: ref[Array[Int]]): Int {\n def sum: Int = 0;\n\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n sum += a(i);\n }\n\n return sum;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Array\";\n\nuse Srl;\n\ndef Matrix: alias Array[Array[Float[64]]];\n\nfunc multiply(a: ref[Matrix], b: ref[Matrix]): Matrix {\n def rowsA: Int = a.getLength();\n def rowsB: Int = b.getLength();\n def colsA: Int = a(0).getLength();\n def colsB: Int = b(0).getLength();\n \n def result: Matrix;\n\n def i: Int;\n def j: Int;\n def k: Int;\n for i = 0 , i < rowsA , i++ {\n def row: Array[Float[64]];\n for j = 0 , j < colsB , j++ {\n row.add(0);\n for k = 0 , k < colsA , k++ {\n row(j) += a(i)(k) * b(k)(j);\n }\n }\n result.add(row);\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "Calculate the product of two given matrices represented by a 2D array and return the result"}]}
{"messages": [{"role": "user", "content": "Using js, Find and return the sum of the given array `a`"}, {"role": "assistant", "content": "function sum(a) {\n let result = 0;\n\n for (let i = 0; i < a.length; i++) {\n result += a[i];\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction multiply(matrix, vector) {\n let rows = matrix.length, cols = matrix[0].length;\n let result = new Array(rows);\n\n for (let i = 0; i < rows; i++) {\n result[i] = 0;\n for (let j = 0; j < cols; j++) {\n result[i] += matrix[i][j] * vector[j];\n }\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "Calculate the product of a given matrix, represented as 2D array, and a given vector, represented as an array, and return the result"}]}
{"messages": [{"role": "user", "content": "What this code do?\n// Criteria function that checks if a number is positive\nfunction criteria(num) {\n return num > 0;\n}\n\n// Function to check all elements in an array\nfunction check_all(arr) {\n for(let i = 0; i < arr.length; i++) {\n if(!criteria(arr[i])) {\n return false;\n }\n }\n return true;\n}\n"}, {"role": "assistant", "content": "Check if all elements in a given array satisfy a criteria defined by a function with boolean return value"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Array\";\n\nuse Srl;\n\n\nfunc max(a: ref[Array[Int]]): Int {\n def result: Int = a(0);\n\n def i: Int;\n for i = 1 , i < a.getLength() , i++ {\n if a(i) > result {\n result = a(i);\n }\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "function max(a) {\n let result = a[0];\n for (let i = 1 ; i < a.length ; i++) {\n if (result < a[i]) {\n result = a[i];\n }\n }\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\n#include <math.h>\n\ntypedef struct {\n double x;\n double y;\n} Point;\n\ndouble calculateDistance(Point a, Point b) {\n return sqrt(pow(b.x - a.x, 2) + pow(b.y - a.y, 2));\n}\n\nPoint findClosestPoint(Point givenPoint, Point points[], int size) {\n double minDistance = calculateDistance(givenPoint, points[0]);\n Point closestPoint = points[0];\n\n for(int i = 1; i < size; i++) {\n double distance = calculateDistance(givenPoint, points[i]);\n if(distance < minDistance) {\n minDistance = distance;\n closestPoint = points[i];\n }\n }\n\n return closestPoint;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/ريـاضيات\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nصنف نـقطة {\n\tعرف س: عـائم؛\n\tعرف ص: عـائم؛\n}\n\nدالة احسب_مسافة(ن1: نـقطة، ن2: نـقطة): عـائم {\n\tارجع ريـاضيات.جذر(ريـاضيات.ارفع(ن2.س - ن1.س، 2.0) + ريـاضيات.ارفع(ن2.ص - ن1.ص، 2.0))؛\n}\n\nدالة جد_أقرب_نقطة(ن: نـقطة، نقاط: سند[مـصفوفة[نـقطة]]): نـقطة {\n\tعرف أقرب_مسافة: عـائم = احسب_مسافة(ن، نقاط(0))؛\n\tعرف أقرب_نقطة: نـقطة = نقاط(0)؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 1 ، دليل < نقاط.هات_الطول() ، دليل++ {\n\t\tعرف مسافة: عـائم = احسب_مسافة(ن، نقاط(دليل))؛\n\t\tإذا مسافة < أقرب_مسافة {\n\t\t\tأقرب_مسافة = مسافة؛\n\t\t\tأقرب_نقطة = نقاط(دليل)؛\n\t\t}\n\t}\n\tارجع أقرب_نقطة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\n#include <stdlib.h>\n\nint* multiply(int** a, int* v, int rows, int cols) {\n int i, j;\n // Create a result vector dynamically\n int* result = (int*)malloc(rows * sizeof(int));\n\n // Initialize the result vector with 0\n for(i = 0; i < rows; i++) {\n result[i] = 0;\n }\n\n // Multiply the matrix by the vector\n for(i = 0; i < rows; i++) {\n for(j = 0; j < cols; j++) {\n result[i] += a[i][j] * v[j];\n }\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "Calculate the product of a given matrix, represented as 2D array, and a given vector, represented as an array, and return the result"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\n#include <math.h>\n\ntypedef struct {\n double x;\n double y;\n} Point;\n\ndouble calculateDistance(Point a, Point b) {\n return sqrt(pow(b.x - a.x, 2) + pow(b.y - a.y, 2));\n}\n\nPoint findClosestPoint(Point givenPoint, Point points[], int size) {\n double minDistance = calculateDistance(givenPoint, points[0]);\n Point closestPoint = points[0];\n\n for(int i = 1; i < size; i++) {\n double distance = calculateDistance(givenPoint, points[i]);\n if(distance < minDistance) {\n minDistance = distance;\n closestPoint = points[i];\n }\n }\n\n return closestPoint;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Math\";\nimport \"Srl/Array\";\n\n\n\nuse Srl;\n\nclass Point {\n def x : Float;\n def y : Float;\n};\n\nfunc calculateDistance(a: Point, b: Point): Float {\n return Math.sqrt(Math.pow(b.x - a.x, 2.0) + Math.pow(b.y - a.y, 2.0));\n}\n\nfunc findClosestPoint(givenPoint: Point, points: ref[Array[Point]]): Point {\n def minDistance: Float = calculateDistance(givenPoint, points(0));\n def closestPoint: Point = points(0);\n\n def i: Int;\n for i = 1 , i < points.getLength() , i++ {\n def distance: Float = calculateDistance(givenPoint, points(i));\n if distance < minDistance {\n minDistance = distance;\n closestPoint = points(i);\n }\n }\n\n return closestPoint;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\nvoid rotate(int a[], int n) {\n int first_element = a[0];\n\n for (int i = 0 ; i < n - 1; i++) {\n a[i] = a[i + 1];\n }\n\n a[n - 1] = first_element;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc rotate(a: ref[Array[Int]]) {\n def size: Int = a.getLength();\n\n def first_element: Int = a(0);\n\n def i: Int;\n for i = 0 , i < size - 1 , i++ {\n a(i) = a(i + 1);\n }\n\n a(size - 1) = first_element;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nuse Srl;\n\n\nfunc is_alpha(c: Char): Bool {\n return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');\n}\n"}, {"role": "assistant", "content": "استخدم مـتم؛\n\n\nدالة ينتمي_للأبجدية(م: مـحرف): ثـنائي {\n\tارجع ( م <= 'Z' && م >= 'A') || ( م <= 'z' && م >= 'a')؛\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, جد و أرجع ناتج جمع عناصر المصفوفة المعطاة م"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جمع(م: سند[مـصفوفة[صـحيح]]): صـحيح {\n\tعرف نتيجة: صـحيح = 0؛\n\n\tعرف دليل: صـحيح؛\n\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n نتيجة += م(دليل)؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\n// Criteria function that checks if a number is positive\nfunction criteria(num) {\n return num > 0;\n}\n\n// Function to check all elements in an array\nfunction check_all(arr) {\n for(let i = 0; i < arr.length; i++) {\n if(!criteria(arr[i])) {\n return false;\n }\n }\n return true;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة تفحص_الكل(م: سند[مـصفوفة[صـحيح]]، د: مغلفة(رقم: صـحيح): ثـنائي): ثـنائي {\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا !د(م(دليل)) {\n\t\t\tارجع خطأ؛\n\t\t}\n\t}\n\t\n\tارجع صح؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/ريـاضيات\"؛\n\nاستخدم مـتم؛\n\n\nدالة جداء_نقطي(شعاع1: سند[مـصفوفة[عـائم[64]]]، شعاع2: سند[مـصفوفة[عـائم[64]]]): عـائم[64] {\n\tعرف نتيجة: عـائم[64] = 0؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < شعاع1.هات_الطول() ، دليل++ {\n\t\tنتيجة += شعاع1(دليل) * شعاع2(دليل)؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "احسب الجداء النقطي لشعاعين معطيين كل منهما ممثل على شكل مصفوفة و ارجع النتيجة"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/طـرفية\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nدالة دفس(عقدة: صـحيح، مزارة: سند[مـصفوفة[ثـنائي]]، بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]) {\n\tمزارة(عقدة) = صح؛\n\tطـرفية.اطبع(\"%d \"، عقدة)؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان(عقدة).هات_الطول() ، دليل++ {\n\t\tعرف عقدة_ابن: صـحيح = بيان(عقدة)(دليل)؛\n\t\tإذا !مزارة(عقدة_ابن) {\n\t\t\tدفس(عقدة_ابن، مزارة، بيان)؛\n\t\t}\n\t}\n}\n"}, {"role": "assistant", "content": "اكتب خوارزمية البحث بالعمق للبيان المعطى"}]}
{"messages": [{"role": "user", "content": "Using js, Check if any element in a given array satisfy a criteria defined by a function with boolean return value"}, {"role": "assistant", "content": "// Criteria function that checks if a number is positive\nfunction criteria(num) {\n return num > 0;\n}\n\n// Function to check all elements in an array\nfunction check_any(arr) {\n for(let i = 0; i < arr.length; i++) {\n if(criteria(arr[i])) {\n return true;\n }\n }\n return false;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, Find the number of connected components in a given undirected graph"}, {"role": "assistant", "content": "#include <stdio.h>\n\n#define MAX 100\n\nint visited[MAX];\nint matrix[MAX][MAX];\n\nvoid DFS(int v, int n) {\n visited[v] = 1;\n for(int i = 0; i < n; i++) {\n if(matrix[v][i] == 1 && visited[i] == 0) {\n DFS(i, n);\n }\n }\n}\n\nint numberOfConnectedComponents(int n) {\n int components = 0;\n for(int i = 0; i < n; i++) {\n if(visited[i] == 0) {\n DFS(i, n);\n components++;\n }\n }\n return components;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/نـم\"؛\nاشمل \"مـتم/نـص\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة اقرأ_الملف_إلى_مصفوفة(مسار_الملف: سند[نـص]): مـصفوفة[نـص] {\n\tعرف ملف: مؤشر[نـم.مـلف] = نـم.افتح_ملف(مسار_الملف، \"r\")؛\n\tعرف المحتوى: مـصفوفة[نـص]؛\n\n\tنـم.انتقل(ملف، 0، نـم.انـتقال._نهاية_)؛\n\tعرف حجم: صـحيح = نـم.هات_الموقع(ملف)؛\n\tنـم.انتقل(ملف، 0، نـم.انـتقال._بداية_)؛\n\t\n\tالمحتوى.أضف(نـص())؛\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح = 0؛\n\tلكل دليل1 = 0 ، دليل1 < حجم ، دليل1++ {\n\t\tعرف مؤقت: مـحرف؛\n\t\tنـم.اقرأ(مؤقت~مؤشر، 1، 1، ملف)؛\n\t\t\n\t\tإذا مؤقت == '\\n' {\n\t\t\tالمحتوى.أضف(نـص())؛\n\t\t\tدليل2++؛\n\t\t}\n\t\tوإلا {\n\t\t\tالمحتوى(دليل2).ألحق(مؤقت)؛\n\t\t}\n\t}\n\t\n\tارجع المحتوى؛\n}\n"}, {"role": "assistant", "content": "const fs = require('fs');\n\nfunction readFileToArray(filename) {\n const data = fs.readFileSync(filename, 'utf8');\n let lines = [''];\n let j = 0;\n for (let i = 0; i < data.length; i++) {\n if (data[i] === '\\n') {\n lines.push('');\n j++;\n } else {\n lines[j] += data[i];\n }\n }\n return lines;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Array\";\n\nuse Srl;\n\ndef Matrix: alias Array[Array[Float[64]]];\ndef Vector: alias Array[Float[64]];\n\n\nfunc multiply(m: ref[Matrix], v: ref[Vector]): Vector {\n def rows: Int = m.getLength();\n def cols: Int = m(0).getLength();\n \n def result: Vector;\n\n def i: Int;\n def j: Int;\n for i = 0 , i < rows , i++ {\n result.add(0);\n for j = 0 , j < cols , j++ {\n result(i) += m(i)(j) * v(j);\n }\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "#include <stdlib.h>\n\nint* multiply(int** a, int* v, int rows, int cols) {\n int i, j;\n // Create a result vector dynamically\n int* result = (int*)malloc(rows * sizeof(int));\n\n // Initialize the result vector with 0\n for(i = 0; i < rows; i++) {\n result[i] = 0;\n }\n\n // Multiply the matrix by the vector\n for(i = 0; i < rows; i++) {\n for(j = 0; j < cols; j++) {\n result[i] += a[i][j] * v[j];\n }\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction calculatePolygonArea(vertices) {\n let area = 0;\n let j = vertices.length - 1;\n\n for (let i = 0; i < vertices.length; i++) {\n area += (vertices[j].x + vertices[i].x) * (vertices[j].y - vertices[i].y);\n j = i;\n }\n\n return Math.abs(area / 2);\n}\n"}, {"role": "assistant", "content": "import \"Srl/Math\";\nimport \"Srl/Array\";\n\nuse Srl;\n\nclass Point {\n def x : Float;\n def y : Float;\n};\n\nfunc calculatePolygonArea(vertices: ref[Array[Point]]): Float {\n def area: Float = 0;\n def numVertices: Int = vertices.getLength();\n def j: Int = numVertices - 1;\n\n def i: Int;\n for i = 0 , i < numVertices , i++ {\n area += (vertices(j).x + vertices(i).x) * (vertices(j).y - vertices(i).y);\n j = i;\n }\n return Math.abs(area / 2.0);\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/طـرفية\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nدالة دفس(عقدة: صـحيح، مزارة: سند[مـصفوفة[ثـنائي]]، بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]) {\n\tمزارة(عقدة) = صح؛\n\tطـرفية.اطبع(\"%d \"، عقدة)؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان(عقدة).هات_الطول() ، دليل++ {\n\t\tعرف عقدة_ابن: صـحيح = بيان(عقدة)(دليل)؛\n\t\tإذا !مزارة(عقدة_ابن) {\n\t\t\tدفس(عقدة_ابن، مزارة، بيان)؛\n\t\t}\n\t}\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"Srl/Console\";\n\nuse Srl;\n\nfunc dfs(node: Int, visited: ref[Array[Bool]], graph: ref[Array[Array[Int]]]) {\n visited(node) = true;\n Console.print(\"%d \", node);\n\n def i: Int;\n for i = 0 , i < graph(node).getLength(), i++ {\n def childNode: Int = graph(node)(i);\n if !visited(childNode) {\n dfs(childNode, visited, graph);\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\nvoid reduce(char a[4][10], char result[50], void (*f)(char*, char*)) {\n for(int i = 0; i < 4; i++) {\n f(result, a[i]);\n }\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/نـص\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة اختصر(م: سند[مـصفوفة[نـص]]، د: مغلفة(قيمة_سابقة: سند[نـص]، قيمة_حالية: سند[نـص])): نـص {\n\tعرف نتيجة: نـص = \"\"؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tد(نتيجة، م(دليل))؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Array\";\n\nuse Srl;\n\n\nfunc merge(a: ref[Array[Int]], l: Int, m: Int, r: Int) {\n def i: Int;\n def j: Int;\n def k: Int;\n\n def n1: Int = m - l + 1;\n def n2: Int = r - m;\n\n def L: Array[Int];\n def R: Array[Int];\n\n for i = 0 , i < n1 , i++ {\n L.add(a(l+i));\n }\n for i = 0 , i < n2 , i++ {\n R.add(a(m + 1 + i));\n }\n\n i = 0;\n j = 0;\n k = l;\n while i < n1 && j < n2 {\n if L(i) <= R(j) {\n a(k) = L(i);\n i++;\n }\n else {\n a(k) = R(j);\n j++;\n }\n k++;\n }\n\n while i < n1 {\n a(k) = L(i);\n i++;\n k++;\n }\n\n while j < n2 {\n a(k) = R(j);\n j++;\n k++;\n }\n}\n\nfunc mergeSort(a: ref[Array[Int]], l: Int, r: Int) {\n if l < r {\n def m: Int = l + (r - l) / 2;\n\n mergeSort(a, l, m);\n mergeSort(a, m + 1, r);\n\n merge(a, l, m, r);\n }\n}\n"}, {"role": "assistant", "content": "function mergeSort(arr) {\n if (arr.length < 2)\n return arr;\n\n let mid = Math.floor(arr.length / 2);\n let left = arr.slice(0, mid);\n let right = arr.slice(mid);\n\n return merge(mergeSort(left), mergeSort(right));\n}\n\nfunction merge(left, right) {\n let result = [];\n let i = 0;\n let j = 0;\n\n while (i < left.length && j < right.length) {\n if (left[i] < right[j]) {\n result.push(left[i]);\n i++;\n } else {\n result.push(right[j]);\n j++;\n }\n }\n\n return result.concat(left.slice(i)).concat(right.slice(j));\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/ريـاضيات\"؛\n\nاستخدم مـتم؛\n\n\nدالة انحراف_معياري(م: سند[مـصفوفة[صـحيح]]، متوسط: عـائم): عـائم {\n\tعرف حجم: صـحيح = م.هات_الطول()؛\n\tعرف تباين: عـائم = 0؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < حجم ، دليل++ {\n\t\tتباين += (م(دليل) - متوسط) * (م(دليل) - متوسط)؛\n\t}\n\t\n\tارجع ريـاضيات.جذر(تباين / حجم)؛\n}\n"}, {"role": "assistant", "content": "احسب الانحراف المعياري للمصفوفة المعطاة"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة اجتزئ(م: سند[مـصفوفة[صـحيح]]، بداية: صـحيح، نهاية: صـحيح، نتيجة: سند[مـصفوفة[صـحيح]]) {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = بداية ، دليل <= نهاية ، دليل++ {\n\t\tنتيجة.أضف(م(دليل))؛\n\t}\n}\n"}, {"role": "assistant", "content": "اجتزئ مصفوفة معطاة ضمن مجال معطى"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة استبدل(م: سند[مـصفوفة[صـحيح]]، ق1: صـحيح، ق2: صـحيح) {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا م(دليل) == ق1 {\n\t\t\tم(دليل) = ق2؛\n\t\t}\n\t}\n}\n"}, {"role": "assistant", "content": "function replace(arr, oldValue, newValue) {\n for(var i = 0; i < arr.length; i++) {\n if(arr[i] == oldValue) {\n arr[i] = newValue;\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة راكم(م: سند[مـصفوفة[صـحيح]]، د: مغلفة(قيمة_سابقة: صـحيح، قيمة_حالية: صـحيح): صـحيح): مـصفوفة[صـحيح] {\n\tعرف طول: صـحيح = م.هات_الطول()؛\n\tعرف نتيجة: مـصفوفة[صـحيح]؛\n\t\n\tعرف دليل: صـحيح؛\n\tنتيجة.أضف(م(0))؛\n\tلكل دليل = 1 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tنتيجة.أضف(د(نتيجة(دليل - 1)، م(دليل)))؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "راكم المصفوفة المعطاة م باستعمال الدالة المعطاة د و احتفط بكل النتائج الجزئية و أرجعهم"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Math\";\n\nuse Srl;\n\nclass Point {\n def x : Float;\n def y : Float;\n};\n\nfunc triangleArea(p1: Point, p2: Point, p3: Point): Float {\n return Math.abs(p1.x*(p2.y-p3.y) + p2.x*(p3.y-p1.y) + p3.x*(p1.y-p2.y)) / 2.0;\n}\n"}, {"role": "assistant", "content": "#include <stdlib.h>\n\ntypedef struct {\n float x;\n float y;\n} Point;\n\ndouble triangleArea(Point p1, Point p2, Point p3) {\n return abs(p1.x*(p2.y-p3.y) + p2.x*(p3.y-p1.y) + p3.x*(p1.y-p2.y)) / 2.0;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة إلى_حالة_صغيرة(س: سند[نـص]): نـص {\n\tعرف نتيجة: نـص = \"\"؛\n\n\tعرف دليل: صـحيح؛\n\tعرف م: مـحرف؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) >= 'A' && س(دليل) <= 'Z' {\n\t\t\tم = س(دليل) - 'A' + 'a'؛\n\t\t}\n\t\tوإلا {\n\t\t\tم = س(دليل)؛\n\t\t}\n\t\tنتيجة += م؛\n\t}\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "function toLowerCase(s) {\n let result = '';\n for(let i = 0; i < s.length; i++){\n let code = s.charCodeAt(i);\n if(code >= 65 && code <= 90){\n result += String.fromCharCode(code + 32);\n } else {\n result += s[i];\n }\n }\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جد_التقاطع(أ1: عـائم[64]، ب1: عـائم[64]، ج1: عـائم[64]، أ2: عـائم[64]، ب2: عـائم[64]، ج2: عـائم[64]): مـصفوفة[عـائم[64]] {\n\tعرف نتيجة: مـصفوفة[عـائم[64]]؛\n\tإذا أ1 * ب2 - أ2 * ب1 == 0 {\n\t\tارجع نتيجة؛\n\t}\n\t\n\tنتيجة.أضف((ب1*ج2 - ب2*ج1) / (أ1 * ب2 - أ2 * ب1))؛\n\tنتيجة.أضف((أ2*ج1 - أ1*ج2) / (أ1 * ب2 - أ2 * ب1))؛\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "جد نقطة التقاطع لخطين مستقيمين معطيين (الخط المستقيم ممثل بثلاث قيم هي أ، ب، ج كما يلي أ*س + ب*ص + ج = 0) و ارجع هذه النقطة، في حال كان المستقيمان متوازيان ارجع خالٍ أو مصفوفة فارغة"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction accumulate(a, f) {\n let result = [];\n result[0] = a[0];\n for(let i = 1; i < a.length; i++) {\n result[i] = f(result[i-1], a[i]);\n }\n return result;\n}\n"}, {"role": "assistant", "content": "accumulate the given array `a` using the given function `f` and keep the partial results and return them"}]}
{"messages": [{"role": "user", "content": "Using c, write the insertion sort algorithm for a given array"}, {"role": "assistant", "content": "void insertionSort(int arr[], int n) {\n int i, key, j;\n for (i = 1; i < n; i++) {\n key = arr[i];\n j = i - 1;\n\n /* Move elements of arr[0..i-1], that are greater than key,\n to one position ahead of their current position */\n while (j >= 0 && arr[j] > key) {\n arr[j + 1] = arr[j];\n j = j - 1;\n }\n arr[j + 1] = key;\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nuse Srl;\n\nclass Point {\n def x : Int;\n def y : Int;\n};\n\nfunc areCollinear(p1: Point, p2: Point, p3: Point): Bool {\n return (p2.y - p1.y) * (p3.x - p1.x) == (p3.y - p1.y) * (p2.x - p1.x);\n}\n"}, {"role": "assistant", "content": "check if three given points are collinear"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction char_exists(s, c) {\n for (let i = 0; i < s.length; i++) {\n if (s[i] === c) {\n return true;\n }\n }\n return false;\n}\n"}, {"role": "assistant", "content": "import \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc char_exists(s: ref[String], c: Char): Bool {\n def i: Int;\n\tfor i = 0 , i < s.getLength() , i++ {\n\t\tif (s(i) == c) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Array\";\nimport \"Srl/Math\";\n\nuse Srl;\n\n\nfunc dot_product(v1: ref[Array[Float[64]]], v2: ref[Array[Float[64]]]): Float[64] {\n def result: Float[64] = 0;\n\n def i: Int;\n for i = 0 , i < v1.getLength() , i++ {\n result += v1(i) * v2(i);\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "function dot_product(v1, v2) {\n let result = 0;\n for (let i = 0; i < v1.length; i++) {\n result += v1[i] * v2[i];\n }\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, Check if all elements in a given array satisfy a criteria defined by a function with boolean return value"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"closure\";\n\n\nuse Srl;\n\n\nfunc check_all(a: ref[Array[Int]], f: closure (num: Int): Bool): Bool {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if !f(a(i)) {\n return false;\n }\n }\n\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة هل_تباديل(م1: سند[مـصفوفة[صـحيح]]، م2: سند[مـصفوفة[صـحيح]]): ثـنائي {\n\tإذا م1.هات_الطول() != م2.هات_الطول() {\n\t\tارجع خطأ؛\n\t}\n\t\n\tعرف مزار: مـصفوفة[ثـنائي]؛\n\tعرف دليل1: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < م2.هات_الطول() ، دليل1++ {\n\t\tمزار.أضف(خطأ)؛\n\t}\n\t\n\tعرف دليل2: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < م1.هات_الطول() ، دليل1++ {\n\t\tعرف موجود: ثـنائي = خطأ؛\n\t\tلكل دليل2 = 0 ، دليل2 < م2.هات_الطول() ، دليل2++ {\n\t\t\tإذا م1(دليل1) == م2(دليل2) && !مزار(دليل2) {\n\t\t\t\tموجود = صح؛\n\t\t\t\tمزار(دليل2) = صح؛\n\t\t\t\tاقطع؛\n\t\t\t}\n\t\t}\n\t\tإذا !موجود {\n\t\t\tارجع خطأ؛\n\t\t}\n\t}\n\tارجع صح؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc is_permutation(a1: ref[Array[Int]], a2: ref[Array[Int]]): Bool {\n if a1.getLength() != a2.getLength() {\n return false;\n }\n\n def visited: Array[Bool];\n def i: Int;\n for i = 0 , i < a2.getLength() , i++ {\n visited.add(false);\n }\n\n def j: Int;\n for i = 0 , i < a1.getLength() , i++ {\n def found: Bool = false;\n for j = 0 , j < a2.getLength() , j++ {\n if a1(i) == a2(j) && !visited(j) {\n found = true;\n visited(j) = true;\n break;\n }\n }\n if !found {\n return false;\n }\n }\n\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction dfs(node, visited, G) {\n visited[node] = true;\n console.log(node);\n\n for(let i = 0; i < G[node].length; i++) {\n if(!visited[G[node][i]]) {\n dfs(G[node][i], visited, G);\n }\n }\n}\n"}, {"role": "assistant", "content": "Write DFS algorithm for the given graph"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nlet visited = [];\n\nfunction DFS(v, adjList) {\n visited[v] = true;\n for(let i = 0; i < adjList[v].length; i++) {\n if(!visited[adjList[v][i]]) {\n DFS(adjList[v][i], adjList);\n }\n }\n}\n\nfunction numberOfConnectedComponents(adjList) {\n let components = 0;\n for(let i = 0; i < adjList.length; i++) {\n if(!visited[i]) {\n DFS(i, adjList);\n components++;\n }\n }\n return components;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nدالة دفس(عقدة: صـحيح، مزارة: سند[مـصفوفة[ثـنائي]]، بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]) {\n\tمزارة(عقدة) = صح؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان(عقدة).هات_الطول() ، دليل++ {\n\t\tعرف عقدة_ابن: صـحيح = بيان(عقدة)(دليل)؛\n\t\tإذا !مزارة(عقدة_ابن) {\n\t\t\tدفس(عقدة_ابن، مزارة، بيان)؛\n\t\t}\n\t}\n}\n\n\nدالة عدد_المكونات_المترابطة(بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]): صـحيح {\n\tعرف مزارة: مـصفوفة[ثـنائي]؛\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان.هات_الطول() ، دليل++ {\n\t\tمزارة.أضف(خطأ)؛\n\t}\n\t\n\tعرف عدد_المكونات: صـحيح = 0؛\n\tلكل دليل = 0 ، دليل < بيان.هات_الطول() ، دليل++ {\n\t\tإذا !مزارة(دليل) {\n\t\t\tدفس(دليل، مزارة، بيان)؛\n\t\t\tعدد_المكونات++؛\n\t\t}\n\t}\n\t\n\tارجع عدد_المكونات؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\n#include <math.h>\n\ndouble std(int data[], int n, float mean)\n{\n double variance = 0.0;\n\n for(int i=0; i<n; ++i)\n variance += (data[i] - mean) * (data[i] - mean);\n\n return sqrt(variance/n);\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"Srl/Math\";\n\n\nuse Srl;\n\n\nfunc std(a: ref[Array[Int]], mean: Float): Float {\n def size: Int = a.getLength();\n def variance: Float = 0;\n\n def i: Int;\n for i = 0 , i < size , i++ {\n variance += (a(i) - mean) * ( a(i) - mean);\n }\n\n return Math.sqrt(variance / size);\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nlet visited = [];\n\nfunction DFS(v, adjList) {\n visited[v] = true;\n for(let i = 0; i < adjList[v].length; i++) {\n if(!visited[adjList[v][i]]) {\n DFS(adjList[v][i], adjList);\n }\n }\n}\n\nfunction numberOfConnectedComponents(adjList) {\n let components = 0;\n for(let i = 0; i < adjList.length; i++) {\n if(!visited[i]) {\n DFS(i, adjList);\n components++;\n }\n }\n return components;\n}\n"}, {"role": "assistant", "content": "Find the number of connected components in a given undirected graph"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc trim(s: ref[String]) {\n def start: Int = 0;\n def end: Int = s.getLength() - 1;\n\n while (s(start) == ' ' || s(start) == '\\t' || s(start) == '\\n') {\n start++;\n }\n\n while (s(end) == ' ' || s(end) == '\\t' || s(end) == '\\n') {\n end--;\n }\n\n s = s.slice(start, end - start + 1);\n}\n"}, {"role": "assistant", "content": "#include <string.h>\n\nvoid trim(char *str) {\n int start = 0, end = strlen(str) - 1;\n\n // Trim leading white spaces\n while(str[start] == ' ' || str[start] == '\\t' || str[start] == '\\n') start++;\n\n // Trim trailing white spaces\n while(str[end] == ' ' || str[end] == '\\t' || str[end] == '\\n') end--;\n\n // Shift characters\n memmove(str, str + start, end - start + 1);\n\n // Null terminate the string\n str[end - start + 1] = '\\0';\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, احذف عنصرا من موقع معطى ضمن المصفوفة المعطى"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة أزل(م: سند[مـصفوفة[صـحيح]]، موقع: صـحيح) {\n\tعرف حجم: صـحيح = م.هات_الطول()؛\n\n\tعرف دليل: صـحيح؛\n\tلكل دليل = موقع ، دليل < حجم - 1 ، دليل++ {\n\t\tم(دليل) = م(دليل + 1)؛\n\t}\n\tم.أزل(حجم - 1)؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/ريـاضيات\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nصنف نـقطة {\n\tعرف س: عـائم؛\n\tعرف ص: عـائم؛\n}\n\nدالة مساحة_مضلع(رؤوس: سند[مـصفوفة[نـقطة]]): عـائم {\n\tعرف مساحة: عـائم = 0؛\n\tعرف عدد_الرؤوس: صـحيح = رؤوس.هات_الطول()؛\n\tعرف دليل2: صـحيح = عدد_الرؤوس - 1؛\n\t\n\tعرف دليل1: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < عدد_الرؤوس ، دليل1++ {\n\t\tمساحة += (رؤوس(دليل1).س + رؤوس(دليل2).س) * (رؤوس(دليل1).ص - رؤوس(دليل2).ص)؛\n\t\tدليل2 = دليل1؛\n\t}\n\tارجع ريـاضيات.مطلق(مساحة / 2.0)؛\n}\n"}, {"role": "assistant", "content": "#include <stdlib.h>\n\ntypedef struct {\n double x;\n double y;\n} Point;\n\ndouble calculatePolygonArea(Point* vertices, int numVertices) {\n double area = 0.0;\n int j = numVertices - 1;\n\n for (int i = 0; i < numVertices; i++) {\n area += (vertices[j].x + vertices[i].x) * (vertices[j].y - vertices[i].y);\n j = i;\n }\n\n return abs(area / 2.0);\n}\n\n"}]}
{"messages": [{"role": "user", "content": "Using js, Calculate the product of a given matrix, represented as 2D array, and a given scalar, and return the result"}, {"role": "assistant", "content": "function multiply(matrix, scalar) {\n let rows = matrix.length, cols = matrix[0].length;\n let result = new Array(rows);\n\n for (let i = 0; i < rows; i++) {\n result[i] = new Array(cols);\n for (let j = 0; j < cols; j++) {\n result[i][j] = matrix[i][j] * scalar;\n }\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة يبدأ_ب(س: سند[نـص]، سابق: سند[نـص]): ثـنائي {\n\tإذا س.هات_الطول() < سابق.هات_الطول() {\n\t\tارجع خطأ؛\n\t}\n\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < سابق.هات_الطول() ، دليل++ {\n\t\tإذا سابق(دليل) != س(دليل) {\n\t\t\tارجع خطأ؛\n\t\t}\n\t}\n\tارجع صح؛\n}\n"}, {"role": "assistant", "content": "function startsWith(str, prefix) {\n for(let i = 0; i < prefix.length; i++) {\n if(str[i] !== prefix[i])\n return false;\n }\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Math\";\n\nuse Srl;\n\nclass Point {\n def x : Float;\n def y : Float;\n};\n\nfunc triangleArea(p1: Point, p2: Point, p3: Point): Float {\n return Math.abs(p1.x*(p2.y-p3.y) + p2.x*(p3.y-p1.y) + p3.x*(p1.y-p2.y)) / 2.0;\n}\n"}, {"role": "assistant", "content": "calculate and return the area of a triangle from its points"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction startsWith(str, prefix) {\n for(let i = 0; i < prefix.length; i++) {\n if(str[i] !== prefix[i])\n return false;\n }\n return true;\n}\n"}, {"role": "assistant", "content": "import \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc starts_with(s: ref[String], prefix: ref[String]): Bool {\n\tif s.getLength() < prefix.getLength() {\n\t\treturn false;\n\t}\n\n def i: Int;\n\tfor i = 0 , i < prefix.getLength() , i++ {\n\t\tif (prefix(i) != s(i)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, Replace a given char with another given char in a given string and return the new string"}, {"role": "assistant", "content": "import \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc replace(s: ref[String], oldChar: Char, newChar: Char): String {\n def result: String;\n\n def i: Int;\n for i = 0 , i < s.getLength() , i++ {\n if (s(i) == oldChar) {\n result.append(newChar);\n }\n else {\n result.append(s(i));\n }\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nclass Point {\n constructor(x, y) {\n this.x = x;\n this.y = y;\n }\n}\n\nfunction calculateDistance(a, b) {\n return Math.sqrt(Math.pow(b.x - a.x, 2) + Math.pow(b.y - a.y, 2));\n}\n\nfunction findFarthestPoint(givenPoint, points) {\n let maxDistance = 0;\n let farthestPoint;\n \n for(let i = 0; i < points.length; i++) {\n let distance = calculateDistance(givenPoint, points[i]);\n if(distance > maxDistance) {\n maxDistance = distance;\n farthestPoint = points[i];\n }\n }\n \n return farthestPoint;\n}\n"}, {"role": "assistant", "content": "find and return the farthest point to a given point from a given set of points"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\n#include <stdio.h>\n\n#define MAX 100\n\nint visited[MAX];\nint matrix[MAX][MAX];\n\nint DFS(int v, int parent, int n) {\n visited[v] = 1;\n for(int i = 0; i < n; i++) {\n if(matrix[v][i] == 1) {\n if(!visited[i]) {\n if(DFS(i, v, n)) {\n return 1;\n }\n } else if(i != parent) {\n return 1;\n }\n }\n }\n return 0;\n}\n\nint isTree(int n) {\n if(DFS(0, -1, n)) {\n return 0;\n }\n for(int i = 0; i < n; i++) {\n if(!visited[i]) {\n return 0;\n }\n }\n return 1;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nدالة دفس(عقدة: صـحيح، العقدة_الأب: صـحيح، مزارة: سند[مـصفوفة[ثـنائي]]، بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]): ثـنائي {\n\tمزارة(عقدة) = صح؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان(عقدة).هات_الطول() ، دليل++ {\n\t\tعرف عقدة_ابن: صـحيح = بيان(عقدة)(دليل)؛\n\t\tإذا !مزارة(عقدة_ابن) {\n\t\t\tإذا دفس(عقدة_ابن، عقدة، مزارة، بيان) {\n\t\t\t\tارجع صح؛\n\t\t\t}\n\t\t}\n\t\tوإلا إذا عقدة_ابن != العقدة_الأب {\n\t\t\tارجع صح؛\n\t\t}\n\t}\n\tارجع خطأ؛\n}\n\n\nدالة هل_شجرة(بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]): ثـنائي {\n\tعرف مزارة: مـصفوفة[ثـنائي]؛\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان.هات_الطول() ، دليل++ {\n\t\tمزارة.أضف(خطأ)؛\n\t}\n\t\n\tإذا دفس(0، -1، مزارة، بيان) {\n\t\tارجع خطأ؛\n\t}\n\t\n\tعرف عدد_المكونات: صـحيح = 0؛\n\tلكل دليل = 0 ، دليل < بيان.هات_الطول() ، دليل++ {\n\t\tإذا !مزارة(دليل) {\n\t\t\tارجع خطأ؛\n\t\t}\n\t}\n\t\n\tارجع صح؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc rfind(a: ref[Array[Int]], val: Int): Int {\n def i: Int;\n for i = a.getLength() - 1 , i != 0 , i-- {\n if a(i) == val {\n return i;\n }\n }\n return -1;\n}\n"}, {"role": "assistant", "content": "function rfind(a, val) {\n for (let i = a.length - 1; i != 0 ; i--) {\n if (a[i] == val) {\n return i;\n }\n }\n return -1;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction is_digit(c) {\n return (c >= '0' && c <= '9');\n}\n"}, {"role": "assistant", "content": "check if a given character is a digit"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc find_char(s: ref[String], c: Char): Int {\n def i: Int;\n\tfor i = 0 , i < s.getLength() , i++ {\n\t\tif (s(i) == c) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n"}, {"role": "assistant", "content": "int find_char(char s[], int n, char c) {\n for (int i = 0; i < n; i++) {\n if (s[i] == c) {\n return i;\n }\n }\n return -1;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, Read the nth line of a text file given its path and return the result"}, {"role": "assistant", "content": "const fs = require('fs');\nconst readline = require('readline');\n\nfunction read_nth_line(file_path, n) {\n return new Promise((resolve, reject) => {\n const fileStream = fs.createReadStream(file_path);\n\n const rl = readline.createInterface({\n input: fileStream,\n crlfDelay: Infinity\n });\n\n let line_no = 0;\n\n rl.on('line', (line) => {\n line_no++;\n if(line_no === n) {\n resolve(line);\n rl.close();\n }\n });\n\n rl.on('close', () => {\n if(line_no < n) {\n reject(new Error(`The file has less than ${n} lines.`));\n }\n });\n });\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\n#include <stdlib.h>\n\n#define MAX_VALUE 100000\n\nvoid counting_sort(int arr[], int n) {\n int i, j;\n int idx = 0;\n int* count = calloc(MAX_VALUE + 1, sizeof(int));\n\n // Count the occurrence of each number\n for(i = 0; i < n; i++) {\n count[arr[i]]++;\n }\n\n // Reconstruct the sorted array\n for(i = 0; i <= MAX_VALUE; i++) {\n for(j = 0; j < count[i]; j++) {\n arr[idx++] = i;\n }\n }\n\n free(count);\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\n\ndef MAX_VALUE: Int = 100000;\n\nfunc countingSort(a: ref[Array[Int]]) {\n def i: Int;\n def j: Int;\n def idx: Int;\n\n def count: Array[Int];\n for i = 0 , i < MAX_VALUE , i++ {\n count.add(0);\n }\n\n for i = 0 , i < a.getLength() , i++ {\n count(a(i))++;\n }\n\n for i = 0 , i < MAX_VALUE , i++ {\n for j = 0 , j < count(i) , j++ {\n a(idx++) = i;\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة اقتطع(م: سند[مـصفوفة[صـحيح]]، أدنى: صـحيح، أعلى: صـحيح) {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا م(دليل) < أدنى {\n\t\t\tم(دليل) = أدنى؛\n\t\t}\n\t\tوإلا إذا م(دليل) > أعلى {\n\t\t\tم(دليل) = أعلى؛\n\t\t}\n\t}\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc clip(a: ref[Array[Int]], lower: Int, upper: Int) {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if a(i) < lower {\n a(i) = lower;\n }\n else if a(i) > upper {\n a(i) = upper;\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction reduce(a, f) {\n let result = \"\";\n\n for (let i = 0; i < a.length; i++) {\n result = f(result, a[i]);\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/نـص\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة اختصر(م: سند[مـصفوفة[نـص]]، د: مغلفة(قيمة_سابقة: سند[نـص]، قيمة_حالية: سند[نـص])): نـص {\n\tعرف نتيجة: نـص = \"\"؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tد(نتيجة، م(دليل))؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة استبدل(س: سند[نـص]، م1: مـحرف، م2: مـحرف): نـص {\n\tعرف نتيجة: نـص؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) == م1 {\n\t\t\tنتيجة.ألحق(م2)؛\n\t\t}\n\t\tوإلا {\n\t\t\tنتيجة.ألحق(س(دليل))؛\n\t\t}\n\t}\n\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "#include <stdlib.h>\n#include <string.h>\n\nchar* replace(char* str, char oldChar, char newChar) {\n int len = strlen(str);\n char* result = (char*)malloc(sizeof(char) * (len + 1));\n int i;\n\n for(i = 0; i < len; i++) {\n if(str[i] == oldChar) {\n result[i] = newChar;\n } else {\n result[i] = str[i];\n }\n }\n result[i] = '\\0';\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc rfind(a: ref[Array[Int]], val: Int): Int {\n def i: Int;\n for i = a.getLength() - 1 , i != 0 , i-- {\n if a(i) == val {\n return i;\n }\n }\n return -1;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جد_من_الخلف(م: سند[مـصفوفة[صـحيح]]، قيمة: صـحيح): صحيح {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = م.هات_الطول() - 1 ، دليل != 0 ، دليل-- {\n\t\tإذا م(دليل) == قيمة {\n\t\t\tارجع دليل؛\n\t\t}\n\t}\n\tارجع -1؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\n#include <stdio.h>\n#include <stdlib.h>\n\n#define MAX_LINE_LENGTH 1024\n#define MAX_LINES 1000\n\nvoid readFileToArray(char *filename, char lines[MAX_LINES][MAX_LINE_LENGTH]) {\n FILE *file = fopen(filename, \"r\");\n if(file == NULL) {\n printf(\"Cannot open file.\\n\");\n exit(1);\n }\n\n int i = 0, j = 0;\n while(!feof(file) && i < MAX_LINES) {\n fread(&lines[i][j], sizeof(char), 1, file);\n if(lines[i][j] == '\\n' || lines[i][j] == '\\0') {\n lines[i][j] = '\\0'; // end of string\n i++; // next line\n j = 0; // reset character index\n } else {\n j++;\n }\n }\n\n fclose(file);\n}\n"}, {"role": "assistant", "content": "import \"Srl/Fs\";\nimport \"Srl/String\";\nimport \"Srl/Array\";\n\nuse Srl;\n\n\nfunc readFileToArray(file_path: ref[String]): Array[String] {\n def file: ptr[Fs.File] = Fs.openFile(file_path.buf, \"r\");\n def content: Array[String];\n\n Fs.seek(file, 0, Fs.Seek.END);\n def size: Int = Fs.tell(file);\n Fs.seek(file, 0, Fs.Seek.SET);\n \n content.add(String());\n def i: Int;\n def j: Int = 0;\n for i = 0 , i < size , i++ {\n def temp: Char;\n Fs.read(temp~ptr, 1, 1, file);\n\n if temp == '\\n' {\n content.add(String());\n j++;\n }\n else {\n content(j).append(temp);\n }\n }\n\n return content;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, اكتب خوارزمية البحث بالعمق للبيان المعطى"}, {"role": "assistant", "content": "اشمل \"مـتم/طـرفية\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nدالة دفس(عقدة: صـحيح، مزارة: سند[مـصفوفة[ثـنائي]]، بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]) {\n\tمزارة(عقدة) = صح؛\n\tطـرفية.اطبع(\"%d \"، عقدة)؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان(عقدة).هات_الطول() ، دليل++ {\n\t\tعرف عقدة_ابن: صـحيح = بيان(عقدة)(دليل)؛\n\t\tإذا !مزارة(عقدة_ابن) {\n\t\t\tدفس(عقدة_ابن، مزارة، بيان)؛\n\t\t}\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Array\";\n\nuse Srl;\n\n\nfunc max(a: ref[Array[Int]]): Int {\n def result: Int = a(0);\n\n def i: Int;\n for i = 1 , i < a.getLength() , i++ {\n if a(i) > result {\n result = a(i);\n }\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة أكبر_عنصر(م: سند[مـصفوفة[صـحيح]]): صـحيح {\n\n\tعرف نتيجة: صـحيح = م(0)؛\n\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 1 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا م(دليل) > نتيجة {\n\t\t\tنتيجة = م(دليل)؛\n\t\t}\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Array\";\n\nuse Srl;\n\n\ndef MAX_VALUE: Int = 100000;\n\nfunc countingSort(a: ref[Array[Int]]) {\n def i: Int;\n def j: Int;\n def idx: Int;\n\n def count: Array[Int];\n for i = 0 , i < MAX_VALUE , i++ {\n count.add(0);\n }\n\n for i = 0 , i < a.getLength() , i++ {\n count(a(i))++;\n }\n\n for i = 0 , i < MAX_VALUE , i++ {\n for j = 0 , j < count(i) , j++ {\n a(idx++) = i;\n }\n }\n}\n"}, {"role": "assistant", "content": "#include <stdlib.h>\n\n#define MAX_VALUE 100000\n\nvoid counting_sort(int arr[], int n) {\n int i, j;\n int idx = 0;\n int* count = calloc(MAX_VALUE + 1, sizeof(int));\n\n // Count the occurrence of each number\n for(i = 0; i < n; i++) {\n count[arr[i]]++;\n }\n\n // Reconstruct the sorted array\n for(i = 0; i <= MAX_VALUE; i++) {\n for(j = 0; j < count[i]; j++) {\n arr[idx++] = i;\n }\n }\n\n free(count);\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction Point(x, y) {\n this.x = x;\n this.y = y;\n}\n\nfunction triangleArea(p1, p2, p3) {\n return Math.abs(p1.x*(p2.y-p3.y) + p2.x*(p3.y-p1.y) + p3.x*(p1.y-p2.y)) / 2.0;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/ريـاضيات\"؛\n\nاستخدم مـتم؛\n\n\nصنف نـقطة {\n\tعرف س: عـائم؛\n\tعرف ص: عـائم؛\n}\n\nدالة مساحة_مثلث(ن1: نـقطة، ن2: نـقطة، ن3: نـقطة): عـائم {\n\tارجع ريـاضيات.مطلق(ن1.س*(ن2.ص - ن3.ص) + ن2.س*(ن3.ص - ن1.ص) + ن3.س*(ن1.ص - ن2.ص)) / 2.0؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/ريـاضيات\"؛\n\nاستخدم مـتم؛\n\n\nدالة طويلة_شعاع(شعاع: سند[مـصفوفة[عـائم[64]]]): عـائم[64] {\n\tعرف مجموع: عـائم[64] = 0؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < شعاع.هات_الطول() ، دليل++ {\n\t\tمجموع += شعاع(دليل) * شعاع(دليل)؛\n\t}\n\t\n\tارجع ريـاضيات.جذر(مجموع)؛\n}\n"}, {"role": "assistant", "content": "#include <math.h>\n\n\ndouble vectorNorm(double* vector, int size) {\n double sum = 0.0;\n for (int i = 0; i < size; i++) {\n sum += vector[i] * vector[i];\n }\n return sqrt(sum);\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/ريـاضيات\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nصنف نـقطة {\n\tعرف س: عـائم؛\n\tعرف ص: عـائم؛\n}\n\nدالة مساحة_مضلع(رؤوس: سند[مـصفوفة[نـقطة]]): عـائم {\n\tعرف مساحة: عـائم = 0؛\n\tعرف عدد_الرؤوس: صـحيح = رؤوس.هات_الطول()؛\n\tعرف دليل2: صـحيح = عدد_الرؤوس - 1؛\n\t\n\tعرف دليل1: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < عدد_الرؤوس ، دليل1++ {\n\t\tمساحة += (رؤوس(دليل1).س + رؤوس(دليل2).س) * (رؤوس(دليل1).ص - رؤوس(دليل2).ص)؛\n\t\tدليل2 = دليل1؛\n\t}\n\tارجع ريـاضيات.مطلق(مساحة / 2.0)؛\n}\n"}, {"role": "assistant", "content": "function calculatePolygonArea(vertices) {\n let area = 0;\n let j = vertices.length - 1;\n\n for (let i = 0; i < vertices.length; i++) {\n area += (vertices[j].x + vertices[i].x) * (vertices[j].y - vertices[i].y);\n j = i;\n }\n\n return Math.abs(area / 2);\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\n#include <stdio.h>\n#include <stdlib.h>\n\n#define MAX_LINE_LENGTH 1024\n#define MAX_LINES 1000\n\nvoid readFileToArray(char *filename, char lines[MAX_LINES][MAX_LINE_LENGTH]) {\n FILE *file = fopen(filename, \"r\");\n if(file == NULL) {\n printf(\"Cannot open file.\\n\");\n exit(1);\n }\n\n int i = 0, j = 0;\n while(!feof(file) && i < MAX_LINES) {\n fread(&lines[i][j], sizeof(char), 1, file);\n if(lines[i][j] == '\\n' || lines[i][j] == '\\0') {\n lines[i][j] = '\\0'; // end of string\n i++; // next line\n j = 0; // reset character index\n } else {\n j++;\n }\n }\n\n fclose(file);\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/نـم\"؛\nاشمل \"مـتم/نـص\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة اقرأ_الملف_إلى_مصفوفة(مسار_الملف: سند[نـص]): مـصفوفة[نـص] {\n\tعرف ملف: مؤشر[نـم.مـلف] = نـم.افتح_ملف(مسار_الملف، \"r\")؛\n\tعرف المحتوى: مـصفوفة[نـص]؛\n\n\tنـم.انتقل(ملف، 0، نـم.انـتقال._نهاية_)؛\n\tعرف حجم: صـحيح = نـم.هات_الموقع(ملف)؛\n\tنـم.انتقل(ملف، 0، نـم.انـتقال._بداية_)؛\n\t\n\tالمحتوى.أضف(نـص())؛\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح = 0؛\n\tلكل دليل1 = 0 ، دليل1 < حجم ، دليل1++ {\n\t\tعرف مؤقت: مـحرف؛\n\t\tنـم.اقرأ(مؤقت~مؤشر، 1، 1، ملف)؛\n\t\t\n\t\tإذا مؤقت == '\\n' {\n\t\t\tالمحتوى.أضف(نـص())؛\n\t\t\tدليل2++؛\n\t\t}\n\t\tوإلا {\n\t\t\tالمحتوى(دليل2).ألحق(مؤقت)؛\n\t\t}\n\t}\n\t\n\tارجع المحتوى؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\nvoid toLowerCase(char *s, char *result) {\n for(int i = 0; s[i]; i++){\n if(s[i] >= 'A' && s[i] <= 'Z'){\n result[i] = s[i] - 'A' + 'a';\n }\n else {\n result[i] = s[i];\n }\n }\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة إلى_حالة_صغيرة(س: سند[نـص]): نـص {\n\tعرف نتيجة: نـص = \"\"؛\n\n\tعرف دليل: صـحيح؛\n\tعرف م: مـحرف؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) >= 'A' && س(دليل) <= 'Z' {\n\t\t\tم = س(دليل) - 'A' + 'a'؛\n\t\t}\n\t\tوإلا {\n\t\t\tم = س(دليل)؛\n\t\t}\n\t\tنتيجة += م؛\n\t}\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nدالة دفس(عقدة: صـحيح، العقدة_الأب: صـحيح، مزارة: سند[مـصفوفة[ثـنائي]]، بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]): ثـنائي {\n\tمزارة(عقدة) = صح؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان(عقدة).هات_الطول() ، دليل++ {\n\t\tعرف عقدة_ابن: صـحيح = بيان(عقدة)(دليل)؛\n\t\tإذا !مزارة(عقدة_ابن) {\n\t\t\tإذا دفس(عقدة_ابن، عقدة، مزارة، بيان) {\n\t\t\t\tارجع صح؛\n\t\t\t}\n\t\t}\n\t\tوإلا إذا عقدة_ابن != العقدة_الأب {\n\t\t\tارجع صح؛\n\t\t}\n\t}\n\tارجع خطأ؛\n}\n\n\nدالة هل_شجرة(بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]): ثـنائي {\n\tعرف مزارة: مـصفوفة[ثـنائي]؛\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان.هات_الطول() ، دليل++ {\n\t\tمزارة.أضف(خطأ)؛\n\t}\n\t\n\tإذا دفس(0، -1، مزارة، بيان) {\n\t\tارجع خطأ؛\n\t}\n\t\n\tعرف عدد_المكونات: صـحيح = 0؛\n\tلكل دليل = 0 ، دليل < بيان.هات_الطول() ، دليل++ {\n\t\tإذا !مزارة(دليل) {\n\t\t\tارجع خطأ؛\n\t\t}\n\t}\n\t\n\tارجع صح؛\n}\n"}, {"role": "assistant", "content": "تحقق فيما إذا كان بيان غير موجه معطى يمثل شجرة"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc find_diff_index(a1: ref[Array[Int]], a2: ref[Array[Int]]): Int {\n def i: Int;\n for i = 0 , i < a1.getLength() , i++ {\n if a1(i) != a2(i) {\n return i;\n }\n }\n return -1;\n}\n"}, {"role": "assistant", "content": "int find_diff_index(int arr1[], int arr2[], int n) {\n int i;\n for(i = 0; i < n; i++) {\n if(arr1[i] != arr2[i]) {\n return i;\n }\n }\n return -1; // return -1 if no difference is found\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, Delete an element at a given position in the given array"}, {"role": "assistant", "content": "function erase(a, n, pos) {\n // Shift elements to left\n for (let i = pos; i < n - 1; i++)\n a[i] = a[i + 1];\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\n#include <stdlib.h>\n\nint** multiply(int** a, int scalar, int rows, int cols) {\n int i, j;\n // Create a result matrix dynamically\n int** result = (int**)malloc(rows * sizeof(int*));\n for(i = 0; i < rows; i++) {\n result[i] = (int*)malloc(cols * sizeof(int));\n }\n\n // Multiply the matrix by the scalar\n for(i = 0; i < rows; i++) {\n for(j = 0; j < cols; j++) {\n result[i][j] = a[i][j] * scalar;\n }\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\ndef Matrix: alias Array[Array[Float[64]]];\n\n\nfunc multiply(m: ref[Matrix], s: Float[64]): Matrix {\n def rows: Int = m.getLength();\n def cols: Int = m(0).getLength();\n \n def result: Matrix;\n\n def i: Int;\n def j: Int;\n for i = 0 , i < rows , i++ {\n result.add(Array[Float[64]]());\n for j = 0 , j < cols , j++ {\n result(i).add(m(i)(j)*s);\n }\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة اجتزئ(س: سند[نـص]، بداية: صـحيح، نهاية: صـحيح): نـص {\n\tعرف نتيجة: نـص = \"\"؛\n\n\tعرف دليل: صـحيح؛\n\tلكل دليل = بداية ، دليل <= نهاية ، دليل++ {\n\t\tنتيجة.ألحق(س(دليل))؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "function slice_string(str, start, end) {\n var result = \"\";\n for(var i = start; i <= end; i++) {\n result += str[i];\n }\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction findIntersection(a1, b1, c1, a2, b2, c2) {\n // Check if the lines are parallel\n if(a1*b2 - a2*b1 === 0) {\n return null;\n }\n\n let result = [];\n result[0] = (b1*c2 - b2*c1) / (a1*b2 - a2*b1);\n result[1] = (a2*c1 - a1*c2) / (a1*b2 - a2*b1);\n return result;\n}\n"}, {"role": "assistant", "content": "Find the intersection point of two given lines (the line represented by three values `a`, `b`, `c` as ax + by + c = 0) and return it, in case of parallel line return null or empty array"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Array\";\n\nuse Srl;\n\ndef Matrix: alias Array[Array[Float[64]]];\ndef Vector: alias Array[Float[64]];\n\n\nfunc multiply(m: ref[Matrix], v: ref[Vector]): Vector {\n def rows: Int = m.getLength();\n def cols: Int = m(0).getLength();\n \n def result: Vector;\n\n def i: Int;\n def j: Int;\n for i = 0 , i < rows , i++ {\n result.add(0);\n for j = 0 , j < cols , j++ {\n result(i) += m(i)(j) * v(j);\n }\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "function multiply(matrix, vector) {\n let rows = matrix.length, cols = matrix[0].length;\n let result = new Array(rows);\n\n for (let i = 0; i < rows; i++) {\n result[i] = 0;\n for (let j = 0; j < cols; j++) {\n result[i] += matrix[i][j] * vector[j];\n }\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\n#define V 4\n\nvoid floydWarshall (int graph[V][V], int dist[V][V]) \n{ \n int i, j, k; \n \n for (i = 0; i < V; i++) \n for (j = 0; j < V; j++) \n dist[i][j] = graph[i][j]; \n \n for (k = 0; k < V; k++) \n { \n for (i = 0; i < V; i++) \n { \n for (j = 0; j < V; j++) \n { \n if (dist[i][k] + dist[k][j] < dist[i][j]) \n dist[i][j] = dist[i][k] + dist[k][j]; \n } \n } \n }\n} \n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\nfunc floydWarshall(graph: ref[Array[Array[Int]]], dist: ref[Array[Array[Int]]]) {\n def n: Int = graph.getLength();\n def i: Int;\n def j: Int;\n def k: Int;\n\n for i = 0 , i < n , i++ {\n dist.add(graph(i));\n }\n\n for k = 0 , k < n , k++ {\n for i = 0 , i < n , i++ {\n for j = 0 , j < n , j++ {\n if dist(i)(k) + dist(k)(j) < dist(i)(j) {\n dist(i)(j) = dist(i)(k) + dist(k)(j);\n }\n }\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Array\";\n\nuse Srl;\n\ndef Matrix: alias Array[Array[Float[64]]];\ndef Vector: alias Array[Float[64]];\n\n\nfunc multiply(m: ref[Matrix], v: ref[Vector]): Vector {\n def rows: Int = m.getLength();\n def cols: Int = m(0).getLength();\n \n def result: Vector;\n\n def i: Int;\n def j: Int;\n for i = 0 , i < rows , i++ {\n result.add(0);\n for j = 0 , j < cols , j++ {\n result(i) += m(i)(j) * v(j);\n }\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nعرف مـصفوفة_ثنائية: لقب مـصفوفة[مـصفوفة[عـائم[64]]]؛\nعرف شـعاع: لقب مـصفوفة[عـائم[64]]؛\n\n\nدالة جداء(م: سند[مـصفوفة_ثنائية]، ش: سند[شـعاع]): شـعاع {\n\tعرف أسطر: صـحيح = م.هات_الطول()؛\n\tعرف أعمدة: صـحيح = م(0).هات_الطول()؛\n\n\tعرف نتيجة: شـعاع؛\n\t\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < أسطر ، دليل1++ {\n\t\tنتيجة.أضف(0)؛\n\t\tلكل دليل2 = 0 ، دليل2 < أعمدة ، دليل2++ {\n\t\t\t\tنتيجة(دليل1) += م(دليل1)(دليل2) * ش(دليل2)؛\n\t\t}\n\t}\n\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\n#include <math.h>\n\n\ndouble vectorNorm(double* vector, int size) {\n double sum = 0.0;\n for (int i = 0; i < size; i++) {\n sum += vector[i] * vector[i];\n }\n return sqrt(sum);\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/ريـاضيات\"؛\n\nاستخدم مـتم؛\n\n\nدالة طويلة_شعاع(شعاع: سند[مـصفوفة[عـائم[64]]]): عـائم[64] {\n\tعرف مجموع: عـائم[64] = 0؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < شعاع.هات_الطول() ، دليل++ {\n\t\tمجموع += شعاع(دليل) * شعاع(دليل)؛\n\t}\n\t\n\tارجع ريـاضيات.جذر(مجموع)؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\n#include <stdlib.h>\n\ntypedef struct {\n float x;\n float y;\n} Point;\n\ndouble triangleArea(Point p1, Point p2, Point p3) {\n return abs(p1.x*(p2.y-p3.y) + p2.x*(p3.y-p1.y) + p3.x*(p1.y-p2.y)) / 2.0;\n}\n"}, {"role": "assistant", "content": "calculate and return the area of a triangle from its points"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Fs\";\nimport \"Srl/String\";\n\nuse Srl;\n\n\nfunc read_nth_line(file_path: ref[String], n: Int): String {\n def file: ptr[Fs.File] = Fs.openFile(file_path.buf, \"r\");\n\n def i: Int;\n def temp: Char = ' ';\n for i = 0 , i < n - 1 , i++ {\n temp = ' ';\n while temp != '\\n' {\n Fs.read(temp~ptr, 1, 1, file);\n }\n }\n\n def nth_line: String;\n temp = ' ';\n while temp != '\\n' {\n Fs.read(temp~ptr, 1, 1, file);\n nth_line.append(temp);\n }\n\n return nth_line;\n}\n"}, {"role": "assistant", "content": "Read the nth line of a text file given its path and return the result"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nعرف مـصفوفة_ثنائية: لقب مـصفوفة[مـصفوفة[عـائم[64]]]؛\n\n\nدالة جداء(م: سند[مـصفوفة_ثنائية]، س: عـائم[64]): مـصفوفة_ثنائية {\n\tعرف أسطر: صـحيح = م.هات_الطول()؛\n\tعرف أعمدة: صـحيح = م(0).هات_الطول()؛\n\n\tعرف نتيجة: مـصفوفة_ثنائية؛\n\t\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < أسطر ، دليل1++ {\n\t\tنتيجة.أضف(مـصفوفة[عـائم[64]]())؛\n\t\tلكل دليل2 = 0 ، دليل2 < أعمدة ، دليل2++ {\n\t\t\t\tنتيجة(دليل1).أضف(م(دليل1)(دليل2)*س)؛\n\t\t}\n\t}\n\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "#include <stdlib.h>\n\nint** multiply(int** a, int scalar, int rows, int cols) {\n int i, j;\n // Create a result matrix dynamically\n int** result = (int**)malloc(rows * sizeof(int*));\n for(i = 0; i < rows; i++) {\n result[i] = (int*)malloc(cols * sizeof(int));\n }\n\n // Multiply the matrix by the scalar\n for(i = 0; i < rows; i++) {\n for(j = 0; j < cols; j++) {\n result[i][j] = a[i][j] * scalar;\n }\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\n#include <stdio.h>\n\nvoid printArray(int a[], int size) {\n int i;\n for(i = 0; i < size; i++) {\n printf(\"%d \", a[i]);\n }\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"Srl/Console\";\n\n\nuse Srl;\n\n\nfunc print(a: ref[Array[Int]]) {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n Console.print(\"%d \", a(i));\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nعرف قيمة_عظمى: صـحيح = 100000؛\n\nدالة الترتيب_بالعد(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tعرف دليل: صـحيح؛\n\t\n\tعرف عداد: مـصفوفة[صـحيح]؛\n\tلكل دليل1 = 0 ، دليل1 < قيمة_عظمى ، دليل1++ {\n\t\tعداد.أضف(0)؛\n\t}\n\t\n\tلكل دليل1 = 0 ، دليل1 < م.هات_الطول() ، دليل1++ {\n\t\tعداد(م(دليل1))++؛\n\t}\n\t\n\tلكل دليل1 = 0 ، دليل1 < قيمة_عظمى ، دليل1++ {\n\t\tلكل دليل2 = 0 ، دليل2 < عداد(دليل1) ، دليل2++ {\n\t\t\tم(دليل++) = دليل1؛\n\t\t}\n\t}\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\n\ndef MAX_VALUE: Int = 100000;\n\nfunc countingSort(a: ref[Array[Int]]) {\n def i: Int;\n def j: Int;\n def idx: Int;\n\n def count: Array[Int];\n for i = 0 , i < MAX_VALUE , i++ {\n count.add(0);\n }\n\n for i = 0 , i < a.getLength() , i++ {\n count(a(i))++;\n }\n\n for i = 0 , i < MAX_VALUE , i++ {\n for j = 0 , j < count(i) , j++ {\n a(idx++) = i;\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة إلى_حالة_كبيرة(س: سند[نـص]): نـص {\n\tعرف نتيجة: نـص = \"\"؛\n\n\tعرف دليل: صـحيح؛\n\tعرف م: مـحرف؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) >= 'a' && س(دليل) <= 'z' {\n\t\t\tم = س(دليل) - 'a' + 'A'؛\n\t\t}\n\t\tوإلا {\n\t\t\tم = س(دليل)؛\n\t\t}\n\t\tنتيجة += م؛\n\t}\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc toUpperCase(s: ref[String]): String {\n\tdef result: String = \"\";\n def i: Int;\n\tdef c: Char;\n\tfor i = 0 , i < s.getLength() , i++ {\n\t\tif (s(i) >= 'a' && s(i) <= 'z') {\n\t\t\tc = s(i) - 'a' + 'A';\n\t\t}\n\t\telse {\n\t\t\tc = s(i);\n\t\t}\n\t\tresult += c;\n\t}\n\treturn result;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, accumulate the given array `a` using the given function `f` and keep the partial results and return them"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"closure\";\n\n\nuse Srl;\n\n\nfunc accumulate(a: ref[Array[Int]], f: closure (previousValue: Int, currentValue: Int): Int): Array[Int] {\n def size: Int = a.getLength();\n def result: Array[Int];\n\n def i: Int;\n result.add(a(0));\n for i = 1 , i < a.getLength() , i++ {\n result.add(f(result(i-1), a(i)));\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, find and return the most frequent item in a given array"}, {"role": "assistant", "content": "int find_most_frequent(int arr[], int n) {\n int max_count = 0, res = -1;\n\n for (int i = 0; i < n; i++) {\n int count = 1;\n for (int j = i + 1; j < n; j++)\n if (arr[i] == arr[j])\n count++;\n if (count > max_count) {\n max_count = count;\n res = arr[i];\n }\n }\n\n return res;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc rfind(a: ref[Array[Int]], val: Int): Int {\n def i: Int;\n for i = a.getLength() - 1 , i != 0 , i-- {\n if a(i) == val {\n return i;\n }\n }\n return -1;\n}\n"}, {"role": "assistant", "content": "Find and return the position of a given element in the given array starting from its end"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة دور(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف حجم: صـحيح = م.هات_الطول()؛\n\t\n\tعرف أول_عنصر: صـحيح = م(0)؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < حجم - 1 ، دليل++ {\n\t\tم(دليل) = م(دليل + 1)؛\n\t}\n\t\n\tم(حجم - 1) = أول_عنصر؛\n}\n"}, {"role": "assistant", "content": "دور المصفوفة المعطاة بعكس اتجاه عقارب الساعة و أرجع النتيجة"}]}
{"messages": [{"role": "user", "content": "What this code do?\n#include <stdbool.h>\n\nvoid filter(int a[], int size, int result[], int *newSize, bool (*condition)(int)) {\n *newSize = 0;\n for (int i = 0; i < size; i++) {\n if (condition(a[i])) {\n result[(*newSize)++] = a[i];\n }\n }\n}\n"}, {"role": "assistant", "content": "filter the given array based on the given function `f` and return the result"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة جد_المحرف(س: سند[نـص]، م: مـحرف): صـحيح {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) == م {\n\t\t\tارجع دليل؛\n\t\t}\n\t}\n\tارجع -1؛\n}\n"}, {"role": "assistant", "content": "جد و أرجع موقع محرف معطى ضمن سلسلة نصية معطاة"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة أكبر_عنصر(م: سند[مـصفوفة[صـحيح]]): صـحيح {\n\n\tعرف نتيجة: صـحيح = م(0)؛\n\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 1 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا م(دليل) > نتيجة {\n\t\t\tنتيجة = م(دليل)؛\n\t\t}\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "جد و أرجع أكبر عدد في المصفوفة المعطاة م"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc replace(a: ref[Array[Int]], oldValue: Int, newValue: Int) {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if a(i) == oldValue {\n a(i) = newValue;\n }\n }\n}\n"}, {"role": "assistant", "content": "void replace(int* arr, int len, int oldValue, int newValue) {\n for(int i = 0; i < len; i++) {\n if(arr[i] == oldValue) {\n arr[i] = newValue;\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, Find the first index at which the two given arrays differ, return -1 if not found"}, {"role": "assistant", "content": "int find_diff_index(int arr1[], int arr2[], int n) {\n int i;\n for(i = 0; i < n; i++) {\n if(arr1[i] != arr2[i]) {\n return i;\n }\n }\n return -1; // return -1 if no difference is found\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, write the insertion sort algorithm for a given array"}, {"role": "assistant", "content": "function insertionSort(arr) {\n let n = arr.length;\n for (let i = 1; i < n; i++) {\n let key = arr[i];\n let j = i - 1;\n\n /* Move elements of arr[0..i-1], that are greater than key,\n to one position ahead of their current position */\n while (j >= 0 && arr[j] > key) {\n arr[j + 1] = arr[j];\n j = j - 1;\n }\n arr[j + 1] = key;\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Array\";\n\nuse Srl;\n\nfunc floydWarshall(graph: ref[Array[Array[Int]]], dist: ref[Array[Array[Int]]]) {\n def n: Int = graph.getLength();\n def i: Int;\n def j: Int;\n def k: Int;\n\n for i = 0 , i < n , i++ {\n dist.add(graph(i));\n }\n\n for k = 0 , k < n , k++ {\n for i = 0 , i < n , i++ {\n for j = 0 , j < n , j++ {\n if dist(i)(k) + dist(k)(j) < dist(i)(j) {\n dist(i)(j) = dist(i)(k) + dist(k)(j);\n }\n }\n }\n }\n}\n"}, {"role": "assistant", "content": "#define V 4\n\nvoid floydWarshall (int graph[V][V], int dist[V][V]) \n{ \n int i, j, k; \n \n for (i = 0; i < V; i++) \n for (j = 0; j < V; j++) \n dist[i][j] = graph[i][j]; \n \n for (k = 0; k < V; k++) \n { \n for (i = 0; i < V; i++) \n { \n for (j = 0; j < V; j++) \n { \n if (dist[i][k] + dist[k][j] < dist[i][j]) \n dist[i][j] = dist[i][k] + dist[k][j]; \n } \n } \n }\n} \n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\nvoid dfs(int node, int visited[], int G[][N]) {\n visited[node] = 1;\n printf(\"%d \", node);\n\n for(int i = 0; i < N; i++) {\n if(G[node][i] == 1 && visited[i] == 0) {\n dfs(i, visited, G);\n }\n }\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"Srl/Console\";\n\nuse Srl;\n\nfunc dfs(node: Int, visited: ref[Array[Bool]], graph: ref[Array[Array[Int]]]) {\n visited(node) = true;\n Console.print(\"%d \", node);\n\n def i: Int;\n for i = 0 , i < graph(node).getLength(), i++ {\n def childNode: Int = graph(node)(i);\n if !visited(childNode) {\n dfs(childNode, visited, graph);\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\nvoid accumulate(int* a, int* result, int size, int (*f)(int, int)) {\n result[0] = a[0];\n for(int i = 1; i < size; i++) {\n result[i] = f(result[i-1], a[i]);\n }\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة راكم(م: سند[مـصفوفة[صـحيح]]، د: مغلفة(قيمة_سابقة: صـحيح، قيمة_حالية: صـحيح): صـحيح): مـصفوفة[صـحيح] {\n\tعرف طول: صـحيح = م.هات_الطول()؛\n\tعرف نتيجة: مـصفوفة[صـحيح]؛\n\t\n\tعرف دليل: صـحيح؛\n\tنتيجة.أضف(م(0))؛\n\tلكل دليل = 1 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tنتيجة.أضف(د(نتيجة(دليل - 1)، م(دليل)))؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, Invert the given string `s` and return the result"}, {"role": "assistant", "content": "function invert_string(str) {\n return str.split('').reverse().join('');\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction mergeSort(arr) {\n if (arr.length < 2)\n return arr;\n\n let mid = Math.floor(arr.length / 2);\n let left = arr.slice(0, mid);\n let right = arr.slice(mid);\n\n return merge(mergeSort(left), mergeSort(right));\n}\n\nfunction merge(left, right) {\n let result = [];\n let i = 0;\n let j = 0;\n\n while (i < left.length && j < right.length) {\n if (left[i] < right[j]) {\n result.push(left[i]);\n i++;\n } else {\n result.push(right[j]);\n j++;\n }\n }\n\n return result.concat(left.slice(i)).concat(right.slice(j));\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة ادمج(م: سند[مـصفوفة[صـحيح]]، يسار: صـحيح، وسط: صـحيح، يمين: صـحيح) {\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tعرف دليل3: صـحيح؛\n\t\n\tعرف حجم1: صـحيح = وسط - يسار + 1؛\n\tعرف حجم2: صـحيح = يمين - وسط؛\n\t\n\tعرف م_يسار: مـصفوفة[صـحيح]؛\n\tعرف م_يمين: مـصفوفة[صـحيح]؛\n\t\n\tلكل دليل1 = 0 ، دليل1 < حجم1 ، دليل1++ {\n\t\tم_يسار.أضف(م(يسار+دليل1))؛\n\t}\n\tلكل دليل1 = 0 ، دليل1 < حجم2 ، دليل1++ {\n\t\tم_يمين.أضف(م(وسط + 1 + دليل1))؛\n\t}\n\t\n\tدليل1 = 0؛\n\tدليل2 = 0؛\n\tدليل3 = يسار؛\n\t\n\tبينما دليل1 < حجم1 && دليل2 < حجم2 {\n\t\tإذا م_يسار(دليل1) <= م_يمين(دليل2) {\n\t\t\tم(دليل3) = م_يسار(دليل1)؛\n\t\t\tدليل1++؛\n\t\t}\n\t\tوإلا {\n\t\t\tم(دليل3) = م_يمين(دليل2)؛\n\t\t\tدليل2++؛\n\t\t}\n\t\tدليل3++؛\n\t}\n\t\n\tبينما دليل1 < حجم1 {\n\t\tم(دليل3) = م_يسار(دليل1)؛\n\t\tدليل1++؛\n\t\tدليل3++؛\n\t}\n\t\n\tبينما دليل2 < حجم2 {\n\t\tم(دليل3) = م_يمين(دليل2)؛\n\t\tدليل2++؛\n\t\tدليل3++؛\n\t}\n}\n\n\nدالة ترتيب_بالدمج(م: سند[مـصفوفة[صـحيح]]، يسار: صـحيح، يمين: صـحيح) {\n\tإذا يسار < يمين {\n\t\tعرف وسط: صـحيح = يسار + (يمين - يسار) / 2؛\n\t\t\n\t\tترتيب_بالدمج(م، يسار، وسط)؛\n\t\tترتيب_بالدمج(م، وسط + 1، يمين)؛\n\t\t\n\t\tادمج(م، يسار، وسط، يمين)؛\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\n#include <string.h>\n\nvoid invert_string(char* str) {\n int len = strlen(str);\n for(int i = 0; i < len / 2; i++) {\n char temp = str[i];\n str[i] = str[len - i - 1];\n str[len - i - 1] = temp;\n }\n}\n"}, {"role": "assistant", "content": "Invert the given string `s` and return the result"}]}
{"messages": [{"role": "user", "content": "Using c, Check whether a given array is a permutation for another given array"}, {"role": "assistant", "content": "#include <stdbool.h>\n\n// Function to check if arr2 is a permutation of arr1\nbool is_permutation(int arr1[], int size1, int arr2[], int size2) {\n // If sizes are not equal, return false\n if(size1 != size2) {\n return false;\n }\n\n // Create an array to keep track of visited elements\n bool visited[size2];\n for(int i = 0; i < size2; i++) {\n visited[i] = false;\n }\n\n // For each element in arr1\n for(int i = 0; i < size1; i++) {\n bool found = false;\n\n // For each element in arr2\n for(int j = 0; j < size2; j++) {\n // If the element in arr1 is found in arr2 and it has not been visited\n if(arr1[i] == arr2[j] && !visited[j]) {\n found = true;\n visited[j] = true; // Mark the element in arr2 as visited\n break;\n }\n }\n\n // If the element in arr1 is not found in arr2, return false\n if(!found) {\n return false;\n }\n }\n\n // If we reach here, then arr2 is a permutation of arr1\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Array\";\n\nuse Srl;\n\nfunc findIntersection(a1: Float[64], b1: Float[64], c1: Float[64], a2: Float[64], b2: Float[64], c2: Float[64]): Array[Float[64]] {\n def result: Array[Float[64]];\n if a1*b2 - a2*b1 == 0 {\n return result;\n }\n\n result.add((b1*c2 - b2*c1) / (a1*b2 - a2*b1));\n result.add((a2*c1 - a1*c2) / (a1*b2 - a2*b1));\n\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جد_التقاطع(أ1: عـائم[64]، ب1: عـائم[64]، ج1: عـائم[64]، أ2: عـائم[64]، ب2: عـائم[64]، ج2: عـائم[64]): مـصفوفة[عـائم[64]] {\n\tعرف نتيجة: مـصفوفة[عـائم[64]]؛\n\tإذا أ1 * ب2 - أ2 * ب1 == 0 {\n\t\tارجع نتيجة؛\n\t}\n\t\n\tنتيجة.أضف((ب1*ج2 - ب2*ج1) / (أ1 * ب2 - أ2 * ب1))؛\n\tنتيجة.أضف((أ2*ج1 - أ1*ج2) / (أ1 * ب2 - أ2 * ب1))؛\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/ريـاضيات\"؛\n\nاستخدم مـتم؛\n\n\nصنف نـقطة {\n\tعرف س: عـائم؛\n\tعرف ص: عـائم؛\n}\n\nدالة مساحة_مثلث(ن1: نـقطة، ن2: نـقطة، ن3: نـقطة): عـائم {\n\tارجع ريـاضيات.مطلق(ن1.س*(ن2.ص - ن3.ص) + ن2.س*(ن3.ص - ن1.ص) + ن3.س*(ن1.ص - ن2.ص)) / 2.0؛\n}\n"}, {"role": "assistant", "content": "احسب و أرجع مساحة مثلت من إحداثيات نقاطه"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Array\";\nimport \"closure\";\n\n\nuse Srl;\n\n\nfunc check_all(a: ref[Array[Int]], f: closure (num: Int): Bool): Bool {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if !f(a(i)) {\n return false;\n }\n }\n\n return true;\n}\n"}, {"role": "assistant", "content": "Check if all elements in a given array satisfy a criteria defined by a function with boolean return value"}]}
{"messages": [{"role": "user", "content": "Using js, apply the given function `f` on each element of the given array `a` and return the result"}, {"role": "assistant", "content": "function accumulate(a, f) {\n for (let i = 0 ; i < a.length ; i++) {\n a[i] = f(a[i]);\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\nvoid slice(int arr[], int start, int end, int result[]) {\n int i;\n for(i = start; i <= end; i++) {\n result[i - start] = arr[i];\n }\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc slice(a: ref[Array[Int]], start: Int, end: Int, result: ref[Array[Int]]) {\n def i: Int;\n for i = start , i <= end , i++ {\n result.add(a(i));\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة دور(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف حجم: صـحيح = م.هات_الطول()؛\n\t\n\tعرف أول_عنصر: صـحيح = م(0)؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < حجم - 1 ، دليل++ {\n\t\tم(دليل) = م(دليل + 1)؛\n\t}\n\t\n\tم(حجم - 1) = أول_عنصر؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc rotate(a: ref[Array[Int]]) {\n def size: Int = a.getLength();\n\n def first_element: Int = a(0);\n\n def i: Int;\n for i = 0 , i < size - 1 , i++ {\n a(i) = a(i + 1);\n }\n\n a(size - 1) = first_element;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة إلى_حالة_كبيرة(س: سند[نـص]): نـص {\n\tعرف نتيجة: نـص = \"\"؛\n\n\tعرف دليل: صـحيح؛\n\tعرف م: مـحرف؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) >= 'a' && س(دليل) <= 'z' {\n\t\t\tم = س(دليل) - 'a' + 'A'؛\n\t\t}\n\t\tوإلا {\n\t\t\tم = س(دليل)؛\n\t\t}\n\t\tنتيجة += م؛\n\t}\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "function toUpperCase(s) {\n let result = '';\n for(let i = 0; i < s.length; i++){\n let code = s.charCodeAt(i);\n if(code >= 97 && code <= 122){\n result += String.fromCharCode(code - 97 + 65);\n } else {\n result += s[i];\n }\n }\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nعرف مـصفوفة_ثنائية: لقب مـصفوفة[مـصفوفة[عـائم[64]]]؛\n\n\nدالة جداء(م1: سند[مـصفوفة_ثنائية]، م2: سند[مـصفوفة_ثنائية]): مـصفوفة_ثنائية {\n\tعرف أسطر_م1: صـحيح = م1.هات_الطول()؛\n\tعرف أسطر_م2: صـحيح = م2.هات_الطول()؛\n\tعرف أعمدة_م1: صـحيح = م1(0).هات_الطول()؛\n\tعرف أعمدة_م2: صـحيح = م2(0).هات_الطول()؛\n\n\tعرف نتيجة: مـصفوفة_ثنائية؛\n\t\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tعرف دليل3: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < أسطر_م1 ، دليل1++ {\n\t\tعرف سطر: مـصفوفة[عـائم[64]]؛\n\t\tلكل دليل2 = 0 ، دليل2 < أعمدة_م2 ، دليل2++ {\n\t\t\tسطر.أضف(0)؛\n\t\t\tلكل دليل3 = 0 ، دليل3 < أعمدة_م1 ، دليل3++ {\n\t\t\t\tسطر(دليل2) += م1(دليل1)(دليل3) * م2(دليل3)(دليل2)؛\n\t\t\t}\n\t\t}\n\t\tنتيجة.أضف(سطر)؛\n\t}\n\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\ndef Matrix: alias Array[Array[Float[64]]];\n\nfunc multiply(a: ref[Matrix], b: ref[Matrix]): Matrix {\n def rowsA: Int = a.getLength();\n def rowsB: Int = b.getLength();\n def colsA: Int = a(0).getLength();\n def colsB: Int = b(0).getLength();\n \n def result: Matrix;\n\n def i: Int;\n def j: Int;\n def k: Int;\n for i = 0 , i < rowsA , i++ {\n def row: Array[Float[64]];\n for j = 0 , j < colsB , j++ {\n row.add(0);\n for k = 0 , k < colsA , k++ {\n row(j) += a(i)(k) * b(k)(j);\n }\n }\n result.add(row);\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction dot_product(v1, v2) {\n let result = 0;\n for (let i = 0; i < v1.length; i++) {\n result += v1[i] * v2[i];\n }\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/ريـاضيات\"؛\n\nاستخدم مـتم؛\n\n\nدالة جداء_نقطي(شعاع1: سند[مـصفوفة[عـائم[64]]]، شعاع2: سند[مـصفوفة[عـائم[64]]]): عـائم[64] {\n\tعرف نتيجة: عـائم[64] = 0؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < شعاع1.هات_الطول() ، دليل++ {\n\t\tنتيجة += شعاع1(دليل) * شعاع2(دليل)؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction sum(a) {\n let result = 0;\n\n for (let i = 0; i < a.length; i++) {\n result += a[i];\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\nfunc sum(a: ref[Array[Int]]): Int {\n def sum: Int = 0;\n\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n sum += a(i);\n }\n\n return sum;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction selectionSort(arr) {\n let n = arr.length;\n\n for(let i = 0; i < n; i++) {\n // Finding the smallest number in the subarray\n let min = i;\n for(let j = i+1; j < n; j++){\n if(arr[j] < arr[min]) {\n min=j; \n }\n }\n // Swapping the elements\n let tmp = arr[i]; \n arr[i] = arr[min];\n arr[min] = tmp; \n }\n return arr;\n}\n"}, {"role": "assistant", "content": "write the selection sort algorithm for a given array"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\nvoid slice(int arr[], int start, int end, int result[]) {\n int i;\n for(i = start; i <= end; i++) {\n result[i - start] = arr[i];\n }\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة اجتزئ(م: سند[مـصفوفة[صـحيح]]، بداية: صـحيح، نهاية: صـحيح، نتيجة: سند[مـصفوفة[صـحيح]]) {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = بداية ، دليل <= نهاية ، دليل++ {\n\t\tنتيجة.أضف(م(دليل))؛\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة اجتزئ(س: سند[نـص]، بداية: صـحيح، نهاية: صـحيح): نـص {\n\tعرف نتيجة: نـص = \"\"؛\n\n\tعرف دليل: صـحيح؛\n\tلكل دليل = بداية ، دليل <= نهاية ، دليل++ {\n\t\tنتيجة.ألحق(س(دليل))؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "اجتزئ سلسلة نصية معطاة ضمن مجال معطى و ارجع النتيجة"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\n#include <stdbool.h>\n\n// Function to check if arr2 is a permutation of arr1\nbool is_permutation(int arr1[], int size1, int arr2[], int size2) {\n // If sizes are not equal, return false\n if(size1 != size2) {\n return false;\n }\n\n // Create an array to keep track of visited elements\n bool visited[size2];\n for(int i = 0; i < size2; i++) {\n visited[i] = false;\n }\n\n // For each element in arr1\n for(int i = 0; i < size1; i++) {\n bool found = false;\n\n // For each element in arr2\n for(int j = 0; j < size2; j++) {\n // If the element in arr1 is found in arr2 and it has not been visited\n if(arr1[i] == arr2[j] && !visited[j]) {\n found = true;\n visited[j] = true; // Mark the element in arr2 as visited\n break;\n }\n }\n\n // If the element in arr1 is not found in arr2, return false\n if(!found) {\n return false;\n }\n }\n\n // If we reach here, then arr2 is a permutation of arr1\n return true;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc is_permutation(a1: ref[Array[Int]], a2: ref[Array[Int]]): Bool {\n if a1.getLength() != a2.getLength() {\n return false;\n }\n\n def visited: Array[Bool];\n def i: Int;\n for i = 0 , i < a2.getLength() , i++ {\n visited.add(false);\n }\n\n def j: Int;\n for i = 0 , i < a1.getLength() , i++ {\n def found: Bool = false;\n for j = 0 , j < a2.getLength() , j++ {\n if a1(i) == a2(j) && !visited(j) {\n found = true;\n visited(j) = true;\n break;\n }\n }\n if !found {\n return false;\n }\n }\n\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nclass Point {\n constructor(x, y) {\n this.x = x;\n this.y = y;\n }\n}\n\nfunction calculateDistance(a, b) {\n return Math.sqrt(Math.pow(b.x - a.x, 2) + Math.pow(b.y - a.y, 2));\n}\n\nfunction findFarthestPoint(givenPoint, points) {\n let maxDistance = 0;\n let farthestPoint;\n \n for(let i = 0; i < points.length; i++) {\n let distance = calculateDistance(givenPoint, points[i]);\n if(distance > maxDistance) {\n maxDistance = distance;\n farthestPoint = points[i];\n }\n }\n \n return farthestPoint;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Math\";\nimport \"Srl/Array\";\n\n\n\nuse Srl;\n\nclass Point {\n def x : Float;\n def y : Float;\n};\n\nfunc calculateDistance(a: Point, b: Point): Float {\n return Math.sqrt(Math.pow(b.x - a.x, 2.0) + Math.pow(b.y - a.y, 2.0));\n}\n\nfunc findFarthestPoint(givenPoint: Point, points: ref[Array[Point]]): Point {\n def maxDistance: Float = 0;\n def farthestPoint: Point;\n\n def i: Int;\n for i = 0 , i < points.getLength() , i++ {\n def distance: Float = calculateDistance(givenPoint, points(i));\n if distance > maxDistance {\n maxDistance = distance;\n farthestPoint = points(i);\n }\n }\n\n return farthestPoint;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, Delete an element at a given position in the given array"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc erase(a: ref[Array[Int]], pos: Int) {\n def size: Int = a.getLength();\n\n def i: Int;\n for i = pos , i < size - 1 , i++ {\n a(i) = a(i + 1);\n }\n a.remove(size - 1);\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/ريـاضيات\"؛\n\nاستخدم مـتم؛\n\n\nصنف نـقطة {\n\tعرف س: عـائم؛\n\tعرف ص: عـائم؛\n}\n\nدالة مساحة_مثلث(ن1: نـقطة، ن2: نـقطة، ن3: نـقطة): عـائم {\n\tارجع ريـاضيات.مطلق(ن1.س*(ن2.ص - ن3.ص) + ن2.س*(ن3.ص - ن1.ص) + ن3.س*(ن1.ص - ن2.ص)) / 2.0؛\n}\n"}, {"role": "assistant", "content": "function Point(x, y) {\n this.x = x;\n this.y = y;\n}\n\nfunction triangleArea(p1, p2, p3) {\n return Math.abs(p1.x*(p2.y-p3.y) + p2.x*(p3.y-p1.y) + p3.x*(p1.y-p2.y)) / 2.0;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction is_alphabet(c) {\n return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');\n}\n"}, {"role": "assistant", "content": "استخدم مـتم؛\n\n\nدالة ينتمي_للأبجدية(م: مـحرف): ثـنائي {\n\tارجع ( م <= 'Z' && م >= 'A') || ( م <= 'z' && م >= 'a')؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Array\";\nimport \"closure\";\n\n\nuse Srl;\n\n\nfunc accumulate(a: ref[Array[Int]], f: closure (previousValue: Int, currentValue: Int): Int): Array[Int] {\n def size: Int = a.getLength();\n def result: Array[Int];\n\n def i: Int;\n result.add(a(0));\n for i = 1 , i < a.getLength() , i++ {\n result.add(f(result(i-1), a(i)));\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة راكم(م: سند[مـصفوفة[صـحيح]]، د: مغلفة(قيمة_سابقة: صـحيح، قيمة_حالية: صـحيح): صـحيح): مـصفوفة[صـحيح] {\n\tعرف طول: صـحيح = م.هات_الطول()؛\n\tعرف نتيجة: مـصفوفة[صـحيح]؛\n\t\n\tعرف دليل: صـحيح؛\n\tنتيجة.أضف(م(0))؛\n\tلكل دليل = 1 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tنتيجة.أضف(د(نتيجة(دليل - 1)، م(دليل)))؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction multiply(a, b) {\n let rowsA = a.length, colsA = a[0].length,\n rowsB = b.length, colsB = b[0].length,\n result = new Array(rowsA);\n\n for (let i = 0; i < rowsA; i++) {\n result[i] = new Array(colsB); // initialize the current row\n for (let j = 0; j < colsB; j++) {\n result[i][j] = 0; // initialize the current cell\n for (let k = 0; k < colsA; k++) {\n result[i][j] += a[i][k] * b[k][j];\n }\n }\n }\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nعرف مـصفوفة_ثنائية: لقب مـصفوفة[مـصفوفة[عـائم[64]]]؛\n\n\nدالة جداء(م1: سند[مـصفوفة_ثنائية]، م2: سند[مـصفوفة_ثنائية]): مـصفوفة_ثنائية {\n\tعرف أسطر_م1: صـحيح = م1.هات_الطول()؛\n\tعرف أسطر_م2: صـحيح = م2.هات_الطول()؛\n\tعرف أعمدة_م1: صـحيح = م1(0).هات_الطول()؛\n\tعرف أعمدة_م2: صـحيح = م2(0).هات_الطول()؛\n\n\tعرف نتيجة: مـصفوفة_ثنائية؛\n\t\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tعرف دليل3: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < أسطر_م1 ، دليل1++ {\n\t\tعرف سطر: مـصفوفة[عـائم[64]]؛\n\t\tلكل دليل2 = 0 ، دليل2 < أعمدة_م2 ، دليل2++ {\n\t\t\tسطر.أضف(0)؛\n\t\t\tلكل دليل3 = 0 ، دليل3 < أعمدة_م1 ، دليل3++ {\n\t\t\t\tسطر(دليل2) += م1(دليل1)(دليل3) * م2(دليل3)(دليل2)؛\n\t\t\t}\n\t\t}\n\t\tنتيجة.أضف(سطر)؛\n\t}\n\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Array\";\n\nuse Srl;\n\ndef Matrix: alias Array[Array[Float[64]]];\n\n\nfunc multiply(m: ref[Matrix], s: Float[64]): Matrix {\n def rows: Int = m.getLength();\n def cols: Int = m(0).getLength();\n \n def result: Matrix;\n\n def i: Int;\n def j: Int;\n for i = 0 , i < rows , i++ {\n result.add(Array[Float[64]]());\n for j = 0 , j < cols , j++ {\n result(i).add(m(i)(j)*s);\n }\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nعرف مـصفوفة_ثنائية: لقب مـصفوفة[مـصفوفة[عـائم[64]]]؛\n\n\nدالة جداء(م: سند[مـصفوفة_ثنائية]، س: عـائم[64]): مـصفوفة_ثنائية {\n\tعرف أسطر: صـحيح = م.هات_الطول()؛\n\tعرف أعمدة: صـحيح = م(0).هات_الطول()؛\n\n\tعرف نتيجة: مـصفوفة_ثنائية؛\n\t\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < أسطر ، دليل1++ {\n\t\tنتيجة.أضف(مـصفوفة[عـائم[64]]())؛\n\t\tلكل دليل2 = 0 ، دليل2 < أعمدة ، دليل2++ {\n\t\t\t\tنتيجة(دليل1).أضف(م(دليل1)(دليل2)*س)؛\n\t\t}\n\t}\n\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nconst fs = require('fs');\n\nfunction readFileToArray(filename) {\n const data = fs.readFileSync(filename, 'utf8');\n let lines = [''];\n let j = 0;\n for (let i = 0; i < data.length; i++) {\n if (data[i] === '\\n') {\n lines.push('');\n j++;\n } else {\n lines[j] += data[i];\n }\n }\n return lines;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/نـم\"؛\nاشمل \"مـتم/نـص\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة اقرأ_الملف_إلى_مصفوفة(مسار_الملف: سند[نـص]): مـصفوفة[نـص] {\n\tعرف ملف: مؤشر[نـم.مـلف] = نـم.افتح_ملف(مسار_الملف، \"r\")؛\n\tعرف المحتوى: مـصفوفة[نـص]؛\n\n\tنـم.انتقل(ملف، 0، نـم.انـتقال._نهاية_)؛\n\tعرف حجم: صـحيح = نـم.هات_الموقع(ملف)؛\n\tنـم.انتقل(ملف، 0، نـم.انـتقال._بداية_)؛\n\t\n\tالمحتوى.أضف(نـص())؛\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح = 0؛\n\tلكل دليل1 = 0 ، دليل1 < حجم ، دليل1++ {\n\t\tعرف مؤقت: مـحرف؛\n\t\tنـم.اقرأ(مؤقت~مؤشر، 1، 1، ملف)؛\n\t\t\n\t\tإذا مؤقت == '\\n' {\n\t\t\tالمحتوى.أضف(نـص())؛\n\t\t\tدليل2++؛\n\t\t}\n\t\tوإلا {\n\t\t\tالمحتوى(دليل2).ألحق(مؤقت)؛\n\t\t}\n\t}\n\t\n\tارجع المحتوى؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\n#include <math.h>\n\ntypedef struct {\n double x;\n double y;\n} Point;\n\ndouble calculateDistance(Point a, Point b) {\n return sqrt(pow(b.x - a.x, 2) + pow(b.y - a.y, 2));\n}\n\nPoint findFarthestPoint(Point givenPoint, Point points[], int size) {\n double maxDistance = 0;\n Point farthestPoint;\n \n for(int i = 0; i < size; i++) {\n double distance = calculateDistance(givenPoint, points[i]);\n if(distance > maxDistance) {\n maxDistance = distance;\n farthestPoint = points[i];\n }\n }\n \n return farthestPoint;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Math\";\nimport \"Srl/Array\";\n\n\n\nuse Srl;\n\nclass Point {\n def x : Float;\n def y : Float;\n};\n\nfunc calculateDistance(a: Point, b: Point): Float {\n return Math.sqrt(Math.pow(b.x - a.x, 2.0) + Math.pow(b.y - a.y, 2.0));\n}\n\nfunc findFarthestPoint(givenPoint: Point, points: ref[Array[Point]]): Point {\n def maxDistance: Float = 0;\n def farthestPoint: Point;\n\n def i: Int;\n for i = 0 , i < points.getLength() , i++ {\n def distance: Float = calculateDistance(givenPoint, points(i));\n if distance > maxDistance {\n maxDistance = distance;\n farthestPoint = points(i);\n }\n }\n\n return farthestPoint;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Fs\";\nimport \"Srl/String\";\n\nuse Srl;\n\n\nfunc read_file(file_path: ref[String]): String {\n def file: ptr[Fs.File] = Fs.openFile(file_path.buf, \"r\");\n def content: String;\n\n Fs.seek(file, 0, Fs.Seek.END);\n def size: Int = Fs.tell(file);\n Fs.seek(file, 0, Fs.Seek.SET);\n \n\n def i: Int;\n for i = 0 , i < size , i++ {\n def temp: Char;\n Fs.read(temp~ptr, 1, 1, file);\n content.append(temp);\n }\n\n return content;\n}\n"}, {"role": "assistant", "content": "Read the content of a text file given its path and return the result"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\n#include <stdlib.h>\n#include <string.h>\n\nchar* replace(char* str, char oldChar, char newChar) {\n int len = strlen(str);\n char* result = (char*)malloc(sizeof(char) * (len + 1));\n int i;\n\n for(i = 0; i < len; i++) {\n if(str[i] == oldChar) {\n result[i] = newChar;\n } else {\n result[i] = str[i];\n }\n }\n result[i] = '\\0';\n\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة استبدل(س: سند[نـص]، م1: مـحرف، م2: مـحرف): نـص {\n\tعرف نتيجة: نـص؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) == م1 {\n\t\t\tنتيجة.ألحق(م2)؛\n\t\t}\n\t\tوإلا {\n\t\t\tنتيجة.ألحق(س(دليل))؛\n\t\t}\n\t}\n\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/نـم\"؛\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة اقرأ_السطر_ن(مسار_الملف: سند[نـص]، ن: صـحيح): نـص {\n\tعرف ملف: مؤشر[نـم.مـلف] = نـم.افتح_ملف(مسار_الملف، \"r\")؛\n\t\n\tعرف دليل: صـحيح؛\n\tعرف مؤقت: مـحرف = ' '؛\n\tلكل دليل = 0 ، دليل < ن - 1 ، دليل++ {\n\t\tمؤقت = ' '؛\n\t\tبينما مؤقت != '\\n' {\n\t\t\tنـم.اقرأ(مؤقت~مؤشر، 1، 1، ملف)؛\n\t\t}\n\t}\n\t\n\tعرف السطر_ن: نـص؛\n\tمؤقت = ' '؛\n\tبينما مؤقت != '\\n' {\n\t\tنـم.اقرأ(مؤقت~مؤشر، 1، 1، ملف)؛\n\t\tالسطر_ن.ألحق(مؤقت)؛\n\t}\n\t\n\tارجع السطر_ن؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/Fs\";\nimport \"Srl/String\";\n\nuse Srl;\n\n\nfunc read_nth_line(file_path: ref[String], n: Int): String {\n def file: ptr[Fs.File] = Fs.openFile(file_path.buf, \"r\");\n\n def i: Int;\n def temp: Char = ' ';\n for i = 0 , i < n - 1 , i++ {\n temp = ' ';\n while temp != '\\n' {\n Fs.read(temp~ptr, 1, 1, file);\n }\n }\n\n def nth_line: String;\n temp = ' ';\n while temp != '\\n' {\n Fs.read(temp~ptr, 1, 1, file);\n nth_line.append(temp);\n }\n\n return nth_line;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة فلتر(م: سند[مـصفوفة[صـحيح]]، د: مغلفة(رقم: صـحيح): ثـنائي): مـصفوفة[صـحيح] {\n\tعرف نتيجة: مـصفوفة[صـحيح]؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا د(م(دليل)) {\n\t\t\tنتيجة.أضف(م(دليل))؛\n\t\t}\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "function filter(a, condition) {\n let result = [];\n for(let i = 0; i < a.length; i++) {\n if(condition(a[i])) {\n result.push(a[i]);\n }\n }\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Array\";\n\nuse Srl;\n\n\nfunc max(a: ref[Array[Int]]): Int {\n def result: Int = a(0);\n\n def i: Int;\n for i = 1 , i < a.getLength() , i++ {\n if a(i) > result {\n result = a(i);\n }\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "Find and return the maximum in the given array `a`"}]}
{"messages": [{"role": "user", "content": "Using js, convert string to lowercase and return the result"}, {"role": "assistant", "content": "function toLowerCase(s) {\n let result = '';\n for(let i = 0; i < s.length; i++){\n let code = s.charCodeAt(i);\n if(code >= 65 && code <= 90){\n result += String.fromCharCode(code + 32);\n } else {\n result += s[i];\n }\n }\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nدالة هل_حلقي(عقدة: صـحيح، مزارة: سند[مـصفوفة[صـحيح]]، بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]): ثـنائي {\n\tإذا مزارة(عقدة) == 2 {\n\t\tارجع صح؛\n\t}\n\tمزارة(عقدة) = 1؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان(عقدة).هات_الطول() ، دليل++ {\n\t\tعرف عقدة_ابن: صـحيح = بيان(عقدة)(دليل)؛\n\t\tإذا مزارة(عقدة_ابن) == 1 {\n\t\t\tارجع صح؛\n\t\t}\n\t\tوإلا إذا مزارة(عقدة_ابن) == 0 && هل_حلقي(عقدة_ابن، مزارة، بيان) {\n\t\t\tارجع صح؛\n\t\t}\n\t}\n\tمزارة(عقدة) = 2؛\n\tارجع خطأ؛\n}\n\n\nدالة هل_داغ(بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]): ثـنائي {\n\tعرف مزارة: مـصفوفة[صـحيح]؛\n\t\n\tعرف دليل1: صـحيح؛\n\tعرف عدد_المكونات: صـحيح = 0؛\n\tلكل دليل1 = 0 ، دليل1 < بيان.هات_الطول() ، دليل1++ {\n\t\tعرف دليل2: صـحيح؛\n\t\tلكل دليل2 = 0 ، دليل2 < بيان.هات_الطول() ، دليل2++ {\n\t\t\tمزارة.أضف(0)؛\n\t\t}\n\n\t\tإذا هل_حلقي(دليل1، مزارة، بيان) {\n\t\t\tارجع خطأ؛\n\t\t}\n\t\tمزارة.فرغ()؛\n\t}\n\t\n\tارجع صح؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\nfunc isCyclic(node: Int, visited: ref[Array[Int]], graph: ref[Array[Array[Int]]]): Bool {\n if visited(node) == 2 {\n return true;\n }\n visited(node) = 1;\n\n def i: Int;\n for i = 0 , i < graph(node).getLength(), i++ {\n def childNode: Int = graph(node)(i);\n if visited(childNode) == 1 {\n return true;\n }\n else if visited(childNode) == 0 && isCyclic(childNode, visited, graph){\n return true;\n }\n }\n visited(node) = 2;\n return false;\n}\n\n\nfunc isDAG(graph: ref[Array[Array[Int]]]): Bool {\n def visited: Array[Int];\n def i: Int;\n\n for i = 0 , i < graph.getLength() , i++ {\n def j: Int;\n for j = 0 , j < graph.getLength() , j++ {\n visited.add(0);\n }\n if isCyclic(i, visited, graph) {\n return false;\n }\n visited.clear();\n }\n\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc starts_with(s: ref[String], prefix: ref[String]): Bool {\n\tif s.getLength() < prefix.getLength() {\n\t\treturn false;\n\t}\n\n def i: Int;\n\tfor i = 0 , i < prefix.getLength() , i++ {\n\t\tif (prefix(i) != s(i)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n"}, {"role": "assistant", "content": "int starts_with(const char *str, const char *prefix) {\n while(*prefix) {\n if (!(*str))\n return 0;\n if(*prefix++ != *str++)\n return 0;\n }\n return 1;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction rfind(a, val) {\n for (let i = a.length - 1; i != 0 ; i--) {\n if (a[i] == val) {\n return i;\n }\n }\n return -1;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc rfind(a: ref[Array[Int]], val: Int): Int {\n def i: Int;\n for i = a.getLength() - 1 , i != 0 , i-- {\n if a(i) == val {\n return i;\n }\n }\n return -1;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\n#include <stdio.h>\n#include <string.h>\n\nvoid appendLogEntry(char *filename, char *logEntry) {\n FILE *file = fopen(filename, \"a\");\n\n fwrite(logEntry, 1, strlen(logEntry), file);\n fwrite(\"\\n\", 1, 1, file);\n fclose(file);\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/نـم\"؛\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة ألحق_سجل(مسار_الملف: سند[نـص]، سجل: سند[نـص]) {\n\tعرف ملف: مؤشر[نـم.مـلف] = نـم.افتح_ملف(مسار_الملف، \"a\")؛\n\t\n\tنـم.اكتب(سجل.صوان، 1، سجل.هات_الطول()، ملف)؛\n\tنـم.اكتب(\"\\ج\"، 1، 1، ملف)؛\n\tنـم.اغلق_ملف(ملف)؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\n#include <stdbool.h>\n\nbool char_exists(char s[], int n, char c) {\n for (int i = 0; i < n; i++) {\n if (s[i] == c) {\n return true;\n }\n }\n return false;\n}\n"}, {"role": "assistant", "content": "import \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc char_exists(s: ref[String], c: Char): Bool {\n def i: Int;\n\tfor i = 0 , i < s.getLength() , i++ {\n\t\tif (s(i) == c) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Array\";\nimport \"Srl/Math\";\n\n\nuse Srl;\n\n\nfunc std(a: ref[Array[Int]], mean: Float): Float {\n def size: Int = a.getLength();\n def variance: Float = 0;\n\n def i: Int;\n for i = 0 , i < size , i++ {\n variance += (a(i) - mean) * ( a(i) - mean);\n }\n\n return Math.sqrt(variance / size);\n}\n"}, {"role": "assistant", "content": "#include <math.h>\n\ndouble std(int data[], int n, float mean)\n{\n double variance = 0.0;\n\n for(int i=0; i<n; ++i)\n variance += (data[i] - mean) * (data[i] - mean);\n\n return sqrt(variance/n);\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Array\";\nimport \"closure\";\n\n\nuse Srl;\n\n\nfunc filter(a: ref[Array[Int]], f: closure (num: Int): Bool): Array[Int] {\n def result: Array[Int];\n\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if f(a(i)) {\n result.add(a(i));\n }\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "filter the given array based on the given function `f` and return the result"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\n#include <stdlib.h>\n\n#define MAX_VALUE 100000\n\nvoid counting_sort(int arr[], int n) {\n int i, j;\n int idx = 0;\n int* count = calloc(MAX_VALUE + 1, sizeof(int));\n\n // Count the occurrence of each number\n for(i = 0; i < n; i++) {\n count[arr[i]]++;\n }\n\n // Reconstruct the sorted array\n for(i = 0; i <= MAX_VALUE; i++) {\n for(j = 0; j < count[i]; j++) {\n arr[idx++] = i;\n }\n }\n\n free(count);\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nعرف قيمة_عظمى: صـحيح = 100000؛\n\nدالة الترتيب_بالعد(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tعرف دليل: صـحيح؛\n\t\n\tعرف عداد: مـصفوفة[صـحيح]؛\n\tلكل دليل1 = 0 ، دليل1 < قيمة_عظمى ، دليل1++ {\n\t\tعداد.أضف(0)؛\n\t}\n\t\n\tلكل دليل1 = 0 ، دليل1 < م.هات_الطول() ، دليل1++ {\n\t\tعداد(م(دليل1))++؛\n\t}\n\t\n\tلكل دليل1 = 0 ، دليل1 < قيمة_عظمى ، دليل1++ {\n\t\tلكل دليل2 = 0 ، دليل2 < عداد(دليل1) ، دليل2++ {\n\t\t\tم(دليل++) = دليل1؛\n\t\t}\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة إلى_حالة_صغيرة(س: سند[نـص]): نـص {\n\tعرف نتيجة: نـص = \"\"؛\n\n\tعرف دليل: صـحيح؛\n\tعرف م: مـحرف؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) >= 'A' && س(دليل) <= 'Z' {\n\t\t\tم = س(دليل) - 'A' + 'a'؛\n\t\t}\n\t\tوإلا {\n\t\t\tم = س(دليل)؛\n\t\t}\n\t\tنتيجة += م؛\n\t}\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "void toLowerCase(char *s, char *result) {\n for(int i = 0; s[i]; i++){\n if(s[i] >= 'A' && s[i] <= 'Z'){\n result[i] = s[i] - 'A' + 'a';\n }\n else {\n result[i] = s[i];\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Array\";\n\nuse Srl;\n\ndef Matrix: alias Array[Array[Float[64]]];\n\n\nfunc multiply(m: ref[Matrix], s: Float[64]): Matrix {\n def rows: Int = m.getLength();\n def cols: Int = m(0).getLength();\n \n def result: Matrix;\n\n def i: Int;\n def j: Int;\n for i = 0 , i < rows , i++ {\n result.add(Array[Float[64]]());\n for j = 0 , j < cols , j++ {\n result(i).add(m(i)(j)*s);\n }\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "function multiply(matrix, scalar) {\n let rows = matrix.length, cols = matrix[0].length;\n let result = new Array(rows);\n\n for (let i = 0; i < rows; i++) {\n result[i] = new Array(cols);\n for (let j = 0; j < cols; j++) {\n result[i][j] = matrix[i][j] * scalar;\n }\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة إلى_حالة_صغيرة(س: سند[نـص]): نـص {\n\tعرف نتيجة: نـص = \"\"؛\n\n\tعرف دليل: صـحيح؛\n\tعرف م: مـحرف؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) >= 'A' && س(دليل) <= 'Z' {\n\t\t\tم = س(دليل) - 'A' + 'a'؛\n\t\t}\n\t\tوإلا {\n\t\t\tم = س(دليل)؛\n\t\t}\n\t\tنتيجة += م؛\n\t}\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "حول حالة محارف سلسلة نصية إلى أحرف صغيرة و أرجع النتيجة"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction is_digit(c) {\n return (c >= '0' && c <= '9');\n}\n"}, {"role": "assistant", "content": "استخدم مـتم؛\n\n\nدالة ينتمي_للأرقام(م: مـحرف): ثـنائي {\n\tارجع ( م <= '9' && م >= '0')؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جد_التقاطع(أ1: عـائم[64]، ب1: عـائم[64]، ج1: عـائم[64]، أ2: عـائم[64]، ب2: عـائم[64]، ج2: عـائم[64]): مـصفوفة[عـائم[64]] {\n\tعرف نتيجة: مـصفوفة[عـائم[64]]؛\n\tإذا أ1 * ب2 - أ2 * ب1 == 0 {\n\t\tارجع نتيجة؛\n\t}\n\t\n\tنتيجة.أضف((ب1*ج2 - ب2*ج1) / (أ1 * ب2 - أ2 * ب1))؛\n\tنتيجة.أضف((أ2*ج1 - أ1*ج2) / (أ1 * ب2 - أ2 * ب1))؛\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "function findIntersection(a1, b1, c1, a2, b2, c2) {\n // Check if the lines are parallel\n if(a1*b2 - a2*b1 === 0) {\n return null;\n }\n\n let result = [];\n result[0] = (b1*c2 - b2*c1) / (a1*b2 - a2*b1);\n result[1] = (a2*c1 - a1*c2) / (a1*b2 - a2*b1);\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة متوسط(م: سند[مـصفوفة[صـحيح]]): عـائم {\n\tعرف حجم: صـحيح = م.هات_الطول()؛\n\tعرف مجموع: صـحيح = 0؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < حجم ، دليل++ {\n\t\tمجموع += م(دليل)؛\n\t}\n\t\n\tارجع مجموع~مثل[عـائم] / حجم؛\n}\n"}, {"role": "assistant", "content": "function calculateMean(arr) {\n var sum = 0;\n for (var i = 0; i < arr.length; i++) {\n sum += arr[i];\n }\n return sum / arr.length;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, Invert the given array `a` and return the result"}, {"role": "assistant", "content": "void invertArray(int a[], int n) {\n int start = 0;\n int end = n - 1;\n while (start < end) {\n int temp = a[start];\n a[start] = a[end];\n a[end] = temp;\n start++;\n end--;\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc find_diff_index(a1: ref[Array[Int]], a2: ref[Array[Int]]): Int {\n def i: Int;\n for i = 0 , i < a1.getLength() , i++ {\n if a1(i) != a2(i) {\n return i;\n }\n }\n return -1;\n}\n"}, {"role": "assistant", "content": "Find the first index at which the two given arrays differ, return -1 if not found"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/ريـاضيات\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nصنف نـقطة {\n\tعرف س: عـائم؛\n\tعرف ص: عـائم؛\n}\n\nدالة احسب_مسافة(ن1: نـقطة، ن2: نـقطة): عـائم {\n\tارجع ريـاضيات.جذر(ريـاضيات.ارفع(ن2.س - ن1.س، 2.0) + ريـاضيات.ارفع(ن2.ص - ن1.ص، 2.0))؛\n}\n\nدالة جد_أبعد_نقطة(ن: نـقطة، نقاط: سند[مـصفوفة[نـقطة]]): نـقطة {\n\tعرف أبعد_مسافة: عـائم = 0؛\n\tعرف أبعد_نقطة: نـقطة؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < نقاط.هات_الطول() ، دليل++ {\n\t\tعرف مسافة: عـائم = احسب_مسافة(ن، نقاط(دليل))؛\n\t\tإذا مسافة > أبعد_مسافة {\n\t\t\tأبعد_مسافة = مسافة؛\n\t\t\tأبعد_نقطة = نقاط(دليل)؛\n\t\t}\n\t}\n\tارجع أبعد_نقطة؛\n}\n"}, {"role": "assistant", "content": "جد و أرجع أبعد نقطة من بين مجموعة من النقاط المعطاة عن نقطة معطاة"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Array\";\n\nuse Srl;\n\n\nfunc outer_product(v1: ref[Array[Float[64]]], v2: ref[Array[Float[64]]]): Array[Array[Float[64]]] {\n def result: Array[Array[Float[64]]];\n\n def i: Int;\n def j: Int;\n for i = 0 , i < v1.getLength() , i++ {\n def row: Array[Float[64]];\n for j = 0 , j < v2.getLength() , j++ {\n row.add(v1(i)*v2(j));\n }\n result.add(row);\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "function outer_product(v1, v2) {\n let result = [];\n for (let i = 0; i < v1.length; i++) {\n let row = [];\n for (let j = 0; j < v2.length; j++) {\n row.push(v1[i] * v2[j]);\n }\n result.push(row);\n }\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, find and return the farthest point to a given point from a given set of points"}, {"role": "assistant", "content": "import \"Srl/Math\";\nimport \"Srl/Array\";\n\n\n\nuse Srl;\n\nclass Point {\n def x : Float;\n def y : Float;\n};\n\nfunc calculateDistance(a: Point, b: Point): Float {\n return Math.sqrt(Math.pow(b.x - a.x, 2.0) + Math.pow(b.y - a.y, 2.0));\n}\n\nfunc findFarthestPoint(givenPoint: Point, points: ref[Array[Point]]): Point {\n def maxDistance: Float = 0;\n def farthestPoint: Point;\n\n def i: Int;\n for i = 0 , i < points.getLength() , i++ {\n def distance: Float = calculateDistance(givenPoint, points(i));\n if distance > maxDistance {\n maxDistance = distance;\n farthestPoint = points(i);\n }\n }\n\n return farthestPoint;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, احسب جداء مصفوفة معطاة ممثلة على شكل مصفوفة ثنائية الأبعاد، و قيمة سلمية و أعد النتيجة"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nعرف مـصفوفة_ثنائية: لقب مـصفوفة[مـصفوفة[عـائم[64]]]؛\n\n\nدالة جداء(م: سند[مـصفوفة_ثنائية]، س: عـائم[64]): مـصفوفة_ثنائية {\n\tعرف أسطر: صـحيح = م.هات_الطول()؛\n\tعرف أعمدة: صـحيح = م(0).هات_الطول()؛\n\n\tعرف نتيجة: مـصفوفة_ثنائية؛\n\t\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < أسطر ، دليل1++ {\n\t\tنتيجة.أضف(مـصفوفة[عـائم[64]]())؛\n\t\tلكل دليل2 = 0 ، دليل2 < أعمدة ، دليل2++ {\n\t\t\t\tنتيجة(دليل1).أضف(م(دليل1)(دليل2)*س)؛\n\t\t}\n\t}\n\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nvoid selectionSort(int arr[], int n) {\n int i, j, min_idx, temp;\n\n // One by one move boundary of unsorted subarray\n for (i = 0; i < n-1; i++) {\n // Find the minimum element in unsorted array\n min_idx = i;\n for (j = i+1; j < n; j++)\n if (arr[j] < arr[min_idx])\n min_idx = j;\n\n // Swap the found minimum element with the first element\n temp = arr[min_idx];\n arr[min_idx] = arr[i];\n arr[i] = temp;\n }\n}\n"}, {"role": "assistant", "content": "write the selection sort algorithm for a given array"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction Point(x, y) {\n this.x = x;\n this.y = y;\n}\n\nfunction areCollinear(p1, p2, p3) {\n // Calculate the slopes of the lines formed by (p1, p2) and (p1, p3)\n // If the slopes are equal, then p1, p2 and p3 are collinear\n return (p2.y - p1.y) * (p3.x - p1.x) === (p3.y - p1.y) * (p2.x - p1.x);\n}\n"}, {"role": "assistant", "content": "use Srl;\n\nclass Point {\n def x : Int;\n def y : Int;\n};\n\nfunc areCollinear(p1: Point, p2: Point, p3: Point): Bool {\n return (p2.y - p1.y) * (p3.x - p1.x) == (p3.y - p1.y) * (p2.x - p1.x);\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction trim(str) {\n let start = 0, end = str.length - 1;\n\n // Trim leading white spaces\n while(str[start] === ' ' || str[start] === '\\t' || str[start] === '\\n') start++;\n\n // Trim trailing white spaces\n while(str[end] === ' ' || str[end] === '\\t' || str[end] === '\\n') end--;\n\n // Return the trimmed string\n return str.substring(start, end + 1);\n}\n"}, {"role": "assistant", "content": "Remove any whitespace character from both ends of a given string"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة احشر(م: سند[مـصفوفة[صـحيح]]، موقع: صـحيح، قيمة: صـحيح) {\n\tعرف حجم: صـحيح = م.هات_الطول()؛\n\tم.أضف(0)؛ // لزيادة الحجم بمقدار 1\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = حجم ، دليل > موقع ، دليل-- {\n\t\tم(دليل) = م(دليل - 1)؛\n\t}\n\t\n\tم(موقع) = قيمة؛\n}\n"}, {"role": "assistant", "content": "احشر عنصرا في موقع معطى ضمن المصفوفة المعطى"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Array\";\n\nuse Srl;\n\nfunc sum(a: ref[Array[Int]], start: Int, end: Int): Int {\n def sum: Int = 0;\n\n def i: Int;\n for i = start , i < end , i++ {\n sum += a(i);\n }\n\n return sum;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جمع(م: سند[مـصفوفة[صـحيح]]، بداية: صـحيح، نهاية: صـحيح): صـحيح {\n\tعرف نتيجة: صـحيح = 0؛\n\n\tعرف دليل: صـحيح؛\n\n\tلكل دليل = بداية ، دليل < نهاية ، دليل++ {\n نتيجة += م(دليل)؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nconst fs = require('fs');\nconst readline = require('readline');\n\nfunction read_nth_line(file_path, n) {\n return new Promise((resolve, reject) => {\n const fileStream = fs.createReadStream(file_path);\n\n const rl = readline.createInterface({\n input: fileStream,\n crlfDelay: Infinity\n });\n\n let line_no = 0;\n\n rl.on('line', (line) => {\n line_no++;\n if(line_no === n) {\n resolve(line);\n rl.close();\n }\n });\n\n rl.on('close', () => {\n if(line_no < n) {\n reject(new Error(`The file has less than ${n} lines.`));\n }\n });\n });\n}\n"}, {"role": "assistant", "content": "Read the nth line of a text file given its path and return the result"}]}
{"messages": [{"role": "user", "content": "What this code do?\ndouble calculateMean(int arr[], int n) {\n int sum = 0;\n for (int i = 0; i < n; i++) {\n sum += arr[i];\n }\n return (double)sum / n;\n}\n"}, {"role": "assistant", "content": "calculate and return the mean of the given array"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, write the selection sort algorithm for a given array"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\n\nfunc selectionSort(a: ref[Array[Int]]) {\n def i: Int;\n def j: Int;\n def temp: Int;\n def min_idx: Int;\n\n for i = 0 , i < a.getLength() - 1 , i++ {\n min_idx = i;\n for j = i + 1 , j < a.getLength() , j++ {\n if a(j) < a(min_idx) {\n min_idx = j;\n }\n }\n\n temp = a(min_idx);\n a(min_idx) = a(i);\n a(i) = temp;\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة شذب(س: سند[نـص]) {\n\tعرف بداية: صـحيح = 0؛\n\tعرف نهاية: صـحيح = س.هات_الطول() - 1؛\n\t\n\tبينما (س(بداية) == ' ' || س(بداية) == '\\t' || س(بداية) == '\\n') {\n\t\tبداية++؛\n\t}\n\t\n\tبينما (س(نهاية) == ' ' || س(نهاية) == '\\t' || س(نهاية) == '\\n') {\n\t\tنهاية--؛\n\t}\n\t\n\tس = س.اجتزئ(بداية، نهاية - بداية + 1)؛\n}\n"}, {"role": "assistant", "content": "function trim(str) {\n let start = 0, end = str.length - 1;\n\n // Trim leading white spaces\n while(str[start] === ' ' || str[start] === '\\t' || str[start] === '\\n') start++;\n\n // Trim trailing white spaces\n while(str[end] === ' ' || str[end] === '\\t' || str[end] === '\\n') end--;\n\n // Return the trimmed string\n return str.substring(start, end + 1);\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Array\";\n\nuse Srl;\n\n\nfunc selectionSort(a: ref[Array[Int]]) {\n def i: Int;\n def j: Int;\n def temp: Int;\n def min_idx: Int;\n\n for i = 0 , i < a.getLength() - 1 , i++ {\n min_idx = i;\n for j = i + 1 , j < a.getLength() , j++ {\n if a(j) < a(min_idx) {\n min_idx = j;\n }\n }\n\n temp = a(min_idx);\n a(min_idx) = a(i);\n a(i) = temp;\n }\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة الترتيب_بالاختيار(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tعرف مؤقت: صـحيح؛\n\tعرف أصغر_دليل: صـحيح؛\n\t\n\tلكل دليل1 = 0 ، دليل1 < م.هات_الطول() - 1 ، دليل1++ {\n\t\tأصغر_دليل = دليل1؛\n\t\t\n\t\tلكل دليل2 = دليل1 + 1 ، دليل2 < م.هات_الطول() ، دليل2++ {\n\t\t\tإذا م(دليل2) < م(أصغر_دليل) {\n\t\t\t\tأصغر_دليل = دليل2؛\n\t\t\t}\n\t\t}\n\t\t\n\t\tمؤقت = م(أصغر_دليل)؛\n\t\tم(أصغر_دليل) = م(دليل1)؛\n\t\tم(دليل1) = مؤقت؛\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\n#include <stdio.h>\n#include <stdlib.h>\n\n// Function to read the content of a file into a string\nchar* read_file(const char* file_path) {\n FILE* file = fopen(file_path, \"r\");\n if(file == NULL) {\n printf(\"Could not open file %s\\n\", file_path);\n return NULL;\n }\n\n // Get the size of the file\n fseek(file, 0, SEEK_END);\n long file_size = ftell(file);\n fseek(file, 0, SEEK_SET);\n\n // Allocate memory for the string\n char* str = malloc(file_size + 1);\n if(str == NULL) {\n printf(\"Could not allocate memory for the string\\n\");\n fclose(file);\n return NULL;\n }\n\n // Read the file into the string one character at a time\n for(long i = 0; i < file_size; i++) {\n fread(&str[i], sizeof(char), 1, file);\n }\n\n // Null-terminate the string\n str[file_size] = '\\0';\n\n fclose(file);\n return str;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Fs\";\nimport \"Srl/String\";\n\nuse Srl;\n\n\nfunc read_file(file_path: ref[String]): String {\n def file: ptr[Fs.File] = Fs.openFile(file_path.buf, \"r\");\n def content: String;\n\n Fs.seek(file, 0, Fs.Seek.END);\n def size: Int = Fs.tell(file);\n Fs.seek(file, 0, Fs.Seek.SET);\n \n\n def i: Int;\n for i = 0 , i < size , i++ {\n def temp: Char;\n Fs.read(temp~ptr, 1, 1, file);\n content.append(temp);\n }\n\n return content;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Array\";\nimport \"Srl/Console\";\n\n\nuse Srl;\n\n\nfunc print(a: ref[Array[Int]]) {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n Console.print(\"%d \", a(i));\n }\n}\n"}, {"role": "assistant", "content": "#include <stdio.h>\n\nvoid printArray(int a[], int size) {\n int i;\n for(i = 0; i < size; i++) {\n printf(\"%d \", a[i]);\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاستخدم مـتم؛\n\nدالة هل_أولي (عدد: صـحيح): ثـنائي {\n\tإذا عدد <= 1 {\n\t\tارجع خطأ؛\n\t}\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 2 ، دليل * دليل <= عدد ، دليل++ {\n\t\tإذا عدد % دليل == 0 {\n\t\t\tارجع خطأ؛\n\t\t}\n\t}\n\t\n\tارجع صح؛\n}\n"}, {"role": "assistant", "content": "#include <stdbool.h>\n\nbool isPrime(int num) {\n if (num <= 1) {\n return false;\n }\n for (int i = 2; i * i <= num; i++) {\n if (num % i == 0) {\n return false;\n }\n }\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة أكبر_عنصر(م: سند[مـصفوفة[صـحيح]]): صـحيح {\n\n\tعرف نتيجة: صـحيح = م(0)؛\n\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 1 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا م(دليل) > نتيجة {\n\t\t\tنتيجة = م(دليل)؛\n\t\t}\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "function max(a) {\n let result = a[0];\n for (let i = 1 ; i < a.length ; i++) {\n if (result < a[i]) {\n result = a[i];\n }\n }\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, جد و أرجع أكثر عنصر مكرر في المصفوفة المعطاة"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جد_أكثر_عنصر_مكرر(م: سند[مـصفوفة[صـحيح]]): صـحيح {\n\tعرف أكثر_تكرار: صـحيح = 0؛\n\tعرف نتيجة: صـحيح = -1؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tعرف عداد: صـحيح = 1؛\n\t\t\n\t\tعرف دليل2: صـحيح؛\n\t\tلكل دليل2 = دليل + 1 ، دليل2 < م.هات_الطول() ، دليل2++ {\n\t\t\tإذا م(دليل2) == م(دليل) {\n\t\t\t\tعداد++؛\n\t\t\t}\n\t\t}\n\t\t\n\t\tإذا عداد > أكثر_تكرار {\n\t\t\tأكثر_تكرار = عداد؛\n\t\t\tنتيجة = م(دليل)؛\n\t\t}\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction Point(x, y) {\n this.x = x;\n this.y = y;\n}\n\nfunction triangleArea(p1, p2, p3) {\n return Math.abs(p1.x*(p2.y-p3.y) + p2.x*(p3.y-p1.y) + p3.x*(p1.y-p2.y)) / 2.0;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Math\";\n\nuse Srl;\n\nclass Point {\n def x : Float;\n def y : Float;\n};\n\nfunc triangleArea(p1: Point, p2: Point, p3: Point): Float {\n return Math.abs(p1.x*(p2.y-p3.y) + p2.x*(p3.y-p1.y) + p3.x*(p1.y-p2.y)) / 2.0;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\ndouble dot_product(double v1[], double v2[], int n) {\n double result = 0;\n for (int i = 0; i < n; i++) {\n result += v1[i] * v2[i];\n }\n return result;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"Srl/Math\";\n\nuse Srl;\n\n\nfunc dot_product(v1: ref[Array[Float[64]]], v2: ref[Array[Float[64]]]): Float[64] {\n def result: Float[64] = 0;\n\n def i: Int;\n for i = 0 , i < v1.getLength() , i++ {\n result += v1(i) * v2(i);\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, Check if any element in a given array satisfy a criteria defined by a function with boolean return value"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"closure\";\n\n\nuse Srl;\n\n\nfunc check_any(a: ref[Array[Int]], f: closure (num: Int): Bool): Bool {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if f(a(i)) {\n return true;\n }\n }\n\n return false;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, اختبر فيما إذا كانت سلسلة نصية معطاة تحتوي محرفا معطى"}, {"role": "assistant", "content": "اشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة المحرف_متواجد(س: سند[نـص]، م: مـحرف): ثـنائي {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) == م {\n\t\t\tارجع صح؛\n\t\t}\n\t}\n\tارجع خطأ؛\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, حول حالة محارف سلسلة نصية إلى أحرف كبيرة و أرجع النتيجة"}, {"role": "assistant", "content": "اشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة إلى_حالة_كبيرة(س: سند[نـص]): نـص {\n\tعرف نتيجة: نـص = \"\"؛\n\n\tعرف دليل: صـحيح؛\n\tعرف م: مـحرف؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) >= 'a' && س(دليل) <= 'z' {\n\t\t\tم = س(دليل) - 'a' + 'A'؛\n\t\t}\n\t\tوإلا {\n\t\t\tم = س(دليل)؛\n\t\t}\n\t\tنتيجة += م؛\n\t}\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, Calculate the dot product of two given vectors each represented by an array and return the result"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"Srl/Math\";\n\nuse Srl;\n\n\nfunc dot_product(v1: ref[Array[Float[64]]], v2: ref[Array[Float[64]]]): Float[64] {\n def result: Float[64] = 0;\n\n def i: Int;\n for i = 0 , i < v1.getLength() , i++ {\n result += v1(i) * v2(i);\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, find and return the farthest point to a given point from a given set of points"}, {"role": "assistant", "content": "#include <math.h>\n\ntypedef struct {\n double x;\n double y;\n} Point;\n\ndouble calculateDistance(Point a, Point b) {\n return sqrt(pow(b.x - a.x, 2) + pow(b.y - a.y, 2));\n}\n\nPoint findFarthestPoint(Point givenPoint, Point points[], int size) {\n double maxDistance = 0;\n Point farthestPoint;\n \n for(int i = 0; i < size; i++) {\n double distance = calculateDistance(givenPoint, points[i]);\n if(distance > maxDistance) {\n maxDistance = distance;\n farthestPoint = points[i];\n }\n }\n \n return farthestPoint;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction erase(a, n, pos) {\n // Shift elements to left\n for (let i = pos; i < n - 1; i++)\n a[i] = a[i + 1];\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc erase(a: ref[Array[Int]], pos: Int) {\n def size: Int = a.getLength();\n\n def i: Int;\n for i = pos , i < size - 1 , i++ {\n a(i) = a(i + 1);\n }\n a.remove(size - 1);\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Math\";\n\nuse Srl;\n\nclass Point {\n def x : Float;\n def y : Float;\n};\n\nfunc triangleArea(p1: Point, p2: Point, p3: Point): Float {\n return Math.abs(p1.x*(p2.y-p3.y) + p2.x*(p3.y-p1.y) + p3.x*(p1.y-p2.y)) / 2.0;\n}\n"}, {"role": "assistant", "content": "function Point(x, y) {\n this.x = x;\n this.y = y;\n}\n\nfunction triangleArea(p1, p2, p3) {\n return Math.abs(p1.x*(p2.y-p3.y) + p2.x*(p3.y-p1.y) + p3.x*(p1.y-p2.y)) / 2.0;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\n// Function to check if arr2 is a permutation of arr1\nfunction is_permutation(arr1, arr2) {\n // If sizes are not equal, return false\n if(arr1.length !== arr2.length) {\n return false;\n }\n\n // Create an array to keep track of visited elements\n let visited = new Array(arr2.length).fill(false);\n\n // For each element in arr1\n for(let i = 0; i < arr1.length; i++) {\n let found = false;\n\n // For each element in arr2\n for(let j = 0; j < arr2.length; j++) {\n // If the element in arr1 is found in arr2 and it has not been visited\n if(arr1[i] === arr2[j] && !visited[j]) {\n found = true;\n visited[j] = true; // Mark the element in arr2 as visited\n break;\n }\n }\n\n // If the element in arr1 is not found in arr2, return false\n if(!found) {\n return false;\n }\n }\n\n // If we reach here, then arr2 is a permutation of arr1\n return true;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc is_permutation(a1: ref[Array[Int]], a2: ref[Array[Int]]): Bool {\n if a1.getLength() != a2.getLength() {\n return false;\n }\n\n def visited: Array[Bool];\n def i: Int;\n for i = 0 , i < a2.getLength() , i++ {\n visited.add(false);\n }\n\n def j: Int;\n for i = 0 , i < a1.getLength() , i++ {\n def found: Bool = false;\n for j = 0 , j < a2.getLength() , j++ {\n if a1(i) == a2(j) && !visited(j) {\n found = true;\n visited(j) = true;\n break;\n }\n }\n if !found {\n return false;\n }\n }\n\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction replace(str, oldChar, newChar) {\n var result = \"\";\n for(var i = 0; i < str.length; i++) {\n if(str[i] == oldChar) {\n result += newChar;\n } else {\n result += str[i];\n }\n }\n return result;\n}\n"}, {"role": "assistant", "content": "Replace a given char with another given char in a given string and return the new string"}]}
{"messages": [{"role": "user", "content": "What this code do?\n#include <stdio.h>\n#include <stdlib.h>\n\n#define MAX_LINE_LENGTH 1024\n#define MAX_LINES 1000\n\nvoid readFileToArray(char *filename, char lines[MAX_LINES][MAX_LINE_LENGTH]) {\n FILE *file = fopen(filename, \"r\");\n if(file == NULL) {\n printf(\"Cannot open file.\\n\");\n exit(1);\n }\n\n int i = 0, j = 0;\n while(!feof(file) && i < MAX_LINES) {\n fread(&lines[i][j], sizeof(char), 1, file);\n if(lines[i][j] == '\\n' || lines[i][j] == '\\0') {\n lines[i][j] = '\\0'; // end of string\n i++; // next line\n j = 0; // reset character index\n } else {\n j++;\n }\n }\n\n fclose(file);\n}\n"}, {"role": "assistant", "content": "Read the lines of a text file given its path into an array and return it"}]}
{"messages": [{"role": "user", "content": "Using c, Replace a given char with another given char in a given string and return the new string"}, {"role": "assistant", "content": "#include <stdlib.h>\n#include <string.h>\n\nchar* replace(char* str, char oldChar, char newChar) {\n int len = strlen(str);\n char* result = (char*)malloc(sizeof(char) * (len + 1));\n int i;\n\n for(i = 0; i < len; i++) {\n if(str[i] == oldChar) {\n result[i] = newChar;\n } else {\n result[i] = str[i];\n }\n }\n result[i] = '\\0';\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\n#include <stdlib.h>\n\n#define MAX_STRINGS 100\n#define MAX_STRING_LEN 100\n\nchar** split(char* str, char token) {\n char** result = (char**) malloc(MAX_STRINGS * sizeof(char*));\n for(int i = 0; i < MAX_STRINGS; i++) {\n result[i] = (char*) malloc(MAX_STRING_LEN * sizeof(char));\n }\n\n int i = 0, j = 0, k = 0;\n while(str[i] != '\\0') {\n if(str[i] != token) {\n result[j][k] = str[i];\n k++;\n } else {\n result[j][k] = '\\0';\n j++;\n k = 0;\n }\n i++;\n }\n result[j][k] = '\\0';\n result[j+1] = NULL; // End of strings\n\n return result;\n}\n"}, {"role": "assistant", "content": "Split a given string into a list of strings based on a given character"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction filter(a, condition) {\n let result = [];\n for(let i = 0; i < a.length; i++) {\n if(condition(a[i])) {\n result.push(a[i]);\n }\n }\n return result;\n}\n"}, {"role": "assistant", "content": "filter the given array based on the given function `f` and return the result"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جداء_خارجي(شعاع1: سند[مـصفوفة[عـائم[64]]]، شعاع2: سند[مـصفوفة[عـائم[64]]]): مـصفوفة[مـصفوفة[عـائم[64]]] {\n\tعرف نتيجة: مـصفوفة[مـصفوفة[عـائم[64]]]؛\n\t\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < شعاع1.هات_الطول() ، دليل1++ {\n\t\tعرف سطر: مـصفوفة[عـائم[64]]؛\n\t\tلكل دليل2 = 0 ، دليل2 < شعاع2.هات_الطول() ، دليل2++ {\n\t\t\tسطر.أضف(شعاع1(دليل1)*شعاع2(دليل2))؛\n\t\t}\n\t\tنتيجة.أضف(سطر)؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "احسب الجداء الخارجي لشعاعين معطيين كل منهما ممثل على شكل مصفوفة و ارجع النتيجة"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, rotate the given array counterclockwise and return the result"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc rotate(a: ref[Array[Int]]) {\n def size: Int = a.getLength();\n\n def first_element: Int = a(0);\n\n def i: Int;\n for i = 0 , i < size - 1 , i++ {\n a(i) = a(i + 1);\n }\n\n a(size - 1) = first_element;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Array\";\nimport \"closure\";\n\n\nuse Srl;\n\n\nfunc filter(a: ref[Array[Int]], f: closure (num: Int): Bool): Array[Int] {\n def result: Array[Int];\n\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if f(a(i)) {\n result.add(a(i));\n }\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "function filter(a, condition) {\n let result = [];\n for(let i = 0; i < a.length; i++) {\n if(condition(a[i])) {\n result.push(a[i]);\n }\n }\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\nvoid erase(int a[], int n, int pos) {\n // Shift elements to left\n for (int i = pos; i < n - 1; i++)\n a[i] = a[i + 1];\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc erase(a: ref[Array[Int]], pos: Int) {\n def size: Int = a.getLength();\n\n def i: Int;\n for i = pos , i < size - 1 , i++ {\n a(i) = a(i + 1);\n }\n a.remove(size - 1);\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction multiply(a, b) {\n let rowsA = a.length, colsA = a[0].length,\n rowsB = b.length, colsB = b[0].length,\n result = new Array(rowsA);\n\n for (let i = 0; i < rowsA; i++) {\n result[i] = new Array(colsB); // initialize the current row\n for (let j = 0; j < colsB; j++) {\n result[i][j] = 0; // initialize the current cell\n for (let k = 0; k < colsA; k++) {\n result[i][j] += a[i][k] * b[k][j];\n }\n }\n }\n return result;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\ndef Matrix: alias Array[Array[Float[64]]];\n\nfunc multiply(a: ref[Matrix], b: ref[Matrix]): Matrix {\n def rowsA: Int = a.getLength();\n def rowsB: Int = b.getLength();\n def colsA: Int = a(0).getLength();\n def colsB: Int = b(0).getLength();\n \n def result: Matrix;\n\n def i: Int;\n def j: Int;\n def k: Int;\n for i = 0 , i < rowsA , i++ {\n def row: Array[Float[64]];\n for j = 0 , j < colsB , j++ {\n row.add(0);\n for k = 0 , k < colsA , k++ {\n row(j) += a(i)(k) * b(k)(j);\n }\n }\n result.add(row);\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nعرف مـصفوفة_ثنائية: لقب مـصفوفة[مـصفوفة[عـائم[64]]]؛\nعرف شـعاع: لقب مـصفوفة[عـائم[64]]؛\n\n\nدالة جداء(م: سند[مـصفوفة_ثنائية]، ش: سند[شـعاع]): شـعاع {\n\tعرف أسطر: صـحيح = م.هات_الطول()؛\n\tعرف أعمدة: صـحيح = م(0).هات_الطول()؛\n\n\tعرف نتيجة: شـعاع؛\n\t\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < أسطر ، دليل1++ {\n\t\tنتيجة.أضف(0)؛\n\t\tلكل دليل2 = 0 ، دليل2 < أعمدة ، دليل2++ {\n\t\t\t\tنتيجة(دليل1) += م(دليل1)(دليل2) * ش(دليل2)؛\n\t\t}\n\t}\n\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\ndef Matrix: alias Array[Array[Float[64]]];\ndef Vector: alias Array[Float[64]];\n\n\nfunc multiply(m: ref[Matrix], v: ref[Vector]): Vector {\n def rows: Int = m.getLength();\n def cols: Int = m(0).getLength();\n \n def result: Vector;\n\n def i: Int;\n def j: Int;\n for i = 0 , i < rows , i++ {\n result.add(0);\n for j = 0 , j < cols , j++ {\n result(i) += m(i)(j) * v(j);\n }\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\n#include <stdbool.h>\n\nbool exists(int a[], int n, int val) {\n for (int i = 0; i < n; i++) {\n if (a[i] == val) {\n return true;\n }\n }\n return false;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة موجود(م: سند[مـصفوفة[صـحيح]]، قيمة: صـحيح): ثـنائي {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا م(دليل) == قيمة {\n\t\t\tارجع صح؛\n\t\t}\n\t}\n\tارجع خطأ؛\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, Clip the values of a given array within a given range"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc clip(a: ref[Array[Int]], lower: Int, upper: Int) {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if a(i) < lower {\n a(i) = lower;\n }\n else if a(i) > upper {\n a(i) = upper;\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, Split a given string into a list of strings based on a given character"}, {"role": "assistant", "content": "#include <stdlib.h>\n\n#define MAX_STRINGS 100\n#define MAX_STRING_LEN 100\n\nchar** split(char* str, char token) {\n char** result = (char**) malloc(MAX_STRINGS * sizeof(char*));\n for(int i = 0; i < MAX_STRINGS; i++) {\n result[i] = (char*) malloc(MAX_STRING_LEN * sizeof(char));\n }\n\n int i = 0, j = 0, k = 0;\n while(str[i] != '\\0') {\n if(str[i] != token) {\n result[j][k] = str[i];\n k++;\n } else {\n result[j][k] = '\\0';\n j++;\n k = 0;\n }\n i++;\n }\n result[j][k] = '\\0';\n result[j+1] = NULL; // End of strings\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Array\";\nimport \"Srl/Math\";\n\nuse Srl;\n\n\nfunc dot_product(v1: ref[Array[Float[64]]], v2: ref[Array[Float[64]]]): Float[64] {\n def result: Float[64] = 0;\n\n def i: Int;\n for i = 0 , i < v1.getLength() , i++ {\n result += v1(i) * v2(i);\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/ريـاضيات\"؛\n\nاستخدم مـتم؛\n\n\nدالة جداء_نقطي(شعاع1: سند[مـصفوفة[عـائم[64]]]، شعاع2: سند[مـصفوفة[عـائم[64]]]): عـائم[64] {\n\tعرف نتيجة: عـائم[64] = 0؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < شعاع1.هات_الطول() ، دليل++ {\n\t\tنتيجة += شعاع1(دليل) * شعاع2(دليل)؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\n// Function to check if arr2 is a permutation of arr1\nfunction is_permutation(arr1, arr2) {\n // If sizes are not equal, return false\n if(arr1.length !== arr2.length) {\n return false;\n }\n\n // Create an array to keep track of visited elements\n let visited = new Array(arr2.length).fill(false);\n\n // For each element in arr1\n for(let i = 0; i < arr1.length; i++) {\n let found = false;\n\n // For each element in arr2\n for(let j = 0; j < arr2.length; j++) {\n // If the element in arr1 is found in arr2 and it has not been visited\n if(arr1[i] === arr2[j] && !visited[j]) {\n found = true;\n visited[j] = true; // Mark the element in arr2 as visited\n break;\n }\n }\n\n // If the element in arr1 is not found in arr2, return false\n if(!found) {\n return false;\n }\n }\n\n // If we reach here, then arr2 is a permutation of arr1\n return true;\n}\n"}, {"role": "assistant", "content": "Check whether a given array is a permutation for another given array"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nعرف مـصفوفة_ثنائية: لقب مـصفوفة[مـصفوفة[عـائم[64]]]؛\n\n\nدالة جداء(م1: سند[مـصفوفة_ثنائية]، م2: سند[مـصفوفة_ثنائية]): مـصفوفة_ثنائية {\n\tعرف أسطر_م1: صـحيح = م1.هات_الطول()؛\n\tعرف أسطر_م2: صـحيح = م2.هات_الطول()؛\n\tعرف أعمدة_م1: صـحيح = م1(0).هات_الطول()؛\n\tعرف أعمدة_م2: صـحيح = م2(0).هات_الطول()؛\n\n\tعرف نتيجة: مـصفوفة_ثنائية؛\n\t\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tعرف دليل3: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < أسطر_م1 ، دليل1++ {\n\t\tعرف سطر: مـصفوفة[عـائم[64]]؛\n\t\tلكل دليل2 = 0 ، دليل2 < أعمدة_م2 ، دليل2++ {\n\t\t\tسطر.أضف(0)؛\n\t\t\tلكل دليل3 = 0 ، دليل3 < أعمدة_م1 ، دليل3++ {\n\t\t\t\tسطر(دليل2) += م1(دليل1)(دليل3) * م2(دليل3)(دليل2)؛\n\t\t\t}\n\t\t}\n\t\tنتيجة.أضف(سطر)؛\n\t}\n\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "احسب جداء مصفوفتين ثنائيتي البعد معطاتان و ممثلتان بمصفوفة ثنائية البعد و ارجع النتيجة"}]}
{"messages": [{"role": "user", "content": "Using c, print the given array"}, {"role": "assistant", "content": "#include <stdio.h>\n\nvoid printArray(int a[], int size) {\n int i;\n for(i = 0; i < size; i++) {\n printf(\"%d \", a[i]);\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/نـم\"؛\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة اقرأ_السطر_ن(مسار_الملف: سند[نـص]، ن: صـحيح): نـص {\n\tعرف ملف: مؤشر[نـم.مـلف] = نـم.افتح_ملف(مسار_الملف، \"r\")؛\n\t\n\tعرف دليل: صـحيح؛\n\tعرف مؤقت: مـحرف = ' '؛\n\tلكل دليل = 0 ، دليل < ن - 1 ، دليل++ {\n\t\tمؤقت = ' '؛\n\t\tبينما مؤقت != '\\n' {\n\t\t\tنـم.اقرأ(مؤقت~مؤشر، 1، 1، ملف)؛\n\t\t}\n\t}\n\t\n\tعرف السطر_ن: نـص؛\n\tمؤقت = ' '؛\n\tبينما مؤقت != '\\n' {\n\t\tنـم.اقرأ(مؤقت~مؤشر، 1، 1، ملف)؛\n\t\tالسطر_ن.ألحق(مؤقت)؛\n\t}\n\t\n\tارجع السطر_ن؛\n}\n"}, {"role": "assistant", "content": "#include <stdio.h>\n#include <stdlib.h>\n\n// Function to read the n-th line of a file\nchar* read_nth_line(const char* file_path, int n) {\n FILE* file = fopen(file_path, \"r\");\n if(file == NULL) {\n printf(\"Could not open file %s\\n\", file_path);\n return NULL;\n }\n\n char* line = NULL;\n size_t len = 0;\n ssize_t read;\n\n int current_line = 0;\n while((read = getline(&line, &len, file)) != -1) {\n current_line++;\n if(current_line == n) {\n fclose(file);\n return line;\n }\n }\n\n // If we reach here, then the file has less than n lines\n fclose(file);\n free(line);\n return NULL;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction multiply(matrix, scalar) {\n let rows = matrix.length, cols = matrix[0].length;\n let result = new Array(rows);\n\n for (let i = 0; i < rows; i++) {\n result[i] = new Array(cols);\n for (let j = 0; j < cols; j++) {\n result[i][j] = matrix[i][j] * scalar;\n }\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nعرف مـصفوفة_ثنائية: لقب مـصفوفة[مـصفوفة[عـائم[64]]]؛\n\n\nدالة جداء(م: سند[مـصفوفة_ثنائية]، س: عـائم[64]): مـصفوفة_ثنائية {\n\tعرف أسطر: صـحيح = م.هات_الطول()؛\n\tعرف أعمدة: صـحيح = م(0).هات_الطول()؛\n\n\tعرف نتيجة: مـصفوفة_ثنائية؛\n\t\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < أسطر ، دليل1++ {\n\t\tنتيجة.أضف(مـصفوفة[عـائم[64]]())؛\n\t\tلكل دليل2 = 0 ، دليل2 < أعمدة ، دليل2++ {\n\t\t\t\tنتيجة(دليل1).أضف(م(دليل1)(دليل2)*س)؛\n\t\t}\n\t}\n\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة يبدأ_ب(س: سند[نـص]، سابق: سند[نـص]): ثـنائي {\n\tإذا س.هات_الطول() < سابق.هات_الطول() {\n\t\tارجع خطأ؛\n\t}\n\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < سابق.هات_الطول() ، دليل++ {\n\t\tإذا سابق(دليل) != س(دليل) {\n\t\t\tارجع خطأ؛\n\t\t}\n\t}\n\tارجع صح؛\n}\n"}, {"role": "assistant", "content": "int starts_with(const char *str, const char *prefix) {\n while(*prefix) {\n if (!(*str))\n return 0;\n if(*prefix++ != *str++)\n return 0;\n }\n return 1;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nدالة دفس(عقدة: صـحيح، مزارة: سند[مـصفوفة[ثـنائي]]، بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]) {\n\tمزارة(عقدة) = صح؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان(عقدة).هات_الطول() ، دليل++ {\n\t\tعرف عقدة_ابن: صـحيح = بيان(عقدة)(دليل)؛\n\t\tإذا !مزارة(عقدة_ابن) {\n\t\t\tدفس(عقدة_ابن، مزارة، بيان)؛\n\t\t}\n\t}\n}\n\n\nدالة عدد_المكونات_المترابطة(بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]): صـحيح {\n\tعرف مزارة: مـصفوفة[ثـنائي]؛\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان.هات_الطول() ، دليل++ {\n\t\tمزارة.أضف(خطأ)؛\n\t}\n\t\n\tعرف عدد_المكونات: صـحيح = 0؛\n\tلكل دليل = 0 ، دليل < بيان.هات_الطول() ، دليل++ {\n\t\tإذا !مزارة(دليل) {\n\t\t\tدفس(دليل، مزارة، بيان)؛\n\t\t\tعدد_المكونات++؛\n\t\t}\n\t}\n\t\n\tارجع عدد_المكونات؛\n}\n"}, {"role": "assistant", "content": "جد عدد المكونات المترابطة في بيان غير موجه معطى"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Array\";\n\nuse Srl;\n\n\nfunc insertionSort(a: ref[Array[Int]]) {\n def i: Int;\n def key: Int;\n def j: Int;\n\n for i = 1 , i < a.getLength() , i++ {\n key = a(i);\n j = i - 1;\n\n while j >= 0 && a(j) > key {\n a(j + 1) = a(j);\n j = j - 1;\n }\n a(j + 1) = key;\n }\n}\n"}, {"role": "assistant", "content": "function insertionSort(arr) {\n let n = arr.length;\n for (let i = 1; i < n; i++) {\n let key = arr[i];\n let j = i - 1;\n\n /* Move elements of arr[0..i-1], that are greater than key,\n to one position ahead of their current position */\n while (j >= 0 && arr[j] > key) {\n arr[j + 1] = arr[j];\n j = j - 1;\n }\n arr[j + 1] = key;\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/نـص\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة اختصر(م: سند[مـصفوفة[نـص]]، د: مغلفة(قيمة_سابقة: سند[نـص]، قيمة_حالية: سند[نـص])): نـص {\n\tعرف نتيجة: نـص = \"\"؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tد(نتيجة، م(دليل))؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "اختصر المصفوفة المعطاة م باستعمال الدالة المعطاة د و أرجع النتيجة"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/ريـاضيات\"؛\n\nاستخدم مـتم؛\n\n\nدالة انحراف_معياري(م: سند[مـصفوفة[صـحيح]]، متوسط: عـائم): عـائم {\n\tعرف حجم: صـحيح = م.هات_الطول()؛\n\tعرف تباين: عـائم = 0؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < حجم ، دليل++ {\n\t\tتباين += (م(دليل) - متوسط) * (م(دليل) - متوسط)؛\n\t}\n\t\n\tارجع ريـاضيات.جذر(تباين / حجم)؛\n}\n"}, {"role": "assistant", "content": "#include <math.h>\n\ndouble std(int data[], int n, float mean)\n{\n double variance = 0.0;\n\n for(int i=0; i<n; ++i)\n variance += (data[i] - mean) * (data[i] - mean);\n\n return sqrt(variance/n);\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, Invert the given array `a` and return the result"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\n\nfunc invertArray(a: ref[Array[Int]]) {\n def start: Int = 0;\n def end: Int = a.getLength() - 1;\n\n while start < end {\n def temp: Int = a(start);\n a(start) = a(end);\n a(end) = temp;\n start++;\n end--;\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة شذب(س: سند[نـص]) {\n\tعرف بداية: صـحيح = 0؛\n\tعرف نهاية: صـحيح = س.هات_الطول() - 1؛\n\t\n\tبينما (س(بداية) == ' ' || س(بداية) == '\\t' || س(بداية) == '\\n') {\n\t\tبداية++؛\n\t}\n\t\n\tبينما (س(نهاية) == ' ' || س(نهاية) == '\\t' || س(نهاية) == '\\n') {\n\t\tنهاية--؛\n\t}\n\t\n\tس = س.اجتزئ(بداية، نهاية - بداية + 1)؛\n}\n"}, {"role": "assistant", "content": "أزل أي محرف فراغ من كلتا نهايتي سلسلة نصية معطاة"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, Replace a given value with another given value in a given array"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc replace(a: ref[Array[Int]], oldValue: Int, newValue: Int) {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if a(i) == oldValue {\n a(i) = newValue;\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nconst fs = require('fs');\n\n// Function to read the content of a file into a string one character at a time\nfunction read_file(file_path) {\n const fileDescriptor = fs.openSync(file_path, 'r');\n let file_content = '';\n let buffer = Buffer.alloc(1);\n\n // Read the file one character at a time\n while(fs.readSync(fileDescriptor, buffer, 0, 1)) {\n file_content += buffer.toString();\n }\n\n fs.closeSync(fileDescriptor);\n return file_content;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/نـم\"؛\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة اقرأ_الملف(مسار_الملف: سند[نـص]): نـص {\n\tعرف ملف: مؤشر[نـم.مـلف] = نـم.افتح_ملف(مسار_الملف، \"r\")؛\n\t\n\tنـم.انتقل(ملف، 0، نـم.انـتقال._نهاية_)؛\n\tعرف حجم: صـحيح = نـم.هات_الموقع(ملف)؛\n\tنـم.انتقل(ملف، 0، نـم.انـتقال._بداية_)؛\n\t\n\tعرف المحتوى: نـص؛\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < حجم ، دليل++ {\n\t\tعرف مؤقت: مـحرف؛\n\t\tنـم.اقرأ(مؤقت~مؤشر، 1، 1، ملف)؛\n\t\tالمحتوى.ألحق(مؤقت)؛\n\t}\n\t\n\tارجع المحتوى؛\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, احسب و أرجع مساحة مضلع من إحداثيات رؤوسه"}, {"role": "assistant", "content": "اشمل \"مـتم/ريـاضيات\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nصنف نـقطة {\n\tعرف س: عـائم؛\n\tعرف ص: عـائم؛\n}\n\nدالة مساحة_مضلع(رؤوس: سند[مـصفوفة[نـقطة]]): عـائم {\n\tعرف مساحة: عـائم = 0؛\n\tعرف عدد_الرؤوس: صـحيح = رؤوس.هات_الطول()؛\n\tعرف دليل2: صـحيح = عدد_الرؤوس - 1؛\n\t\n\tعرف دليل1: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < عدد_الرؤوس ، دليل1++ {\n\t\tمساحة += (رؤوس(دليل1).س + رؤوس(دليل2).س) * (رؤوس(دليل1).ص - رؤوس(دليل2).ص)؛\n\t\tدليل2 = دليل1؛\n\t}\n\tارجع ريـاضيات.مطلق(مساحة / 2.0)؛\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, check if a given character is a digit"}, {"role": "assistant", "content": "function is_digit(c) {\n return (c >= '0' && c <= '9');\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction replace(arr, oldValue, newValue) {\n for(var i = 0; i < arr.length; i++) {\n if(arr[i] == oldValue) {\n arr[i] = newValue;\n }\n }\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة استبدل(م: سند[مـصفوفة[صـحيح]]، ق1: صـحيح، ق2: صـحيح) {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا م(دليل) == ق1 {\n\t\t\tم(دليل) = ق2؛\n\t\t}\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة فلويد_وارشال(بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]، مسافة: سند[مـصفوفة[مـصفوفة[صـحيح]]]) {\n\tعرف حجم: صـحيح = بيان.هات_الطول()؛\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tعرف دليل3: صـحيح؛\n\n\t\n\tلكل دليل1 = 0 ، دليل1 < حجم ، دليل1++ {\n\t\tمسافة.أضف(بيان(دليل1))؛\n\t}\n\t\n\tلكل دليل3 = 0 ، دليل3 < حجم ، دليل3++ {\n\t\tلكل دليل1 = 0 ، دليل1 < حجم ، دليل1++ {\n\t\t\tلكل دليل2 = 0 ، دليل2 < حجم ، دليل2++ {\n\t\t\t\tإذا مسافة(دليل1)(دليل3) + مسافة(دليل3)(دليل2) < مسافة(دليل1)(دليل2) {\n\t\t\t\t\tمسافة(دليل1)(دليل2) = مسافة(دليل1)(دليل3) + مسافة(دليل3)(دليل2)؛\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\n}\n"}, {"role": "assistant", "content": "اكتب خوارزمية Floyd Warshall لبيان معطى"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Array\";\n\nuse Srl;\n\nfunc dfs(node: Int, visited: ref[Array[Bool]], graph: ref[Array[Array[Int]]]) {\n visited(node) = true;\n\n def i: Int;\n for i = 0 , i < graph(node).getLength(), i++ {\n def childNode: Int = graph(node)(i);\n if !visited(childNode) {\n dfs(childNode, visited, graph);\n }\n }\n}\n\n\nfunc numberOfConnectedComponents(graph: ref[Array[Array[Int]]]): Int {\n def visited: Array[Bool];\n def i: Int;\n for i = 0 , i < graph.getLength() , i++ {\n visited.add(false);\n }\n\n def components: Int = 0;\n for i = 0 , i < graph.getLength() , i++ {\n if !visited(i) {\n dfs(i, visited, graph);\n components++;\n }\n }\n\n return components;\n}\n"}, {"role": "assistant", "content": "#include <stdio.h>\n\n#define MAX 100\n\nint visited[MAX];\nint matrix[MAX][MAX];\n\nvoid DFS(int v, int n) {\n visited[v] = 1;\n for(int i = 0; i < n; i++) {\n if(matrix[v][i] == 1 && visited[i] == 0) {\n DFS(i, n);\n }\n }\n}\n\nint numberOfConnectedComponents(int n) {\n int components = 0;\n for(int i = 0; i < n; i++) {\n if(visited[i] == 0) {\n DFS(i, n);\n components++;\n }\n }\n return components;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جد_من_الخلف(م: سند[مـصفوفة[صـحيح]]، قيمة: صـحيح): صحيح {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = م.هات_الطول() - 1 ، دليل != 0 ، دليل-- {\n\t\tإذا م(دليل) == قيمة {\n\t\t\tارجع دليل؛\n\t\t}\n\t}\n\tارجع -1؛\n}\n"}, {"role": "assistant", "content": "int rfind(int a[], int n, int val) {\n for (int i = n - 1; i != 0; i--) {\n if (a[i] == val) {\n return i;\n }\n }\n return -1;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\n#include <stdlib.h>\n\n#define MAX_STRINGS 100\n#define MAX_STRING_LEN 100\n\nchar** split(char* str, char token) {\n char** result = (char**) malloc(MAX_STRINGS * sizeof(char*));\n for(int i = 0; i < MAX_STRINGS; i++) {\n result[i] = (char*) malloc(MAX_STRING_LEN * sizeof(char));\n }\n\n int i = 0, j = 0, k = 0;\n while(str[i] != '\\0') {\n if(str[i] != token) {\n result[j][k] = str[i];\n k++;\n } else {\n result[j][k] = '\\0';\n j++;\n k = 0;\n }\n i++;\n }\n result[j][k] = '\\0';\n result[j+1] = NULL; // End of strings\n\n return result;\n}\n"}, {"role": "assistant", "content": "import \"Srl/String\";\nimport \"Srl/Array\"\n\nuse Srl;\n\n\nfunc split(s: ref[String], token: Char): Array[String] {\n def result: Array[String];\n\n def temp: String;\n def i: Int;\n for i = 0 , i < s.getLength() , i++ {\n if (s(i) != token) {\n temp.append(s(i));\n }\n else {\n result.add(temp);\n temp = \"\";\n }\n }\n result.add(temp);\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/ريـاضيات\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nصنف نـقطة {\n\tعرف س: عـائم؛\n\tعرف ص: عـائم؛\n}\n\nدالة احسب_مسافة(ن1: نـقطة، ن2: نـقطة): عـائم {\n\tارجع ريـاضيات.جذر(ريـاضيات.ارفع(ن2.س - ن1.س، 2.0) + ريـاضيات.ارفع(ن2.ص - ن1.ص، 2.0))؛\n}\n\nدالة جد_أقرب_نقطة(ن: نـقطة، نقاط: سند[مـصفوفة[نـقطة]]): نـقطة {\n\tعرف أقرب_مسافة: عـائم = احسب_مسافة(ن، نقاط(0))؛\n\tعرف أقرب_نقطة: نـقطة = نقاط(0)؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 1 ، دليل < نقاط.هات_الطول() ، دليل++ {\n\t\tعرف مسافة: عـائم = احسب_مسافة(ن، نقاط(دليل))؛\n\t\tإذا مسافة < أقرب_مسافة {\n\t\t\tأقرب_مسافة = مسافة؛\n\t\t\tأقرب_نقطة = نقاط(دليل)؛\n\t\t}\n\t}\n\tارجع أقرب_نقطة؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/Math\";\nimport \"Srl/Array\";\n\n\n\nuse Srl;\n\nclass Point {\n def x : Float;\n def y : Float;\n};\n\nfunc calculateDistance(a: Point, b: Point): Float {\n return Math.sqrt(Math.pow(b.x - a.x, 2.0) + Math.pow(b.y - a.y, 2.0));\n}\n\nfunc findClosestPoint(givenPoint: Point, points: ref[Array[Point]]): Point {\n def minDistance: Float = calculateDistance(givenPoint, points(0));\n def closestPoint: Point = points(0);\n\n def i: Int;\n for i = 1 , i < points.getLength() , i++ {\n def distance: Float = calculateDistance(givenPoint, points(i));\n if distance < minDistance {\n minDistance = distance;\n closestPoint = points(i);\n }\n }\n\n return closestPoint;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, تفحص فيما إذا كان أي عنصر في مصفوفة معطاة يحقق معيارًا معرفًا بدالة تعيد قيمة ثـنائية"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة تفحص_أي(م: سند[مـصفوفة[صـحيح]]، د: مغلفة(رقم: صـحيح): ثـنائي): ثـنائي {\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا د(م(دليل)) {\n\t\t\tارجع صح؛\n\t\t}\n\t}\n\n\tارجع خطأ؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\n#include <stdlib.h>\n\nvoid merge(int arr[], int l, int m, int r) {\n int i, j, k;\n int n1 = m - l + 1;\n int n2 = r - m;\n\n int L[n1], R[n2];\n\n for (i = 0; i < n1; i++)\n L[i] = arr[l + i];\n for (j = 0; j < n2; j++)\n R[j] = arr[m + 1 + j];\n\n i = 0;\n j = 0;\n k = l;\n while (i < n1 && j < n2) {\n if (L[i] <= R[j]) {\n arr[k] = L[i];\n i++;\n } else {\n arr[k] = R[j];\n j++;\n }\n k++;\n }\n\n while (i < n1) {\n arr[k] = L[i];\n i++;\n k++;\n }\n\n while (j < n2) {\n arr[k] = R[j];\n j++;\n k++;\n }\n}\n\nvoid mergeSort(int arr[], int l, int r) {\n if (l < r) {\n int m = l + (r - l) / 2;\n\n mergeSort(arr, l, m);\n mergeSort(arr, m + 1, r);\n\n merge(arr, l, m, r);\n }\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة ادمج(م: سند[مـصفوفة[صـحيح]]، يسار: صـحيح، وسط: صـحيح، يمين: صـحيح) {\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tعرف دليل3: صـحيح؛\n\t\n\tعرف حجم1: صـحيح = وسط - يسار + 1؛\n\tعرف حجم2: صـحيح = يمين - وسط؛\n\t\n\tعرف م_يسار: مـصفوفة[صـحيح]؛\n\tعرف م_يمين: مـصفوفة[صـحيح]؛\n\t\n\tلكل دليل1 = 0 ، دليل1 < حجم1 ، دليل1++ {\n\t\tم_يسار.أضف(م(يسار+دليل1))؛\n\t}\n\tلكل دليل1 = 0 ، دليل1 < حجم2 ، دليل1++ {\n\t\tم_يمين.أضف(م(وسط + 1 + دليل1))؛\n\t}\n\t\n\tدليل1 = 0؛\n\tدليل2 = 0؛\n\tدليل3 = يسار؛\n\t\n\tبينما دليل1 < حجم1 && دليل2 < حجم2 {\n\t\tإذا م_يسار(دليل1) <= م_يمين(دليل2) {\n\t\t\tم(دليل3) = م_يسار(دليل1)؛\n\t\t\tدليل1++؛\n\t\t}\n\t\tوإلا {\n\t\t\tم(دليل3) = م_يمين(دليل2)؛\n\t\t\tدليل2++؛\n\t\t}\n\t\tدليل3++؛\n\t}\n\t\n\tبينما دليل1 < حجم1 {\n\t\tم(دليل3) = م_يسار(دليل1)؛\n\t\tدليل1++؛\n\t\tدليل3++؛\n\t}\n\t\n\tبينما دليل2 < حجم2 {\n\t\tم(دليل3) = م_يمين(دليل2)؛\n\t\tدليل2++؛\n\t\tدليل3++؛\n\t}\n}\n\n\nدالة ترتيب_بالدمج(م: سند[مـصفوفة[صـحيح]]، يسار: صـحيح، يمين: صـحيح) {\n\tإذا يسار < يمين {\n\t\tعرف وسط: صـحيح = يسار + (يمين - يسار) / 2؛\n\t\t\n\t\tترتيب_بالدمج(م، يسار، وسط)؛\n\t\tترتيب_بالدمج(م، وسط + 1، يمين)؛\n\t\t\n\t\tادمج(م، يسار، وسط، يمين)؛\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\n#include <stdio.h>\n\n#define MAX 100\n\nint visited[MAX];\nint matrix[MAX][MAX];\n\nvoid DFS(int v, int n) {\n visited[v] = 1;\n for(int i = 0; i < n; i++) {\n if(matrix[v][i] == 1 && visited[i] == 0) {\n DFS(i, n);\n }\n }\n}\n\nint numberOfConnectedComponents(int n) {\n int components = 0;\n for(int i = 0; i < n; i++) {\n if(visited[i] == 0) {\n DFS(i, n);\n components++;\n }\n }\n return components;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nدالة دفس(عقدة: صـحيح، مزارة: سند[مـصفوفة[ثـنائي]]، بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]) {\n\tمزارة(عقدة) = صح؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان(عقدة).هات_الطول() ، دليل++ {\n\t\tعرف عقدة_ابن: صـحيح = بيان(عقدة)(دليل)؛\n\t\tإذا !مزارة(عقدة_ابن) {\n\t\t\tدفس(عقدة_ابن، مزارة، بيان)؛\n\t\t}\n\t}\n}\n\n\nدالة عدد_المكونات_المترابطة(بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]): صـحيح {\n\tعرف مزارة: مـصفوفة[ثـنائي]؛\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان.هات_الطول() ، دليل++ {\n\t\tمزارة.أضف(خطأ)؛\n\t}\n\t\n\tعرف عدد_المكونات: صـحيح = 0؛\n\tلكل دليل = 0 ، دليل < بيان.هات_الطول() ، دليل++ {\n\t\tإذا !مزارة(دليل) {\n\t\t\tدفس(دليل، مزارة، بيان)؛\n\t\t\tعدد_المكونات++؛\n\t\t}\n\t}\n\t\n\tارجع عدد_المكونات؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاستخدم مـتم؛\n\n\nدالة ينتمي_للأرقام(م: مـحرف): ثـنائي {\n\tارجع ( م <= '9' && م >= '0')؛\n}\n"}, {"role": "assistant", "content": "function is_digit(c) {\n return (c >= '0' && c <= '9');\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Array\";\n\nuse Srl;\n\n\nfunc selectionSort(a: ref[Array[Int]]) {\n def i: Int;\n def j: Int;\n def temp: Int;\n def min_idx: Int;\n\n for i = 0 , i < a.getLength() - 1 , i++ {\n min_idx = i;\n for j = i + 1 , j < a.getLength() , j++ {\n if a(j) < a(min_idx) {\n min_idx = j;\n }\n }\n\n temp = a(min_idx);\n a(min_idx) = a(i);\n a(i) = temp;\n }\n}\n"}, {"role": "assistant", "content": "write the selection sort algorithm for a given array"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nconst MAX_VALUE = 100000;\n\nfunction countingSort(arr) {\n let i, j;\n let count = new Array(MAX_VALUE + 1).fill(0);\n let output = [];\n\n // Count the occurrence of each number\n for(i = 0; i < arr.length; i++) {\n count[arr[i]]++;\n }\n\n // Reconstruct the sorted array\n for(i = 0; i <= MAX_VALUE; i++) {\n for(j = 0; j < count[i]; j++) {\n output.push(i);\n }\n }\n\n return output;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\n\ndef MAX_VALUE: Int = 100000;\n\nfunc countingSort(a: ref[Array[Int]]) {\n def i: Int;\n def j: Int;\n def idx: Int;\n\n def count: Array[Int];\n for i = 0 , i < MAX_VALUE , i++ {\n count.add(0);\n }\n\n for i = 0 , i < a.getLength() , i++ {\n count(a(i))++;\n }\n\n for i = 0 , i < MAX_VALUE , i++ {\n for j = 0 , j < count(i) , j++ {\n a(idx++) = i;\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nint find_most_frequent(int arr[], int n) {\n int max_count = 0, res = -1;\n\n for (int i = 0; i < n; i++) {\n int count = 1;\n for (int j = i + 1; j < n; j++)\n if (arr[i] == arr[j])\n count++;\n if (count > max_count) {\n max_count = count;\n res = arr[i];\n }\n }\n\n return res;\n}\n"}, {"role": "assistant", "content": "find and return the most frequent item in a given array"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Array\";\n\nuse Srl;\n\nfunc dfs(node: Int, visited: ref[Array[Bool]], graph: ref[Array[Array[Int]]]) {\n visited(node) = true;\n\n def i: Int;\n for i = 0 , i < graph(node).getLength(), i++ {\n def childNode: Int = graph(node)(i);\n if !visited(childNode) {\n dfs(childNode, visited, graph);\n }\n }\n}\n\n\nfunc numberOfConnectedComponents(graph: ref[Array[Array[Int]]]): Int {\n def visited: Array[Bool];\n def i: Int;\n for i = 0 , i < graph.getLength() , i++ {\n visited.add(false);\n }\n\n def components: Int = 0;\n for i = 0 , i < graph.getLength() , i++ {\n if !visited(i) {\n dfs(i, visited, graph);\n components++;\n }\n }\n\n return components;\n}\n"}, {"role": "assistant", "content": "let visited = [];\n\nfunction DFS(v, adjList) {\n visited[v] = true;\n for(let i = 0; i < adjList[v].length; i++) {\n if(!visited[adjList[v][i]]) {\n DFS(adjList[v][i], adjList);\n }\n }\n}\n\nfunction numberOfConnectedComponents(adjList) {\n let components = 0;\n for(let i = 0; i < adjList.length; i++) {\n if(!visited[i]) {\n DFS(i, adjList);\n components++;\n }\n }\n return components;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\n#include <stdio.h>\n\n#define MAX 100\n\nint visited[MAX];\nint matrix[MAX][MAX];\n\nvoid DFS(int v, int n) {\n visited[v] = 1;\n for(int i = 0; i < n; i++) {\n if(matrix[v][i] == 1 && visited[i] == 0) {\n DFS(i, n);\n }\n }\n}\n\nint numberOfConnectedComponents(int n) {\n int components = 0;\n for(int i = 0; i < n; i++) {\n if(visited[i] == 0) {\n DFS(i, n);\n components++;\n }\n }\n return components;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\nfunc dfs(node: Int, visited: ref[Array[Bool]], graph: ref[Array[Array[Int]]]) {\n visited(node) = true;\n\n def i: Int;\n for i = 0 , i < graph(node).getLength(), i++ {\n def childNode: Int = graph(node)(i);\n if !visited(childNode) {\n dfs(childNode, visited, graph);\n }\n }\n}\n\n\nfunc numberOfConnectedComponents(graph: ref[Array[Array[Int]]]): Int {\n def visited: Array[Bool];\n def i: Int;\n for i = 0 , i < graph.getLength() , i++ {\n visited.add(false);\n }\n\n def components: Int = 0;\n for i = 0 , i < graph.getLength() , i++ {\n if !visited(i) {\n dfs(i, visited, graph);\n components++;\n }\n }\n\n return components;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, Find the intersection point of two given lines (the line represented by three values `a`, `b`, `c` as ax + by + c = 0) and return it, in case of parallel line return null or empty array"}, {"role": "assistant", "content": "#include <stdlib.h>\n\n// Function to find the intersection point of two lines\ndouble* findIntersection(double a1, double b1, double c1, double a2, double b2, double c2) {\n // Check if the lines are parallel\n if(a1*b2 - a2*b1 == 0) {\n return NULL;\n }\n\n double* result = (double*)malloc(2 * sizeof(double));\n result[0] = (b1*c2 - b2*c1) / (a1*b2 - a2*b1);\n result[1] = (a2*c1 - a1*c2) / (a1*b2 - a2*b1);\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction toUpperCase(s) {\n let result = '';\n for(let i = 0; i < s.length; i++){\n let code = s.charCodeAt(i);\n if(code >= 97 && code <= 122){\n result += String.fromCharCode(code - 97 + 65);\n } else {\n result += s[i];\n }\n }\n return result;\n}\n"}, {"role": "assistant", "content": "import \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc toUpperCase(s: ref[String]): String {\n\tdef result: String = \"\";\n def i: Int;\n\tdef c: Char;\n\tfor i = 0 , i < s.getLength() , i++ {\n\t\tif (s(i) >= 'a' && s(i) <= 'z') {\n\t\t\tc = s(i) - 'a' + 'A';\n\t\t}\n\t\telse {\n\t\t\tc = s(i);\n\t\t}\n\t\tresult += c;\n\t}\n\treturn result;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction vectorNorm(vector) {\n let sum = 0.0;\n for (let i = 0; i < vector.length; i++) {\n sum += vector[i] * vector[i];\n }\n return Math.sqrt(sum);\n}\n"}, {"role": "assistant", "content": "Calculate the norm of a given vector which is represented by an array and return the result"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction Point(x, y) {\n this.x = x;\n this.y = y;\n}\n\nfunction areCollinear(p1, p2, p3) {\n // Calculate the slopes of the lines formed by (p1, p2) and (p1, p3)\n // If the slopes are equal, then p1, p2 and p3 are collinear\n return (p2.y - p1.y) * (p3.x - p1.x) === (p3.y - p1.y) * (p2.x - p1.x);\n}\n"}, {"role": "assistant", "content": "check if three given points are collinear"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction selectionSort(arr) {\n let n = arr.length;\n\n for(let i = 0; i < n; i++) {\n // Finding the smallest number in the subarray\n let min = i;\n for(let j = i+1; j < n; j++){\n if(arr[j] < arr[min]) {\n min=j; \n }\n }\n // Swapping the elements\n let tmp = arr[i]; \n arr[i] = arr[min];\n arr[min] = tmp; \n }\n return arr;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\n\nfunc selectionSort(a: ref[Array[Int]]) {\n def i: Int;\n def j: Int;\n def temp: Int;\n def min_idx: Int;\n\n for i = 0 , i < a.getLength() - 1 , i++ {\n min_idx = i;\n for j = i + 1 , j < a.getLength() , j++ {\n if a(j) < a(min_idx) {\n min_idx = j;\n }\n }\n\n temp = a(min_idx);\n a(min_idx) = a(i);\n a(i) = temp;\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction split(str, token) {\n let result = [];\n let temp = \"\";\n\n for(let i = 0; i < str.length; i++) {\n if(str[i] !== token) {\n temp += str[i];\n } else {\n result.push(temp);\n temp = \"\";\n }\n }\n\n // Push the last substring if it's not empty\n if(temp !== \"\") {\n result.push(temp);\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/نـص\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جزئ(س: سند[نـص]، رمز: مـحرف): مـصفوفة[نـص] {\n\tعرف نتيجة: مـصفوفة[نـص]؛\n\t\n\tعرف مؤقت: نـص؛\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) != رمز {\n\t\t\tمؤقت.ألحق(س(دليل))؛\n\t\t}\n\t\tوإلا {\n\t\t\tنتيجة.أضف(مؤقت)؛\n\t\t\tمؤقت = \"\"؛\n\t\t}\n\t}\n\tنتيجة.أضف(مؤقت)؛\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\n#include <stdlib.h>\n\n#define MAX_STRINGS 100\n#define MAX_STRING_LEN 100\n\nchar** split(char* str, char token) {\n char** result = (char**) malloc(MAX_STRINGS * sizeof(char*));\n for(int i = 0; i < MAX_STRINGS; i++) {\n result[i] = (char*) malloc(MAX_STRING_LEN * sizeof(char));\n }\n\n int i = 0, j = 0, k = 0;\n while(str[i] != '\\0') {\n if(str[i] != token) {\n result[j][k] = str[i];\n k++;\n } else {\n result[j][k] = '\\0';\n j++;\n k = 0;\n }\n i++;\n }\n result[j][k] = '\\0';\n result[j+1] = NULL; // End of strings\n\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/نـص\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جزئ(س: سند[نـص]، رمز: مـحرف): مـصفوفة[نـص] {\n\tعرف نتيجة: مـصفوفة[نـص]؛\n\t\n\tعرف مؤقت: نـص؛\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) != رمز {\n\t\t\tمؤقت.ألحق(س(دليل))؛\n\t\t}\n\t\tوإلا {\n\t\t\tنتيجة.أضف(مؤقت)؛\n\t\t\tمؤقت = \"\"؛\n\t\t}\n\t}\n\tنتيجة.أضف(مؤقت)؛\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nconst MAX_VALUE = 100000;\n\nfunction countingSort(arr) {\n let i, j;\n let count = new Array(MAX_VALUE + 1).fill(0);\n let output = [];\n\n // Count the occurrence of each number\n for(i = 0; i < arr.length; i++) {\n count[arr[i]]++;\n }\n\n // Reconstruct the sorted array\n for(i = 0; i <= MAX_VALUE; i++) {\n for(j = 0; j < count[i]; j++) {\n output.push(i);\n }\n }\n\n return output;\n}\n"}, {"role": "assistant", "content": "write the counting sort algorithm for a given array"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Array\";\n\nuse Srl;\n\nfunc isCyclic(node: Int, visited: ref[Array[Int]], graph: ref[Array[Array[Int]]]): Bool {\n if visited(node) == 2 {\n return true;\n }\n visited(node) = 1;\n\n def i: Int;\n for i = 0 , i < graph(node).getLength(), i++ {\n def childNode: Int = graph(node)(i);\n if visited(childNode) == 1 {\n return true;\n }\n else if visited(childNode) == 0 && isCyclic(childNode, visited, graph){\n return true;\n }\n }\n visited(node) = 2;\n return false;\n}\n\n\nfunc isDAG(graph: ref[Array[Array[Int]]]): Bool {\n def visited: Array[Int];\n def i: Int;\n\n for i = 0 , i < graph.getLength() , i++ {\n def j: Int;\n for j = 0 , j < graph.getLength() , j++ {\n visited.add(0);\n }\n if isCyclic(i, visited, graph) {\n return false;\n }\n visited.clear();\n }\n\n return true;\n}\n"}, {"role": "assistant", "content": "let graph = [];\nlet visited = [];\nlet n;\n\nfunction isCyclic(i) {\n if (visited[i] === 2) {\n return true;\n }\n visited[i] = 1;\n for (let j = 0; j < graph[i].length; j++) {\n let node = graph[i][j];\n if (visited[node] === 1) return true;\n else if (visited[node] === 0 && isCyclic(node)) return true;\n }\n visited[i] = 2;\n return false;\n}\n\nfunction isDAG() {\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < n; j++) {\n visited[j] = 0;\n }\n if (isCyclic(i)) {\n return false;\n }\n }\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction find_char(s, c) {\n for (let i = 0; i < s.length; i++) {\n if (s[i] === c) {\n return i;\n }\n }\n return -1;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة جد_المحرف(س: سند[نـص]، م: مـحرف): صـحيح {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) == م {\n\t\t\tارجع دليل؛\n\t\t}\n\t}\n\tارجع -1؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction std(data, n, mean) {\n let variance = 0.0;\n\n for(let i=0; i<n; ++i)\n variance += (data[i] - mean) * (data[i] - mean);\n\n return Math.sqrt(variance/n);\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"Srl/Math\";\n\n\nuse Srl;\n\n\nfunc std(a: ref[Array[Int]], mean: Float): Float {\n def size: Int = a.getLength();\n def variance: Float = 0;\n\n def i: Int;\n for i = 0 , i < size , i++ {\n variance += (a(i) - mean) * ( a(i) - mean);\n }\n\n return Math.sqrt(variance / size);\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nvoid clip(int arr[], int n, int lower, int upper) {\n for(int i = 0; i < n; i++) {\n if(arr[i] < lower) {\n arr[i] = lower;\n } else if(arr[i] > upper) {\n arr[i] = upper;\n }\n }\n}\n"}, {"role": "assistant", "content": "Clip the values of a given array within a given range"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/ريـاضيات\"؛\n\nاستخدم مـتم؛\n\n\nدالة انحراف_معياري(م: سند[مـصفوفة[صـحيح]]، متوسط: عـائم): عـائم {\n\tعرف حجم: صـحيح = م.هات_الطول()؛\n\tعرف تباين: عـائم = 0؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < حجم ، دليل++ {\n\t\tتباين += (م(دليل) - متوسط) * (م(دليل) - متوسط)؛\n\t}\n\t\n\tارجع ريـاضيات.جذر(تباين / حجم)؛\n}\n"}, {"role": "assistant", "content": "function std(data, n, mean) {\n let variance = 0.0;\n\n for(let i=0; i<n; ++i)\n variance += (data[i] - mean) * (data[i] - mean);\n\n return Math.sqrt(variance/n);\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Array\";\nimport \"closure\";\n\n\nuse Srl;\n\n\nfunc filter(a: ref[Array[Int]], f: closure (num: Int): Bool): Array[Int] {\n def result: Array[Int];\n\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if f(a(i)) {\n result.add(a(i));\n }\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "#include <stdbool.h>\n\nvoid filter(int a[], int size, int result[], int *newSize, bool (*condition)(int)) {\n *newSize = 0;\n for (int i = 0; i < size; i++) {\n if (condition(a[i])) {\n result[(*newSize)++] = a[i];\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction selectionSort(arr) {\n let n = arr.length;\n\n for(let i = 0; i < n; i++) {\n // Finding the smallest number in the subarray\n let min = i;\n for(let j = i+1; j < n; j++){\n if(arr[j] < arr[min]) {\n min=j; \n }\n }\n // Swapping the elements\n let tmp = arr[i]; \n arr[i] = arr[min];\n arr[min] = tmp; \n }\n return arr;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة الترتيب_بالاختيار(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tعرف مؤقت: صـحيح؛\n\tعرف أصغر_دليل: صـحيح؛\n\t\n\tلكل دليل1 = 0 ، دليل1 < م.هات_الطول() - 1 ، دليل1++ {\n\t\tأصغر_دليل = دليل1؛\n\t\t\n\t\tلكل دليل2 = دليل1 + 1 ، دليل2 < م.هات_الطول() ، دليل2++ {\n\t\t\tإذا م(دليل2) < م(أصغر_دليل) {\n\t\t\t\tأصغر_دليل = دليل2؛\n\t\t\t}\n\t\t}\n\t\t\n\t\tمؤقت = م(أصغر_دليل)؛\n\t\tم(أصغر_دليل) = م(دليل1)؛\n\t\tم(دليل1) = مؤقت؛\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة إلى_حالة_صغيرة(س: سند[نـص]): نـص {\n\tعرف نتيجة: نـص = \"\"؛\n\n\tعرف دليل: صـحيح؛\n\tعرف م: مـحرف؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) >= 'A' && س(دليل) <= 'Z' {\n\t\t\tم = س(دليل) - 'A' + 'a'؛\n\t\t}\n\t\tوإلا {\n\t\t\tم = س(دليل)؛\n\t\t}\n\t\tنتيجة += م؛\n\t}\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc toLowerCase(s: ref[String]): String {\n\tdef result: String = \"\";\n def i: Int;\n\tdef c: Char;\n\tfor i = 0 , i < s.getLength() , i++ {\n\t\tif (s(i) >= 'A' && s(i) <= 'Z') {\n\t\t\tc = s(i) - 'A' + 'a';\n\t\t}\n\t\telse {\n\t\t\tc = s(i);\n\t\t}\n\t\tresult += c;\n\t}\n\treturn result;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\n#include <stdio.h>\n#include <string.h>\n\nvoid appendLogEntry(char *filename, char *logEntry) {\n FILE *file = fopen(filename, \"a\");\n\n fwrite(logEntry, 1, strlen(logEntry), file);\n fwrite(\"\\n\", 1, 1, file);\n fclose(file);\n}\n"}, {"role": "assistant", "content": "Append a given log entry to a file given its path"}]}
{"messages": [{"role": "user", "content": "What this code do?\nuse Srl;\n\n\nfunc is_alpha(c: Char): Bool {\n return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');\n}\n"}, {"role": "assistant", "content": "check if a given character is from the alphabet"}]}
{"messages": [{"role": "user", "content": "What this code do?\nint sum(int a[], int n) {\n int result = 0;\n for (int i = 0; i < n; i++) {\n result += a[i];\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "Find and return the sum of the given array `a`"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, اختبر فيما إذا كانت 3 نقاط معطاة على استقامة واحدة"}, {"role": "assistant", "content": "استخدم مـتم؛\n\n\nصنف نـقطة {\n\tعرف س: صـحيح؛\n\tعرف ص: صـحيح؛\n}\n\nدالة على_خط_مستقيم(ن1: نـقطة، ن2: نـقطة، ن3: نـقطة): ثـنائي {\n\tارجع (ن2.ص - ن1.ص) * (ن3.س - ن1.ص) == (ن3.ص - ن1.ص) * (ن2.س - ن1.س)؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc toUpperCase(s: ref[String]): String {\n\tdef result: String = \"\";\n def i: Int;\n\tdef c: Char;\n\tfor i = 0 , i < s.getLength() , i++ {\n\t\tif (s(i) >= 'a' && s(i) <= 'z') {\n\t\t\tc = s(i) - 'a' + 'A';\n\t\t}\n\t\telse {\n\t\t\tc = s(i);\n\t\t}\n\t\tresult += c;\n\t}\n\treturn result;\n}\n"}, {"role": "assistant", "content": "convert string to uppercase and return the result"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/نـم\"؛\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة ألحق_سجل(مسار_الملف: سند[نـص]، سجل: سند[نـص]) {\n\tعرف ملف: مؤشر[نـم.مـلف] = نـم.افتح_ملف(مسار_الملف، \"a\")؛\n\t\n\tنـم.اكتب(سجل.صوان، 1، سجل.هات_الطول()، ملف)؛\n\tنـم.اكتب(\"\\ج\"، 1، 1، ملف)؛\n\tنـم.اغلق_ملف(ملف)؛\n}\n"}, {"role": "assistant", "content": "#include <stdio.h>\n#include <string.h>\n\nvoid appendLogEntry(char *filename, char *logEntry) {\n FILE *file = fopen(filename, \"a\");\n\n fwrite(logEntry, 1, strlen(logEntry), file);\n fwrite(\"\\n\", 1, 1, file);\n fclose(file);\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\n#include <stdbool.h>\n\ntypedef struct {\n int x;\n int y;\n} Point;\n\nbool areCollinear(Point p1, Point p2, Point p3) {\n // Calculate the slopes of the lines formed by (p1, p2) and (p1, p3)\n // If the slopes are equal, then p1, p2 and p3 are collinear\n return (p2.y - p1.y) * (p3.x - p1.x) == (p3.y - p1.y) * (p2.x - p1.x);\n}\n"}, {"role": "assistant", "content": "استخدم مـتم؛\n\n\nصنف نـقطة {\n\tعرف س: صـحيح؛\n\tعرف ص: صـحيح؛\n}\n\nدالة على_خط_مستقيم(ن1: نـقطة، ن2: نـقطة، ن3: نـقطة): ثـنائي {\n\tارجع (ن2.ص - ن1.ص) * (ن3.س - ن1.ص) == (ن3.ص - ن1.ص) * (ن2.س - ن1.س)؛\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, Replace a given char with another given char in a given string and return the new string"}, {"role": "assistant", "content": "function replace(str, oldChar, newChar) {\n var result = \"\";\n for(var i = 0; i < str.length; i++) {\n if(str[i] == oldChar) {\n result += newChar;\n } else {\n result += str[i];\n }\n }\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction rotate(a) {\n const n = a.length;\n\n let first_element = a[0];\n\n for (let i = 0; i < n - 1; i++) {\n a[i] = a[i + 1];\n }\n\n a[n - 1] = first_element;\n}\n"}, {"role": "assistant", "content": "rotate the given array counterclockwise and return the result"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\nvoid foreach(int a[], int n, int (*f)(int)) {\n for(int i = 0; i < n; i++) {\n a[i] = f(a[i]);\n }\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"closure\";\n\nuse Srl;\n\n\nfunc foreach(a: ref[Array[Int]], f: closure(element: Int): Int) {\n def i: Int;\n \n for i = 0 , i < a.getLength() , i++ {\n a(i) = f(a(i));\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Array\";\n\nuse Srl;\n\n\nfunc outer_product(v1: ref[Array[Float[64]]], v2: ref[Array[Float[64]]]): Array[Array[Float[64]]] {\n def result: Array[Array[Float[64]]];\n\n def i: Int;\n def j: Int;\n for i = 0 , i < v1.getLength() , i++ {\n def row: Array[Float[64]];\n for j = 0 , j < v2.getLength() , j++ {\n row.add(v1(i)*v2(j));\n }\n result.add(row);\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جداء_خارجي(شعاع1: سند[مـصفوفة[عـائم[64]]]، شعاع2: سند[مـصفوفة[عـائم[64]]]): مـصفوفة[مـصفوفة[عـائم[64]]] {\n\tعرف نتيجة: مـصفوفة[مـصفوفة[عـائم[64]]]؛\n\t\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < شعاع1.هات_الطول() ، دليل1++ {\n\t\tعرف سطر: مـصفوفة[عـائم[64]]؛\n\t\tلكل دليل2 = 0 ، دليل2 < شعاع2.هات_الطول() ، دليل2++ {\n\t\t\tسطر.أضف(شعاع1(دليل1)*شعاع2(دليل2))؛\n\t\t}\n\t\tنتيجة.أضف(سطر)؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, calculate and return the standard deviation of the given array"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"Srl/Math\";\n\n\nuse Srl;\n\n\nfunc std(a: ref[Array[Int]], mean: Float): Float {\n def size: Int = a.getLength();\n def variance: Float = 0;\n\n def i: Int;\n for i = 0 , i < size , i++ {\n variance += (a(i) - mean) * ( a(i) - mean);\n }\n\n return Math.sqrt(variance / size);\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/String\";\nimport \"Srl/Array\"\n\nuse Srl;\n\n\nfunc split(s: ref[String], token: Char): Array[String] {\n def result: Array[String];\n\n def temp: String;\n def i: Int;\n for i = 0 , i < s.getLength() , i++ {\n if (s(i) != token) {\n temp.append(s(i));\n }\n else {\n result.add(temp);\n temp = \"\";\n }\n }\n result.add(temp);\n return result;\n}\n"}, {"role": "assistant", "content": "Split a given string into a list of strings based on a given character"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, احسب طويلة شعاع معطى ممثل على شكل مصفوفة و ارجع النتيجة"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/ريـاضيات\"؛\n\nاستخدم مـتم؛\n\n\nدالة طويلة_شعاع(شعاع: سند[مـصفوفة[عـائم[64]]]): عـائم[64] {\n\tعرف مجموع: عـائم[64] = 0؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < شعاع.هات_الطول() ، دليل++ {\n\t\tمجموع += شعاع(دليل) * شعاع(دليل)؛\n\t}\n\t\n\tارجع ريـاضيات.جذر(مجموع)؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction char_exists(s, c) {\n for (let i = 0; i < s.length; i++) {\n if (s[i] === c) {\n return true;\n }\n }\n return false;\n}\n"}, {"role": "assistant", "content": "check if a given string contains a given char"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة فلتر(م: سند[مـصفوفة[صـحيح]]، د: مغلفة(رقم: صـحيح): ثـنائي): مـصفوفة[صـحيح] {\n\tعرف نتيجة: مـصفوفة[صـحيح]؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا د(م(دليل)) {\n\t\t\tنتيجة.أضف(م(دليل))؛\n\t\t}\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "#include <stdbool.h>\n\nvoid filter(int a[], int size, int result[], int *newSize, bool (*condition)(int)) {\n *newSize = 0;\n for (int i = 0; i < size; i++) {\n if (condition(a[i])) {\n result[(*newSize)++] = a[i];\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, Check if a given undirected graph is tree"}, {"role": "assistant", "content": "#include <stdio.h>\n\n#define MAX 100\n\nint visited[MAX];\nint matrix[MAX][MAX];\n\nint DFS(int v, int parent, int n) {\n visited[v] = 1;\n for(int i = 0; i < n; i++) {\n if(matrix[v][i] == 1) {\n if(!visited[i]) {\n if(DFS(i, v, n)) {\n return 1;\n }\n } else if(i != parent) {\n return 1;\n }\n }\n }\n return 0;\n}\n\nint isTree(int n) {\n if(DFS(0, -1, n)) {\n return 0;\n }\n for(int i = 0; i < n; i++) {\n if(!visited[i]) {\n return 0;\n }\n }\n return 1;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاستخدم مـتم؛\n\n\nدالة ينتمي_للأبجدية(م: مـحرف): ثـنائي {\n\tارجع ( م <= 'Z' && م >= 'A') || ( م <= 'z' && م >= 'a')؛\n}\n"}, {"role": "assistant", "content": "function is_alphabet(c) {\n return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, write the merge sort algorithm for a given array"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\n\nfunc merge(a: ref[Array[Int]], l: Int, m: Int, r: Int) {\n def i: Int;\n def j: Int;\n def k: Int;\n\n def n1: Int = m - l + 1;\n def n2: Int = r - m;\n\n def L: Array[Int];\n def R: Array[Int];\n\n for i = 0 , i < n1 , i++ {\n L.add(a(l+i));\n }\n for i = 0 , i < n2 , i++ {\n R.add(a(m + 1 + i));\n }\n\n i = 0;\n j = 0;\n k = l;\n while i < n1 && j < n2 {\n if L(i) <= R(j) {\n a(k) = L(i);\n i++;\n }\n else {\n a(k) = R(j);\n j++;\n }\n k++;\n }\n\n while i < n1 {\n a(k) = L(i);\n i++;\n k++;\n }\n\n while j < n2 {\n a(k) = R(j);\n j++;\n k++;\n }\n}\n\nfunc mergeSort(a: ref[Array[Int]], l: Int, r: Int) {\n if l < r {\n def m: Int = l + (r - l) / 2;\n\n mergeSort(a, l, m);\n mergeSort(a, m + 1, r);\n\n merge(a, l, m, r);\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/String\";\n\nuse Srl;\n\n\nfunction invertString(s) {\n def size: Int = s.getLength();\n def result: String = \"\";\n\n def i: Int;\n for i = size - 1 , i >= 0 , i-- {\n result += s(i);\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "#include <string.h>\n\nvoid invert_string(char* str) {\n int len = strlen(str);\n for(int i = 0; i < len / 2; i++) {\n char temp = str[i];\n str[i] = str[len - i - 1];\n str[len - i - 1] = temp;\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/نـم\"؛\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة اقرأ_السطر_ن(مسار_الملف: سند[نـص]، ن: صـحيح): نـص {\n\tعرف ملف: مؤشر[نـم.مـلف] = نـم.افتح_ملف(مسار_الملف، \"r\")؛\n\t\n\tعرف دليل: صـحيح؛\n\tعرف مؤقت: مـحرف = ' '؛\n\tلكل دليل = 0 ، دليل < ن - 1 ، دليل++ {\n\t\tمؤقت = ' '؛\n\t\tبينما مؤقت != '\\n' {\n\t\t\tنـم.اقرأ(مؤقت~مؤشر، 1، 1، ملف)؛\n\t\t}\n\t}\n\t\n\tعرف السطر_ن: نـص؛\n\tمؤقت = ' '؛\n\tبينما مؤقت != '\\n' {\n\t\tنـم.اقرأ(مؤقت~مؤشر، 1، 1، ملف)؛\n\t\tالسطر_ن.ألحق(مؤقت)؛\n\t}\n\t\n\tارجع السطر_ن؛\n}\n"}, {"role": "assistant", "content": "const fs = require('fs');\nconst readline = require('readline');\n\nfunction read_nth_line(file_path, n) {\n return new Promise((resolve, reject) => {\n const fileStream = fs.createReadStream(file_path);\n\n const rl = readline.createInterface({\n input: fileStream,\n crlfDelay: Infinity\n });\n\n let line_no = 0;\n\n rl.on('line', (line) => {\n line_no++;\n if(line_no === n) {\n resolve(line);\n rl.close();\n }\n });\n\n rl.on('close', () => {\n if(line_no < n) {\n reject(new Error(`The file has less than ${n} lines.`));\n }\n });\n });\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction reverseArray(a) {\n let start = 0;\n let end = a.length - 1;\n\n while (start < end) {\n let temp = a[start];\n a[start] = a[end];\n a[end] = temp;\n\n start++;\n end--;\n }\n}\n"}, {"role": "assistant", "content": "Invert the given array `a` and return the result"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, اكتب خوارزمية الفرز بالحشر لمصفوفة معطاة"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة الترتيب_بالحشر(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف دليل1: صـحيح؛\n\tعرف مفتاح: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\t\n\tلكل دليل1 = 1 ، دليل1 < م.هات_الطول() ، دليل1++ {\n\t\tمفتاح = م(دليل1)؛\n\t\tدليل2 = دليل1 - 1؛\n\t\t\n\t\tبينما دليل2 >= 0 && م(دليل2) > مفتاح {\n\t\t\tم(دليل2 + 1) = م(دليل2)؛\n\t\t\tدليل2 = دليل2 - 1؛\n\t\t}\n\t\tم(دليل2 + 1) = مفتاح؛\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction max(a) {\n let result = a[0];\n for (let i = 1 ; i < a.length ; i++) {\n if (result < a[i]) {\n result = a[i];\n }\n }\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة أكبر_عنصر(م: سند[مـصفوفة[صـحيح]]): صـحيح {\n\n\tعرف نتيجة: صـحيح = م(0)؛\n\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 1 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا م(دليل) > نتيجة {\n\t\t\tنتيجة = م(دليل)؛\n\t\t}\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, احسب الجداء النقطي لشعاعين معطيين كل منهما ممثل على شكل مصفوفة و ارجع النتيجة"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/ريـاضيات\"؛\n\nاستخدم مـتم؛\n\n\nدالة جداء_نقطي(شعاع1: سند[مـصفوفة[عـائم[64]]]، شعاع2: سند[مـصفوفة[عـائم[64]]]): عـائم[64] {\n\tعرف نتيجة: عـائم[64] = 0؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < شعاع1.هات_الطول() ، دليل++ {\n\t\tنتيجة += شعاع1(دليل) * شعاع2(دليل)؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, find and return the closest point to a given point from a given set of points"}, {"role": "assistant", "content": "#include <math.h>\n\ntypedef struct {\n double x;\n double y;\n} Point;\n\ndouble calculateDistance(Point a, Point b) {\n return sqrt(pow(b.x - a.x, 2) + pow(b.y - a.y, 2));\n}\n\nPoint findClosestPoint(Point givenPoint, Point points[], int size) {\n double minDistance = calculateDistance(givenPoint, points[0]);\n Point closestPoint = points[0];\n\n for(int i = 1; i < size; i++) {\n double distance = calculateDistance(givenPoint, points[i]);\n if(distance < minDistance) {\n minDistance = distance;\n closestPoint = points[i];\n }\n }\n\n return closestPoint;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\n#define V 4\n\nvoid floydWarshall (int graph[V][V], int dist[V][V]) \n{ \n int i, j, k; \n \n for (i = 0; i < V; i++) \n for (j = 0; j < V; j++) \n dist[i][j] = graph[i][j]; \n \n for (k = 0; k < V; k++) \n { \n for (i = 0; i < V; i++) \n { \n for (j = 0; j < V; j++) \n { \n if (dist[i][k] + dist[k][j] < dist[i][j]) \n dist[i][j] = dist[i][k] + dist[k][j]; \n } \n } \n }\n} \n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة فلويد_وارشال(بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]، مسافة: سند[مـصفوفة[مـصفوفة[صـحيح]]]) {\n\tعرف حجم: صـحيح = بيان.هات_الطول()؛\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tعرف دليل3: صـحيح؛\n\n\t\n\tلكل دليل1 = 0 ، دليل1 < حجم ، دليل1++ {\n\t\tمسافة.أضف(بيان(دليل1))؛\n\t}\n\t\n\tلكل دليل3 = 0 ، دليل3 < حجم ، دليل3++ {\n\t\tلكل دليل1 = 0 ، دليل1 < حجم ، دليل1++ {\n\t\t\tلكل دليل2 = 0 ، دليل2 < حجم ، دليل2++ {\n\t\t\t\tإذا مسافة(دليل1)(دليل3) + مسافة(دليل3)(دليل2) < مسافة(دليل1)(دليل2) {\n\t\t\t\t\tمسافة(دليل1)(دليل2) = مسافة(دليل1)(دليل3) + مسافة(دليل3)(دليل2)؛\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Array\";\nimport \"closure\";\n\nuse Srl;\n\n\nfunc foreach(a: ref[Array[Int]], f: closure(element: Int): Int) {\n def i: Int;\n \n for i = 0 , i < a.getLength() , i++ {\n a(i) = f(a(i));\n }\n}\n"}, {"role": "assistant", "content": "function accumulate(a, f) {\n for (let i = 0 ; i < a.length ; i++) {\n a[i] = f(a[i]);\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\nint find_most_frequent(int arr[], int n) {\n int max_count = 0, res = -1;\n\n for (int i = 0; i < n; i++) {\n int count = 1;\n for (int j = i + 1; j < n; j++)\n if (arr[i] == arr[j])\n count++;\n if (count > max_count) {\n max_count = count;\n res = arr[i];\n }\n }\n\n return res;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جد_أكثر_عنصر_مكرر(م: سند[مـصفوفة[صـحيح]]): صـحيح {\n\tعرف أكثر_تكرار: صـحيح = 0؛\n\tعرف نتيجة: صـحيح = -1؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tعرف عداد: صـحيح = 1؛\n\t\t\n\t\tعرف دليل2: صـحيح؛\n\t\tلكل دليل2 = دليل + 1 ، دليل2 < م.هات_الطول() ، دليل2++ {\n\t\t\tإذا م(دليل2) == م(دليل) {\n\t\t\t\tعداد++؛\n\t\t\t}\n\t\t}\n\t\t\n\t\tإذا عداد > أكثر_تكرار {\n\t\t\tأكثر_تكرار = عداد؛\n\t\t\tنتيجة = م(دليل)؛\n\t\t}\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة فلويد_وارشال(بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]، مسافة: سند[مـصفوفة[مـصفوفة[صـحيح]]]) {\n\tعرف حجم: صـحيح = بيان.هات_الطول()؛\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tعرف دليل3: صـحيح؛\n\n\t\n\tلكل دليل1 = 0 ، دليل1 < حجم ، دليل1++ {\n\t\tمسافة.أضف(بيان(دليل1))؛\n\t}\n\t\n\tلكل دليل3 = 0 ، دليل3 < حجم ، دليل3++ {\n\t\tلكل دليل1 = 0 ، دليل1 < حجم ، دليل1++ {\n\t\t\tلكل دليل2 = 0 ، دليل2 < حجم ، دليل2++ {\n\t\t\t\tإذا مسافة(دليل1)(دليل3) + مسافة(دليل3)(دليل2) < مسافة(دليل1)(دليل2) {\n\t\t\t\t\tمسافة(دليل1)(دليل2) = مسافة(دليل1)(دليل3) + مسافة(دليل3)(دليل2)؛\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\n}\n"}, {"role": "assistant", "content": "const V = 4;\n\nfunction floydWarshall(graph) {\n let dist = [];\n for (let i = 0; i < V; i++) {\n dist[i] = [];\n for (let j = 0; j < V; j++) {\n dist[i][j] = graph[i][j];\n }\n }\n\n for (let k = 0; k < V; k++) {\n for (let i = 0; i < V; i++) {\n for (let j = 0; j < V; j++) {\n if (dist[i][k] + dist[k][j] < dist[i][j]) {\n dist[i][j] = dist[i][k] + dist[k][j];\n }\n }\n }\n }\n\n return dist;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, Write DFS algorithm for the given graph"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"Srl/Console\";\n\nuse Srl;\n\nfunc dfs(node: Int, visited: ref[Array[Bool]], graph: ref[Array[Array[Int]]]) {\n visited(node) = true;\n Console.print(\"%d \", node);\n\n def i: Int;\n for i = 0 , i < graph(node).getLength(), i++ {\n def childNode: Int = graph(node)(i);\n if !visited(childNode) {\n dfs(childNode, visited, graph);\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/نـم\"؛\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة ألحق_سجل(مسار_الملف: سند[نـص]، سجل: سند[نـص]) {\n\tعرف ملف: مؤشر[نـم.مـلف] = نـم.افتح_ملف(مسار_الملف، \"a\")؛\n\t\n\tنـم.اكتب(سجل.صوان، 1، سجل.هات_الطول()، ملف)؛\n\tنـم.اكتب(\"\\ج\"، 1، 1، ملف)؛\n\tنـم.اغلق_ملف(ملف)؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/Fs\";\nimport \"Srl/String\";\n\nuse Srl;\n\n\nfunc appendLogEntry(file_path: ref[String], logEntry: ref[String]) {\n def file: ptr[Fs.File] = Fs.openFile(file_path.buf, \"a\");\n\n Fs.write(logEntry.buf, 1, logEntry.getLength(), file);\n Fs.write(\"\\n\", 1, 1, file);\n Fs.closeFile(file);\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Array\";\n\nuse Srl;\n\nfunc isCyclic(node: Int, visited: ref[Array[Int]], graph: ref[Array[Array[Int]]]): Bool {\n if visited(node) == 2 {\n return true;\n }\n visited(node) = 1;\n\n def i: Int;\n for i = 0 , i < graph(node).getLength(), i++ {\n def childNode: Int = graph(node)(i);\n if visited(childNode) == 1 {\n return true;\n }\n else if visited(childNode) == 0 && isCyclic(childNode, visited, graph){\n return true;\n }\n }\n visited(node) = 2;\n return false;\n}\n\n\nfunc isDAG(graph: ref[Array[Array[Int]]]): Bool {\n def visited: Array[Int];\n def i: Int;\n\n for i = 0 , i < graph.getLength() , i++ {\n def j: Int;\n for j = 0 , j < graph.getLength() , j++ {\n visited.add(0);\n }\n if isCyclic(i, visited, graph) {\n return false;\n }\n visited.clear();\n }\n\n return true;\n}\n"}, {"role": "assistant", "content": "#include <stdio.h>\n#define MAX 100\n\nint graph[MAX][MAX];\nint visited[MAX];\nint n;\n\nint isCyclic(int i) {\n if (visited[i] == 2) {\n return 1;\n }\n visited[i] = 1;\n for (int j = 0; j < n; j++) {\n if (graph[i][j]) {\n if (visited[j] == 1) return 1;\n else if (visited[j] == 0 && isCyclic(j)) return 1;\n }\n }\n visited[i] = 2;\n return 0;\n}\n\nint isDAG() {\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n visited[j] = 0;\n }\n if (isCyclic(i)) {\n return 0;\n }\n }\n return 1;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, Check whether a given array is a permutation for another given array"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc is_permutation(a1: ref[Array[Int]], a2: ref[Array[Int]]): Bool {\n if a1.getLength() != a2.getLength() {\n return false;\n }\n\n def visited: Array[Bool];\n def i: Int;\n for i = 0 , i < a2.getLength() , i++ {\n visited.add(false);\n }\n\n def j: Int;\n for i = 0 , i < a1.getLength() , i++ {\n def found: Bool = false;\n for j = 0 , j < a2.getLength() , j++ {\n if a1(i) == a2(j) && !visited(j) {\n found = true;\n visited(j) = true;\n break;\n }\n }\n if !found {\n return false;\n }\n }\n\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Array\";\n\nuse Srl;\n\nfunc sum(a: ref[Array[Int]]): Int {\n def sum: Int = 0;\n\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n sum += a(i);\n }\n\n return sum;\n}\n"}, {"role": "assistant", "content": "Find and return the sum of the given array `a`"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction find_char(s, c) {\n for (let i = 0; i < s.length; i++) {\n if (s[i] === c) {\n return i;\n }\n }\n return -1;\n}\n"}, {"role": "assistant", "content": "import \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc find_char(s: ref[String], c: Char): Int {\n def i: Int;\n\tfor i = 0 , i < s.getLength() , i++ {\n\t\tif (s(i) == c) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, اختصر المصفوفة المعطاة م باستعمال الدالة المعطاة د و أرجع النتيجة"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/نـص\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة اختصر(م: سند[مـصفوفة[نـص]]، د: مغلفة(قيمة_سابقة: سند[نـص]، قيمة_حالية: سند[نـص])): نـص {\n\tعرف نتيجة: نـص = \"\"؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tد(نتيجة، م(دليل))؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction initializeArray(arr, value) {\n for(let i = 0; i < arr.length; i++) {\n arr[i] = value;\n }\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc initializeArray(a: ref[Array[Int]], size: Int, val: Int) {\n def i: Int;\n for i = 0, i < size, i++ {\n a.add(val);\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction sum(a) {\n let result = 0;\n\n for (let i = 0; i < a.length; i++) {\n result += a[i];\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جمع(م: سند[مـصفوفة[صـحيح]]): صـحيح {\n\tعرف نتيجة: صـحيح = 0؛\n\n\tعرف دليل: صـحيح؛\n\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n نتيجة += م(دليل)؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc erase(a: ref[Array[Int]], pos: Int) {\n def size: Int = a.getLength();\n\n def i: Int;\n for i = pos , i < size - 1 , i++ {\n a(i) = a(i + 1);\n }\n a.remove(size - 1);\n}\n"}, {"role": "assistant", "content": "void erase(int a[], int n, int pos) {\n // Shift elements to left\n for (int i = pos; i < n - 1; i++)\n a[i] = a[i + 1];\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة إلى_حالة_كبيرة(س: سند[نـص]): نـص {\n\tعرف نتيجة: نـص = \"\"؛\n\n\tعرف دليل: صـحيح؛\n\tعرف م: مـحرف؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) >= 'a' && س(دليل) <= 'z' {\n\t\t\tم = س(دليل) - 'a' + 'A'؛\n\t\t}\n\t\tوإلا {\n\t\t\tم = س(دليل)؛\n\t\t}\n\t\tنتيجة += م؛\n\t}\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "void toUpperCase(char *s, char *result) {\n for(int i = 0; s[i]; i++){\n if(s[i] >= 'a' && s[i] <= 'z'){\n result[i] = s[i] - 'a' + 'A';\n }\n else {\n result[i] = s[i];\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة اعكس_نص(س: نـص): نـص {\n\tعرف طول: صـحيح = س.هات_الطول()؛\n\tعرف نتيجة: نـص = \"\"؛\n\n\tعرف دليل: صـحيح؛\n\tلكل دليل = طول - 1 ، دليل >= 0 ، دليل-- {\n\t\tنتيجة.ألحق(س(دليل))؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "function invert_string(str) {\n return str.split('').reverse().join('');\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Array\";\n\nuse Srl;\n\nfunc sum(a: ref[Array[Int]], start: Int, end: Int): Int {\n def sum: Int = 0;\n\n def i: Int;\n for i = start , i < end , i++ {\n sum += a(i);\n }\n\n return sum;\n}\n"}, {"role": "assistant", "content": "function sum(a, start, end) {\n let result = 0;\n\n for (let i = start; i < end; i++) {\n result += a[i];\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction char_exists(s, c) {\n for (let i = 0; i < s.length; i++) {\n if (s[i] === c) {\n return true;\n }\n }\n return false;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة المحرف_متواجد(س: سند[نـص]، م: مـحرف): ثـنائي {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) == م {\n\t\t\tارجع صح؛\n\t\t}\n\t}\n\tارجع خطأ؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc slice(a: ref[Array[Int]], start: Int, end: Int, result: ref[Array[Int]]) {\n def i: Int;\n for i = start , i <= end , i++ {\n result.add(a(i));\n }\n}\n"}, {"role": "assistant", "content": "Slice a given array within a given range"}]}
{"messages": [{"role": "user", "content": "Using js, check if a given array contains a given element"}, {"role": "assistant", "content": "function exists(a, val) {\n for (let i = 0; i < a.length ; i++) {\n if (a[i] == val) {\n return true;\n }\n }\n return false;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, احشر عنصرا في موقع معطى ضمن المصفوفة المعطى"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة احشر(م: سند[مـصفوفة[صـحيح]]، موقع: صـحيح، قيمة: صـحيح) {\n\tعرف حجم: صـحيح = م.هات_الطول()؛\n\tم.أضف(0)؛ // لزيادة الحجم بمقدار 1\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = حجم ، دليل > موقع ، دليل-- {\n\t\tم(دليل) = م(دليل - 1)؛\n\t}\n\t\n\tم(موقع) = قيمة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\n#include <stdlib.h>\n\nvoid merge(int arr[], int l, int m, int r) {\n int i, j, k;\n int n1 = m - l + 1;\n int n2 = r - m;\n\n int L[n1], R[n2];\n\n for (i = 0; i < n1; i++)\n L[i] = arr[l + i];\n for (j = 0; j < n2; j++)\n R[j] = arr[m + 1 + j];\n\n i = 0;\n j = 0;\n k = l;\n while (i < n1 && j < n2) {\n if (L[i] <= R[j]) {\n arr[k] = L[i];\n i++;\n } else {\n arr[k] = R[j];\n j++;\n }\n k++;\n }\n\n while (i < n1) {\n arr[k] = L[i];\n i++;\n k++;\n }\n\n while (j < n2) {\n arr[k] = R[j];\n j++;\n k++;\n }\n}\n\nvoid mergeSort(int arr[], int l, int r) {\n if (l < r) {\n int m = l + (r - l) / 2;\n\n mergeSort(arr, l, m);\n mergeSort(arr, m + 1, r);\n\n merge(arr, l, m, r);\n }\n}\n"}, {"role": "assistant", "content": "write the merge sort algorithm for a given array"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc initializeArray(a: ref[Array[Int]], size: Int, val: Int) {\n def i: Int;\n for i = 0, i < size, i++ {\n a.add(val);\n }\n}\n"}, {"role": "assistant", "content": "Initialize a given array with a given size by a given value"}]}
{"messages": [{"role": "user", "content": "Using js, Insert an element at a given position in the given array"}, {"role": "assistant", "content": "function insert(a, n, pos, x) {\n // Shift elements to right\n for (let i = n; i > pos; i--)\n a[i] = a[i - 1];\n\n // Insert x at pos\n a[pos] = x;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة تفحص_الكل(م: سند[مـصفوفة[صـحيح]]، د: مغلفة(رقم: صـحيح): ثـنائي): ثـنائي {\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا !د(م(دليل)) {\n\t\t\tارجع خطأ؛\n\t\t}\n\t}\n\t\n\tارجع صح؛\n}\n"}, {"role": "assistant", "content": "#include <stdbool.h>\n\n// Criteria function that checks if a number is positive\nbool criteria(int num) {\n return num > 0;\n}\n\n// Function to check all elements in an array\nbool check_all(int arr[], int size) {\n for(int i = 0; i < size; i++) {\n if(!criteria(arr[i])) {\n return false;\n }\n }\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/طـرفية\"؛\n\nاستخدم مـتم؛\n\n\nدالة اطبع(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tطـرفية.اطبع(\"%d \"، م(دليل))؛\n\t}\n}\n"}, {"role": "assistant", "content": "function printArray(a, size) {\n var output = '';\n for(var i = 0; i < size; i++) {\n output += a[i] + ' ';\n }\n console.log(output);\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction exists(a, val) {\n for (let i = 0; i < a.length ; i++) {\n if (a[i] == val) {\n return true;\n }\n }\n return false;\n}\n"}, {"role": "assistant", "content": "check if a given array contains a given element"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Array\";\nimport \"closure\";\n\nuse Srl;\n\n\nfunc foreach(a: ref[Array[Int]], f: closure(element: Int): Int) {\n def i: Int;\n \n for i = 0 , i < a.getLength() , i++ {\n a(i) = f(a(i));\n }\n}\n"}, {"role": "assistant", "content": "apply the given function `f` on each element of the given array `a` and return the result"}]}
{"messages": [{"role": "user", "content": "Using js, reduce the given array `a` using the given function `f` and return the result"}, {"role": "assistant", "content": "function reduce(a, f) {\n let result = \"\";\n\n for (let i = 0; i < a.length; i++) {\n result = f(result, a[i]);\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction dfs(node, visited, G) {\n visited[node] = true;\n console.log(node);\n\n for(let i = 0; i < G[node].length; i++) {\n if(!visited[G[node][i]]) {\n dfs(G[node][i], visited, G);\n }\n }\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/طـرفية\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nدالة دفس(عقدة: صـحيح، مزارة: سند[مـصفوفة[ثـنائي]]، بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]) {\n\tمزارة(عقدة) = صح؛\n\tطـرفية.اطبع(\"%d \"، عقدة)؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان(عقدة).هات_الطول() ، دليل++ {\n\t\tعرف عقدة_ابن: صـحيح = بيان(عقدة)(دليل)؛\n\t\tإذا !مزارة(عقدة_ابن) {\n\t\t\tدفس(عقدة_ابن، مزارة، بيان)؛\n\t\t}\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة هيئ_مصفوفة(م: سند[مـصفوفة[صـحيح]]، حجم: صـحيح، قيمة: صـحيح) {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < حجم ، دليل++ {\n\t\tم.أضف(قيمة)؛\n\t}\n}\n"}, {"role": "assistant", "content": "void initializeArray(int* arr, int size, int value) {\n for(int i = 0; i < size; i++) {\n arr[i] = value;\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, احسب و أرجع المتوسط الحسابي للمصفوفة المعطاة"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة متوسط(م: سند[مـصفوفة[صـحيح]]): عـائم {\n\tعرف حجم: صـحيح = م.هات_الطول()؛\n\tعرف مجموع: صـحيح = 0؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < حجم ، دليل++ {\n\t\tمجموع += م(دليل)؛\n\t}\n\t\n\tارجع مجموع~مثل[عـائم] / حجم؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/نـم\"؛\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة اقرأ_الملف(مسار_الملف: سند[نـص]): نـص {\n\tعرف ملف: مؤشر[نـم.مـلف] = نـم.افتح_ملف(مسار_الملف، \"r\")؛\n\t\n\tنـم.انتقل(ملف، 0، نـم.انـتقال._نهاية_)؛\n\tعرف حجم: صـحيح = نـم.هات_الموقع(ملف)؛\n\tنـم.انتقل(ملف، 0، نـم.انـتقال._بداية_)؛\n\t\n\tعرف المحتوى: نـص؛\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < حجم ، دليل++ {\n\t\tعرف مؤقت: مـحرف؛\n\t\tنـم.اقرأ(مؤقت~مؤشر، 1، 1، ملف)؛\n\t\tالمحتوى.ألحق(مؤقت)؛\n\t}\n\t\n\tارجع المحتوى؛\n}\n"}, {"role": "assistant", "content": "const fs = require('fs');\n\n// Function to read the content of a file into a string one character at a time\nfunction read_file(file_path) {\n const fileDescriptor = fs.openSync(file_path, 'r');\n let file_content = '';\n let buffer = Buffer.alloc(1);\n\n // Read the file one character at a time\n while(fs.readSync(fileDescriptor, buffer, 0, 1)) {\n file_content += buffer.toString();\n }\n\n fs.closeSync(fileDescriptor);\n return file_content;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction slice(arr, start, end) {\n let result = [];\n for(let i = start; i <= end; i++) {\n result.push(arr[i]);\n }\n return result;\n}\n"}, {"role": "assistant", "content": "Slice a given array within a given range"}]}
{"messages": [{"role": "user", "content": "Using js, calculate and return the area of a triangle from its points"}, {"role": "assistant", "content": "function Point(x, y) {\n this.x = x;\n this.y = y;\n}\n\nfunction triangleArea(p1, p2, p3) {\n return Math.abs(p1.x*(p2.y-p3.y) + p2.x*(p3.y-p1.y) + p3.x*(p1.y-p2.y)) / 2.0;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction vectorNorm(vector) {\n let sum = 0.0;\n for (let i = 0; i < vector.length; i++) {\n sum += vector[i] * vector[i];\n }\n return Math.sqrt(sum);\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"Srl/Math\";\n\nuse Srl;\n\n\nfunc vectorNorm(vector: ref[Array[Float[64]]]): Float[64] {\n def sum: Float[64] = 0;\n\n def i: Int;\n for i = 0 , i < vector.getLength() , i++ {\n sum += vector(i) * vector(i);\n }\n\n return Math.sqrt(sum);\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, calculate and return the area of polygon given its vertices"}, {"role": "assistant", "content": "import \"Srl/Math\";\nimport \"Srl/Array\";\n\nuse Srl;\n\nclass Point {\n def x : Float;\n def y : Float;\n};\n\nfunc calculatePolygonArea(vertices: ref[Array[Point]]): Float {\n def area: Float = 0;\n def numVertices: Int = vertices.getLength();\n def j: Int = numVertices - 1;\n\n def i: Int;\n for i = 0 , i < numVertices , i++ {\n area += (vertices(j).x + vertices(i).x) * (vertices(j).y - vertices(i).y);\n j = i;\n }\n return Math.abs(area / 2.0);\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/String\";\nimport \"Srl/Array\"\n\nuse Srl;\n\n\nfunc split(s: ref[String], token: Char): Array[String] {\n def result: Array[String];\n\n def temp: String;\n def i: Int;\n for i = 0 , i < s.getLength() , i++ {\n if (s(i) != token) {\n temp.append(s(i));\n }\n else {\n result.add(temp);\n temp = \"\";\n }\n }\n result.add(temp);\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/نـص\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جزئ(س: سند[نـص]، رمز: مـحرف): مـصفوفة[نـص] {\n\tعرف نتيجة: مـصفوفة[نـص]؛\n\t\n\tعرف مؤقت: نـص؛\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) != رمز {\n\t\t\tمؤقت.ألحق(س(دليل))؛\n\t\t}\n\t\tوإلا {\n\t\t\tنتيجة.أضف(مؤقت)؛\n\t\t\tمؤقت = \"\"؛\n\t\t}\n\t}\n\tنتيجة.أضف(مؤقت)؛\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc replace(a: ref[Array[Int]], oldValue: Int, newValue: Int) {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if a(i) == oldValue {\n a(i) = newValue;\n }\n }\n}\n"}, {"role": "assistant", "content": "Replace a given value with another given value in a given array"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جمع(م: سند[مـصفوفة[صـحيح]]): صـحيح {\n\tعرف نتيجة: صـحيح = 0؛\n\n\tعرف دليل: صـحيح؛\n\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n نتيجة += م(دليل)؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "function sum(a) {\n let result = 0;\n\n for (let i = 0; i < a.length; i++) {\n result += a[i];\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, Invert the given string `s` and return the result"}, {"role": "assistant", "content": "#include <string.h>\n\nvoid invert_string(char* str) {\n int len = strlen(str);\n for(int i = 0; i < len / 2; i++) {\n char temp = str[i];\n str[i] = str[len - i - 1];\n str[len - i - 1] = temp;\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, Check whether a given array is a permutation for another given array"}, {"role": "assistant", "content": "// Function to check if arr2 is a permutation of arr1\nfunction is_permutation(arr1, arr2) {\n // If sizes are not equal, return false\n if(arr1.length !== arr2.length) {\n return false;\n }\n\n // Create an array to keep track of visited elements\n let visited = new Array(arr2.length).fill(false);\n\n // For each element in arr1\n for(let i = 0; i < arr1.length; i++) {\n let found = false;\n\n // For each element in arr2\n for(let j = 0; j < arr2.length; j++) {\n // If the element in arr1 is found in arr2 and it has not been visited\n if(arr1[i] === arr2[j] && !visited[j]) {\n found = true;\n visited[j] = true; // Mark the element in arr2 as visited\n break;\n }\n }\n\n // If the element in arr1 is not found in arr2, return false\n if(!found) {\n return false;\n }\n }\n\n // If we reach here, then arr2 is a permutation of arr1\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\nint find_most_frequent(int arr[], int n) {\n int max_count = 0, res = -1;\n\n for (int i = 0; i < n; i++) {\n int count = 1;\n for (int j = i + 1; j < n; j++)\n if (arr[i] == arr[j])\n count++;\n if (count > max_count) {\n max_count = count;\n res = arr[i];\n }\n }\n\n return res;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc find_most_frequent(a: ref[Array[Int]]): Int {\n def max_count: Int = 0;\n def res: Int = -1;\n\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n def count: Int = 1;\n \n def j: Int;\n for j = i + 1 , j < a.getLength() , j++ {\n if a(j) == a(i) {\n count++;\n }\n }\n\n if count > max_count {\n max_count = count;\n res = a(i);\n }\n }\n\n return res;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\n#include <string.h>\n\nvoid invert_string(char* str) {\n int len = strlen(str);\n for(int i = 0; i < len / 2; i++) {\n char temp = str[i];\n str[i] = str[len - i - 1];\n str[len - i - 1] = temp;\n }\n}\n"}, {"role": "assistant", "content": "import \"Srl/String\";\n\nuse Srl;\n\n\nfunction invertString(s) {\n def size: Int = s.getLength();\n def result: String = \"\";\n\n def i: Int;\n for i = size - 1 , i >= 0 , i-- {\n result += s(i);\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Array\";\n\nuse Srl;\n\nfunc findIntersection(a1: Float[64], b1: Float[64], c1: Float[64], a2: Float[64], b2: Float[64], c2: Float[64]): Array[Float[64]] {\n def result: Array[Float[64]];\n if a1*b2 - a2*b1 == 0 {\n return result;\n }\n\n result.add((b1*c2 - b2*c1) / (a1*b2 - a2*b1));\n result.add((a2*c1 - a1*c2) / (a1*b2 - a2*b1));\n\n return result;\n}\n"}, {"role": "assistant", "content": "#include <stdlib.h>\n\n// Function to find the intersection point of two lines\ndouble* findIntersection(double a1, double b1, double c1, double a2, double b2, double c2) {\n // Check if the lines are parallel\n if(a1*b2 - a2*b1 == 0) {\n return NULL;\n }\n\n double* result = (double*)malloc(2 * sizeof(double));\n result[0] = (b1*c2 - b2*c1) / (a1*b2 - a2*b1);\n result[1] = (a2*c1 - a1*c2) / (a1*b2 - a2*b1);\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\n#include <stdlib.h>\n\nchar* slice_string(char* str, int start, int end) {\n int len = end - start + 1;\n char* result = (char*)malloc(sizeof(char) * (len + 1));\n int i;\n\n for(i = start; i <= end; i++) {\n result[i-start] = str[i];\n }\n result[i-start] = '\\0';\n\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة اجتزئ(س: سند[نـص]، بداية: صـحيح، نهاية: صـحيح): نـص {\n\tعرف نتيجة: نـص = \"\"؛\n\n\tعرف دليل: صـحيح؛\n\tلكل دليل = بداية ، دليل <= نهاية ، دليل++ {\n\t\tنتيجة.ألحق(س(دليل))؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nعرف مـصفوفة_ثنائية: لقب مـصفوفة[مـصفوفة[عـائم[64]]]؛\nعرف شـعاع: لقب مـصفوفة[عـائم[64]]؛\n\n\nدالة جداء(م: سند[مـصفوفة_ثنائية]، ش: سند[شـعاع]): شـعاع {\n\tعرف أسطر: صـحيح = م.هات_الطول()؛\n\tعرف أعمدة: صـحيح = م(0).هات_الطول()؛\n\n\tعرف نتيجة: شـعاع؛\n\t\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < أسطر ، دليل1++ {\n\t\tنتيجة.أضف(0)؛\n\t\tلكل دليل2 = 0 ، دليل2 < أعمدة ، دليل2++ {\n\t\t\t\tنتيجة(دليل1) += م(دليل1)(دليل2) * ش(دليل2)؛\n\t\t}\n\t}\n\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "احسب جداء مصفوفة معطاة ممثلة على شكل مصفوفة ثنائية الأبعاد، و شعاع معطى ممثل على شكل مصفوفة و أعد النتيجة"}]}
{"messages": [{"role": "user", "content": "Using js, check if a given string contains a given char"}, {"role": "assistant", "content": "function char_exists(s, c) {\n for (let i = 0; i < s.length; i++) {\n if (s[i] === c) {\n return true;\n }\n }\n return false;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Array\";\n\nuse Srl;\n\nfunc floydWarshall(graph: ref[Array[Array[Int]]], dist: ref[Array[Array[Int]]]) {\n def n: Int = graph.getLength();\n def i: Int;\n def j: Int;\n def k: Int;\n\n for i = 0 , i < n , i++ {\n dist.add(graph(i));\n }\n\n for k = 0 , k < n , k++ {\n for i = 0 , i < n , i++ {\n for j = 0 , j < n , j++ {\n if dist(i)(k) + dist(k)(j) < dist(i)(j) {\n dist(i)(j) = dist(i)(k) + dist(k)(j);\n }\n }\n }\n }\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة فلويد_وارشال(بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]، مسافة: سند[مـصفوفة[مـصفوفة[صـحيح]]]) {\n\tعرف حجم: صـحيح = بيان.هات_الطول()؛\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tعرف دليل3: صـحيح؛\n\n\t\n\tلكل دليل1 = 0 ، دليل1 < حجم ، دليل1++ {\n\t\tمسافة.أضف(بيان(دليل1))؛\n\t}\n\t\n\tلكل دليل3 = 0 ، دليل3 < حجم ، دليل3++ {\n\t\tلكل دليل1 = 0 ، دليل1 < حجم ، دليل1++ {\n\t\t\tلكل دليل2 = 0 ، دليل2 < حجم ، دليل2++ {\n\t\t\t\tإذا مسافة(دليل1)(دليل3) + مسافة(دليل3)(دليل2) < مسافة(دليل1)(دليل2) {\n\t\t\t\t\tمسافة(دليل1)(دليل2) = مسافة(دليل1)(دليل3) + مسافة(دليل3)(دليل2)؛\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, اجتزئ مصفوفة معطاة ضمن مجال معطى"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة اجتزئ(م: سند[مـصفوفة[صـحيح]]، بداية: صـحيح، نهاية: صـحيح، نتيجة: سند[مـصفوفة[صـحيح]]) {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = بداية ، دليل <= نهاية ، دليل++ {\n\t\tنتيجة.أضف(م(دليل))؛\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, جد و أرجع أقرب نقطة من بين مجموعة من النقاط المعطاة عن نقطة معطاة"}, {"role": "assistant", "content": "اشمل \"مـتم/ريـاضيات\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nصنف نـقطة {\n\tعرف س: عـائم؛\n\tعرف ص: عـائم؛\n}\n\nدالة احسب_مسافة(ن1: نـقطة، ن2: نـقطة): عـائم {\n\tارجع ريـاضيات.جذر(ريـاضيات.ارفع(ن2.س - ن1.س، 2.0) + ريـاضيات.ارفع(ن2.ص - ن1.ص، 2.0))؛\n}\n\nدالة جد_أقرب_نقطة(ن: نـقطة، نقاط: سند[مـصفوفة[نـقطة]]): نـقطة {\n\tعرف أقرب_مسافة: عـائم = احسب_مسافة(ن، نقاط(0))؛\n\tعرف أقرب_نقطة: نـقطة = نقاط(0)؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 1 ، دليل < نقاط.هات_الطول() ، دليل++ {\n\t\tعرف مسافة: عـائم = احسب_مسافة(ن، نقاط(دليل))؛\n\t\tإذا مسافة < أقرب_مسافة {\n\t\t\tأقرب_مسافة = مسافة؛\n\t\t\tأقرب_نقطة = نقاط(دليل)؛\n\t\t}\n\t}\n\tارجع أقرب_نقطة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Array\";\n\nuse Srl;\n\n\ndef MAX_VALUE: Int = 100000;\n\nfunc countingSort(a: ref[Array[Int]]) {\n def i: Int;\n def j: Int;\n def idx: Int;\n\n def count: Array[Int];\n for i = 0 , i < MAX_VALUE , i++ {\n count.add(0);\n }\n\n for i = 0 , i < a.getLength() , i++ {\n count(a(i))++;\n }\n\n for i = 0 , i < MAX_VALUE , i++ {\n for j = 0 , j < count(i) , j++ {\n a(idx++) = i;\n }\n }\n}\n"}, {"role": "assistant", "content": "const MAX_VALUE = 100000;\n\nfunction countingSort(arr) {\n let i, j;\n let count = new Array(MAX_VALUE + 1).fill(0);\n let output = [];\n\n // Count the occurrence of each number\n for(i = 0; i < arr.length; i++) {\n count[arr[i]]++;\n }\n\n // Reconstruct the sorted array\n for(i = 0; i <= MAX_VALUE; i++) {\n for(j = 0; j < count[i]; j++) {\n output.push(i);\n }\n }\n\n return output;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction outer_product(v1, v2) {\n let result = [];\n for (let i = 0; i < v1.length; i++) {\n let row = [];\n for (let j = 0; j < v2.length; j++) {\n row.push(v1[i] * v2[j]);\n }\n result.push(row);\n }\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جداء_خارجي(شعاع1: سند[مـصفوفة[عـائم[64]]]، شعاع2: سند[مـصفوفة[عـائم[64]]]): مـصفوفة[مـصفوفة[عـائم[64]]] {\n\tعرف نتيجة: مـصفوفة[مـصفوفة[عـائم[64]]]؛\n\t\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < شعاع1.هات_الطول() ، دليل1++ {\n\t\tعرف سطر: مـصفوفة[عـائم[64]]؛\n\t\tلكل دليل2 = 0 ، دليل2 < شعاع2.هات_الطول() ، دليل2++ {\n\t\t\tسطر.أضف(شعاع1(دليل1)*شعاع2(دليل2))؛\n\t\t}\n\t\tنتيجة.أضف(سطر)؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction max(a) {\n let result = a[0];\n for (let i = 1 ; i < a.length ; i++) {\n if (result < a[i]) {\n result = a[i];\n }\n }\n return result;\n}\n"}, {"role": "assistant", "content": "Find and return the maximum in the given array `a`"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة أكبر_عنصر(م: سند[مـصفوفة[صـحيح]]): صـحيح {\n\n\tعرف نتيجة: صـحيح = م(0)؛\n\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 1 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا م(دليل) > نتيجة {\n\t\t\tنتيجة = م(دليل)؛\n\t\t}\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "int findMax(int* a, int n) {\n int max = a[0];\n for(int i = 1; i < n; i++) {\n if(a[i] > max) {\n max = a[i];\n }\n }\n return max;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\n// Criteria function that checks if a number is positive\nfunction criteria(num) {\n return num > 0;\n}\n\n// Function to check all elements in an array\nfunction check_all(arr) {\n for(let i = 0; i < arr.length; i++) {\n if(!criteria(arr[i])) {\n return false;\n }\n }\n return true;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"closure\";\n\n\nuse Srl;\n\n\nfunc check_all(a: ref[Array[Int]], f: closure (num: Int): Bool): Bool {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if !f(a(i)) {\n return false;\n }\n }\n\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, convert string to uppercase and return the result"}, {"role": "assistant", "content": "void toUpperCase(char *s, char *result) {\n for(int i = 0; s[i]; i++){\n if(s[i] >= 'a' && s[i] <= 'z'){\n result[i] = s[i] - 'a' + 'A';\n }\n else {\n result[i] = s[i];\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nvoid reduce(char a[4][10], char result[50], void (*f)(char*, char*)) {\n for(int i = 0; i < 4; i++) {\n f(result, a[i]);\n }\n}\n"}, {"role": "assistant", "content": "reduce the given array `a` using the given function `f` and return the result"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة متوسط(م: سند[مـصفوفة[صـحيح]]): عـائم {\n\tعرف حجم: صـحيح = م.هات_الطول()؛\n\tعرف مجموع: صـحيح = 0؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < حجم ، دليل++ {\n\t\tمجموع += م(دليل)؛\n\t}\n\t\n\tارجع مجموع~مثل[عـائم] / حجم؛\n}\n"}, {"role": "assistant", "content": "double calculateMean(int arr[], int n) {\n int sum = 0;\n for (int i = 0; i < n; i++) {\n sum += arr[i];\n }\n return (double)sum / n;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\nint starts_with(const char *str, const char *prefix) {\n while(*prefix) {\n if (!(*str))\n return 0;\n if(*prefix++ != *str++)\n return 0;\n }\n return 1;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة يبدأ_ب(س: سند[نـص]، سابق: سند[نـص]): ثـنائي {\n\tإذا س.هات_الطول() < سابق.هات_الطول() {\n\t\tارجع خطأ؛\n\t}\n\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < سابق.هات_الطول() ، دليل++ {\n\t\tإذا سابق(دليل) != س(دليل) {\n\t\t\tارجع خطأ؛\n\t\t}\n\t}\n\tارجع صح؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nعرف مـصفوفة_ثنائية: لقب مـصفوفة[مـصفوفة[عـائم[64]]]؛\nعرف شـعاع: لقب مـصفوفة[عـائم[64]]؛\n\n\nدالة جداء(م: سند[مـصفوفة_ثنائية]، ش: سند[شـعاع]): شـعاع {\n\tعرف أسطر: صـحيح = م.هات_الطول()؛\n\tعرف أعمدة: صـحيح = م(0).هات_الطول()؛\n\n\tعرف نتيجة: شـعاع؛\n\t\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < أسطر ، دليل1++ {\n\t\tنتيجة.أضف(0)؛\n\t\tلكل دليل2 = 0 ، دليل2 < أعمدة ، دليل2++ {\n\t\t\t\tنتيجة(دليل1) += م(دليل1)(دليل2) * ش(دليل2)؛\n\t\t}\n\t}\n\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "#include <stdlib.h>\n\nint* multiply(int** a, int* v, int rows, int cols) {\n int i, j;\n // Create a result vector dynamically\n int* result = (int*)malloc(rows * sizeof(int));\n\n // Initialize the result vector with 0\n for(i = 0; i < rows; i++) {\n result[i] = 0;\n }\n\n // Multiply the matrix by the vector\n for(i = 0; i < rows; i++) {\n for(j = 0; j < cols; j++) {\n result[i] += a[i][j] * v[j];\n }\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nclass Point {\n constructor(x, y) {\n this.x = x;\n this.y = y;\n }\n}\n\nfunction calculateDistance(a, b) {\n return Math.sqrt(Math.pow(b.x - a.x, 2) + Math.pow(b.y - a.y, 2));\n}\n\nfunction findFarthestPoint(givenPoint, points) {\n let maxDistance = 0;\n let farthestPoint;\n \n for(let i = 0; i < points.length; i++) {\n let distance = calculateDistance(givenPoint, points[i]);\n if(distance > maxDistance) {\n maxDistance = distance;\n farthestPoint = points[i];\n }\n }\n \n return farthestPoint;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/ريـاضيات\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nصنف نـقطة {\n\tعرف س: عـائم؛\n\tعرف ص: عـائم؛\n}\n\nدالة احسب_مسافة(ن1: نـقطة، ن2: نـقطة): عـائم {\n\tارجع ريـاضيات.جذر(ريـاضيات.ارفع(ن2.س - ن1.س، 2.0) + ريـاضيات.ارفع(ن2.ص - ن1.ص، 2.0))؛\n}\n\nدالة جد_أبعد_نقطة(ن: نـقطة، نقاط: سند[مـصفوفة[نـقطة]]): نـقطة {\n\tعرف أبعد_مسافة: عـائم = 0؛\n\tعرف أبعد_نقطة: نـقطة؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < نقاط.هات_الطول() ، دليل++ {\n\t\tعرف مسافة: عـائم = احسب_مسافة(ن، نقاط(دليل))؛\n\t\tإذا مسافة > أبعد_مسافة {\n\t\t\tأبعد_مسافة = مسافة؛\n\t\t\tأبعد_نقطة = نقاط(دليل)؛\n\t\t}\n\t}\n\tارجع أبعد_نقطة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, filter the given array based on the given function `f` and return the result"}, {"role": "assistant", "content": "function filter(a, condition) {\n let result = [];\n for(let i = 0; i < a.length; i++) {\n if(condition(a[i])) {\n result.push(a[i]);\n }\n }\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\ndouble calculateMean(int arr[], int n) {\n int sum = 0;\n for (int i = 0; i < n; i++) {\n sum += arr[i];\n }\n return (double)sum / n;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة متوسط(م: سند[مـصفوفة[صـحيح]]): عـائم {\n\tعرف حجم: صـحيح = م.هات_الطول()؛\n\tعرف مجموع: صـحيح = 0؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < حجم ، دليل++ {\n\t\tمجموع += م(دليل)؛\n\t}\n\t\n\tارجع مجموع~مثل[عـائم] / حجم؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاستخدم مـتم؛\n\n\nدالة ينتمي_للأرقام(م: مـحرف): ثـنائي {\n\tارجع ( م <= '9' && م >= '0')؛\n}\n"}, {"role": "assistant", "content": "#include <stdbool.h>\n\nbool is_digit(char c) {\n return (c >= '0' && c <= '9');\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc replace(a: ref[Array[Int]], oldValue: Int, newValue: Int) {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if a(i) == oldValue {\n a(i) = newValue;\n }\n }\n}\n"}, {"role": "assistant", "content": "function replace(arr, oldValue, newValue) {\n for(var i = 0; i < arr.length; i++) {\n if(arr[i] == oldValue) {\n arr[i] = newValue;\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, Slice a given string within a given range and return the result"}, {"role": "assistant", "content": "#include <stdlib.h>\n\nchar* slice_string(char* str, int start, int end) {\n int len = end - start + 1;\n char* result = (char*)malloc(sizeof(char) * (len + 1));\n int i;\n\n for(i = start; i <= end; i++) {\n result[i-start] = str[i];\n }\n result[i-start] = '\\0';\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, rotate the given array counterclockwise and return the result"}, {"role": "assistant", "content": "void rotate(int a[], int n) {\n int first_element = a[0];\n\n for (int i = 0 ; i < n - 1; i++) {\n a[i] = a[i + 1];\n }\n\n a[n - 1] = first_element;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nدالة دفس(عقدة: صـحيح، العقدة_الأب: صـحيح، مزارة: سند[مـصفوفة[ثـنائي]]، بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]): ثـنائي {\n\tمزارة(عقدة) = صح؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان(عقدة).هات_الطول() ، دليل++ {\n\t\tعرف عقدة_ابن: صـحيح = بيان(عقدة)(دليل)؛\n\t\tإذا !مزارة(عقدة_ابن) {\n\t\t\tإذا دفس(عقدة_ابن، عقدة، مزارة، بيان) {\n\t\t\t\tارجع صح؛\n\t\t\t}\n\t\t}\n\t\tوإلا إذا عقدة_ابن != العقدة_الأب {\n\t\t\tارجع صح؛\n\t\t}\n\t}\n\tارجع خطأ؛\n}\n\n\nدالة هل_شجرة(بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]): ثـنائي {\n\tعرف مزارة: مـصفوفة[ثـنائي]؛\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان.هات_الطول() ، دليل++ {\n\t\tمزارة.أضف(خطأ)؛\n\t}\n\t\n\tإذا دفس(0، -1، مزارة، بيان) {\n\t\tارجع خطأ؛\n\t}\n\t\n\tعرف عدد_المكونات: صـحيح = 0؛\n\tلكل دليل = 0 ، دليل < بيان.هات_الطول() ، دليل++ {\n\t\tإذا !مزارة(دليل) {\n\t\t\tارجع خطأ؛\n\t\t}\n\t}\n\t\n\tارجع صح؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\nfunc dfs(node: Int, parentNode: Int, visited: ref[Array[Bool]], graph: ref[Array[Array[Int]]]): Bool {\n visited(node) = true;\n\n def i: Int;\n for i = 0 , i < graph(node).getLength(), i++ {\n def childNode: Int = graph(node)(i);\n if !visited(childNode) {\n if dfs(childNode, node, visited, graph) {\n return true;\n }\n }\n else if childNode != parentNode {\n return true;\n }\n }\n return false;\n}\n\n\nfunc isTree(graph: ref[Array[Array[Int]]]): Bool {\n def visited: Array[Bool];\n def i: Int;\n for i = 0 , i < graph.getLength() , i++ {\n visited.add(false);\n }\n\n if dfs(0, -1, visited, graph) {\n return false;\n }\n\n for i = 0 , i < graph.getLength() , i++ {\n if !visited(i) {\n return false;\n }\n }\n\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\n#include <stdio.h>\n#include <stdlib.h>\n\n// Function to read the n-th line of a file\nchar* read_nth_line(const char* file_path, int n) {\n FILE* file = fopen(file_path, \"r\");\n if(file == NULL) {\n printf(\"Could not open file %s\\n\", file_path);\n return NULL;\n }\n\n char* line = NULL;\n size_t len = 0;\n ssize_t read;\n\n int current_line = 0;\n while((read = getline(&line, &len, file)) != -1) {\n current_line++;\n if(current_line == n) {\n fclose(file);\n return line;\n }\n }\n\n // If we reach here, then the file has less than n lines\n fclose(file);\n free(line);\n return NULL;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/نـم\"؛\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة اقرأ_السطر_ن(مسار_الملف: سند[نـص]، ن: صـحيح): نـص {\n\tعرف ملف: مؤشر[نـم.مـلف] = نـم.افتح_ملف(مسار_الملف، \"r\")؛\n\t\n\tعرف دليل: صـحيح؛\n\tعرف مؤقت: مـحرف = ' '؛\n\tلكل دليل = 0 ، دليل < ن - 1 ، دليل++ {\n\t\tمؤقت = ' '؛\n\t\tبينما مؤقت != '\\n' {\n\t\t\tنـم.اقرأ(مؤقت~مؤشر، 1، 1، ملف)؛\n\t\t}\n\t}\n\t\n\tعرف السطر_ن: نـص؛\n\tمؤقت = ' '؛\n\tبينما مؤقت != '\\n' {\n\t\tنـم.اقرأ(مؤقت~مؤشر، 1، 1، ملف)؛\n\t\tالسطر_ن.ألحق(مؤقت)؛\n\t}\n\t\n\tارجع السطر_ن؛\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, Check if a given directed graph is a DAG"}, {"role": "assistant", "content": "let graph = [];\nlet visited = [];\nlet n;\n\nfunction isCyclic(i) {\n if (visited[i] === 2) {\n return true;\n }\n visited[i] = 1;\n for (let j = 0; j < graph[i].length; j++) {\n let node = graph[i][j];\n if (visited[node] === 1) return true;\n else if (visited[node] === 0 && isCyclic(node)) return true;\n }\n visited[i] = 2;\n return false;\n}\n\nfunction isDAG() {\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < n; j++) {\n visited[j] = 0;\n }\n if (isCyclic(i)) {\n return false;\n }\n }\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\nvoid selectionSort(int arr[], int n) {\n int i, j, min_idx, temp;\n\n // One by one move boundary of unsorted subarray\n for (i = 0; i < n-1; i++) {\n // Find the minimum element in unsorted array\n min_idx = i;\n for (j = i+1; j < n; j++)\n if (arr[j] < arr[min_idx])\n min_idx = j;\n\n // Swap the found minimum element with the first element\n temp = arr[min_idx];\n arr[min_idx] = arr[i];\n arr[i] = temp;\n }\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\n\nfunc selectionSort(a: ref[Array[Int]]) {\n def i: Int;\n def j: Int;\n def temp: Int;\n def min_idx: Int;\n\n for i = 0 , i < a.getLength() - 1 , i++ {\n min_idx = i;\n for j = i + 1 , j < a.getLength() , j++ {\n if a(j) < a(min_idx) {\n min_idx = j;\n }\n }\n\n temp = a(min_idx);\n a(min_idx) = a(i);\n a(i) = temp;\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nlet graph = [];\nlet visited = [];\nlet n;\n\nfunction isCyclic(i) {\n if (visited[i] === 2) {\n return true;\n }\n visited[i] = 1;\n for (let j = 0; j < graph[i].length; j++) {\n let node = graph[i][j];\n if (visited[node] === 1) return true;\n else if (visited[node] === 0 && isCyclic(node)) return true;\n }\n visited[i] = 2;\n return false;\n}\n\nfunction isDAG() {\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < n; j++) {\n visited[j] = 0;\n }\n if (isCyclic(i)) {\n return false;\n }\n }\n return true;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\nfunc isCyclic(node: Int, visited: ref[Array[Int]], graph: ref[Array[Array[Int]]]): Bool {\n if visited(node) == 2 {\n return true;\n }\n visited(node) = 1;\n\n def i: Int;\n for i = 0 , i < graph(node).getLength(), i++ {\n def childNode: Int = graph(node)(i);\n if visited(childNode) == 1 {\n return true;\n }\n else if visited(childNode) == 0 && isCyclic(childNode, visited, graph){\n return true;\n }\n }\n visited(node) = 2;\n return false;\n}\n\n\nfunc isDAG(graph: ref[Array[Array[Int]]]): Bool {\n def visited: Array[Int];\n def i: Int;\n\n for i = 0 , i < graph.getLength() , i++ {\n def j: Int;\n for j = 0 , j < graph.getLength() , j++ {\n visited.add(0);\n }\n if isCyclic(i, visited, graph) {\n return false;\n }\n visited.clear();\n }\n\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\n#include <stdlib.h>\n#include <string.h>\n\nchar* replace(char* str, char oldChar, char newChar) {\n int len = strlen(str);\n char* result = (char*)malloc(sizeof(char) * (len + 1));\n int i;\n\n for(i = 0; i < len; i++) {\n if(str[i] == oldChar) {\n result[i] = newChar;\n } else {\n result[i] = str[i];\n }\n }\n result[i] = '\\0';\n\n return result;\n}\n"}, {"role": "assistant", "content": "import \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc replace(s: ref[String], oldChar: Char, newChar: Char): String {\n def result: String;\n\n def i: Int;\n for i = 0 , i < s.getLength() , i++ {\n if (s(i) == oldChar) {\n result.append(newChar);\n }\n else {\n result.append(s(i));\n }\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, Write Floyd Warshall algorithm for a given graph"}, {"role": "assistant", "content": "#define V 4\n\nvoid floydWarshall (int graph[V][V], int dist[V][V]) \n{ \n int i, j, k; \n \n for (i = 0; i < V; i++) \n for (j = 0; j < V; j++) \n dist[i][j] = graph[i][j]; \n \n for (k = 0; k < V; k++) \n { \n for (i = 0; i < V; i++) \n { \n for (j = 0; j < V; j++) \n { \n if (dist[i][k] + dist[k][j] < dist[i][j]) \n dist[i][j] = dist[i][k] + dist[k][j]; \n } \n } \n }\n} \n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/ريـاضيات\"؛\n\nاستخدم مـتم؛\n\n\nصنف نـقطة {\n\tعرف س: عـائم؛\n\tعرف ص: عـائم؛\n}\n\nدالة مساحة_مثلث(ن1: نـقطة، ن2: نـقطة، ن3: نـقطة): عـائم {\n\tارجع ريـاضيات.مطلق(ن1.س*(ن2.ص - ن3.ص) + ن2.س*(ن3.ص - ن1.ص) + ن3.س*(ن1.ص - ن2.ص)) / 2.0؛\n}\n"}, {"role": "assistant", "content": "#include <stdlib.h>\n\ntypedef struct {\n float x;\n float y;\n} Point;\n\ndouble triangleArea(Point p1, Point p2, Point p3) {\n return abs(p1.x*(p2.y-p3.y) + p2.x*(p3.y-p1.y) + p3.x*(p1.y-p2.y)) / 2.0;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc exists(a: ref[Array[Int]], val: Int): Bool {\n def i: Int;\n for i = 0, i < a.getLength(), i++ {\n if a(i) == val {\n return true;\n }\n }\n return false;\n}\n"}, {"role": "assistant", "content": "#include <stdbool.h>\n\nbool exists(int a[], int n, int val) {\n for (int i = 0; i < n; i++) {\n if (a[i] == val) {\n return true;\n }\n }\n return false;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction filter(a, condition) {\n let result = [];\n for(let i = 0; i < a.length; i++) {\n if(condition(a[i])) {\n result.push(a[i]);\n }\n }\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة فلتر(م: سند[مـصفوفة[صـحيح]]، د: مغلفة(رقم: صـحيح): ثـنائي): مـصفوفة[صـحيح] {\n\tعرف نتيجة: مـصفوفة[صـحيح]؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا د(م(دليل)) {\n\t\t\tنتيجة.أضف(م(دليل))؛\n\t\t}\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\nvoid selectionSort(int arr[], int n) {\n int i, j, min_idx, temp;\n\n // One by one move boundary of unsorted subarray\n for (i = 0; i < n-1; i++) {\n // Find the minimum element in unsorted array\n min_idx = i;\n for (j = i+1; j < n; j++)\n if (arr[j] < arr[min_idx])\n min_idx = j;\n\n // Swap the found minimum element with the first element\n temp = arr[min_idx];\n arr[min_idx] = arr[i];\n arr[i] = temp;\n }\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة الترتيب_بالاختيار(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tعرف مؤقت: صـحيح؛\n\tعرف أصغر_دليل: صـحيح؛\n\t\n\tلكل دليل1 = 0 ، دليل1 < م.هات_الطول() - 1 ، دليل1++ {\n\t\tأصغر_دليل = دليل1؛\n\t\t\n\t\tلكل دليل2 = دليل1 + 1 ، دليل2 < م.هات_الطول() ، دليل2++ {\n\t\t\tإذا م(دليل2) < م(أصغر_دليل) {\n\t\t\t\tأصغر_دليل = دليل2؛\n\t\t\t}\n\t\t}\n\t\t\n\t\tمؤقت = م(أصغر_دليل)؛\n\t\tم(أصغر_دليل) = م(دليل1)؛\n\t\tم(دليل1) = مؤقت؛\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة استبدل(س: سند[نـص]، م1: مـحرف، م2: مـحرف): نـص {\n\tعرف نتيجة: نـص؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) == م1 {\n\t\t\tنتيجة.ألحق(م2)؛\n\t\t}\n\t\tوإلا {\n\t\t\tنتيجة.ألحق(س(دليل))؛\n\t\t}\n\t}\n\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc replace(s: ref[String], oldChar: Char, newChar: Char): String {\n def result: String;\n\n def i: Int;\n for i = 0 , i < s.getLength() , i++ {\n if (s(i) == oldChar) {\n result.append(newChar);\n }\n else {\n result.append(s(i));\n }\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc erase(a: ref[Array[Int]], pos: Int) {\n def size: Int = a.getLength();\n\n def i: Int;\n for i = pos , i < size - 1 , i++ {\n a(i) = a(i + 1);\n }\n a.remove(size - 1);\n}\n"}, {"role": "assistant", "content": "function erase(a, n, pos) {\n // Shift elements to left\n for (let i = pos; i < n - 1; i++)\n a[i] = a[i + 1];\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Array\";\nimport \"Srl/Console\";\n\n\nuse Srl;\n\n\nfunc print(a: ref[Array[Int]]) {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n Console.print(\"%d \", a(i));\n }\n}\n"}, {"role": "assistant", "content": "print the given array"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\nint find_diff_index(int arr1[], int arr2[], int n) {\n int i;\n for(i = 0; i < n; i++) {\n if(arr1[i] != arr2[i]) {\n return i;\n }\n }\n return -1; // return -1 if no difference is found\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جد_بداية_الاختلاف(م1: سند[مـصفوفة[صـحيح]]، م2: سند[مـصفوفة[صـحيح]]): صـحيح {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م1.هات_الطول() ، دليل++ {\n\t\tإذا م1(دليل) != م2(دليل) {\n\t\t\tارجع دليل؛\n\t\t}\n\t}\n\tارجع -1؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nlet graph = [];\nlet visited = [];\nlet n;\n\nfunction isCyclic(i) {\n if (visited[i] === 2) {\n return true;\n }\n visited[i] = 1;\n for (let j = 0; j < graph[i].length; j++) {\n let node = graph[i][j];\n if (visited[node] === 1) return true;\n else if (visited[node] === 0 && isCyclic(node)) return true;\n }\n visited[i] = 2;\n return false;\n}\n\nfunction isDAG() {\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < n; j++) {\n visited[j] = 0;\n }\n if (isCyclic(i)) {\n return false;\n }\n }\n return true;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nدالة هل_حلقي(عقدة: صـحيح، مزارة: سند[مـصفوفة[صـحيح]]، بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]): ثـنائي {\n\tإذا مزارة(عقدة) == 2 {\n\t\tارجع صح؛\n\t}\n\tمزارة(عقدة) = 1؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان(عقدة).هات_الطول() ، دليل++ {\n\t\tعرف عقدة_ابن: صـحيح = بيان(عقدة)(دليل)؛\n\t\tإذا مزارة(عقدة_ابن) == 1 {\n\t\t\tارجع صح؛\n\t\t}\n\t\tوإلا إذا مزارة(عقدة_ابن) == 0 && هل_حلقي(عقدة_ابن، مزارة، بيان) {\n\t\t\tارجع صح؛\n\t\t}\n\t}\n\tمزارة(عقدة) = 2؛\n\tارجع خطأ؛\n}\n\n\nدالة هل_داغ(بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]): ثـنائي {\n\tعرف مزارة: مـصفوفة[صـحيح]؛\n\t\n\tعرف دليل1: صـحيح؛\n\tعرف عدد_المكونات: صـحيح = 0؛\n\tلكل دليل1 = 0 ، دليل1 < بيان.هات_الطول() ، دليل1++ {\n\t\tعرف دليل2: صـحيح؛\n\t\tلكل دليل2 = 0 ، دليل2 < بيان.هات_الطول() ، دليل2++ {\n\t\t\tمزارة.أضف(0)؛\n\t\t}\n\n\t\tإذا هل_حلقي(دليل1، مزارة، بيان) {\n\t\t\tارجع خطأ؛\n\t\t}\n\t\tمزارة.فرغ()؛\n\t}\n\t\n\tارجع صح؛\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, Check if a given directed graph is a DAG"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\nfunc isCyclic(node: Int, visited: ref[Array[Int]], graph: ref[Array[Array[Int]]]): Bool {\n if visited(node) == 2 {\n return true;\n }\n visited(node) = 1;\n\n def i: Int;\n for i = 0 , i < graph(node).getLength(), i++ {\n def childNode: Int = graph(node)(i);\n if visited(childNode) == 1 {\n return true;\n }\n else if visited(childNode) == 0 && isCyclic(childNode, visited, graph){\n return true;\n }\n }\n visited(node) = 2;\n return false;\n}\n\n\nfunc isDAG(graph: ref[Array[Array[Int]]]): Bool {\n def visited: Array[Int];\n def i: Int;\n\n for i = 0 , i < graph.getLength() , i++ {\n def j: Int;\n for j = 0 , j < graph.getLength() , j++ {\n visited.add(0);\n }\n if isCyclic(i, visited, graph) {\n return false;\n }\n visited.clear();\n }\n\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction accumulate(a, f) {\n for (let i = 0 ; i < a.length ; i++) {\n a[i] = f(a[i]);\n }\n}\n"}, {"role": "assistant", "content": "apply the given function `f` on each element of the given array `a` and return the result"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جد_بداية_الاختلاف(م1: سند[مـصفوفة[صـحيح]]، م2: سند[مـصفوفة[صـحيح]]): صـحيح {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م1.هات_الطول() ، دليل++ {\n\t\tإذا م1(دليل) != م2(دليل) {\n\t\t\tارجع دليل؛\n\t\t}\n\t}\n\tارجع -1؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc find_diff_index(a1: ref[Array[Int]], a2: ref[Array[Int]]): Int {\n def i: Int;\n for i = 0 , i < a1.getLength() , i++ {\n if a1(i) != a2(i) {\n return i;\n }\n }\n return -1;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\n#include <stdbool.h>\n\nbool is_alphabet(char c) {\n return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');\n}\n"}, {"role": "assistant", "content": "استخدم مـتم؛\n\n\nدالة ينتمي_للأبجدية(م: مـحرف): ثـنائي {\n\tارجع ( م <= 'Z' && م >= 'A') || ( م <= 'z' && م >= 'a')؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nvoid replace(int* arr, int len, int oldValue, int newValue) {\n for(int i = 0; i < len; i++) {\n if(arr[i] == oldValue) {\n arr[i] = newValue;\n }\n }\n}\n"}, {"role": "assistant", "content": "Replace a given value with another given value in a given array"}]}
{"messages": [{"role": "user", "content": "What this code do?\nconst fs = require('fs');\n\n// Function to read the content of a file into a string one character at a time\nfunction read_file(file_path) {\n const fileDescriptor = fs.openSync(file_path, 'r');\n let file_content = '';\n let buffer = Buffer.alloc(1);\n\n // Read the file one character at a time\n while(fs.readSync(fileDescriptor, buffer, 0, 1)) {\n file_content += buffer.toString();\n }\n\n fs.closeSync(fileDescriptor);\n return file_content;\n}\n"}, {"role": "assistant", "content": "Read the content of a text file given its path and return the result"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nuse Srl;\n\nfunc isPrime(num: Int): Bool {\n if num <= 1 {\n return false;\n }\n\n def i: Int;\n for i = 2 , i * i <= num , i++ {\n if num % i == 0 {\n return false;\n }\n }\n \n return true;\n}\n"}, {"role": "assistant", "content": "function isPrime(num) {\n if (num <= 1) {\n return false;\n }\n for (let i = 2; i * i <= num; i++) {\n if (num % i === 0) {\n return false;\n }\n }\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/ريـاضيات\"؛\n\nاستخدم مـتم؛\n\n\nدالة جداء_نقطي(شعاع1: سند[مـصفوفة[عـائم[64]]]، شعاع2: سند[مـصفوفة[عـائم[64]]]): عـائم[64] {\n\tعرف نتيجة: عـائم[64] = 0؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < شعاع1.هات_الطول() ، دليل++ {\n\t\tنتيجة += شعاع1(دليل) * شعاع2(دليل)؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"Srl/Math\";\n\nuse Srl;\n\n\nfunc dot_product(v1: ref[Array[Float[64]]], v2: ref[Array[Float[64]]]): Float[64] {\n def result: Float[64] = 0;\n\n def i: Int;\n for i = 0 , i < v1.getLength() , i++ {\n result += v1(i) * v2(i);\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة أزل(م: سند[مـصفوفة[صـحيح]]، موقع: صـحيح) {\n\tعرف حجم: صـحيح = م.هات_الطول()؛\n\n\tعرف دليل: صـحيح؛\n\tلكل دليل = موقع ، دليل < حجم - 1 ، دليل++ {\n\t\tم(دليل) = م(دليل + 1)؛\n\t}\n\tم.أزل(حجم - 1)؛\n}\n"}, {"role": "assistant", "content": "function erase(a, n, pos) {\n // Shift elements to left\n for (let i = pos; i < n - 1; i++)\n a[i] = a[i + 1];\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Array\";\n\nuse Srl;\n\nfunc findIntersection(a1: Float[64], b1: Float[64], c1: Float[64], a2: Float[64], b2: Float[64], c2: Float[64]): Array[Float[64]] {\n def result: Array[Float[64]];\n if a1*b2 - a2*b1 == 0 {\n return result;\n }\n\n result.add((b1*c2 - b2*c1) / (a1*b2 - a2*b1));\n result.add((a2*c1 - a1*c2) / (a1*b2 - a2*b1));\n\n return result;\n}\n"}, {"role": "assistant", "content": "function findIntersection(a1, b1, c1, a2, b2, c2) {\n // Check if the lines are parallel\n if(a1*b2 - a2*b1 === 0) {\n return null;\n }\n\n let result = [];\n result[0] = (b1*c2 - b2*c1) / (a1*b2 - a2*b1);\n result[1] = (a2*c1 - a1*c2) / (a1*b2 - a2*b1);\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/طـرفية\"؛\n\nاستخدم مـتم؛\n\n\nدالة اطبع(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tطـرفية.اطبع(\"%d \"، م(دليل))؛\n\t}\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"Srl/Console\";\n\n\nuse Srl;\n\n\nfunc print(a: ref[Array[Int]]) {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n Console.print(\"%d \", a(i));\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Array\";\n\nuse Srl;\n\nfunc isCyclic(node: Int, visited: ref[Array[Int]], graph: ref[Array[Array[Int]]]): Bool {\n if visited(node) == 2 {\n return true;\n }\n visited(node) = 1;\n\n def i: Int;\n for i = 0 , i < graph(node).getLength(), i++ {\n def childNode: Int = graph(node)(i);\n if visited(childNode) == 1 {\n return true;\n }\n else if visited(childNode) == 0 && isCyclic(childNode, visited, graph){\n return true;\n }\n }\n visited(node) = 2;\n return false;\n}\n\n\nfunc isDAG(graph: ref[Array[Array[Int]]]): Bool {\n def visited: Array[Int];\n def i: Int;\n\n for i = 0 , i < graph.getLength() , i++ {\n def j: Int;\n for j = 0 , j < graph.getLength() , j++ {\n visited.add(0);\n }\n if isCyclic(i, visited, graph) {\n return false;\n }\n visited.clear();\n }\n\n return true;\n}\n"}, {"role": "assistant", "content": "Check if a given directed graph is a DAG"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Array\";\nimport \"Srl/Console\";\n\n\nuse Srl;\n\n\nfunc print(a: ref[Array[Int]]) {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n Console.print(\"%d \", a(i));\n }\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/طـرفية\"؛\n\nاستخدم مـتم؛\n\n\nدالة اطبع(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tطـرفية.اطبع(\"%d \"، م(دليل))؛\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\n#include <stdlib.h>\n\ndouble** outer_product(double v1[], double v2[], int n) {\n double** result = (double**)malloc(n * sizeof(double*));\n for (int i = 0; i < n; i++) {\n result[i] = (double*)malloc(n * sizeof(double));\n for (int j = 0; j < n; j++) {\n result[i][j] = v1[i] * v2[j];\n }\n }\n return result;\n}\n"}, {"role": "assistant", "content": "Calculate the outer product of two given vectors each represented by an array and return the result"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جمع(م: سند[مـصفوفة[صـحيح]]، بداية: صـحيح، نهاية: صـحيح): صـحيح {\n\tعرف نتيجة: صـحيح = 0؛\n\n\tعرف دليل: صـحيح؛\n\n\tلكل دليل = بداية ، دليل < نهاية ، دليل++ {\n نتيجة += م(دليل)؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "function sum(a, start, end) {\n let result = 0;\n\n for (let i = start; i < end; i++) {\n result += a[i];\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\n#include <math.h>\n\ndouble std(int data[], int n, float mean)\n{\n double variance = 0.0;\n\n for(int i=0; i<n; ++i)\n variance += (data[i] - mean) * (data[i] - mean);\n\n return sqrt(variance/n);\n}\n"}, {"role": "assistant", "content": "calculate and return the standard deviation of the given array"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction rfind(a, val) {\n for (let i = a.length - 1; i != 0 ; i--) {\n if (a[i] == val) {\n return i;\n }\n }\n return -1;\n}\n"}, {"role": "assistant", "content": "Find and return the position of a given element in the given array starting from its end"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nعرف قيمة_عظمى: صـحيح = 100000؛\n\nدالة الترتيب_بالعد(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tعرف دليل: صـحيح؛\n\t\n\tعرف عداد: مـصفوفة[صـحيح]؛\n\tلكل دليل1 = 0 ، دليل1 < قيمة_عظمى ، دليل1++ {\n\t\tعداد.أضف(0)؛\n\t}\n\t\n\tلكل دليل1 = 0 ، دليل1 < م.هات_الطول() ، دليل1++ {\n\t\tعداد(م(دليل1))++؛\n\t}\n\t\n\tلكل دليل1 = 0 ، دليل1 < قيمة_عظمى ، دليل1++ {\n\t\tلكل دليل2 = 0 ، دليل2 < عداد(دليل1) ، دليل2++ {\n\t\t\tم(دليل++) = دليل1؛\n\t\t}\n\t}\n}\n"}, {"role": "assistant", "content": "اكتب خوارزمية الفرز بالعد لمصفوفة معطاة"}]}
{"messages": [{"role": "user", "content": "Using c, Append a given log entry to a file given its path"}, {"role": "assistant", "content": "#include <stdio.h>\n#include <string.h>\n\nvoid appendLogEntry(char *filename, char *logEntry) {\n FILE *file = fopen(filename, \"a\");\n\n fwrite(logEntry, 1, strlen(logEntry), file);\n fwrite(\"\\n\", 1, 1, file);\n fclose(file);\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة اجتزئ(م: سند[مـصفوفة[صـحيح]]، بداية: صـحيح، نهاية: صـحيح، نتيجة: سند[مـصفوفة[صـحيح]]) {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = بداية ، دليل <= نهاية ، دليل++ {\n\t\tنتيجة.أضف(م(دليل))؛\n\t}\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc slice(a: ref[Array[Int]], start: Int, end: Int, result: ref[Array[Int]]) {\n def i: Int;\n for i = start , i <= end , i++ {\n result.add(a(i));\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nvoid rotate(int a[], int n) {\n int first_element = a[0];\n\n for (int i = 0 ; i < n - 1; i++) {\n a[i] = a[i + 1];\n }\n\n a[n - 1] = first_element;\n}\n"}, {"role": "assistant", "content": "rotate the given array counterclockwise and return the result"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Array\";\nimport \"Srl/Console\";\n\n\nuse Srl;\n\n\nfunc print(a: ref[Array[Int]]) {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n Console.print(\"%d \", a(i));\n }\n}\n"}, {"role": "assistant", "content": "function printArray(a, size) {\n var output = '';\n for(var i = 0; i < size; i++) {\n output += a[i] + ' ';\n }\n console.log(output);\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, Split a given string into a list of strings based on a given character"}, {"role": "assistant", "content": "function split(str, token) {\n let result = [];\n let temp = \"\";\n\n for(let i = 0; i < str.length; i++) {\n if(str[i] !== token) {\n temp += str[i];\n } else {\n result.push(temp);\n temp = \"\";\n }\n }\n\n // Push the last substring if it's not empty\n if(temp !== \"\") {\n result.push(temp);\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, Remove any whitespace character from both ends of a given string"}, {"role": "assistant", "content": "#include <string.h>\n\nvoid trim(char *str) {\n int start = 0, end = strlen(str) - 1;\n\n // Trim leading white spaces\n while(str[start] == ' ' || str[start] == '\\t' || str[start] == '\\n') start++;\n\n // Trim trailing white spaces\n while(str[end] == ' ' || str[end] == '\\t' || str[end] == '\\n') end--;\n\n // Shift characters\n memmove(str, str + start, end - start + 1);\n\n // Null terminate the string\n str[end - start + 1] = '\\0';\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة راكم(م: سند[مـصفوفة[صـحيح]]، د: مغلفة(قيمة_سابقة: صـحيح، قيمة_حالية: صـحيح): صـحيح): مـصفوفة[صـحيح] {\n\tعرف طول: صـحيح = م.هات_الطول()؛\n\tعرف نتيجة: مـصفوفة[صـحيح]؛\n\t\n\tعرف دليل: صـحيح؛\n\tنتيجة.أضف(م(0))؛\n\tلكل دليل = 1 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tنتيجة.أضف(د(نتيجة(دليل - 1)، م(دليل)))؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "function accumulate(a, f) {\n let result = [];\n result[0] = a[0];\n for(let i = 1; i < a.length; i++) {\n result[i] = f(result[i-1], a[i]);\n }\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Array\";\nimport \"Srl/Console\";\n\nuse Srl;\n\nfunc dfs(node: Int, visited: ref[Array[Bool]], graph: ref[Array[Array[Int]]]) {\n visited(node) = true;\n Console.print(\"%d \", node);\n\n def i: Int;\n for i = 0 , i < graph(node).getLength(), i++ {\n def childNode: Int = graph(node)(i);\n if !visited(childNode) {\n dfs(childNode, visited, graph);\n }\n }\n}\n"}, {"role": "assistant", "content": "Write DFS algorithm for the given graph"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Math\";\nimport \"Srl/Array\";\n\n\n\nuse Srl;\n\nclass Point {\n def x : Float;\n def y : Float;\n};\n\nfunc calculateDistance(a: Point, b: Point): Float {\n return Math.sqrt(Math.pow(b.x - a.x, 2.0) + Math.pow(b.y - a.y, 2.0));\n}\n\nfunc findFarthestPoint(givenPoint: Point, points: ref[Array[Point]]): Point {\n def maxDistance: Float = 0;\n def farthestPoint: Point;\n\n def i: Int;\n for i = 0 , i < points.getLength() , i++ {\n def distance: Float = calculateDistance(givenPoint, points(i));\n if distance > maxDistance {\n maxDistance = distance;\n farthestPoint = points(i);\n }\n }\n\n return farthestPoint;\n}\n"}, {"role": "assistant", "content": "#include <math.h>\n\ntypedef struct {\n double x;\n double y;\n} Point;\n\ndouble calculateDistance(Point a, Point b) {\n return sqrt(pow(b.x - a.x, 2) + pow(b.y - a.y, 2));\n}\n\nPoint findFarthestPoint(Point givenPoint, Point points[], int size) {\n double maxDistance = 0;\n Point farthestPoint;\n \n for(int i = 0; i < size; i++) {\n double distance = calculateDistance(givenPoint, points[i]);\n if(distance > maxDistance) {\n maxDistance = distance;\n farthestPoint = points[i];\n }\n }\n \n return farthestPoint;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, reduce the given array `a` using the given function `f` and return the result"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"Srl/String\";\nimport \"closure\";\n\nuse Srl;\n\n\nfunc reduce(a: ref[Array[String]], f: closure(previousValue: ref[String], currentValue: ref[String])): String {\n def result: String = \"\";\n\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n f(result, a(i));\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\n#include <stdio.h>\n#define MAX 100\n\nint graph[MAX][MAX];\nint visited[MAX];\nint n;\n\nint isCyclic(int i) {\n if (visited[i] == 2) {\n return 1;\n }\n visited[i] = 1;\n for (int j = 0; j < n; j++) {\n if (graph[i][j]) {\n if (visited[j] == 1) return 1;\n else if (visited[j] == 0 && isCyclic(j)) return 1;\n }\n }\n visited[i] = 2;\n return 0;\n}\n\nint isDAG() {\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n visited[j] = 0;\n }\n if (isCyclic(i)) {\n return 0;\n }\n }\n return 1;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\nfunc isCyclic(node: Int, visited: ref[Array[Int]], graph: ref[Array[Array[Int]]]): Bool {\n if visited(node) == 2 {\n return true;\n }\n visited(node) = 1;\n\n def i: Int;\n for i = 0 , i < graph(node).getLength(), i++ {\n def childNode: Int = graph(node)(i);\n if visited(childNode) == 1 {\n return true;\n }\n else if visited(childNode) == 0 && isCyclic(childNode, visited, graph){\n return true;\n }\n }\n visited(node) = 2;\n return false;\n}\n\n\nfunc isDAG(graph: ref[Array[Array[Int]]]): Bool {\n def visited: Array[Int];\n def i: Int;\n\n for i = 0 , i < graph.getLength() , i++ {\n def j: Int;\n for j = 0 , j < graph.getLength() , j++ {\n visited.add(0);\n }\n if isCyclic(i, visited, graph) {\n return false;\n }\n visited.clear();\n }\n\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة اعكس_مصفوفة(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف بداية: صـحيح = 0؛\n\tعرف نهاية: صـحيح = م.هات_الطول() - 1؛\n\n\tبينما بداية < نهاية {\n\t\tعرف مؤقت: صـحيح = م(بداية)؛\n\t\tم(بداية) = م(نهاية)؛\n\t\tم(نهاية) = مؤقت؛\n\t\tبداية++؛\n\t\tنهاية--؛\n\t}\n}\n"}, {"role": "assistant", "content": "اعكس المصفوفة المعطاة م و أرجع النتيجة"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة موجود(م: سند[مـصفوفة[صـحيح]]، قيمة: صـحيح): ثـنائي {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا م(دليل) == قيمة {\n\t\t\tارجع صح؛\n\t\t}\n\t}\n\tارجع خطأ؛\n}\n"}, {"role": "assistant", "content": "#include <stdbool.h>\n\nbool exists(int a[], int n, int val) {\n for (int i = 0; i < n; i++) {\n if (a[i] == val) {\n return true;\n }\n }\n return false;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Math\";\nimport \"Srl/Array\";\n\n\n\nuse Srl;\n\nclass Point {\n def x : Float;\n def y : Float;\n};\n\nfunc calculateDistance(a: Point, b: Point): Float {\n return Math.sqrt(Math.pow(b.x - a.x, 2.0) + Math.pow(b.y - a.y, 2.0));\n}\n\nfunc findFarthestPoint(givenPoint: Point, points: ref[Array[Point]]): Point {\n def maxDistance: Float = 0;\n def farthestPoint: Point;\n\n def i: Int;\n for i = 0 , i < points.getLength() , i++ {\n def distance: Float = calculateDistance(givenPoint, points(i));\n if distance > maxDistance {\n maxDistance = distance;\n farthestPoint = points(i);\n }\n }\n\n return farthestPoint;\n}\n"}, {"role": "assistant", "content": "class Point {\n constructor(x, y) {\n this.x = x;\n this.y = y;\n }\n}\n\nfunction calculateDistance(a, b) {\n return Math.sqrt(Math.pow(b.x - a.x, 2) + Math.pow(b.y - a.y, 2));\n}\n\nfunction findFarthestPoint(givenPoint, points) {\n let maxDistance = 0;\n let farthestPoint;\n \n for(let i = 0; i < points.length; i++) {\n let distance = calculateDistance(givenPoint, points[i]);\n if(distance > maxDistance) {\n maxDistance = distance;\n farthestPoint = points[i];\n }\n }\n \n return farthestPoint;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة المحرف_متواجد(س: سند[نـص]، م: مـحرف): ثـنائي {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) == م {\n\t\t\tارجع صح؛\n\t\t}\n\t}\n\tارجع خطأ؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc char_exists(s: ref[String], c: Char): Bool {\n def i: Int;\n\tfor i = 0 , i < s.getLength() , i++ {\n\t\tif (s(i) == c) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction split(str, token) {\n let result = [];\n let temp = \"\";\n\n for(let i = 0; i < str.length; i++) {\n if(str[i] !== token) {\n temp += str[i];\n } else {\n result.push(temp);\n temp = \"\";\n }\n }\n\n // Push the last substring if it's not empty\n if(temp !== \"\") {\n result.push(temp);\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "import \"Srl/String\";\nimport \"Srl/Array\"\n\nuse Srl;\n\n\nfunc split(s: ref[String], token: Char): Array[String] {\n def result: Array[String];\n\n def temp: String;\n def i: Int;\n for i = 0 , i < s.getLength() , i++ {\n if (s(i) != token) {\n temp.append(s(i));\n }\n else {\n result.add(temp);\n temp = \"\";\n }\n }\n result.add(temp);\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, Find and return the position of a given element in the given array starting from its end"}, {"role": "assistant", "content": "int rfind(int a[], int n, int val) {\n for (int i = n - 1; i != 0; i--) {\n if (a[i] == val) {\n return i;\n }\n }\n return -1;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Array\";\n\nuse Srl;\n\nfunc dfs(node: Int, parentNode: Int, visited: ref[Array[Bool]], graph: ref[Array[Array[Int]]]): Bool {\n visited(node) = true;\n\n def i: Int;\n for i = 0 , i < graph(node).getLength(), i++ {\n def childNode: Int = graph(node)(i);\n if !visited(childNode) {\n if dfs(childNode, node, visited, graph) {\n return true;\n }\n }\n else if childNode != parentNode {\n return true;\n }\n }\n return false;\n}\n\n\nfunc isTree(graph: ref[Array[Array[Int]]]): Bool {\n def visited: Array[Bool];\n def i: Int;\n for i = 0 , i < graph.getLength() , i++ {\n visited.add(false);\n }\n\n if dfs(0, -1, visited, graph) {\n return false;\n }\n\n for i = 0 , i < graph.getLength() , i++ {\n if !visited(i) {\n return false;\n }\n }\n\n return true;\n}\n"}, {"role": "assistant", "content": "#include <stdio.h>\n\n#define MAX 100\n\nint visited[MAX];\nint matrix[MAX][MAX];\n\nint DFS(int v, int parent, int n) {\n visited[v] = 1;\n for(int i = 0; i < n; i++) {\n if(matrix[v][i] == 1) {\n if(!visited[i]) {\n if(DFS(i, v, n)) {\n return 1;\n }\n } else if(i != parent) {\n return 1;\n }\n }\n }\n return 0;\n}\n\nint isTree(int n) {\n if(DFS(0, -1, n)) {\n return 0;\n }\n for(int i = 0; i < n; i++) {\n if(!visited[i]) {\n return 0;\n }\n }\n return 1;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\n#include <stdio.h>\n#define MAX 100\n\nint graph[MAX][MAX];\nint visited[MAX];\nint n;\n\nint isCyclic(int i) {\n if (visited[i] == 2) {\n return 1;\n }\n visited[i] = 1;\n for (int j = 0; j < n; j++) {\n if (graph[i][j]) {\n if (visited[j] == 1) return 1;\n else if (visited[j] == 0 && isCyclic(j)) return 1;\n }\n }\n visited[i] = 2;\n return 0;\n}\n\nint isDAG() {\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n visited[j] = 0;\n }\n if (isCyclic(i)) {\n return 0;\n }\n }\n return 1;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nدالة هل_حلقي(عقدة: صـحيح، مزارة: سند[مـصفوفة[صـحيح]]، بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]): ثـنائي {\n\tإذا مزارة(عقدة) == 2 {\n\t\tارجع صح؛\n\t}\n\tمزارة(عقدة) = 1؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان(عقدة).هات_الطول() ، دليل++ {\n\t\tعرف عقدة_ابن: صـحيح = بيان(عقدة)(دليل)؛\n\t\tإذا مزارة(عقدة_ابن) == 1 {\n\t\t\tارجع صح؛\n\t\t}\n\t\tوإلا إذا مزارة(عقدة_ابن) == 0 && هل_حلقي(عقدة_ابن، مزارة، بيان) {\n\t\t\tارجع صح؛\n\t\t}\n\t}\n\tمزارة(عقدة) = 2؛\n\tارجع خطأ؛\n}\n\n\nدالة هل_داغ(بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]): ثـنائي {\n\tعرف مزارة: مـصفوفة[صـحيح]؛\n\t\n\tعرف دليل1: صـحيح؛\n\tعرف عدد_المكونات: صـحيح = 0؛\n\tلكل دليل1 = 0 ، دليل1 < بيان.هات_الطول() ، دليل1++ {\n\t\tعرف دليل2: صـحيح؛\n\t\tلكل دليل2 = 0 ، دليل2 < بيان.هات_الطول() ، دليل2++ {\n\t\t\tمزارة.أضف(0)؛\n\t\t}\n\n\t\tإذا هل_حلقي(دليل1، مزارة، بيان) {\n\t\t\tارجع خطأ؛\n\t\t}\n\t\tمزارة.فرغ()؛\n\t}\n\t\n\tارجع صح؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/نـم\"؛\nاشمل \"مـتم/نـص\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة اقرأ_الملف_إلى_مصفوفة(مسار_الملف: سند[نـص]): مـصفوفة[نـص] {\n\tعرف ملف: مؤشر[نـم.مـلف] = نـم.افتح_ملف(مسار_الملف، \"r\")؛\n\tعرف المحتوى: مـصفوفة[نـص]؛\n\n\tنـم.انتقل(ملف، 0، نـم.انـتقال._نهاية_)؛\n\tعرف حجم: صـحيح = نـم.هات_الموقع(ملف)؛\n\tنـم.انتقل(ملف، 0، نـم.انـتقال._بداية_)؛\n\t\n\tالمحتوى.أضف(نـص())؛\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح = 0؛\n\tلكل دليل1 = 0 ، دليل1 < حجم ، دليل1++ {\n\t\tعرف مؤقت: مـحرف؛\n\t\tنـم.اقرأ(مؤقت~مؤشر، 1، 1، ملف)؛\n\t\t\n\t\tإذا مؤقت == '\\n' {\n\t\t\tالمحتوى.أضف(نـص())؛\n\t\t\tدليل2++؛\n\t\t}\n\t\tوإلا {\n\t\t\tالمحتوى(دليل2).ألحق(مؤقت)؛\n\t\t}\n\t}\n\t\n\tارجع المحتوى؛\n}\n"}, {"role": "assistant", "content": "اقرأ أسطر ملف نصي معطى مساره إلى مصفوفة و ارجعها"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\n#include <stdio.h>\n#include <stdlib.h>\n\n// Function to read the content of a file into a string\nchar* read_file(const char* file_path) {\n FILE* file = fopen(file_path, \"r\");\n if(file == NULL) {\n printf(\"Could not open file %s\\n\", file_path);\n return NULL;\n }\n\n // Get the size of the file\n fseek(file, 0, SEEK_END);\n long file_size = ftell(file);\n fseek(file, 0, SEEK_SET);\n\n // Allocate memory for the string\n char* str = malloc(file_size + 1);\n if(str == NULL) {\n printf(\"Could not allocate memory for the string\\n\");\n fclose(file);\n return NULL;\n }\n\n // Read the file into the string one character at a time\n for(long i = 0; i < file_size; i++) {\n fread(&str[i], sizeof(char), 1, file);\n }\n\n // Null-terminate the string\n str[file_size] = '\\0';\n\n fclose(file);\n return str;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/نـم\"؛\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة اقرأ_الملف(مسار_الملف: سند[نـص]): نـص {\n\tعرف ملف: مؤشر[نـم.مـلف] = نـم.افتح_ملف(مسار_الملف، \"r\")؛\n\t\n\tنـم.انتقل(ملف، 0، نـم.انـتقال._نهاية_)؛\n\tعرف حجم: صـحيح = نـم.هات_الموقع(ملف)؛\n\tنـم.انتقل(ملف، 0، نـم.انـتقال._بداية_)؛\n\t\n\tعرف المحتوى: نـص؛\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < حجم ، دليل++ {\n\t\tعرف مؤقت: مـحرف؛\n\t\tنـم.اقرأ(مؤقت~مؤشر، 1، 1، ملف)؛\n\t\tالمحتوى.ألحق(مؤقت)؛\n\t}\n\t\n\tارجع المحتوى؛\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, طبق الدالة المعطاة د على كل عنصر من عناصر المصفوفة المعطاة م و أرجع النتيجة"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة لكل_عنصر(م: سند[مـصفوفة[صـحيح]]، د: مغلفة(عنصر: صـحيح): صـحيح) {\n\tعرف دليل: صـحيح؛\n\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tم(دليل) = د(م(دليل))؛\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\n#include <stdio.h>\n#include <string.h>\n\nvoid appendLogEntry(char *filename, char *logEntry) {\n FILE *file = fopen(filename, \"a\");\n\n fwrite(logEntry, 1, strlen(logEntry), file);\n fwrite(\"\\n\", 1, 1, file);\n fclose(file);\n}\n"}, {"role": "assistant", "content": "import \"Srl/Fs\";\nimport \"Srl/String\";\n\nuse Srl;\n\n\nfunc appendLogEntry(file_path: ref[String], logEntry: ref[String]) {\n def file: ptr[Fs.File] = Fs.openFile(file_path.buf, \"a\");\n\n Fs.write(logEntry.buf, 1, logEntry.getLength(), file);\n Fs.write(\"\\n\", 1, 1, file);\n Fs.closeFile(file);\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة اقتطع(م: سند[مـصفوفة[صـحيح]]، أدنى: صـحيح، أعلى: صـحيح) {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا م(دليل) < أدنى {\n\t\t\tم(دليل) = أدنى؛\n\t\t}\n\t\tوإلا إذا م(دليل) > أعلى {\n\t\t\tم(دليل) = أعلى؛\n\t\t}\n\t}\n}\n"}, {"role": "assistant", "content": "function clip(arr, lower, upper) {\n for(let i = 0; i < arr.length; i++) {\n if(arr[i] < lower) {\n arr[i] = lower;\n } else if(arr[i] > upper) {\n arr[i] = upper;\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\nvoid replace(int* arr, int len, int oldValue, int newValue) {\n for(int i = 0; i < len; i++) {\n if(arr[i] == oldValue) {\n arr[i] = newValue;\n }\n }\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc replace(a: ref[Array[Int]], oldValue: Int, newValue: Int) {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if a(i) == oldValue {\n a(i) = newValue;\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nuse Srl;\n\n\nfunc is_alpha(c: Char): Bool {\n return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');\n}\n"}, {"role": "assistant", "content": "function is_alphabet(c) {\n return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nconst fs = require('fs');\n\nfunction appendLogEntry(filename, logEntry) {\n let stream = fs.createWriteStream(filename, {flags:'a'});\n stream.write(logEntry + '\\n');\n stream.end();\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/نـم\"؛\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة ألحق_سجل(مسار_الملف: سند[نـص]، سجل: سند[نـص]) {\n\tعرف ملف: مؤشر[نـم.مـلف] = نـم.افتح_ملف(مسار_الملف، \"a\")؛\n\t\n\tنـم.اكتب(سجل.صوان، 1، سجل.هات_الطول()، ملف)؛\n\tنـم.اكتب(\"\\ج\"، 1، 1، ملف)؛\n\tنـم.اغلق_ملف(ملف)؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/نـم\"؛\nاشمل \"مـتم/نـص\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة اقرأ_الملف_إلى_مصفوفة(مسار_الملف: سند[نـص]): مـصفوفة[نـص] {\n\tعرف ملف: مؤشر[نـم.مـلف] = نـم.افتح_ملف(مسار_الملف، \"r\")؛\n\tعرف المحتوى: مـصفوفة[نـص]؛\n\n\tنـم.انتقل(ملف، 0، نـم.انـتقال._نهاية_)؛\n\tعرف حجم: صـحيح = نـم.هات_الموقع(ملف)؛\n\tنـم.انتقل(ملف، 0، نـم.انـتقال._بداية_)؛\n\t\n\tالمحتوى.أضف(نـص())؛\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح = 0؛\n\tلكل دليل1 = 0 ، دليل1 < حجم ، دليل1++ {\n\t\tعرف مؤقت: مـحرف؛\n\t\tنـم.اقرأ(مؤقت~مؤشر، 1، 1، ملف)؛\n\t\t\n\t\tإذا مؤقت == '\\n' {\n\t\t\tالمحتوى.أضف(نـص())؛\n\t\t\tدليل2++؛\n\t\t}\n\t\tوإلا {\n\t\t\tالمحتوى(دليل2).ألحق(مؤقت)؛\n\t\t}\n\t}\n\t\n\tارجع المحتوى؛\n}\n"}, {"role": "assistant", "content": "#include <stdio.h>\n#include <stdlib.h>\n\n#define MAX_LINE_LENGTH 1024\n#define MAX_LINES 1000\n\nvoid readFileToArray(char *filename, char lines[MAX_LINES][MAX_LINE_LENGTH]) {\n FILE *file = fopen(filename, \"r\");\n if(file == NULL) {\n printf(\"Cannot open file.\\n\");\n exit(1);\n }\n\n int i = 0, j = 0;\n while(!feof(file) && i < MAX_LINES) {\n fread(&lines[i][j], sizeof(char), 1, file);\n if(lines[i][j] == '\\n' || lines[i][j] == '\\0') {\n lines[i][j] = '\\0'; // end of string\n i++; // next line\n j = 0; // reset character index\n } else {\n j++;\n }\n }\n\n fclose(file);\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, check if a given string starts with another given string"}, {"role": "assistant", "content": "function startsWith(str, prefix) {\n for(let i = 0; i < prefix.length; i++) {\n if(str[i] !== prefix[i])\n return false;\n }\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, check if a given character is from the alphabet"}, {"role": "assistant", "content": "#include <stdbool.h>\n\nbool is_alphabet(char c) {\n return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, استبدل قيمة معطاة بآخرى معطاة في مصفوفة معطاة"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة استبدل(م: سند[مـصفوفة[صـحيح]]، ق1: صـحيح، ق2: صـحيح) {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا م(دليل) == ق1 {\n\t\t\tم(دليل) = ق2؛\n\t\t}\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, write the insertion sort algorithm for a given array"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\n\nfunc insertionSort(a: ref[Array[Int]]) {\n def i: Int;\n def key: Int;\n def j: Int;\n\n for i = 1 , i < a.getLength() , i++ {\n key = a(i);\n j = i - 1;\n\n while j >= 0 && a(j) > key {\n a(j + 1) = a(j);\n j = j - 1;\n }\n a(j + 1) = key;\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction replace(str, oldChar, newChar) {\n var result = \"\";\n for(var i = 0; i < str.length; i++) {\n if(str[i] == oldChar) {\n result += newChar;\n } else {\n result += str[i];\n }\n }\n return result;\n}\n"}, {"role": "assistant", "content": "import \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc replace(s: ref[String], oldChar: Char, newChar: Char): String {\n def result: String;\n\n def i: Int;\n for i = 0 , i < s.getLength() , i++ {\n if (s(i) == oldChar) {\n result.append(newChar);\n }\n else {\n result.append(s(i));\n }\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Array\";\n\nuse Srl;\n\n\nfunc merge(a: ref[Array[Int]], l: Int, m: Int, r: Int) {\n def i: Int;\n def j: Int;\n def k: Int;\n\n def n1: Int = m - l + 1;\n def n2: Int = r - m;\n\n def L: Array[Int];\n def R: Array[Int];\n\n for i = 0 , i < n1 , i++ {\n L.add(a(l+i));\n }\n for i = 0 , i < n2 , i++ {\n R.add(a(m + 1 + i));\n }\n\n i = 0;\n j = 0;\n k = l;\n while i < n1 && j < n2 {\n if L(i) <= R(j) {\n a(k) = L(i);\n i++;\n }\n else {\n a(k) = R(j);\n j++;\n }\n k++;\n }\n\n while i < n1 {\n a(k) = L(i);\n i++;\n k++;\n }\n\n while j < n2 {\n a(k) = R(j);\n j++;\n k++;\n }\n}\n\nfunc mergeSort(a: ref[Array[Int]], l: Int, r: Int) {\n if l < r {\n def m: Int = l + (r - l) / 2;\n\n mergeSort(a, l, m);\n mergeSort(a, m + 1, r);\n\n merge(a, l, m, r);\n }\n}\n"}, {"role": "assistant", "content": "write the merge sort algorithm for a given array"}]}
{"messages": [{"role": "user", "content": "Using c, Slice a given array within a given range"}, {"role": "assistant", "content": "void slice(int arr[], int start, int end, int result[]) {\n int i;\n for(i = start; i <= end; i++) {\n result[i - start] = arr[i];\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\nvoid foreach(int a[], int n, int (*f)(int)) {\n for(int i = 0; i < n; i++) {\n a[i] = f(a[i]);\n }\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة لكل_عنصر(م: سند[مـصفوفة[صـحيح]]، د: مغلفة(عنصر: صـحيح): صـحيح) {\n\tعرف دليل: صـحيح؛\n\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tم(دليل) = د(م(دليل))؛\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nvoid accumulate(int* a, int* result, int size, int (*f)(int, int)) {\n result[0] = a[0];\n for(int i = 1; i < size; i++) {\n result[i] = f(result[i-1], a[i]);\n }\n}\n"}, {"role": "assistant", "content": "accumulate the given array `a` using the given function `f` and keep the partial results and return them"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Fs\";\nimport \"Srl/String\";\nimport \"Srl/Array\";\n\nuse Srl;\n\n\nfunc readFileToArray(file_path: ref[String]): Array[String] {\n def file: ptr[Fs.File] = Fs.openFile(file_path.buf, \"r\");\n def content: Array[String];\n\n Fs.seek(file, 0, Fs.Seek.END);\n def size: Int = Fs.tell(file);\n Fs.seek(file, 0, Fs.Seek.SET);\n \n content.add(String());\n def i: Int;\n def j: Int = 0;\n for i = 0 , i < size , i++ {\n def temp: Char;\n Fs.read(temp~ptr, 1, 1, file);\n\n if temp == '\\n' {\n content.add(String());\n j++;\n }\n else {\n content(j).append(temp);\n }\n }\n\n return content;\n}\n"}, {"role": "assistant", "content": "const fs = require('fs');\n\nfunction readFileToArray(filename) {\n const data = fs.readFileSync(filename, 'utf8');\n let lines = [''];\n let j = 0;\n for (let i = 0; i < data.length; i++) {\n if (data[i] === '\\n') {\n lines.push('');\n j++;\n } else {\n lines[j] += data[i];\n }\n }\n return lines;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction Point(x, y) {\n this.x = x;\n this.y = y;\n}\n\nfunction areCollinear(p1, p2, p3) {\n // Calculate the slopes of the lines formed by (p1, p2) and (p1, p3)\n // If the slopes are equal, then p1, p2 and p3 are collinear\n return (p2.y - p1.y) * (p3.x - p1.x) === (p3.y - p1.y) * (p2.x - p1.x);\n}\n"}, {"role": "assistant", "content": "استخدم مـتم؛\n\n\nصنف نـقطة {\n\tعرف س: صـحيح؛\n\tعرف ص: صـحيح؛\n}\n\nدالة على_خط_مستقيم(ن1: نـقطة، ن2: نـقطة، ن3: نـقطة): ثـنائي {\n\tارجع (ن2.ص - ن1.ص) * (ن3.س - ن1.ص) == (ن3.ص - ن1.ص) * (ن2.س - ن1.س)؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc toLowerCase(s: ref[String]): String {\n\tdef result: String = \"\";\n def i: Int;\n\tdef c: Char;\n\tfor i = 0 , i < s.getLength() , i++ {\n\t\tif (s(i) >= 'A' && s(i) <= 'Z') {\n\t\t\tc = s(i) - 'A' + 'a';\n\t\t}\n\t\telse {\n\t\t\tc = s(i);\n\t\t}\n\t\tresult += c;\n\t}\n\treturn result;\n}\n"}, {"role": "assistant", "content": "convert string to lowercase and return the result"}]}
{"messages": [{"role": "user", "content": "Using js, accumulate the given array `a` using the given function `f` and keep the partial results and return them"}, {"role": "assistant", "content": "function accumulate(a, f) {\n let result = [];\n result[0] = a[0];\n for(let i = 1; i < a.length; i++) {\n result[i] = f(result[i-1], a[i]);\n }\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة الترتيب_بالحشر(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف دليل1: صـحيح؛\n\tعرف مفتاح: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\t\n\tلكل دليل1 = 1 ، دليل1 < م.هات_الطول() ، دليل1++ {\n\t\tمفتاح = م(دليل1)؛\n\t\tدليل2 = دليل1 - 1؛\n\t\t\n\t\tبينما دليل2 >= 0 && م(دليل2) > مفتاح {\n\t\t\tم(دليل2 + 1) = م(دليل2)؛\n\t\t\tدليل2 = دليل2 - 1؛\n\t\t}\n\t\tم(دليل2 + 1) = مفتاح؛\n\t}\n}\n"}, {"role": "assistant", "content": "اكتب خوارزمية الفرز بالحشر لمصفوفة معطاة"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Array\";\n\nuse Srl;\n\n\nfunc insertionSort(a: ref[Array[Int]]) {\n def i: Int;\n def key: Int;\n def j: Int;\n\n for i = 1 , i < a.getLength() , i++ {\n key = a(i);\n j = i - 1;\n\n while j >= 0 && a(j) > key {\n a(j + 1) = a(j);\n j = j - 1;\n }\n a(j + 1) = key;\n }\n}\n"}, {"role": "assistant", "content": "void insertionSort(int arr[], int n) {\n int i, key, j;\n for (i = 1; i < n; i++) {\n key = arr[i];\n j = i - 1;\n\n /* Move elements of arr[0..i-1], that are greater than key,\n to one position ahead of their current position */\n while (j >= 0 && arr[j] > key) {\n arr[j + 1] = arr[j];\n j = j - 1;\n }\n arr[j + 1] = key;\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/ريـاضيات\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nصنف نـقطة {\n\tعرف س: عـائم؛\n\tعرف ص: عـائم؛\n}\n\nدالة احسب_مسافة(ن1: نـقطة، ن2: نـقطة): عـائم {\n\tارجع ريـاضيات.جذر(ريـاضيات.ارفع(ن2.س - ن1.س، 2.0) + ريـاضيات.ارفع(ن2.ص - ن1.ص، 2.0))؛\n}\n\nدالة جد_أبعد_نقطة(ن: نـقطة، نقاط: سند[مـصفوفة[نـقطة]]): نـقطة {\n\tعرف أبعد_مسافة: عـائم = 0؛\n\tعرف أبعد_نقطة: نـقطة؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < نقاط.هات_الطول() ، دليل++ {\n\t\tعرف مسافة: عـائم = احسب_مسافة(ن، نقاط(دليل))؛\n\t\tإذا مسافة > أبعد_مسافة {\n\t\t\tأبعد_مسافة = مسافة؛\n\t\t\tأبعد_نقطة = نقاط(دليل)؛\n\t\t}\n\t}\n\tارجع أبعد_نقطة؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/Math\";\nimport \"Srl/Array\";\n\n\n\nuse Srl;\n\nclass Point {\n def x : Float;\n def y : Float;\n};\n\nfunc calculateDistance(a: Point, b: Point): Float {\n return Math.sqrt(Math.pow(b.x - a.x, 2.0) + Math.pow(b.y - a.y, 2.0));\n}\n\nfunc findFarthestPoint(givenPoint: Point, points: ref[Array[Point]]): Point {\n def maxDistance: Float = 0;\n def farthestPoint: Point;\n\n def i: Int;\n for i = 0 , i < points.getLength() , i++ {\n def distance: Float = calculateDistance(givenPoint, points(i));\n if distance > maxDistance {\n maxDistance = distance;\n farthestPoint = points(i);\n }\n }\n\n return farthestPoint;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, Find the first index at which the two given arrays differ, return -1 if not found"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc find_diff_index(a1: ref[Array[Int]], a2: ref[Array[Int]]): Int {\n def i: Int;\n for i = 0 , i < a1.getLength() , i++ {\n if a1(i) != a2(i) {\n return i;\n }\n }\n return -1;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\n#include <stdbool.h>\n\nbool char_exists(char s[], int n, char c) {\n for (int i = 0; i < n; i++) {\n if (s[i] == c) {\n return true;\n }\n }\n return false;\n}\n"}, {"role": "assistant", "content": "check if a given string contains a given char"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nconst fs = require('fs');\nconst readline = require('readline');\n\nfunction read_nth_line(file_path, n) {\n return new Promise((resolve, reject) => {\n const fileStream = fs.createReadStream(file_path);\n\n const rl = readline.createInterface({\n input: fileStream,\n crlfDelay: Infinity\n });\n\n let line_no = 0;\n\n rl.on('line', (line) => {\n line_no++;\n if(line_no === n) {\n resolve(line);\n rl.close();\n }\n });\n\n rl.on('close', () => {\n if(line_no < n) {\n reject(new Error(`The file has less than ${n} lines.`));\n }\n });\n });\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/نـم\"؛\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة اقرأ_السطر_ن(مسار_الملف: سند[نـص]، ن: صـحيح): نـص {\n\tعرف ملف: مؤشر[نـم.مـلف] = نـم.افتح_ملف(مسار_الملف، \"r\")؛\n\t\n\tعرف دليل: صـحيح؛\n\tعرف مؤقت: مـحرف = ' '؛\n\tلكل دليل = 0 ، دليل < ن - 1 ، دليل++ {\n\t\tمؤقت = ' '؛\n\t\tبينما مؤقت != '\\n' {\n\t\t\tنـم.اقرأ(مؤقت~مؤشر، 1، 1، ملف)؛\n\t\t}\n\t}\n\t\n\tعرف السطر_ن: نـص؛\n\tمؤقت = ' '؛\n\tبينما مؤقت != '\\n' {\n\t\tنـم.اقرأ(مؤقت~مؤشر، 1، 1، ملف)؛\n\t\tالسطر_ن.ألحق(مؤقت)؛\n\t}\n\t\n\tارجع السطر_ن؛\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, Replace a given value with another given value in a given array"}, {"role": "assistant", "content": "void replace(int* arr, int len, int oldValue, int newValue) {\n for(int i = 0; i < len; i++) {\n if(arr[i] == oldValue) {\n arr[i] = newValue;\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nuse Srl;\n\nclass Point {\n def x : Int;\n def y : Int;\n};\n\nfunc areCollinear(p1: Point, p2: Point, p3: Point): Bool {\n return (p2.y - p1.y) * (p3.x - p1.x) == (p3.y - p1.y) * (p2.x - p1.x);\n}\n"}, {"role": "assistant", "content": "function Point(x, y) {\n this.x = x;\n this.y = y;\n}\n\nfunction areCollinear(p1, p2, p3) {\n // Calculate the slopes of the lines formed by (p1, p2) and (p1, p3)\n // If the slopes are equal, then p1, p2 and p3 are collinear\n return (p2.y - p1.y) * (p3.x - p1.x) === (p3.y - p1.y) * (p2.x - p1.x);\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, Calculate the product of a given matrix, represented as 2D array, and a given scalar, and return the result"}, {"role": "assistant", "content": "#include <stdlib.h>\n\nint** multiply(int** a, int scalar, int rows, int cols) {\n int i, j;\n // Create a result matrix dynamically\n int** result = (int**)malloc(rows * sizeof(int*));\n for(i = 0; i < rows; i++) {\n result[i] = (int*)malloc(cols * sizeof(int));\n }\n\n // Multiply the matrix by the scalar\n for(i = 0; i < rows; i++) {\n for(j = 0; j < cols; j++) {\n result[i][j] = a[i][j] * scalar;\n }\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc is_permutation(a1: ref[Array[Int]], a2: ref[Array[Int]]): Bool {\n if a1.getLength() != a2.getLength() {\n return false;\n }\n\n def visited: Array[Bool];\n def i: Int;\n for i = 0 , i < a2.getLength() , i++ {\n visited.add(false);\n }\n\n def j: Int;\n for i = 0 , i < a1.getLength() , i++ {\n def found: Bool = false;\n for j = 0 , j < a2.getLength() , j++ {\n if a1(i) == a2(j) && !visited(j) {\n found = true;\n visited(j) = true;\n break;\n }\n }\n if !found {\n return false;\n }\n }\n\n return true;\n}\n"}, {"role": "assistant", "content": "Check whether a given array is a permutation for another given array"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, اقتطع قيم مصفوفة معطاة ضمن مجال معطى"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة اقتطع(م: سند[مـصفوفة[صـحيح]]، أدنى: صـحيح، أعلى: صـحيح) {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا م(دليل) < أدنى {\n\t\t\tم(دليل) = أدنى؛\n\t\t}\n\t\tوإلا إذا م(دليل) > أعلى {\n\t\t\tم(دليل) = أعلى؛\n\t\t}\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة فلتر(م: سند[مـصفوفة[صـحيح]]، د: مغلفة(رقم: صـحيح): ثـنائي): مـصفوفة[صـحيح] {\n\tعرف نتيجة: مـصفوفة[صـحيح]؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا د(م(دليل)) {\n\t\t\tنتيجة.أضف(م(دليل))؛\n\t\t}\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"closure\";\n\n\nuse Srl;\n\n\nfunc filter(a: ref[Array[Int]], f: closure (num: Int): Bool): Array[Int] {\n def result: Array[Int];\n\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if f(a(i)) {\n result.add(a(i));\n }\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/نـم\"؛\nاشمل \"مـتم/نـص\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة اقرأ_الملف_إلى_مصفوفة(مسار_الملف: سند[نـص]): مـصفوفة[نـص] {\n\tعرف ملف: مؤشر[نـم.مـلف] = نـم.افتح_ملف(مسار_الملف، \"r\")؛\n\tعرف المحتوى: مـصفوفة[نـص]؛\n\n\tنـم.انتقل(ملف، 0، نـم.انـتقال._نهاية_)؛\n\tعرف حجم: صـحيح = نـم.هات_الموقع(ملف)؛\n\tنـم.انتقل(ملف، 0، نـم.انـتقال._بداية_)؛\n\t\n\tالمحتوى.أضف(نـص())؛\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح = 0؛\n\tلكل دليل1 = 0 ، دليل1 < حجم ، دليل1++ {\n\t\tعرف مؤقت: مـحرف؛\n\t\tنـم.اقرأ(مؤقت~مؤشر، 1، 1، ملف)؛\n\t\t\n\t\tإذا مؤقت == '\\n' {\n\t\t\tالمحتوى.أضف(نـص())؛\n\t\t\tدليل2++؛\n\t\t}\n\t\tوإلا {\n\t\t\tالمحتوى(دليل2).ألحق(مؤقت)؛\n\t\t}\n\t}\n\t\n\tارجع المحتوى؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/Fs\";\nimport \"Srl/String\";\nimport \"Srl/Array\";\n\nuse Srl;\n\n\nfunc readFileToArray(file_path: ref[String]): Array[String] {\n def file: ptr[Fs.File] = Fs.openFile(file_path.buf, \"r\");\n def content: Array[String];\n\n Fs.seek(file, 0, Fs.Seek.END);\n def size: Int = Fs.tell(file);\n Fs.seek(file, 0, Fs.Seek.SET);\n \n content.add(String());\n def i: Int;\n def j: Int = 0;\n for i = 0 , i < size , i++ {\n def temp: Char;\n Fs.read(temp~ptr, 1, 1, file);\n\n if temp == '\\n' {\n content.add(String());\n j++;\n }\n else {\n content(j).append(temp);\n }\n }\n\n return content;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Array\";\nimport \"Srl/String\";\nimport \"closure\";\n\nuse Srl;\n\n\nfunc reduce(a: ref[Array[String]], f: closure(previousValue: ref[String], currentValue: ref[String])): String {\n def result: String = \"\";\n\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n f(result, a(i));\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "function reduce(a, f) {\n let result = \"\";\n\n for (let i = 0; i < a.length; i++) {\n result = f(result, a[i]);\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc find_most_frequent(a: ref[Array[Int]]): Int {\n def max_count: Int = 0;\n def res: Int = -1;\n\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n def count: Int = 1;\n \n def j: Int;\n for j = i + 1 , j < a.getLength() , j++ {\n if a(j) == a(i) {\n count++;\n }\n }\n\n if count > max_count {\n max_count = count;\n res = a(i);\n }\n }\n\n return res;\n}\n"}, {"role": "assistant", "content": "find and return the most frequent item in a given array"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\nint findMax(int* a, int n) {\n int max = a[0];\n for(int i = 1; i < n; i++) {\n if(a[i] > max) {\n max = a[i];\n }\n }\n return max;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\n\nfunc max(a: ref[Array[Int]]): Int {\n def result: Int = a(0);\n\n def i: Int;\n for i = 1 , i < a.getLength() , i++ {\n if a(i) > result {\n result = a(i);\n }\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, Write Floyd Warshall algorithm for a given graph"}, {"role": "assistant", "content": "const V = 4;\n\nfunction floydWarshall(graph) {\n let dist = [];\n for (let i = 0; i < V; i++) {\n dist[i] = [];\n for (let j = 0; j < V; j++) {\n dist[i][j] = graph[i][j];\n }\n }\n\n for (let k = 0; k < V; k++) {\n for (let i = 0; i < V; i++) {\n for (let j = 0; j < V; j++) {\n if (dist[i][k] + dist[k][j] < dist[i][j]) {\n dist[i][j] = dist[i][k] + dist[k][j];\n }\n }\n }\n }\n\n return dist;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc insert(a: ref[Array[Int]], pos: Int, val: Int) {\n def size: Int = a.getLength();\n\ta.add(0); // increase the size by 1\n\n def i: Int;\n for i = size , i > pos , i-- {\n a(i) = a(i - 1);\n }\n\n a(pos) = val;\n}\n"}, {"role": "assistant", "content": "function insert(a, n, pos, x) {\n // Shift elements to right\n for (let i = n; i > pos; i--)\n a[i] = a[i - 1];\n\n // Insert x at pos\n a[pos] = x;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, هيئ مصفوفة معطاة لها حجم معطى بقيمة معطاة"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة هيئ_مصفوفة(م: سند[مـصفوفة[صـحيح]]، حجم: صـحيح، قيمة: صـحيح) {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < حجم ، دليل++ {\n\t\tم.أضف(قيمة)؛\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nuse Srl;\n\n\nfunc is_digit(c: Char): Bool {\n return (c >= '0' && c <= '9');\n}\n"}, {"role": "assistant", "content": "function is_digit(c) {\n return (c >= '0' && c <= '9');\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, check if a given character is from the alphabet"}, {"role": "assistant", "content": "function is_alphabet(c) {\n return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction findIntersection(a1, b1, c1, a2, b2, c2) {\n // Check if the lines are parallel\n if(a1*b2 - a2*b1 === 0) {\n return null;\n }\n\n let result = [];\n result[0] = (b1*c2 - b2*c1) / (a1*b2 - a2*b1);\n result[1] = (a2*c1 - a1*c2) / (a1*b2 - a2*b1);\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جد_التقاطع(أ1: عـائم[64]، ب1: عـائم[64]، ج1: عـائم[64]، أ2: عـائم[64]، ب2: عـائم[64]، ج2: عـائم[64]): مـصفوفة[عـائم[64]] {\n\tعرف نتيجة: مـصفوفة[عـائم[64]]؛\n\tإذا أ1 * ب2 - أ2 * ب1 == 0 {\n\t\tارجع نتيجة؛\n\t}\n\t\n\tنتيجة.أضف((ب1*ج2 - ب2*ج1) / (أ1 * ب2 - أ2 * ب1))؛\n\tنتيجة.أضف((أ2*ج1 - أ1*ج2) / (أ1 * ب2 - أ2 * ب1))؛\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc is_permutation(a1: ref[Array[Int]], a2: ref[Array[Int]]): Bool {\n if a1.getLength() != a2.getLength() {\n return false;\n }\n\n def visited: Array[Bool];\n def i: Int;\n for i = 0 , i < a2.getLength() , i++ {\n visited.add(false);\n }\n\n def j: Int;\n for i = 0 , i < a1.getLength() , i++ {\n def found: Bool = false;\n for j = 0 , j < a2.getLength() , j++ {\n if a1(i) == a2(j) && !visited(j) {\n found = true;\n visited(j) = true;\n break;\n }\n }\n if !found {\n return false;\n }\n }\n\n return true;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة هل_تباديل(م1: سند[مـصفوفة[صـحيح]]، م2: سند[مـصفوفة[صـحيح]]): ثـنائي {\n\tإذا م1.هات_الطول() != م2.هات_الطول() {\n\t\tارجع خطأ؛\n\t}\n\t\n\tعرف مزار: مـصفوفة[ثـنائي]؛\n\tعرف دليل1: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < م2.هات_الطول() ، دليل1++ {\n\t\tمزار.أضف(خطأ)؛\n\t}\n\t\n\tعرف دليل2: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < م1.هات_الطول() ، دليل1++ {\n\t\tعرف موجود: ثـنائي = خطأ؛\n\t\tلكل دليل2 = 0 ، دليل2 < م2.هات_الطول() ، دليل2++ {\n\t\t\tإذا م1(دليل1) == م2(دليل2) && !مزار(دليل2) {\n\t\t\t\tموجود = صح؛\n\t\t\t\tمزار(دليل2) = صح؛\n\t\t\t\tاقطع؛\n\t\t\t}\n\t\t}\n\t\tإذا !موجود {\n\t\t\tارجع خطأ؛\n\t\t}\n\t}\n\tارجع صح؛\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, Append a given log entry to a file given its path"}, {"role": "assistant", "content": "import \"Srl/Fs\";\nimport \"Srl/String\";\n\nuse Srl;\n\n\nfunc appendLogEntry(file_path: ref[String], logEntry: ref[String]) {\n def file: ptr[Fs.File] = Fs.openFile(file_path.buf, \"a\");\n\n Fs.write(logEntry.buf, 1, logEntry.getLength(), file);\n Fs.write(\"\\n\", 1, 1, file);\n Fs.closeFile(file);\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction startsWith(str, prefix) {\n for(let i = 0; i < prefix.length; i++) {\n if(str[i] !== prefix[i])\n return false;\n }\n return true;\n}\n"}, {"role": "assistant", "content": "check if a given string starts with another given string"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جد_أكثر_عنصر_مكرر(م: سند[مـصفوفة[صـحيح]]): صـحيح {\n\tعرف أكثر_تكرار: صـحيح = 0؛\n\tعرف نتيجة: صـحيح = -1؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tعرف عداد: صـحيح = 1؛\n\t\t\n\t\tعرف دليل2: صـحيح؛\n\t\tلكل دليل2 = دليل + 1 ، دليل2 < م.هات_الطول() ، دليل2++ {\n\t\t\tإذا م(دليل2) == م(دليل) {\n\t\t\t\tعداد++؛\n\t\t\t}\n\t\t}\n\t\t\n\t\tإذا عداد > أكثر_تكرار {\n\t\t\tأكثر_تكرار = عداد؛\n\t\t\tنتيجة = م(دليل)؛\n\t\t}\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "int find_most_frequent(int arr[], int n) {\n int max_count = 0, res = -1;\n\n for (int i = 0; i < n; i++) {\n int count = 1;\n for (int j = i + 1; j < n; j++)\n if (arr[i] == arr[j])\n count++;\n if (count > max_count) {\n max_count = count;\n res = arr[i];\n }\n }\n\n return res;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nconst fs = require('fs');\n\nfunction readFileToArray(filename) {\n const data = fs.readFileSync(filename, 'utf8');\n let lines = [''];\n let j = 0;\n for (let i = 0; i < data.length; i++) {\n if (data[i] === '\\n') {\n lines.push('');\n j++;\n } else {\n lines[j] += data[i];\n }\n }\n return lines;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Fs\";\nimport \"Srl/String\";\nimport \"Srl/Array\";\n\nuse Srl;\n\n\nfunc readFileToArray(file_path: ref[String]): Array[String] {\n def file: ptr[Fs.File] = Fs.openFile(file_path.buf, \"r\");\n def content: Array[String];\n\n Fs.seek(file, 0, Fs.Seek.END);\n def size: Int = Fs.tell(file);\n Fs.seek(file, 0, Fs.Seek.SET);\n \n content.add(String());\n def i: Int;\n def j: Int = 0;\n for i = 0 , i < size , i++ {\n def temp: Char;\n Fs.read(temp~ptr, 1, 1, file);\n\n if temp == '\\n' {\n content.add(String());\n j++;\n }\n else {\n content(j).append(temp);\n }\n }\n\n return content;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nclass Point {\n constructor(x, y) {\n this.x = x;\n this.y = y;\n }\n}\n\nfunction calculateDistance(a, b) {\n return Math.sqrt(Math.pow(b.x - a.x, 2) + Math.pow(b.y - a.y, 2));\n}\n\nfunction findClosestPoint(givenPoint, points) {\n let minDistance = calculateDistance(givenPoint, points[0]);\n let closestPoint = points[0];\n \n for(let i = 1; i < points.length; i++) {\n let distance = calculateDistance(givenPoint, points[i]);\n if(distance < minDistance) {\n minDistance = distance;\n closestPoint = points[i];\n }\n }\n \n return closestPoint;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Math\";\nimport \"Srl/Array\";\n\n\n\nuse Srl;\n\nclass Point {\n def x : Float;\n def y : Float;\n};\n\nfunc calculateDistance(a: Point, b: Point): Float {\n return Math.sqrt(Math.pow(b.x - a.x, 2.0) + Math.pow(b.y - a.y, 2.0));\n}\n\nfunc findClosestPoint(givenPoint: Point, points: ref[Array[Point]]): Point {\n def minDistance: Float = calculateDistance(givenPoint, points(0));\n def closestPoint: Point = points(0);\n\n def i: Int;\n for i = 1 , i < points.getLength() , i++ {\n def distance: Float = calculateDistance(givenPoint, points(i));\n if distance < minDistance {\n minDistance = distance;\n closestPoint = points(i);\n }\n }\n\n return closestPoint;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Array\";\n\nuse Srl;\n\nfunc sum(a: ref[Array[Int]], start: Int, end: Int): Int {\n def sum: Int = 0;\n\n def i: Int;\n for i = start , i < end , i++ {\n sum += a(i);\n }\n\n return sum;\n}\n"}, {"role": "assistant", "content": "calculate and return the sum of the given array in a given range"}]}
{"messages": [{"role": "user", "content": "What this code do?\nint sum(int a[], int n, int start, int end) {\n int result = 0;\n for (int i = start; i < end; i++) {\n result += a[i];\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "calculate and return the sum of the given array in a given range"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, convert string to lowercase and return the result"}, {"role": "assistant", "content": "import \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc toLowerCase(s: ref[String]): String {\n\tdef result: String = \"\";\n def i: Int;\n\tdef c: Char;\n\tfor i = 0 , i < s.getLength() , i++ {\n\t\tif (s(i) >= 'A' && s(i) <= 'Z') {\n\t\t\tc = s(i) - 'A' + 'a';\n\t\t}\n\t\telse {\n\t\t\tc = s(i);\n\t\t}\n\t\tresult += c;\n\t}\n\treturn result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Fs\";\nimport \"Srl/String\";\n\nuse Srl;\n\n\nfunc appendLogEntry(file_path: ref[String], logEntry: ref[String]) {\n def file: ptr[Fs.File] = Fs.openFile(file_path.buf, \"a\");\n\n Fs.write(logEntry.buf, 1, logEntry.getLength(), file);\n Fs.write(\"\\n\", 1, 1, file);\n Fs.closeFile(file);\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/نـم\"؛\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة ألحق_سجل(مسار_الملف: سند[نـص]، سجل: سند[نـص]) {\n\tعرف ملف: مؤشر[نـم.مـلف] = نـم.افتح_ملف(مسار_الملف، \"a\")؛\n\t\n\tنـم.اكتب(سجل.صوان، 1، سجل.هات_الطول()، ملف)؛\n\tنـم.اكتب(\"\\ج\"، 1، 1، ملف)؛\n\tنـم.اغلق_ملف(ملف)؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction is_alphabet(c) {\n return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');\n}\n"}, {"role": "assistant", "content": "use Srl;\n\n\nfunc is_alpha(c: Char): Bool {\n return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, تحقق فيما إذا كانت سلسلة نصية معطاة تبدأ بسلسلة نصية أخرى معطاة"}, {"role": "assistant", "content": "اشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة يبدأ_ب(س: سند[نـص]، سابق: سند[نـص]): ثـنائي {\n\tإذا س.هات_الطول() < سابق.هات_الطول() {\n\t\tارجع خطأ؛\n\t}\n\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < سابق.هات_الطول() ، دليل++ {\n\t\tإذا سابق(دليل) != س(دليل) {\n\t\t\tارجع خطأ؛\n\t\t}\n\t}\n\tارجع صح؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\n#include <stdio.h>\n\nvoid printArray(int a[], int size) {\n int i;\n for(i = 0; i < size; i++) {\n printf(\"%d \", a[i]);\n }\n}\n"}, {"role": "assistant", "content": "print the given array"}]}
{"messages": [{"role": "user", "content": "What this code do?\nuse Srl;\n\nfunc isPrime(num: Int): Bool {\n if num <= 1 {\n return false;\n }\n\n def i: Int;\n for i = 2 , i * i <= num , i++ {\n if num % i == 0 {\n return false;\n }\n }\n \n return true;\n}\n"}, {"role": "assistant", "content": "Check whether a given number is prime or not and return that result"}]}
{"messages": [{"role": "user", "content": "Using c, Insert an element at a given position in the given array"}, {"role": "assistant", "content": "void insert(int a[], int n, int pos, int x) {\n // Shift elements to right\n for (int i = n; i > pos; i--)\n a[i] = a[i - 1];\n\n // Insert x at pos\n a[pos] = x;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nlet visited = [];\n\nfunction DFS(v, parent, adjList) {\n visited[v] = true;\n for(let i = 0; i < adjList[v].length; i++) {\n if(!visited[adjList[v][i]]) {\n if(DFS(adjList[v][i], v, adjList)) {\n return true;\n }\n } else if(adjList[v][i] != parent) {\n return true;\n }\n }\n return false;\n}\n\nfunction isTree(adjList) {\n visited = new Array(adjList.length).fill(false);\n if(DFS(0, -1, adjList)) {\n return false;\n }\n for(let i = 0; i < adjList.length; i++) {\n if(!visited[i]) {\n return false;\n }\n }\n return true;\n}\n"}, {"role": "assistant", "content": "Check if a given undirected graph is tree"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction toUpperCase(s) {\n let result = '';\n for(let i = 0; i < s.length; i++){\n let code = s.charCodeAt(i);\n if(code >= 97 && code <= 122){\n result += String.fromCharCode(code - 97 + 65);\n } else {\n result += s[i];\n }\n }\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة إلى_حالة_كبيرة(س: سند[نـص]): نـص {\n\tعرف نتيجة: نـص = \"\"؛\n\n\tعرف دليل: صـحيح؛\n\tعرف م: مـحرف؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) >= 'a' && س(دليل) <= 'z' {\n\t\t\tم = س(دليل) - 'a' + 'A'؛\n\t\t}\n\t\tوإلا {\n\t\t\tم = س(دليل)؛\n\t\t}\n\t\tنتيجة += م؛\n\t}\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Array\";\nimport \"Srl/String\";\nimport \"closure\";\n\nuse Srl;\n\n\nfunc reduce(a: ref[Array[String]], f: closure(previousValue: ref[String], currentValue: ref[String])): String {\n def result: String = \"\";\n\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n f(result, a(i));\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "reduce the given array `a` using the given function `f` and return the result"}]}
{"messages": [{"role": "user", "content": "Using js, Calculate the product of a given matrix, represented as 2D array, and a given vector, represented as an array, and return the result"}, {"role": "assistant", "content": "function multiply(matrix, vector) {\n let rows = matrix.length, cols = matrix[0].length;\n let result = new Array(rows);\n\n for (let i = 0; i < rows; i++) {\n result[i] = 0;\n for (let j = 0; j < cols; j++) {\n result[i] += matrix[i][j] * vector[j];\n }\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\nint rfind(int a[], int n, int val) {\n for (int i = n - 1; i != 0; i--) {\n if (a[i] == val) {\n return i;\n }\n }\n return -1;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جد_من_الخلف(م: سند[مـصفوفة[صـحيح]]، قيمة: صـحيح): صحيح {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = م.هات_الطول() - 1 ، دليل != 0 ، دليل-- {\n\t\tإذا م(دليل) == قيمة {\n\t\t\tارجع دليل؛\n\t\t}\n\t}\n\tارجع -1؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction outer_product(v1, v2) {\n let result = [];\n for (let i = 0; i < v1.length; i++) {\n let row = [];\n for (let j = 0; j < v2.length; j++) {\n row.push(v1[i] * v2[j]);\n }\n result.push(row);\n }\n return result;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\n\nfunc outer_product(v1: ref[Array[Float[64]]], v2: ref[Array[Float[64]]]): Array[Array[Float[64]]] {\n def result: Array[Array[Float[64]]];\n\n def i: Int;\n def j: Int;\n for i = 0 , i < v1.getLength() , i++ {\n def row: Array[Float[64]];\n for j = 0 , j < v2.getLength() , j++ {\n row.add(v1(i)*v2(j));\n }\n result.add(row);\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Math\";\nimport \"Srl/Array\";\n\n\n\nuse Srl;\n\nclass Point {\n def x : Float;\n def y : Float;\n};\n\nfunc calculateDistance(a: Point, b: Point): Float {\n return Math.sqrt(Math.pow(b.x - a.x, 2.0) + Math.pow(b.y - a.y, 2.0));\n}\n\nfunc findClosestPoint(givenPoint: Point, points: ref[Array[Point]]): Point {\n def minDistance: Float = calculateDistance(givenPoint, points(0));\n def closestPoint: Point = points(0);\n\n def i: Int;\n for i = 1 , i < points.getLength() , i++ {\n def distance: Float = calculateDistance(givenPoint, points(i));\n if distance < minDistance {\n minDistance = distance;\n closestPoint = points(i);\n }\n }\n\n return closestPoint;\n}\n"}, {"role": "assistant", "content": "#include <math.h>\n\ntypedef struct {\n double x;\n double y;\n} Point;\n\ndouble calculateDistance(Point a, Point b) {\n return sqrt(pow(b.x - a.x, 2) + pow(b.y - a.y, 2));\n}\n\nPoint findClosestPoint(Point givenPoint, Point points[], int size) {\n double minDistance = calculateDistance(givenPoint, points[0]);\n Point closestPoint = points[0];\n\n for(int i = 1; i < size; i++) {\n double distance = calculateDistance(givenPoint, points[i]);\n if(distance < minDistance) {\n minDistance = distance;\n closestPoint = points[i];\n }\n }\n\n return closestPoint;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction reverseArray(a) {\n let start = 0;\n let end = a.length - 1;\n\n while (start < end) {\n let temp = a[start];\n a[start] = a[end];\n a[end] = temp;\n\n start++;\n end--;\n }\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة اعكس_مصفوفة(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف بداية: صـحيح = 0؛\n\tعرف نهاية: صـحيح = م.هات_الطول() - 1؛\n\n\tبينما بداية < نهاية {\n\t\tعرف مؤقت: صـحيح = م(بداية)؛\n\t\tم(بداية) = م(نهاية)؛\n\t\tم(نهاية) = مؤقت؛\n\t\tبداية++؛\n\t\tنهاية--؛\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, find and return the closest point to a given point from a given set of points"}, {"role": "assistant", "content": "import \"Srl/Math\";\nimport \"Srl/Array\";\n\n\n\nuse Srl;\n\nclass Point {\n def x : Float;\n def y : Float;\n};\n\nfunc calculateDistance(a: Point, b: Point): Float {\n return Math.sqrt(Math.pow(b.x - a.x, 2.0) + Math.pow(b.y - a.y, 2.0));\n}\n\nfunc findClosestPoint(givenPoint: Point, points: ref[Array[Point]]): Point {\n def minDistance: Float = calculateDistance(givenPoint, points(0));\n def closestPoint: Point = points(0);\n\n def i: Int;\n for i = 1 , i < points.getLength() , i++ {\n def distance: Float = calculateDistance(givenPoint, points(i));\n if distance < minDistance {\n minDistance = distance;\n closestPoint = points(i);\n }\n }\n\n return closestPoint;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Array\";\nimport \"closure\";\n\nuse Srl;\n\n\nfunc foreach(a: ref[Array[Int]], f: closure(element: Int): Int) {\n def i: Int;\n \n for i = 0 , i < a.getLength() , i++ {\n a(i) = f(a(i));\n }\n}\n"}, {"role": "assistant", "content": "void foreach(int a[], int n, int (*f)(int)) {\n for(int i = 0; i < n; i++) {\n a[i] = f(a[i]);\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, check if a given string starts with another given string"}, {"role": "assistant", "content": "import \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc starts_with(s: ref[String], prefix: ref[String]): Bool {\n\tif s.getLength() < prefix.getLength() {\n\t\treturn false;\n\t}\n\n def i: Int;\n\tfor i = 0 , i < prefix.getLength() , i++ {\n\t\tif (prefix(i) != s(i)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Array\";\n\nuse Srl;\n\n\nfunc selectionSort(a: ref[Array[Int]]) {\n def i: Int;\n def j: Int;\n def temp: Int;\n def min_idx: Int;\n\n for i = 0 , i < a.getLength() - 1 , i++ {\n min_idx = i;\n for j = i + 1 , j < a.getLength() , j++ {\n if a(j) < a(min_idx) {\n min_idx = j;\n }\n }\n\n temp = a(min_idx);\n a(min_idx) = a(i);\n a(i) = temp;\n }\n}\n"}, {"role": "assistant", "content": "void selectionSort(int arr[], int n) {\n int i, j, min_idx, temp;\n\n // One by one move boundary of unsorted subarray\n for (i = 0; i < n-1; i++) {\n // Find the minimum element in unsorted array\n min_idx = i;\n for (j = i+1; j < n; j++)\n if (arr[j] < arr[min_idx])\n min_idx = j;\n\n // Swap the found minimum element with the first element\n temp = arr[min_idx];\n arr[min_idx] = arr[i];\n arr[i] = temp;\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\nint sum(int a[], int n) {\n int result = 0;\n for (int i = 0; i < n; i++) {\n result += a[i];\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جمع(م: سند[مـصفوفة[صـحيح]]): صـحيح {\n\tعرف نتيجة: صـحيح = 0؛\n\n\tعرف دليل: صـحيح؛\n\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n نتيجة += م(دليل)؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc find_char(s: ref[String], c: Char): Int {\n def i: Int;\n\tfor i = 0 , i < s.getLength() , i++ {\n\t\tif (s(i) == c) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n"}, {"role": "assistant", "content": "find and return the position of a given char in a given string"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction findDiffIndex(arr1, arr2) {\n for(let i = 0; i < arr1.length; i++) {\n if(arr1[i] !== arr2[i]) {\n return i;\n }\n }\n return -1; // return -1 if no difference is found\n}\n"}, {"role": "assistant", "content": "Find the first index at which the two given arrays differ, return -1 if not found"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, Invert the given string `s` and return the result"}, {"role": "assistant", "content": "import \"Srl/String\";\n\nuse Srl;\n\n\nfunction invertString(s) {\n def size: Int = s.getLength();\n def result: String = \"\";\n\n def i: Int;\n for i = size - 1 , i >= 0 , i-- {\n result += s(i);\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة هيئ_مصفوفة(م: سند[مـصفوفة[صـحيح]]، حجم: صـحيح، قيمة: صـحيح) {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < حجم ، دليل++ {\n\t\tم.أضف(قيمة)؛\n\t}\n}\n"}, {"role": "assistant", "content": "function initializeArray(arr, value) {\n for(let i = 0; i < arr.length; i++) {\n arr[i] = value;\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\n#include <stdlib.h>\n\ntypedef struct {\n float x;\n float y;\n} Point;\n\ndouble triangleArea(Point p1, Point p2, Point p3) {\n return abs(p1.x*(p2.y-p3.y) + p2.x*(p3.y-p1.y) + p3.x*(p1.y-p2.y)) / 2.0;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Math\";\n\nuse Srl;\n\nclass Point {\n def x : Float;\n def y : Float;\n};\n\nfunc triangleArea(p1: Point, p2: Point, p3: Point): Float {\n return Math.abs(p1.x*(p2.y-p3.y) + p2.x*(p3.y-p1.y) + p3.x*(p1.y-p2.y)) / 2.0;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\n#include <stdlib.h>\n\ntypedef struct {\n double x;\n double y;\n} Point;\n\ndouble calculatePolygonArea(Point* vertices, int numVertices) {\n double area = 0.0;\n int j = numVertices - 1;\n\n for (int i = 0; i < numVertices; i++) {\n area += (vertices[j].x + vertices[i].x) * (vertices[j].y - vertices[i].y);\n j = i;\n }\n\n return abs(area / 2.0);\n}\n\n"}, {"role": "assistant", "content": "calculate and return the area of polygon given its vertices"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة راكم(م: سند[مـصفوفة[صـحيح]]، د: مغلفة(قيمة_سابقة: صـحيح، قيمة_حالية: صـحيح): صـحيح): مـصفوفة[صـحيح] {\n\tعرف طول: صـحيح = م.هات_الطول()؛\n\tعرف نتيجة: مـصفوفة[صـحيح]؛\n\t\n\tعرف دليل: صـحيح؛\n\tنتيجة.أضف(م(0))؛\n\tلكل دليل = 1 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tنتيجة.أضف(د(نتيجة(دليل - 1)، م(دليل)))؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "void accumulate(int* a, int* result, int size, int (*f)(int, int)) {\n result[0] = a[0];\n for(int i = 1; i < size; i++) {\n result[i] = f(result[i-1], a[i]);\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\n#include <stdlib.h>\n\n// Function to multiply two matrices\nint** multiply(int** a, int** b, int r1, int c1, int r2, int c2) {\n int i, j, k;\n // Create a result matrix dynamically\n int** result = (int**)malloc(r1 * sizeof(int*));\n for(i = 0; i < r1; i++) {\n result[i] = (int*)malloc(c2 * sizeof(int));\n }\n\n // Initialize the result matrix with 0\n for(i = 0; i < r1; i++) {\n for(j = 0; j < c2; j++) {\n result[i][j] = 0;\n }\n }\n\n // Multiply the two matrices\n for(i = 0; i < r1; i++) {\n for(j = 0; j < c2; j++) {\n for(k = 0; k < c1; k++) {\n result[i][j] += a[i][k] * b[k][j];\n }\n }\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\ndef Matrix: alias Array[Array[Float[64]]];\n\nfunc multiply(a: ref[Matrix], b: ref[Matrix]): Matrix {\n def rowsA: Int = a.getLength();\n def rowsB: Int = b.getLength();\n def colsA: Int = a(0).getLength();\n def colsB: Int = b(0).getLength();\n \n def result: Matrix;\n\n def i: Int;\n def j: Int;\n def k: Int;\n for i = 0 , i < rowsA , i++ {\n def row: Array[Float[64]];\n for j = 0 , j < colsB , j++ {\n row.add(0);\n for k = 0 , k < colsA , k++ {\n row(j) += a(i)(k) * b(k)(j);\n }\n }\n result.add(row);\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction insertionSort(arr) {\n let n = arr.length;\n for (let i = 1; i < n; i++) {\n let key = arr[i];\n let j = i - 1;\n\n /* Move elements of arr[0..i-1], that are greater than key,\n to one position ahead of their current position */\n while (j >= 0 && arr[j] > key) {\n arr[j + 1] = arr[j];\n j = j - 1;\n }\n arr[j + 1] = key;\n }\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\n\nfunc insertionSort(a: ref[Array[Int]]) {\n def i: Int;\n def key: Int;\n def j: Int;\n\n for i = 1 , i < a.getLength() , i++ {\n key = a(i);\n j = i - 1;\n\n while j >= 0 && a(j) > key {\n a(j + 1) = a(j);\n j = j - 1;\n }\n a(j + 1) = key;\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\n#include <stdbool.h>\n\nbool isPrime(int num) {\n if (num <= 1) {\n return false;\n }\n for (int i = 2; i * i <= num; i++) {\n if (num % i == 0) {\n return false;\n }\n }\n return true;\n}\n"}, {"role": "assistant", "content": "استخدم مـتم؛\n\nدالة هل_أولي (عدد: صـحيح): ثـنائي {\n\tإذا عدد <= 1 {\n\t\tارجع خطأ؛\n\t}\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 2 ، دليل * دليل <= عدد ، دليل++ {\n\t\tإذا عدد % دليل == 0 {\n\t\t\tارجع خطأ؛\n\t\t}\n\t}\n\t\n\tارجع صح؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction findMostFrequent(arr) {\n var maxCount = 0, res = -1;\n\n for (var i = 0; i < arr.length; i++) {\n var count = 1;\n for (var j = i + 1; j < arr.length; j++)\n if (arr[i] == arr[j])\n count++;\n if (count > maxCount) {\n maxCount = count;\n res = arr[i];\n }\n }\n\n return res;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جد_أكثر_عنصر_مكرر(م: سند[مـصفوفة[صـحيح]]): صـحيح {\n\tعرف أكثر_تكرار: صـحيح = 0؛\n\tعرف نتيجة: صـحيح = -1؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tعرف عداد: صـحيح = 1؛\n\t\t\n\t\tعرف دليل2: صـحيح؛\n\t\tلكل دليل2 = دليل + 1 ، دليل2 < م.هات_الطول() ، دليل2++ {\n\t\t\tإذا م(دليل2) == م(دليل) {\n\t\t\t\tعداد++؛\n\t\t\t}\n\t\t}\n\t\t\n\t\tإذا عداد > أكثر_تكرار {\n\t\t\tأكثر_تكرار = عداد؛\n\t\t\tنتيجة = م(دليل)؛\n\t\t}\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/ريـاضيات\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nصنف نـقطة {\n\tعرف س: عـائم؛\n\tعرف ص: عـائم؛\n}\n\nدالة احسب_مسافة(ن1: نـقطة، ن2: نـقطة): عـائم {\n\tارجع ريـاضيات.جذر(ريـاضيات.ارفع(ن2.س - ن1.س، 2.0) + ريـاضيات.ارفع(ن2.ص - ن1.ص، 2.0))؛\n}\n\nدالة جد_أبعد_نقطة(ن: نـقطة، نقاط: سند[مـصفوفة[نـقطة]]): نـقطة {\n\tعرف أبعد_مسافة: عـائم = 0؛\n\tعرف أبعد_نقطة: نـقطة؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < نقاط.هات_الطول() ، دليل++ {\n\t\tعرف مسافة: عـائم = احسب_مسافة(ن، نقاط(دليل))؛\n\t\tإذا مسافة > أبعد_مسافة {\n\t\t\tأبعد_مسافة = مسافة؛\n\t\t\tأبعد_نقطة = نقاط(دليل)؛\n\t\t}\n\t}\n\tارجع أبعد_نقطة؛\n}\n"}, {"role": "assistant", "content": "class Point {\n constructor(x, y) {\n this.x = x;\n this.y = y;\n }\n}\n\nfunction calculateDistance(a, b) {\n return Math.sqrt(Math.pow(b.x - a.x, 2) + Math.pow(b.y - a.y, 2));\n}\n\nfunction findFarthestPoint(givenPoint, points) {\n let maxDistance = 0;\n let farthestPoint;\n \n for(let i = 0; i < points.length; i++) {\n let distance = calculateDistance(givenPoint, points[i]);\n if(distance > maxDistance) {\n maxDistance = distance;\n farthestPoint = points[i];\n }\n }\n \n return farthestPoint;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, Check whether a given number is prime or not and return that result"}, {"role": "assistant", "content": "function isPrime(num) {\n if (num <= 1) {\n return false;\n }\n for (let i = 2; i * i <= num; i++) {\n if (num % i === 0) {\n return false;\n }\n }\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, Check if all elements in a given array satisfy a criteria defined by a function with boolean return value"}, {"role": "assistant", "content": "// Criteria function that checks if a number is positive\nfunction criteria(num) {\n return num > 0;\n}\n\n// Function to check all elements in an array\nfunction check_all(arr) {\n for(let i = 0; i < arr.length; i++) {\n if(!criteria(arr[i])) {\n return false;\n }\n }\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة موجود(م: سند[مـصفوفة[صـحيح]]، قيمة: صـحيح): ثـنائي {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا م(دليل) == قيمة {\n\t\t\tارجع صح؛\n\t\t}\n\t}\n\tارجع خطأ؛\n}\n"}, {"role": "assistant", "content": "function exists(a, val) {\n for (let i = 0; i < a.length ; i++) {\n if (a[i] == val) {\n return true;\n }\n }\n return false;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Array\";\nimport \"closure\";\n\n\nuse Srl;\n\n\nfunc filter(a: ref[Array[Int]], f: closure (num: Int): Bool): Array[Int] {\n def result: Array[Int];\n\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if f(a(i)) {\n result.add(a(i));\n }\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة فلتر(م: سند[مـصفوفة[صـحيح]]، د: مغلفة(رقم: صـحيح): ثـنائي): مـصفوفة[صـحيح] {\n\tعرف نتيجة: مـصفوفة[صـحيح]؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا د(م(دليل)) {\n\t\t\tنتيجة.أضف(م(دليل))؛\n\t\t}\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nvoid toUpperCase(char *s, char *result) {\n for(int i = 0; s[i]; i++){\n if(s[i] >= 'a' && s[i] <= 'z'){\n result[i] = s[i] - 'a' + 'A';\n }\n else {\n result[i] = s[i];\n }\n }\n}\n"}, {"role": "assistant", "content": "convert string to uppercase and return the result"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc replace(s: ref[String], oldChar: Char, newChar: Char): String {\n def result: String;\n\n def i: Int;\n for i = 0 , i < s.getLength() , i++ {\n if (s(i) == oldChar) {\n result.append(newChar);\n }\n else {\n result.append(s(i));\n }\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة استبدل(س: سند[نـص]، م1: مـحرف، م2: مـحرف): نـص {\n\tعرف نتيجة: نـص؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) == م1 {\n\t\t\tنتيجة.ألحق(م2)؛\n\t\t}\n\t\tوإلا {\n\t\t\tنتيجة.ألحق(س(دليل))؛\n\t\t}\n\t}\n\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, find and return the position of a given char in a given string"}, {"role": "assistant", "content": "int find_char(char s[], int n, char c) {\n for (int i = 0; i < n; i++) {\n if (s[i] == c) {\n return i;\n }\n }\n return -1;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, accumulate the given array `a` using the given function `f` and keep the partial results and return them"}, {"role": "assistant", "content": "void accumulate(int* a, int* result, int size, int (*f)(int, int)) {\n result[0] = a[0];\n for(int i = 1; i < size; i++) {\n result[i] = f(result[i-1], a[i]);\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction replace(str, oldChar, newChar) {\n var result = \"\";\n for(var i = 0; i < str.length; i++) {\n if(str[i] == oldChar) {\n result += newChar;\n } else {\n result += str[i];\n }\n }\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة استبدل(س: سند[نـص]، م1: مـحرف، م2: مـحرف): نـص {\n\tعرف نتيجة: نـص؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) == م1 {\n\t\t\tنتيجة.ألحق(م2)؛\n\t\t}\n\t\tوإلا {\n\t\t\tنتيجة.ألحق(س(دليل))؛\n\t\t}\n\t}\n\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nدالة هل_حلقي(عقدة: صـحيح، مزارة: سند[مـصفوفة[صـحيح]]، بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]): ثـنائي {\n\tإذا مزارة(عقدة) == 2 {\n\t\tارجع صح؛\n\t}\n\tمزارة(عقدة) = 1؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان(عقدة).هات_الطول() ، دليل++ {\n\t\tعرف عقدة_ابن: صـحيح = بيان(عقدة)(دليل)؛\n\t\tإذا مزارة(عقدة_ابن) == 1 {\n\t\t\tارجع صح؛\n\t\t}\n\t\tوإلا إذا مزارة(عقدة_ابن) == 0 && هل_حلقي(عقدة_ابن، مزارة، بيان) {\n\t\t\tارجع صح؛\n\t\t}\n\t}\n\tمزارة(عقدة) = 2؛\n\tارجع خطأ؛\n}\n\n\nدالة هل_داغ(بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]): ثـنائي {\n\tعرف مزارة: مـصفوفة[صـحيح]؛\n\t\n\tعرف دليل1: صـحيح؛\n\tعرف عدد_المكونات: صـحيح = 0؛\n\tلكل دليل1 = 0 ، دليل1 < بيان.هات_الطول() ، دليل1++ {\n\t\tعرف دليل2: صـحيح؛\n\t\tلكل دليل2 = 0 ، دليل2 < بيان.هات_الطول() ، دليل2++ {\n\t\t\tمزارة.أضف(0)؛\n\t\t}\n\n\t\tإذا هل_حلقي(دليل1، مزارة، بيان) {\n\t\t\tارجع خطأ؛\n\t\t}\n\t\tمزارة.فرغ()؛\n\t}\n\t\n\tارجع صح؛\n}\n"}, {"role": "assistant", "content": "#include <stdio.h>\n#define MAX 100\n\nint graph[MAX][MAX];\nint visited[MAX];\nint n;\n\nint isCyclic(int i) {\n if (visited[i] == 2) {\n return 1;\n }\n visited[i] = 1;\n for (int j = 0; j < n; j++) {\n if (graph[i][j]) {\n if (visited[j] == 1) return 1;\n else if (visited[j] == 0 && isCyclic(j)) return 1;\n }\n }\n visited[i] = 2;\n return 0;\n}\n\nint isDAG() {\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n visited[j] = 0;\n }\n if (isCyclic(i)) {\n return 0;\n }\n }\n return 1;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Math\";\nimport \"Srl/Array\";\n\nuse Srl;\n\nclass Point {\n def x : Float;\n def y : Float;\n};\n\nfunc calculatePolygonArea(vertices: ref[Array[Point]]): Float {\n def area: Float = 0;\n def numVertices: Int = vertices.getLength();\n def j: Int = numVertices - 1;\n\n def i: Int;\n for i = 0 , i < numVertices , i++ {\n area += (vertices(j).x + vertices(i).x) * (vertices(j).y - vertices(i).y);\n j = i;\n }\n return Math.abs(area / 2.0);\n}\n"}, {"role": "assistant", "content": "function calculatePolygonArea(vertices) {\n let area = 0;\n let j = vertices.length - 1;\n\n for (let i = 0; i < vertices.length; i++) {\n area += (vertices[j].x + vertices[i].x) * (vertices[j].y - vertices[i].y);\n j = i;\n }\n\n return Math.abs(area / 2);\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, جد أول دليل تختلف عنده المصفوفتان المعطاتان، ارجع -1 إذا لم يوجد هكذا دليل"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جد_بداية_الاختلاف(م1: سند[مـصفوفة[صـحيح]]، م2: سند[مـصفوفة[صـحيح]]): صـحيح {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م1.هات_الطول() ، دليل++ {\n\t\tإذا م1(دليل) != م2(دليل) {\n\t\t\tارجع دليل؛\n\t\t}\n\t}\n\tارجع -1؛\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, write the selection sort algorithm for a given array"}, {"role": "assistant", "content": "function selectionSort(arr) {\n let n = arr.length;\n\n for(let i = 0; i < n; i++) {\n // Finding the smallest number in the subarray\n let min = i;\n for(let j = i+1; j < n; j++){\n if(arr[j] < arr[min]) {\n min=j; \n }\n }\n // Swapping the elements\n let tmp = arr[i]; \n arr[i] = arr[min];\n arr[min] = tmp; \n }\n return arr;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة الترتيب_بالاختيار(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tعرف مؤقت: صـحيح؛\n\tعرف أصغر_دليل: صـحيح؛\n\t\n\tلكل دليل1 = 0 ، دليل1 < م.هات_الطول() - 1 ، دليل1++ {\n\t\tأصغر_دليل = دليل1؛\n\t\t\n\t\tلكل دليل2 = دليل1 + 1 ، دليل2 < م.هات_الطول() ، دليل2++ {\n\t\t\tإذا م(دليل2) < م(أصغر_دليل) {\n\t\t\t\tأصغر_دليل = دليل2؛\n\t\t\t}\n\t\t}\n\t\t\n\t\tمؤقت = م(أصغر_دليل)؛\n\t\tم(أصغر_دليل) = م(دليل1)؛\n\t\tم(دليل1) = مؤقت؛\n\t}\n}\n"}, {"role": "assistant", "content": "void selectionSort(int arr[], int n) {\n int i, j, min_idx, temp;\n\n // One by one move boundary of unsorted subarray\n for (i = 0; i < n-1; i++) {\n // Find the minimum element in unsorted array\n min_idx = i;\n for (j = i+1; j < n; j++)\n if (arr[j] < arr[min_idx])\n min_idx = j;\n\n // Swap the found minimum element with the first element\n temp = arr[min_idx];\n arr[min_idx] = arr[i];\n arr[i] = temp;\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جداء_خارجي(شعاع1: سند[مـصفوفة[عـائم[64]]]، شعاع2: سند[مـصفوفة[عـائم[64]]]): مـصفوفة[مـصفوفة[عـائم[64]]] {\n\tعرف نتيجة: مـصفوفة[مـصفوفة[عـائم[64]]]؛\n\t\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < شعاع1.هات_الطول() ، دليل1++ {\n\t\tعرف سطر: مـصفوفة[عـائم[64]]؛\n\t\tلكل دليل2 = 0 ، دليل2 < شعاع2.هات_الطول() ، دليل2++ {\n\t\t\tسطر.أضف(شعاع1(دليل1)*شعاع2(دليل2))؛\n\t\t}\n\t\tنتيجة.أضف(سطر)؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "#include <stdlib.h>\n\ndouble** outer_product(double v1[], double v2[], int n) {\n double** result = (double**)malloc(n * sizeof(double*));\n for (int i = 0; i < n; i++) {\n result[i] = (double*)malloc(n * sizeof(double));\n for (int j = 0; j < n; j++) {\n result[i][j] = v1[i] * v2[j];\n }\n }\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, calculate and return the sum of the given array in a given range"}, {"role": "assistant", "content": "int sum(int a[], int n, int start, int end) {\n int result = 0;\n for (int i = start; i < end; i++) {\n result += a[i];\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction filter(a, condition) {\n let result = [];\n for(let i = 0; i < a.length; i++) {\n if(condition(a[i])) {\n result.push(a[i]);\n }\n }\n return result;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"closure\";\n\n\nuse Srl;\n\n\nfunc filter(a: ref[Array[Int]], f: closure (num: Int): Bool): Array[Int] {\n def result: Array[Int];\n\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if f(a(i)) {\n result.add(a(i));\n }\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاستخدم مـتم؛\n\n\nصنف نـقطة {\n\tعرف س: صـحيح؛\n\tعرف ص: صـحيح؛\n}\n\nدالة على_خط_مستقيم(ن1: نـقطة، ن2: نـقطة، ن3: نـقطة): ثـنائي {\n\tارجع (ن2.ص - ن1.ص) * (ن3.س - ن1.ص) == (ن3.ص - ن1.ص) * (ن2.س - ن1.س)؛\n}\n"}, {"role": "assistant", "content": "#include <stdbool.h>\n\ntypedef struct {\n int x;\n int y;\n} Point;\n\nbool areCollinear(Point p1, Point p2, Point p3) {\n // Calculate the slopes of the lines formed by (p1, p2) and (p1, p3)\n // If the slopes are equal, then p1, p2 and p3 are collinear\n return (p2.y - p1.y) * (p3.x - p1.x) == (p3.y - p1.y) * (p2.x - p1.x);\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction dot_product(v1, v2) {\n let result = 0;\n for (let i = 0; i < v1.length; i++) {\n result += v1[i] * v2[i];\n }\n return result;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"Srl/Math\";\n\nuse Srl;\n\n\nfunc dot_product(v1: ref[Array[Float[64]]], v2: ref[Array[Float[64]]]): Float[64] {\n def result: Float[64] = 0;\n\n def i: Int;\n for i = 0 , i < v1.getLength() , i++ {\n result += v1(i) * v2(i);\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة استبدل(م: سند[مـصفوفة[صـحيح]]، ق1: صـحيح، ق2: صـحيح) {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا م(دليل) == ق1 {\n\t\t\tم(دليل) = ق2؛\n\t\t}\n\t}\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc replace(a: ref[Array[Int]], oldValue: Int, newValue: Int) {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if a(i) == oldValue {\n a(i) = newValue;\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاستخدم مـتم؛\n\nدالة هل_أولي (عدد: صـحيح): ثـنائي {\n\tإذا عدد <= 1 {\n\t\tارجع خطأ؛\n\t}\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 2 ، دليل * دليل <= عدد ، دليل++ {\n\t\tإذا عدد % دليل == 0 {\n\t\t\tارجع خطأ؛\n\t\t}\n\t}\n\t\n\tارجع صح؛\n}\n"}, {"role": "assistant", "content": "function isPrime(num) {\n if (num <= 1) {\n return false;\n }\n for (let i = 2; i * i <= num; i++) {\n if (num % i === 0) {\n return false;\n }\n }\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, Slice a given array within a given range"}, {"role": "assistant", "content": "function slice(arr, start, end) {\n let result = [];\n for(let i = start; i <= end; i++) {\n result.push(arr[i]);\n }\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nعرف مـصفوفة_ثنائية: لقب مـصفوفة[مـصفوفة[عـائم[64]]]؛\n\n\nدالة جداء(م1: سند[مـصفوفة_ثنائية]، م2: سند[مـصفوفة_ثنائية]): مـصفوفة_ثنائية {\n\tعرف أسطر_م1: صـحيح = م1.هات_الطول()؛\n\tعرف أسطر_م2: صـحيح = م2.هات_الطول()؛\n\tعرف أعمدة_م1: صـحيح = م1(0).هات_الطول()؛\n\tعرف أعمدة_م2: صـحيح = م2(0).هات_الطول()؛\n\n\tعرف نتيجة: مـصفوفة_ثنائية؛\n\t\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tعرف دليل3: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < أسطر_م1 ، دليل1++ {\n\t\tعرف سطر: مـصفوفة[عـائم[64]]؛\n\t\tلكل دليل2 = 0 ، دليل2 < أعمدة_م2 ، دليل2++ {\n\t\t\tسطر.أضف(0)؛\n\t\t\tلكل دليل3 = 0 ، دليل3 < أعمدة_م1 ، دليل3++ {\n\t\t\t\tسطر(دليل2) += م1(دليل1)(دليل3) * م2(دليل3)(دليل2)؛\n\t\t\t}\n\t\t}\n\t\tنتيجة.أضف(سطر)؛\n\t}\n\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "function multiply(a, b) {\n let rowsA = a.length, colsA = a[0].length,\n rowsB = b.length, colsB = b[0].length,\n result = new Array(rowsA);\n\n for (let i = 0; i < rowsA; i++) {\n result[i] = new Array(colsB); // initialize the current row\n for (let j = 0; j < colsB; j++) {\n result[i][j] = 0; // initialize the current cell\n for (let k = 0; k < colsA; k++) {\n result[i][j] += a[i][k] * b[k][j];\n }\n }\n }\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/ريـاضيات\"؛\n\nاستخدم مـتم؛\n\n\nدالة طويلة_شعاع(شعاع: سند[مـصفوفة[عـائم[64]]]): عـائم[64] {\n\tعرف مجموع: عـائم[64] = 0؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < شعاع.هات_الطول() ، دليل++ {\n\t\tمجموع += شعاع(دليل) * شعاع(دليل)؛\n\t}\n\t\n\tارجع ريـاضيات.جذر(مجموع)؛\n}\n"}, {"role": "assistant", "content": "احسب طويلة شعاع معطى ممثل على شكل مصفوفة و ارجع النتيجة"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Array\";\n\nuse Srl;\n\n\ndef MAX_VALUE: Int = 100000;\n\nfunc countingSort(a: ref[Array[Int]]) {\n def i: Int;\n def j: Int;\n def idx: Int;\n\n def count: Array[Int];\n for i = 0 , i < MAX_VALUE , i++ {\n count.add(0);\n }\n\n for i = 0 , i < a.getLength() , i++ {\n count(a(i))++;\n }\n\n for i = 0 , i < MAX_VALUE , i++ {\n for j = 0 , j < count(i) , j++ {\n a(idx++) = i;\n }\n }\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nعرف قيمة_عظمى: صـحيح = 100000؛\n\nدالة الترتيب_بالعد(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tعرف دليل: صـحيح؛\n\t\n\tعرف عداد: مـصفوفة[صـحيح]؛\n\tلكل دليل1 = 0 ، دليل1 < قيمة_عظمى ، دليل1++ {\n\t\tعداد.أضف(0)؛\n\t}\n\t\n\tلكل دليل1 = 0 ، دليل1 < م.هات_الطول() ، دليل1++ {\n\t\tعداد(م(دليل1))++؛\n\t}\n\t\n\tلكل دليل1 = 0 ، دليل1 < قيمة_عظمى ، دليل1++ {\n\t\tلكل دليل2 = 0 ، دليل2 < عداد(دليل1) ، دليل2++ {\n\t\t\tم(دليل++) = دليل1؛\n\t\t}\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc clip(a: ref[Array[Int]], lower: Int, upper: Int) {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if a(i) < lower {\n a(i) = lower;\n }\n else if a(i) > upper {\n a(i) = upper;\n }\n }\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة اقتطع(م: سند[مـصفوفة[صـحيح]]، أدنى: صـحيح، أعلى: صـحيح) {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا م(دليل) < أدنى {\n\t\t\tم(دليل) = أدنى؛\n\t\t}\n\t\tوإلا إذا م(دليل) > أعلى {\n\t\t\tم(دليل) = أعلى؛\n\t\t}\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc insert(a: ref[Array[Int]], pos: Int, val: Int) {\n def size: Int = a.getLength();\n\ta.add(0); // increase the size by 1\n\n def i: Int;\n for i = size , i > pos , i-- {\n a(i) = a(i - 1);\n }\n\n a(pos) = val;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة احشر(م: سند[مـصفوفة[صـحيح]]، موقع: صـحيح، قيمة: صـحيح) {\n\tعرف حجم: صـحيح = م.هات_الطول()؛\n\tم.أضف(0)؛ // لزيادة الحجم بمقدار 1\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = حجم ، دليل > موقع ، دليل-- {\n\t\tم(دليل) = م(دليل - 1)؛\n\t}\n\t\n\tم(موقع) = قيمة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction isPrime(num) {\n if (num <= 1) {\n return false;\n }\n for (let i = 2; i * i <= num; i++) {\n if (num % i === 0) {\n return false;\n }\n }\n return true;\n}\n"}, {"role": "assistant", "content": "استخدم مـتم؛\n\nدالة هل_أولي (عدد: صـحيح): ثـنائي {\n\tإذا عدد <= 1 {\n\t\tارجع خطأ؛\n\t}\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 2 ، دليل * دليل <= عدد ، دليل++ {\n\t\tإذا عدد % دليل == 0 {\n\t\t\tارجع خطأ؛\n\t\t}\n\t}\n\t\n\tارجع صح؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\nvoid rotate(int a[], int n) {\n int first_element = a[0];\n\n for (int i = 0 ; i < n - 1; i++) {\n a[i] = a[i + 1];\n }\n\n a[n - 1] = first_element;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة دور(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف حجم: صـحيح = م.هات_الطول()؛\n\t\n\tعرف أول_عنصر: صـحيح = م(0)؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < حجم - 1 ، دليل++ {\n\t\tم(دليل) = م(دليل + 1)؛\n\t}\n\t\n\tم(حجم - 1) = أول_عنصر؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nعرف مـصفوفة_ثنائية: لقب مـصفوفة[مـصفوفة[عـائم[64]]]؛\n\n\nدالة جداء(م: سند[مـصفوفة_ثنائية]، س: عـائم[64]): مـصفوفة_ثنائية {\n\tعرف أسطر: صـحيح = م.هات_الطول()؛\n\tعرف أعمدة: صـحيح = م(0).هات_الطول()؛\n\n\tعرف نتيجة: مـصفوفة_ثنائية؛\n\t\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < أسطر ، دليل1++ {\n\t\tنتيجة.أضف(مـصفوفة[عـائم[64]]())؛\n\t\tلكل دليل2 = 0 ، دليل2 < أعمدة ، دليل2++ {\n\t\t\t\tنتيجة(دليل1).أضف(م(دليل1)(دليل2)*س)؛\n\t\t}\n\t}\n\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "function multiply(matrix, scalar) {\n let rows = matrix.length, cols = matrix[0].length;\n let result = new Array(rows);\n\n for (let i = 0; i < rows; i++) {\n result[i] = new Array(cols);\n for (let j = 0; j < cols; j++) {\n result[i][j] = matrix[i][j] * scalar;\n }\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Fs\";\nimport \"Srl/String\";\n\nuse Srl;\n\n\nfunc appendLogEntry(file_path: ref[String], logEntry: ref[String]) {\n def file: ptr[Fs.File] = Fs.openFile(file_path.buf, \"a\");\n\n Fs.write(logEntry.buf, 1, logEntry.getLength(), file);\n Fs.write(\"\\n\", 1, 1, file);\n Fs.closeFile(file);\n}\n"}, {"role": "assistant", "content": "#include <stdio.h>\n#include <string.h>\n\nvoid appendLogEntry(char *filename, char *logEntry) {\n FILE *file = fopen(filename, \"a\");\n\n fwrite(logEntry, 1, strlen(logEntry), file);\n fwrite(\"\\n\", 1, 1, file);\n fclose(file);\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\ndouble dot_product(double v1[], double v2[], int n) {\n double result = 0;\n for (int i = 0; i < n; i++) {\n result += v1[i] * v2[i];\n }\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/ريـاضيات\"؛\n\nاستخدم مـتم؛\n\n\nدالة جداء_نقطي(شعاع1: سند[مـصفوفة[عـائم[64]]]، شعاع2: سند[مـصفوفة[عـائم[64]]]): عـائم[64] {\n\tعرف نتيجة: عـائم[64] = 0؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < شعاع1.هات_الطول() ، دليل++ {\n\t\tنتيجة += شعاع1(دليل) * شعاع2(دليل)؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, Calculate the dot product of two given vectors each represented by an array and return the result"}, {"role": "assistant", "content": "double dot_product(double v1[], double v2[], int n) {\n double result = 0;\n for (int i = 0; i < n; i++) {\n result += v1[i] * v2[i];\n }\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\n#include <stdbool.h>\n\nbool char_exists(char s[], int n, char c) {\n for (int i = 0; i < n; i++) {\n if (s[i] == c) {\n return true;\n }\n }\n return false;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة المحرف_متواجد(س: سند[نـص]، م: مـحرف): ثـنائي {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) == م {\n\t\t\tارجع صح؛\n\t\t}\n\t}\n\tارجع خطأ؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Fs\";\nimport \"Srl/String\";\n\nuse Srl;\n\n\nfunc read_file(file_path: ref[String]): String {\n def file: ptr[Fs.File] = Fs.openFile(file_path.buf, \"r\");\n def content: String;\n\n Fs.seek(file, 0, Fs.Seek.END);\n def size: Int = Fs.tell(file);\n Fs.seek(file, 0, Fs.Seek.SET);\n \n\n def i: Int;\n for i = 0 , i < size , i++ {\n def temp: Char;\n Fs.read(temp~ptr, 1, 1, file);\n content.append(temp);\n }\n\n return content;\n}\n"}, {"role": "assistant", "content": "const fs = require('fs');\n\n// Function to read the content of a file into a string one character at a time\nfunction read_file(file_path) {\n const fileDescriptor = fs.openSync(file_path, 'r');\n let file_content = '';\n let buffer = Buffer.alloc(1);\n\n // Read the file one character at a time\n while(fs.readSync(fileDescriptor, buffer, 0, 1)) {\n file_content += buffer.toString();\n }\n\n fs.closeSync(fileDescriptor);\n return file_content;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction insertionSort(arr) {\n let n = arr.length;\n for (let i = 1; i < n; i++) {\n let key = arr[i];\n let j = i - 1;\n\n /* Move elements of arr[0..i-1], that are greater than key,\n to one position ahead of their current position */\n while (j >= 0 && arr[j] > key) {\n arr[j + 1] = arr[j];\n j = j - 1;\n }\n arr[j + 1] = key;\n }\n}\n"}, {"role": "assistant", "content": "write the insertion sort algorithm for a given array"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Fs\";\nimport \"Srl/String\";\n\nuse Srl;\n\n\nfunc read_file(file_path: ref[String]): String {\n def file: ptr[Fs.File] = Fs.openFile(file_path.buf, \"r\");\n def content: String;\n\n Fs.seek(file, 0, Fs.Seek.END);\n def size: Int = Fs.tell(file);\n Fs.seek(file, 0, Fs.Seek.SET);\n \n\n def i: Int;\n for i = 0 , i < size , i++ {\n def temp: Char;\n Fs.read(temp~ptr, 1, 1, file);\n content.append(temp);\n }\n\n return content;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/نـم\"؛\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة اقرأ_الملف(مسار_الملف: سند[نـص]): نـص {\n\tعرف ملف: مؤشر[نـم.مـلف] = نـم.افتح_ملف(مسار_الملف، \"r\")؛\n\t\n\tنـم.انتقل(ملف، 0، نـم.انـتقال._نهاية_)؛\n\tعرف حجم: صـحيح = نـم.هات_الموقع(ملف)؛\n\tنـم.انتقل(ملف، 0، نـم.انـتقال._بداية_)؛\n\t\n\tعرف المحتوى: نـص؛\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < حجم ، دليل++ {\n\t\tعرف مؤقت: مـحرف؛\n\t\tنـم.اقرأ(مؤقت~مؤشر، 1، 1، ملف)؛\n\t\tالمحتوى.ألحق(مؤقت)؛\n\t}\n\t\n\tارجع المحتوى؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nconst fs = require('fs');\nconst readline = require('readline');\n\nfunction read_nth_line(file_path, n) {\n return new Promise((resolve, reject) => {\n const fileStream = fs.createReadStream(file_path);\n\n const rl = readline.createInterface({\n input: fileStream,\n crlfDelay: Infinity\n });\n\n let line_no = 0;\n\n rl.on('line', (line) => {\n line_no++;\n if(line_no === n) {\n resolve(line);\n rl.close();\n }\n });\n\n rl.on('close', () => {\n if(line_no < n) {\n reject(new Error(`The file has less than ${n} lines.`));\n }\n });\n });\n}\n"}, {"role": "assistant", "content": "import \"Srl/Fs\";\nimport \"Srl/String\";\n\nuse Srl;\n\n\nfunc read_nth_line(file_path: ref[String], n: Int): String {\n def file: ptr[Fs.File] = Fs.openFile(file_path.buf, \"r\");\n\n def i: Int;\n def temp: Char = ' ';\n for i = 0 , i < n - 1 , i++ {\n temp = ' ';\n while temp != '\\n' {\n Fs.read(temp~ptr, 1, 1, file);\n }\n }\n\n def nth_line: String;\n temp = ' ';\n while temp != '\\n' {\n Fs.read(temp~ptr, 1, 1, file);\n nth_line.append(temp);\n }\n\n return nth_line;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction insertionSort(arr) {\n let n = arr.length;\n for (let i = 1; i < n; i++) {\n let key = arr[i];\n let j = i - 1;\n\n /* Move elements of arr[0..i-1], that are greater than key,\n to one position ahead of their current position */\n while (j >= 0 && arr[j] > key) {\n arr[j + 1] = arr[j];\n j = j - 1;\n }\n arr[j + 1] = key;\n }\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة الترتيب_بالحشر(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف دليل1: صـحيح؛\n\tعرف مفتاح: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\t\n\tلكل دليل1 = 1 ، دليل1 < م.هات_الطول() ، دليل1++ {\n\t\tمفتاح = م(دليل1)؛\n\t\tدليل2 = دليل1 - 1؛\n\t\t\n\t\tبينما دليل2 >= 0 && م(دليل2) > مفتاح {\n\t\t\tم(دليل2 + 1) = م(دليل2)؛\n\t\t\tدليل2 = دليل2 - 1؛\n\t\t}\n\t\tم(دليل2 + 1) = مفتاح؛\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Fs\";\nimport \"Srl/String\";\n\nuse Srl;\n\n\nfunc appendLogEntry(file_path: ref[String], logEntry: ref[String]) {\n def file: ptr[Fs.File] = Fs.openFile(file_path.buf, \"a\");\n\n Fs.write(logEntry.buf, 1, logEntry.getLength(), file);\n Fs.write(\"\\n\", 1, 1, file);\n Fs.closeFile(file);\n}\n"}, {"role": "assistant", "content": "const fs = require('fs');\n\nfunction appendLogEntry(filename, logEntry) {\n let stream = fs.createWriteStream(filename, {flags:'a'});\n stream.write(logEntry + '\\n');\n stream.end();\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction clip(arr, lower, upper) {\n for(let i = 0; i < arr.length; i++) {\n if(arr[i] < lower) {\n arr[i] = lower;\n } else if(arr[i] > upper) {\n arr[i] = upper;\n }\n }\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة اقتطع(م: سند[مـصفوفة[صـحيح]]، أدنى: صـحيح، أعلى: صـحيح) {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا م(دليل) < أدنى {\n\t\t\tم(دليل) = أدنى؛\n\t\t}\n\t\tوإلا إذا م(دليل) > أعلى {\n\t\t\tم(دليل) = أعلى؛\n\t\t}\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Array\";\n\nuse Srl;\n\n\nfunc invertArray(a: ref[Array[Int]]) {\n def start: Int = 0;\n def end: Int = a.getLength() - 1;\n\n while start < end {\n def temp: Int = a(start);\n a(start) = a(end);\n a(end) = temp;\n start++;\n end--;\n }\n}\n"}, {"role": "assistant", "content": "Invert the given array `a` and return the result"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction std(data, n, mean) {\n let variance = 0.0;\n\n for(let i=0; i<n; ++i)\n variance += (data[i] - mean) * (data[i] - mean);\n\n return Math.sqrt(variance/n);\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/ريـاضيات\"؛\n\nاستخدم مـتم؛\n\n\nدالة انحراف_معياري(م: سند[مـصفوفة[صـحيح]]، متوسط: عـائم): عـائم {\n\tعرف حجم: صـحيح = م.هات_الطول()؛\n\tعرف تباين: عـائم = 0؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < حجم ، دليل++ {\n\t\tتباين += (م(دليل) - متوسط) * (م(دليل) - متوسط)؛\n\t}\n\t\n\tارجع ريـاضيات.جذر(تباين / حجم)؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction slice(arr, start, end) {\n let result = [];\n for(let i = start; i <= end; i++) {\n result.push(arr[i]);\n }\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة اجتزئ(م: سند[مـصفوفة[صـحيح]]، بداية: صـحيح، نهاية: صـحيح، نتيجة: سند[مـصفوفة[صـحيح]]) {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = بداية ، دليل <= نهاية ، دليل++ {\n\t\tنتيجة.أضف(م(دليل))؛\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Math\";\nimport \"Srl/Array\";\n\n\n\nuse Srl;\n\nclass Point {\n def x : Float;\n def y : Float;\n};\n\nfunc calculateDistance(a: Point, b: Point): Float {\n return Math.sqrt(Math.pow(b.x - a.x, 2.0) + Math.pow(b.y - a.y, 2.0));\n}\n\nfunc findFarthestPoint(givenPoint: Point, points: ref[Array[Point]]): Point {\n def maxDistance: Float = 0;\n def farthestPoint: Point;\n\n def i: Int;\n for i = 0 , i < points.getLength() , i++ {\n def distance: Float = calculateDistance(givenPoint, points(i));\n if distance > maxDistance {\n maxDistance = distance;\n farthestPoint = points(i);\n }\n }\n\n return farthestPoint;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/ريـاضيات\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nصنف نـقطة {\n\tعرف س: عـائم؛\n\tعرف ص: عـائم؛\n}\n\nدالة احسب_مسافة(ن1: نـقطة، ن2: نـقطة): عـائم {\n\tارجع ريـاضيات.جذر(ريـاضيات.ارفع(ن2.س - ن1.س، 2.0) + ريـاضيات.ارفع(ن2.ص - ن1.ص، 2.0))؛\n}\n\nدالة جد_أبعد_نقطة(ن: نـقطة، نقاط: سند[مـصفوفة[نـقطة]]): نـقطة {\n\tعرف أبعد_مسافة: عـائم = 0؛\n\tعرف أبعد_نقطة: نـقطة؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < نقاط.هات_الطول() ، دليل++ {\n\t\tعرف مسافة: عـائم = احسب_مسافة(ن، نقاط(دليل))؛\n\t\tإذا مسافة > أبعد_مسافة {\n\t\t\tأبعد_مسافة = مسافة؛\n\t\t\tأبعد_نقطة = نقاط(دليل)؛\n\t\t}\n\t}\n\tارجع أبعد_نقطة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, Calculate the outer product of two given vectors each represented by an array and return the result"}, {"role": "assistant", "content": "function outer_product(v1, v2) {\n let result = [];\n for (let i = 0; i < v1.length; i++) {\n let row = [];\n for (let j = 0; j < v2.length; j++) {\n row.push(v1[i] * v2[j]);\n }\n result.push(row);\n }\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc char_exists(s: ref[String], c: Char): Bool {\n def i: Int;\n\tfor i = 0 , i < s.getLength() , i++ {\n\t\tif (s(i) == c) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة المحرف_متواجد(س: سند[نـص]، م: مـحرف): ثـنائي {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) == م {\n\t\t\tارجع صح؛\n\t\t}\n\t}\n\tارجع خطأ؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\n// Criteria function that checks if a number is positive\nfunction criteria(num) {\n return num > 0;\n}\n\n// Function to check all elements in an array\nfunction check_any(arr) {\n for(let i = 0; i < arr.length; i++) {\n if(criteria(arr[i])) {\n return true;\n }\n }\n return false;\n}\n"}, {"role": "assistant", "content": "Check if any element in a given array satisfy a criteria defined by a function with boolean return value"}]}
{"messages": [{"role": "user", "content": "Using c, check if a given character is a digit"}, {"role": "assistant", "content": "#include <stdbool.h>\n\nbool is_digit(char c) {\n return (c >= '0' && c <= '9');\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Array\";\nimport \"closure\";\n\n\nuse Srl;\n\n\nfunc check_all(a: ref[Array[Int]], f: closure (num: Int): Bool): Bool {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if !f(a(i)) {\n return false;\n }\n }\n\n return true;\n}\n"}, {"role": "assistant", "content": "// Criteria function that checks if a number is positive\nfunction criteria(num) {\n return num > 0;\n}\n\n// Function to check all elements in an array\nfunction check_all(arr) {\n for(let i = 0; i < arr.length; i++) {\n if(!criteria(arr[i])) {\n return false;\n }\n }\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\n#include <math.h>\n\n\ndouble vectorNorm(double* vector, int size) {\n double sum = 0.0;\n for (int i = 0; i < size; i++) {\n sum += vector[i] * vector[i];\n }\n return sqrt(sum);\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"Srl/Math\";\n\nuse Srl;\n\n\nfunc vectorNorm(vector: ref[Array[Float[64]]]): Float[64] {\n def sum: Float[64] = 0;\n\n def i: Int;\n for i = 0 , i < vector.getLength() , i++ {\n sum += vector(i) * vector(i);\n }\n\n return Math.sqrt(sum);\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, check if three given points are collinear"}, {"role": "assistant", "content": "#include <stdbool.h>\n\ntypedef struct {\n int x;\n int y;\n} Point;\n\nbool areCollinear(Point p1, Point p2, Point p3) {\n // Calculate the slopes of the lines formed by (p1, p2) and (p1, p3)\n // If the slopes are equal, then p1, p2 and p3 are collinear\n return (p2.y - p1.y) * (p3.x - p1.x) == (p3.y - p1.y) * (p2.x - p1.x);\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nعرف قيمة_عظمى: صـحيح = 100000؛\n\nدالة الترتيب_بالعد(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tعرف دليل: صـحيح؛\n\t\n\tعرف عداد: مـصفوفة[صـحيح]؛\n\tلكل دليل1 = 0 ، دليل1 < قيمة_عظمى ، دليل1++ {\n\t\tعداد.أضف(0)؛\n\t}\n\t\n\tلكل دليل1 = 0 ، دليل1 < م.هات_الطول() ، دليل1++ {\n\t\tعداد(م(دليل1))++؛\n\t}\n\t\n\tلكل دليل1 = 0 ، دليل1 < قيمة_عظمى ، دليل1++ {\n\t\tلكل دليل2 = 0 ، دليل2 < عداد(دليل1) ، دليل2++ {\n\t\t\tم(دليل++) = دليل1؛\n\t\t}\n\t}\n}\n"}, {"role": "assistant", "content": "#include <stdlib.h>\n\n#define MAX_VALUE 100000\n\nvoid counting_sort(int arr[], int n) {\n int i, j;\n int idx = 0;\n int* count = calloc(MAX_VALUE + 1, sizeof(int));\n\n // Count the occurrence of each number\n for(i = 0; i < n; i++) {\n count[arr[i]]++;\n }\n\n // Reconstruct the sorted array\n for(i = 0; i <= MAX_VALUE; i++) {\n for(j = 0; j < count[i]; j++) {\n arr[idx++] = i;\n }\n }\n\n free(count);\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/String\";\nimport \"Srl/Array\"\n\nuse Srl;\n\n\nfunc split(s: ref[String], token: Char): Array[String] {\n def result: Array[String];\n\n def temp: String;\n def i: Int;\n for i = 0 , i < s.getLength() , i++ {\n if (s(i) != token) {\n temp.append(s(i));\n }\n else {\n result.add(temp);\n temp = \"\";\n }\n }\n result.add(temp);\n return result;\n}\n"}, {"role": "assistant", "content": "#include <stdlib.h>\n\n#define MAX_STRINGS 100\n#define MAX_STRING_LEN 100\n\nchar** split(char* str, char token) {\n char** result = (char**) malloc(MAX_STRINGS * sizeof(char*));\n for(int i = 0; i < MAX_STRINGS; i++) {\n result[i] = (char*) malloc(MAX_STRING_LEN * sizeof(char));\n }\n\n int i = 0, j = 0, k = 0;\n while(str[i] != '\\0') {\n if(str[i] != token) {\n result[j][k] = str[i];\n k++;\n } else {\n result[j][k] = '\\0';\n j++;\n k = 0;\n }\n i++;\n }\n result[j][k] = '\\0';\n result[j+1] = NULL; // End of strings\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, احسب و أرجع مجموع عناصر مصفوفة معطاة في مجال معطى"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جمع(م: سند[مـصفوفة[صـحيح]]، بداية: صـحيح، نهاية: صـحيح): صـحيح {\n\tعرف نتيجة: صـحيح = 0؛\n\n\tعرف دليل: صـحيح؛\n\n\tلكل دليل = بداية ، دليل < نهاية ، دليل++ {\n نتيجة += م(دليل)؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\n// Criteria function that checks if a number is positive\nfunction criteria(num) {\n return num > 0;\n}\n\n// Function to check all elements in an array\nfunction check_any(arr) {\n for(let i = 0; i < arr.length; i++) {\n if(criteria(arr[i])) {\n return true;\n }\n }\n return false;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة تفحص_أي(م: سند[مـصفوفة[صـحيح]]، د: مغلفة(رقم: صـحيح): ثـنائي): ثـنائي {\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا د(م(دليل)) {\n\t\t\tارجع صح؛\n\t\t}\n\t}\n\n\tارجع خطأ؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction is_alphabet(c) {\n return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');\n}\n"}, {"role": "assistant", "content": "check if a given character is from the alphabet"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction dfs(node, visited, G) {\n visited[node] = true;\n console.log(node);\n\n for(let i = 0; i < G[node].length; i++) {\n if(!visited[G[node][i]]) {\n dfs(G[node][i], visited, G);\n }\n }\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"Srl/Console\";\n\nuse Srl;\n\nfunc dfs(node: Int, visited: ref[Array[Bool]], graph: ref[Array[Array[Int]]]) {\n visited(node) = true;\n Console.print(\"%d \", node);\n\n def i: Int;\n for i = 0 , i < graph(node).getLength(), i++ {\n def childNode: Int = graph(node)(i);\n if !visited(childNode) {\n dfs(childNode, visited, graph);\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, احسب الانحراف المعياري للمصفوفة المعطاة"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/ريـاضيات\"؛\n\nاستخدم مـتم؛\n\n\nدالة انحراف_معياري(م: سند[مـصفوفة[صـحيح]]، متوسط: عـائم): عـائم {\n\tعرف حجم: صـحيح = م.هات_الطول()؛\n\tعرف تباين: عـائم = 0؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < حجم ، دليل++ {\n\t\tتباين += (م(دليل) - متوسط) * (م(دليل) - متوسط)؛\n\t}\n\t\n\tارجع ريـاضيات.جذر(تباين / حجم)؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة لكل_عنصر(م: سند[مـصفوفة[صـحيح]]، د: مغلفة(عنصر: صـحيح): صـحيح) {\n\tعرف دليل: صـحيح؛\n\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tم(دليل) = د(م(دليل))؛\n\t}\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"closure\";\n\nuse Srl;\n\n\nfunc foreach(a: ref[Array[Int]], f: closure(element: Int): Int) {\n def i: Int;\n \n for i = 0 , i < a.getLength() , i++ {\n a(i) = f(a(i));\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc starts_with(s: ref[String], prefix: ref[String]): Bool {\n\tif s.getLength() < prefix.getLength() {\n\t\treturn false;\n\t}\n\n def i: Int;\n\tfor i = 0 , i < prefix.getLength() , i++ {\n\t\tif (prefix(i) != s(i)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة يبدأ_ب(س: سند[نـص]، سابق: سند[نـص]): ثـنائي {\n\tإذا س.هات_الطول() < سابق.هات_الطول() {\n\t\tارجع خطأ؛\n\t}\n\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < سابق.هات_الطول() ، دليل++ {\n\t\tإذا سابق(دليل) != س(دليل) {\n\t\t\tارجع خطأ؛\n\t\t}\n\t}\n\tارجع صح؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/نـم\"؛\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة ألحق_سجل(مسار_الملف: سند[نـص]، سجل: سند[نـص]) {\n\tعرف ملف: مؤشر[نـم.مـلف] = نـم.افتح_ملف(مسار_الملف، \"a\")؛\n\t\n\tنـم.اكتب(سجل.صوان، 1، سجل.هات_الطول()، ملف)؛\n\tنـم.اكتب(\"\\ج\"، 1، 1، ملف)؛\n\tنـم.اغلق_ملف(ملف)؛\n}\n"}, {"role": "assistant", "content": "ألحق سجل إلى ملف معطى مساره"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\n#include <stdlib.h>\n\ndouble** outer_product(double v1[], double v2[], int n) {\n double** result = (double**)malloc(n * sizeof(double*));\n for (int i = 0; i < n; i++) {\n result[i] = (double*)malloc(n * sizeof(double));\n for (int j = 0; j < n; j++) {\n result[i][j] = v1[i] * v2[j];\n }\n }\n return result;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\n\nfunc outer_product(v1: ref[Array[Float[64]]], v2: ref[Array[Float[64]]]): Array[Array[Float[64]]] {\n def result: Array[Array[Float[64]]];\n\n def i: Int;\n def j: Int;\n for i = 0 , i < v1.getLength() , i++ {\n def row: Array[Float[64]];\n for j = 0 , j < v2.getLength() , j++ {\n row.add(v1(i)*v2(j));\n }\n result.add(row);\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Array\";\n\nuse Srl;\n\n\nfunc selectionSort(a: ref[Array[Int]]) {\n def i: Int;\n def j: Int;\n def temp: Int;\n def min_idx: Int;\n\n for i = 0 , i < a.getLength() - 1 , i++ {\n min_idx = i;\n for j = i + 1 , j < a.getLength() , j++ {\n if a(j) < a(min_idx) {\n min_idx = j;\n }\n }\n\n temp = a(min_idx);\n a(min_idx) = a(i);\n a(i) = temp;\n }\n}\n"}, {"role": "assistant", "content": "function selectionSort(arr) {\n let n = arr.length;\n\n for(let i = 0; i < n; i++) {\n // Finding the smallest number in the subarray\n let min = i;\n for(let j = i+1; j < n; j++){\n if(arr[j] < arr[min]) {\n min=j; \n }\n }\n // Swapping the elements\n let tmp = arr[i]; \n arr[i] = arr[min];\n arr[min] = tmp; \n }\n return arr;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\ndouble calculateMean(int arr[], int n) {\n int sum = 0;\n for (int i = 0; i < n; i++) {\n sum += arr[i];\n }\n return (double)sum / n;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"Srl/Math\";\n\n\nuse Srl;\n\n\nfunc mean(a: ref[Array[Int]]): Float {\n def size: Int = a.getLength();\n def sum: Int = 0;\n\n def i: Int;\n for i = 0 , i < size , i++ {\n sum += a(i);\n }\n\n return sum~cast[Float] / size;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, قم بتصفية المصفوفة المعطاة بناءً على الدالة المعطاة د و أرجع النتيجة"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة فلتر(م: سند[مـصفوفة[صـحيح]]، د: مغلفة(رقم: صـحيح): ثـنائي): مـصفوفة[صـحيح] {\n\tعرف نتيجة: مـصفوفة[صـحيح]؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا د(م(دليل)) {\n\t\t\tنتيجة.أضف(م(دليل))؛\n\t\t}\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, دور المصفوفة المعطاة بعكس اتجاه عقارب الساعة و أرجع النتيجة"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة دور(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف حجم: صـحيح = م.هات_الطول()؛\n\t\n\tعرف أول_عنصر: صـحيح = م(0)؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < حجم - 1 ، دليل++ {\n\t\tم(دليل) = م(دليل + 1)؛\n\t}\n\t\n\tم(حجم - 1) = أول_عنصر؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة الترتيب_بالاختيار(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tعرف مؤقت: صـحيح؛\n\tعرف أصغر_دليل: صـحيح؛\n\t\n\tلكل دليل1 = 0 ، دليل1 < م.هات_الطول() - 1 ، دليل1++ {\n\t\tأصغر_دليل = دليل1؛\n\t\t\n\t\tلكل دليل2 = دليل1 + 1 ، دليل2 < م.هات_الطول() ، دليل2++ {\n\t\t\tإذا م(دليل2) < م(أصغر_دليل) {\n\t\t\t\tأصغر_دليل = دليل2؛\n\t\t\t}\n\t\t}\n\t\t\n\t\tمؤقت = م(أصغر_دليل)؛\n\t\tم(أصغر_دليل) = م(دليل1)؛\n\t\tم(دليل1) = مؤقت؛\n\t}\n}\n"}, {"role": "assistant", "content": "اكتب خوارزمية الفرز بالاختيار لمصفوفة معطاة"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction calculatePolygonArea(vertices) {\n let area = 0;\n let j = vertices.length - 1;\n\n for (let i = 0; i < vertices.length; i++) {\n area += (vertices[j].x + vertices[i].x) * (vertices[j].y - vertices[i].y);\n j = i;\n }\n\n return Math.abs(area / 2);\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/ريـاضيات\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nصنف نـقطة {\n\tعرف س: عـائم؛\n\tعرف ص: عـائم؛\n}\n\nدالة مساحة_مضلع(رؤوس: سند[مـصفوفة[نـقطة]]): عـائم {\n\tعرف مساحة: عـائم = 0؛\n\tعرف عدد_الرؤوس: صـحيح = رؤوس.هات_الطول()؛\n\tعرف دليل2: صـحيح = عدد_الرؤوس - 1؛\n\t\n\tعرف دليل1: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < عدد_الرؤوس ، دليل1++ {\n\t\tمساحة += (رؤوس(دليل1).س + رؤوس(دليل2).س) * (رؤوس(دليل1).ص - رؤوس(دليل2).ص)؛\n\t\tدليل2 = دليل1؛\n\t}\n\tارجع ريـاضيات.مطلق(مساحة / 2.0)؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاستخدم مـتم؛\n\n\nصنف نـقطة {\n\tعرف س: صـحيح؛\n\tعرف ص: صـحيح؛\n}\n\nدالة على_خط_مستقيم(ن1: نـقطة، ن2: نـقطة، ن3: نـقطة): ثـنائي {\n\tارجع (ن2.ص - ن1.ص) * (ن3.س - ن1.ص) == (ن3.ص - ن1.ص) * (ن2.س - ن1.س)؛\n}\n"}, {"role": "assistant", "content": "function Point(x, y) {\n this.x = x;\n this.y = y;\n}\n\nfunction areCollinear(p1, p2, p3) {\n // Calculate the slopes of the lines formed by (p1, p2) and (p1, p3)\n // If the slopes are equal, then p1, p2 and p3 are collinear\n return (p2.y - p1.y) * (p3.x - p1.x) === (p3.y - p1.y) * (p2.x - p1.x);\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\n#include <stdbool.h>\n\n// Criteria function that checks if a number is positive\nbool criteria(int num) {\n return num > 0;\n}\n\n// Function to check all elements in an array\nbool check_any(int arr[], int size) {\n for(int i = 0; i < size; i++) {\n if(criteria(arr[i])) {\n return true;\n }\n }\n return false;\n}\n"}, {"role": "assistant", "content": "Check if any element in a given array satisfy a criteria defined by a function with boolean return value"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc insert(a: ref[Array[Int]], pos: Int, val: Int) {\n def size: Int = a.getLength();\n\ta.add(0); // increase the size by 1\n\n def i: Int;\n for i = size , i > pos , i-- {\n a(i) = a(i - 1);\n }\n\n a(pos) = val;\n}\n"}, {"role": "assistant", "content": "void insert(int a[], int n, int pos, int x) {\n // Shift elements to right\n for (int i = n; i > pos; i--)\n a[i] = a[i - 1];\n\n // Insert x at pos\n a[pos] = x;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\n#include <stdlib.h>\n\nvoid merge(int arr[], int l, int m, int r) {\n int i, j, k;\n int n1 = m - l + 1;\n int n2 = r - m;\n\n int L[n1], R[n2];\n\n for (i = 0; i < n1; i++)\n L[i] = arr[l + i];\n for (j = 0; j < n2; j++)\n R[j] = arr[m + 1 + j];\n\n i = 0;\n j = 0;\n k = l;\n while (i < n1 && j < n2) {\n if (L[i] <= R[j]) {\n arr[k] = L[i];\n i++;\n } else {\n arr[k] = R[j];\n j++;\n }\n k++;\n }\n\n while (i < n1) {\n arr[k] = L[i];\n i++;\n k++;\n }\n\n while (j < n2) {\n arr[k] = R[j];\n j++;\n k++;\n }\n}\n\nvoid mergeSort(int arr[], int l, int r) {\n if (l < r) {\n int m = l + (r - l) / 2;\n\n mergeSort(arr, l, m);\n mergeSort(arr, m + 1, r);\n\n merge(arr, l, m, r);\n }\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\n\nfunc merge(a: ref[Array[Int]], l: Int, m: Int, r: Int) {\n def i: Int;\n def j: Int;\n def k: Int;\n\n def n1: Int = m - l + 1;\n def n2: Int = r - m;\n\n def L: Array[Int];\n def R: Array[Int];\n\n for i = 0 , i < n1 , i++ {\n L.add(a(l+i));\n }\n for i = 0 , i < n2 , i++ {\n R.add(a(m + 1 + i));\n }\n\n i = 0;\n j = 0;\n k = l;\n while i < n1 && j < n2 {\n if L(i) <= R(j) {\n a(k) = L(i);\n i++;\n }\n else {\n a(k) = R(j);\n j++;\n }\n k++;\n }\n\n while i < n1 {\n a(k) = L(i);\n i++;\n k++;\n }\n\n while j < n2 {\n a(k) = R(j);\n j++;\n k++;\n }\n}\n\nfunc mergeSort(a: ref[Array[Int]], l: Int, r: Int) {\n if l < r {\n def m: Int = l + (r - l) / 2;\n\n mergeSort(a, l, m);\n mergeSort(a, m + 1, r);\n\n merge(a, l, m, r);\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جد_من_الخلف(م: سند[مـصفوفة[صـحيح]]، قيمة: صـحيح): صحيح {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = م.هات_الطول() - 1 ، دليل != 0 ، دليل-- {\n\t\tإذا م(دليل) == قيمة {\n\t\t\tارجع دليل؛\n\t\t}\n\t}\n\tارجع -1؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc rfind(a: ref[Array[Int]], val: Int): Int {\n def i: Int;\n for i = a.getLength() - 1 , i != 0 , i-- {\n if a(i) == val {\n return i;\n }\n }\n return -1;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\n#include <stdlib.h>\n\nint** multiply(int** a, int scalar, int rows, int cols) {\n int i, j;\n // Create a result matrix dynamically\n int** result = (int**)malloc(rows * sizeof(int*));\n for(i = 0; i < rows; i++) {\n result[i] = (int*)malloc(cols * sizeof(int));\n }\n\n // Multiply the matrix by the scalar\n for(i = 0; i < rows; i++) {\n for(j = 0; j < cols; j++) {\n result[i][j] = a[i][j] * scalar;\n }\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nعرف مـصفوفة_ثنائية: لقب مـصفوفة[مـصفوفة[عـائم[64]]]؛\n\n\nدالة جداء(م: سند[مـصفوفة_ثنائية]، س: عـائم[64]): مـصفوفة_ثنائية {\n\tعرف أسطر: صـحيح = م.هات_الطول()؛\n\tعرف أعمدة: صـحيح = م(0).هات_الطول()؛\n\n\tعرف نتيجة: مـصفوفة_ثنائية؛\n\t\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < أسطر ، دليل1++ {\n\t\tنتيجة.أضف(مـصفوفة[عـائم[64]]())؛\n\t\tلكل دليل2 = 0 ، دليل2 < أعمدة ، دليل2++ {\n\t\t\t\tنتيجة(دليل1).أضف(م(دليل1)(دليل2)*س)؛\n\t\t}\n\t}\n\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction mergeSort(arr) {\n if (arr.length < 2)\n return arr;\n\n let mid = Math.floor(arr.length / 2);\n let left = arr.slice(0, mid);\n let right = arr.slice(mid);\n\n return merge(mergeSort(left), mergeSort(right));\n}\n\nfunction merge(left, right) {\n let result = [];\n let i = 0;\n let j = 0;\n\n while (i < left.length && j < right.length) {\n if (left[i] < right[j]) {\n result.push(left[i]);\n i++;\n } else {\n result.push(right[j]);\n j++;\n }\n }\n\n return result.concat(left.slice(i)).concat(right.slice(j));\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\n\nfunc merge(a: ref[Array[Int]], l: Int, m: Int, r: Int) {\n def i: Int;\n def j: Int;\n def k: Int;\n\n def n1: Int = m - l + 1;\n def n2: Int = r - m;\n\n def L: Array[Int];\n def R: Array[Int];\n\n for i = 0 , i < n1 , i++ {\n L.add(a(l+i));\n }\n for i = 0 , i < n2 , i++ {\n R.add(a(m + 1 + i));\n }\n\n i = 0;\n j = 0;\n k = l;\n while i < n1 && j < n2 {\n if L(i) <= R(j) {\n a(k) = L(i);\n i++;\n }\n else {\n a(k) = R(j);\n j++;\n }\n k++;\n }\n\n while i < n1 {\n a(k) = L(i);\n i++;\n k++;\n }\n\n while j < n2 {\n a(k) = R(j);\n j++;\n k++;\n }\n}\n\nfunc mergeSort(a: ref[Array[Int]], l: Int, r: Int) {\n if l < r {\n def m: Int = l + (r - l) / 2;\n\n mergeSort(a, l, m);\n mergeSort(a, m + 1, r);\n\n merge(a, l, m, r);\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Array\";\nimport \"closure\";\n\nuse Srl;\n\n\nfunc foreach(a: ref[Array[Int]], f: closure(element: Int): Int) {\n def i: Int;\n \n for i = 0 , i < a.getLength() , i++ {\n a(i) = f(a(i));\n }\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة لكل_عنصر(م: سند[مـصفوفة[صـحيح]]، د: مغلفة(عنصر: صـحيح): صـحيح) {\n\tعرف دليل: صـحيح؛\n\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tم(دليل) = د(م(دليل))؛\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/نـم\"؛\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة ألحق_سجل(مسار_الملف: سند[نـص]، سجل: سند[نـص]) {\n\tعرف ملف: مؤشر[نـم.مـلف] = نـم.افتح_ملف(مسار_الملف، \"a\")؛\n\t\n\tنـم.اكتب(سجل.صوان، 1، سجل.هات_الطول()، ملف)؛\n\tنـم.اكتب(\"\\ج\"، 1، 1، ملف)؛\n\tنـم.اغلق_ملف(ملف)؛\n}\n"}, {"role": "assistant", "content": "const fs = require('fs');\n\nfunction appendLogEntry(filename, logEntry) {\n let stream = fs.createWriteStream(filename, {flags:'a'});\n stream.write(logEntry + '\\n');\n stream.end();\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, جد عدد المكونات المترابطة في بيان غير موجه معطى"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nدالة دفس(عقدة: صـحيح، مزارة: سند[مـصفوفة[ثـنائي]]، بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]) {\n\tمزارة(عقدة) = صح؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان(عقدة).هات_الطول() ، دليل++ {\n\t\tعرف عقدة_ابن: صـحيح = بيان(عقدة)(دليل)؛\n\t\tإذا !مزارة(عقدة_ابن) {\n\t\t\tدفس(عقدة_ابن، مزارة، بيان)؛\n\t\t}\n\t}\n}\n\n\nدالة عدد_المكونات_المترابطة(بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]): صـحيح {\n\tعرف مزارة: مـصفوفة[ثـنائي]؛\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان.هات_الطول() ، دليل++ {\n\t\tمزارة.أضف(خطأ)؛\n\t}\n\t\n\tعرف عدد_المكونات: صـحيح = 0؛\n\tلكل دليل = 0 ، دليل < بيان.هات_الطول() ، دليل++ {\n\t\tإذا !مزارة(دليل) {\n\t\t\tدفس(دليل، مزارة، بيان)؛\n\t\t\tعدد_المكونات++؛\n\t\t}\n\t}\n\t\n\tارجع عدد_المكونات؛\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, اعكس السلسلة النصية المعطاة س و أرجع النتيجة"}, {"role": "assistant", "content": "اشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة اعكس_نص(س: نـص): نـص {\n\tعرف طول: صـحيح = س.هات_الطول()؛\n\tعرف نتيجة: نـص = \"\"؛\n\n\tعرف دليل: صـحيح؛\n\tلكل دليل = طول - 1 ، دليل >= 0 ، دليل-- {\n\t\tنتيجة.ألحق(س(دليل))؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة متوسط(م: سند[مـصفوفة[صـحيح]]): عـائم {\n\tعرف حجم: صـحيح = م.هات_الطول()؛\n\tعرف مجموع: صـحيح = 0؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < حجم ، دليل++ {\n\t\tمجموع += م(دليل)؛\n\t}\n\t\n\tارجع مجموع~مثل[عـائم] / حجم؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"Srl/Math\";\n\n\nuse Srl;\n\n\nfunc mean(a: ref[Array[Int]]): Float {\n def size: Int = a.getLength();\n def sum: Int = 0;\n\n def i: Int;\n for i = 0 , i < size , i++ {\n sum += a(i);\n }\n\n return sum~cast[Float] / size;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة اعكس_مصفوفة(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف بداية: صـحيح = 0؛\n\tعرف نهاية: صـحيح = م.هات_الطول() - 1؛\n\n\tبينما بداية < نهاية {\n\t\tعرف مؤقت: صـحيح = م(بداية)؛\n\t\tم(بداية) = م(نهاية)؛\n\t\tم(نهاية) = مؤقت؛\n\t\tبداية++؛\n\t\tنهاية--؛\n\t}\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\n\nfunc invertArray(a: ref[Array[Int]]) {\n def start: Int = 0;\n def end: Int = a.getLength() - 1;\n\n while start < end {\n def temp: Int = a(start);\n a(start) = a(end);\n a(end) = temp;\n start++;\n end--;\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة تفحص_الكل(م: سند[مـصفوفة[صـحيح]]، د: مغلفة(رقم: صـحيح): ثـنائي): ثـنائي {\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا !د(م(دليل)) {\n\t\t\tارجع خطأ؛\n\t\t}\n\t}\n\t\n\tارجع صح؛\n}\n"}, {"role": "assistant", "content": "تفحص فيما إذا كان كل عناصر مصفوفة معطاة تحقق معيارًا معرفًا بدالة تعيد قيمة ثـنائية"}]}
{"messages": [{"role": "user", "content": "Using js, print the given array"}, {"role": "assistant", "content": "function printArray(a, size) {\n var output = '';\n for(var i = 0; i < size; i++) {\n output += a[i] + ' ';\n }\n console.log(output);\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Array\";\n\nuse Srl;\n\n\nfunc invertArray(a: ref[Array[Int]]) {\n def start: Int = 0;\n def end: Int = a.getLength() - 1;\n\n while start < end {\n def temp: Int = a(start);\n a(start) = a(end);\n a(end) = temp;\n start++;\n end--;\n }\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة اعكس_مصفوفة(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف بداية: صـحيح = 0؛\n\tعرف نهاية: صـحيح = م.هات_الطول() - 1؛\n\n\tبينما بداية < نهاية {\n\t\tعرف مؤقت: صـحيح = م(بداية)؛\n\t\tم(بداية) = م(نهاية)؛\n\t\tم(نهاية) = مؤقت؛\n\t\tبداية++؛\n\t\tنهاية--؛\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc toLowerCase(s: ref[String]): String {\n\tdef result: String = \"\";\n def i: Int;\n\tdef c: Char;\n\tfor i = 0 , i < s.getLength() , i++ {\n\t\tif (s(i) >= 'A' && s(i) <= 'Z') {\n\t\t\tc = s(i) - 'A' + 'a';\n\t\t}\n\t\telse {\n\t\t\tc = s(i);\n\t\t}\n\t\tresult += c;\n\t}\n\treturn result;\n}\n"}, {"role": "assistant", "content": "function toLowerCase(s) {\n let result = '';\n for(let i = 0; i < s.length; i++){\n let code = s.charCodeAt(i);\n if(code >= 65 && code <= 90){\n result += String.fromCharCode(code + 32);\n } else {\n result += s[i];\n }\n }\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة استبدل(س: سند[نـص]، م1: مـحرف، م2: مـحرف): نـص {\n\tعرف نتيجة: نـص؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) == م1 {\n\t\t\tنتيجة.ألحق(م2)؛\n\t\t}\n\t\tوإلا {\n\t\t\tنتيجة.ألحق(س(دليل))؛\n\t\t}\n\t}\n\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "استبدل محرف معطى بآخر معطى في سلسلة نصية معطاة و ارجع السلسلة النصية الجديدة"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Array\";\nimport \"Srl/Math\";\n\n\nuse Srl;\n\n\nfunc mean(a: ref[Array[Int]]): Float {\n def size: Int = a.getLength();\n def sum: Int = 0;\n\n def i: Int;\n for i = 0 , i < size , i++ {\n sum += a(i);\n }\n\n return sum~cast[Float] / size;\n}\n"}, {"role": "assistant", "content": "function calculateMean(arr) {\n var sum = 0;\n for (var i = 0; i < arr.length; i++) {\n sum += arr[i];\n }\n return sum / arr.length;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\n#include <stdbool.h>\n\n// Function to check if arr2 is a permutation of arr1\nbool is_permutation(int arr1[], int size1, int arr2[], int size2) {\n // If sizes are not equal, return false\n if(size1 != size2) {\n return false;\n }\n\n // Create an array to keep track of visited elements\n bool visited[size2];\n for(int i = 0; i < size2; i++) {\n visited[i] = false;\n }\n\n // For each element in arr1\n for(int i = 0; i < size1; i++) {\n bool found = false;\n\n // For each element in arr2\n for(int j = 0; j < size2; j++) {\n // If the element in arr1 is found in arr2 and it has not been visited\n if(arr1[i] == arr2[j] && !visited[j]) {\n found = true;\n visited[j] = true; // Mark the element in arr2 as visited\n break;\n }\n }\n\n // If the element in arr1 is not found in arr2, return false\n if(!found) {\n return false;\n }\n }\n\n // If we reach here, then arr2 is a permutation of arr1\n return true;\n}\n"}, {"role": "assistant", "content": "Check whether a given array is a permutation for another given array"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة احشر(م: سند[مـصفوفة[صـحيح]]، موقع: صـحيح، قيمة: صـحيح) {\n\tعرف حجم: صـحيح = م.هات_الطول()؛\n\tم.أضف(0)؛ // لزيادة الحجم بمقدار 1\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = حجم ، دليل > موقع ، دليل-- {\n\t\tم(دليل) = م(دليل - 1)؛\n\t}\n\t\n\tم(موقع) = قيمة؛\n}\n"}, {"role": "assistant", "content": "void insert(int a[], int n, int pos, int x) {\n // Shift elements to right\n for (int i = n; i > pos; i--)\n a[i] = a[i - 1];\n\n // Insert x at pos\n a[pos] = x;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, اعكس المصفوفة المعطاة م و أرجع النتيجة"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة اعكس_مصفوفة(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف بداية: صـحيح = 0؛\n\tعرف نهاية: صـحيح = م.هات_الطول() - 1؛\n\n\tبينما بداية < نهاية {\n\t\tعرف مؤقت: صـحيح = م(بداية)؛\n\t\tم(بداية) = م(نهاية)؛\n\t\tم(نهاية) = مؤقت؛\n\t\tبداية++؛\n\t\tنهاية--؛\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\n#include <stdbool.h>\n\nbool is_digit(char c) {\n return (c >= '0' && c <= '9');\n}\n"}, {"role": "assistant", "content": "use Srl;\n\n\nfunc is_digit(c: Char): Bool {\n return (c >= '0' && c <= '9');\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nint findMax(int* a, int n) {\n int max = a[0];\n for(int i = 1; i < n; i++) {\n if(a[i] > max) {\n max = a[i];\n }\n }\n return max;\n}\n"}, {"role": "assistant", "content": "Find and return the maximum in the given array `a`"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Array\";\nimport \"Srl/Math\";\n\n\nuse Srl;\n\n\nfunc mean(a: ref[Array[Int]]): Float {\n def size: Int = a.getLength();\n def sum: Int = 0;\n\n def i: Int;\n for i = 0 , i < size , i++ {\n sum += a(i);\n }\n\n return sum~cast[Float] / size;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة متوسط(م: سند[مـصفوفة[صـحيح]]): عـائم {\n\tعرف حجم: صـحيح = م.هات_الطول()؛\n\tعرف مجموع: صـحيح = 0؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < حجم ، دليل++ {\n\t\tمجموع += م(دليل)؛\n\t}\n\t\n\tارجع مجموع~مثل[عـائم] / حجم؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Array\";\n\nuse Srl;\n\nfunc floydWarshall(graph: ref[Array[Array[Int]]], dist: ref[Array[Array[Int]]]) {\n def n: Int = graph.getLength();\n def i: Int;\n def j: Int;\n def k: Int;\n\n for i = 0 , i < n , i++ {\n dist.add(graph(i));\n }\n\n for k = 0 , k < n , k++ {\n for i = 0 , i < n , i++ {\n for j = 0 , j < n , j++ {\n if dist(i)(k) + dist(k)(j) < dist(i)(j) {\n dist(i)(j) = dist(i)(k) + dist(k)(j);\n }\n }\n }\n }\n}\n"}, {"role": "assistant", "content": "Write Floyd Warshall algorithm for a given graph"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc toLowerCase(s: ref[String]): String {\n\tdef result: String = \"\";\n def i: Int;\n\tdef c: Char;\n\tfor i = 0 , i < s.getLength() , i++ {\n\t\tif (s(i) >= 'A' && s(i) <= 'Z') {\n\t\t\tc = s(i) - 'A' + 'a';\n\t\t}\n\t\telse {\n\t\t\tc = s(i);\n\t\t}\n\t\tresult += c;\n\t}\n\treturn result;\n}\n"}, {"role": "assistant", "content": "void toLowerCase(char *s, char *result) {\n for(int i = 0; s[i]; i++){\n if(s[i] >= 'A' && s[i] <= 'Z'){\n result[i] = s[i] - 'A' + 'a';\n }\n else {\n result[i] = s[i];\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction mergeSort(arr) {\n if (arr.length < 2)\n return arr;\n\n let mid = Math.floor(arr.length / 2);\n let left = arr.slice(0, mid);\n let right = arr.slice(mid);\n\n return merge(mergeSort(left), mergeSort(right));\n}\n\nfunction merge(left, right) {\n let result = [];\n let i = 0;\n let j = 0;\n\n while (i < left.length && j < right.length) {\n if (left[i] < right[j]) {\n result.push(left[i]);\n i++;\n } else {\n result.push(right[j]);\n j++;\n }\n }\n\n return result.concat(left.slice(i)).concat(right.slice(j));\n}\n"}, {"role": "assistant", "content": "write the merge sort algorithm for a given array"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, تحقق فيما إذا كان عدد معطى أولي أم لا و ارجع تلك النتيجة"}, {"role": "assistant", "content": "استخدم مـتم؛\n\nدالة هل_أولي (عدد: صـحيح): ثـنائي {\n\tإذا عدد <= 1 {\n\t\tارجع خطأ؛\n\t}\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 2 ، دليل * دليل <= عدد ، دليل++ {\n\t\tإذا عدد % دليل == 0 {\n\t\t\tارجع خطأ؛\n\t\t}\n\t}\n\t\n\tارجع صح؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction invert_string(str) {\n return str.split('').reverse().join('');\n}\n"}, {"role": "assistant", "content": "Invert the given string `s` and return the result"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\n#include <stdio.h>\n#include <stdlib.h>\n\n// Function to read the n-th line of a file\nchar* read_nth_line(const char* file_path, int n) {\n FILE* file = fopen(file_path, \"r\");\n if(file == NULL) {\n printf(\"Could not open file %s\\n\", file_path);\n return NULL;\n }\n\n char* line = NULL;\n size_t len = 0;\n ssize_t read;\n\n int current_line = 0;\n while((read = getline(&line, &len, file)) != -1) {\n current_line++;\n if(current_line == n) {\n fclose(file);\n return line;\n }\n }\n\n // If we reach here, then the file has less than n lines\n fclose(file);\n free(line);\n return NULL;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Fs\";\nimport \"Srl/String\";\n\nuse Srl;\n\n\nfunc read_nth_line(file_path: ref[String], n: Int): String {\n def file: ptr[Fs.File] = Fs.openFile(file_path.buf, \"r\");\n\n def i: Int;\n def temp: Char = ' ';\n for i = 0 , i < n - 1 , i++ {\n temp = ' ';\n while temp != '\\n' {\n Fs.read(temp~ptr, 1, 1, file);\n }\n }\n\n def nth_line: String;\n temp = ' ';\n while temp != '\\n' {\n Fs.read(temp~ptr, 1, 1, file);\n nth_line.append(temp);\n }\n\n return nth_line;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction dot_product(v1, v2) {\n let result = 0;\n for (let i = 0; i < v1.length; i++) {\n result += v1[i] * v2[i];\n }\n return result;\n}\n"}, {"role": "assistant", "content": "Calculate the dot product of two given vectors each represented by an array and return the result"}]}
{"messages": [{"role": "user", "content": "Using js, rotate the given array counterclockwise and return the result"}, {"role": "assistant", "content": "function rotate(a) {\n const n = a.length;\n\n let first_element = a[0];\n\n for (let i = 0; i < n - 1; i++) {\n a[i] = a[i + 1];\n }\n\n a[n - 1] = first_element;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة اجتزئ(س: سند[نـص]، بداية: صـحيح، نهاية: صـحيح): نـص {\n\tعرف نتيجة: نـص = \"\"؛\n\n\tعرف دليل: صـحيح؛\n\tلكل دليل = بداية ، دليل <= نهاية ، دليل++ {\n\t\tنتيجة.ألحق(س(دليل))؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "#include <stdlib.h>\n\nchar* slice_string(char* str, int start, int end) {\n int len = end - start + 1;\n char* result = (char*)malloc(sizeof(char) * (len + 1));\n int i;\n\n for(i = start; i <= end; i++) {\n result[i-start] = str[i];\n }\n result[i-start] = '\\0';\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Array\";\nimport \"Srl/Console\";\n\nuse Srl;\n\nfunc dfs(node: Int, visited: ref[Array[Bool]], graph: ref[Array[Array[Int]]]) {\n visited(node) = true;\n Console.print(\"%d \", node);\n\n def i: Int;\n for i = 0 , i < graph(node).getLength(), i++ {\n def childNode: Int = graph(node)(i);\n if !visited(childNode) {\n dfs(childNode, visited, graph);\n }\n }\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/طـرفية\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nدالة دفس(عقدة: صـحيح، مزارة: سند[مـصفوفة[ثـنائي]]، بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]) {\n\tمزارة(عقدة) = صح؛\n\tطـرفية.اطبع(\"%d \"، عقدة)؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان(عقدة).هات_الطول() ، دليل++ {\n\t\tعرف عقدة_ابن: صـحيح = بيان(عقدة)(دليل)؛\n\t\tإذا !مزارة(عقدة_ابن) {\n\t\t\tدفس(عقدة_ابن، مزارة، بيان)؛\n\t\t}\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc find_diff_index(a1: ref[Array[Int]], a2: ref[Array[Int]]): Int {\n def i: Int;\n for i = 0 , i < a1.getLength() , i++ {\n if a1(i) != a2(i) {\n return i;\n }\n }\n return -1;\n}\n"}, {"role": "assistant", "content": "function findDiffIndex(arr1, arr2) {\n for(let i = 0; i < arr1.length; i++) {\n if(arr1[i] !== arr2[i]) {\n return i;\n }\n }\n return -1; // return -1 if no difference is found\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\nvoid erase(int a[], int n, int pos) {\n // Shift elements to left\n for (int i = pos; i < n - 1; i++)\n a[i] = a[i + 1];\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة أزل(م: سند[مـصفوفة[صـحيح]]، موقع: صـحيح) {\n\tعرف حجم: صـحيح = م.هات_الطول()؛\n\n\tعرف دليل: صـحيح؛\n\tلكل دليل = موقع ، دليل < حجم - 1 ، دليل++ {\n\t\tم(دليل) = م(دليل + 1)؛\n\t}\n\tم.أزل(حجم - 1)؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\n#include <stdlib.h>\n\nchar* slice_string(char* str, int start, int end) {\n int len = end - start + 1;\n char* result = (char*)malloc(sizeof(char) * (len + 1));\n int i;\n\n for(i = start; i <= end; i++) {\n result[i-start] = str[i];\n }\n result[i-start] = '\\0';\n\n return result;\n}\n"}, {"role": "assistant", "content": "import \"Srl/String\";\n\nuse Srl;\n\nfunc slice(s: ref[String], start: Int, end: Int): String {\n def result: String = \"\";\n\n def i: Int;\n for i = start , i <= end , i++ {\n result.append(s(i));\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة احشر(م: سند[مـصفوفة[صـحيح]]، موقع: صـحيح، قيمة: صـحيح) {\n\tعرف حجم: صـحيح = م.هات_الطول()؛\n\tم.أضف(0)؛ // لزيادة الحجم بمقدار 1\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = حجم ، دليل > موقع ، دليل-- {\n\t\tم(دليل) = م(دليل - 1)؛\n\t}\n\t\n\tم(موقع) = قيمة؛\n}\n"}, {"role": "assistant", "content": "function insert(a, n, pos, x) {\n // Shift elements to right\n for (let i = n; i > pos; i--)\n a[i] = a[i - 1];\n\n // Insert x at pos\n a[pos] = x;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction reverseArray(a) {\n let start = 0;\n let end = a.length - 1;\n\n while (start < end) {\n let temp = a[start];\n a[start] = a[end];\n a[end] = temp;\n\n start++;\n end--;\n }\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\n\nfunc invertArray(a: ref[Array[Int]]) {\n def start: Int = 0;\n def end: Int = a.getLength() - 1;\n\n while start < end {\n def temp: Int = a(start);\n a(start) = a(end);\n a(end) = temp;\n start++;\n end--;\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, check if a given string contains a given char"}, {"role": "assistant", "content": "#include <stdbool.h>\n\nbool char_exists(char s[], int n, char c) {\n for (int i = 0; i < n; i++) {\n if (s[i] == c) {\n return true;\n }\n }\n return false;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\n#include <stdlib.h>\n\n// Function to find the intersection point of two lines\ndouble* findIntersection(double a1, double b1, double c1, double a2, double b2, double c2) {\n // Check if the lines are parallel\n if(a1*b2 - a2*b1 == 0) {\n return NULL;\n }\n\n double* result = (double*)malloc(2 * sizeof(double));\n result[0] = (b1*c2 - b2*c1) / (a1*b2 - a2*b1);\n result[1] = (a2*c1 - a1*c2) / (a1*b2 - a2*b1);\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جد_التقاطع(أ1: عـائم[64]، ب1: عـائم[64]، ج1: عـائم[64]، أ2: عـائم[64]، ب2: عـائم[64]، ج2: عـائم[64]): مـصفوفة[عـائم[64]] {\n\tعرف نتيجة: مـصفوفة[عـائم[64]]؛\n\tإذا أ1 * ب2 - أ2 * ب1 == 0 {\n\t\tارجع نتيجة؛\n\t}\n\t\n\tنتيجة.أضف((ب1*ج2 - ب2*ج1) / (أ1 * ب2 - أ2 * ب1))؛\n\tنتيجة.أضف((أ2*ج1 - أ1*ج2) / (أ1 * ب2 - أ2 * ب1))؛\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/طـرفية\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nدالة دفس(عقدة: صـحيح، مزارة: سند[مـصفوفة[ثـنائي]]، بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]) {\n\tمزارة(عقدة) = صح؛\n\tطـرفية.اطبع(\"%d \"، عقدة)؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان(عقدة).هات_الطول() ، دليل++ {\n\t\tعرف عقدة_ابن: صـحيح = بيان(عقدة)(دليل)؛\n\t\tإذا !مزارة(عقدة_ابن) {\n\t\t\tدفس(عقدة_ابن، مزارة، بيان)؛\n\t\t}\n\t}\n}\n"}, {"role": "assistant", "content": "void dfs(int node, int visited[], int G[][N]) {\n visited[node] = 1;\n printf(\"%d \", node);\n\n for(int i = 0; i < N; i++) {\n if(G[node][i] == 1 && visited[i] == 0) {\n dfs(i, visited, G);\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/نـص\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة اختصر(م: سند[مـصفوفة[نـص]]، د: مغلفة(قيمة_سابقة: سند[نـص]، قيمة_حالية: سند[نـص])): نـص {\n\tعرف نتيجة: نـص = \"\"؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tد(نتيجة، م(دليل))؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "void reduce(char a[4][10], char result[50], void (*f)(char*, char*)) {\n for(int i = 0; i < 4; i++) {\n f(result, a[i]);\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Array\";\nimport \"closure\";\n\n\nuse Srl;\n\n\nfunc check_all(a: ref[Array[Int]], f: closure (num: Int): Bool): Bool {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if !f(a(i)) {\n return false;\n }\n }\n\n return true;\n}\n"}, {"role": "assistant", "content": "#include <stdbool.h>\n\n// Criteria function that checks if a number is positive\nbool criteria(int num) {\n return num > 0;\n}\n\n// Function to check all elements in an array\nbool check_all(int arr[], int size) {\n for(int i = 0; i < size; i++) {\n if(!criteria(arr[i])) {\n return false;\n }\n }\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction trim(str) {\n let start = 0, end = str.length - 1;\n\n // Trim leading white spaces\n while(str[start] === ' ' || str[start] === '\\t' || str[start] === '\\n') start++;\n\n // Trim trailing white spaces\n while(str[end] === ' ' || str[end] === '\\t' || str[end] === '\\n') end--;\n\n // Return the trimmed string\n return str.substring(start, end + 1);\n}\n"}, {"role": "assistant", "content": "import \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc trim(s: ref[String]) {\n def start: Int = 0;\n def end: Int = s.getLength() - 1;\n\n while (s(start) == ' ' || s(start) == '\\t' || s(start) == '\\n') {\n start++;\n }\n\n while (s(end) == ' ' || s(end) == '\\t' || s(end) == '\\n') {\n end--;\n }\n\n s = s.slice(start, end - start + 1);\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\nvoid invertArray(int a[], int n) {\n int start = 0;\n int end = n - 1;\n while (start < end) {\n int temp = a[start];\n a[start] = a[end];\n a[end] = temp;\n start++;\n end--;\n }\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\n\nfunc invertArray(a: ref[Array[Int]]) {\n def start: Int = 0;\n def end: Int = a.getLength() - 1;\n\n while start < end {\n def temp: Int = a(start);\n a(start) = a(end);\n a(end) = temp;\n start++;\n end--;\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, calculate and return the mean of the given array"}, {"role": "assistant", "content": "double calculateMean(int arr[], int n) {\n int sum = 0;\n for (int i = 0; i < n; i++) {\n sum += arr[i];\n }\n return (double)sum / n;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, احسب جداء مصفوفة معطاة ممثلة على شكل مصفوفة ثنائية الأبعاد، و شعاع معطى ممثل على شكل مصفوفة و أعد النتيجة"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nعرف مـصفوفة_ثنائية: لقب مـصفوفة[مـصفوفة[عـائم[64]]]؛\nعرف شـعاع: لقب مـصفوفة[عـائم[64]]؛\n\n\nدالة جداء(م: سند[مـصفوفة_ثنائية]، ش: سند[شـعاع]): شـعاع {\n\tعرف أسطر: صـحيح = م.هات_الطول()؛\n\tعرف أعمدة: صـحيح = م(0).هات_الطول()؛\n\n\tعرف نتيجة: شـعاع؛\n\t\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < أسطر ، دليل1++ {\n\t\tنتيجة.أضف(0)؛\n\t\tلكل دليل2 = 0 ، دليل2 < أعمدة ، دليل2++ {\n\t\t\t\tنتيجة(دليل1) += م(دليل1)(دليل2) * ش(دليل2)؛\n\t\t}\n\t}\n\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, جد و أرجع أكبر عدد في المصفوفة المعطاة م"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة أكبر_عنصر(م: سند[مـصفوفة[صـحيح]]): صـحيح {\n\n\tعرف نتيجة: صـحيح = م(0)؛\n\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 1 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا م(دليل) > نتيجة {\n\t\t\tنتيجة = م(دليل)؛\n\t\t}\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة شذب(س: سند[نـص]) {\n\tعرف بداية: صـحيح = 0؛\n\tعرف نهاية: صـحيح = س.هات_الطول() - 1؛\n\t\n\tبينما (س(بداية) == ' ' || س(بداية) == '\\t' || س(بداية) == '\\n') {\n\t\tبداية++؛\n\t}\n\t\n\tبينما (س(نهاية) == ' ' || س(نهاية) == '\\t' || س(نهاية) == '\\n') {\n\t\tنهاية--؛\n\t}\n\t\n\tس = س.اجتزئ(بداية، نهاية - بداية + 1)؛\n}\n"}, {"role": "assistant", "content": "#include <string.h>\n\nvoid trim(char *str) {\n int start = 0, end = strlen(str) - 1;\n\n // Trim leading white spaces\n while(str[start] == ' ' || str[start] == '\\t' || str[start] == '\\n') start++;\n\n // Trim trailing white spaces\n while(str[end] == ' ' || str[end] == '\\t' || str[end] == '\\n') end--;\n\n // Shift characters\n memmove(str, str + start, end - start + 1);\n\n // Null terminate the string\n str[end - start + 1] = '\\0';\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc find_most_frequent(a: ref[Array[Int]]): Int {\n def max_count: Int = 0;\n def res: Int = -1;\n\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n def count: Int = 1;\n \n def j: Int;\n for j = i + 1 , j < a.getLength() , j++ {\n if a(j) == a(i) {\n count++;\n }\n }\n\n if count > max_count {\n max_count = count;\n res = a(i);\n }\n }\n\n return res;\n}\n"}, {"role": "assistant", "content": "int find_most_frequent(int arr[], int n) {\n int max_count = 0, res = -1;\n\n for (int i = 0; i < n; i++) {\n int count = 1;\n for (int j = i + 1; j < n; j++)\n if (arr[i] == arr[j])\n count++;\n if (count > max_count) {\n max_count = count;\n res = arr[i];\n }\n }\n\n return res;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nuse Srl;\n\nfunc isPrime(num: Int): Bool {\n if num <= 1 {\n return false;\n }\n\n def i: Int;\n for i = 2 , i * i <= num , i++ {\n if num % i == 0 {\n return false;\n }\n }\n \n return true;\n}\n"}, {"role": "assistant", "content": "#include <stdbool.h>\n\nbool isPrime(int num) {\n if (num <= 1) {\n return false;\n }\n for (int i = 2; i * i <= num; i++) {\n if (num % i == 0) {\n return false;\n }\n }\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة اعكس_نص(س: نـص): نـص {\n\tعرف طول: صـحيح = س.هات_الطول()؛\n\tعرف نتيجة: نـص = \"\"؛\n\n\tعرف دليل: صـحيح؛\n\tلكل دليل = طول - 1 ، دليل >= 0 ، دليل-- {\n\t\tنتيجة.ألحق(س(دليل))؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/String\";\n\nuse Srl;\n\n\nfunction invertString(s) {\n def size: Int = s.getLength();\n def result: String = \"\";\n\n def i: Int;\n for i = size - 1 , i >= 0 , i-- {\n result += s(i);\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/String\";\n\nuse Srl;\n\nfunc slice(s: ref[String], start: Int, end: Int): String {\n def result: String = \"\";\n\n def i: Int;\n for i = start , i <= end , i++ {\n result.append(s(i));\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "#include <stdlib.h>\n\nchar* slice_string(char* str, int start, int end) {\n int len = end - start + 1;\n char* result = (char*)malloc(sizeof(char) * (len + 1));\n int i;\n\n for(i = start; i <= end; i++) {\n result[i-start] = str[i];\n }\n result[i-start] = '\\0';\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\nint rfind(int a[], int n, int val) {\n for (int i = n - 1; i != 0; i--) {\n if (a[i] == val) {\n return i;\n }\n }\n return -1;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc rfind(a: ref[Array[Int]], val: Int): Int {\n def i: Int;\n for i = a.getLength() - 1 , i != 0 , i-- {\n if a(i) == val {\n return i;\n }\n }\n return -1;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\n#include <math.h>\n\n\ndouble vectorNorm(double* vector, int size) {\n double sum = 0.0;\n for (int i = 0; i < size; i++) {\n sum += vector[i] * vector[i];\n }\n return sqrt(sum);\n}\n"}, {"role": "assistant", "content": "Calculate the norm of a given vector which is represented by an array and return the result"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Fs\";\nimport \"Srl/String\";\n\nuse Srl;\n\n\nfunc read_file(file_path: ref[String]): String {\n def file: ptr[Fs.File] = Fs.openFile(file_path.buf, \"r\");\n def content: String;\n\n Fs.seek(file, 0, Fs.Seek.END);\n def size: Int = Fs.tell(file);\n Fs.seek(file, 0, Fs.Seek.SET);\n \n\n def i: Int;\n for i = 0 , i < size , i++ {\n def temp: Char;\n Fs.read(temp~ptr, 1, 1, file);\n content.append(temp);\n }\n\n return content;\n}\n"}, {"role": "assistant", "content": "#include <stdio.h>\n#include <stdlib.h>\n\n// Function to read the content of a file into a string\nchar* read_file(const char* file_path) {\n FILE* file = fopen(file_path, \"r\");\n if(file == NULL) {\n printf(\"Could not open file %s\\n\", file_path);\n return NULL;\n }\n\n // Get the size of the file\n fseek(file, 0, SEEK_END);\n long file_size = ftell(file);\n fseek(file, 0, SEEK_SET);\n\n // Allocate memory for the string\n char* str = malloc(file_size + 1);\n if(str == NULL) {\n printf(\"Could not allocate memory for the string\\n\");\n fclose(file);\n return NULL;\n }\n\n // Read the file into the string one character at a time\n for(long i = 0; i < file_size; i++) {\n fread(&str[i], sizeof(char), 1, file);\n }\n\n // Null-terminate the string\n str[file_size] = '\\0';\n\n fclose(file);\n return str;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction isPrime(num) {\n if (num <= 1) {\n return false;\n }\n for (let i = 2; i * i <= num; i++) {\n if (num % i === 0) {\n return false;\n }\n }\n return true;\n}\n"}, {"role": "assistant", "content": "use Srl;\n\nfunc isPrime(num: Int): Bool {\n if num <= 1 {\n return false;\n }\n\n def i: Int;\n for i = 2 , i * i <= num , i++ {\n if num % i == 0 {\n return false;\n }\n }\n \n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, Check if a given undirected graph is tree"}, {"role": "assistant", "content": "let visited = [];\n\nfunction DFS(v, parent, adjList) {\n visited[v] = true;\n for(let i = 0; i < adjList[v].length; i++) {\n if(!visited[adjList[v][i]]) {\n if(DFS(adjList[v][i], v, adjList)) {\n return true;\n }\n } else if(adjList[v][i] != parent) {\n return true;\n }\n }\n return false;\n}\n\nfunction isTree(adjList) {\n visited = new Array(adjList.length).fill(false);\n if(DFS(0, -1, adjList)) {\n return false;\n }\n for(let i = 0; i < adjList.length; i++) {\n if(!visited[i]) {\n return false;\n }\n }\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc slice(a: ref[Array[Int]], start: Int, end: Int, result: ref[Array[Int]]) {\n def i: Int;\n for i = start , i <= end , i++ {\n result.add(a(i));\n }\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة اجتزئ(م: سند[مـصفوفة[صـحيح]]، بداية: صـحيح، نهاية: صـحيح، نتيجة: سند[مـصفوفة[صـحيح]]) {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = بداية ، دليل <= نهاية ، دليل++ {\n\t\tنتيجة.أضف(م(دليل))؛\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جد_بداية_الاختلاف(م1: سند[مـصفوفة[صـحيح]]، م2: سند[مـصفوفة[صـحيح]]): صـحيح {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م1.هات_الطول() ، دليل++ {\n\t\tإذا م1(دليل) != م2(دليل) {\n\t\t\tارجع دليل؛\n\t\t}\n\t}\n\tارجع -1؛\n}\n"}, {"role": "assistant", "content": "function findDiffIndex(arr1, arr2) {\n for(let i = 0; i < arr1.length; i++) {\n if(arr1[i] !== arr2[i]) {\n return i;\n }\n }\n return -1; // return -1 if no difference is found\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction accumulate(a, f) {\n let result = [];\n result[0] = a[0];\n for(let i = 1; i < a.length; i++) {\n result[i] = f(result[i-1], a[i]);\n }\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة راكم(م: سند[مـصفوفة[صـحيح]]، د: مغلفة(قيمة_سابقة: صـحيح، قيمة_حالية: صـحيح): صـحيح): مـصفوفة[صـحيح] {\n\tعرف طول: صـحيح = م.هات_الطول()؛\n\tعرف نتيجة: مـصفوفة[صـحيح]؛\n\t\n\tعرف دليل: صـحيح؛\n\tنتيجة.أضف(م(0))؛\n\tلكل دليل = 1 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tنتيجة.أضف(د(نتيجة(دليل - 1)، م(دليل)))؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction rotate(a) {\n const n = a.length;\n\n let first_element = a[0];\n\n for (let i = 0; i < n - 1; i++) {\n a[i] = a[i + 1];\n }\n\n a[n - 1] = first_element;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc rotate(a: ref[Array[Int]]) {\n def size: Int = a.getLength();\n\n def first_element: Int = a(0);\n\n def i: Int;\n for i = 0 , i < size - 1 , i++ {\n a(i) = a(i + 1);\n }\n\n a(size - 1) = first_element;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Fs\";\nimport \"Srl/String\";\n\nuse Srl;\n\n\nfunc appendLogEntry(file_path: ref[String], logEntry: ref[String]) {\n def file: ptr[Fs.File] = Fs.openFile(file_path.buf, \"a\");\n\n Fs.write(logEntry.buf, 1, logEntry.getLength(), file);\n Fs.write(\"\\n\", 1, 1, file);\n Fs.closeFile(file);\n}\n"}, {"role": "assistant", "content": "Append a given log entry to a file given its path"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\n#include <stdbool.h>\n\n// Criteria function that checks if a number is positive\nbool criteria(int num) {\n return num > 0;\n}\n\n// Function to check all elements in an array\nbool check_all(int arr[], int size) {\n for(int i = 0; i < size; i++) {\n if(!criteria(arr[i])) {\n return false;\n }\n }\n return true;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة تفحص_الكل(م: سند[مـصفوفة[صـحيح]]، د: مغلفة(رقم: صـحيح): ثـنائي): ثـنائي {\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا !د(م(دليل)) {\n\t\t\tارجع خطأ؛\n\t\t}\n\t}\n\t\n\tارجع صح؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction max(a) {\n let result = a[0];\n for (let i = 1 ; i < a.length ; i++) {\n if (result < a[i]) {\n result = a[i];\n }\n }\n return result;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\n\nfunc max(a: ref[Array[Int]]): Int {\n def result: Int = a(0);\n\n def i: Int;\n for i = 1 , i < a.getLength() , i++ {\n if a(i) > result {\n result = a(i);\n }\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Fs\";\nimport \"Srl/String\";\nimport \"Srl/Array\";\n\nuse Srl;\n\n\nfunc readFileToArray(file_path: ref[String]): Array[String] {\n def file: ptr[Fs.File] = Fs.openFile(file_path.buf, \"r\");\n def content: Array[String];\n\n Fs.seek(file, 0, Fs.Seek.END);\n def size: Int = Fs.tell(file);\n Fs.seek(file, 0, Fs.Seek.SET);\n \n content.add(String());\n def i: Int;\n def j: Int = 0;\n for i = 0 , i < size , i++ {\n def temp: Char;\n Fs.read(temp~ptr, 1, 1, file);\n\n if temp == '\\n' {\n content.add(String());\n j++;\n }\n else {\n content(j).append(temp);\n }\n }\n\n return content;\n}\n"}, {"role": "assistant", "content": "#include <stdio.h>\n#include <stdlib.h>\n\n#define MAX_LINE_LENGTH 1024\n#define MAX_LINES 1000\n\nvoid readFileToArray(char *filename, char lines[MAX_LINES][MAX_LINE_LENGTH]) {\n FILE *file = fopen(filename, \"r\");\n if(file == NULL) {\n printf(\"Cannot open file.\\n\");\n exit(1);\n }\n\n int i = 0, j = 0;\n while(!feof(file) && i < MAX_LINES) {\n fread(&lines[i][j], sizeof(char), 1, file);\n if(lines[i][j] == '\\n' || lines[i][j] == '\\0') {\n lines[i][j] = '\\0'; // end of string\n i++; // next line\n j = 0; // reset character index\n } else {\n j++;\n }\n }\n\n fclose(file);\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, Calculate the product of a given matrix, represented as 2D array, and a given vector, represented as an array, and return the result"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\ndef Matrix: alias Array[Array[Float[64]]];\ndef Vector: alias Array[Float[64]];\n\n\nfunc multiply(m: ref[Matrix], v: ref[Vector]): Vector {\n def rows: Int = m.getLength();\n def cols: Int = m(0).getLength();\n \n def result: Vector;\n\n def i: Int;\n def j: Int;\n for i = 0 , i < rows , i++ {\n result.add(0);\n for j = 0 , j < cols , j++ {\n result(i) += m(i)(j) * v(j);\n }\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, Find and return the sum of the given array `a`"}, {"role": "assistant", "content": "int sum(int a[], int n) {\n int result = 0;\n for (int i = 0; i < n; i++) {\n result += a[i];\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Array\";\nimport \"Srl/Math\";\n\nuse Srl;\n\n\nfunc vectorNorm(vector: ref[Array[Float[64]]]): Float[64] {\n def sum: Float[64] = 0;\n\n def i: Int;\n for i = 0 , i < vector.getLength() , i++ {\n sum += vector(i) * vector(i);\n }\n\n return Math.sqrt(sum);\n}\n"}, {"role": "assistant", "content": "function vectorNorm(vector) {\n let sum = 0.0;\n for (let i = 0; i < vector.length; i++) {\n sum += vector[i] * vector[i];\n }\n return Math.sqrt(sum);\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\nint findMax(int* a, int n) {\n int max = a[0];\n for(int i = 1; i < n; i++) {\n if(a[i] > max) {\n max = a[i];\n }\n }\n return max;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة أكبر_عنصر(م: سند[مـصفوفة[صـحيح]]): صـحيح {\n\n\tعرف نتيجة: صـحيح = م(0)؛\n\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 1 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا م(دليل) > نتيجة {\n\t\t\tنتيجة = م(دليل)؛\n\t\t}\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc trim(s: ref[String]) {\n def start: Int = 0;\n def end: Int = s.getLength() - 1;\n\n while (s(start) == ' ' || s(start) == '\\t' || s(start) == '\\n') {\n start++;\n }\n\n while (s(end) == ' ' || s(end) == '\\t' || s(end) == '\\n') {\n end--;\n }\n\n s = s.slice(start, end - start + 1);\n}\n"}, {"role": "assistant", "content": "Remove any whitespace character from both ends of a given string"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction reduce(a, f) {\n let result = \"\";\n\n for (let i = 0; i < a.length; i++) {\n result = f(result, a[i]);\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "reduce the given array `a` using the given function `f` and return the result"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاستخدم مـتم؛\n\nدالة هل_أولي (عدد: صـحيح): ثـنائي {\n\tإذا عدد <= 1 {\n\t\tارجع خطأ؛\n\t}\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 2 ، دليل * دليل <= عدد ، دليل++ {\n\t\tإذا عدد % دليل == 0 {\n\t\t\tارجع خطأ؛\n\t\t}\n\t}\n\t\n\tارجع صح؛\n}\n"}, {"role": "assistant", "content": "use Srl;\n\nfunc isPrime(num: Int): Bool {\n if num <= 1 {\n return false;\n }\n\n def i: Int;\n for i = 2 , i * i <= num , i++ {\n if num % i == 0 {\n return false;\n }\n }\n \n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\nint starts_with(const char *str, const char *prefix) {\n while(*prefix) {\n if (!(*str))\n return 0;\n if(*prefix++ != *str++)\n return 0;\n }\n return 1;\n}\n"}, {"role": "assistant", "content": "import \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc starts_with(s: ref[String], prefix: ref[String]): Bool {\n\tif s.getLength() < prefix.getLength() {\n\t\treturn false;\n\t}\n\n def i: Int;\n\tfor i = 0 , i < prefix.getLength() , i++ {\n\t\tif (prefix(i) != s(i)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة دور(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف حجم: صـحيح = م.هات_الطول()؛\n\t\n\tعرف أول_عنصر: صـحيح = م(0)؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < حجم - 1 ، دليل++ {\n\t\tم(دليل) = م(دليل + 1)؛\n\t}\n\t\n\tم(حجم - 1) = أول_عنصر؛\n}\n"}, {"role": "assistant", "content": "void rotate(int a[], int n) {\n int first_element = a[0];\n\n for (int i = 0 ; i < n - 1; i++) {\n a[i] = a[i + 1];\n }\n\n a[n - 1] = first_element;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, احسب جداء مصفوفتين ثنائيتي البعد معطاتان و ممثلتان بمصفوفة ثنائية البعد و ارجع النتيجة"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nعرف مـصفوفة_ثنائية: لقب مـصفوفة[مـصفوفة[عـائم[64]]]؛\n\n\nدالة جداء(م1: سند[مـصفوفة_ثنائية]، م2: سند[مـصفوفة_ثنائية]): مـصفوفة_ثنائية {\n\tعرف أسطر_م1: صـحيح = م1.هات_الطول()؛\n\tعرف أسطر_م2: صـحيح = م2.هات_الطول()؛\n\tعرف أعمدة_م1: صـحيح = م1(0).هات_الطول()؛\n\tعرف أعمدة_م2: صـحيح = م2(0).هات_الطول()؛\n\n\tعرف نتيجة: مـصفوفة_ثنائية؛\n\t\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tعرف دليل3: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < أسطر_م1 ، دليل1++ {\n\t\tعرف سطر: مـصفوفة[عـائم[64]]؛\n\t\tلكل دليل2 = 0 ، دليل2 < أعمدة_م2 ، دليل2++ {\n\t\t\tسطر.أضف(0)؛\n\t\t\tلكل دليل3 = 0 ، دليل3 < أعمدة_م1 ، دليل3++ {\n\t\t\t\tسطر(دليل2) += م1(دليل1)(دليل3) * م2(دليل3)(دليل2)؛\n\t\t\t}\n\t\t}\n\t\tنتيجة.أضف(سطر)؛\n\t}\n\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction sum(a, start, end) {\n let result = 0;\n\n for (let i = start; i < end; i++) {\n result += a[i];\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جمع(م: سند[مـصفوفة[صـحيح]]، بداية: صـحيح، نهاية: صـحيح): صـحيح {\n\tعرف نتيجة: صـحيح = 0؛\n\n\tعرف دليل: صـحيح؛\n\n\tلكل دليل = بداية ، دليل < نهاية ، دليل++ {\n نتيجة += م(دليل)؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/Array\";\n\nuse Srl;\n\n\nfunc outer_product(v1: ref[Array[Float[64]]], v2: ref[Array[Float[64]]]): Array[Array[Float[64]]] {\n def result: Array[Array[Float[64]]];\n\n def i: Int;\n def j: Int;\n for i = 0 , i < v1.getLength() , i++ {\n def row: Array[Float[64]];\n for j = 0 , j < v2.getLength() , j++ {\n row.add(v1(i)*v2(j));\n }\n result.add(row);\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "#include <stdlib.h>\n\ndouble** outer_product(double v1[], double v2[], int n) {\n double** result = (double**)malloc(n * sizeof(double*));\n for (int i = 0; i < n; i++) {\n result[i] = (double*)malloc(n * sizeof(double));\n for (int j = 0; j < n; j++) {\n result[i][j] = v1[i] * v2[j];\n }\n }\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, apply the given function `f` on each element of the given array `a` and return the result"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"closure\";\n\nuse Srl;\n\n\nfunc foreach(a: ref[Array[Int]], f: closure(element: Int): Int) {\n def i: Int;\n \n for i = 0 , i < a.getLength() , i++ {\n a(i) = f(a(i));\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة تفحص_الكل(م: سند[مـصفوفة[صـحيح]]، د: مغلفة(رقم: صـحيح): ثـنائي): ثـنائي {\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا !د(م(دليل)) {\n\t\t\tارجع خطأ؛\n\t\t}\n\t}\n\t\n\tارجع صح؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"closure\";\n\n\nuse Srl;\n\n\nfunc check_all(a: ref[Array[Int]], f: closure (num: Int): Bool): Bool {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if !f(a(i)) {\n return false;\n }\n }\n\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة فلويد_وارشال(بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]، مسافة: سند[مـصفوفة[مـصفوفة[صـحيح]]]) {\n\tعرف حجم: صـحيح = بيان.هات_الطول()؛\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tعرف دليل3: صـحيح؛\n\n\t\n\tلكل دليل1 = 0 ، دليل1 < حجم ، دليل1++ {\n\t\tمسافة.أضف(بيان(دليل1))؛\n\t}\n\t\n\tلكل دليل3 = 0 ، دليل3 < حجم ، دليل3++ {\n\t\tلكل دليل1 = 0 ، دليل1 < حجم ، دليل1++ {\n\t\t\tلكل دليل2 = 0 ، دليل2 < حجم ، دليل2++ {\n\t\t\t\tإذا مسافة(دليل1)(دليل3) + مسافة(دليل3)(دليل2) < مسافة(دليل1)(دليل2) {\n\t\t\t\t\tمسافة(دليل1)(دليل2) = مسافة(دليل1)(دليل3) + مسافة(دليل3)(دليل2)؛\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\nfunc floydWarshall(graph: ref[Array[Array[Int]]], dist: ref[Array[Array[Int]]]) {\n def n: Int = graph.getLength();\n def i: Int;\n def j: Int;\n def k: Int;\n\n for i = 0 , i < n , i++ {\n dist.add(graph(i));\n }\n\n for k = 0 , k < n , k++ {\n for i = 0 , i < n , i++ {\n for j = 0 , j < n , j++ {\n if dist(i)(k) + dist(k)(j) < dist(i)(j) {\n dist(i)(j) = dist(i)(k) + dist(k)(j);\n }\n }\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة تفحص_أي(م: سند[مـصفوفة[صـحيح]]، د: مغلفة(رقم: صـحيح): ثـنائي): ثـنائي {\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا د(م(دليل)) {\n\t\t\tارجع صح؛\n\t\t}\n\t}\n\n\tارجع خطأ؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"closure\";\n\n\nuse Srl;\n\n\nfunc check_any(a: ref[Array[Int]], f: closure (num: Int): Bool): Bool {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if f(a(i)) {\n return true;\n }\n }\n\n return false;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, Clip the values of a given array within a given range"}, {"role": "assistant", "content": "function clip(arr, lower, upper) {\n for(let i = 0; i < arr.length; i++) {\n if(arr[i] < lower) {\n arr[i] = lower;\n } else if(arr[i] > upper) {\n arr[i] = upper;\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/ريـاضيات\"؛\n\nاستخدم مـتم؛\n\n\nصنف نـقطة {\n\tعرف س: عـائم؛\n\tعرف ص: عـائم؛\n}\n\nدالة مساحة_مثلث(ن1: نـقطة، ن2: نـقطة، ن3: نـقطة): عـائم {\n\tارجع ريـاضيات.مطلق(ن1.س*(ن2.ص - ن3.ص) + ن2.س*(ن3.ص - ن1.ص) + ن3.س*(ن1.ص - ن2.ص)) / 2.0؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/Math\";\n\nuse Srl;\n\nclass Point {\n def x : Float;\n def y : Float;\n};\n\nfunc triangleArea(p1: Point, p2: Point, p3: Point): Float {\n return Math.abs(p1.x*(p2.y-p3.y) + p2.x*(p3.y-p1.y) + p3.x*(p1.y-p2.y)) / 2.0;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, Check if a given undirected graph is tree"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\nfunc dfs(node: Int, parentNode: Int, visited: ref[Array[Bool]], graph: ref[Array[Array[Int]]]): Bool {\n visited(node) = true;\n\n def i: Int;\n for i = 0 , i < graph(node).getLength(), i++ {\n def childNode: Int = graph(node)(i);\n if !visited(childNode) {\n if dfs(childNode, node, visited, graph) {\n return true;\n }\n }\n else if childNode != parentNode {\n return true;\n }\n }\n return false;\n}\n\n\nfunc isTree(graph: ref[Array[Array[Int]]]): Bool {\n def visited: Array[Bool];\n def i: Int;\n for i = 0 , i < graph.getLength() , i++ {\n visited.add(false);\n }\n\n if dfs(0, -1, visited, graph) {\n return false;\n }\n\n for i = 0 , i < graph.getLength() , i++ {\n if !visited(i) {\n return false;\n }\n }\n\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, جزئ نص معطى إلى لائحة من النصوص بناء على محرف معطى"}, {"role": "assistant", "content": "اشمل \"مـتم/نـص\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جزئ(س: سند[نـص]، رمز: مـحرف): مـصفوفة[نـص] {\n\tعرف نتيجة: مـصفوفة[نـص]؛\n\t\n\tعرف مؤقت: نـص؛\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) != رمز {\n\t\t\tمؤقت.ألحق(س(دليل))؛\n\t\t}\n\t\tوإلا {\n\t\t\tنتيجة.أضف(مؤقت)؛\n\t\t\tمؤقت = \"\"؛\n\t\t}\n\t}\n\tنتيجة.أضف(مؤقت)؛\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Array\";\nimport \"Srl/Math\";\n\nuse Srl;\n\n\nfunc vectorNorm(vector: ref[Array[Float[64]]]): Float[64] {\n def sum: Float[64] = 0;\n\n def i: Int;\n for i = 0 , i < vector.getLength() , i++ {\n sum += vector(i) * vector(i);\n }\n\n return Math.sqrt(sum);\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/ريـاضيات\"؛\n\nاستخدم مـتم؛\n\n\nدالة طويلة_شعاع(شعاع: سند[مـصفوفة[عـائم[64]]]): عـائم[64] {\n\tعرف مجموع: عـائم[64] = 0؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < شعاع.هات_الطول() ، دليل++ {\n\t\tمجموع += شعاع(دليل) * شعاع(دليل)؛\n\t}\n\t\n\tارجع ريـاضيات.جذر(مجموع)؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Math\";\nimport \"Srl/Array\";\n\n\n\nuse Srl;\n\nclass Point {\n def x : Float;\n def y : Float;\n};\n\nfunc calculateDistance(a: Point, b: Point): Float {\n return Math.sqrt(Math.pow(b.x - a.x, 2.0) + Math.pow(b.y - a.y, 2.0));\n}\n\nfunc findClosestPoint(givenPoint: Point, points: ref[Array[Point]]): Point {\n def minDistance: Float = calculateDistance(givenPoint, points(0));\n def closestPoint: Point = points(0);\n\n def i: Int;\n for i = 1 , i < points.getLength() , i++ {\n def distance: Float = calculateDistance(givenPoint, points(i));\n if distance < minDistance {\n minDistance = distance;\n closestPoint = points(i);\n }\n }\n\n return closestPoint;\n}\n"}, {"role": "assistant", "content": "find and return the closest point to a given point from a given set of points"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, calculate and return the area of a triangle from its points"}, {"role": "assistant", "content": "import \"Srl/Math\";\n\nuse Srl;\n\nclass Point {\n def x : Float;\n def y : Float;\n};\n\nfunc triangleArea(p1: Point, p2: Point, p3: Point): Float {\n return Math.abs(p1.x*(p2.y-p3.y) + p2.x*(p3.y-p1.y) + p3.x*(p1.y-p2.y)) / 2.0;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\n#include <stdlib.h>\n\nchar* slice_string(char* str, int start, int end) {\n int len = end - start + 1;\n char* result = (char*)malloc(sizeof(char) * (len + 1));\n int i;\n\n for(i = start; i <= end; i++) {\n result[i-start] = str[i];\n }\n result[i-start] = '\\0';\n\n return result;\n}\n"}, {"role": "assistant", "content": "Slice a given string within a given range and return the result"}]}
{"messages": [{"role": "user", "content": "Using c, calculate and return the area of a triangle from its points"}, {"role": "assistant", "content": "#include <stdlib.h>\n\ntypedef struct {\n float x;\n float y;\n} Point;\n\ndouble triangleArea(Point p1, Point p2, Point p3) {\n return abs(p1.x*(p2.y-p3.y) + p2.x*(p3.y-p1.y) + p3.x*(p1.y-p2.y)) / 2.0;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\n#include <math.h>\n\ntypedef struct {\n double x;\n double y;\n} Point;\n\ndouble calculateDistance(Point a, Point b) {\n return sqrt(pow(b.x - a.x, 2) + pow(b.y - a.y, 2));\n}\n\nPoint findClosestPoint(Point givenPoint, Point points[], int size) {\n double minDistance = calculateDistance(givenPoint, points[0]);\n Point closestPoint = points[0];\n\n for(int i = 1; i < size; i++) {\n double distance = calculateDistance(givenPoint, points[i]);\n if(distance < minDistance) {\n minDistance = distance;\n closestPoint = points[i];\n }\n }\n\n return closestPoint;\n}\n"}, {"role": "assistant", "content": "find and return the closest point to a given point from a given set of points"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nlet visited = [];\n\nfunction DFS(v, adjList) {\n visited[v] = true;\n for(let i = 0; i < adjList[v].length; i++) {\n if(!visited[adjList[v][i]]) {\n DFS(adjList[v][i], adjList);\n }\n }\n}\n\nfunction numberOfConnectedComponents(adjList) {\n let components = 0;\n for(let i = 0; i < adjList.length; i++) {\n if(!visited[i]) {\n DFS(i, adjList);\n components++;\n }\n }\n return components;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\nfunc dfs(node: Int, visited: ref[Array[Bool]], graph: ref[Array[Array[Int]]]) {\n visited(node) = true;\n\n def i: Int;\n for i = 0 , i < graph(node).getLength(), i++ {\n def childNode: Int = graph(node)(i);\n if !visited(childNode) {\n dfs(childNode, visited, graph);\n }\n }\n}\n\n\nfunc numberOfConnectedComponents(graph: ref[Array[Array[Int]]]): Int {\n def visited: Array[Bool];\n def i: Int;\n for i = 0 , i < graph.getLength() , i++ {\n visited.add(false);\n }\n\n def components: Int = 0;\n for i = 0 , i < graph.getLength() , i++ {\n if !visited(i) {\n dfs(i, visited, graph);\n components++;\n }\n }\n\n return components;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/نـم\"؛\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة اقرأ_الملف(مسار_الملف: سند[نـص]): نـص {\n\tعرف ملف: مؤشر[نـم.مـلف] = نـم.افتح_ملف(مسار_الملف، \"r\")؛\n\t\n\tنـم.انتقل(ملف، 0، نـم.انـتقال._نهاية_)؛\n\tعرف حجم: صـحيح = نـم.هات_الموقع(ملف)؛\n\tنـم.انتقل(ملف، 0، نـم.انـتقال._بداية_)؛\n\t\n\tعرف المحتوى: نـص؛\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < حجم ، دليل++ {\n\t\tعرف مؤقت: مـحرف؛\n\t\tنـم.اقرأ(مؤقت~مؤشر، 1، 1، ملف)؛\n\t\tالمحتوى.ألحق(مؤقت)؛\n\t}\n\t\n\tارجع المحتوى؛\n}\n"}, {"role": "assistant", "content": "اقرأ محتوى ملف نصي معطى مساره و ارجع النتيجة"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nuse Srl;\n\n\nfunc is_alpha(c: Char): Bool {\n return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');\n}\n"}, {"role": "assistant", "content": "#include <stdbool.h>\n\nbool is_alphabet(char c) {\n return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, جد نقطة التقاطع لخطين مستقيمين معطيين (الخط المستقيم ممثل بثلاث قيم هي أ، ب، ج كما يلي أ*س + ب*ص + ج = 0) و ارجع هذه النقطة، في حال كان المستقيمان متوازيان ارجع خالٍ أو مصفوفة فارغة"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جد_التقاطع(أ1: عـائم[64]، ب1: عـائم[64]، ج1: عـائم[64]، أ2: عـائم[64]، ب2: عـائم[64]، ج2: عـائم[64]): مـصفوفة[عـائم[64]] {\n\tعرف نتيجة: مـصفوفة[عـائم[64]]؛\n\tإذا أ1 * ب2 - أ2 * ب1 == 0 {\n\t\tارجع نتيجة؛\n\t}\n\t\n\tنتيجة.أضف((ب1*ج2 - ب2*ج1) / (أ1 * ب2 - أ2 * ب1))؛\n\tنتيجة.أضف((أ2*ج1 - أ1*ج2) / (أ1 * ب2 - أ2 * ب1))؛\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nدالة دفس(عقدة: صـحيح، مزارة: سند[مـصفوفة[ثـنائي]]، بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]) {\n\tمزارة(عقدة) = صح؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان(عقدة).هات_الطول() ، دليل++ {\n\t\tعرف عقدة_ابن: صـحيح = بيان(عقدة)(دليل)؛\n\t\tإذا !مزارة(عقدة_ابن) {\n\t\t\tدفس(عقدة_ابن، مزارة، بيان)؛\n\t\t}\n\t}\n}\n\n\nدالة عدد_المكونات_المترابطة(بيان: سند[مـصفوفة[مـصفوفة[صـحيح]]]): صـحيح {\n\tعرف مزارة: مـصفوفة[ثـنائي]؛\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < بيان.هات_الطول() ، دليل++ {\n\t\tمزارة.أضف(خطأ)؛\n\t}\n\t\n\tعرف عدد_المكونات: صـحيح = 0؛\n\tلكل دليل = 0 ، دليل < بيان.هات_الطول() ، دليل++ {\n\t\tإذا !مزارة(دليل) {\n\t\t\tدفس(دليل، مزارة، بيان)؛\n\t\t\tعدد_المكونات++؛\n\t\t}\n\t}\n\t\n\tارجع عدد_المكونات؛\n}\n"}, {"role": "assistant", "content": "#include <stdio.h>\n\n#define MAX 100\n\nint visited[MAX];\nint matrix[MAX][MAX];\n\nvoid DFS(int v, int n) {\n visited[v] = 1;\n for(int i = 0; i < n; i++) {\n if(matrix[v][i] == 1 && visited[i] == 0) {\n DFS(i, n);\n }\n }\n}\n\nint numberOfConnectedComponents(int n) {\n int components = 0;\n for(int i = 0; i < n; i++) {\n if(visited[i] == 0) {\n DFS(i, n);\n components++;\n }\n }\n return components;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nconst V = 4;\n\nfunction floydWarshall(graph) {\n let dist = [];\n for (let i = 0; i < V; i++) {\n dist[i] = [];\n for (let j = 0; j < V; j++) {\n dist[i][j] = graph[i][j];\n }\n }\n\n for (let k = 0; k < V; k++) {\n for (let i = 0; i < V; i++) {\n for (let j = 0; j < V; j++) {\n if (dist[i][k] + dist[k][j] < dist[i][j]) {\n dist[i][j] = dist[i][k] + dist[k][j];\n }\n }\n }\n }\n\n return dist;\n}\n"}, {"role": "assistant", "content": "Write Floyd Warshall algorithm for a given graph"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة هيئ_مصفوفة(م: سند[مـصفوفة[صـحيح]]، حجم: صـحيح، قيمة: صـحيح) {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < حجم ، دليل++ {\n\t\tم.أضف(قيمة)؛\n\t}\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc initializeArray(a: ref[Array[Int]], size: Int, val: Int) {\n def i: Int;\n for i = 0, i < size, i++ {\n a.add(val);\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc find_most_frequent(a: ref[Array[Int]]): Int {\n def max_count: Int = 0;\n def res: Int = -1;\n\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n def count: Int = 1;\n \n def j: Int;\n for j = i + 1 , j < a.getLength() , j++ {\n if a(j) == a(i) {\n count++;\n }\n }\n\n if count > max_count {\n max_count = count;\n res = a(i);\n }\n }\n\n return res;\n}\n"}, {"role": "assistant", "content": "function findMostFrequent(arr) {\n var maxCount = 0, res = -1;\n\n for (var i = 0; i < arr.length; i++) {\n var count = 1;\n for (var j = i + 1; j < arr.length; j++)\n if (arr[i] == arr[j])\n count++;\n if (count > maxCount) {\n maxCount = count;\n res = arr[i];\n }\n }\n\n return res;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"js\":\nimport \"Srl/Array\";\nimport \"closure\";\n\n\nuse Srl;\n\n\nfunc check_any(a: ref[Array[Int]], f: closure (num: Int): Bool): Bool {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if f(a(i)) {\n return true;\n }\n }\n\n return false;\n}\n"}, {"role": "assistant", "content": "// Criteria function that checks if a number is positive\nfunction criteria(num) {\n return num > 0;\n}\n\n// Function to check all elements in an array\nfunction check_any(arr) {\n for(let i = 0; i < arr.length; i++) {\n if(criteria(arr[i])) {\n return true;\n }\n }\n return false;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction startsWith(str, prefix) {\n for(let i = 0; i < prefix.length; i++) {\n if(str[i] !== prefix[i])\n return false;\n }\n return true;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة يبدأ_ب(س: سند[نـص]، سابق: سند[نـص]): ثـنائي {\n\tإذا س.هات_الطول() < سابق.هات_الطول() {\n\t\tارجع خطأ؛\n\t}\n\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < سابق.هات_الطول() ، دليل++ {\n\t\tإذا سابق(دليل) != س(دليل) {\n\t\t\tارجع خطأ؛\n\t\t}\n\t}\n\tارجع صح؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nvoid initializeArray(int* arr, int size, int value) {\n for(int i = 0; i < size; i++) {\n arr[i] = value;\n }\n}\n"}, {"role": "assistant", "content": "Initialize a given array with a given size by a given value"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction insert(a, n, pos, x) {\n // Shift elements to right\n for (let i = n; i > pos; i--)\n a[i] = a[i - 1];\n\n // Insert x at pos\n a[pos] = x;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة احشر(م: سند[مـصفوفة[صـحيح]]، موقع: صـحيح، قيمة: صـحيح) {\n\tعرف حجم: صـحيح = م.هات_الطول()؛\n\tم.أضف(0)؛ // لزيادة الحجم بمقدار 1\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = حجم ، دليل > موقع ، دليل-- {\n\t\tم(دليل) = م(دليل - 1)؛\n\t}\n\t\n\tم(موقع) = قيمة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, Find the intersection point of two given lines (the line represented by three values `a`, `b`, `c` as ax + by + c = 0) and return it, in case of parallel line return null or empty array"}, {"role": "assistant", "content": "function findIntersection(a1, b1, c1, a2, b2, c2) {\n // Check if the lines are parallel\n if(a1*b2 - a2*b1 === 0) {\n return null;\n }\n\n let result = [];\n result[0] = (b1*c2 - b2*c1) / (a1*b2 - a2*b1);\n result[1] = (a2*c1 - a1*c2) / (a1*b2 - a2*b1);\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nعرف مـصفوفة_ثنائية: لقب مـصفوفة[مـصفوفة[عـائم[64]]]؛\n\n\nدالة جداء(م1: سند[مـصفوفة_ثنائية]، م2: سند[مـصفوفة_ثنائية]): مـصفوفة_ثنائية {\n\tعرف أسطر_م1: صـحيح = م1.هات_الطول()؛\n\tعرف أسطر_م2: صـحيح = م2.هات_الطول()؛\n\tعرف أعمدة_م1: صـحيح = م1(0).هات_الطول()؛\n\tعرف أعمدة_م2: صـحيح = م2(0).هات_الطول()؛\n\n\tعرف نتيجة: مـصفوفة_ثنائية؛\n\t\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tعرف دليل3: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < أسطر_م1 ، دليل1++ {\n\t\tعرف سطر: مـصفوفة[عـائم[64]]؛\n\t\tلكل دليل2 = 0 ، دليل2 < أعمدة_م2 ، دليل2++ {\n\t\t\tسطر.أضف(0)؛\n\t\t\tلكل دليل3 = 0 ، دليل3 < أعمدة_م1 ، دليل3++ {\n\t\t\t\tسطر(دليل2) += م1(دليل1)(دليل3) * م2(دليل3)(دليل2)؛\n\t\t\t}\n\t\t}\n\t\tنتيجة.أضف(سطر)؛\n\t}\n\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "#include <stdlib.h>\n\n// Function to multiply two matrices\nint** multiply(int** a, int** b, int r1, int c1, int r2, int c2) {\n int i, j, k;\n // Create a result matrix dynamically\n int** result = (int**)malloc(r1 * sizeof(int*));\n for(i = 0; i < r1; i++) {\n result[i] = (int*)malloc(c2 * sizeof(int));\n }\n\n // Initialize the result matrix with 0\n for(i = 0; i < r1; i++) {\n for(j = 0; j < c2; j++) {\n result[i][j] = 0;\n }\n }\n\n // Multiply the two matrices\n for(i = 0; i < r1; i++) {\n for(j = 0; j < c2; j++) {\n for(k = 0; k < c1; k++) {\n result[i][j] += a[i][k] * b[k][j];\n }\n }\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة اعكس_مصفوفة(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف بداية: صـحيح = 0؛\n\tعرف نهاية: صـحيح = م.هات_الطول() - 1؛\n\n\tبينما بداية < نهاية {\n\t\tعرف مؤقت: صـحيح = م(بداية)؛\n\t\tم(بداية) = م(نهاية)؛\n\t\tم(نهاية) = مؤقت؛\n\t\tبداية++؛\n\t\tنهاية--؛\n\t}\n}\n"}, {"role": "assistant", "content": "void invertArray(int a[], int n) {\n int start = 0;\n int end = n - 1;\n while (start < end) {\n int temp = a[start];\n a[start] = a[end];\n a[end] = temp;\n start++;\n end--;\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, check if a given array contains a given element"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc exists(a: ref[Array[Int]], val: Int): Bool {\n def i: Int;\n for i = 0, i < a.getLength(), i++ {\n if a(i) == val {\n return true;\n }\n }\n return false;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, Remove any whitespace character from both ends of a given string"}, {"role": "assistant", "content": "import \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc trim(s: ref[String]) {\n def start: Int = 0;\n def end: Int = s.getLength() - 1;\n\n while (s(start) == ' ' || s(start) == '\\t' || s(start) == '\\n') {\n start++;\n }\n\n while (s(end) == ' ' || s(end) == '\\t' || s(end) == '\\n') {\n end--;\n }\n\n s = s.slice(start, end - start + 1);\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Array\";\n\nuse Srl;\n\n\nfunc insertionSort(a: ref[Array[Int]]) {\n def i: Int;\n def key: Int;\n def j: Int;\n\n for i = 1 , i < a.getLength() , i++ {\n key = a(i);\n j = i - 1;\n\n while j >= 0 && a(j) > key {\n a(j + 1) = a(j);\n j = j - 1;\n }\n a(j + 1) = key;\n }\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة الترتيب_بالحشر(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف دليل1: صـحيح؛\n\tعرف مفتاح: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\t\n\tلكل دليل1 = 1 ، دليل1 < م.هات_الطول() ، دليل1++ {\n\t\tمفتاح = م(دليل1)؛\n\t\tدليل2 = دليل1 - 1؛\n\t\t\n\t\tبينما دليل2 >= 0 && م(دليل2) > مفتاح {\n\t\t\tم(دليل2 + 1) = م(دليل2)؛\n\t\t\tدليل2 = دليل2 - 1؛\n\t\t}\n\t\tم(دليل2 + 1) = مفتاح؛\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\n#include <stdlib.h>\n\n// Function to find the intersection point of two lines\ndouble* findIntersection(double a1, double b1, double c1, double a2, double b2, double c2) {\n // Check if the lines are parallel\n if(a1*b2 - a2*b1 == 0) {\n return NULL;\n }\n\n double* result = (double*)malloc(2 * sizeof(double));\n result[0] = (b1*c2 - b2*c1) / (a1*b2 - a2*b1);\n result[1] = (a2*c1 - a1*c2) / (a1*b2 - a2*b1);\n return result;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\nfunc findIntersection(a1: Float[64], b1: Float[64], c1: Float[64], a2: Float[64], b2: Float[64], c2: Float[64]): Array[Float[64]] {\n def result: Array[Float[64]];\n if a1*b2 - a2*b1 == 0 {\n return result;\n }\n\n result.add((b1*c2 - b2*c1) / (a1*b2 - a2*b1));\n result.add((a2*c1 - a1*c2) / (a1*b2 - a2*b1));\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, راكم المصفوفة المعطاة م باستعمال الدالة المعطاة د و احتفط بكل النتائج الجزئية و أرجعهم"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة راكم(م: سند[مـصفوفة[صـحيح]]، د: مغلفة(قيمة_سابقة: صـحيح، قيمة_حالية: صـحيح): صـحيح): مـصفوفة[صـحيح] {\n\tعرف طول: صـحيح = م.هات_الطول()؛\n\tعرف نتيجة: مـصفوفة[صـحيح]؛\n\t\n\tعرف دليل: صـحيح؛\n\tنتيجة.أضف(م(0))؛\n\tلكل دليل = 1 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tنتيجة.أضف(د(نتيجة(دليل - 1)، م(دليل)))؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction clip(arr, lower, upper) {\n for(let i = 0; i < arr.length; i++) {\n if(arr[i] < lower) {\n arr[i] = lower;\n } else if(arr[i] > upper) {\n arr[i] = upper;\n }\n }\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc clip(a: ref[Array[Int]], lower: Int, upper: Int) {\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n if a(i) < lower {\n a(i) = lower;\n }\n else if a(i) > upper {\n a(i) = upper;\n }\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة اعكس_نص(س: نـص): نـص {\n\tعرف طول: صـحيح = س.هات_الطول()؛\n\tعرف نتيجة: نـص = \"\"؛\n\n\tعرف دليل: صـحيح؛\n\tلكل دليل = طول - 1 ، دليل >= 0 ، دليل-- {\n\t\tنتيجة.ألحق(س(دليل))؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "#include <string.h>\n\nvoid invert_string(char* str) {\n int len = strlen(str);\n for(int i = 0; i < len / 2; i++) {\n char temp = str[i];\n str[i] = str[len - i - 1];\n str[len - i - 1] = temp;\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة المحرف_متواجد(س: سند[نـص]، م: مـحرف): ثـنائي {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < س.هات_الطول() ، دليل++ {\n\t\tإذا س(دليل) == م {\n\t\t\tارجع صح؛\n\t\t}\n\t}\n\tارجع خطأ؛\n}\n"}, {"role": "assistant", "content": "اختبر فيما إذا كانت سلسلة نصية معطاة تحتوي محرفا معطى"}]}
{"messages": [{"role": "user", "content": "Using c, check if a given string starts with another given string"}, {"role": "assistant", "content": "int starts_with(const char *str, const char *prefix) {\n while(*prefix) {\n if (!(*str))\n return 0;\n if(*prefix++ != *str++)\n return 0;\n }\n return 1;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة اعكس_مصفوفة(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف بداية: صـحيح = 0؛\n\tعرف نهاية: صـحيح = م.هات_الطول() - 1؛\n\n\tبينما بداية < نهاية {\n\t\tعرف مؤقت: صـحيح = م(بداية)؛\n\t\tم(بداية) = م(نهاية)؛\n\t\tم(نهاية) = مؤقت؛\n\t\tبداية++؛\n\t\tنهاية--؛\n\t}\n}\n"}, {"role": "assistant", "content": "function reverseArray(a) {\n let start = 0;\n let end = a.length - 1;\n\n while (start < end) {\n let temp = a[start];\n a[start] = a[end];\n a[end] = temp;\n\n start++;\n end--;\n }\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nuse Srl;\n\nclass Point {\n def x : Int;\n def y : Int;\n};\n\nfunc areCollinear(p1: Point, p2: Point, p3: Point): Bool {\n return (p2.y - p1.y) * (p3.x - p1.x) == (p3.y - p1.y) * (p2.x - p1.x);\n}\n"}, {"role": "assistant", "content": "استخدم مـتم؛\n\n\nصنف نـقطة {\n\tعرف س: صـحيح؛\n\tعرف ص: صـحيح؛\n}\n\nدالة على_خط_مستقيم(ن1: نـقطة، ن2: نـقطة، ن3: نـقطة): ثـنائي {\n\tارجع (ن2.ص - ن1.ص) * (ن3.س - ن1.ص) == (ن3.ص - ن1.ص) * (ن2.س - ن1.س)؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction exists(a, val) {\n for (let i = 0; i < a.length ; i++) {\n if (a[i] == val) {\n return true;\n }\n }\n return false;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة موجود(م: سند[مـصفوفة[صـحيح]]، قيمة: صـحيح): ثـنائي {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا م(دليل) == قيمة {\n\t\t\tارجع صح؛\n\t\t}\n\t}\n\tارجع خطأ؛\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, Find and return the maximum in the given array `a`"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\n\nfunc max(a: ref[Array[Int]]): Int {\n def result: Int = a(0);\n\n def i: Int;\n for i = 1 , i < a.getLength() , i++ {\n if a(i) > result {\n result = a(i);\n }\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة دور(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف حجم: صـحيح = م.هات_الطول()؛\n\t\n\tعرف أول_عنصر: صـحيح = م(0)؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < حجم - 1 ، دليل++ {\n\t\tم(دليل) = م(دليل + 1)؛\n\t}\n\t\n\tم(حجم - 1) = أول_عنصر؛\n}\n"}, {"role": "assistant", "content": "function rotate(a) {\n const n = a.length;\n\n let first_element = a[0];\n\n for (let i = 0; i < n - 1; i++) {\n a[i] = a[i + 1];\n }\n\n a[n - 1] = first_element;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, Split a given string into a list of strings based on a given character"}, {"role": "assistant", "content": "import \"Srl/String\";\nimport \"Srl/Array\"\n\nuse Srl;\n\n\nfunc split(s: ref[String], token: Char): Array[String] {\n def result: Array[String];\n\n def temp: String;\n def i: Int;\n for i = 0 , i < s.getLength() , i++ {\n if (s(i) != token) {\n temp.append(s(i));\n }\n else {\n result.add(temp);\n temp = \"\";\n }\n }\n result.add(temp);\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, Check whether a given number is prime or not and return that result"}, {"role": "assistant", "content": "#include <stdbool.h>\n\nbool isPrime(int num) {\n if (num <= 1) {\n return false;\n }\n for (int i = 2; i * i <= num; i++) {\n if (num % i == 0) {\n return false;\n }\n }\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using js, Remove any whitespace character from both ends of a given string"}, {"role": "assistant", "content": "function trim(str) {\n let start = 0, end = str.length - 1;\n\n // Trim leading white spaces\n while(str[start] === ' ' || str[start] === '\\t' || str[start] === '\\n') start++;\n\n // Trim trailing white spaces\n while(str[end] === ' ' || str[end] === '\\t' || str[end] === '\\n') end--;\n\n // Return the trimmed string\n return str.substring(start, end + 1);\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"enAlusus\":\nfunction sum(a, start, end) {\n let result = 0;\n\n for (let i = start; i < end; i++) {\n result += a[i];\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\nfunc sum(a: ref[Array[Int]], start: Int, end: Int): Int {\n def sum: Int = 0;\n\n def i: Int;\n for i = start , i < end , i++ {\n sum += a(i);\n }\n\n return sum;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"enAlusus\":\n#include <string.h>\n\nvoid trim(char *str) {\n int start = 0, end = strlen(str) - 1;\n\n // Trim leading white spaces\n while(str[start] == ' ' || str[start] == '\\t' || str[start] == '\\n') start++;\n\n // Trim trailing white spaces\n while(str[end] == ' ' || str[end] == '\\t' || str[end] == '\\n') end--;\n\n // Shift characters\n memmove(str, str + start, end - start + 1);\n\n // Null terminate the string\n str[end - start + 1] = '\\0';\n}\n"}, {"role": "assistant", "content": "import \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc trim(s: ref[String]) {\n def start: Int = 0;\n def end: Int = s.getLength() - 1;\n\n while (s(start) == ' ' || s(start) == '\\t' || s(start) == '\\n') {\n start++;\n }\n\n while (s(end) == ' ' || s(end) == '\\t' || s(end) == '\\n') {\n end--;\n }\n\n s = s.slice(start, end - start + 1);\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Fs\";\nimport \"Srl/String\";\nimport \"Srl/Array\";\n\nuse Srl;\n\n\nfunc readFileToArray(file_path: ref[String]): Array[String] {\n def file: ptr[Fs.File] = Fs.openFile(file_path.buf, \"r\");\n def content: Array[String];\n\n Fs.seek(file, 0, Fs.Seek.END);\n def size: Int = Fs.tell(file);\n Fs.seek(file, 0, Fs.Seek.SET);\n \n content.add(String());\n def i: Int;\n def j: Int = 0;\n for i = 0 , i < size , i++ {\n def temp: Char;\n Fs.read(temp~ptr, 1, 1, file);\n\n if temp == '\\n' {\n content.add(String());\n j++;\n }\n else {\n content(j).append(temp);\n }\n }\n\n return content;\n}\n"}, {"role": "assistant", "content": "Read the lines of a text file given its path into an array and return it"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction multiply(matrix, vector) {\n let rows = matrix.length, cols = matrix[0].length;\n let result = new Array(rows);\n\n for (let i = 0; i < rows; i++) {\n result[i] = 0;\n for (let j = 0; j < cols; j++) {\n result[i] += matrix[i][j] * vector[j];\n }\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nعرف مـصفوفة_ثنائية: لقب مـصفوفة[مـصفوفة[عـائم[64]]]؛\nعرف شـعاع: لقب مـصفوفة[عـائم[64]]؛\n\n\nدالة جداء(م: سند[مـصفوفة_ثنائية]، ش: سند[شـعاع]): شـعاع {\n\tعرف أسطر: صـحيح = م.هات_الطول()؛\n\tعرف أعمدة: صـحيح = م(0).هات_الطول()؛\n\n\tعرف نتيجة: شـعاع؛\n\t\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < أسطر ، دليل1++ {\n\t\tنتيجة.أضف(0)؛\n\t\tلكل دليل2 = 0 ، دليل2 < أعمدة ، دليل2++ {\n\t\t\t\tنتيجة(دليل1) += م(دليل1)(دليل2) * ش(دليل2)؛\n\t\t}\n\t}\n\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "Using c, Read the content of a text file given its path and return the result"}, {"role": "assistant", "content": "#include <stdio.h>\n#include <stdlib.h>\n\n// Function to read the content of a file into a string\nchar* read_file(const char* file_path) {\n FILE* file = fopen(file_path, \"r\");\n if(file == NULL) {\n printf(\"Could not open file %s\\n\", file_path);\n return NULL;\n }\n\n // Get the size of the file\n fseek(file, 0, SEEK_END);\n long file_size = ftell(file);\n fseek(file, 0, SEEK_SET);\n\n // Allocate memory for the string\n char* str = malloc(file_size + 1);\n if(str == NULL) {\n printf(\"Could not allocate memory for the string\\n\");\n fclose(file);\n return NULL;\n }\n\n // Read the file into the string one character at a time\n for(long i = 0; i < file_size; i++) {\n fread(&str[i], sizeof(char), 1, file);\n }\n\n // Null-terminate the string\n str[file_size] = '\\0';\n\n fclose(file);\n return str;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\n#include <stdbool.h>\n\n// Function to check if arr2 is a permutation of arr1\nbool is_permutation(int arr1[], int size1, int arr2[], int size2) {\n // If sizes are not equal, return false\n if(size1 != size2) {\n return false;\n }\n\n // Create an array to keep track of visited elements\n bool visited[size2];\n for(int i = 0; i < size2; i++) {\n visited[i] = false;\n }\n\n // For each element in arr1\n for(int i = 0; i < size1; i++) {\n bool found = false;\n\n // For each element in arr2\n for(int j = 0; j < size2; j++) {\n // If the element in arr1 is found in arr2 and it has not been visited\n if(arr1[i] == arr2[j] && !visited[j]) {\n found = true;\n visited[j] = true; // Mark the element in arr2 as visited\n break;\n }\n }\n\n // If the element in arr1 is not found in arr2, return false\n if(!found) {\n return false;\n }\n }\n\n // If we reach here, then arr2 is a permutation of arr1\n return true;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة هل_تباديل(م1: سند[مـصفوفة[صـحيح]]، م2: سند[مـصفوفة[صـحيح]]): ثـنائي {\n\tإذا م1.هات_الطول() != م2.هات_الطول() {\n\t\tارجع خطأ؛\n\t}\n\t\n\tعرف مزار: مـصفوفة[ثـنائي]؛\n\tعرف دليل1: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < م2.هات_الطول() ، دليل1++ {\n\t\tمزار.أضف(خطأ)؛\n\t}\n\t\n\tعرف دليل2: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < م1.هات_الطول() ، دليل1++ {\n\t\tعرف موجود: ثـنائي = خطأ؛\n\t\tلكل دليل2 = 0 ، دليل2 < م2.هات_الطول() ، دليل2++ {\n\t\t\tإذا م1(دليل1) == م2(دليل2) && !مزار(دليل2) {\n\t\t\t\tموجود = صح؛\n\t\t\t\tمزار(دليل2) = صح؛\n\t\t\t\tاقطع؛\n\t\t\t}\n\t\t}\n\t\tإذا !موجود {\n\t\t\tارجع خطأ؛\n\t\t}\n\t}\n\tارجع صح؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nfunction toUpperCase(s) {\n let result = '';\n for(let i = 0; i < s.length; i++){\n let code = s.charCodeAt(i);\n if(code >= 97 && code <= 122){\n result += String.fromCharCode(code - 97 + 65);\n } else {\n result += s[i];\n }\n }\n return result;\n}\n"}, {"role": "assistant", "content": "convert string to uppercase and return the result"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Math\";\nimport \"Srl/Array\";\n\nuse Srl;\n\nclass Point {\n def x : Float;\n def y : Float;\n};\n\nfunc calculatePolygonArea(vertices: ref[Array[Point]]): Float {\n def area: Float = 0;\n def numVertices: Int = vertices.getLength();\n def j: Int = numVertices - 1;\n\n def i: Int;\n for i = 0 , i < numVertices , i++ {\n area += (vertices(j).x + vertices(i).x) * (vertices(j).y - vertices(i).y);\n j = i;\n }\n return Math.abs(area / 2.0);\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/ريـاضيات\"؛\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nصنف نـقطة {\n\tعرف س: عـائم؛\n\tعرف ص: عـائم؛\n}\n\nدالة مساحة_مضلع(رؤوس: سند[مـصفوفة[نـقطة]]): عـائم {\n\tعرف مساحة: عـائم = 0؛\n\tعرف عدد_الرؤوس: صـحيح = رؤوس.هات_الطول()؛\n\tعرف دليل2: صـحيح = عدد_الرؤوس - 1؛\n\t\n\tعرف دليل1: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < عدد_الرؤوس ، دليل1++ {\n\t\tمساحة += (رؤوس(دليل1).س + رؤوس(دليل2).س) * (رؤوس(دليل1).ص - رؤوس(دليل2).ص)؛\n\t\tدليل2 = دليل1؛\n\t}\n\tارجع ريـاضيات.مطلق(مساحة / 2.0)؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"arAlusus\":\nimport \"Srl/Array\";\nimport \"Srl/Math\";\n\n\nuse Srl;\n\n\nfunc std(a: ref[Array[Int]], mean: Float): Float {\n def size: Int = a.getLength();\n def variance: Float = 0;\n\n def i: Int;\n for i = 0 , i < size , i++ {\n variance += (a(i) - mean) * ( a(i) - mean);\n }\n\n return Math.sqrt(variance / size);\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/ريـاضيات\"؛\n\nاستخدم مـتم؛\n\n\nدالة انحراف_معياري(م: سند[مـصفوفة[صـحيح]]، متوسط: عـائم): عـائم {\n\tعرف حجم: صـحيح = م.هات_الطول()؛\n\tعرف تباين: عـائم = 0؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < حجم ، دليل++ {\n\t\tتباين += (م(دليل) - متوسط) * (م(دليل) - متوسط)؛\n\t}\n\t\n\tارجع ريـاضيات.جذر(تباين / حجم)؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة لكل_عنصر(م: سند[مـصفوفة[صـحيح]]، د: مغلفة(عنصر: صـحيح): صـحيح) {\n\tعرف دليل: صـحيح؛\n\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tم(دليل) = د(م(دليل))؛\n\t}\n}\n"}, {"role": "assistant", "content": "طبق الدالة المعطاة د على كل عنصر من عناصر المصفوفة المعطاة م و أرجع النتيجة"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, اقرأ محتوى ملف نصي معطى مساره و ارجع النتيجة"}, {"role": "assistant", "content": "اشمل \"مـتم/نـم\"؛\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة اقرأ_الملف(مسار_الملف: سند[نـص]): نـص {\n\tعرف ملف: مؤشر[نـم.مـلف] = نـم.افتح_ملف(مسار_الملف، \"r\")؛\n\t\n\tنـم.انتقل(ملف، 0، نـم.انـتقال._نهاية_)؛\n\tعرف حجم: صـحيح = نـم.هات_الموقع(ملف)؛\n\tنـم.انتقل(ملف، 0، نـم.انـتقال._بداية_)؛\n\t\n\tعرف المحتوى: نـص؛\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < حجم ، دليل++ {\n\t\tعرف مؤقت: مـحرف؛\n\t\tنـم.اقرأ(مؤقت~مؤشر، 1، 1، ملف)؛\n\t\tالمحتوى.ألحق(مؤقت)؛\n\t}\n\t\n\tارجع المحتوى؛\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جمع(م: سند[مـصفوفة[صـحيح]]): صـحيح {\n\tعرف نتيجة: صـحيح = 0؛\n\n\tعرف دليل: صـحيح؛\n\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n نتيجة += م(دليل)؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "جد و أرجع ناتج جمع عناصر المصفوفة المعطاة م"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"js\":\nاشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة تفحص_الكل(م: سند[مـصفوفة[صـحيح]]، د: مغلفة(رقم: صـحيح): ثـنائي): ثـنائي {\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tإذا !د(م(دليل)) {\n\t\t\tارجع خطأ؛\n\t\t}\n\t}\n\t\n\tارجع صح؛\n}\n"}, {"role": "assistant", "content": "// Criteria function that checks if a number is positive\nfunction criteria(num) {\n return num > 0;\n}\n\n// Function to check all elements in an array\nfunction check_all(arr) {\n for(let i = 0; i < arr.length; i++) {\n if(!criteria(arr[i])) {\n return false;\n }\n }\n return true;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"enAlusus\" to \"c\":\nimport \"Srl/String\";\n\n\nuse Srl;\n\n\nfunc char_exists(s: ref[String], c: Char): Bool {\n def i: Int;\n\tfor i = 0 , i < s.getLength() , i++ {\n\t\tif (s(i) == c) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n"}, {"role": "assistant", "content": "#include <stdbool.h>\n\nbool char_exists(char s[], int n, char c) {\n for (int i = 0; i < n; i++) {\n if (s[i] == c) {\n return true;\n }\n }\n return false;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, اطبع المصفوفة المعطاة"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مـتم/طـرفية\"؛\n\nاستخدم مـتم؛\n\n\nدالة اطبع(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tطـرفية.اطبع(\"%d \"، م(دليل))؛\n\t}\n}\n"}]}
{"messages": [{"role": "user", "content": "Using enAlusus, find and return the most frequent item in a given array"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\n\nuse Srl;\n\n\nfunc find_most_frequent(a: ref[Array[Int]]): Int {\n def max_count: Int = 0;\n def res: Int = -1;\n\n def i: Int;\n for i = 0 , i < a.getLength() , i++ {\n def count: Int = 1;\n \n def j: Int;\n for j = i + 1 , j < a.getLength() , j++ {\n if a(j) == a(i) {\n count++;\n }\n }\n\n if count > max_count {\n max_count = count;\n res = a(i);\n }\n }\n\n return res;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"c\":\nاشمل \"مـتم/نـم\"؛\nاشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة اقرأ_الملف(مسار_الملف: سند[نـص]): نـص {\n\tعرف ملف: مؤشر[نـم.مـلف] = نـم.افتح_ملف(مسار_الملف، \"r\")؛\n\t\n\tنـم.انتقل(ملف، 0، نـم.انـتقال._نهاية_)؛\n\tعرف حجم: صـحيح = نـم.هات_الموقع(ملف)؛\n\tنـم.انتقل(ملف، 0، نـم.انـتقال._بداية_)؛\n\t\n\tعرف المحتوى: نـص؛\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < حجم ، دليل++ {\n\t\tعرف مؤقت: مـحرف؛\n\t\tنـم.اقرأ(مؤقت~مؤشر، 1، 1، ملف)؛\n\t\tالمحتوى.ألحق(مؤقت)؛\n\t}\n\t\n\tارجع المحتوى؛\n}\n"}, {"role": "assistant", "content": "#include <stdio.h>\n#include <stdlib.h>\n\n// Function to read the content of a file into a string\nchar* read_file(const char* file_path) {\n FILE* file = fopen(file_path, \"r\");\n if(file == NULL) {\n printf(\"Could not open file %s\\n\", file_path);\n return NULL;\n }\n\n // Get the size of the file\n fseek(file, 0, SEEK_END);\n long file_size = ftell(file);\n fseek(file, 0, SEEK_SET);\n\n // Allocate memory for the string\n char* str = malloc(file_size + 1);\n if(str == NULL) {\n printf(\"Could not allocate memory for the string\\n\");\n fclose(file);\n return NULL;\n }\n\n // Read the file into the string one character at a time\n for(long i = 0; i < file_size; i++) {\n fread(&str[i], sizeof(char), 1, file);\n }\n\n // Null-terminate the string\n str[file_size] = '\\0';\n\n fclose(file);\n return str;\n}\n"}]}
{"messages": [{"role": "user", "content": "Using arAlusus, احسب و أرجع مساحة مثلت من إحداثيات نقاطه"}, {"role": "assistant", "content": "اشمل \"مـتم/ريـاضيات\"؛\n\nاستخدم مـتم؛\n\n\nصنف نـقطة {\n\tعرف س: عـائم؛\n\tعرف ص: عـائم؛\n}\n\nدالة مساحة_مثلث(ن1: نـقطة، ن2: نـقطة، ن3: نـقطة): عـائم {\n\tارجع ريـاضيات.مطلق(ن1.س*(ن2.ص - ن3.ص) + ن2.س*(ن3.ص - ن1.ص) + ن3.س*(ن1.ص - ن2.ص)) / 2.0؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\n#include <stdlib.h>\n\nint* multiply(int** a, int* v, int rows, int cols) {\n int i, j;\n // Create a result vector dynamically\n int* result = (int*)malloc(rows * sizeof(int));\n\n // Initialize the result vector with 0\n for(i = 0; i < rows; i++) {\n result[i] = 0;\n }\n\n // Multiply the matrix by the vector\n for(i = 0; i < rows; i++) {\n for(j = 0; j < cols; j++) {\n result[i] += a[i][j] * v[j];\n }\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nعرف مـصفوفة_ثنائية: لقب مـصفوفة[مـصفوفة[عـائم[64]]]؛\nعرف شـعاع: لقب مـصفوفة[عـائم[64]]؛\n\n\nدالة جداء(م: سند[مـصفوفة_ثنائية]، ش: سند[شـعاع]): شـعاع {\n\tعرف أسطر: صـحيح = م.هات_الطول()؛\n\tعرف أعمدة: صـحيح = م(0).هات_الطول()؛\n\n\tعرف نتيجة: شـعاع؛\n\t\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < أسطر ، دليل1++ {\n\t\tنتيجة.أضف(0)؛\n\t\tلكل دليل2 = 0 ، دليل2 < أعمدة ، دليل2++ {\n\t\t\t\tنتيجة(دليل1) += م(دليل1)(دليل2) * ش(دليل2)؛\n\t\t}\n\t}\n\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"c\" to \"arAlusus\":\n#include <stdlib.h>\n\n// Function to multiply two matrices\nint** multiply(int** a, int** b, int r1, int c1, int r2, int c2) {\n int i, j, k;\n // Create a result matrix dynamically\n int** result = (int**)malloc(r1 * sizeof(int*));\n for(i = 0; i < r1; i++) {\n result[i] = (int*)malloc(c2 * sizeof(int));\n }\n\n // Initialize the result matrix with 0\n for(i = 0; i < r1; i++) {\n for(j = 0; j < c2; j++) {\n result[i][j] = 0;\n }\n }\n\n // Multiply the two matrices\n for(i = 0; i < r1; i++) {\n for(j = 0; j < c2; j++) {\n for(k = 0; k < c1; k++) {\n result[i][j] += a[i][k] * b[k][j];\n }\n }\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\nعرف مـصفوفة_ثنائية: لقب مـصفوفة[مـصفوفة[عـائم[64]]]؛\n\n\nدالة جداء(م1: سند[مـصفوفة_ثنائية]، م2: سند[مـصفوفة_ثنائية]): مـصفوفة_ثنائية {\n\tعرف أسطر_م1: صـحيح = م1.هات_الطول()؛\n\tعرف أسطر_م2: صـحيح = م2.هات_الطول()؛\n\tعرف أعمدة_م1: صـحيح = م1(0).هات_الطول()؛\n\tعرف أعمدة_م2: صـحيح = م2(0).هات_الطول()؛\n\n\tعرف نتيجة: مـصفوفة_ثنائية؛\n\t\n\tعرف دليل1: صـحيح؛\n\tعرف دليل2: صـحيح؛\n\tعرف دليل3: صـحيح؛\n\tلكل دليل1 = 0 ، دليل1 < أسطر_م1 ، دليل1++ {\n\t\tعرف سطر: مـصفوفة[عـائم[64]]؛\n\t\tلكل دليل2 = 0 ، دليل2 < أعمدة_م2 ، دليل2++ {\n\t\t\tسطر.أضف(0)؛\n\t\t\tلكل دليل3 = 0 ، دليل3 < أعمدة_م1 ، دليل3++ {\n\t\t\t\tسطر(دليل2) += م1(دليل1)(دليل3) * م2(دليل3)(دليل2)؛\n\t\t\t}\n\t\t}\n\t\tنتيجة.أضف(سطر)؛\n\t}\n\n\tارجع نتيجة؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/مـصفوفة\"؛\nاشمل \"مغلفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة راكم(م: سند[مـصفوفة[صـحيح]]، د: مغلفة(قيمة_سابقة: صـحيح، قيمة_حالية: صـحيح): صـحيح): مـصفوفة[صـحيح] {\n\tعرف طول: صـحيح = م.هات_الطول()؛\n\tعرف نتيجة: مـصفوفة[صـحيح]؛\n\t\n\tعرف دليل: صـحيح؛\n\tنتيجة.أضف(م(0))؛\n\tلكل دليل = 1 ، دليل < م.هات_الطول() ، دليل++ {\n\t\tنتيجة.أضف(د(نتيجة(دليل - 1)، م(دليل)))؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\nimport \"closure\";\n\n\nuse Srl;\n\n\nfunc accumulate(a: ref[Array[Int]], f: closure (previousValue: Int, currentValue: Int): Int): Array[Int] {\n def size: Int = a.getLength();\n def result: Array[Int];\n\n def i: Int;\n result.add(a(0));\n for i = 1 , i < a.getLength() , i++ {\n result.add(f(result(i-1), a(i)));\n }\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جد_التقاطع(أ1: عـائم[64]، ب1: عـائم[64]، ج1: عـائم[64]، أ2: عـائم[64]، ب2: عـائم[64]، ج2: عـائم[64]): مـصفوفة[عـائم[64]] {\n\tعرف نتيجة: مـصفوفة[عـائم[64]]؛\n\tإذا أ1 * ب2 - أ2 * ب1 == 0 {\n\t\tارجع نتيجة؛\n\t}\n\t\n\tنتيجة.أضف((ب1*ج2 - ب2*ج1) / (أ1 * ب2 - أ2 * ب1))؛\n\tنتيجة.أضف((أ2*ج1 - أ1*ج2) / (أ1 * ب2 - أ2 * ب1))؛\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\nfunc findIntersection(a1: Float[64], b1: Float[64], c1: Float[64], a2: Float[64], b2: Float[64], c2: Float[64]): Array[Float[64]] {\n def result: Array[Float[64]];\n if a1*b2 - a2*b1 == 0 {\n return result;\n }\n\n result.add((b1*c2 - b2*c1) / (a1*b2 - a2*b1));\n result.add((a2*c1 - a1*c2) / (a1*b2 - a2*b1));\n\n return result;\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction trim(str) {\n let start = 0, end = str.length - 1;\n\n // Trim leading white spaces\n while(str[start] === ' ' || str[start] === '\\t' || str[start] === '\\n') start++;\n\n // Trim trailing white spaces\n while(str[end] === ' ' || str[end] === '\\t' || str[end] === '\\n') end--;\n\n // Return the trimmed string\n return str.substring(start, end + 1);\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/نـص\"؛\n\nاستخدم مـتم؛\n\n\nدالة شذب(س: سند[نـص]) {\n\tعرف بداية: صـحيح = 0؛\n\tعرف نهاية: صـحيح = س.هات_الطول() - 1؛\n\t\n\tبينما (س(بداية) == ' ' || س(بداية) == '\\t' || س(بداية) == '\\n') {\n\t\tبداية++؛\n\t}\n\t\n\tبينما (س(نهاية) == ' ' || س(نهاية) == '\\t' || س(نهاية) == '\\n') {\n\t\tنهاية--؛\n\t}\n\t\n\tس = س.اجتزئ(بداية، نهاية - بداية + 1)؛\n}\n"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"arAlusus\" to \"enAlusus\":\nاشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة جمع(م: سند[مـصفوفة[صـحيح]]، بداية: صـحيح، نهاية: صـحيح): صـحيح {\n\tعرف نتيجة: صـحيح = 0؛\n\n\tعرف دليل: صـحيح؛\n\n\tلكل دليل = بداية ، دليل < نهاية ، دليل++ {\n نتيجة += م(دليل)؛\n\t}\n\t\n\tارجع نتيجة؛\n}\n"}, {"role": "assistant", "content": "import \"Srl/Array\";\n\nuse Srl;\n\nfunc sum(a: ref[Array[Int]], start: Int, end: Int): Int {\n def sum: Int = 0;\n\n def i: Int;\n for i = start , i < end , i++ {\n sum += a(i);\n }\n\n return sum;\n}\n"}]}
{"messages": [{"role": "user", "content": "What this code do?\nimport \"Srl/Array\";\nimport \"closure\";\n\n\nuse Srl;\n\n\nfunc accumulate(a: ref[Array[Int]], f: closure (previousValue: Int, currentValue: Int): Int): Array[Int] {\n def size: Int = a.getLength();\n def result: Array[Int];\n\n def i: Int;\n result.add(a(0));\n for i = 1 , i < a.getLength() , i++ {\n result.add(f(result(i-1), a(i)));\n }\n\n return result;\n}\n"}, {"role": "assistant", "content": "accumulate the given array `a` using the given function `f` and keep the partial results and return them"}]}
{"messages": [{"role": "user", "content": "translate the following code from \"js\" to \"arAlusus\":\nfunction rotate(a) {\n const n = a.length;\n\n let first_element = a[0];\n\n for (let i = 0; i < n - 1; i++) {\n a[i] = a[i + 1];\n }\n\n a[n - 1] = first_element;\n}\n"}, {"role": "assistant", "content": "اشمل \"مـتم/مـصفوفة\"؛\n\nاستخدم مـتم؛\n\n\nدالة دور(م: سند[مـصفوفة[صـحيح]]) {\n\tعرف حجم: صـحيح = م.هات_الطول()؛\n\t\n\tعرف أول_عنصر: صـحيح = م(0)؛\n\t\n\tعرف دليل: صـحيح؛\n\tلكل دليل = 0 ، دليل < حجم - 1 ، دليل++ {\n\t\tم(دليل) = م(دليل + 1)؛\n\t}\n\t\n\tم(حجم - 1) = أول_عنصر؛\n}\n"}]}