आगे रोड पेंटिंग


12

दो मापदंडों को देखते हुए लेन पैटर्न और सड़क की लंबाई , सड़कों को चित्रित करने के लिए सड़क और यातायात सेवा के लिए लेन चिह्नों के ASCII प्रतिनिधित्व को प्रिंट करें।

उदाहरण इनपुट / आउटपुट

इनपुट: BTHMLRPHU २१

मुझे परवाह नहीं है अगर आप दो मापदंडों को लेते हैं या स्ट्रिंग के अंत में संख्या को बदलते हैं, यह असंदिग्ध है।

एसटीडीआईएन से इनपुट लिया जा सकता है, फ़ंक्शन तर्क के रूप में, पर्यावरण चर, जो भी आपकी भाषा में समझ में आता है।

आउटपुट:

!   |      x      ##      |      |      x      x      !
! B |  /\  x HOV3 ##  <-  |  ->  |  ^^  x HOV3 x      !
! B |  \/  x HOV3 ##   |  |  |   |  ^^  x HOV3 x      !
!   |      x      ##      |      |      x      x      !
!   |      x      ##      |      |      x      x      !
!   |      |      ##      |      |      |      |      !
!   |      |      ##      |      |      |      |      !
!   |      |      ##      |      |      |      |      !
! B |  /\  | HOV3 ##  <-  |  ->  |  ^^  | HOV3 |      !
! B |  \/  | HOV3 ##   |  |  |   |  ^^  | HOV3 |      !
!   |      x      ##      |      |      x      x      !
! B |  /\  x HOV3 ##  <-  |  ->  |  ^^  x HOV3 x      !
! B |  \/  x HOV3 ##   |  |  |   |  ^^  x HOV3 x      !
!   |      x      ##      |      |      x      x      !
!   |      x      ##      |      |      x      x      !
!   |      |      ##      |      |      |      |      !
!   |      |      ##      |      |      |      |      !
!   |      |      ##      |      |      |      |      !
! B |  /\  | HOV3 ##  <-  |  ->  |  ^^  | HOV3 |      !
! B |  \/  | HOV3 ##   |  |  |   |  ^^  | HOV3 |      !
!   |      x      ##      |      |      x      x      !

प्रत्येक वर्ण चौड़ाई में 0.5 मीटर और लंबाई में एक किलोमीटर दर्शाता है।

विशिष्टता

लेन का चिह्न

सड़क के प्रत्येक 10 किमी के लिए, अंक 2, 3, 9 और 10 (आउटपुट के "शीर्ष" से) पर चित्रित किए गए हैं। अंकन लेन में केंद्रित हैं। बाइक लेन और माध्यिका के अपवाद के साथ, सभी लेन 3 मीटर (6 वर्ण) चौड़ी हैं।

उदाहरण के आउटपुट में संकेत के अनुसार ASCII हीरे और तीर वर्णों को अनुमति नहीं है

  • B: दुपहिया पथ। Bअंकन। 1.5 मीटर (3 वर्ण) चौड़ा।
  • T: पारगमन। हीरा का अंकन
  • H: उच्च-अधिभोग वाहन लेन। HOV3अंकन
  • Lऔर R: टर्निंग लेन। तीर का निशान
  • P: पासिंग लेन। देखभाल के निशान
  • U: अप्रतिबंधित लेन। कोई निशान नहीं

विभाजक (पूर्वता के क्रम में)

  • मेडियन: ##( Mइनपुट स्ट्रिंग द्वारा दर्शाया गया है, खाई सहित किसी अन्य विभाजक को प्रतिस्थापित करता है)
  • खाई (चरम बाएं और चरम दाएं): !विस्मयादिबोधक चिह्न
  • एचओवी गलियों वैकल्पिक के बीच xऔर |हर 5 किमी
  • सामान्य: |

प्रतिबन्ध

