Skip to content

Instantly share code, notes, and snippets.

@ijo42
Created December 10, 2020 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ijo42/597c95e8525fdd71194a413e29982b5e to your computer and use it in GitHub Desktop.
Save ijo42/597c95e8525fdd71194a413e29982b5e to your computer and use it in GitHub Desktop.
sorry for your eyes
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.stream.Collector;
import java.util.stream.Collectors;
public class PascalTrinagle {
public static void print(String st){
System.out.println(st);
}
public static void main(String[] args) {
try(BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))){
pascalTriangle(Integer.parseInt(reader.readLine()));
}catch (IOException e) {
e.printStackTrace();
}
}
public static void pascalTriangle(final int k){
List<Integer> c = new ArrayList<>();
c.add(1);
for (int i = 0; i < k + 1; i++) {
for (int j = k; j > i; j--)
System.out.print(" ");
print(c.stream().map(Objects::toString).
collect(Collectors.joining(" ")));
if(i > k)
return;
List<Integer> out = new ArrayList<>();
out.add(1);
for (int j = 1, kSize = c.size(); j < kSize; j++)
out.add(c.get(j - 1) + c.get(j));
out.add(1);
c = out;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment