丹尼斯高尔夫温度计


74

丹尼斯为此社区付出了巨大的努力,包括担任主持人语言设计师TIO提供者。

不幸的是,他的四岁女儿得了感冒,所以让我们所有人为他提供温度计,以帮助她了解自己的康复情况(可能很快):

.-----------.
|           |
|           |
'-.       .-'
.-'   -   '-.
|107.6- 42.0|
|106.7- 41.5|
|105.8- 41.0|
|104.9- 40.5|
|104.0- 40.0|
|103.1- 39.5|
|102.2- 39.0|
|101.3- 38.5|
|100.4- 38.0|
| 99.5- 37.5|
| 98.6- 37.0|
| 97.7- 36.5|
| 96.8- 36.0|
| 95.9- 35.5|
| 95.0- 35.0|
'---. - .---'
    | - |
    |---|
    |   |
    '---'

由于Dennis没有太多时间阅读代码,因此您必须使代码尽可能短。


13
形状使我想起了更多的妊娠试验。
魔术章鱼缸

3
@carusocomputing他付出了巨大的努力。也许他所做的一切对他来说真的很容易。他有没有提到过很难?
亚当

8
噢,希望她好起来。无论如何,我给谁制造一个功能温度计+100悬赏!:P
Matthew Roh

4
@SIGSEGV 在线尝试!-
亚当

5
@SIGSEGV将会是一种威胁。
魔术章鱼缸

Answers:


16

Jelly90 89 84 83 82 字节

