The sum is always 15
Java - 229 200 192 181 172 170 168 bytes
Had already begun, not for the win but for the fun :)
Any suggestion is welcome.
Saved 8 bytes thanks to @ThomasKwa
Saved 20 bytes thanks to @corsiKa
Saved 2 bytes thanks to @Ypnypn
Saved 2 bytes thanks to @user902383
String p(int[]a){int c=0,j;String s="";f:for(int i:a){for(j=i;j-->0;)if(++c>14){s+=(i-j)+"\n";c=0;if(j<15){if(j>0)s+=j+" ";c+=j;continue f;}}s+=i+" ";}return s+(15-c);}
170 bytes
String p(int[]a){int c=0,j;String s="";f:for(int i:a){for(j=i;j-->0;){if(++c>14){s+=(i-j)+"\n";c=0;if(j<15){if(j>0)s+=j+" ";c+=j;continue f;}}}s+=i+" ";}return s+(15-c);}
172 bytes
String p(int[]a){int c=0,j;String s="";f:for(int i:a){for(j=i;j>0;){j--;if(++c>14){s+=(i-j)+"\n";c=0;if(j<15){if(j>0)s+=j+" ";c+=j;continue f;}}}s+=i+" ";}return s+(15-c);}
181 bytes
void p(int[]a){int c=0,j;String s="";f:for(int i:a){for(j=i;j>0;){j--;if(++c>14){s+=(i-j)+"\n";c=0;if(j<15){if(j>0)s+=j+" ";c+=j;continue f;}}}s+=i+" ";}System.out.print(s+(15-c));}
192 bytes
void p(int[]a){int c=0,j;String s="";f:for(int i:a){for(j=i;j>0;){j--;c++;if(c==15){s+=(i-j)+"\n";c=0;if(j>=15)continue;if(j>0)s+=j+" ";c+=j;continue f;}}s+=i+" ";}System.out.print(s+(15-c));}
200 bytes
void p(int[]a){int c=0,j;String s="";f:for(int i:a){j=i;while(j>0){j--;c++;if(c==15){s+=(i-j)+"\n";c=0;if(j>=15)continue;else{if(j!=0)s+=j+" ";c+=j;continue f;}}}s+=i+" ";}System.out.print(s+(15-c));}
229 bytes
void p(int[]a){int c=0,j;f:for(int i:a){j=i;while(j>0){j--;c++;if(c==15){System.out.print(i-j+"\n");c=0;if(j>=15){continue;}else{if(j!=0)System.out.print(j+" ");c+=j;continue f;}}}System.out.print(i+" ");}System.out.print(15-c);}
String p(int[] a) {
int c = 0, j;
String s = "";
f: for (int i: a) {
for (j = i; j-- > 0;)
if (++c > 14) {
s += (i - j) + "\n";
c = 0;
if (j < 15) {
if (j > 0) s += j + " ";
c += j;
continue f;
}
}
s += i + " ";
}
return s + (15 - c);
}
Pyth, 37 bytes
K15VQ=+ZNIgZK=-ZK-NZbIZZ)).?N;I>KZ-KZ
Explained
This is an implementation of Noah's equation in Pyth
K15 Store 15 in K (the max) (K is Autoinitializing, no = needed here)
VQ For N in the evaluated input
=+ZN Set Z(Which in pyth defaults to 0) to Z+N
IgZK If Z(row total) is greater than or equal to K (row max)
=-ZK Set Z to Z-K (How much the max was exceeded)
-NZ Implicitly print N-Z
b Implicitly print b (in pyth defaults to a newline)
IZ If Z > 0 (There was excess to carry to the next row)
Z Implicitly print Z (the excess)
.?N Else(the current row count is < the max(15)) output the current number
; Use infinite )'s in place of )) (to save 1 character)
I>KZ If K > Z (The max is greater than the current row count)
-KZ Implicitly print K-Z (The amount needed for the row to equal 15)
This was my first pyth, so feel free to suggest improvements.
Example:
Input
[1, 3, 4, 5, 9, 8]
Output
1
3
4
5
2
7
8
Note: Much thanks to Isaacg for several bytes of size reduction advice and creating pyth in the first place! Please upvote his comments below :)
Haskell, 126 107 102 100 bytes
[]#c=[]
(h:t)#c|s<0=t#u|s<1=u:t#[]|1<2=(c++[h-s]):(s:t)#[]where s=sum c+h-15;u=c++[h]
(#[]).(++[14])
Usage example: (#[]).(++[14]) $ [1..17]
-> [[1,2,3,4,5],[6,7,2],[6,9],[10,5],[6,9],[3,12],[1,14],[15],[15],[1,14],[3,12]]
Edit: @Stewie Griffin helped me saving 19 bytes. Thanks!