RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 1545054
Accepted
Acinit
Acinit
Asked:2023-10-10 19:00:58 +0000 UTC2023-10-10 19:00:58 +0000 UTC 2023-10-10 19:00:58 +0000 UTC

高尔夫代码。埃及金字塔(俯视图)

  • 772

健康)状况

埃及金字塔是具有古埃及特色的建筑结构,是法老和其他高级人士的重要纪念碑和墓地。埃及金字塔是人类历史上最著名、最神秘的建筑结构之一。这种金字塔的特殊性被认为是其几何形状,具有一定的角度,其中使用块作为材料。

您需要实现一个获取金字塔高度的函数,以字符串形式返回方形金字塔的自然数高度图。

输入数据

  • 金字塔的高度是从1到 的自然数9。指定金字塔应有多少层

输出

  • 四角锥结构中包含空格、连字符、从1到 的自然数的字符串9

测试用例

Вход: 1
Выход:
1

Вход: 2
Выход:
1 1 1
1 2 1
1 1 1

Вход: 3
Выход:
1 1 1 1 1
1 2 2 2 1
1 2 3 2 1
1 2 2 2 1
1 1 1 1 1

评价标准

适用标准竞赛问题规则。

任何编程语言。

最小化函数形式的符号的最短解决方案将赢得比赛。空格和连字符被视为字符。仅在函数体中计算字符数(从不是连字符或空格的第一个字符开始),不考虑外部包装器(库的初始化等)。公平竞争原则适用。更改:函数声明包含在字符计数中。

此问题将开启 100 点声望值的竞赛。获胜者的回答将获得奖励。

比赛结束时得票最多的答案将被视为正确答案。

在选择获胜者时不会使用提问者的答案。

比赛持续时间为10天。于莫斯科时间 2023 年 10 月 20 日 14:00 结束。


聚苯乙烯

请在响应头中注明语言和最小化函数的字符数,以逗号分隔。

排行榜(结果表格代码取自此处)

