-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfp-3.java
More file actions
58 lines (42 loc) · 1.17 KB
/
Copy pathfp-3.java
File metadata and controls
58 lines (42 loc) · 1.17 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
import java.util.*;
import java.lang.*;
import java.util.ArrayList;
class Rextester {
static Integer d;
static class MutableCmp implements Comparator<Integer> {
@Override
public int compare(Integer a, Integer b) { return a%d - b%d; }
}
static class ImmutableCmp implements Comparator<Integer> {
Integer d;
ImmutableCmp(Integer d) { this.d = d; }
@Override
public int compare(Integer a, Integer b) { return a%this.d - b%this.d; }
}
public static void main(String args[]) {
ArrayList<Integer> a = new ArrayList<>();
for (int i=0; i<10; i++) a.add(i);
Scanner scan = new Scanner(System.in);
MutableCmp mc = new MutableCmp();
while (scan.hasNextInt()) {
int i = scan.nextInt();
d = i;
Collections.sort(a, mc);
System.out.println(a);
Collections.sort(a, new ImmutableCmp(i));
System.out.println(a);
System.out.println();
}
}
}
/*
# Python
def addGen(x):
def go(y): return x+y
return go
add1 = addGen(1)
add3 = addGen(3)
print (add1(1))
print (addGen(1)(1))
print (add3(1))
*/