11
\$\begingroup\$

There is a Sioux village. It has a totem:

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

The totem lets the Sioux mastering the weather for helping in their different tasks. Help the villagers properly decorating the totem for invoking the adequate weather. The totem has several parts:

             __
         ___|AA|___
   \/    \BBBBBBBB/    \/
   /\     ``|CC|``     /\
  /^^\      |DD|      /^^\
 / /\ \  13 |EE| 42  / /\ \
''''''''''''''''''''''''''''
  • A is for sun () or clouds ww
  • B is for rain """""""" or snow ::::::::
  • C is for thunderstorm zz
  • D is for wind ~~
  • E is for fog ==

But that's not all. The totem needs weather dancers. The more elements are invoked, the higher the number of required dancers is. If there is one element invoked, a dancer is needed. Two elements, two dancers. Beyond four elements, there will always be at most four dancers. If there is no element invoked, no dancers are needed. The totem needs to rest.

The weather dancers must appear in the order 1234. For instance if there are two dancers, the slots 1 and 2 must be occupied. Moreover, each dancer performs a different figure:

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

Now, the villagers will express their weather wishes. They will pronounce a sentence containing the weather element(s) they would like to have. Setup the totem and the dancers for fulfilling their wishes.

Challenge

Write a program which takes a string as input, matches the elements in the sentence (sun, rain, …), and outputs the full village with the totem properly set and its dancers. Your program does not have to check the correctness of the input string (e.g. it won't contain both sun and clouds). It must matches words (in the literal sense):

  • The input string X says: "I like the wind, it blows the worries away" matches wind, because the comma is not part of the word
  • The input string Y says: "I hope the weather won't get too windy" does not match wind, because windy and wind are two different words

The word(s) to match are guaranteed to be in the quoted part of the input string (the first part designating who is talking will never contain a word that could be matched).

Examples

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  / /\ \
''''''''''''''''''''''''''''

This is so the shortest answer in bytes win. Explanations are encouraged.

\$\endgroup\$
  • \$\begingroup\$ Can we assume that we won't get both sun and clouds, or both rain and snow? \$\endgroup\$ – HyperNeutrino Jul 18 '17 at 20:50
  • \$\begingroup\$ @HyperNeutrino This is already specified in the challenge. \$\endgroup\$ – Jim Jul 18 '17 at 20:54
  • \$\begingroup\$ Ah. I've done that many times (missing parts of the challenge). Sorry :P \$\endgroup\$ – HyperNeutrino Jul 18 '17 at 20:54
  • \$\begingroup\$ lol +1 for The papoose shouts: "I WANNA GO OUTSIDE PLAY UNDER THE SUN!". Also this challenge was a lot less painful and a lot more fun than I thought it would be so thanks for the challenge :P :) \$\endgroup\$ – HyperNeutrino Jul 18 '17 at 21:01
  • \$\begingroup\$ I miss challenges like this one. Not too hard, not too FGITW, not too golfing languages and actually requires you to code rather than find a small 4-byter \$\endgroup\$ – Uriel Jul 18 '17 at 21:24
2
\$\begingroup\$

Python, 527 524 508 504 481 474 462 461 bytes

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)

Try it online!

\$\endgroup\$
  • \$\begingroup\$ In my last challenge I was disappointed how everyone used regex. I thought that with this one, I would have none. Well, I'm kinda surprised… \$\endgroup\$ – Jim Jul 18 '17 at 20:49
  • \$\begingroup\$ @Jim well, they are definitely not the main part of the function \$\endgroup\$ – Uriel Jul 18 '17 at 20:50
  • \$\begingroup\$ I posted another Python solution that uses a fairly different algorithm; if you think it would be better to just use it as a golf of yours, I'll delete mine as a Too Similar to yours. \$\endgroup\$ – HyperNeutrino Jul 18 '17 at 20:57
  • \$\begingroup\$ @HyperNeutrino I was just golfing it and I think I hit some of the stuff you used btw. I generally don't mind other solutions the same lang as mine, though I usually prefer not to post these \$\endgroup\$ – Uriel Jul 18 '17 at 21:10
  • \$\begingroup\$ 485 bytes \$\endgroup\$ – HyperNeutrino Jul 18 '17 at 21:10
2
\$\begingroup\$

Python 3, 473 464 460 bytes

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)

Try it online!

-9 bytes
-4 bytes thanks to ovs

\$\endgroup\$
  • \$\begingroup\$ I don't see why you would need s. Just merge your last two lines to print(r...28) for 460 bytes. \$\endgroup\$ – ovs Jul 19 '17 at 18:54
  • \$\begingroup\$ @ovs whoops forgot about that. Thanks! \$\endgroup\$ – HyperNeutrino Jul 19 '17 at 18:54
1
\$\begingroup\$

JavaScript (ES6), 417 bytes

(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,"'")

The idea here was to generate the totem pole first, then add the mirrored tikis on both sides of it.

Includes two helper functions: i, which checks if a string is one of the words in the input; and g, which does i and returns the given string or " ". g also counts how many elements are missing to be used for the dancers at the bottom.

Test Snippet

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>

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.