execute("ru.stackoverflow.com", "1545054");
.cssload-container,.cssload-cube{width:97px;height:97px;transform-style:preserve-3d}.cssload-container,.cssload-cube,.cssload-half1,.cssload-half2{transform-style:preserve-3d}.cssload-container{position:relative;margin:23px 84px;perspective:292px}.cssload-cube{animation:cube 11.5s forwards infinite;transform-origin:center 49px}.cssload-half1,.cssload-s1{top:0;transform-origin:50% 100%}.cssload-half1{height:39px;position:absolute;animation:half-fold 11.5s forwards infinite}.cssload-side{width:19px;height:19px;background:#ddd;position:absolute}.cssload-s1{left:39px;animation:s1ani 11.5s forwards infinite}.cssload-s2,.cssload-s3,.cssload-s4{left:39px;transform-origin:50% 0}.cssload-s2{top:19px;animation:s2ani 11.5s forwards infinite}.cssload-s3{top:39px;animation:s3ani 11.5s forwards infinite}.cssload-s4{top:58px;animation:s4ani 11.5s forwards infinite}.cssload-s5{left:19px;top:19px;transform-origin:100% 50%;animation:s5ani 11.5s forwards infinite}.cssload-s6{left:58px;top:39px;transform-origin:0 50%;animation:s6ani 11.5s forwards infinite}@keyframes cube{0%,30%{transform:rotateX(0)}40%{transform:rotateX(45deg) rotateY(0) rotate(45deg)}60%{transform:rotateX(60deg) rotateY(0) rotate(45deg)}65%,70%{transform:rotateX(60deg) rotate(45deg) rotate(180deg)}75%,80%{transform:rotateX(60deg) rotate(45deg) rotate(1turn)}90%{transform:rotateX(0) rotate(0) rotate(0)}}@keyframes s1ani{0%{opacity:1;transform:translateY(0);background:#ddd}40%{transform:rotateX(0);background:#ddd}50%{transform:rotateX(-90deg);background:#ddd}90%{transform:rotateX(-90deg)}}@keyframes s2ani{0%{opacity:0;transform:rotateX(-179deg)}10%{opacity:1;transform:rotateX(0)}40%{background:#ddd}45%,80%{background:#b4b4b4}65%{opacity:1;background:#b4b4b4}90%{opacity:1}to{opacity:0}}@keyframes s3ani{0%,10%{opacity:0;transform:rotateX(-179deg)}20%,90%{opacity:1;transform:rotateX(0)}40%{background:#ddd}45%{background:#969696}to{opacity:0}}@keyframes s4ani{0%,20%{opacity:0;transform:rotateX(-179deg)}10%,to{opacity:0}30%{opacity:1;transform:rotateX(0)}40%{transform:rotateX(0);background:#ddd}50%{transform:rotateX(90deg);background:#b4b4b4}80%{background:#b4b4b4}90%{opacity:1;transform:rotateX(90deg)}}@keyframes s5ani{0%,10%{opacity:0;transform:rotateY(-179deg)}20%{opacity:1;background:#ddd;transform:rotateY(0)}40%{transform:rotateY(0)}50%{transform:rotateY(90deg)}55%{background:#ddd}60%{background:#c8c8c8}90%{transform:rotateY(90deg);opacity:1}to{opacity:0}}@keyframes s6ani{0%,20%{opacity:0;transform:rotateY(179deg)}30%{opacity:1;transform:rotateY(0)}40%{transform:rotateY(0)}50%{transform:rotateY(-90deg);background:#ddd}60%,80%{background:#c8c8c8}90%{opacity:1;transform:rotateY(-90deg)}to{opacity:0}}@keyframes half-fold{0%,50%{transform:rotateX(0)}60%,90%{transform:rotateX(-90deg)}}
<script src="https://mayorovp.github.io/codegolf/table-8c505e68f1349e4c69e7.js"></script>
<div class=cssload-container><div class=cssload-cube><div class=cssload-half1><div class="cssload-side cssload-s1"></div><div class="cssload-side cssload-s2"></div><div class="cssload-side cssload-s5"></div></div><div class=cssload-half2><div class="cssload-side cssload-s3"></div><div class="cssload-side cssload-s4"></div><div class="cssload-side cssload-s6"></div></div></div></div>


结果

根据竞赛条款:

  • 1 位,@extrn,Haskell,55 个字符!

  • 2 Place,@tim-vyazovick,Python,96 个字符!

  • 3 位,@qwertiy,Python,100 个字符!

比赛的获胜者将获得100点声誉的奖励。


通过投票

  • 第一名,@qwertiy,没有脚本和文本的 HTML,12 票!

  • 第二名,@extrn,Haskell,11 票!

  • 第三名,@aepot,C#,7 票!

获胜者的答案被标记为正确。


感谢大家的参与!提供的答案令人惊叹!

массивы
  • 19 19 个回答
  • 953 Views

19 个回答

  • Voted
  1. Best Answer
    Qwertiy
    2023-10-13T03:24:28Z2023-10-13T03:24:28Z

    没有脚本和文本的 HTML,3955 3849 2318

    输入数据由选中的复选框的数量指定。

    不幸的是,这里的标记指定了计数器的使用。
    下面较长的解决方案没有这个。

    * { font-weight: normal }
    body { counter-reset: i }
    tr { counter-increment: i; counter-reset: j }
    tr:nth-child(n + 10) { counter-increment: i -1 }
    tr > * { counter-increment: j }
    tr > :nth-child(n + 10) { counter-increment: j -1 }
    th::before { content: counter(i) }
    td::before { content: counter(j) }
    
    tr, th, td { display: none }
    
    #a:checked ~ * :first-child,
    #b:checked ~ * :is(:nth-child(2), :last-child),
    #c:checked ~ * :is(:nth-child(3), :nth-last-child(2)),
    #d:checked ~ * :is(:nth-child(4), :nth-last-child(3)),
    #e:checked ~ * :is(:nth-child(5), :nth-last-child(4)),
    #f:checked ~ * :is(:nth-child(6), :nth-last-child(5)),
    #g:checked ~ * :is(:nth-child(7), :nth-last-child(6)),
    #h:checked ~ * :is(:nth-child(8), :nth-last-child(7)),
    #i:checked ~ * :is(:nth-child(9), :nth-last-child(8)) {
      display: revert;
    }
    <input type=checkbox id=a checked disabled><input type=checkbox id=b checked><input type=checkbox id=c checked><input type=checkbox id=d><input type=checkbox id=e><input type=checkbox id=f><input type=checkbox id=g><input type=checkbox id=h><input type=checkbox id=i>
    <table>
      <tr><th><th><th><th><th><th><th><th><th><th><th><th><th><th><th><th><th></tr>
      <tr><td><th><th><th><th><th><th><th><th><th><th><th><th><th><th><th><td></tr>
      <tr><td><td><th><th><th><th><th><th><th><th><th><th><th><th><th><td><td></tr>
      <tr><td><td><td><th><th><th><th><th><th><th><th><th><th><th><td><td><td></tr>
      <tr><td><td><td><td><th><th><th><th><th><th><th><th><th><td><td><td><td></tr>
      <tr><td><td><td><td><td><th><th><th><th><th><th><th><td><td><td><td><td></tr>
      <tr><td><td><td><td><td><td><th><th><th><th><th><td><td><td><td><td><td></tr>
      <tr><td><td><td><td><td><td><td><th><th><th><td><td><td><td><td><td><td></tr>
      <tr><td><td><td><td><td><td><td><td><th><td><td><td><td><td><td><td><td></tr>
      <tr><td><td><td><td><td><td><td><td><th><td><td><td><td><td><td><td><td></tr>
      <tr><td><td><td><td><td><td><td><th><th><th><td><td><td><td><td><td><td></tr>
      <tr><td><td><td><td><td><td><th><th><th><th><th><td><td><td><td><td><td></tr>
      <tr><td><td><td><td><td><th><th><th><th><th><th><th><td><td><td><td><td></tr>
      <tr><td><td><td><td><th><th><th><th><th><th><th><th><th><td><td><td><td></tr>
      <tr><td><td><td><th><th><th><th><th><th><th><th><th><th><th><td><td><td></tr>
      <tr><td><td><th><th><th><th><th><th><th><th><th><th><th><th><th><td><td></tr>
      <tr><td><th><th><th><th><th><th><th><th><th><th><th><th><th><th><th><td></tr>
    </table>

    缩小版:

    <input type=checkbox id=a checked disabled><input type=checkbox id=b checked><input type=checkbox id=c checked><input type=checkbox id=d><input type=checkbox id=e><input type=checkbox id=f><input type=checkbox id=g><input type=checkbox id=h><input type=checkbox id=i><table><tr><th><th><th><th><th><th><th><th><th><th><th><th><th><th><th><th><th></tr><tr><td><th><th><th><th><th><th><th><th><th><th><th><th><th><th><th><td></tr><tr><td><td><th><th><th><th><th><th><th><th><th><th><th><th><th><td><td></tr><tr><td><td><td><th><th><th><th><th><th><th><th><th><th><th><td><td><td></tr><tr><td><td><td><td><th><th><th><th><th><th><th><th><th><td><td><td><td></tr><tr><td><td><td><td><td><th><th><th><th><th><th><th><td><td><td><td><td></tr><tr><td><td><td><td><td><td><th><th><th><th><th><td><td><td><td><td><td></tr><tr><td><td><td><td><td><td><td><th><th><th><td><td><td><td><td><td><td></tr><tr><td><td><td><td><td><td><td><td><th><td><td><td><td><td><td><td><td></tr><tr><td><td><td><td><td><td><td><td><th><td><td><td><td><td><td><td><td></tr><tr><td><td><td><td><td><td><td><th><th><th><td><td><td><td><td><td><td></tr><tr><td><td><td><td><td><td><th><th><th><th><th><td><td><td><td><td><td></tr><tr><td><td><td><td><td><th><th><th><th><th><th><th><td><td><td><td><td></tr><tr><td><td><td><td><th><th><th><th><th><th><th><th><th><td><td><td><td></tr><tr><td><td><td><th><th><th><th><th><th><th><th><th><th><th><td><td><td></tr><tr><td><td><th><th><th><th><th><th><th><th><th><th><th><th><th><td><td></tr><tr><td><th><th><th><th><th><th><th><th><th><th><th><th><th><th><th><td></tr></table><style>*{font-weight:400}body{counter-reset:i}tr{counter-increment:i;counter-reset:j}tr:nth-child(n+10){counter-increment:i -1}tr>*{counter-increment:j}tr>:nth-child(n+10){counter-increment:j -1}th::before{content:counter(i)}td::before{content:counter(j)}td,th,tr{display:none}#a:checked~* :first-child,#b:checked~* :is(:nth-child(2),:last-child),#c:checked~* :is(:nth-child(3),:nth-last-child(2)),#d:checked~* :is(:nth-child(4),:nth-last-child(3)),#e:checked~* :is(:nth-child(5),:nth-last-child(4)),#f:checked~* :is(:nth-child(6),:nth-last-child(5)),#g:checked~* :is(:nth-child(7),:nth-last-child(6)),#h:checked~* :is(:nth-child(8),:nth-last-child(7)),#i:checked~* :is(:nth-child(9),:nth-last-child(8)){display:revert}</style>

    更有趣的解决方案,3849

    div { --c: j; counter-increment: i; counter-reset: j }
    div:nth-child(n+10) { counter-increment: i -1 }
    x { counter-increment: j }
    x:nth-child(n+10) { counter-increment: j -1 }
    x::before { content: counter(var(--c)) " " }
    
    div, x { display: none }
    
    #a:checked ~ * :first-child,
    #b:checked ~ * :is(:nth-child(2), :last-child),
    #c:checked ~ * :is(:nth-child(3), :nth-last-child(2)),
    #d:checked ~ * :is(:nth-child(4), :nth-last-child(3)),
    #e:checked ~ * :is(:nth-child(5), :nth-last-child(4)),
    #f:checked ~ * :is(:nth-child(6), :nth-last-child(5)),
    #g:checked ~ * :is(:nth-child(7), :nth-last-child(6)),
    #h:checked ~ * :is(:nth-child(8), :nth-last-child(7)),
    #i:checked ~ * :is(:nth-child(9), :nth-last-child(8)) {
      display: revert;
    }
    
    div:is(:nth-child(1), :nth-last-child(1)) > :nth-child(n+1):nth-last-child(n+1),
    div:is(:nth-child(2), :nth-last-child(2)) > :nth-child(n+2):nth-last-child(n+2),
    div:is(:nth-child(3), :nth-last-child(3)) > :nth-child(n+3):nth-last-child(n+3),
    div:is(:nth-child(4), :nth-last-child(4)) > :nth-child(n+4):nth-last-child(n+4),
    div:is(:nth-child(5), :nth-last-child(5)) > :nth-child(n+5):nth-last-child(n+5),
    div:is(:nth-child(6), :nth-last-child(6)) > :nth-child(n+6):nth-last-child(n+6),
    div:is(:nth-child(7), :nth-last-child(7)) > :nth-child(n+7):nth-last-child(n+7),
    div:is(:nth-child(8), :nth-last-child(8)) > :nth-child(n+8):nth-last-child(n+8),
    div:is(:nth-child(9), :nth-last-child(9)) > :nth-child(n+9):nth-last-child(n+9) {
      --c: i;
    }
    <input type=checkbox id=a checked disabled><input type=checkbox id=b checked><input type=checkbox id=c checked><input type=checkbox id=d><input type=checkbox id=e><input type=checkbox id=f><input type=checkbox id=g><input type=checkbox id=h><input type=checkbox id=i>
    <main>
      <div><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x></div>
      <div><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x></div>
      <div><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x></div>
      <div><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x></div>
      <div><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x></div>
      <div><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x></div>
      <div><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x></div>
      <div><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x></div>
      <div><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x></div>
      <div><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x></div>
      <div><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x></div>
      <div><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x></div>
      <div><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x></div>
      <div><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x></div>
      <div><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x></div>
      <div><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x></div>
      <div><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x></div>
    </main>

    缩小版:

    <style>div{--c:j;counter-increment:i;counter-reset:j}div:nth-child(n+10){counter-increment:i -1}x{counter-increment:j}x:nth-child(n+10){counter-increment:j -1}x::before{content:counter(var(--c)) " "}div,x{display:none}#a:checked~* :first-child,#b:checked~* :is(:nth-child(2),:last-child),#c:checked~* :is(:nth-child(3),:nth-last-child(2)),#d:checked~* :is(:nth-child(4),:nth-last-child(3)),#e:checked~* :is(:nth-child(5),:nth-last-child(4)),#f:checked~* :is(:nth-child(6),:nth-last-child(5)),#g:checked~* :is(:nth-child(7),:nth-last-child(6)),#h:checked~* :is(:nth-child(8),:nth-last-child(7)),#i:checked~* :is(:nth-child(9),:nth-last-child(8)){display:revert}div:is(:first-child,:last-child)>:nth-child(n+1):nth-last-child(n+1),div:is(:nth-child(2),:nth-last-child(2))>:nth-child(n+2):nth-last-child(n+2),div:is(:nth-child(3),:nth-last-child(3))>:nth-child(n+3):nth-last-child(n+3),div:is(:nth-child(4),:nth-last-child(4))>:nth-child(n+4):nth-last-child(n+4),div:is(:nth-child(5),:nth-last-child(5))>:nth-child(n+5):nth-last-child(n+5),div:is(:nth-child(6),:nth-last-child(6))>:nth-child(n+6):nth-last-child(n+6),div:is(:nth-child(7),:nth-last-child(7))>:nth-child(n+7):nth-last-child(n+7),div:is(:nth-child(8),:nth-last-child(8))>:nth-child(n+8):nth-last-child(n+8),div:is(:nth-child(9),:nth-last-child(9))>:nth-child(n+9):nth-last-child(n+9){--c:i}</style><input type=checkbox id=a checked disabled><input type=checkbox id=b checked><input type=checkbox id=c checked><input type=checkbox id=d><input type=checkbox id=e><input type=checkbox id=f><input type=checkbox id=g><input type=checkbox id=h><input type=checkbox id=i><main><div><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x></div><div><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x></div><div><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x></div><div><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x></div><div><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x></div><div><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x></div><div><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x></div><div><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x></div><div><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x></div><div><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x></div><div><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x></div><div><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x></div><div><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x></div><div><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x></div><div><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x></div><div><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x></div><div><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x><x></x></div></main>

    • 12
  2. extrn
    2023-10-11T08:03:54Z2023-10-11T08:03:54Z

    哈斯克尔,55 64 66

    f n|u<-show$div(10^n)9^2=unlines[(:" ").min x=<<u|x<-u]
    

    在线尝试一下!

    • 11
  3. Qwertiy
    2023-10-13T02:04:00Z2023-10-13T02:04:00Z

    JavaScript,106 105

    n=>(n*=2," ".repeat(n-1)+"\n").repeat(n-1).replace(/ /g,(m,i)=>Math.min(1+i%n,1+i/n|0,n-i%n-1,n+~(i/n))+m)
    

    f=n=>(n*=2," ".repeat(n-1)+"\n").repeat(n-1).replace(/ /g,(m,i)=>Math.min(1+i%n,1+i/n|0,n-i%n-1,n+~(i/n))+m)
    for(q=1;q<10;++q)console.log(f(q))
    .as-console-wrapper.as-console-wrapper{max-height:100vh}

    • 9
  4. extrn
    2023-10-17T09:02:23Z2023-10-17T09:02:23Z

    蟒蛇,82 85

    def f(n):r=str((10**n//9)**2);return'\n'.join(' '.join(map(min,r,x*17))for x in r)
    

    在线尝试一下!

    • 9
  5. Acinit
    2023-10-10T20:10:52Z2023-10-10T20:10:52Z

    蟒蛇,100 101 102 115

    根据经典,我是第一

    def f(h):q=range(1,h*2);return'\n'.join(' '.join(str(h-max(abs(h-i),abs(h-j)))for j in q)for i in q)
    

    用法

    height = int(input("Введите высоту пирамиды (от 1 до 9): "))
    result = f(height)
    print(result)
    

    终端:

    Введите высоту пирамиды (от 1 до 9): 5
    1 1 1 1 1 1 1 1 1
    1 2 2 2 2 2 2 2 1
    1 2 3 3 3 3 3 2 1
    1 2 3 4 4 4 3 2 1
    1 2 3 4 5 4 3 2 1
    1 2 3 4 4 4 3 2 1
    1 2 3 3 3 3 3 2 1
    1 2 2 2 2 2 2 2 1
    1 1 1 1 1 1 1 1 1
    

    感谢@n1tr0xs、@Gleb的减少建议!

    • 9
  6. Byb
    2023-10-11T23:55:19Z2023-10-11T23:55:19Z

    爪哇,156

    最小化版本:

    String f(int h){int n=h*2-1;String s="";for(int i=0,k=0;i<n;++i,k=(i<h)?i:h-i%h-2){for(int j=0;j<n;++j){s+=(j<=k?j+1:j<n-k?k+1:n-j)+" ";}s+="\n";}return s;}
    

    可读版本:

    String f(int h) {
        int n = h * 2 - 1;
        String s = "";
        for (int i = 0, k = 0; i < n; ++i, k = (i < h) ? i : h - i % h - 2) {
            for (int j = 0; j < n; ++j) {
                s += (j <= k ? j + 1 : j < n - k ? k + 1 : n - j) + " ";
            }
            s += "\n";
        }
        return s;
    }
    
    • 7
  7. Qwertiy
    2023-10-13T01:44:06Z2023-10-13T01:44:06Z

    Python 3.8+ ,108100

    lambda n:[r:=range((n:=2*n-2)+1),'\n'.join(' '.join(str(1+min(i,j,n-i,n-j))for j in r)for i in r)][1]
    

    运行tio

    f = lambda n:[r:=range((n:=2*n-2)+1),'\n'.join(' '.join(str(1+min(i,j,n-i,n-j))for j in r)for i in r)][1]
        
    print('\n\n'.join(f(n) for n in range(1,10)))
    

    旧版本(108):tio.run

    def f(n):
     n=2*n-2
     return'\n'.join(' '.join(str(1+min(i,j,n-i,n-j))for j in range(n+1))for i in range(n+1))
        
    print('\n\n'.join(f(n) for n in range(1,10)))
    
    • 7
  8. Зонтик
    2023-10-11T22:16:24Z2023-10-11T22:16:24Z

    爪哇,410

    也许他太聪明了,但事实就是如此。

    主意

    金字塔中的每条线都是回文。这意味着计算字符串的第一部分就足够了,字符串的第二部分是反转的第一部分

    整个金字塔也是如此:金字塔的第二部分是倒置的第一部分。

    代码

    1. 该函数的不可读版本:
    String f(int h){int l=1+(h*2-1)/2;String[]e=new String[l];Arrays.fill(e,"");int m=1;int c=1;for(int i=0;i<l;i++){for(int j= 0;j<l;j++){e[i]=e[i]+" "+c;if(c<m)c++;}e[i]+=new StringBuilder(e[i].substring(0,e[i].length()-1)).reverse().toString();e[i]+="\n";m++;c=1;}String s=String.join("",e);e[e.length - 1]="";s=s.substring(0,s.length()-1);s+=new StringBuilder(String.join("",e)).reverse().toString();return s;}
    
    1. 完整代码(可读函数+用法):
    import java.util.Scanner;
    import java.util.Arrays;
    
    public class CreatingPyramid {
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            System.out.println("Введите высоту пирамиды (число от 1 до 9):");
            int higthOfPyramid = scanner.nextInt();
            System.out.println("Пирамида:");
            CreatingPyramid creating = new CreatingPyramid();
            System.out.println(creating.create(higthOfPyramid));
        }
    
        String create(int hight) {
            int length = 1 + (hight*2 - 1) / 2;
            String[] lines = new String[length];
            Arrays.fill(lines, "");
            int maxNumber = 1;
            int currentNumber = 1;
            for (int i = 0; i < length; i++){
                for (int j = 0; j < length; j++){
                    lines[i] = lines[i] + " " + currentNumber;
                    if(currentNumber < maxNumber) currentNumber++;
                }
                lines[i] += new StringBuilder(lines[i].substring(0, lines[i].length() - 1)).reverse().toString();
                lines[i] += "\n";
                maxNumber++;
                currentNumber = 1;
            }
            String result = String.join("", lines);
            lines[lines.length - 1] = "";
            result = result.substring(0, result.length() - 1);
            result += new StringBuilder(String.join("", lines)).reverse().toString();
            return result;
        }
    }
    

    考试

    运行代码

    该函数的另一个用例

    最酷的使用这样的函数(尽管此代码很可能不会在在线编译器中运行,因为它有图形界面):

    import javax.swing.JOptionPane;
    import javax.swing.UIManager;
    
    ..........
    
    public static void main(String[] args) {
        UIManager.put("OptionPane.cancelButtonText", "Отмена");
        Integer[] options = {1, 2, 3, 4, 5, 6, 7, 8, 9};
        int higthOfPyramid = (Integer)JOptionPane.showInputDialog(null, 
                "Какая будет высота пирамиды?", "Выбор высоты", 
                JOptionPane.QUESTION_MESSAGE, null, options, options[2]);
    
        CreatingPyramid creating = new CreatingPyramid();
        JOptionPane.showMessageDialog(null, "Ваша пирамида:\n" + 
                creating.create(higthOfPyramid), "Результат",
                JOptionPane.INFORMATION_MESSAGE);
    }
    
    ............
    

    输出是这样的:

    选择金字塔的高度(我选择了9)

    在对话框中显示金字塔

    • 7
  9. Yuki
    2023-10-11T14:54:23Z2023-10-11T14:54:23Z

    C#, 194

    string f(int n){int i,j,r=n-1,v;string s="",q ="",w,l="\n";for(i=0;i<=r;i++){v=n-i;for(j=0;j<=r;j++){if(i>0&&j>0&&i+1-j>0)v++;w=(v-j)+" ";q=(j==0?v+" ":w+q+w);}s=i==0?l+q+l:l+q+s+q+l;}return s;}
    

    这是一个更易读的版本:

    string f(int n)
    {
        int i, j, r = n - 1, v;
        string s = "", q = "", w, l = "\n";
        for (i = 0; i <= r; i++)
        {
            v = n - i;
            for (j = 0; j <= r; j++)
            {
                if (i > 0 && j > 0 && i + 1 - j > 0)
                    v++;
                w = (v - j) + " "; q = (j == 0 ? v + " " : w + q + w);
            }
            s = i == 0 ? l + q + l : l + q + s + q + l;
        }
        return s;
    }
    
    • 7
  10. aepot
    2023-10-13T04:49:55Z2023-10-13T04:49:55Z

    C#, 107

    附公告 (107)

    using static System.Math;
    
    string f(int n){var s="";for(int i=-n,j;++i<n;s+='\n')for(j=-n;++j<n;)s+=n-Max(Abs(i),Abs(j))+" ";return s;}
    

    暂无公告 (117)

    string f(int n){var s="";for(int i=-n,j;++i<n;s+='\n')for(j=-n;++j<n;)s+=n-Math.Max(i<0?-i:i,j<0?-j:j)+" ";return s;}
    

    带广告的 Linq,仅供娱乐 (115)

    using static System.Math;
    using static System.Linq.Enumerable;
    using static System.String;
    
    string f(int n)=>Join('\n',Range(1-n,n*2-1).Select(i=>Join(" ",Range(1-n,n*2-1).Select(j=>n-Max(Abs(i),Abs(j))))));
    // или так
    string f(int n){var x=Range(1-n,n*2-1);return Join('\n',x.Select(i=>Join(" ",x.Select(j=>n-Max(Abs(i),Abs(j))))));}
    

    我还找到了一个替代方案Max(Abs(i),Abs(j))- Sqrt(Max(i*i,j*j)),但字符数完全相同。

    • 7

相关问题

  • Node.js如何通过参数将数组拆分为多个部分

  • 如何在 Kotlin 中创建一个特定长度的空字符串数组?

  • 查找和修改数组中的结构

  • 我找不到疏忽,应该从最大到最小显示数字,但相反

  • 如何显示没有重复值的数组元素?

  • 替换数组中的匹配项

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5