-
-
Save anonymous/def807372fda240ca2664378cef25e02 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.savaskoc.tckn; | |
import com.amd.aparapi.Kernel; | |
import java.io.FileNotFoundException; | |
import java.io.PrintWriter; | |
import java.io.UnsupportedEncodingException; | |
public class Main { | |
public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException { | |
int num = 406816900 - 406816880; | |
TCKernel kernel = new TCKernel(406816880, num); | |
kernel.execute(num); | |
System.out.printf("%d numbers in %d ms\n", num, kernel.getAccumulatedExecutionTime()); | |
PrintWriter writer = new PrintWriter("numbers.txt"); | |
kernel.saveResults(writer); | |
writer.flush(); | |
} | |
public static class TCKernel extends Kernel { | |
long[] result; | |
int start; | |
public TCKernel(int start, int num) { | |
this.result = new long[num]; | |
this.start = start; | |
} | |
@Override | |
public void run() { | |
result[getGlobalId()] = calculate(start + getGlobalId()); | |
} | |
public long calculate(int tc) { | |
int num = tc; | |
int n9 = num % 10; | |
num /= 10; | |
int n8 = num % 10; | |
num /= 10; | |
int n7 = num % 10; | |
num /= 10; | |
int n6 = num % 10; | |
num /= 10; | |
int n5 = num % 10; | |
num /= 10; | |
int n4 = num % 10; | |
num /= 10; | |
int n3 = num % 10; | |
num /= 10; | |
int n2 = num % 10; | |
num /= 10; | |
int n1 = num % 10; | |
int odds = n1 + n3 + n5 + n7 + n9; | |
int evens = n2 + n4 + n6 + n8; | |
int n10 = (odds * 7 - evens) % 10; | |
int n11 = (odds + evens + n10) % 10; | |
return (long) tc * 100 + (n10 * 10 + n11); | |
} | |
public void saveResults(PrintWriter writer) { | |
writer.println("Result\t\tNum\t\tExpected"); | |
for (int i = 0; i < result.length; i++) { | |
int tc = start + i; | |
writer.printf("%d\t%d\t%d%s", result[i], tc, calculate(tc), System.lineSeparator()); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment