var QUESTION_ID=111861,OVERRIDE_USER=20260;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/111861/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>
Antworten:
Kohle ,
181613 Bytes-3 Bytes dank @Neil !
Erläuterung
Probieren Sie es online! Link ist zum ausführlichen Code.
quelle
↘O
, können Sie stattdessen eine Schleife von 0 bis einschließlich N ausführen, wodurch Sie sofort zwei Bytes sparen.⁺¹
mit⊕
. Jetzt, da Sie das←
von‖C
auf verschoben habenO
, können Sie ein weiteres Byte speichern, indem Sie schreiben↙OMι↓
, sodass ich wieder auf ein Speichern von zwei Bytes zurückgreifen kann.C,
9392(Beachten Sie, dass jemand in den Kommentaren auf 87 steht.)
Probieren Sie es online!
Lesbar:
Anmerkungen:
Ich kann beide for-Schleifen zu einer for-Schleife zusammenfassen, indem ich die Gesamtzahl der ausgegebenen Zeilen iteriere, die durch die folgende Formel gegeben ist:
n*-~n/2+1
Am Ende sind es jedoch noch mehr Bytes als nur zwei separate for-Schleifen
quelle
s
am Anfang inkrementieren , wiey,n;f(s){++s;for(y=0;y<s;){printf("%*c%*c",s-y,79,y*2+1,79);for(n=++y;s-n&&n--;)puts("");}}
++s;
am Anfang hinzuzufügen und danny<=s
zuy<s
unds-y+1
zus-y
unds+1-n
zu zu wechselns-n
, damit es kompiliert werden sollte (und 91 Byte groß sein sollte).Python 2 , 65 Bytes
Probieren Sie es online!
quelle
GNU sed, 41
-r
Flaggen bis Sed.Die Eingabe ist als Zeichenfolge von Leerzeichen unär - die Länge der Zeichenfolge ist die Eingabe.
Probieren Sie es online aus .
quelle
Python 2, 76 bytes
Pretty simple. The
i-x+1and i
is to prevent a bunch of trailing newlines.quelle
'\n'*(i-1)
saves 7 bytes while avoiding the trailing newlines.MATL,
1917 bytesTry it at MATL Online! Or verify all test cases.
Explanation
quelle
05AB1E,
1814 bytesSaved 4 bytes thanks to Adnan
Try it online!
Explanation
quelle
ƒ¶N×'ONúRÂJ}.c
:).c
with a different version, but it didn't work well then. Forgot about trying it with this one and complete forgot thatú
exists :)JavaScript (ES6),
9892898478 bytes(-20 bytes thanks to Arnauld!)
A recursive solution. This is also my first ever answer in JavaScript, so please be gentle! I am still learning all this neat language has to offer, so golfing tips are very much appreciated. :)
Test Snippet
You may need to scroll to see the entire output.
quelle
${}
only saves bytes when the variable part is surrounded by static parts. As such, these strings should always start and end with static parts.0
instead of"0"
. They'll be coerced to strings. And on second thought:i++<v&&i
is actually one byte shorter than(i<v)*++i
.RProgN 2, 37 bytes
Getting in with my kind-of-golfy language before the proper golfy langauges jump in.
Explained
Try it online!
quelle
Retina,
2919 bytesTry it online!
Takes input in unary as a run of spaces. Port of my JavaScript answer. Edit: Saved 10 bytes thanks to @MartinEnder♦.
quelle
Bash, 76 bytes
Only works in a terminal since it uses ANSI escape sequences.
›
represents the CSI byte (0x9b).Test run
quelle
sed $nq
to save a byte.sed ${n}q
which is longer.sed $n\q
instead, but that does not make much sense either, as it would be the same byte count ashead
!Retina, 35
Port of my sed answer:
Try it online.
quelle
R, 89 bytes
This is my first attempt at golfing, comments welcome...
quelle
Röda,
5352 bytesTry it online!
Usage:
main { f(5) }
Ungolfed version:
quelle
\n
and save 1 byte?Befunge,
7573 bytesTry it online!
The first line reads in the velocity, v, and saves a copy in memory. The second line then counts down from v to zero, with the index i, and on each iteration pushes a sequence of character/length pairs onto the stack.
This sequence represents a kind of run-length encoding of the required output in reverse. The last two lines then simply pop these character/length pairs off the stack, outputting length occurrences of each character, until the stack is empty.
quelle
Java 8,
129124109 bytesGolfed:
Try it online!
Ungolfed:
quelle
for(;j<v;++)
would work, because at this point in timej==y
. Also, you could remove the third by adding a second string variable inside the main for loopString t="";
(12) andt+=" ";
(8) inside the first nested loop. Then the third loop just becomess+="o"+t+"o";
for(j=0;j<v;++j)s+=j<y?"\n":" ";
although I'm not sure how this meshes with my previous comment aboutt
t=""
alongside s in the beginning, and then addt+=" "
each loop around after you dos+="o"+t+"o"
Haskell, 69 bytes
Usage example:
f 3
->" OO\n O O\n\n O O\n\n\nO O"
. Try it online!.quelle
VBA,
1241128588666359 bytesSaved 29 bytes in total thanks to Taylor Scott
This must be run the in VBA Immediate window and print the result in the same.
Expanded / Formatted, it becomes:
(It turns out that concatenation in a print command is automatic without an operator.)
quelle
b & s &
Spaces alert!b &s &String
but notb&s&String
. Also, at first I thought you meant to use theSpace
function which I totally should have and that ended up saving more bytes.for i=0 To v
anddebug.? b
tofor i=0To v
andDebug.?b
, respectively for-2
bytes. And just so you know, the community consensus is that for languages with autoformatting, you may count before it is autoformatted, meaning after you make these changes you should have a byte count of 85 Bytes[A1]
(v=[A1]
) Also, I don't think you actually need thes
variable.;
to the end of the print command, though, because it kept adding an extra line break by default. Thanks!05AB1E,
1813 bytesTry it online!
quelle
Jelly,
1716 bytesTry it online!
How?
quelle
PHP, 76 bytes
Run with
echo <v> | php -nR '<code>'
or test it online.loops
$argn
down from input to0
and$i
up from 0;prints - in that order - in each iteration
$i
newlines (none in the first iteration)$argn
spaceso
2*$i
spaceso
quelle
V,
2319 bytesTry it online!
Explain
quelle
JavaScript (ES6), 87 bytes
Nonrecursive solution. Indexing requirement was annoying, both in the above and the following 62-byte (I don't know whether it would result in a shorter Retina port) recursive solution:
quelle
Perl 5, 48 bytes
47 bytes code + 1 for
-n
.Try it online!
quelle
Stacked,
6763 bytesInitial attempt, 67 bytes
Full program. Generates something like:
Which is the padded, transposed, reversed, and outputted.
quelle
Batch, 163 bytes
quelle
Ruby, 52 bytes
No trailing newline (allowed by the rules: "at most one trailing newline")
quelle
AHK, 93 bytes
If I could figure out how to do math inside of repeating keystrokes, that'd be great.
-
VK20
equates to a space-
FileAppend
outputs tostdout
if the filename is*
quelle
Haskell, 77 bytes
Try it online! Usage:
(#0) 5
quelle
Python 2, 59 bytes
Try it online!
quelle