根据要求的天气设置部落图腾


11

有一个苏城村。它有一个图腾:

             __
         ___|  |___
   \/    \        /    \/
   /\     ``|  |``     /\
  /^^\      |  |      /^^\
 / /\ \     |  |     / /\ \
''''''''''''''''''''''''''''

图腾让苏族人可以掌握天气情况,以帮助他们完成不同的任务。帮助村民适当地装饰图腾,以获取充足的天气。图腾包含以下几个部分:

             __
         ___|AA|___
   \/    \BBBBBBBB/    \/
   /\     ``|CC|``     /\
  /^^\      |DD|      /^^\
 / /\ \  13 |EE| 42  / /\ \
''''''''''''''''''''''''''''
  • A适用于太阳 () ww
  • B用于下雨 """"""""下雪 ::::::::
  • C雷雨 zz
  • D ~~
  • E用于 ==

但这还不是全部。图腾需要气象舞蹈演员。调用的元素越多,所需的舞者数量越多。如果调用了一个元素,则需要一个舞者。两个元素,两个舞者。除了四个元素之外,最多还会有四个舞者。如果没有调用任何元素,则不需要舞者。图腾需要休息。

天气舞者必须按顺序出现1234。例如,如果有两个舞者,槽12必须被占用。而且,每个舞者都表现出不同的身材:

  • 1T
  • 2Y
  • 3K
  • 4X

现在,村民们将表达他们的天气愿望。他们将说出一个句子,其中包含他们想要的天气元素。设置图腾和舞者以实现他们的愿望。

挑战

编写一个程序,该程序将字符串作为输入,匹配句子中的元素(sunrain,…),并输出图腾及其设置正确的舞者的整个村庄。您的程序不必检查输入字符串的正确性(例如,它不会同时包含suncloud)。它必须与单词匹配(按字面意义):

  • 输入字符串X says: "I like the wind, it blows the worries away"匹配wind,因为逗号不是单词的一部分
  • 输入的字符串Y says: "I hope the weather won't get too windy"wind不匹配,因为windywind是两个不同的词

确保匹配的单词在输入字符串的带引号的部分中(第一部分指定正在讲话的人永远不会包含可以匹配的单词)。

例子

The squaw says: "I want sun and wind for drying the clothes"
             __
         ___|()|___
   \/    \        /    \/
   /\     ``|  |``     /\
  /^^\      |~~|      /^^\
 / /\ \  T  |  |  Y  / /\ \
''''''''''''''''''''''''''''

The warrior thinks: "A good thunderstorm will afraid the invaders. Or a snow storm. Or an impenetrable fog. Or an oppressive sun."
             __
         ___|()|___
   \/    \::::::::/    \/
   /\     ``|zz|``     /\
  /^^\      |  |      /^^\
 / /\ \  TK |==| XY  / /\ \
''''''''''''''''''''''''''''

The papoose shouts: "I WANNA GO OUTSIDE PLAY UNDER THE SUN!"
             __
         ___|()|___
   \/    \        /    \/
   /\     ``|  |``     /\
  /^^\      |  |      /^^\
 / /\ \  T  |  |     / /\ \
''''''''''''''''''''''''''''

The wise grandma whispers: "The totem is an illusion"
             __
         ___|  |___
   \/    \        /    \/
   /\     ``|  |``     /\
  /^^\      |  |      /^^\
 / /\ \     |  |     / /\ \
''''''''''''''''''''''''''''

The shaman confides: "I perform my magic hidden in the fog, under the rain or at least under heavy clouds"
             __
         ___|ww|___
   \/    \""""""""/    \/
   /\     ``|  |``     /\
  /^^\      |  |      /^^\
 / /\ \  TK |==|  Y  / /\ \
''''''''''''''''''''''''''''

The village chief claims: "The meat of bison is better preserved in the snow, or dried under a burning sun. My Pa' used to say that heavy wind and a thunderstorm could help too, but I have no clue how. And despite everyone contradicting me, I am persuaded a good fog will do as well"
             __
         ___|()|___
   \/    \::::::::/    \/
   /\     ``|zz|``     /\
  /^^\      |~~|      /^^\
 / /\ \  TK |==| XY  / /\ \
''''''''''''''''''''''''''''

这是因此最短的答案以字节为单位。鼓励解释。


我们可以假设,我们不会得到两个sunclouds,或两者rainsnow
HyperNeutrino

@HyperNeutrino这已在挑战中指定。
吉姆(Jim)

啊。我已经做了很多次了(错过了部分挑战)。抱歉:P
HyperNeutrino

大声笑+1 The papoose shouts: "I WANNA GO OUTSIDE PLAY UNDER THE SUN!"。同样,这个挑战比我想象的要少很多痛苦,也很多乐趣,所以非常感谢挑战:P :)
HyperNeutrino

我想念像这样的挑战。不太难,也不是FGITW,也不是打高尔夫球的语言,实际上要求您编码而不是找一个小的4乘
Uriel

Answers:


2

Python中,527 524 508 504 481 474 462 461字节