आपका कार्य या कार्यक्रम होना चाहिए:

  • STDOUT पर प्रिंट करें (इसका अर्थ System.out.printजावा के console.logलिए जावास्क्रिप्ट के लिए समकक्ष है , आदि)
  • 0 - 10 पदकों के साथ 1 - 9 लेन प्रिंट करने में सक्षम हो
  • सड़क के 50 किमी (उत्पादन की 50 लाइनें) तक प्रिंट करने में सक्षम हो
  • किसी भी मानक खामियों का उपयोग न करें
  • \nआउटपुट के अंत में एक वैकल्पिक के अपवाद के साथ अनुगामी श्वेत स्थान स्वीकार्य नहीं है

सबसे बड़ा संभव उत्पादन: 3700 बाइट्स (74 अक्षर * 50 लाइनें)।

सबसे छोटा संभव आउटपुट: 5 बाइट्स (इनपुट के साथ B, 1)

मान्यताओं

  • कोई आसन्न मध्यस्थ ( MMघटित नहीं होगा)
  • चिह्नों की दूसरी पंक्ति काट दी जा सकती है (उदाहरण के लिए यदि लंबाई 9 या 12 किमी है)
  • लेन तार्किक रूप से समझ में नहीं आ सकते हैं (उदाहरण के लिए कोई भी आदेश संभव है, उदाहरण के लिए सड़क के बाईं ओर दाएं मोड़ लेन)

यह , इसलिए सबसे छोटा कोड (बाइट्स में) जीतता है!


1
और वहां, आपको
मोनोपॉजेड

जवाबों:


4

रूबी, २४५

यदि प्रासंगिक हो, तो लेन विभाजन को मुद्रित करें।

मुझे जीत की उम्मीद नहीं है।

->(n,i){i.times{|d,t|*e=''
g=e+%w{HOV3 ^^ B}
n.chars{|c|$><<(c==?M?'##':!t ??!:(t+c)[?H]&&d%10<5??x:?|)if(M=t!=?M)
$><<((e+[(%w{/\\ <- ->}+g)[v='TLRUHPB'.index(c)],(%w{\\/ \ | |\ }+g)[v]]+e*4)*2)[d%10].center(v>5?3:6)if(t=c)!=?M}
puts M ? e:?!}}

बदलाव का

245 चोक स्टडर और स्प्लिट एरेज़ प्रभावी रूप से।

सूचकांक सरणी के लिए 263 बेहतर तरीका है

268 बस प्रत्येक पंक्ति को प्रिंट करें, एक विहित संस्करण की गणना न करें।

330 प्रारंभिक प्रतिबद्ध


मैं रूबी से या तो जीतने की उम्मीद नहीं करूंगा, लेकिन अगर अगले सप्ताह के भीतर कोई अन्य जवाब नहीं मिलता है, तो मुझे लगता है कि आप जीतेंगे :-P एक दूसरे नोट पर कहीं भी मैं अपने कंप्यूटर पर रूबी को स्थापित किए बिना यह परीक्षण कर सकता हूं?
rink.attenders.6


2

जावास्क्रिप्ट (ईएस 6), 316 बाइट्स