-1字节感谢埃里克Outgolfer(替换10

15r1×€9,5+“£Ȧ“¡^’d⁵Dj€€”.j€⁾- Uz⁶ZUj@€⁾||
“¡ẹƭgụḌẊṘgYƊxyẓṡƝçƤ5ȥṭ’ṃ“.| '-”s7ŒBs5j¢Y

在线尝试!

怎么样?

15r1×€9,5+“£Ȧ“¡^’d⁵Dj€€”.j€⁾- Uz⁶ZUj@€⁾|| - Link 1, body: no arguments
15r1                                      - inclusive range(15,1)      = [15,14,...,2,1]
      9,5                                 - pair nine with five        = [9,5]
    ×€                                    - multiply for €ach          = [[135,75],[126,70],...,[18,10],[9,5]]
          “£Ȧ“¡^’                         - list of base 250 numbers   = [941,345]
         +                                - addition                   = [[1076,420],[1067,415],...,[959,355],[950,350]]
                 d⁵                       - div&mod 10                 = [[[107,6],[42,0]],[[106,7],[41,5]],...,[[95,9],[35,5]],[[95,0],[35,0]]]
                   D                      - convert to decimal lists   = [[[[1,0,7],6],[[4,2],0]],[[[1,0,6],7],[[4,1],5]],...,[[[9,5],9],[[3,5],5]],[[[9,5],0],[[3,5],0]]]
                       ”.                 - literal '.'
                    j€€                   - join €ach for €ach         = [[[1,0,7,'.',6],[4,2,'.',0]],[[1,0,6,'.',7],[4,1,'.',5]],...,[[9,5,'.',9],[3,5,'.',5]],[[9,5,'.',0],[3,5,'.',0]]]
                           ⁾- <space      - literal ['-',' ']
                         j€               - join €ach                  = [[1,0,7,'.',6,'-',' ',4,2,'.',0],[1,0,6,'.',7,'-',' ',4,1,'.',5],...,[9,5,'.',9,'-',' ',3,5,'.',5],[9,5,'.',0,'-',' ',3,5,'.',0]]
                              U           - upend (reverse each)       = [[0,'.',2,4,' ','-',6,'.',7,0,1],[5,'.',1,4,' ','-',7,'.',6,0,1],...,[0,'.',5,3,' ','-',9,'.',5,9],[0,'.',5,3,' ','-',0,'.',5,9]]
                               z⁶         - transpose space filler     = [[0,5,...,5,0],['.','.',...,'.','.'],[2,1,...,5,5],[4,4,...,3,3],[' ',' ',...,' ',' '],['-','-',...,'-','-'],[6,7,...,9,0],['.','.',...'.','.'],[7,6,...,5,5],[0,0,...,9,9],[1,1,...,' ',' ']]
                                 Z        - transpose                  = [[0,'.',2,4,' ','-',6,'.',7,0,1],[5,'.',1,4,' ','-',7,'.',6,0,1],...,[5,'.',5,3,' ','-',9,'.',5,9,' '],[0,'.',5,3,' ','-',0,'.',5,9,' ']]
                                  U       - upend                      = [[1,0,7,'.',6,'-',' ',4,2,'.',0],[1,0,6,'.',7,'-',' ',4,1,'.',5],...,[' ',9,5,'.',9,'-',' ',3,5,'.',5],[' ',9,5,'.',0,'-',' ',3,5,'.',0]]
                                      ⁾|| - literal ['|','|']
                                   j@€    - join €ach (reversed @rgs)  = [['|',1,0,7,'.',6,'-',' ',4,2,'.',0,'|'],['|',1,0,6,'.',7,'-',' ',4,1,'.',5,'|'],...,['|',' ',9,5,'.',9,'-',' ',3,5,'.',5,'|'],['|',' ',9,5,'.',0,'-',' ',3,5,'.',0,'|']]
                                          -                  effectively ["|107.6- 42.0|","|106.7- 41.5|","|105.8- 41.0|","|104.9- 40.5|","|104.0- 40.0|","|103.1- 39.5|","|102.2- 39.0|","|101.3- 38.5|","|100.4- 38.0|","| 99.5- 37.5|","| 98.6- 37.0|","| 97.7- 36.5|","| 96.8- 36.0|","| 95.9- 35.5|","| 95.0- 35.0|"]

“¡ẹƭgụḌẊṘgYƊxyẓṡƝçƤ5ȥṭ’ṃ“.| '-”s7ŒBs5j¢Y - Main link: no arguments   (using "..." below to represent lists of characters)
“¡ẹƭgụḌẊṘgYƊxyẓṡƝçƤ5ȥṭ’                  - base 250 number     =  1694125525350532761476179586378844141697690917975
                        “.| '-”          - literal ['.','|',' ',"'",'-']
                       ṃ                 - base decompression  =  ".------|      |      '-.    .-'   -'---. -    | -    |--    |      '--"
                               s7        - split into 7s       =  [".------","|      ","|      ","'-.    ",".-'   -","'---. -","    | -","    |--","    |  ","    '--"]
                                 ŒB      - bounce (vectorises) =  [".-----------.","|           |","|           |","'-.       .-'",".-'   -   '-.","'---. - .---'","    | - |    ","    |---|    ","    |   |    ","    '---'    "]
                                   s5    - split into 5s       = [[".-----------.","|           |","|           |","'-.       .-'",".-'   -   '-."],["'---. - .---'","    | - |    ","    |---|    ","    |   |    ","    '---'    "]]
                                      ¢  - call last link (1) as a nilad
                                     j   - join                = (using "..." below to represent mixed-type lists from the result of ¢)
                                                               = [".-----------.","|           |","|           |","'-.       .-'",".-'   -   '-.","|107.6- 42.0|","|106.7- 41.5|","|105.8- 41.0|","|104.9- 40.5|","|104.0- 40.0|","|103.1- 39.5|","|102.2- 39.0|","|101.3- 38.5|","|100.4- 38.0|","| 99.5- 37.5|","| 98.6- 37.0|","| 97.7- 36.5|","| 96.8- 36.0|","| 95.9- 35.5|","| 95.0- 35.0|","'---. - .---'","    | - |    ","    |---|    ","    |   |    ","    '---'    "]
                                       Y - join with newlines  = :
                                                                 .-----------.
                                                                 |           |
                                                                 |           |
                                                                 '-.       .-'
                                                                 .-'   -   '-.
                                                                 |107.6- 42.0|
                                                                 |106.7- 41.5|
                                                                 |105.8- 41.0|
                                                                 |104.9- 40.5|
                                                                 |104.0- 40.0|
                                                                 |103.1- 39.5|
                                                                 |102.2- 39.0|
                                                                 |101.3- 38.5|
                                                                 |100.4- 38.0|
                                                                 | 99.5- 37.5|
                                                                 | 98.6- 37.0|
                                                                 | 97.7- 36.5|
                                                                 | 96.8- 36.0|
                                                                 | 95.9- 35.5|
                                                                 | 95.0- 35.0|
                                                                 '---. - .---'
                                                                     | - |
                                                                     |---|
                                                                     |   |
                                                                     '---'

12

批处理,325字节

@echo off
for %%l in ("|           |" "|           |" "'-.       .-'" ".-'   -   '-.")do echo %%~l
set/ac=42,d=5
for /l %%f in (1076,-9,950)do call:c %%f
for %%l in ("'---. - .---'" "    | - |" "    |---|" "    |   |" "    '---'")do echo %%~l
exit/b
:c
set f= %1
set/ac-=!d,d=5-d
echo ^|%f:~-4,-1%.%f:~-1%- %c%.%d%^|

11

SOGL98 97 字节

▼⅜¦┌Υ   υl←│Γφγ⅔3wο╚°⁸ofč√&@⁶‘O’⁴∫ |O:9L/*’a6L/+;-l4=?@o}oƧ- o12/*’ ;-o |o"ģ⌠℮Ζ║Kgš‰¶¶ksθ○╤Ƨ%←└⅟ΟS‘

注意:靠近程序开始的3个空格是一个制表符

说明:

...‘O                                                  output the beginning part
     ’⁴∫                                               repeat 15 times, pushing (0-indexed iteration)
         |O                                            output in a new line "|"
           :                                           duplicate the iteration
            9L/                                        push 0.9 (9/10)
               *                                       multiply [0.9 and the iteration]
                ’a6L/+                                 push 107.6 (107+6/10)
                      ;-                               reverse subtract (107.6 - 0.9*iteration)
                        l4=?  }                        if length is 4
                            @o                           output a space
                               o                       output the number
                                Ƨ- o                   output "- "
                                    12/                push 0.5 (1/2)
                                       *               multiply that by iteration
                                        ’              push 42
                                          ;-           reverse subtract (42-0.5*iteration)
                                            o          output that
                                              |o       output "|"
                                                "...‘  push the ending part

为了节省一个字节,我使它每次在循环中都推送结束字符串,这样它才可以输出一次。


4
丹尼斯(Dennis)希望您增加一种在线尝试的方式,这样他就不必花时间陪女儿找出在哪里可以找到SOGL编译器。
owlswipe

1
SOGL的压缩从未间断,给我留下深刻的印象
Kritixi Lithos 17-4-27的

1
@owlswipe当SOGL处于繁重的开发过程中(例如,不久之后,我将发布一个使用功能或压缩功能破坏所有程序的版本(我希望这是最后一次)),在线尝试东西将不是优先考虑
dzaima

2
@dzaima我没意识到您亲自制作了SOGL!太酷了,因为没有编译器而被原谅了:))
owlswipe 17-04-27

9

V,113字节

i|1076- 420|14ñÙ9l5ñÎeé.$hé.
ç|9/á 
o'³-. - .³-'
| - |
|³-|
|³ |
'³-'4>3kHO.±±-.
|±± |Ùo'-.· .-'
.-'³ -³ '-.

在线尝试!

十六进制转储:

00000000: 697c 3130 3736 2d20 3432 307c 1b31 34f1  i|1076- 420|.14.
00000010: d939 186c 3518 f1ce 65e9 2e24 68e9 2e0a  .9.l5...e..$h...
00000020: e77c 392f e120 0a6f 27b3 2d2e 202d 202e  .|9/. .o'.-. - .
00000030: b32d 270a 7c20 2d20 7c0a 7cb3 2d7c 0a7c  .-'.| - |.|.-|.|
00000040: b320 7c0a 27b3 2d27 1b34 3e33 6b48 4f2e  . |.'.-'.4>3kHO.
00000050: b1b1 2d2e 0a7c b1b1 207c 1bd9 6f27 2d2e  ..-..|.. |..o'-.
00000060: b720 2e2d 270a 2e2d 27b3 202d b320 272d  . .-'..-'. -. '-
00000070: 2e                                       .

途中还有更多高尔夫活动!


1
丹尼斯不了解代码到底是如何工作的,但是赞赏它在很少的字节中工作得很好。
owlswipe

@owlswipe我对此表示怀疑。我们在这里谈论丹尼斯;他知道一切正常。; p
Kevin Cruijssen

@KevinCruijssen也许:))。我不知道这是如何工作的!
owlswipe

@owlswipe都不用,所以我同意可以使用一个解释。:)
凯文·克鲁伊森

7

PHP,187字节

在变量中存储4个空格可节省7个字节

<?=".-----------.
|",$f="    ","$f   |
|$f$f   |
'-.$f   .-'
.-'   -   '-.
";for($n=85;--$n>69;)printf("|%5.1f-%5.1f|
",$n*.9+32,$n/2);echo"'---. - .---'
$f| - |
$f|---|
$f|   |
$f'---'";

在线尝试!

PHP,188字节

<?$s=".000--.
|1223|1223'-.12.-'
.-'1-1'-.
4";for($n=85;--$n>69;)$t.=sprintf("|%5.1f-%5.1f|
",$n*.9+32,$n/2);$s.="'0. - .0'
2| - 32|032|132'0'";echo strtr($s,["---","   ","    ","|
",$t]);

在线尝试!

PHP,220字节

<?=gzinflate(base64_decode("XZBJCkUhDAT3niI7VzbOw908/O/EwIMviCnLQBukbyFc+db9o5jgNVIM3KwSd9S+khdmkl6Rr9LEIhUMo4Ft9FzHIWV3HdnouYaSpB13FdXouYJG2u4yupE6OewgLXNytmYhPbc0S5vupmYhPTc0SxvuhmYhZf0t58H/gWcMNgHSfRXvvLLJiE2B734="));

在线尝试!

PHP,247字节

<?=bzdecompress(base64_decode("QlpoNDFBWSZTWREU1+kAAEnYgEiQQIN/4AAEMAC6bDTRA1NBtqglJ7VIA0AJNSEAAXhknxmxdEkbQhoFWMYrEL1cASWoMYgwHEpJJJKZmZ638CwPCeQHBCLKs3qj1vvz37lF4trWtWviLC4wJoHJywEMA8GmAh2WwUSEom/JeNAioiokhJa9V5bL02pVVVXw+EiwPxdyRThQkBEU1+k="));

在线尝试!


5

Python 2,163字节

i=89
for x in("------.x|x|x.-'x-   '-."+"x"*16+"- .---'x- |x--|x  |x--'").split('x'):y='%%-77ss'[i>80::2]%x;print['|%5s- %s|'%(32+.9*i,i/2.),y[:0:-1]+y][x>''];i-=1

在线尝试!


我参加这个聚会很晚,但是y='%*s'%(i/80*14-7,x)节省了一个字节。
林恩

4

///,261字节

/`/\/\///i/|
|`~/---`_/   `+/- `f/.5`z/.0`(/i10`)/i 9`!/|
    |/
.--~~~.
|  ___i  ___|
'-. __.-'
.-'_-_'-.
|107.6+42z(6.7+41f(5.8+41z(4.9+40f(4.0+40z(3.1+39f(2.2+39z(1.3+38f(0.4+38z)9f+37f)8.6+37z)7.7+36f)6.8+36z)5.9+35f)5.0+35z|
'~. - .~'
    | - !~!_|
    '~'

在线尝试!

通过使用诸如---替换之类的常见事件来工作。没有什么花哨。


4

APL(Dyalog) 144个 143 字节SBCS

m←⊢,1↓⌽
1'.||',⍣211/⍪3d'-'
m 7a←∪∊z←⊂'''---. -'
m(6↑⌽a),d
⊃{'|',⍵,'-',⍺,'|'}/(5 1⍕⍪)¨35 95+↓.5 .9∘.×⌽⍳15
m¨z7↑¨'| -' '|--' '|  ' '''--'

在线尝试!


3

Mathematica 247字节

嗯...和PHP一样

Uncompress@"1:eJxtkLsNAyEQRM+d4OgiRssf2rBTR27ADdCG+/WAODYxEkL7eKDR3N+fx/N7Ow5YXXiJ893o6n/BabFG2HMAHhws97n+cFKQrYke0hfIKAQO6QIJdYJtRDQCUSNCJthGgLMmNDU8/ATbcAgEVQ1BnGAZpvE1QbkM0+pISrCNMpKGrEYeSQm2kUbSkNRIIymBrILYJfsY3c6CZnUEfQ+80eEq1swG+eYH1XhZzA=="

3

JavaScript(ES6),198个字节

数字格式在JS中有点昂贵,而且我似乎对这种字节数感到困惑。这次您赢了,PHP!;-)

let f =

_=>`.222--.
|56|
|56|
'-.7.-'
.-'3-3'-.
000000000111111'2. - .2'
4| - |
4|2|
4|3|
4'2'`.replace(/\d/g,n=>['|'+(s=F(32+.9*i)+`- ${F(i--/2)}|
`),'| '+s,'---'][n]||' '.repeat(n),i=94,F=v=>v.toFixed(1))

console.log(f())


1
我希望您对我可以再节省8个字节不感到生气。谢谢你的提醒尝试第二种方法有strtr
约尔格Hülsermann

1
@JörgHülsermann不用担心!:) 做得好!
Arnauld

3

Japt,106字节

[".{6î-}
|
'-.
.-'   -"y y 9"'
-
-
-
.|||'
  - -
--- -"y]·mê0R d9FÆ"|{S+(#k6-9*X)t4n)i.J}- {½*Xn84)x1}|"÷

在线测试!

非常感谢@obarakon,他首先使代码生效,并且在打高尔夫球方面做了很多工作。

说明

首先我们有数据

[                                     // Create an array of:
  ".{6î-}\n|\n'-.\n.-'   -"           //   This string ({6î-} inserts 6 hyphens),
  y y                                 //   transposed twice to pad it with spaces;
  9                                   //   the number 9;
  "'\n-\n-\n-\n.|||'\n  - -\n--- -"   //   and this string,
  y                                   //   transposed once.
]·                                    // Join the array with newlines.

这给了我们

.------
|      
'-.    
.-'   -
9
'---. -
    | -
    |--
    |  
    '--

也就是说,温度计的左半部分用矩形替换了主矩形9。请注意,除了包含的行以外,每一行都用空格填充9

m  R   // Map each line with the function
 ê     //   ê, or "bounce"; mirrors the string about its last character ("abc" -> "abcba").
       // (The 0 is just filler because `m` expects the `R` to be the third parameter)

最终结果是它将温度计的左半部分镜像到右侧:

.-----------.
|           |
'-.       .-'
.-'   -   '-.
9
'---. - .---'
    | - |    
    |---|    
    |   |    
    '---'    

现在我们有了ASCII艺术部分,我们要做的就是放在主矩形中:

d9FÆ  "|{S+(#k 6-9*X)t4n)i.J}- {½ *Xn84)x1}|"Ã ·
d9FoX{"|{S+(1076-9*X)t4n)i.J}- {.5*Xn84)x1}|"} qR

  FoX{  ...  }        // Create the range [0...15), and map each item X to
"|{ ... }- { ... }"   //   this string, with the two blanks filled in with...

S+(1076-9*X)t4n)i.J
   1076-9*X           //   Calculate 1076 - 9*X. This gives us °F * 10.
S+(        )t4n)      //   Prepend a space and take only the last 4 chars.
                      //   This pads the entries under 100°F to the correct length.
                i.J   //   Insert a decimal point before the last char.
                      //   This turns e.g. "1076" to "107.6".

.5*Xn84)x1
   Xn84               //   Take 84 - X.
.5*    )              //   Multiply it by 0.5. This gives us °C.
        x1            //   Convert to a string with exactly 1 decimal point.

                qR    // Join the resulting array with newlines.
d9                    // In the thermometer art, replace "9" with the resulting string.

至此,我们的ASCII艺术生成会话结束了。下周收看更多使用Japt编写的ASCII美术类程序!


2

木炭,62字节

←⁶↓.↓²'-.¶.-'¶↓¹⁵'³↓.↓³'²M²↖¹↑×¹⁹-‖OM⁵¦¹⁶←E¹⁵⮌⁺⁺⁺⁹⁵×·⁹ι- ⁺³⁵⊘ι

在线尝试!链接是详细版本的代码。说明:

←⁶↓.↓²'-.¶.-'¶↓¹⁵'³↓.↓³'²M²↖¹↑×¹⁹-

打印温度计的左半部分。

‖O

反映它完成身体。

M⁵¦¹⁶←E¹⁵⮌⁺⁺⁺⁹⁵×·⁹ι- ⁺³⁵⊘ι

计算比例尺,然后颠倒并上下颠倒打印,以使其右对齐。在撰写本文时,Charcoal的串联运算符使用Python的内置函数将浮点数转换为字符串,str该内置.0函数会附加表示整数的浮点数,否则我将不得不求助于格式设置,因为其Cast运算符会特别避免这种行为。


1

vim,222次按键

:.!seq 42 -0.5 35
:%!awk '{printf("|\%5.1f- \%.1f|\n",1.8*$1+32,$1)}'
Go'===. - .==='<ESC>yy
:s/=/-/g
p
:.!tr "'.=" ' | '
:s/ *$/
yyP
:s/-/ /
ddpPlR---<ESC>yyGp
:s/|/'/g
ggO..<ESC>11i-<ESC>yyP
:.!tr .- '| '
yypo'-.<ESC>7a <ESC>a.-'<ENTER>.-'   -   '-.<ESC>

1

C,234个字节

main(i){float f=42;puts(".-----------.");for(;i--;)printf("|%*s|\n",11,"");puts("'-.       .-'\n.-'   -   '-.");for(;f>34.5;f-=.5)printf("|%5.1f- %.1f|\n",32+f*1.8,f);puts("'---. - .---'\n    | - |\n    |---|\n    |   |\n    '---'");}

在线尝试

输出:

.-----------.
|           |
|           |
'-.       .-'
.-'   -   '-.
|107.6- 42.0|
|106.7- 41.5|
|105.8- 41.0|
|104.9- 40.5|
|104.0- 40.0|
|103.1- 39.5|
|102.2- 39.0|
|101.3- 38.5|
|100.4- 38.0|
| 99.5- 37.5|
| 98.6- 37.0|
| 97.7- 36.5|
| 96.8- 36.0|
| 95.9- 35.5|
| 95.0- 35.0|
'---. - .---'
    | - |
    |---|
    |   |
    '---'

0

C,460个 265字节

#define P(x) puts(x);
#define Z "|           |"
T(){float i=7,j=12.6;P(".-----------.")P(Z)P(Z)P("'-.       .-'")P(".-'   -   '-.")while(i>=0)printf("|%5.1f- %.1f|\n",95+j,35+i),i-=.5,j-=.9;P("'---. - .---'")P("    | - |")P("    |---|")P("    |   |")P("    '---'")}

输出 实时

.-----------.
|           |
|           |
'-.       .-'
.-'   -   '-.
|107.6- 42.0|
|106.7- 41.5|
|105.8- 41.0|
|104.9- 40.5|
|104.0- 40.0|
|103.1- 39.5|
|102.2- 39.0|
|101.3- 38.5|
|100.4- 38.0|
| 99.5- 37.5|
| 98.6- 37.0|
| 97.7- 36.5|
| 96.8- 36.0|
| 95.9- 35.5|
| 95.0- 35.0|
'---. - .---'
    | - |
    |---|
    |   |
    '---'

1
这看起来不太打高尔夫球。您不能将两条相同的线合并吗?此外,你必须对所有行的主要空间
亚当

@Adám现在打高尔夫球。
Khaled.K

1
也许您可以定义四个空间并重用它们?对所有数字进行数学运算?
亚当

@Adámthx,现在进一步打高尔夫球。
Khaled.K

你错过最低气温:95.0- 35.0
亚当


0

C,222字节

f(){puts(".-----------.\n|           |\n|           |\n'-.       .-'\n.-'   -   '-.");for(float n=108.5,m=42.5;m>35;printf("|%5.1f- %.1f|\n",n-=.9,m-=.5));puts("'---. - .---'\n    | - |\n    |---|\n    |   |\n    '---'");}

尽管尝试缩短字符串,但以纯格式对其进行硬编码是最佳选择。我怀疑C语言是否有任何(重大的)改进。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.