-
Notifications
You must be signed in to change notification settings - Fork 0
/
sanitized-mbpp.json
5169 lines (5169 loc) · 272 KB
/
sanitized-mbpp.json
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
[
{
"source_file": "Benchmark Questions Verification V2.ipynb",
"task_id": 2,
"prompt": "Write a function to find the shared elements from the given two lists.",
"code": "def similar_elements(test_tup1, test_tup2):\n res = tuple(set(test_tup1) & set(test_tup2))\n return (res) ",
"test_imports": [],
"test_list": [
"assert set(similar_elements((3, 4, 5, 6),(5, 7, 4, 10))) == set((4, 5))",
"assert set(similar_elements((1, 2, 3, 4),(5, 4, 3, 7))) == set((3, 4))",
"assert set(similar_elements((11, 12, 14, 13),(17, 15, 14, 13))) == set((13, 14))"
]
},
{
"source_file": "Benchmark Questions Verification V2.ipynb",
"task_id": 3,
"prompt": "Write a python function to identify non-prime numbers.",
"code": "import math\ndef is_not_prime(n):\n result = False\n for i in range(2,int(math.sqrt(n)) + 1):\n if n % i == 0:\n result = True\n return result",
"test_imports": [],
"test_list": [
"assert is_not_prime(2) == False",
"assert is_not_prime(10) == True",
"assert is_not_prime(35) == True",
"assert is_not_prime(37) == False"
]
},
{
"source_file": "Benchmark Questions Verification V2.ipynb",
"task_id": 4,
"prompt": "Write a function to find the n largest integers from a given list of numbers, returned in descending order.",
"code": "import heapq as hq\ndef heap_queue_largest(nums,n):\n largest_nums = hq.nlargest(n, nums)\n return largest_nums",
"test_imports": [],
"test_list": [
"assert heap_queue_largest( [25, 35, 22, 85, 14, 65, 75, 22, 58],3)==[85, 75, 65]",
"assert heap_queue_largest( [25, 35, 22, 85, 14, 65, 75, 22, 58],2)==[85, 75]",
"assert heap_queue_largest( [25, 35, 22, 85, 14, 65, 75, 22, 58],5)==[85, 75, 65, 58, 35]"
]
},
{
"source_file": "Benchmark Questions Verification V2.ipynb",
"task_id": 6,
"prompt": "Write a python function to check whether the two numbers differ at one bit position only or not.",
"code": "def is_Power_Of_Two (x): \n return x and (not(x & (x - 1))) \ndef differ_At_One_Bit_Pos(a,b): \n return is_Power_Of_Two(a ^ b)",
"test_imports": [],
"test_list": [
"assert differ_At_One_Bit_Pos(13,9) == True",
"assert differ_At_One_Bit_Pos(15,8) == False",
"assert differ_At_One_Bit_Pos(2,4) == False",
"assert differ_At_One_Bit_Pos(2, 3) == True",
"assert differ_At_One_Bit_Pos(5, 1) == True",
"assert differ_At_One_Bit_Pos(1, 5) == True"
]
},
{
"source_file": "Benchmark Questions Verification V2.ipynb",
"task_id": 7,
"prompt": "Write a function to find all words which are at least 4 characters long in a string.",
"code": "import re\ndef find_char_long(text):\n return (re.findall(r\"\\b\\w{4,}\\b\", text))",
"test_imports": [],
"test_list": [
"assert set(find_char_long('Please move back to stream')) == set(['Please', 'move', 'back', 'stream'])",
"assert set(find_char_long('Jing Eco and Tech')) == set(['Jing', 'Tech'])",
"assert set(find_char_long('Jhingai wulu road Zone 3')) == set(['Jhingai', 'wulu', 'road', 'Zone'])"
]
},
{
"source_file": "Benchmark Questions Verification V2.ipynb",
"task_id": 8,
"prompt": "Write a function to find squares of individual elements in a list.",
"code": "def square_nums(nums):\n square_nums = list(map(lambda x: x ** 2, nums))\n return square_nums",
"test_imports": [],
"test_list": [
"assert square_nums([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]",
"assert square_nums([10,20,30])==([100,400,900])",
"assert square_nums([12,15])==([144,225])"
]
},
{
"source_file": "Benchmark Questions Verification V2.ipynb",
"task_id": 9,
"prompt": "Write a python function to find the minimum number of rotations (greater than 0) required to get the same string.",
"code": "def find_Rotations(str): \n tmp = str + str\n n = len(str) \n for i in range(1,n + 1): \n substring = tmp[i: i+n] \n if (str == substring): \n return i \n return n ",
"test_imports": [],
"test_list": [
"assert find_Rotations(\"aaaa\") == 1",
"assert find_Rotations(\"ab\") == 2",
"assert find_Rotations(\"abc\") == 3"
]
},
{
"source_file": "Benchmark Questions Verification V2.ipynb",
"task_id": 11,
"prompt": "Write a python function to remove first and last occurrence of a given character from the string.",
"code": "def remove_Occ(s,ch): \n for i in range(len(s)): \n if (s[i] == ch): \n s = s[0 : i] + s[i + 1:] \n break\n for i in range(len(s) - 1,-1,-1): \n if (s[i] == ch): \n s = s[0 : i] + s[i + 1:] \n break\n return s ",
"test_imports": [],
"test_list": [
"assert remove_Occ(\"hello\",\"l\") == \"heo\"",
"assert remove_Occ(\"abcda\",\"a\") == \"bcd\"",
"assert remove_Occ(\"PHP\",\"P\") == \"H\""
]
},
{
"source_file": "Benchmark Questions Verification V2.ipynb",
"task_id": 12,
"prompt": "Write a function to sort a given matrix in ascending order according to the sum of its rows.",
"code": "def sort_matrix(M):\n result = sorted(M, key=sum)\n return result",
"test_imports": [],
"test_list": [
"assert sort_matrix([[1, 2, 3], [2, 4, 5], [1, 1, 1]])==[[1, 1, 1], [1, 2, 3], [2, 4, 5]]",
"assert sort_matrix([[1, 2, 3], [-2, 4, -5], [1, -1, 1]])==[[-2, 4, -5], [1, -1, 1], [1, 2, 3]]",
"assert sort_matrix([[5,8,9],[6,4,3],[2,1,4]])==[[2, 1, 4], [6, 4, 3], [5, 8, 9]]"
]
},
{
"source_file": "Benchmark Questions Verification V2.ipynb",
"task_id": 14,
"prompt": "Write a python function to find the volume of a triangular prism.",
"code": "def find_Volume(l,b,h) : \n return ((l * b * h) / 2) ",
"test_imports": [],
"test_list": [
"assert find_Volume(10,8,6) == 240",
"assert find_Volume(3,2,2) == 6",
"assert find_Volume(1,2,1) == 1"
]
},
{
"source_file": "Benchmark Questions Verification V2.ipynb",
"task_id": 16,
"prompt": "Write a function to that returns true if the input string contains sequences of lowercase letters joined with an underscore and false otherwise.",
"code": "import re\ndef text_lowercase_underscore(text):\n patterns = '^[a-z]+_[a-z]+$'\n if re.search(patterns, text):\n return True\n else:\n return False",
"test_imports": [],
"test_list": [
"assert text_lowercase_underscore(\"aab_cbbbc\")==(True)",
"assert text_lowercase_underscore(\"aab_Abbbc\")==(False)",
"assert text_lowercase_underscore(\"Aaab_abbbc\")==(False)"
]
},
{
"source_file": "Benchmark Questions Verification V2.ipynb",
"task_id": 17,
"prompt": "Write a function that returns the perimeter of a square given its side length as input.",
"code": "def square_perimeter(a):\n perimeter=4*a\n return perimeter",
"test_imports": [],
"test_list": [
"assert square_perimeter(10)==40",
"assert square_perimeter(5)==20",
"assert square_perimeter(4)==16"
]
},
{
"source_file": "Benchmark Questions Verification V2.ipynb",
"task_id": 18,
"prompt": "Write a function to remove characters from the first string which are present in the second string.",
"code": "NO_OF_CHARS = 256\ndef str_to_list(string): \n\ttemp = [] \n\tfor x in string: \n\t\ttemp.append(x) \n\treturn temp \ndef lst_to_string(List): \n\treturn ''.join(List) \ndef get_char_count_array(string): \n\tcount = [0] * NO_OF_CHARS \n\tfor i in string: \n\t\tcount[ord(i)] += 1\n\treturn count \ndef remove_dirty_chars(string, second_string): \n\tcount = get_char_count_array(second_string) \n\tip_ind = 0\n\tres_ind = 0\n\ttemp = '' \n\tstr_list = str_to_list(string) \n\twhile ip_ind != len(str_list): \n\t\ttemp = str_list[ip_ind] \n\t\tif count[ord(temp)] == 0: \n\t\t\tstr_list[res_ind] = str_list[ip_ind] \n\t\t\tres_ind += 1\n\t\tip_ind+=1\n\treturn lst_to_string(str_list[0:res_ind]) ",
"test_imports": [],
"test_list": [
"assert remove_dirty_chars(\"probasscurve\", \"pros\") == 'bacuve'",
"assert remove_dirty_chars(\"digitalindia\", \"talent\") == 'digiidi'",
"assert remove_dirty_chars(\"exoticmiles\", \"toxic\") == 'emles'"
]
},
{
"source_file": "Benchmark Questions Verification V2.ipynb",
"task_id": 19,
"prompt": "Write a function to find whether a given array of integers contains any duplicate element.",
"code": "def test_duplicate(arraynums):\n nums_set = set(arraynums) \n return len(arraynums) != len(nums_set) ",
"test_imports": [],
"test_list": [
"assert test_duplicate(([1,2,3,4,5]))==False",
"assert test_duplicate(([1,2,3,4, 4]))==True",
"assert test_duplicate([1,1,2,2,3,3,4,4,5])==True"
]
},
{
"source_file": "Benchmark Questions Verification V2.ipynb",
"task_id": 20,
"prompt": "Write a function to check if the given number is woodball or not.",
"code": "def is_woodall(x): \n\tif (x % 2 == 0): \n\t\treturn False\n\tif (x == 1): \n\t\treturn True\n\tx = x + 1 \n\tp = 0\n\twhile (x % 2 == 0): \n\t\tx = x/2\n\t\tp = p + 1\n\t\tif (p == x): \n\t\t\treturn True\n\treturn False",
"test_imports": [],
"test_list": [
"assert is_woodall(383) == True",
"assert is_woodall(254) == False",
"assert is_woodall(200) == False"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 56,
"prompt": "Write a python function to check if a given number is one less than twice its reverse.",
"code": "def rev(num): \n rev_num = 0\n while (num > 0): \n rev_num = (rev_num * 10 + num % 10) \n num = num // 10 \n return rev_num \ndef check(n): \n return (2 * rev(n) == n + 1) ",
"test_imports": [],
"test_list": [
"assert check(70) == False",
"assert check(23) == False",
"assert check(73) == True"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 57,
"prompt": "Write a python function to find the largest number that can be formed with the given list of digits.",
"code": "def find_Max_Num(arr) : \n n = len(arr)\n arr.sort(reverse = True) \n num = arr[0] \n for i in range(1,n) : \n num = num * 10 + arr[i] \n return num ",
"test_imports": [],
"test_list": [
"assert find_Max_Num([1,2,3]) == 321",
"assert find_Max_Num([4,5,6,1]) == 6541",
"assert find_Max_Num([1,2,3,9]) == 9321"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 58,
"prompt": "Write a python function to check whether the given two integers have opposite sign or not.",
"code": "def opposite_Signs(x,y): \n return ((x ^ y) < 0); ",
"test_imports": [],
"test_list": [
"assert opposite_Signs(1,-2) == True",
"assert opposite_Signs(3,2) == False",
"assert opposite_Signs(-10,-10) == False",
"assert opposite_Signs(-2,2) == True"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 59,
"prompt": "Write a function to find the nth octagonal number.",
"code": "def is_octagonal(n): \n\treturn 3 * n * n - 2 * n ",
"test_imports": [],
"test_list": [
"assert is_octagonal(5) == 65",
"assert is_octagonal(10) == 280",
"assert is_octagonal(15) == 645"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 61,
"prompt": "Write a python function to count the number of substrings with the sum of digits equal to their length.",
"code": "from collections import defaultdict\ndef count_Substrings(s):\n n = len(s)\n count,sum = 0,0\n mp = defaultdict(lambda : 0)\n mp[0] += 1\n for i in range(n):\n sum += ord(s[i]) - ord('0')\n count += mp[sum - (i + 1)]\n mp[sum - (i + 1)] += 1\n return count",
"test_imports": [],
"test_list": [
"assert count_Substrings('112112') == 6",
"assert count_Substrings('111') == 6",
"assert count_Substrings('1101112') == 12"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 62,
"prompt": "Write a python function to find smallest number in a list.",
"code": "def smallest_num(xs):\n return min(xs)\n",
"test_imports": [],
"test_list": [
"assert smallest_num([10, 20, 1, 45, 99]) == 1",
"assert smallest_num([1, 2, 3]) == 1",
"assert smallest_num([45, 46, 50, 60]) == 45"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 63,
"prompt": "Write a function to find the maximum difference between available pairs in the given tuple list.",
"code": "def max_difference(test_list):\n temp = [abs(b - a) for a, b in test_list]\n res = max(temp)\n return (res) ",
"test_imports": [],
"test_list": [
"assert max_difference([(3, 5), (1, 7), (10, 3), (1, 2)]) == 7",
"assert max_difference([(4, 6), (2, 17), (9, 13), (11, 12)]) == 15",
"assert max_difference([(12, 35), (21, 27), (13, 23), (41, 22)]) == 23"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 64,
"prompt": "Write a function to sort a list of tuples using the second value of each tuple.",
"code": "def subject_marks(subjectmarks):\n#subject_marks = [('English', 88), ('Science', 90), ('Maths', 97), ('Social sciences', 82)])\n subjectmarks.sort(key = lambda x: x[1])\n return subjectmarks",
"test_imports": [],
"test_list": [
"assert subject_marks([('English', 88), ('Science', 90), ('Maths', 97), ('Social sciences', 82)])==[('Social sciences', 82), ('English', 88), ('Science', 90), ('Maths', 97)]",
"assert subject_marks([('Telugu',49),('Hindhi',54),('Social',33)])==([('Social',33),('Telugu',49),('Hindhi',54)])",
"assert subject_marks([('Physics',96),('Chemistry',97),('Biology',45)])==([('Biology',45),('Physics',96),('Chemistry',97)])"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 65,
"prompt": "Write a function to flatten a list and sum all of its elements.",
"code": "def recursive_list_sum(data_list):\n\ttotal = 0\n\tfor element in data_list:\n\t\tif type(element) == type([]):\n\t\t\ttotal = total + recursive_list_sum(element)\n\t\telse:\n\t\t\ttotal = total + element\n\treturn total",
"test_imports": [],
"test_list": [
"assert recursive_list_sum(([1, 2, [3,4],[5,6]]))==21",
"assert recursive_list_sum(([7, 10, [15,14],[19,41]]))==106",
"assert recursive_list_sum(([10, 20, [30,40],[50,60]]))==210"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 66,
"prompt": "Write a python function to count the number of positive numbers in a list.",
"code": "def pos_count(list):\n pos_count= 0\n for num in list: \n if num >= 0: \n pos_count += 1\n return pos_count ",
"test_imports": [],
"test_list": [
"assert pos_count([1,-2,3,-4]) == 2",
"assert pos_count([3,4,5,-1]) == 3",
"assert pos_count([1,2,3,4]) == 4"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 67,
"prompt": "Write a function to find the number of ways to partition a set of Bell numbers.",
"code": "def bell_number(n): \n bell = [[0 for i in range(n+1)] for j in range(n+1)] \n bell[0][0] = 1\n for i in range(1, n+1): \n bell[i][0] = bell[i-1][i-1] \n for j in range(1, i+1): \n bell[i][j] = bell[i-1][j-1] + bell[i][j-1] \n return bell[n][0] ",
"test_imports": [],
"test_list": [
"assert bell_number(2)==2",
"assert bell_number(10)==115975",
"assert bell_number(56)==6775685320645824322581483068371419745979053216268760300"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 68,
"prompt": "Write a python function to check whether the given array is monotonic or not.",
"code": "def is_Monotonic(A): \n return (all(A[i] <= A[i + 1] for i in range(len(A) - 1)) or\n all(A[i] >= A[i + 1] for i in range(len(A) - 1))) ",
"test_imports": [],
"test_list": [
"assert is_Monotonic([6, 5, 4, 4]) == True",
"assert is_Monotonic([1, 2, 2, 3]) == True",
"assert is_Monotonic([1, 3, 2]) == False"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 69,
"prompt": "Write a function to check whether a list contains the given sublist or not.",
"code": "def is_sublist(l, s):\n\tsub_set = False\n\tif s == []:\n\t\tsub_set = True\n\telif s == l:\n\t\tsub_set = True\n\telif len(s) > len(l):\n\t\tsub_set = False\n\telse:\n\t\tfor i in range(len(l)):\n\t\t\tif l[i] == s[0]:\n\t\t\t\tn = 1\n\t\t\t\twhile (n < len(s)) and (l[i+n] == s[n]):\n\t\t\t\t\tn += 1\t\t\t\t\n\t\t\t\tif n == len(s):\n\t\t\t\t\tsub_set = True\n\treturn sub_set",
"test_imports": [],
"test_list": [
"assert is_sublist([2,4,3,5,7],[3,7])==False",
"assert is_sublist([2,4,3,5,7],[4,3])==True",
"assert is_sublist([2,4,3,5,7],[1,6])==False"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 70,
"prompt": "Write a function to find whether all the given tuples have equal length or not.",
"code": "def find_equal_tuple(Input):\n k = 0 if not Input else len(Input[0])\n flag = 1\n for tuple in Input:\n if len(tuple) != k:\n flag = 0\n break\n return flag\ndef get_equal(Input):\n return find_equal_tuple(Input) == 1",
"test_imports": [],
"test_list": [
"assert get_equal([(11, 22, 33), (44, 55, 66)]) == True",
"assert get_equal([(1, 2, 3), (4, 5, 6, 7)]) == False",
"assert get_equal([(1, 2), (3, 4)]) == True"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 71,
"prompt": "Write a function to sort a list of elements.",
"code": "def comb_sort(nums):\n shrink_fact = 1.3\n gaps = len(nums)\n swapped = True\n i = 0\n while gaps > 1 or swapped:\n gaps = int(float(gaps) / shrink_fact)\n swapped = False\n i = 0\n while gaps + i < len(nums):\n if nums[i] > nums[i+gaps]:\n nums[i], nums[i+gaps] = nums[i+gaps], nums[i]\n swapped = True\n i += 1\n return nums",
"test_imports": [],
"test_list": [
"assert comb_sort([5, 15, 37, 25, 79]) == [5, 15, 25, 37, 79]",
"assert comb_sort([41, 32, 15, 19, 22]) == [15, 19, 22, 32, 41]",
"assert comb_sort([99, 15, 13, 47]) == [13, 15, 47, 99]"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 72,
"prompt": "Write a python function to check whether the given number can be represented as the difference of two squares or not.",
"code": "def dif_Square(n): \n if (n % 4 != 2): \n return True\n return False",
"test_imports": [],
"test_list": [
"assert dif_Square(5) == True",
"assert dif_Square(10) == False",
"assert dif_Square(15) == True"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 74,
"prompt": "Write a function to check whether it follows the sequence given in the patterns array.",
"code": "def is_samepatterns(colors, patterns): \n if len(colors) != len(patterns):\n return False \n sdict = {}\n pset = set()\n sset = set() \n for i in range(len(patterns)):\n pset.add(patterns[i])\n sset.add(colors[i])\n if patterns[i] not in sdict.keys():\n sdict[patterns[i]] = []\n\n keys = sdict[patterns[i]]\n keys.append(colors[i])\n sdict[patterns[i]] = keys\n\n if len(pset) != len(sset):\n return False \n\n for values in sdict.values():\n\n for i in range(len(values) - 1):\n if values[i] != values[i+1]:\n return False\n\n return True",
"test_imports": [],
"test_list": [
"assert is_samepatterns([\"red\",\"green\",\"green\"], [\"a\", \"b\", \"b\"])==True",
"assert is_samepatterns([\"red\",\"green\",\"greenn\"], [\"a\",\"b\",\"b\"])==False",
"assert is_samepatterns([\"red\",\"green\",\"greenn\"], [\"a\",\"b\"])==False"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 75,
"prompt": "Write a function to find tuples which have all elements divisible by k from the given list of tuples.",
"code": "def find_tuples(test_list, K):\n res = [sub for sub in test_list if all(ele % K == 0 for ele in sub)]\n return res",
"test_imports": [],
"test_list": [
"assert find_tuples([(6, 24, 12), (7, 9, 6), (12, 18, 21)], 6) == [(6, 24, 12)]",
"assert find_tuples([(5, 25, 30), (4, 2, 3), (7, 8, 9)], 5) == [(5, 25, 30)]",
"assert find_tuples([(7, 9, 16), (8, 16, 4), (19, 17, 18)], 4) == [(8, 16, 4)]"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 77,
"prompt": "Write a python function to find whether a number is divisible by 11.",
"code": "def is_Diff(n): \n return (n % 11 == 0) ",
"test_imports": [],
"test_list": [
"assert is_Diff (12345) == False",
"assert is_Diff(1212112) == True",
"assert is_Diff(1212) == False"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 79,
"prompt": "Write a python function to check whether the length of the word is odd or not.",
"code": "def word_len(s): \n s = s.split(' ') \n for word in s: \n if len(word)%2!=0: \n return True \n else:\n return False",
"test_imports": [],
"test_list": [
"assert word_len(\"Hadoop\") == False",
"assert word_len(\"great\") == True",
"assert word_len(\"structure\") == True"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 80,
"prompt": "Write a function to find the nth tetrahedral number.",
"code": "def tetrahedral_number(n): \n\treturn (n * (n + 1) * (n + 2)) / 6",
"test_imports": [],
"test_list": [
"assert tetrahedral_number(5) == 35",
"assert tetrahedral_number(6) == 56",
"assert tetrahedral_number(7) == 84"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 82,
"prompt": "Write a function to find the volume of a sphere.",
"code": "import math\ndef volume_sphere(r):\n volume=(4/3)*math.pi*r*r*r\n return volume",
"test_imports": ["import math"],
"test_list": [
"assert math.isclose(volume_sphere(10), 4188.790204786391, rel_tol=0.001)",
"assert math.isclose(volume_sphere(25), 65449.84694978735, rel_tol=0.001)",
"assert math.isclose(volume_sphere(20), 33510.32163829113, rel_tol=0.001)"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 83,
"prompt": "Write a python function to find the character made by adding the ASCII value of all the characters of the given string modulo 26.",
"code": "def get_Char(strr): \n summ = 0\n for i in range(len(strr)): \n summ += (ord(strr[i]) - ord('a') + 1) \n if (summ % 26 == 0): \n return ord('z') \n else: \n summ = summ % 26\n return chr(ord('a') + summ - 1)",
"test_imports": [],
"test_list": [
"assert get_Char(\"abc\") == \"f\"",
"assert get_Char(\"gfg\") == \"t\"",
"assert get_Char(\"ab\") == \"c\""
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 84,
"prompt": "Write a function to find the nth number in the newman conway sequence.",
"code": "def sequence(n): \n\tif n == 1 or n == 2: \n\t\treturn 1\n\telse: \n\t\treturn sequence(sequence(n-1)) + sequence(n-sequence(n-1))",
"test_imports": [],
"test_list": [
"assert sequence(10) == 6",
"assert sequence(2) == 1",
"assert sequence(3) == 2"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 85,
"prompt": "Write a function to find the surface area of a sphere.",
"code": "import math\ndef surfacearea_sphere(r):\n surfacearea=4*math.pi*r*r\n return surfacearea",
"test_imports": ["import math"],
"test_list": [
"assert math.isclose(surfacearea_sphere(10), 1256.6370614359173, rel_tol=0.001)",
"assert math.isclose(surfacearea_sphere(15), 2827.4333882308138, rel_tol=0.001)",
"assert math.isclose(surfacearea_sphere(20), 5026.548245743669, rel_tol=0.001)"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 86,
"prompt": "Write a function to find nth centered hexagonal number.",
"code": "def centered_hexagonal_number(n):\n return 3 * n * (n - 1) + 1",
"test_imports": [],
"test_list": [
"assert centered_hexagonal_number(10) == 271",
"assert centered_hexagonal_number(2) == 7",
"assert centered_hexagonal_number(9) == 217"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 87,
"prompt": "Write a function to merge three dictionaries into a single dictionary.",
"code": "import collections as ct\ndef merge_dictionaries_three(dict1,dict2, dict3):\n merged_dict = dict(ct.ChainMap({},dict1,dict2,dict3))\n return merged_dict",
"test_imports": [],
"test_list": [
"assert merge_dictionaries_three({ \"R\": \"Red\", \"B\": \"Black\", \"P\": \"Pink\" }, { \"G\": \"Green\", \"W\": \"White\" },{ \"O\": \"Orange\", \"W\": \"White\", \"B\": \"Black\" })=={'B': 'Black', 'R': 'Red', 'P': 'Pink', 'G': 'Green', 'W': 'White', 'O': 'Orange'}",
"assert merge_dictionaries_three({ \"R\": \"Red\", \"B\": \"Black\", \"P\": \"Pink\" }, { \"G\": \"Green\", \"W\": \"White\" },{\"L\":\"lavender\",\"B\":\"Blue\"})=={'W': 'White', 'P': 'Pink', 'B': 'Black', 'R': 'Red', 'G': 'Green', 'L': 'lavender'}",
"assert merge_dictionaries_three({ \"R\": \"Red\", \"B\": \"Black\", \"P\": \"Pink\" },{\"L\":\"lavender\",\"B\":\"Blue\"},{ \"G\": \"Green\", \"W\": \"White\" })=={'B': 'Black', 'P': 'Pink', 'R': 'Red', 'G': 'Green', 'L': 'lavender', 'W': 'White'}"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 88,
"prompt": "Write a function to get the frequency of all the elements in a list, returned as a dictionary.",
"code": "import collections\ndef freq_count(list1):\n freq_count= collections.Counter(list1)\n return freq_count",
"test_imports": [],
"test_list": [
"assert freq_count([10,10,10,10,20,20,20,20,40,40,50,50,30])==({10: 4, 20: 4, 40: 2, 50: 2, 30: 1})",
"assert freq_count([1,2,3,4,3,2,4,1,3,1,4])==({1:3, 2:2,3:3,4:3})",
"assert freq_count([5,6,7,4,9,10,4,5,6,7,9,5])==({10:1,5:3,6:2,7:2,4:2,9:2})"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 89,
"prompt": "Write a function to find the closest smaller number than n.",
"code": "def closest_num(N):\n return (N - 1)",
"test_imports": [],
"test_list": [
"assert closest_num(11) == 10",
"assert closest_num(7) == 6",
"assert closest_num(12) == 11"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 90,
"prompt": "Write a python function to find the length of the longest word.",
"code": "def len_log(list1):\n max=len(list1[0])\n for i in list1:\n if len(i)>max:\n max=len(i)\n return max",
"test_imports": [],
"test_list": [
"assert len_log([\"python\",\"PHP\",\"bigdata\"]) == 7",
"assert len_log([\"a\",\"ab\",\"abc\"]) == 3",
"assert len_log([\"small\",\"big\",\"tall\"]) == 5"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 91,
"prompt": "Write a function to check if a string is present as a substring in a given list of string values.",
"code": "def find_substring(str1, sub_str):\n if any(sub_str in s for s in str1):\n return True\n return False",
"test_imports": [],
"test_list": [
"assert find_substring([\"red\", \"black\", \"white\", \"green\", \"orange\"],\"ack\")==True",
"assert find_substring([\"red\", \"black\", \"white\", \"green\", \"orange\"],\"abc\")==False",
"assert find_substring([\"red\", \"black\", \"white\", \"green\", \"orange\"],\"ange\")==True"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 92,
"prompt": "Write a function to check whether the given number is undulating or not.",
"code": "def is_undulating(n): \n\tn = str(n)\n\tif (len(n) <= 2): \n\t\treturn False\n\tfor i in range(2, len(n)): \n\t\tif (n[i - 2] != n[i]): \n\t\t\treturn False\n\treturn True",
"test_imports": [],
"test_list": [
"assert is_undulating(1212121) == True",
"assert is_undulating(1991) == False",
"assert is_undulating(121) == True"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 93,
"prompt": "Write a function to calculate the value of 'a' to the power 'b'.",
"code": "def power(a,b):\n\tif b==0:\n\t\treturn 1\n\telif a==0:\n\t\treturn 0\n\telif b==1:\n\t\treturn a\n\telse:\n\t\treturn a*power(a,b-1)",
"test_imports": [],
"test_list": [
"assert power(3,4) == 81",
"assert power(2,3) == 8",
"assert power(5,5) == 3125"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 94,
"prompt": "Given a list of tuples, write a function that returns the first value of the tuple with the smallest second value.",
"code": "from operator import itemgetter \ndef index_minimum(test_list):\n res = min(test_list, key = itemgetter(1))[0]\n return (res) ",
"test_imports": [],
"test_list": [
"assert index_minimum([('Rash', 143), ('Manjeet', 200), ('Varsha', 100)]) == 'Varsha'",
"assert index_minimum([('Yash', 185), ('Dawood', 125), ('Sanya', 175)]) == 'Dawood'",
"assert index_minimum([('Sai', 345), ('Salman', 145), ('Ayesha', 96)]) == 'Ayesha'"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 95,
"prompt": "Write a python function to find the length of the smallest list in a list of lists.",
"code": "def Find_Min_Length(lst): \n minLength = min(len(x) for x in lst )\n return minLength ",
"test_imports": [],
"test_list": [
"assert Find_Min_Length([[1],[1,2]]) == 1",
"assert Find_Min_Length([[1,2],[1,2,3],[1,2,3,4]]) == 2",
"assert Find_Min_Length([[3,3,3],[4,4,4,4]]) == 3"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 96,
"prompt": "Write a python function to find the number of divisors of a given integer.",
"code": "def divisor(n):\n for i in range(n):\n x = len([i for i in range(1,n+1) if not n % i])\n return x",
"test_imports": [],
"test_list": [
"assert divisor(15) == 4",
"assert divisor(12) == 6",
"assert divisor(9) == 3"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 97,
"prompt": "Write a function to find frequency of each element in a flattened list of lists, returned in a dictionary.",
"code": "def frequency_lists(list1):\n list1 = [item for sublist in list1 for item in sublist]\n dic_data = {}\n for num in list1:\n if num in dic_data.keys():\n dic_data[num] += 1\n else:\n key = num\n value = 1\n dic_data[key] = value\n return dic_data\n",
"test_imports": [],
"test_list": [
"assert frequency_lists([[1, 2, 3, 2], [4, 5, 6, 2], [7, 8, 9, 5]])=={1: 1, 2: 3, 3: 1, 4: 1, 5: 2, 6: 1, 7: 1, 8: 1, 9: 1}",
"assert frequency_lists([[1,2,3,4],[5,6,7,8],[9,10,11,12]])=={1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1, 7: 1, 8: 1, 9: 1,10:1,11:1,12:1}",
"assert frequency_lists([[20,30,40,17],[18,16,14,13],[10,20,30,40]])=={20:2,30:2,40:2,17: 1,18:1, 16: 1,14: 1,13: 1, 10: 1}"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 98,
"prompt": "Write a function to multiply all the numbers in a list and divide with the length of the list.",
"code": "def multiply_num(numbers): \n total = 1\n for x in numbers:\n total *= x \n return total/len(numbers) ",
"test_imports": ["import math"],
"test_list": [
"assert math.isclose(multiply_num((8, 2, 3, -1, 7)), -67.2, rel_tol=0.001)",
"assert math.isclose(multiply_num((-10,-20,-30)), -2000.0, rel_tol=0.001)",
"assert math.isclose(multiply_num((19,15,18)), 1710.0, rel_tol=0.001)"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 99,
"prompt": "Write a function to convert the given decimal number to its binary equivalent, represented as a string with no leading zeros.",
"code": "def decimal_to_binary(n): \n return bin(n).replace(\"0b\",\"\") ",
"test_imports": [],
"test_list": [
"assert decimal_to_binary(8) == '1000'",
"assert decimal_to_binary(18) == '10010'",
"assert decimal_to_binary(7) == '111'"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 100,
"prompt": "Write a function to find the next smallest palindrome of a specified integer, returned as an integer.",
"code": "import sys\ndef next_smallest_palindrome(num):\n numstr = str(num)\n for i in range(num+1,sys.maxsize):\n if str(i) == str(i)[::-1]:\n return i",
"test_imports": [],
"test_list": [
"assert next_smallest_palindrome(99)==101",
"assert next_smallest_palindrome(1221)==1331",
"assert next_smallest_palindrome(120)==121"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 101,
"prompt": "Write a function to find the kth element in the given array using 1-based indexing.",
"code": "def kth_element(arr, k):\n n = len(arr)\n for i in range(n):\n for j in range(0, n-i-1):\n if arr[j] > arr[j+1]:\n arr[j], arr[j+1] == arr[j+1], arr[j]\n return arr[k-1]",
"test_imports": [],
"test_list": [
"assert kth_element([12,3,5,7,19], 2) == 3",
"assert kth_element([17,24,8,23], 3) == 8",
"assert kth_element([16,21,25,36,4], 4) == 36"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 102,
"prompt": "Write a function to convert a snake case string to camel case string.",
"code": "def snake_to_camel(word):\n import re\n return ''.join(x.capitalize() or '_' for x in word.split('_'))",
"test_imports": [],
"test_list": [
"assert snake_to_camel('python_program')=='PythonProgram'",
"assert snake_to_camel('python_language')==('PythonLanguage')",
"assert snake_to_camel('programming_language')==('ProgrammingLanguage')"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 103,
"prompt": "Write a function to find the Eulerian number a(n, m).",
"code": "def eulerian_num(n, m): \n\tif (m >= n or n == 0): \n\t\treturn 0 \n\tif (m == 0): \n\t\treturn 1 \n\treturn ((n - m) * eulerian_num(n - 1, m - 1) +(m + 1) * eulerian_num(n - 1, m))",
"test_imports": [],
"test_list": [
"assert eulerian_num(3, 1) == 4",
"assert eulerian_num(4, 1) == 11",
"assert eulerian_num(5, 3) == 26"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 104,
"prompt": "Write a function to sort each sublist of strings in a given list of lists.",
"code": "def sort_sublists(input_list):\n result = [sorted(x, key = lambda x:x[0]) for x in input_list] \n return result\n",
"test_imports": [],
"test_list": [
"assert sort_sublists(([\"green\", \"orange\"], [\"black\", \"white\"], [\"white\", \"black\", \"orange\"]))==[['green', 'orange'], ['black', 'white'], ['black', 'orange', 'white']]",
"assert sort_sublists(([\" red \",\"green\" ],[\"blue \",\" black\"],[\" orange\",\"brown\"]))==[[' red ', 'green'], [' black', 'blue '], [' orange', 'brown']]",
"assert sort_sublists(([\"zilver\",\"gold\"], [\"magnesium\",\"aluminium\"], [\"steel\", \"bronze\"]))==[['gold', 'zilver'],['aluminium', 'magnesium'], ['bronze', 'steel']]"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 105,
"prompt": "Write a python function to count true booleans in the given list.",
"code": "def count(lst): \n return sum(lst) ",
"test_imports": [],
"test_list": [
"assert count([True,False,True]) == 2",
"assert count([False,False]) == 0",
"assert count([True,True,True]) == 3"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 106,
"prompt": "Write a function to append the given list to the given tuples.",
"code": "def add_lists(test_list, test_tup):\n res = tuple(list(test_tup) + test_list)\n return (res) ",
"test_imports": [],
"test_list": [
"assert add_lists([5, 6, 7], (9, 10)) == (9, 10, 5, 6, 7)",
"assert add_lists([6, 7, 8], (10, 11)) == (10, 11, 6, 7, 8)",
"assert add_lists([7, 8, 9], (11, 12)) == (11, 12, 7, 8, 9)"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 108,
"prompt": "Write a function to merge three lists into a single sorted list.",
"code": "import heapq\ndef merge_sorted_list(num1,num2,num3):\n num1=sorted(num1)\n num2=sorted(num2)\n num3=sorted(num3)\n result = heapq.merge(num1,num2,num3)\n return list(result)",
"test_imports": [],
"test_list": [
"assert merge_sorted_list([25, 24, 15, 4, 5, 29, 110],[19, 20, 11, 56, 25, 233, 154],[24, 26, 54, 48])==[4, 5, 11, 15, 19, 20, 24, 24, 25, 25, 26, 29, 48, 54, 56, 110, 154, 233]",
"assert merge_sorted_list([1, 3, 5, 6, 8, 9], [2, 5, 7, 11], [1, 4, 7, 8, 12])==[1, 1, 2, 3, 4, 5, 5, 6, 7, 7, 8, 8, 9, 11, 12]",
"assert merge_sorted_list([18, 14, 10, 9, 8, 7, 9, 3, 2, 4, 1],[25, 35, 22, 85, 14, 65, 75, 25, 58],[12, 74, 9, 50, 61, 41])==[1, 2, 3, 4, 7, 8, 9, 9, 9, 10, 12, 14, 14, 18, 22, 25, 25, 35, 41, 50, 58, 61, 65, 74, 75, 85]"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 109,
"prompt": "Write a python function to find the number of numbers with an odd value when rotating a binary string the given number of times.",
"code": "def odd_Equivalent(s,n): \n count=0\n for i in range(0,n): \n if (s[i] == '1'): \n count = count + 1\n return count ",
"test_imports": [],
"test_list": [
"assert odd_Equivalent(\"011001\",6) == 3",
"assert odd_Equivalent(\"11011\",5) == 4",
"assert odd_Equivalent(\"1010\",4) == 2"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 111,
"prompt": "Write a function to find the common elements in given nested lists.",
"code": "def common_in_nested_lists(nestedlist):\n result = list(set.intersection(*map(set, nestedlist)))\n return result",
"test_imports": [],
"test_list": [
"assert set(common_in_nested_lists([[12, 18, 23, 25, 45], [7, 12, 18, 24, 28], [1, 5, 8, 12, 15, 16, 18]]))==set([18, 12])",
"assert set(common_in_nested_lists([[12, 5, 23, 25, 45], [7, 11, 5, 23, 28], [1, 5, 8, 18, 23, 16]]))==set([5,23])",
"assert set(common_in_nested_lists([[2, 3,4, 1], [4, 5], [6,4, 8],[4, 5], [6, 8,4]]))==set([4])"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 113,
"prompt": "Write a function to check if a string represents an integer or not.",
"code": "def check_integer(text):\n text = text.strip()\n if len(text) < 1:\n return None\n else:\n if all(text[i] in \"0123456789\" for i in range(len(text))):\n return True\n elif (text[0] in \"+-\") and \\\n all(text[i] in \"0123456789\" for i in range(1,len(text))):\n return True\n else:\n return False",
"test_imports": [],
"test_list": [
"assert check_integer(\"python\")==False",
"assert check_integer(\"1\")==True",
"assert check_integer(\"12345\")==True"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 115,
"prompt": "Write a function to check whether all dictionaries in a list are empty or not.",
"code": "def empty_dit(list1):\n empty_dit=all(not d for d in list1)\n return empty_dit",
"test_imports": [],
"test_list": [
"assert empty_dit([{},{},{}])==True",
"assert empty_dit([{1,2},{},{}])==False",
"assert empty_dit({})==True"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 116,
"prompt": "Write a function to convert a given tuple of positive integers into a single integer.",
"code": "def tuple_to_int(nums):\n result = int(''.join(map(str,nums)))\n return result",
"test_imports": [],
"test_list": [
"assert tuple_to_int((1,2,3))==123",
"assert tuple_to_int((4,5,6))==456",
"assert tuple_to_int((5,6,7))==567"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 117,
"prompt": "Write a function to convert all possible convertible elements in a list of lists to floats.",
"code": "def list_to_float(test_list):\n res = []\n for tup in test_list:\n temp = []\n for ele in tup:\n if ele.isalpha():\n temp.append(ele)\n else:\n temp.append(float(ele))\n res.append((temp[0],temp[1])) \n return res",
"test_imports": [],
"test_list": [
"assert list_to_float( [(\"3\", \"4\"), (\"1\", \"26.45\"), (\"7.32\", \"8\"), (\"4\", \"8\")] ) == [(3.0, 4.0), (1.0, 26.45), (7.32, 8.0), (4.0, 8.0)]",
"assert list_to_float( [(\"4\", \"4\"), (\"2\", \"27\"), (\"4.12\", \"9\"), (\"7\", \"11\")] ) == [(4.0, 4.0), (2.0, 27.0), (4.12, 9.0), (7.0, 11.0)]",
"assert list_to_float( [(\"6\", \"78\"), (\"5\", \"26.45\"), (\"1.33\", \"4\"), (\"82\", \"13\")] ) == [(6.0, 78.0), (5.0, 26.45), (1.33, 4.0), (82.0, 13.0)]"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 118,
"prompt": "Write a function to convert a string to a list of strings split on the space character.",
"code": "def string_to_list(string): \n lst = list(string.split(\" \")) \n return lst",
"test_imports": [],
"test_list": [
"assert string_to_list(\"python programming\")==['python','programming']",
"assert string_to_list(\"lists tuples strings\")==['lists','tuples','strings']",
"assert string_to_list(\"write a program\")==['write','a','program']"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 119,
"prompt": "Write a python function to find the element that appears only once in a sorted array.",
"code": "def search(arr):\n n = len(arr)\n XOR = 0\n for i in range(n) :\n XOR = XOR ^ arr[i]\n return (XOR)",
"test_imports": [],
"test_list": [
"assert search([1,1,2,2,3]) == 3",
"assert search([1,1,3,3,4,4,5,5,7,7,8]) == 8",
"assert search([1,2,2,3,3,4,4]) == 1"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 120,
"prompt": "Write a function to find the maximum absolute product between numbers in pairs of tuples within a given list.",
"code": "def max_product_tuple(list1):\n result_max = max([abs(x * y) for x, y in list1] )\n return result_max",
"test_imports": [],
"test_list": [
"assert max_product_tuple([(2, 7), (2, 6), (1, 8), (4, 9)] )==36",
"assert max_product_tuple([(10,20), (15,2), (5,10)] )==200",
"assert max_product_tuple([(11,44), (10,15), (20,5), (12, 9)] )==484"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 123,
"prompt": "Write a function to sum all amicable numbers from 1 to a specified number.",
"code": "def amicable_numbers_sum(limit):\n if not isinstance(limit, int):\n return \"Input is not an integer!\"\n if limit < 1:\n return \"Input must be bigger than 0!\"\n amicables = set()\n for num in range(2, limit+1):\n if num in amicables:\n continue\n sum_fact = sum([fact for fact in range(1, num) if num % fact == 0])\n sum_fact2 = sum([fact for fact in range(1, sum_fact) if sum_fact % fact == 0])\n if num == sum_fact2 and num != sum_fact:\n amicables.add(num)\n amicables.add(sum_fact2)\n return sum(amicables)",
"test_imports": [],
"test_list": [
"assert amicable_numbers_sum(999)==504",
"assert amicable_numbers_sum(9999)==31626",
"assert amicable_numbers_sum(99)==0"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 124,
"prompt": "Write a function to get the angle of a complex number.",
"code": "import cmath\ndef angle_complex(a,b):\n cn=complex(a,b)\n angle=cmath.phase(a+b)\n return angle",
"test_imports": ["import math"],
"test_list": [
"assert math.isclose(angle_complex(0,1j), 1.5707963267948966, rel_tol=0.001)",
"assert math.isclose(angle_complex(2,1j), 0.4636476090008061, rel_tol=0.001)",
"assert math.isclose(angle_complex(0,2j), 1.5707963267948966, rel_tol=0.001)"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 125,
"prompt": "Write a function to find the maximum difference between the number of 0s and number of 1s in any sub-string of the given binary string.",
"code": "def find_length(string): \n\tn = len(string)\n\tcurrent_sum = 0\n\tmax_sum = 0\n\tfor i in range(n): \n\t\tcurrent_sum += (1 if string[i] == '0' else -1) \n\t\tif current_sum < 0: \n\t\t\tcurrent_sum = 0\n\t\tmax_sum = max(current_sum, max_sum) \n\treturn max_sum if max_sum else 0",
"test_imports": [],
"test_list": [
"assert find_length(\"11000010001\") == 6",
"assert find_length(\"10111\") == 1",
"assert find_length(\"11011101100101\") == 2"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 126,
"prompt": "Write a python function to find the sum of common divisors of two given numbers.",
"code": "def sum(a,b): \n sum = 0\n for i in range (1,min(a,b)): \n if (a % i == 0 and b % i == 0): \n sum += i \n return sum",
"test_imports": [],
"test_list": [
"assert sum(10,15) == 6",
"assert sum(100,150) == 93",
"assert sum(4,6) == 3"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 127,
"prompt": "Write a function to multiply two integers.",
"code": "def multiply_int(x, y):\n if y < 0:\n return -multiply_int(x, -y)\n elif y == 0:\n return 0\n elif y == 1:\n return x\n else:\n return x + multiply_int(x, y - 1)",
"test_imports": [],
"test_list": [
"assert multiply_int(10,20)==200",
"assert multiply_int(5,10)==50",
"assert multiply_int(4,8)==32"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 128,
"prompt": "Write a function to find words that are longer than n characters from a given list of words.",
"code": "def long_words(n, str):\n word_len = []\n txt = str.split(\" \")\n for x in txt:\n if len(x) > n:\n word_len.append(x)\n return word_len\t",
"test_imports": [],
"test_list": [
"assert long_words(3,\"python is a programming language\")==['python','programming','language']",
"assert long_words(2,\"writing a program\")==['writing','program']",
"assert long_words(5,\"sorting list\")==['sorting']"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 129,
"prompt": "Write a function to calculate whether the matrix is a magic square.",
"code": "def magic_square_test(my_matrix):\n iSize = len(my_matrix[0])\n sum_list = []\n sum_list.extend([sum (lines) for lines in my_matrix]) \n for col in range(iSize):\n sum_list.append(sum(row[col] for row in my_matrix))\n result1 = 0\n for i in range(0,iSize):\n result1 +=my_matrix[i][i]\n sum_list.append(result1) \n result2 = 0\n for i in range(iSize-1,-1,-1):\n result2 +=my_matrix[i][i]\n sum_list.append(result2)\n if len(set(sum_list))>1:\n return False\n return True",
"test_imports": [],
"test_list": [
"assert magic_square_test([[7, 12, 1, 14], [2, 13, 8, 11], [16, 3, 10, 5], [9, 6, 15, 4]])==True",
"assert magic_square_test([[2, 7, 6], [9, 5, 1], [4, 3, 8]])==True",
"assert magic_square_test([[2, 7, 6], [9, 5, 1], [4, 3, 7]])==False"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 130,
"prompt": "Write a function to find the item with maximum frequency in a given list.",
"code": "from collections import defaultdict\ndef max_occurrences(nums):\n dict = defaultdict(int)\n for i in nums:\n dict[i] += 1\n result = max(dict.items(), key=lambda x: x[1]) \n return result[0]",
"test_imports": [],
"test_list": [
"assert max_occurrences([2,3,8,4,7,9,8,2,6,5,1,6,1,2,3,2,4,6,9,1,2])==2",
"assert max_occurrences([2,3,8,4,7,9,8,7,9,15,14,10,12,13,16,18])==8",
"assert max_occurrences([10,20,20,30,40,90,80,50,30,20,50,10])==20"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 131,
"prompt": "Write a python function to reverse only the vowels of a given string (where y is not a vowel).",
"code": "def reverse_vowels(str1):\n\tvowels = \"\"\n\tfor char in str1:\n\t\tif char in \"aeiouAEIOU\":\n\t\t\tvowels += char\n\tresult_string = \"\"\n\tfor char in str1:\n\t\tif char in \"aeiouAEIOU\":\n\t\t\tresult_string += vowels[-1]\n\t\t\tvowels = vowels[:-1]\n\t\telse:\n\t\t\tresult_string += char\n\treturn result_string",
"test_imports": [],
"test_list": [
"assert reverse_vowels(\"Python\") == \"Python\"",
"assert reverse_vowels(\"USA\") == \"ASU\"",
"assert reverse_vowels(\"ab\") == \"ab\""
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 132,
"prompt": "Write a function to convert a tuple to a string.",
"code": "def tup_string(tup1):\n str = ''.join(tup1)\n return str",
"test_imports": [],
"test_list": [
"assert tup_string(('e', 'x', 'e', 'r', 'c', 'i', 's', 'e', 's'))==(\"exercises\")",
"assert tup_string(('p','y','t','h','o','n'))==(\"python\")",
"assert tup_string(('p','r','o','g','r','a','m'))==(\"program\")"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 133,
"prompt": "Write a function to calculate the sum of the negative numbers of a given list of numbers.",
"code": "def sum_negativenum(nums):\n sum_negativenum = list(filter(lambda nums:nums<0,nums))\n return sum(sum_negativenum)",
"test_imports": [],
"test_list": [
"assert sum_negativenum([2, 4, -6, -9, 11, -12, 14, -5, 17])==-32",
"assert sum_negativenum([10,15,-14,13,-18,12,-20])==-52",
"assert sum_negativenum([19, -65, 57, 39, 152,-639, 121, 44, 90, -190])==-894"
]
},
{
"source_file": "Mike's Copy of Benchmark Questions Verification V2.ipynb",
"task_id": 135,
"prompt": "Write a function to find the nth hexagonal number.",
"code": "def hexagonal_num(n): \n\treturn n*(2*n - 1) ",
"test_imports": [],
"test_list": [
"assert hexagonal_num(10) == 190",
"assert hexagonal_num(5) == 45",
"assert hexagonal_num(7) == 91"