হোটেল রুম নম্বর


42

চিহ্নিত সিঙ্গল রুম সহ এএসসিআইআই আর্টে একটি "হোটেল" এর একটি ইনপুট দেওয়া হয়েছে, নির্দিষ্ট নিয়ম অনুসারে রুম নম্বর আউটপুট করুন।

এখানে ASCII হোটেলের উদাহরণ রয়েছে:

               ##
               ##
#####          ##
#####  ######  ##
#####  ######  ##
#####  ######  ##

এএসসিআইআই হোটেল সম্পর্কে আরও কয়েকটি বিষয় এখানে দেওয়া হয়েছে:

  • প্রতিটি "বিল্ডিং" #অক্ষরের একটি আয়তক্ষেত্র দ্বারা প্রতিনিধিত্ব করা হয় , যেখানে প্রত্যেকে #একটি "ঘর" উপস্থাপন করে।

  • উপরের হোটেলটিতে তিনটি বিল্ডিং রয়েছে। প্রতিটি বিল্ডিং ফাঁকা দুটি কলাম দ্বারা পৃথক করা হয়, এবং সর্বনিম্ন "তল" সর্বদা শেষ লাইনে থাকবে।

  • প্রতিটি বিল্ডিংয়ে সর্বদা 1-9 "তল" (সারি) এবং প্রতিটি তলায় 1-9 "রুম" থেকে যে কোনও জায়গা থাকবে। সর্বদা 1-9 টি বিল্ডিং থাকবে।

  • কক্ষগুলি নিম্নরূপ সংখ্যাযুক্ত : [building #][floor #][room on floor #]. উদাহরণস্বরূপ, আসুন উপরের অঙ্কনটিতে কয়েকটি কক্ষ চিহ্নিত করুন:

                   ##
                   ##
    #####          ##
    #####  ####$#  ##
    ##%##  ######  ##
    #####  ######  #@
    

    ঘরের সাথে চিহ্নিত %ঘরটি 123 ঘর (বিল্ডিং 1, তল 2, তলায় 3 র্থ ঘর)। একইভাবে, ঘরটি চিহ্নিত চিহ্নযুক্ত $ঘরটি 235, এবং @ঘরটি 312।

  • বিল্ডিং, মেঝে এবং "মেঝেতে নবম ঘর" সর্বদা 1-ইনডেক্সড।

ইনপুটটিতে একটি এএসসিআইআই হোটেল থাকবে যাতে একটি নক্ষত্র ( *) দিয়ে প্রতিস্থাপন করা একটি একক ঘর থাকবে । এটি সেই ঘরটি যার জন্য আপনার অবশ্যই রুম নম্বর আউটপুট করতে হবে। ইনপুটটি অবশ্যই একটি একক স্ট্রিং হিসাবে নেওয়া উচিত, তবে আপনি নিউলাইনগুলির পরিবর্তে লাইন বিভাজক হিসাবে কমা ব্যবহার করতে পারেন (যদি আপনার পছন্দের ভাষাটি মাল্টিলাইন ইনপুট নিতে না পারে বা একক-লাইন ইনপুটটি ছোট করা হয়)। আপনার বিকল্পভাবে একটি পিছনে কমা / নিউলাইন প্রয়োজন হতে পারে। ইনপুটটিকে একটি সম্পূর্ণ আয়তক্ষেত্র তৈরি করতে আপনি পেছনের স্থানগুলির সাথে প্যাড লাইনও করতে পারেন।

যেহেতু এটি , তাই বাইটের মধ্যে সংক্ষিপ্ততম কোডটি জয়ী।

পরীক্ষার কেসগুলি (উল্লম্ব স্থান সংরক্ষণের জন্য একক কোড ব্লকের মধ্যে রয়েছে):

Input:
*

Output: 111

Input:
#  #  *  #  #

Output: 311

Input:
#####
#####
####*
#####
#####

Output: 135

Input:
         #####
         #####           ######
         #####           ######
#  #  #  #####  #  #  #  ######  *

Output: 911

Input:
#
#  #
#  #  ##
#  #  ##  ###
#  #  ##  ###  #####
#  #  ##  ###  ##*##  ########
#  #  ##  ###  #####  ########

Output: 523

Input:
           #
           *
           #
           #
           #
           #
           #
           #
#########  #  #

Output: 281

Input:
                        ########*
                        #########
                        #########
                        #########
                        #########
                        #########
                        #########
                        #########
#  #  #  #  #  #  #  #  #########

Output: 999

1
কখনও কি কোনও সম্পূর্ণ খালি ইনপুট
আসবে

@ দো- সর্বদা কোথাও একটি নক্ষত্র থাকবে, তাই না।
ডুরকনব


5
গম্ভীরভাবে: আপনার বিল্ডিংগুলি সবসময় আয়তক্ষেত্রাকার আকারে (ডান?)
জানার

1
@ আগত না, এটি অবশ্যই একটি একক স্ট্রিং হওয়া উচিত, যেমন প্রশ্নে বর্ণিত হয়েছে।
ডুরকনবব

উত্তর:


11

সিজেম, 34 31 বাইট

qN/W%zSf-La%{_{s'*&}#_)@@=}3*;\

এর জন্য ফাঁকা স্থানগুলির সাথে একটি আয়তক্ষেত্রটি প্যাড করা দরকার।

এটি অনলাইন চেষ্টা করুন! বিকল্পভাবে, সমস্ত পরীক্ষার কেস চালান।

ব্যাখ্যা

qN/      e# Read input and split into lines.
W%z      e# Rotate 90° counter-clockwise.
Sf-      e# Remove all spaces from the rows.
La%      e# Split into buildings. We've now got a 3D array of rooms, where the first
         e# dimension is the building, the second the room number and the third is the
         e# the floor number.
{        e# Run this block three times. At each stage it will find the index of the "*"
         e# along the current dimension and leave the element at that index on the stack
         e# for the next round...
  _      e#   Duplicate the current array.
  {      e#   Find the index of the first element where this block yields something
         e#   truthy...
    s    e#     Flatten into a single string.
    '*&  e#     Set intersection with "*".
  }#
  _)     e#   Duplicate the index and increment it, because the results should be 1-based.
  @@=    e#   Pull up the array and the other copy of the index and select the
         e#   corresponding element.
}3*
;\       e# We've now got the building, room and floor index on the stack, as well as the
         e# "*" character itself. We discard the character and swap the room and the floor
         e# floor number. When the three indices are printed back-to-back at the end of
         e# the program, that will yield the desired result.

9

পাইথ, 34 বাইট

LxKh/#\*b\*jkhM[//<hJ_.zyJd2xJKycK

প্রদর্শন

এটি এমন গল্ফিং ট্রিক ব্যবহার করে যা আমি এর আগে কখনও ব্যবহার করি নি: Kএকটি ফাংশনের ভিতরে কোনও ভেরিয়েবলকে ( ) বরাদ্দ করা ( ) এর ফাংশন yথেকে আংশিক ফলাফল সংরক্ষণ করতে।

ব্যাখ্যা:

LxKh/#\*b\*jkhM[//<hJ_.zyJd2xJKycK
L                                     Define y(b):      (b is a list of strigs)
    /#\*b                             Filter b for strings containing '*'
   h                                  Take the first such string
  K                                   Store it in K
 x       \*                           And return the index of '*' in that string.
                      .z              Take the input as a list of strings
                     _                Reverse it (bottom to top)
                    J                 Store in J
                   h                  Take the bottommost row
                        yJ            Find y(J). This is the index in whichever
                                      row of J has the * of the *. Also store
                                      that row in K.
                  <                   Slice J up to that index.
                 /        d           Count the number of spaces
                /          2          Divide by 2. This is the building number.
                            xJK       Take the index in J of K. This is the floor.
                                cK    Chop K on whitespace.
                               y      Find the index in whatever element of K has
                                      the * of the *. This is the room number.
                                      This also overwrites K, but we don't care.
               [                      Gather the above into a list.
             hM                       Convert 0-indexing to 1-indexing.
           jk                         Concatenate. Print implicitly.

9

জাভাস্ক্রিপ্ট (ES6), 142 136 বাইট

h=>h.split`
`.reverse(r=0).map((t,i,l)=>r?0:(f=i+1,b=1,l[o=0].slice(0,r=t.indexOf`*`+1).replace(/  /g,(_,s)=>o=++b&&s+2),r-=o))&&[b]+f+r

@ রাইডারস্কোরের জন্য 6 টি বাইট সংরক্ষণ করা হয়েছে !

ব্যাখ্যা

h=>
  h.split`
`                            // get each line of the input string
  .reverse(                  // reverse the lines to make getting the ground floor easy
    r=0)                     // initialise r to 0
  .map((t,i,l)=>             // for each line of the reversed input string
    r?0:(                    // if the marked room has not been found yet:
      f=i+1,                 // f = floor number
      b=1,                   // b = building number, default to 1
      l[o=0].slice(0,        // get the substring of 0 to the marked room, default o to 0
        r=t.indexOf`*`+1)    // r = absolute index of room + 1 (or 0 if not found)
      .replace(/  /g,(_,s)=> // count the spaces between buildings
        o=++b&&s+2),         // increment b, o = index of marked room's building
      r-=o                   // make r relative to the room's building
    )
  )
  &&[b]+f+r                  // output the result ([b] casts b to a string)

পরীক্ষা


কিছু বাইট সঞ্চয়ী (-6): .map((t,i,l)=>, slice(0,r=t.indexOf`*`+1), o=++b&&s+2,[b]+f+r
nderscore

@ আন্ডারস্কোর ধন্যবাদ, আমি সত্যিই [b]+f+rটিপটি পছন্দ করি !
ব্যবহারকারী81655

7

আজ, 70

!i{i=index($0,"*")}i{$0=substr($0,0,i);f++}END{print NF f length($NF)}

উদাহরণ:

Input:
#
#  #
#  #  ##
#  #  ##  ###
#  #  ##  ###  #####
#  #  ##  ###  ##*##  ########
#  #  ##  ###  #####  ########

While no * was found, do nothing.
#
#  #
#  #  ##
#  #  ##  ###
#  #  ##  ###  #####
A * is found in column 14. From now on, truncate and increment the floor counter.
#  #  ##  ###  ##*    f=1
#  #  ##  ###  ###    f=2
Awk automatically splits $0 into space separated fields, counted by builtin NR.
In the end, NR and f hold hotel and floor number.
The room number is the length of the last hotel.

6

সি, 131 130 119 113 বাইট

b,f,i,j=111;main(c){for(;c=~getchar();)c&32?f+=10,b=i=0:++i<j?c%3?f=j,j=i:c&2?b+=50-b%50:++b:0;printf("%d",b+f);}

স্টিডিনে ইনপুট নেয়; ইনপুটটির অবশ্যই একটি সমাপ্তি নতুন লাইন থাকা উচিত নয় । ধরে নেয় 2 এর পরিপূরক।

Ungolfed:

// Declare variables (default type is int) and initialize, by default to 0:
b,    // Building number (multiplied by 100, 0-based) + room number (0-based)
f,    // Floor (111-based, multiplied by 10)
i,    // Current column of input character within line (1-based)
j = 111; // Column of asterisk character once found (1-based), 111 before then
main (c)    // Declare main function and variable c to hold input character
{
  for (;    // Loop on input
    c = ~getchar();  // Read a character into c, bitwise inverted to break
                     // EOF (numeric value -1). This means that following 
                     // operations (on the ASCII value of the input) are 
                     // also inverted.
    )
    c & 32 ?              // Newline?
      f += 10, b = i = 0 :  // Increment floor; reset building, room, column
      ++i < j ?             // Increment column; before asterisk, or asterisk not yet found?
        c % 3 ?               // Asterisk character?
          f = j, j = i :        // Reset floor and record column
          c & 2 ?               // Space character?
            b += 50 - b % 50 :    // Increment building and reset room
            ++b :                 // Otherwise, # character; increment room
        0;                    // After asterisk; do nothing
  printf("%d", b + f);  // Write out results
}

আমি নিশ্চিত যে গল্ফ করার ক্ষেত্রে কৌশলটি অবশ্যই প্রচুর ব্যবহার করা উচিত, তবে আমি স্টাডিও ব্যবহার করার আগে এমন কোনও প্রোগ্রাম আগে কখনও দেখিনি, এটি অন্তর্ভুক্ত থাকলে বিরতি!
ডেভ

@ ডেভ খালি জোড়া পেরেন কেবল সম্ভাব্য প্রকাশের অপচয় এবং শিরোনামগুলি একটি বিলাসবহুল :) এছাড়াও গল্ফ করার জন্য আপনার এক বা দুটি ধারণা চুরি করেছে ole
ইকামত্মর

খুশী হলাম। আমি বিল্ডিং ইনক্রিমেন্ট পছন্দ করি - আরও 3 বাইট সাশ্রয় করি। আমি সেই ধারণাটিকে পিছনে ফেলেছি এবং আপনার নতুন বাইকোয়েন্টের সাথে মেলাতে সক্ষম হয়েছি, তবে আমি আর এটিকে আরও উন্নত করতে পারি না।
ডেভ

4

স্ট্যাকবোট , by৩ বাইট [প্রতিদ্বন্দ্বী]

স্ট্যাকবোট একটি স্ট্যাক-ভিত্তিক ভাষা যা ছাগলের সাথে কোনও সম্পর্ক রাখে না।

y'#ZGDYZG'*iVXsV@"\\*"ZGN2/1+y'#ZG' ZG'q:Nq'*i-yXsq'*i@"[#*]+"M0M1-@'*i1+

এটি মোটামুটি নতুন ভাষা তাই তারা যদি এতে কোনও সমস্যা হয় তবে আমাকে জানান। আমি নিজেকে খুঁজে বের করতে বেশ মাথা ব্যাথা দিয়েছি তাই এটি যতটা আমি গল্ফ করছি ing

ব্যাখ্যা

এই প্রোগ্রামটিতে রুম নম্বরটির প্রতিটি 3 ডিজিটের জন্য 3 টি অংশ রয়েছে

y'#ZG    // Remove all # from input
D        // Duplicate
YZG      // Remove all spaces
'*i      // Index of *
V        // Reverse stack
Xs       // Split on spaces
V@       // Unreverse, item at *'s index
"\\*"ZG  // Remove all *s
N        // Get length
2/1+     // Divide by 2, add 1

y'#ZG    // Remove all #
' ZG     // Remove all spaces
'q:      // Store in q
N        // Get length
q'*i     // *'s index in q
-        // Subtracted from length

yXs      // Split on newlines
q'*i     // Get index of * in q
@        // Get indexed-th line
"[#*]+"M // Match all buildings
0M       // Get *'s building no.
1-       // Subtract one
@        // nth building at right line
'*i      // *'s index
1+       // Added to one


6
এটি চ্যালেঞ্জ পোস্ট হওয়ার পরে প্রয়োগ করা দুটি নতুন বৈশিষ্ট্য ব্যবহার করে বলে মনে হচ্ছে , সুতরাং উত্তরটি হ'ল আপত্তিহীন।
ডুরকনবব

কৌতূহলের বাইরে, @ ডুরকনব - এই নিয়মটি কোথায় সংজ্ঞায়িত করা হয়েছে? আমি সমস্ত যৌক্তিক জায়গাগুলি সন্ধান এবং অনুসন্ধান করার চেষ্টা করেছি, কিন্তু আমি এর কিছুই খুঁজে পাইনি ...
অ্যালেক্স


4

রুবি, 103

->n{r=x=b=0
n.lines{|s|(t=s=~/\*/)&&(x=t;r=($`.reverse+' ')=~/ /)
r+=10;b=s[0..x].count" "}
b*50+r+101}

পরীক্ষা প্রোগ্রামে অসম্পূর্ণ

g=->n{
  r=x=b=0
  n.lines{|s|                  #for each line in n
    (t=s=~/\*/)&&              #if the line contains an asterisk
      (x=t                     #record its position in x. $` is a special variable containing the part of the string to the left of the last match made.
      r=($`.reverse+' ')=~/ /) #reverse $` and search for the index of the first space to find room number (before the search a space is appended in case it is 1st building.)
    r+=10                      #increment r by 10 for the floor number (obviously this will have been reset to the row ith the asterisk by the previous line)
    b=s[0..x].count" "}        #count the number of spaces left of x in the current row to find building number (loop will exit with calc from bottom row, which is the correct one.) 
b*50+r+101}                    #multiply number of spaces by 50 to get 1st digit, add r for 2nd and 3rd digit. Then add 101 to correct 1st and 3rd digits from 0-indexed to 1-indexed.

puts g["
*"]



puts g["
#  #  *  #  #"]


puts g["
#####
#####
####*
#####
#####"]

puts g["
         #####
         #####           ######
         #####           ######
#  #  #  #####  #  #  #  ######  *"]



puts g["
#
#  #
#  #  ##
#  #  ##  ###
#  #  ##  ###  #####
#  #  ##  ###  ##*##  ########
#  #  ##  ###  #####  ########"]




puts g["
           #
           *
           #
           #
           #
           #
           #
           #
#########  #  #"]



puts g["
                        ########*
                        #########
                        #########
                        #########
                        #########
                        #########
                        #########
                        #########
#  #  #  #  #  #  #  #  #########"]

আমি সত্যিই $`এই এক মধ্যে চতুর ব্যবহার পছন্দ ।
ডুরকনবব

4

জাভাস্ক্রিপ্ট (ES6), 121

x=>x.split`
`.reverse().map((r,f,h,a=r.indexOf`*`)=>x=~a?(h=h[0].slice(0,a).split`  `).length+[f+1]+-~h.pop().length:x)|x

কম গল্ফ এবং ব্যাখ্যা করা হয়েছে

H=x=>x.split`\n` // split in lines
  .reverse() // reverse, so we can scan bottom up
  .map( (r,f,h) => // exectute for each line
         // r is the current row
         // f in the row index, so that f+1 is the floor number
         // h is the reversed array, h[0] is the bottom floor
       ~(a=r.indexOf`*`) // a is the position of '*' in the line, if found - else 0
       && ( // if a >= 0
         h = h[0]        // bottom floor line 
             .slice(0,a) // ... truncated at position of '*'
             .split`  `, // ... and splitted at '  ', as an array
         x = h.length  // the array len is the building number
             + [f+1]   // floor number, using [] to force string concatenation
             + -~ h.pop().length // the length of the last array element is the number 
                                 // of chars in the block before '*'
                                 // increment by 1 to get the room number
      )
  )
  && x // return the found value

পরীক্ষা

H=x=>x.split`
`.reverse().map((r,f,h,a=r.indexOf`*`)=>x=~a?(h=h[0].slice(0,a).split`  `).length+[f+1]+-~h.pop().length:x)|x

// test
console.log=x=>O.textContent+=x+'\n';

;[['*',111],['#  #  *  #  #',311],
[`#####
#####
####*
#####
#####`,135],
[`         #####
         #####           ######
         #####           ######
#  #  #  #####  #  #  #  ######  *`,911],
[`#
#  #
#  #  ##
#  #  ##  ###
#  #  ##  ###  #####
#  #  ##  ###  ##*##  ########
#  #  ##  ###  #####  ########`,523],
[`           #
           *
           #
           #
           #
           #
           #
           #
#########  #  #`,281],
[`                        ########*
                        #########
                        #########
                        #########
                        #########
                        #########
                        #########
                        #########
#  #  #  #  #  #  #  #  #########`,999]]  
.forEach(t=>{
  var i=t[0],k=t[1],r=H(i)
  console.log(i+'\n' + (k!=r?'Error '+r+' expected '+k:'Ok '+r)+'\n')
})
<pre id=O></pre>


3

পাইথন 2.7, 153 168 টি অক্ষর

আমি এই চ্যালেঞ্জ পছন্দ! যদি পাইথন তালিকাটি ইনপুট হিসাবে ঠিক থাকে (উদাহরণগুলির জন্য পরীক্ষারূপ দেখুন), এই সমাধানটি কাজ করে।

2016-01-05 সম্পাদনা করুন: মাল্টলাইনে স্ট্রিং বিভক্ত করতে একটি লাইন (10 অক্ষর) যুক্ত হয়েছে।

সংক্ষিপ্ত ব্যাখ্যা:

  • t ঘরটি যে সারিটি অবস্থিত তা হ'ল (শীর্ষ-সারি থেকে অ্যারে সূচক হিসাবে গণনা = 0);
  • i এটির সারিতে ঘরটির সূচক;
  • বিল্ডিংটি নীচের সারি পর্যন্ত ডাবল সাদা স্পেসের সংখ্যা হিসাবে গণনা করা হয় i;
  • মেঝেটি সারি বিয়োগের সংখ্যা t;
  • ঘরটি iপ্রথম বিল্ডিংয়ের ক্ষেত্রে কেসটি কভার করার জন্য একটি সাদা স্থান দ্বারা সংযুক্ত করে ঘরটি দিয়ে মেঝে শুরু হওয়ার আগে থেকে বিপরীত স্ট্রিংয়ের প্রথম ডাবল সাদা স্থানের সূচক ।

কোড:

def r(l):
 l=h.split(",")
 a,w,s="*","  ",str
 t=l.index(filter(lambda c:a in c,l)[0])
 i=l[t].find(a)
 return s(l[-1][:i].count(w)+1)+s(len(l)-t)+s((l[t][i::-1]+w).find(w))

পরীক্ষা স্যুট:

cases = [
         (["*"], 111),
         (["#  #  *  #  #"], 311),
         (["#####","#####","####*","#####","#####"], 135),
         (["         #####","         #####           ######","         #####           ######","#  #  #  #####  #  #  #  ######  *"], 911),
         (["#","#  #","#  #  ##","#  #  ##  ###","#  #  ##  ###  #####","#  #  ##  ###  ##*##  ########","#  #  ##  ###  #####  ########"], 523),
         (["           #","           *","           #","           #","           #","           #","           #","           #","#########  #  #"], 281),
         (["                        ########*","                        #########","                        #########","                        #########","                        #########","                        #########","                        #########","                        #########","#  #  #  #  #  #  #  #  #########"], 999)
        ]

for idx,(hotel,roomnr) in enumerate(cases):
    output=r(hotel)
    if str(output)==str(roomnr):
        result="SUCCESS"
    else:
        result="FAILURE!!!"
    print "Case {} gives output: {}. Correct output is: {}. Result: {}".format(idx,output,roomnr,result)


2

সি, 142 138 137 বাইট

#include <stdio.h>
f,b,x,p=110;main(c){while(~(c=getchar()))c<11?f+=c,b=x=0:x++<p?++b,c&2?c&8?f=p,p=x:0:(b+=50-b%50):0;printf("%d",b+f);}

( 123 119 118 বাইট + #includeলাইনের জন্য 19 )

আমি একাটমুর থেকে মান মার্জিং আইডিয়াটি চুরি করেছি, তবে আমি এগুলিকে একদম অন্যভাবে একীভূত করেছি ( শেষ পর্যন্ত 8 টি বাইট সংরক্ষণ করে )। এটি একই ধারণাও করে তোলে EOF == -1

ইনপুটটি স্টিডিনের কাছ থেকে নেওয়া হয়েছে, এবং শেষ লাইনে শেষ বিল্ডিংয়ের পরে অবশ্যই সাদা জায়গা বা নিউলাইনগুলি থাকা উচিত নয়, সুতরাং একটি উদাহরণ ইনপুট হবে:

printf "##\n##       #\n##  ##*  #\n##  ###  #" | ./hotel
# or for better visualisation:
printf "##\n##       #\n##  ##*  #\n##  ###  #" | tee /dev/fd/2 | ./hotel;echo ""

ভাঙ্গন:

// Globals initialise to 0
f,     // floor number * 10 + shift
b,     // building number * 100 + room number
x,     // current column
p=110; // will store column of * (must start >= 11*9-2, and 110 will be used later)
main(c){
    while(~(c=getchar()))              // For each character until EOF
        c<11                           //  Is \n? (10)
            ?f+=c,                     //   Add 10 to floor number
             b=x=0                     //   Reset building, room, column
            :x++<p                     //  Else, is column <= *?
                  ?++b,                //   Add to room number
                   c&2                 //   Is # or *?
                      ?c&8             //   If *:
                          ?f=p,p=x:0   //    Set floor to 110, set p to column
                      :(b+=50-b%50)    //   If ' ': go to next building
                  :0;
    printf("%d",b+f);                  // Result is building+room+floor+shift
}

প্রারম্ভিক কলাম ধ্রুবক পুনরায় ব্যবহার এবং ধ্রুবক হিসাবে অক্ষর মান ব্যবহার করার জন্য দুর্দান্ত ধারণা।
ইকামত্মর

আপনি এতে পরিবর্তন করে একটি বাইট সংরক্ষণ করতে সক্ষম হতে &&(f=p,p=x)পারেন ?f=p,p=x:0- একটি ত্রিশটি শর্তসাপেক্ষে দ্বিতীয় অপারেন্ডের অন্তর্নিহিত বন্ধনী রয়েছে।
একটামুর

@ কেটমুর ভালো পয়েন্ট; ধন্যবাদ!
ডেভ

1

হাস্কেল, 128 125 বাইট

l=length
f h|b<-snd$break(elem '*')$lines h,q<-fst(span(<'*')$b!!0)++"*"=l(last$words$q)+10*l b+l(words$take(l q)$last b)*100

ব্যবহারের উদাহরণ: f "# # * # #"-> 311

কিভাবে এটা কাজ করে:

b<-snd$break(elem '*')$lines h      -- split the input into a list of lines
                                    -- and assign b to the lines starting with
                                    -- the one that includes * up to the end,
                                    -- i.e. drop leading lines without the *
q<-fst(span(<'*')$b!!0)++"*"        -- assign q to the line with the *, but strip
                                    -- off all chars after the *

l(last$words$q)                     -- the room on floor number is the length of
                                    -- the last word of q
10*l b                              -- the floor number is 10 times the length of b
l(words$take(l q)$last b)*100       -- the hotel number is 100 times the number of
                                    -- words in the last line cut down to the
                                    -- length of q

                                    -- add for final room number

1

লুয়া, 165 বাইট

l={}i=1while(l[i-1]~="")do l[i]=io.read()o=l[i]:find"%*"x=o or x y=o and i or y i=i+1 end print(#l[i-2]:sub(1,x):gsub("%S+%s*","#")*100+(i-y-1)*10+#l[y]:match"#-%*")

Ungolfed

l={}
i=1
while(l[i-1]~="")do
    l[i]=io.read()
    o=l[i]:find"%*" --find "*", and record:
    x=o or x        --position and
    y=o and i or y  --current floor
    i=i+1
end
print(#l[i-2]:sub(1,x):gsub("%S+%s*","#")*100 --[[Take last string of list, and then
                                                  take the substring up until the 
                                                  asterisk. Substitute any substrings
                                                  that include nonspace characters 
                                                  (%S+) followed by a minimum of 0 space 
                                                  characters (%s*) with one character
                                                  (in this code snippet I chose # for no 
                                                  particular reason.) Then take the length 
                                                  of this string, with the # operator. 
                                                  The %S+%s* regex and gsub do the bulk 
                                                  of the magic.
                                                ]]
      +(i-y-1)*10                             --[[Total number of lines minus '*' floor 
                                                  minus one.
                                                ]]
      +#l[y]:match"#-%*")                     --[[Find the substring on the asterisk floor
                                                  with '#' symbols preceding an asterisk.
                                                ]]

0

কফিস্ক্রিপ্ট, ১১০ বাইট এবং জাভাস্ক্রিপ্ট, ১২১ বাইট

(s)->s.split('\n').reverse().map((f,g)->f.split('  ').map((h,i)->r=h.indexOf('*');s=''+i+g+r if r>-1));111+1*s

সুপাঠ্য

(s)->
    s.split '\n' 
        .reverse()
        .map (f,fi)->
            f.split('  ')
                .map (h,hi)->
                    ri = h.indexOf('*')
                    s = ''+hi+fi+ri if ri>-1
    111+1*s

জাভাস্ক্রিপ্টে মূলত একই জিনিস:

(s)=>{s.split('\n').reverse().map((f,g)=>f.split('  ').map((h,i)=>{r=h.indexOf('*');r>-1?s=''+i+g+r:''}));return 111+1*s}

0

জাভা, 231 বাইট

String a(String a){String[]b=a.split("\n");int i=0,c=b.length,m;String x,k=" ";for(;i<c;i++){x=b[c-1].substring(0,b[i].indexOf("*")+1);m=x.length();a=m>0?""+(m-x.replace(k+k,k).length()+1)+(c-i)+(m-x.lastIndexOf(k)-1):a;}return a;}

ডি-Golfed

 String a(String a) {
     String[] b = a.split("\n");                                // Split the input into floor lines
     int i = 0, c = b.length, m;                                // i=floor line counter c= number of floor lines
     String x, k = " ";
     for (; i < c; i++) {                                       // Loop through floor lines
        x = b[c - 1].substring(0, b[i].indexOf("*") + 1);       // x = part of bottom floor line up to '*' position in current line (Empty string when no '*')
        m = x.length();                                         // m = length of floor line part
        a = m > 0 ? "" + (m - x.replace(k + k, k).length() + 1) // if m>0 ('*' is on this line) set a=building no+floor no+room no.   building no calculated by replacing double space in x with single space and compare length to x (+1) 
              + (c - i)                                         // floor number is total floor lines (c) - floor line loop counter (i)
              + (m - x.lastIndexOf(k) - 1) : a;                 // room number is m ('*' position in x) - position of last space in x (-1)
     }
     return a;                                                  // return the result at the end.
  }

0

পাওয়ারশেল, 154 বাইট

param($s)filter s{$s|sls $_ -a|% M*|% Le*}(($s-split'
')[-1]|% s*g 0('(?m)^.*\*'|s)|sls '^|  '-a|% M*).Count,('(?ms)(?<=\*.*)$'|s).Count,('#*\*'|s)-join''

কম গল্ফ পরীক্ষা স্ক্রিপ্ট:

$f = {

param($s)

filter s{
    $s|sls $_ -AllMatches|% Matches|% Length
}                                   # select an array of lengths of all matches of the string $s by pattern $_

$hpos='(?m)^.*\*'|s                 # horizontal position of the room in the source string
$basement=($s-split"`n")[-1]        # basement floor string

$building=($basement|% substring 0 $hpos|sls '^|  ' -AllMatches|% Matches).Count
                                    # truncate the basement to the position of the room
                                    # and count all double spaces or a 'start of string'
$floor=('(?ms)(?<=\*.*)$'|s).Count  # count all 'end of line' after the room
$room='#*\*'|s                      # count all #, preceding the room, and room itself

$building,$floor,$room-join''


}

@(

,(@"
*
"@, 111)

,(@"
#  #  *  #  #
"@,311)

,(@"
#####
#####
####*
#####
#####
"@, 135)

,(@"
        #####
        #####           ######
        #####           ######
#  #  #  #####  #  #  #  ######  *
"@, 911)

,(@"
#
#  #
#  #  ##
#  #  ##  ###
#  #  ##  ###  #####
#  #  ##  ###  ##*##  ########
#  #  ##  ###  #####  ########
"@, 523)

,(@"
        #
        *
        #
        #
        #
        #
        #
        #
#########  #  #
"@, 281)

,(@"
                        ########*
                        #########
                        #########
                        #########
                        #########
                        #########
                        #########
                        #########
#  #  #  #  #  #  #  #  #########
"@, 999)

) | % {
    $n,$expected = $_
    $result = &$f $n
    "$($result-eq$expected): $result"
}

আউটপুট:

True: 111
True: 311
True: 135
True: 911
True: 523
True: 281
True: 999

0

05 এ বি 1 ই , 34 বাইট

|€SζJðмõ¡εεR'*k>]DOZ©k>;ò®«sĀ€ƶ˜à«

স্ট্রিং-তালিকা সহ জিপ বর্তমানে বগড। €SζJকেবলমাত্র ζ05AB1E এর পুরানো পাইথন উত্তরাধিকার সংস্করণে থাকতে পারত, তবে কোনও কারণে এলিক্সির পুনর্লিখন সংস্করণে আর কাজ করে না।

এটি অনলাইনে চেষ্টা করুন বা সমস্ত পরীক্ষার কেস যাচাই করুন

ব্যাখ্যা:

|                    # Take the input split by newlines
                     #  i.e. "   ###\n#  ###\n#  ###  ##\n#  ##*  ##"
                     #   → ["   ###","#  ###","#  ###  ##","#  ##*  ##"]
 S                  # Convert each to a list of characters
   ζ                 # Zip, swapping rows and column
    J                # Join them together to a string again
                     #  → [" ###","    ","    ","####","####","###*","    ","    ","  ##","  ##"]
     ðм              # Remove all spaces
                     #  → ["###","","","####","####","###*","","","##","##"]
       õ¡            # Split on empty strings
                     #  → [["###"],[],["####","####","###*"],[],["##","##"]]
ε                    # Map each building to:
 ε                   #  Map each column of the building to:
  R                  #   Reverse the column
   '*k              '#   Get the 0-indexed index of "*"
      >              #   Increase it by 1 to make it 1-indexed
]                    # Close both maps
                     #  → [[0],[],[0,0,1],[],[0,0]]
 D                   # Duplicate the resulting list
  O                  # Sum each building
                     #  → [0,0,1,0,0]
   Z                 # Get the max (without popping)
                     #  → 1
    ©                # Store this max in the register (without popping)
     k>              # Get the index (+ 1) of this max in the sum-list
                     #  → 3
       ;             # Halve it
                     #  → 1.5
        ò            # Round it up to the nearest integer (bankers rounding)
                     #  → 2
         ®           # Retrieve the value from the register again
          «          # Merge the two digits together
                     #  → 21
           s         # Swap so the duplicate list is at the top again
            Ā        # Trutify (0 remains 0, every other integer becomes 1)
                     #  → [[0],[],[0,0,1],[],[0,0]]
                    # For each building:
              ƶ      #  Multiply the integer with the 1-indexed index
                     #  → [[0],[],[0,0,3],[],[0,0]]
               ˜     # Flatten the list
                     #  → [0,0,0,3,0,0]
                à    # Pop the list, and get the max
                     #  → 3
                 «   # Merge it with the other two digits (and output implicitly)
                     #  → 213

আমাদের সাইট ব্যবহার করে, আপনি স্বীকার করেছেন যে আপনি আমাদের কুকি নীতি এবং গোপনীয়তা নীতিটি পড়েছেন এবং বুঝতে পেরেছেন ।
Licensed under cc by-sa 3.0 with attribution required.