Skip to content

Instantly share code, notes, and snippets.

@kishida
kishida / AparapiBench.java
Last active August 29, 2015 14:27
aparapiベンチ
package kishida.aparapisample;
import com.amd.aparapi.Kernel;
import java.util.Random;
import java.util.stream.IntStream;
/**
*
* @author kishida
*/
@kishida
kishida / ParseExp.java
Created January 22, 2016 00:47
Simple expression parser that supports add and sub.
public class ParseExp {
public static void main(String[] args) {
int n = 0;
String exp = "123+44-21";
int s = 0;
int result = 0;
char opCh = '+';
for(int i = 0; i < exp.length(); ++i){
char ch = exp.charAt(i);
boolean num = ch >= '0' && ch <= '9';
@kishida
kishida / AaaParenthesis.java
Last active January 22, 2016 16:59
Retrieve a pair of parenthesis with Stack.
package javaapplication1.beginer;
import java.util.LinkedList;
/**
*
* @author naoki
*/
public class AaaParenthesis {
public static void main(String[] args) {
@kishida
kishida / AaaParenthesisRecursion
Created January 22, 2016 16:59
Retrieve a pair of parenthesis with recursion.
package javaapplication1.beginer;
/**
*
* @author naoki
*/
public class AaaParenthesisRecursion {
public static void main(String[] args) {
String aaa = "aaa(aaa(aa((aaa)aa))aa)a";
for(int i = 0; i < aaa.length(); ++i){
@kishida
kishida / MulParseExp.java
Last active January 23, 2016 11:39
Simple expression parser that supports add and sub and mul.
public class MulParseExp {
public static void main(String[] args) {
int n = 0;
String exp = "123+44*2-21";
int s = 0;
int result = 0;
char opCh = '+';
int mulNum = 1;
for(int i = 0; i < exp.length(); ++i){
@kishida
kishida / Add.java
Created January 23, 2016 17:03
Add only with logical operation.
public class Add {
public static void main(String[] args) {
int a = 0b01100101;
int b = 0b00110110;
System.out.printf("a:%d b:%d a+b:%d%n", a, b, a + b);
int and = a & b;
System.out.printf("%8s(%d)%n", Integer.toBinaryString(a), a);
System.out.printf("%8s(%d)%n", Integer.toBinaryString(b), b);
System.out.printf("%8s(%d) xor%n", Integer.toBinaryString(a ^ b), a ^ b);
@kishida
kishida / AddLogical.java
Created January 23, 2016 17:13
Add only with logical operation for general
public class AddLogical {
public static void main(String[] args) {
int a = 231;
int b = 35;
System.out.printf("%d + %d = %d%n", a, b, a + b);
while(b != 0){
int c = a ^ b;
b = (a & b) << 1;
a = c;
}
@kishida
kishida / LogicalOperation.java
Created January 23, 2016 18:13
Logical operation playground.
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.util.stream.Stream;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
/**
* @author naoki
@kishida
kishida / SingleThread.java
Created January 23, 2016 19:37
Single thread program.
public class SingleThread {
public static void main(String[] args) {
StringBuilder sb = new StringBuilder();
String str = "abc(cdef)gh(ijk)lmn";
int i = 0;
boolean inParenthesis = false;
for(;;){
if(i >= str.length()){
break;
}
@kishida
kishida / ThreadMulti.java
Last active January 23, 2016 20:42
Multi thread but resource is conflict.
import java.util.stream.Stream;
public class ThreadMulti {
static class Context{
String str;
int i = 0;
boolean inParenthesis = false;
boolean terminated = false;
Context(String str){
this.str = str;