from re import*
a=r"""!!! __
!! ___|AA|___
   \/!\BBBBBBBB/!\/
   /\! ``|CC|``! /\
  /^^\!  |DD|!  /^^\
 / /\ \  02 |EE| 31  / /\ \
""";s={'sun':'A2()','clouds':'A2w','rain':'B2"','snow':'B2:','thunderstorm':'C2z','wind':'D2~','fog':'E2='};i=0
for y in[w for w in split('\W+',input().lower())if w in s]:i+=1;z=s[y];w=int(z[1]);a=sub(z[0]*w,(z[2:]*w)[:w],a)
for y in range(min(i,4)):a=sub(str(y),'TYKX'[y],a)
print(sub('!',' '*4,sub('[ABCDE0123]',' ',a))+"'"*28)

在线尝试!


在上一个挑战中,我对每个人如何使用正则表达式感到失望。我以为有了这个,我将一无所有。好吧,我有点惊讶……
Jim

@Jim好吧,它们绝对不是该功能的主要部分
Uriel

我发布了另一个使用完全不同的算法的Python解决方案。如果您认为最好将它用作您的高尔夫,我将把我的名称删除为“与您太相似”。
HyperNeutrino

@HyperNeutrino我只是在打高尔夫球,我想我碰到了您使用过的一些东西。我通常不介意与我的lang相同的其他解决方案,尽管我通常不愿发布这些解决方案
Uriel


2

Python 3中473个 464 460字节

import re
x=re.split('\W+',input().lower())
L='sun clouds rain snow thunderstorm wind fog'.split()
q=sum(map(x.count,L))
print(r'''!    __
!___|#|___
" \/"  \$/" \/
" /\"   ``|%%|``"  /\
  /^^\""  |&&|"" /^^\
 / /\ \  13 |''| 42 / /\ \
'''.translate({33:' '*9,34:' '*2,35:' (w )w'[(L[0]in x)+2*(L[1]in x)::3],36:' ":'[(L[2]in x)+2*(L[3]in x)]*8,37:' z'[L[4]in x],38:' ~'[L[5]in x],39:' ='[L[6]in x],49:' T'[q>0],50:' Y'[q>1],51:' K'[q>2],52:' X'[q>3]})+"'"*28)

在线尝试!

-9字节
-4字节归功于ovs


我不明白你为什么需要s。只需将最后两行合并print(r...28)为460字节即可。
ovs '17

@ovs哎呀忘记了。谢谢!
HyperNeutrino

1

JavaScript(ES6),417字节

(s,i=x=>s.toLowerCase()[q](/\W+/).includes(x[0]),g=x=>y=>i(x)?y[0]:(j--,"  "),j=4,t="||   \\/|   /\\|  /^^\\| / /\\ \\"[q="split"]`|`.map(x=>x[p="padEnd"](9)))=>`    __    n___|${i`sun`?"()":g`clouds``ww`}|___n${"\\"[p](9,i`rain`?'"':g`snow``:`)}/n \`\`|${g`thunderstorm``zz`}|\`\` n   |${g`wind``~~`}|   n02 |${g`fog``==`}| 31`.replace(/\d/g,m=>m>j?" ":"TYKX"[m])[q]`n`.map((v,k)=>t[k]+v+t[k]).join`
`+`
`[p](28,"'")

这里的想法是先生成图腾柱,然后在其两侧添加镜像的tiki。

包括两个帮助函数:i,用于检查字符串是否为输入中的单词之一;和g,这样做i并返回给定的字符串或" "g还计算了缺少的元素供底部的舞者使用。

测试片段

let f=
(s,i=x=>s.toLowerCase()[q](/\W+/).includes(x[0]),g=x=>y=>i(x)?y[0]:(j--,"  "),j=4,t="||   \\/|   /\\|  /^^\\| / /\\ \\"[q="split"]`|`.map(x=>x[p="padEnd"](9)))=>`    __    n___|${i`sun`?"()":g`clouds``ww`}|___n${"\\"[p](9,i`rain`?'"':g`snow``:`)}/n \`\`|${g`thunderstorm``zz`}|\`\` n   |${g`wind``~~`}|   n02 |${g`fog``==`}| 31`.replace(/\d/g,m=>m>j?" ":"TYKX"[m])[q]`n`.map((v,k)=>t[k]+v+t[k]).join`
`+`
`[p](28,"'")

let tests = [`The squaw says: "I want sun and wind for drying the clothes"`,`The warrior thinks: "A good thunderstorm will afraid the invaders. Or a snow storm. Or an impenetrable fog. Or an oppressive sun."`,`The papoose shouts: "I WANNA GO OUTSIDE PLAY UNDER THE SUN!"`,`The wise grandma whispers: "The totem is an illusion"`,`The shaman confides: "I perform my magic hidden in the fog, under the rain or at least under heavy clouds"`,`The village chief claims: "The meat of bison is better preserved in the snow, or dried under a burning sun. My Pa' used to say that heavy wind and a thunderstorm could help too, but I have no clue how. And despite everyone contradicting me, I am persuaded a good fog will do as well"`];I.innerHTML+=tests.map(t=>"<option>"+t).join``
<select id=I oninput="O.innerHTML=(idx=I.selectedIndex)?(t=tests[idx-1])+'\n\n'+f(t):''" style="width:90vw"><option>---Tests---</select>
<pre id=O></pre>

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.