Skip to main content
Commonmark migration
Source Link

#Java 7, 230 215 213 bytes

Java 7, 230 215 213 bytes

#Java 7, 230 215 213 bytes

Java 7, 230 215 213 bytes

Changed print method to shorter generic one
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384

#Java 7, 230 215215 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);}void<T>void p(StringT s){System.out.print(s);}

Try it here.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(StringT 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 });
  }
}

#Java 7, 230 215 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);}void p(String s){System.out.print(s);}

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 void p(String 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 });
  }
}

#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);}

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 });
  }
}
Lowered by 15 bytes thanks to some tips by Giacomo Garabello and some stupid mistakes I've made myself..
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384

#Java 7, 230230 215 bytes

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

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.

Try it here.Try it here.

class Main{
    static int c = 0;

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

    static void printAndReset(int[]aint[] a){
        m(a);
        c = 0;
        System.out.println();
    }
 
   
  public static void main(final 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 });
    }
}

#Java 7, 230 bytes

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

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..

Try it here.

class Main{
    static int c = 0;

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

    static void printAndReset(int[]a){
        m(a);
        c = 0;
        System.out.println();
    }
 
    public static void main(final 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 });
    }
}

#Java 7, 230 215 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);}void p(String 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.

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 void p(String 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 });
  }
}
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384
Loading