-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbench_funcs.py
More file actions
1382 lines (1339 loc) · 37.6 KB
/
bench_funcs.py
File metadata and controls
1382 lines (1339 loc) · 37.6 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
funcs = [
{"original_prefix":
"""public class ADD {
public static int add(int x, int y) {
""",
"prefix":
"""public class ADD {
public static int add(int x, int y) {
// buggy code
// return x | y;
""",
"suffix":
"""
}
}
"""},
{"original_prefix":
"""public class ADD_ELEMENTS {
public static int add_elements(ArrayList<Integer> arr, int k) {
int result = 0;
for(int i = 0; i < k; i++) {
""",
"prefix":
"""public class ADD_ELEMENTS {
public static int add_elements(ArrayList<Integer> arr, int k) {
int result = 0;
for(int i = 0; i < k; i++) {
// buggy code
// if(Integer.toString(arr.get(i)).length() >= 2) {
// result -= arr.get(i);
""",
"suffix":
"""
}
}
return result;
}
}
"""},
{"original_prefix":
"""public class ADD_EVEN_AT_ODD {
public static int add_even_at_odd(int[] lst) {
int sum = 0;
""",
"prefix":
"""public class ADD_EVEN_AT_ODD {
public static int add_even_at_odd(int[] lst) {
int sum = 0;
// buggy code
// for (int i = 0; i < lst.length; i += 1) {
""",
"suffix":
"""
if (lst[i] % 2 == 0)
sum += lst[i];
}
return sum;
}
}
"""},
{"original_prefix":
"""public class ALL_PREFIXES {
public static List<String> all_prefixes(String string){
List<String> result = new ArrayList<String>();
for (int i = 0; i < string.length(); i += 1){
""",
"prefix":
"""public class ALL_PREFIXES {
public static List<String> all_prefixes(String string){
List<String> result = new ArrayList<String>();
for (int i = 0; i < string.length(); i += 1){
// buggy code
// result.add(string.substring(i + 1));
""",
"suffix":
"""
}
return result;
}
}
"""},
{"original_prefix":
"""public class ANTI_SHUFFLE {
public static String anti_shuffle(String s) {
String result = "";
for (String str : s.split(" ")) {
char[] chars = str.toCharArray();
Arrays.sort(chars);
""",
"prefix":
"""public class ANTI_SHUFFLE {
public static String anti_shuffle(String s) {
String result = "";
for (String str : s.split(" ")) {
char[] chars = str.toCharArray();
Arrays.sort(chars);
// buggy code
// result += new String(chars);
// }
// return result;
""",
"suffix":
"""
}
}
"""},
{"original_prefix":
"""public class ANY_INT {
public static boolean any_int(double x, double y, double z) {
""",
"prefix":
"""public class ANY_INT {
public static boolean any_int(double x, double y, double z) {
// buggy code
// if ((int)x == x && (int)y == y) {
// if (x + y == z || x + z == y)
""",
"suffix":
"""
return true;
}
return false;
}
}
"""},
{"original_prefix":
"""public class BELOW_THRESHOLD {
public static boolean below_threshold(int[] l, int t) {
for (int i = 0; i < l.length; i += 1) {
""",
"prefix":
"""public class BELOW_THRESHOLD {
public static boolean below_threshold(int[] l, int t) {
for (int i = 0; i < l.length; i += 1) {
// buggy code
// if (l[i] <= t)
// return true;
// }
// return false;
""",
"suffix":
"""
}
}
"""},
{"original_prefix":
"""public class BELOW_ZERO {
public static boolean below_zero(List<Integer> operations) {
int balance = 0;
for (Integer op : operations){
balance += op;
""",
"prefix":
"""public class BELOW_ZERO {
public static boolean below_zero(List<Integer> operations) {
int balance = 0;
for (Integer op : operations){
balance += op;
// buggy code
// if (balance > 0){
// return false;
// }
// }
// return true;
""",
"suffix":
"""
}
}
"""},
{"original_prefix":
"""public class BF {
public static ArrayList<String> bf(String planet1, String planet2) {
ArrayList<String> planet_names = new ArrayList<String>(Arrays.asList(
"Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"
));
ArrayList<String> result = new ArrayList<String>();
if ((! planet_names.contains(planet1)) || (! planet_names.contains(planet2)))
return result;
int planet1_index = planet_names.indexOf(planet1);
int planet2_index = planet_names.indexOf(planet2);
""",
"prefix":
"""public class BF {
public static ArrayList<String> bf(String planet1, String planet2) {
ArrayList<String> planet_names = new ArrayList<String>(Arrays.asList(
"Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"
));
ArrayList<String> result = new ArrayList<String>();
if ((! planet_names.contains(planet1)) || (! planet_names.contains(planet2)))
return result;
int planet1_index = planet_names.indexOf(planet1);
int planet2_index = planet_names.indexOf(planet2);
// buggy code
// for (int i = planet1_index; i < planet2_index; i += 1)
// result.add(planet_names.get(i));
""",
"suffix":
"""
return result;
}
}
"""},
{"original_prefix":
"""public class BY_LENGTH {
public static ArrayList<String> by_length(ArrayList<Integer> a) {
Map<Integer, String> digit_map = new HashMap<>();
digit_map.put(1, "One");
digit_map.put(2, "Two");
digit_map.put(3, "Three");
digit_map.put(4, "Four");
digit_map.put(5, "Five");
digit_map.put(6, "Six");
digit_map.put(7, "Seven");
digit_map.put(8, "Eight");
digit_map.put(9, "Nine");
Collections.sort(a, Collections.reverseOrder());
ArrayList<String> result = new ArrayList<>();
for(int num : a) {
""",
"prefix":
"""public class BY_LENGTH {
public static ArrayList<String> by_length(ArrayList<Integer> a) {
Map<Integer, String> digit_map = new HashMap<>();
digit_map.put(1, "One");
digit_map.put(2, "Two");
digit_map.put(3, "Three");
digit_map.put(4, "Four");
digit_map.put(5, "Five");
digit_map.put(6, "Six");
digit_map.put(7, "Seven");
digit_map.put(8, "Eight");
digit_map.put(9, "Nine");
Collections.sort(a, Collections.reverseOrder());
ArrayList<String> result = new ArrayList<>();
for(int num : a) {
// buggy code
// if(digit_map.get(num) != "") {
""",
"suffix":
"""
result.add(digit_map.get(num));
}
}
return result;
}
}
"""},
{"original_prefix":
"""public class CAN_ARRANGE {
public static int can_arrange(int[] arr) {
""",
"prefix":
"""public class CAN_ARRANGE {
public static int can_arrange(int[] arr) {
// buggy code
// int ind = 1;
// for(int i = 0; i < arr.length - 1; i++) {
// if(arr[i] < arr[i + 1]) ind = i + 1;
""",
"suffix":
"""
}
return ind;
}
}
"""},
{"original_prefix":
"""public class CAR_RACE_COLLISION {
public static int car_race_collision(int n) {
""",
"prefix":
"""public class CAR_RACE_COLLISION {
public static int car_race_collision(int n) {
// buggy code
// return n;
""",
"suffix":
"""
}
}
"""},
{"original_prefix":
"""public class CHANGE_BASE {
public static String change_base(int x, int base) {
String result = "";
while (x > 0) {
""",
"prefix":
"""public class CHANGE_BASE {
public static String change_base(int x, int base) {
String result = "";
while (x > 0) {
// buggy code
// result = result + x % base;
// x = x - x / base;
""",
"suffix":
"""
}
return result;
}
}
"""},
{"original_prefix":
"""public class CHECK_DICT_CASE {
public static boolean check_dict_case(HashMap<Object, Object> dict) {
if (dict.size() == 0)
return false;
else {
String state = "start";
for (Object key : dict.keySet()) {
if (!(key instanceof String)) {
state = "mixed";
break;
}
String str_key = (String) key;
if (state.equals("start")) {
if (str_key.toUpperCase().equals(str_key))
state = "upper";
else if (str_key.toLowerCase().equals(str_key))
state = "lower";
else {
state = "mixed";
break;
}
""",
"prefix":
"""public class CHECK_DICT_CASE {
public static boolean check_dict_case(HashMap<Object, Object> dict) {
if (dict.size() == 0)
return false;
else {
String state = "start";
for (Object key : dict.keySet()) {
if (!(key instanceof String)) {
state = "mixed";
break;
}
String str_key = (String) key;
if (state.equals("start")) {
if (str_key.toUpperCase().equals(str_key))
state = "upper";
else if (str_key.toLowerCase().equals(str_key))
state = "lower";
else {
state = "mixed";
break;
}
// buggy code
// } else if (state.equals("upper") && !str_key.toUpperCase().equals(str_key)) {
""",
"suffix":
"""
state = "mixed";
break;
}
}
return (state.equals("upper")) || (state.equals("lower"));
}
}
}
"""},
{"original_prefix":
"""public class CHECK_IF_LAST_CHAR_IS_A_LETTER {
public static boolean check_if_last_char_is_a_letter(String txt) {
String[] parts = txt.split(" ");
String last = " ";
""",
"prefix":
"""public class CHECK_IF_LAST_CHAR_IS_A_LETTER {
public static boolean check_if_last_char_is_a_letter(String txt) {
String[] parts = txt.split(" ");
String last = " ";
// buggy code
// last = parts[parts.length - 1];
// if(txt.charAt(txt.length() - 1) == ' ') last = " ";
// if(txt.length() == 1) last = " ";
// int last_char_pos = Character.toUpperCase(last.charAt(0)) - 'a';
// return (last.length() == 1) || (0 <= last_char_pos || last_char_pos <= 25);
""",
"suffix":
"""
}
}
"""},
{"original_prefix":
"""public class CHOOSE_NUM {
public static int choose_num(int x, int y) {
""",
"prefix":
"""public class CHOOSE_NUM {
public static int choose_num(int x, int y) {
// buggy code
// if(x < y) return -1;
""",
"suffix":
"""
if((y % 2) == 0) return y;
if(x == y) return -1;
return y - 1;
}
}
"""},
{"original_prefix":
"""public class CIRCULAR_SHIFT {
public static String circular_shift(int x, int shift) {
String s = x + "";
if (shift > s.length()) {
StringBuilder sb = new StringBuilder();
for (int i = s.length() - 1; i >= 0; i -= 1)
sb.append(s.charAt(i));
return sb.toString();
} else {
""",
"prefix":
"""public class CIRCULAR_SHIFT {
public static String circular_shift(int x, int shift) {
String s = x + "";
if (shift > s.length()) {
StringBuilder sb = new StringBuilder();
for (int i = s.length() - 1; i >= 0; i -= 1)
sb.append(s.charAt(i));
return sb.toString();
} else {
// buggy code
// return s.substring(s.length() - shift + 1) + s.substring(0, s.length() - shift - 1);
""",
"suffix":
"""
}
}
}
"""},
{"original_prefix":
"""public class CLOSEST_INTEGER {
public static int closest_integer(String value) {
if (value.indexOf('.') >= 0) {
while (value.charAt(value.length() - 1) == '0')
value = value.substring(0, value.length() - 1);
}
double num = Double.parseDouble(value);
int result = 0;
""",
"prefix":
"""public class CLOSEST_INTEGER {
public static int closest_integer(String value) {
if (value.indexOf('.') >= 0) {
while (value.charAt(value.length() - 1) == '0')
value = value.substring(0, value.length() - 1);
}
double num = Double.parseDouble(value);
int result = 0;
// buggy code
// if (value.substring(value.length() - 2).equals(".5")) {
// result = num > 0 ? (int)Math.floor(num) : (int)Math.ceil(num);
""",
"suffix":
"""
} else if (value.length() > 0){
result = (int)Math.round(num);
}
return result;
}
}
"""},
{"original_prefix":
"""public class COMMON {
public static int[] common(int[] l1, int[] l2) {
""",
"prefix":
"""public class COMMON {
public static int[] common(int[] l1, int[] l2) {
// buggy code
// ArrayList<Integer> common = new ArrayList<Integer>();
""",
"suffix":
"""
for (int i = 0; i < l1.length; i += 1){
for (int j = 0; j < l2.length; j += 1){
if (l1[i] == l2[j])
common.add(l1[i]);
}
}
int[] result = new int[common.size()];
int index = 0;
for (Integer c : common) {
result[index] = c;
index += 1;
}
Arrays.sort(result);
return result;
}
}
"""},
{"original_prefix":
"""public class COMPARE {
public static int[] compare(int[] game, int[] guess) {
int[] result = new int[game.length];
for (int i = 0; i < game.length; i += 1) {
""",
"prefix":
"""public class COMPARE {
public static int[] compare(int[] game, int[] guess) {
int[] result = new int[game.length];
for (int i = 0; i < game.length; i += 1) {
// buggy code
// result[i] = Math.floorDiv(game[i], guess[i]);
""",
"suffix":
"""
}
return result;
}
}
"""},
{"original_prefix":
"""public class COMPARE_ONE {
public static Object compare_one(Object a, Object b) {
double temp_a = 0, temp_b = 0;
if(a instanceof String) {
String temp_a_string = a.toString();
temp_a_string = temp_a_string.replace(',', '.');
temp_a = Double.parseDouble(temp_a_string);
}
if(b instanceof String) {
String temp_b_string = b.toString();
temp_b_string = temp_b_string.replace(',', '.');
temp_b = Double.parseDouble(temp_b_string);
}
""",
"prefix":
"""public class COMPARE_ONE {
public static Object compare_one(Object a, Object b) {
double temp_a = 0, temp_b = 0;
if(a instanceof String) {
String temp_a_string = a.toString();
temp_a_string = temp_a_string.replace(',', '.');
temp_a = Double.parseDouble(temp_a_string);
}
if(b instanceof String) {
String temp_b_string = b.toString();
temp_b_string = temp_b_string.replace(',', '.');
temp_b = Double.parseDouble(temp_b_string);
}
// buggy code
// if(a instanceof Double) temp_a = ((Integer) b).doubleValue();
// if(b instanceof Double) temp_b = ((Integer) a).doubleValue();
// if(a instanceof Integer) temp_a = (Double) a;
// if(b instanceof Integer) temp_b = (Double) b;
""",
"suffix":
"""
if(temp_a == temp_b) return null;
if(temp_a > temp_b) return a;
else return b;
}
}
"""},
{"original_prefix":
"""public class CONCATENATE {
public static String concatenate(String[] strings) {
""",
"prefix":
"""public class CONCATENATE {
public static String concatenate(String[] strings) {
// buggy code
// String result = null;
""",
"suffix":
"""
for (String string : strings)
result += string;
return result;
}
}
"""},
{"original_prefix":
"""public class CORRECT_BRACKETING {
public static boolean correct_bracketing(String brackets) {
int depth = 0;
for (char b : brackets.toCharArray()) {
if (b == '<')
depth += 1;
else
depth -= 1;
""",
"prefix":
"""public class CORRECT_BRACKETING {
public static boolean correct_bracketing(String brackets) {
int depth = 0;
for (char b : brackets.toCharArray()) {
if (b == '<')
depth += 1;
else
depth -= 1;
// buggy code
// if (depth >= 0)
// return true;
// }
// return false;
""",
"suffix":
"""
}
}
"""},
{"original_prefix":
"""public class COUNT_DISTINCT_CHARACTERS {
public static int count_distinct_characters(String string) {
HashSet<Character> distinct = new HashSet<Character>();
for (char c : string.toCharArray()) {
if (! distinct.contains(Character.toLowerCase(c)))
""",
"prefix":
"""public class COUNT_DISTINCT_CHARACTERS {
public static int count_distinct_characters(String string) {
HashSet<Character> distinct = new HashSet<Character>();
for (char c : string.toCharArray()) {
if (! distinct.contains(Character.toLowerCase(c)))
// buggy code
// distinct.add(c);
""",
"suffix":
"""
}
return distinct.size();
}
}
"""},
{"original_prefix":
"""public class COUNT_NUMS {
public static int count_nums(ArrayList<Integer> arr) {
int count = 0;
for(int num : arr) {
boolean neg = num < 0;
""",
"prefix":
"""public class COUNT_NUMS {
public static int count_nums(ArrayList<Integer> arr) {
int count = 0;
for(int num : arr) {
boolean neg = num < 0;
// buggy code
// if(neg) num *= 1;
""",
"suffix":
"""
String num_string = Integer.toString(num);
int sum = 0;
for(int i = 0; i < num_string.length(); i++) {
if((i == 0) && neg) sum -= num_string.charAt(i) - '0';
else sum += num_string.charAt(i) - '0';
}
if(sum > 0) count++;
}
return count;
}
}
"""},
{"original_prefix":
"""public class COUNT_UP_TO {
public static List<Integer> count_up_to(int n) {
List<Integer> primes = new ArrayList<Integer>();
for (int i = 2; i < n; i += 1){
""",
"prefix":
"""public class COUNT_UP_TO {
public static List<Integer> count_up_to(int n) {
List<Integer> primes = new ArrayList<Integer>();
for (int i = 2; i < n; i += 1){
// buggy code
// boolean is_prime = false;
// for (int j = 2; j < i; j += 1){
// if (i % j == 0) {
// is_prime = false;
""",
"suffix":
"""
}
}
if (is_prime) primes.add(i);
}
return primes;
}
}
"""},
{"original_prefix":
"""public class COUNT_UPPER {
public static int count_upper(String s) {
int count = 0;
for (int i = 0; i < s.length(); i += 2) {
char c = s.charAt(i);
""",
"prefix":
"""public class COUNT_UPPER {
public static int count_upper(String s) {
int count = 0;
for (int i = 0; i < s.length(); i += 2) {
char c = s.charAt(i);
// buggy code
// if (c == 'A' || c == 'e' || c == 'I' || c == 'o' || c == 'u')
""",
"suffix":
"""
count += 1;
}
return count;
}
}
"""},
{"original_prefix":
"""public class CYCPATTERN_CHECK {
public static boolean cycpattern_check(String a, String b) {
int l = b.length();
""",
"prefix":
"""public class CYCPATTERN_CHECK {
public static boolean cycpattern_check(String a, String b) {
int l = b.length();
// buggy code
// String pat = b;
// for (int i = 0; i < a.length(); i += 1) {
// for (int j = 0; j < l; j += 1) {
""",
"suffix":
"""
if (a.substring(i, i + l).equals(pat.substring(j, j + l))) return true;
}
}
return false;
}
}
"""},
{"original_prefix":
"""public class DECIMAL_TO_BINARY {
public static String decimal_to_binary(int decimal) {
""",
"prefix":
"""public class DECIMAL_TO_BINARY {
public static String decimal_to_binary(int decimal) {
// buggy code
// String result = Integer.toHexString(decimal);
""",
"suffix":
"""
return "db" + result + "db";
}
}
"""},
{"original_prefix":
"""public class DECODE_CYCLIC {
public static String decode_cyclic(String str) {
class Cyclic {
String encode_cyclic(String s) {
ArrayList<String> groups = new ArrayList<String>();
""",
"prefix":
"""public class DECODE_CYCLIC {
public static String decode_cyclic(String str) {
class Cyclic {
String encode_cyclic(String s) {
ArrayList<String> groups = new ArrayList<String>();
// buggy code
// for (int i = 0; i < s.length(); i += 3){
""",
"suffix":
"""
groups.add(s.substring(i, Math.min(s.length(), i + 3)));
}
int remain = s.length() % 3;
String result = "";
for (String group : groups){
result += group.substring(1) + group.substring(0, 1);
}
if (remain > 0){
result += s.substring(s.length() - remain);
}
return result;
}
}
final Cyclic cyclic = new Cyclic();
return cyclic.encode_cyclic(cyclic.encode_cyclic(str));
}
}
"""},
{"original_prefix":
"""public class DECODE_SHIFT {
public static String encode_shift(String string){
StringBuilder sb = new StringBuilder();
for (char c : string.toCharArray()) {
c = (char)((((int) c + 5 - (int)('a')) % 26) + (int)('a'));
sb.append(c);
}
return sb.toString();
}
public static String decode_shift(String string) {
StringBuilder sb = new StringBuilder();
for (char c : string.toCharArray()) {
""",
"prefix":
"""public class DECODE_SHIFT {
public static String encode_shift(String string){
StringBuilder sb = new StringBuilder();
for (char c : string.toCharArray()) {
c = (char)((((int) c + 5 - (int)('a')) % 26) + (int)('a'));
sb.append(c);
}
return sb.toString();
}
public static String decode_shift(String string) {
StringBuilder sb = new StringBuilder();
for (char c : string.toCharArray()) {
// buggy code
// c = (char)((((int) c - 5 - (int)('a')) % 26) + (int)('a'));
""",
"suffix":
"""
sb.append(c);
}
return sb.toString();
}
}
"""},
{"original_prefix":
"""public class DERIVATIVE {
public static List<Integer> derivative(List<Integer> xs) {
List<Integer> result = new ArrayList<Integer>();
""",
"prefix":
"""public class DERIVATIVE {
public static List<Integer> derivative(List<Integer> xs) {
List<Integer> result = new ArrayList<Integer>();
// buggy code
// for (int i = 0; i < xs.size(); i += 1)
// result.add(xs.get(i));
""",
"suffix":
"""
return result;
}
}
"""},
{"original_prefix":
"""public class DIGIT_SUM {
public static int digit_sum(String s) {
int result = 0;
for (char c : s.toCharArray()) {
""",
"prefix":
"""public class DIGIT_SUM {
public static int digit_sum(String s) {
int result = 0;
for (char c : s.toCharArray()) {
// buggy code
// if (c == ' ')
// break;
""",
"suffix":
"""
if ('A' <= c && c <= 'Z')
result += (int) c;
}
return result;
}
}
"""},
{"original_prefix":
"""public class DIGITS {
public static int digits(int n) {
int product = 1;
int odd_count = 0;
""",
"prefix":
"""public class DIGITS {
public static int digits(int n) {
int product = 1;
int odd_count = 0;
// buggy code
// while(n >= 0) {
// int digit = n * 10;
// if(digit % 2 == 0) {
// product /= digit;
""",
"suffix":
"""
odd_count++;
}
n /= 10;
}
if(odd_count == 0) return 0;
return product;
}
}
"""},
{"original_prefix":
"""public class DO_ALGEBRA {
public static double do_algebra(String[] operator, int[] operand) throws NumberFormatException, ScriptException {
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("JavaScript");
""",
"prefix":
"""public class DO_ALGEBRA {
public static double do_algebra(String[] operator, int[] operand) throws NumberFormatException, ScriptException {
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("JavaScript");
// buggy code
// String expression = "";
// for (int i = 0; i < operand.length; i += 1) {
// expression += operator[i] + operand[i];
""",
"suffix":
"""
}
return Double.parseDouble(engine.eval(expression).toString());
}
}
"""},
{"original_prefix":
"""public class DOUBLE_THE_DIFFERENCE {
public static int double_the_difference(double[] lst) {
int result = 0;
for (Double d : lst) {
if ((int) d.doubleValue() == d) {
int d_int = (int) d.doubleValue();
if (d_int % 2 == 1 && d_int >= 0) {
""",
"prefix":
"""public class DOUBLE_THE_DIFFERENCE {
public static int double_the_difference(double[] lst) {
int result = 0;
for (Double d : lst) {
if ((int) d.doubleValue() == d) {
int d_int = (int) d.doubleValue();
if (d_int % 2 == 1 && d_int >= 0) {
// buggy code
// result += d_int;
""",
"suffix":
"""
}
}
}
return result;
}
}
"""},
{"original_prefix":
"""public class EAT {
public static int[] eat(int number, int need, int remaining) {
""",
"prefix":
"""public class EAT {
public static int[] eat(int number, int need, int remaining) {
// buggy code
// return new int[] {number + need, remaining - need};
""",
"suffix":
"""
}
}
"""},
{"original_prefix":
"""public class ENCODE {
public static String encode(String message) {
StringBuilder sb = new StringBuilder();
for (char c : message.toCharArray()) {
if (Character.isUpperCase(c)) {
c = Character.toLowerCase(c);
}