-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproblem52.wren
executable file
·65 lines (58 loc) · 1.11 KB
/
problem52.wren
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
class Helper {
static sortImpl(list, a, b) {
if (a >= b - 1) {
return null
}
var j = a
for (i in (a + 1) .. (b - 1)) {
if (list[i] < list[a]) {
j = j + 1
var temp = list[i]
list[i] = list[j]
list[j] = temp
}
}
var temp = list[j]
list[j] = list[a]
list[a] = temp
sortImpl(list, a, j)
sortImpl(list, j + 1, b)
}
static sort(list) {
sortImpl(list, 0, list.count)
}
static characters(arg) {
return arg.toString.bytes.toList
}
static listEq(a, b) {
if (a.count != b.count) {
return false
}
var a1 = null
var b1 = null
while ((a1 = a.iterate(a1)) && (b1 = b.iterate(b1))) {
if (a.iteratorValue(a1) != b.iteratorValue(b1)) {
return false
}
}
return true
}
}
var i = 1
while (true) {
var okay = true
var list0 = Helper.characters(i)
Helper.sort(list0)
for (n in 2..6) {
var list = Helper.characters(i * n)
Helper.sort(list)
if (!Helper.listEq(list0, list)) {
okay = false
}
}
if (okay) {
System.print(i)
break
}
i = i + 1
}