Code Golf: Diamonds
To start the year let's have a round of CodeGolf!
You know the drill. Shortest solution wins.
Print a size ascending range of Diamonds using the numbers 1 to 9, ranging from size 1 to size N, each diamond separated by a blank line.
A size 1 diamond should look like this, a single centered 1:
1
With the size N=9 diamond looking like this:
1 121 12321 1234321 123454321 12345654321 1234567654321 123456787654321 12345678987654321 123456787654321 1234567654321 12345654321 123454321 1234321 12321 121 1
Bonus Level: For N>9 you can either reuse 1-9 or supply arbitrary characters.
Maybe there are shorter solutions, but somebody must start the game... (I hope, class- and method name does not count)
I shrunk your code a bit, it's 72 characters now:
@Sergei.Shutov $e(112345678) prevents you to pass N>9
@Julius Kavay similar issue, but limit is 16
My interpretation was N>9 is any number >9
Yeah I thought N>9 is "bonus level" - it will definitely require more characters. Original answer (top one) was only working for N<=9 anyway
OK, you want it short and endless? You can get it!
Diamond() works from 0 thru 10 using 63 chars
Infinite() works from 0 thru Cache's maxint and has 66 chars of source code.
BINGO!
I see right now, cut-and-paste without looking-and-checking isn't good! Sorry, for some stupid reason, I copied the wrong lines. The correct ones are:
Also, Dimond() works from 0 thru 9 (and not thru 10). The line lengths (with 63 and 66 chars) were correct. Finally, the correct output:
Shrunk your code a bit, 71 chars:
for on "" is great, but just <=9
Yeah I think we can shred a couple of characters using this technique from your code as well - it will become 71 characters, best so far:
UTC: 2021-01-10 21:39:34
N<=9 : 73 chr
N>9 : 78 chr
even less
indeed 66 , THANKS!
N<=9 (59 chr)
N>9 (62 chr)
Who is shorter? ;)
Right part should go back to 1, so
and not
Sorry, I didn't notice. Updated
And now it's right?
Yes!
Social networks
InterSystems resources
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue