――Please do not really take this article. ――This article is an individual impression and does not show the effect or efficacy. --Complaints will only be accepted by mail.
As a service provider in the world, increasing the processing speed is a very important issue. If you simply want to increase the processing speed, you can solve it by increasing the machine power, but it is difficult to do so because it will be unprofitable as a service. Therefore, I will aim to increase the processing speed by writing the code well. In addition, this time we will use sorting, which is easy to use as an example.
We will introduce the idea of spiritual programming and aim to speed up the program.
Select Java to take the measures described below.
If you have the idea of spiritual programming, it is obvious that any code will be explosive. The sorting algorithm uses Bogosort, which has a low best calculation time.
When writing a comment, enclose it in / * * /
instead of //
. The latter is a pair of elements, so it looks like a guardian dog and seems to be very auspicious.
The semicolon (;
) means "end" and is very unlucky and should be removed.
Be sure to pray before you do it.
Avoid annihilation.
It became a detonation velocity. (It is an individual impression.) Also, if you measure the execution time here, Never measure it as it will cause you to be suspicious of the program and cause the program to be in a bad mood and slow down. The code is below. If you can increase your spirituality, you can rewrite it more and more. (In that case, please rewrite without losing gratitude and trust in the program. It will hurt your mood.) I don't do control experiments because I trust this program.
/*The guy who wrote Bogosort, which seems to be compatible with spiritual programming, to represent the "end" and remove the unlucky semicolon*/
/*This is O(n)I feel that the probability of being able to sort by*/
/*Comment//It seems to be more auspicious by sandwiching it with paired elements instead!(Guardian dog) */
public class Bogo {
public static void main(String... args) throws Exception {
/*Because throws Exception doesn't work in a lambda expression*/
for (java.util.ArrayList<Integer> data : new java.util.ArrayList[]{new java.util.ArrayList(java.util.Arrays.asList(1, 3, 2, 4, 0))}) {
while (true) {
/*Find out if sorted*/
if (java.util.stream.IntStream.range(1, data.size())
.mapToObj(i -> data.get(i - 1) > data.get(i))
.noneMatch(b -> b)) {
/*Show if sorted*/
if (java.util.stream.Stream.of(
data.stream()
.map(String::valueOf)
.collect(java.util.stream.Collectors.joining(", "))
)
.peek(System.out::println)
.count() == 0) {
}
if (System.class.getDeclaredMethod("exit", int.class).invoke(null, 0) == null) {
}
} else {
/*Not sorted*/
if (java.util.stream.Stream.of(new java.util.Random(System.currentTimeMillis()))
.peek(rand -> java.util.stream.Stream.of(rand.nextInt(data.size()))
.forEach(n -> java.util.stream.Stream.of(rand.nextInt(data.size()))
.forEach(m -> java.util.Collections.swap(data, n, m))))
.count() == 0) {
}
}
}
}
}
}
Yup
http://blog.mirakui.com/entry/20100301/1267464280
Recommended Posts