# Output a Magical 8 Trapezium

        1 × 8 + 1 = 9
12 × 8 + 2 = 98
123 × 8 + 3 = 987
1234 × 8 + 4 = 9876
12345 × 8 + 5 = 98765
123456 × 8 + 6 = 987654
1234567 × 8 + 7 = 9876543
12345678 × 8 + 8 = 98765432
123456789 × 8 + 9 = 987654321

• Output in your chosen language in the fewest bytes possible.
• Note the number of spaces at the start of each line to maintain the trapezium shape.
• Trailing spaces are allowed.
• You can use × or the letter x - whichever you prefer.
• Related. (slightly...) – Martin Ender Jul 25 '16 at 16:04
• Middle spaces are required, yes? – Value Ink Jul 25 '16 at 18:11
• @KevinLau-notKenny it is, but you could always post an alternative too if it's significant. – rybo111 Jul 25 '16 at 18:49
• It's 6 bytes corresponding to the 6 spaces in the middle, so no, I don't think it's significant enough. – Value Ink Jul 25 '16 at 19:23

# Pascal, 156127 103 bytes

Trivial solution, using the Format library func. Shaved some more bytes by using only integers and no strings. Reduced in size thanks to @manatwork (for teaching me some basic stuff about writeln).

var i,c:int64;begin i:=0;for c in[1..9]do begin i:=i*10+c;WriteLn(i:9,' x 8 + ',c,' = ',i*8+c);end;end.


Ungolfed:

var
i, c: int64;
begin
i := 0;
for c in [1..9] do
begin
i := i*10+c;
WriteLn(i:9, ' x 8 + ', c, ' = ', i*8+c);
end;
end.

• Nice, but why you use Format? WriteLn(i:9,' x 8 + ',c,' = ',i*8+c); And with the price of a compiler warning you can remove i:=0;. (Yes, will not be compatible with some ancient Pascal versions.) – manatwork Jul 28 '16 at 7:48
• @manatwork Because I didn't know about the : operator... Will change it later today – hdrz Jul 28 '16 at 10:11
• I'm afraid, the : is not operator. Is Write/WriteLn specific field width specifier. – manatwork Jul 28 '16 at 10:31
• @manatwork Yeah thats what I meant, didn't know about it. – hdrz Jul 28 '16 at 11:27

# C++, 196 bytes

Ungolfed:

#include <iostream>

using namespace std;

int main()
{
int i=1;
while (i<10){
for (int j=1;j<10-i;j=j+ 1){
cout << " ";
}
for (int j=1;j<=i;j++){
cout << j;
}
cout << " x 8 + 1 = ";

for(int m=1;m<=i;m++){
cout << 10 - m;
}

cout << endl;
i = i + 1;
}
}


Run example:

sh-4.3main 1 x 8 + 1 = 9 12 x 8 + 1 = 98 123 x 8 + 1 = 987 1234 x 8 + 1 = 9876 12345 x 8 + 1 = 98765 123456 x 8 + 1 = 987654 1234567 x 8 + 1 = 9876543 12345678 x 8 + 1 = 98765432 123456789 x 8 + 1 = 987654321  • Hello, and welcome to PPCG! What is the golfed code? – NoOneIsHere Aug 9 '16 at 17:10 # ///, 149 bytes /:/ x 8 + //-/ = //0/1234//_/9876//|/ /||||1:1-9 ||| 12:2-98 |||123:3-987 || 0:4-_ ||05:5-_5 | 056:6-_54 |0567:7-_543 05678:8-_5432 056789:9-_54321  Try it online! # dc, 79 bytes 1[32P]sS[d0<S1-d0<R]sR[dZ9r-lRxrdn[ x 8 + ]PdZn[ = ]Pdd8*rZ+prd10*dZ+dZA>M]dsMx  Try it online! Somewhat better than I expected. Started with a solution that juggled stack and an incremental register before realizing I only need to keep the left-most number around - since the value to be added is the number of digits the left-most number has, this can be determined via Z and the result can just be calculated according to the formula. [32P]sS[d0<S1-d0<R]sR feels wasteful, but I couldn't come up with a much better way to handle the indentation. The main macro, [dZ9r-lRxrdn[ x 8 + ]PdZn[ = ]Pdd8*rZ+prd10*dZ+dZA>M]dsMx should be fairly self-explanatory based on my above description. The initial 1 just seeds the whole thing. # Pyth - 30 bytes First attempt, working on optimization. VS9+*dK-9Njd[jkSN\×8\+N\=jkr9K  # Forth (gforth), 76 bytes : f 0 10 1 do cr 10 * i + dup 9 .r ." x 8 + "i . ." = "dup 8 * i + . loop ;  Try it online! ### Explanation Start a value at 0. Starts a loop from 1 to 9. Each iteration: • Multiply value by 10 and add the loop index • output this value right-aligned • output " x 8 + " • output the loop index • output " = " • calculate results and output ### Code Explanation : f \ start word definition 0 \ set up counter/value 10 1 do \ start a counted loop from 1 to 9 cr \ output a newline 10 * i + \ calculate the next value for the first term dup 9 .r \ make a copy and then output in a right-aligned space of 9 characters ." x 8 + " \ output " x 8 +" i . \ output the loop index ." = " \ output " =" dup 8 * i + \ perform the actual calculation . \ output result loop \ end the counted loop ; \ end the word definition  # Perl 6, 58 bytes mya;printf "%9s x 8 + $_ = %s\n",$a~=$_,$a.flip for 1..9


Try it online!