Monday, February 14, 2011

Pascal's triangle using regex

The pattern can probably be simplified, but this works.
String s;
System.out.println(s = "-;");
for (int n = 10; n --> 0 ;) {
   System.out.println(s = s.replaceAll("^(?=(-;))|;(?=(-*;))", "$1$2"));
}

No comments:

Post a Comment