f=(x,n)=>{for(i=0;n>i++;){b=!(r=i%10)|r==3;y=[...`! ${[...x].join` | `} !`[o='replace'](/[\W] ?M [\W]?/g,'##')].map(c=>~(q='LPRTU'.indexOf(c))?` ${'<- |^^^^->| /\\\\/    '.substr(4*q+2*b,2)} `:c=='H'?'HOV3':c).join``;y=r&&r<6?y[o](/\| H/g,'x H')[o](/3 \|/g,'3 x'):y;console.log(b|r==2|r==9?y:y[o](/[^!\|x#]/g,' '))}}

डेमो

लेखन के समय फ़ायरफ़ॉक्स और एज में काम करना चाहिए, क्रोम / ओपेरा को सक्षम करने के लिए प्रयोगात्मक सुविधाओं की आवश्यकता होती है।

console.log = x => O.innerHTML += x + '\n';

f = (x, n) => {
  for (i = 0; n > i++;) {
    b = !(r = i % 10) | r == 3;
    y = [...
      `! ${[...x].join` | `} !` [o = 'replace'](/[\W] ?M [\W]?/g, '##')
    ].map(c => ~(q = 'LPRTU'.indexOf(c)) ? ` ${'<- |^^^^->| /\\\\/    '.substr(4*q+2*b,2)} ` : c == 'H' ? 'HOV3' : c).join ``;
    y = r && r < 6 ? y[o](/\| H/g, 'x H')[o](/3 \|/g, '3 x') : y;
    console.log(b | r == 2 | r == 9 ? y : y[o](/[^!\|x#]/g, ' '))
  }
}

// Snippet stuff
var demo = () => {
  O.innerHTML = '';
  document.forms[0].checkValidity() && f(document.getElementById('P').value, document.getElementById('N').valueAsNumber);
};

document.getElementById('P').addEventListener('change', demo);
document.getElementById('N').addEventListener('change', demo);

demo();
<form action='#'>
  <p>
    <label>Lane pattern:
      <input type=text pattern=^M?([BHLPRTU]M?)+$ maxlength=19 required id=P value=MLTPUMHUTBR>
    </label>
  </p>
  <p>
    <label>Kilometres:
      <input type=number id=N min=1 value=21 max=50 step=1 required>
    </label>
  </p>
  <pre><output id=O></output></pre>
</form>


1

05AB1E , 175 174 175 बाइट्स

ðTиDU'|TиX'BŽ5ES©ǝX„\/TbSDVè®ǝ€ºX4×"HOV3"®ǝX'<18SǝX„|-Yè®ǝøJDí'<'>:X'^®ǝ2×'#Tи2×'x5и'|5и«'!Tи)I.•o¤[‹‡•uŽDýSтì€ûŽe1ª904ûª8ª₄«ª‡•δ~¬]•2ôDí«Ž
ÿT∍S:ð.ø8ðì‚8:1ðì‚ð:SðT:èεI∍}øJ»

बहुत बुरा दृष्टिकोण, लेकिन यह काम करता है और बनाने में मजेदार था। निश्चित रूप से कुछ और गोल्फ हो सकता है, हालांकि।

दो आसन्न HHगलियों के लिए बग-फिक्स के रूप में +1 बाइट ।

इसे ऑनलाइन आज़माएं।

स्पष्टीकरण:

चरण 1: आकार 10 के साथ सभी संभव लेन बनाएं:

ðTи               # Push a space character, repeated 10 times as list
   DU             # And store a copy in variable `X`
'|Tи             '# Push "|", repeated 10 times as list
X                 # Push the list of spaces of variable `X`
 'B              '# Push a "B"
   Ž5E            # Push compressed integer 1289
      S           # Converted to a list of digits: [1,2,8,9]
       ©          # Store it in variable `®` (without popping)
        ǝ         # Replace the spaces in the pushed `X` with the "B" at these (0-based)
                  # indices
X                 # Push `X` again
 \/              # Push string "\/"
    TbS           # Push 10, converted to binary, as list: [1,0,1,0]
       DV         # Store a copy in variable `Y`
         è        # Index each into this string: ["/","\","/","\"]
          ®       # Push list `®` again ([1,2,8,9])
           ǝ      # And replace the spaces with these characters
            €º    # And then mirror each line (" "→"  "; "/"→"/\"; "\"→"\/")
X                 # Push `X` again
 4×               # Extend each space to four spaces
   "HOV3"         # Push string "HOV3"
         ®ǝ       # And replace the spaces with this string at the indices of `®` again
X                 # Push `X` again
 '<              '# Push string "<"
   18S            # Push 18 as list: [1,8]
      ǝ           # Replace the spaces with "<" at those indices
       X          # Push `X` yet again
        „-|       # Push string "-|"
           Yè     # Use list `Y` ([1,0,1,0]) to index into this string: ["-","|","-","|"]
             ®ǝ   # And replace the spaces at the indices of `®` again
               ø  # Then zip-pair the two lists together
                J # And join each pair of characters to a string
Dí                # Create a copy and reverse each string
  '<'>:           # And replace all "<" with ">"
X'^®ǝ            '# Push `X` with the spaces at indices `®` replaced with "^" 
     2×           # Extend each character to size 2
'#Tи             '# Push "#", repeated 10 times as list
    2×            # And extend each character to size 2
'x5и             '# Push "x" repeated 5 times as list
    '|5и         '# Push "|" repeated 5 times as list
        «         # And merge the lists together
'!Tи             '# Push "!", repeated 10 times as list
)                 # And finally wrap all lists of the stack into one big list of lanes

चरण 2: इनपुट-स्ट्रिंग को सूचक में बदलें (जो हम उस सूची में उपयोग करने जा रहे हैं जिसे हमने चरण 1 में बनाया था):

I                 # Push the input-string
 .•o¤[‹‡•         # Push compressed string "tlrpbhmu"
         u        # And uppercase it
ŽDý               # Push compressed integer 3567
   S              # Converted to a list of digits: [3,5,6,7]
    тì            # Prepend each with "100": ["1003","1005","1006","1007"]
      €û          # And palindromize each: ["1003001","1005001","1006001","1007001"]
Že1               # Push compressed integer 10201
   ª              # And append it to the list
904ûª             # Push 904 palindromized to "90409", and also append it to the list
8ª                # Append 8 to the list
₄Â                # Push 1000, and bifurcate it (short for Duplicate & Reverse copy)
  «               # Merge them together: "10000001"
   ª              # And also append it to the list
                 # Now transliterate all uppercase characters in the input to these numbers
•δ~¬]•            # Push compressed integer 1119188999
      2ô          # Split into parts of size 2: [11,19,18,89,99]
        Dí        # Create a copy, and reverse each item: [11,91,81,98,99]
          «       # And merge the lists together: [11,19,18,89,99,11,91,81,98,99]
Ž\nÿ              # Push compressed integer 19889
    T            # Extended to size 10: 1988919889
      S           # As a list of digits: [1,9,8,8,9,1,9,8,8,9]
:                 # Replace all [11,19,18,89,99,11,91,81,98,99] with [1,9,8,8,9,1,9,8,8,9]
                  # in the converted string
ð.ø               # Surround the string with spaces
8ðì               # Push 8 with a prepended space: " 8"
   ‚             # Bifurcate and pair: [" 8","8 "]
     8:           # And replace all those for 8 in the string
1ðì‚ð:           # Do the same for [" 1","1 "] → " "
S                 # Convert the string to a list of characters (digits and space)
 ðT:              # Replace the spaces for 10

चरण 3: हम उन सूचकांकों का उपयोग गलियों की सूची में सूचीबद्ध करने के लिए करते हैं। और फिर हम लेन की उन सूची को सही आउटपुट में बदल देते हैं, जिसमें पूर्णांक-इनपुट के आकार को विस्तार / छोटा करना शामिल है:

è                 # Index the indices in the integer-list into the lanes-list
 ε                # Map over each lane
  I               #  Push the second integer-input
                 #  Extend/shorten each 10-sized lane to this input-size
                # After the map: zip/transpose; swapping rows/columns
   J              # Join inner list together to a single string
    »             # And then join each string by newlines
                  # (after which the result is output implicitly)

मेरा यह 05AB1E टिप देखें (यह समझने के लिए कि डिक्शनरी का हिस्सा नहींŽ5E है 1289; और बड़े पूर्णांकों को कैसे कंप्रेस करें? ) यह समझने के लिए कि क्यों है ? .•o¤[‹‡•है "tlrpbhmu"; ŽDýहै 10201; •δ~¬]•है 1119188999; Ž\nÿहै 19889

हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.