Skip to main content
4 of 4
Commonmark migration

Java 7, 230 215 213 bytes

int c=0;void m(int[]a){int l=a.length,j=-1,i=-1;if(l<1)return;int[]x=new int[l-1];while(++j<c)p(" ");for(;++i<l;p(a[i]+" "))if(i<l&i>0)x[i-1]=(a[i-1]+a[i])%10;p("\n");c++;m(x);}<T>void p(T s){System.out.print(s);}

This ended up being a bit longer than I thought.. Maybe it can be golfed a bit more though, since I kinda messed up I think..

Some bytes saved thanks to @GiacomoGarabello.

Ungolfed & test code:

Try it here.

class Main{
  static int c = 0;

  static void m(int[] a){
    int l = a.length,
        j = -1,
        i = -1;
    if(l < 1){
      return;
    }
    int[] x = new int[l-1];
    while(++j < c){
      p(" ");
    }
    for(; ++i < l; p(a[i] + " ")){
      if(i < l & i > 0){
        x[i - 1] = (a[i - 1] + a[i]) % 10;
      }
    }
    p("\n");
    c++;
    m(x);
  }
  
  static <T> void p(T s){
    System.out.print(s);
  }

  static void printAndReset(int[] a){
    m(a);
    c = 0;
    System.out.println();
  }
  
  public static void main(String[] a){
    printAndReset(new int[]{ 7, 5, 0, 9 });
    printAndReset(new int[]{ 0 });
    printAndReset(new int[]{ 1, 2 });
    printAndReset(new int[]{ 8, 7 });
    printAndReset(new int[]{ 0, 0 });
    printAndReset(new int[]{ 1, 4, 2 });
    printAndReset(new int[]{ 0, 1, 0 });
    printAndReset(new int[]{ 1, 0, 0, 0 });
    printAndReset(new int[]{ 1, 2, 3, 4 });
    printAndReset(new int[]{ 1, 2, 3, 5, 8 });
    printAndReset(new int[]{ 9, 2, 4, 5, 3, 2, 2 });
  }
}

Output:

7 5 0 9 
 2 5 9 
  7 4 
   1 

0 

1 2 
 3 

8 7 
 5 

0 0 
 0 

1 4 2 
 5 6 
  1 

0 1 0 
 1 1 
  2 

1 0 0 0 
 1 0 0 
  1 0 
   1 

1 2 3 4 
 3 5 7 
  8 2 
   0 

1 2 3 5 8 
 3 5 8 3 
  8 3 1 
   1 4 
    5 

9 2 4 5 3 2 2 
 1 6 9 8 5 4 
  7 5 7 3 9 
   2 2 0 2 
    4 2 2 
     6 4 
      0 
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384