তোমার ফোন ধর! এটা কম্পন!


14

আপনি সম্প্রতি একটি নতুন ফোন পেয়েছেন, তবে এটি যেভাবে কম্পন করে তা আপনি পছন্দ করেন না, আপনি সিদ্ধান্ত নিয়েছেন যে আপনি নিজের কম্পনের নিদর্শন তৈরি করতে চান। সুতরাং, আপনি একটি প্রোগ্রাম যেখানে আপনি কিওয়ার্ড ব্যবহার লিখেছি long, shortএবং pauseএই কীওয়ার্ড অনুযায়ী আপনার ফোন স্পন্দিত করা।

কার্য

একটি ছোট প্রোগ্রাম যা একটি স্ট্রিং গ্রহণ তৈরি করুন long, shortএবং pauseএবং অন্য স্ট্রিং স্পন্দিত একটি ফোন ফনেটিক শব্দ প্রতিনিধিত্বমূলক আউটপুট;Rrrr - Rr

longশব্দগুলি Rrrr
shortশব্দ হয় Rr
(কেসিং বিষয়গুলি)
pauseএকটি ড্যাশ যা -
সমস্ত শব্দ পার্শ্ববর্তী স্পেসগুলির সাথে ড্যাশ দ্বারা সীমিত করা হয়' - '

পরীক্ষার কেস

ইনপুট:    long long short long short
আউটপুট:Rrrr - Rrrr - Rr - Rrrr - Rr

ইনপুট:   long long long short short short
আউটপুট:Rrrr - Rrrr - Rrrr - Rr - Rr - Rr

ইনপুট:   short short short pause short short short
আউটপুট:Rr - Rr - Rr - - - Rr - Rr - Rr

ইনপুট:   long short short long long pause short short
আউটপুট:Rrrr - Rr - Rr - Rrrr - Rrrr - - - Rr - Rr

এটি একটি প্রশ্ন তাই কম বাইট জেতে উত্তরগুলি বাইটে স্কোর করা হবে।


5
এটা কি বিষয়গত মানদণ্ড নয়? আমি খালি স্ট্রিং ব্যবহার করতে চাই, এটি আমার কাছে স্পন্দিত ফোনের মতো শোনাচ্ছে।

6
আপনার "শোনার মতো" নিয়মটি খুব বেশি অস্পষ্ট। আমি ঠিক সঠিক স্ট্রিং প্রয়োজন পরামর্শ দেব। কোড গল্ফের যথাযথ মানদণ্ডের প্রয়োজন তাই আমরা কোনও উন্নতি বৈধ কিনা তা নিয়ে তর্ক ছাড়াই কোডটি অনুকূলিত করতে পারি।
xnor

4
আমাদের কি একটি দিয়ে শব্দগুলি সীমাবদ্ধ করতে হবে -? এটি আপনার উদাহরণের ক্ষেত্রে তবে এটি কোথাও নির্দিষ্ট করা হয়নি।
জেএডি

12
উদাহরণগুলির মধ্যে সমস্ত নিম্ন স্তরের অক্ষরের অনুলিপিগুলির পরে একটি মূলধন নিম্ন ব্যবহার করে। এটা কি নিয়ম?
এক্সনোর

3
এটি আবার খোলার আগে কী করা দরকার: ১) কেস সীমাবদ্ধতা সহ আমাদের অবশ্যই ব্যবহার করতে হবে সঠিক স্ট্রিংগুলি (বা স্ট্রিংগুলির সেটগুলি ) নির্দিষ্ট করুন , ২) ইনপুট এবং / অথবা আউটপুট শব্দের বা অ্যারেগুলির একটি অ্যারে হতে পারে কিনা তা স্পষ্ট করুন অক্ষর, 3) স্ট্রিং হিসাবে আউটপুট করার সময় অবশ্যই সঠিক বিভাজক নির্দিষ্ট করে।
শেগি

উত্তর:


12

পাইকে , 22 20 বাইট

cFh.o6.&\R*\-|l4)J" - 

এখানে চেষ্টা করুন!

c                      -  split(input, " ")
 Fh.o6.&\R*\-|l4)      -  for i in ^:
  h                    -        ^[0]
   .o                  -       ord(^)
     6.&               -      ^ & 6
        \R*            -     ^
           \-|         -    ^ or "-"
              l4       -   ^.title()
                 J" -  - " - ".join(^)

এই উত্তরটি মূল অংশ রূপান্তর হয় ["long", "short", "pause"]মধ্যে [4, 2, 0]। এটি প্রতিটি শব্দের প্রথম অক্ষরের কোড পয়েন্ট পায় এবং ANDএটি with সহ এটি ভাগ্যবান কাকতালীয়ভাবে এটি আমাদের সন্ধান করা মানগুলিতে রূপান্তরিত করে। (এটির সন্ধান করার আগে আমি বেশ কয়েকটি আরও দীর্ঘ সমাধানের মাধ্যমে অনুসন্ধান করেছি)। একবার যে কাজ করছে, আমরা আরও ints এর সেই তালিকাটি চেহারায় রূপান্তরিত হতে পারে ["RRRR", "RR", ""]আমাদের int- এ গুন দ্বারা "R"যা পরে মধ্যে সক্রিয় ["RRRR", "RR", "-"]এবং পরিশেষে আবরণ এটি পেতে শিরোনাম ["Rrrr", "Rr", "-"]। এরপরে আমরা ফলাফলের তালিকায় যোগ দেব" - "


রূপান্তর সঙ্গে এটি সম্পর্কে দুর্দান্ত উপায়!
tisaconundrum


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

@JonathanAllan দ্য বাইট \xefএবং \xa6হয় .oএবং .&যথাক্রমে। এটি একটি পিছনের সামঞ্জস্যপূর্ণ পরিবর্তন যেখানে উচ্চ বিট সেট করা থাকলে এটি এটি পুরানো 2 বাইট কমান্ডের মতো চালায়। পাঠকের পক্ষে এটি আরও সহজ করার জন্য আমি এটি এইভাবে লিখছি এবং কারণ পাইক প্রযুক্তিগতভাবে কোনও কোড পৃষ্ঠা ব্যবহার করে না এবং আমি কাজ করতে চাই না এমন এলোমেলো বাইটগুলি to
ব্লু


11

হাস্কেল , 71 66 59 বাইট

g 'o'="Rr"
g 'n'="rr"
g 'p'="-"
g ' '=" - "
g _=""
f=(g=<<)

এটি অনলাইন চেষ্টা করুন!

হ্যাঁ সঠিক, =<< কনক্যাটম্যাপ।

"long"এবং "short"উভয়ের চিঠি আছে যে সুবিধা গ্রহণ করে o


f=বিনা ব্যতীত বিন্দু মুক্ত ফাংশনগুলির জন্য আপনাকে 2 বাইট প্রদানের দরকার নেই
পোস্ট রক গার্ফ হান্টার

: আপনি lambdabot Haskell পাল্টানোর দ্বারা lambdacase সঙ্গে এক পুরো বাইট সংরক্ষণ করতে পারবেন(>>=(\case 'o'->"Rr";'n'->"rr";'p'->"-";' '->" - ";_->""))
BlackCap

7

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

s=>s.split` `.map(x=>x<'m'?'Rrrr':x<'q'?'-':'Rr').join` - `

let f =

s=>s.split` `.map(x=>x<'m'?'Rrrr':x<'q'?'-':'Rr').join` - `

console.log(f("long long short long short")); // => Rrrr - Rrrr - Rr - Rrrr - Rr
console.log(f("long long long short short short")); // => Rrrr - Rrrr - Rrrr - Rr - Rr - Rr
console.log(f("short short short pause short short short")); // => Rr - Rr - Rr - - - Rr - Rr - Rr
console.log(f("long short short long long pause short short")); // => Rrrr - Rr - Rr - Rrrr - Rrrr - - - Rr - Rr


7

05 এ বি 1 ই , 33 27 25 21 বাইট

#εÇн6&'m×™'-)éθ}… - ý

এটি অনলাইন চেষ্টা করুন!

ব্যাখ্যা

#                       # split input on spaces
 ε             }        # apply to each
  Çн                    # get the character code of the head
    6&                  # AND with 6
      'm×               # repeat "m" this many times
         ™              # title case
          '-)           # wrap in a list with "-"
             éθ         # get the longest string       
                … - ý   # join to string using " - " as separator

মুডিফিশের পাইক উত্তরAND 6 থেকে ট্রিকটি ব্যবহার করে 3 বাইট সংরক্ষণ করা হয়েছে


6

পাইথন 2 , 76 69 64 বাইট

lambda s:' - '.join('Rrrr'[:ord(b[0])&6]or'-'for b in s.split())

এটি অনলাইন চেষ্টা করুন!

পরিবর্তন ঘটান:

পাইথন 2 , 76 69 বাইট

lambda s:' - '.join(['Rrrr','-','Rr'][ord(b[1])%3]for b in s.split())

এটি অনলাইন চেষ্টা করুন!

পাইথন 2 , 69 বাইট

lambda s:' - '.join('-Rrrr'['o'in b:8-ord(b[1])%9]for b in s.split())

এটি অনলাইন চেষ্টা করুন!





4

আর , 77 বাইট

cat(c('Rrrr','Rr','-')[match(scan(,''),c('long','short','pause'))],sep=' - ')

Stdin মাধ্যমে ইনপুট লাগে, চেক কিনা ইনপুট সাথে মিলে যায় long, shortবা pauseএবং অদলবদল জন্য ম্যাচ Rrrr, Rrঅথবা -যথাক্রমে।

এটি পরে পৃথক -হিসাবে স্পেসের সাথে প্যাডযুক্ত প্রিন্ট করা হয় , কাঙ্ক্ষিত আউটপুটটির সাথে মিলে।


ম্যাচ থেকে% এ% তে স্যুইচ করে আপনি 2 বাইট সংরক্ষণ করতে পারেন:scan(,'') %in% c('long','short','pause')
ওয়াইসিআর

@ ওয়াইসিআর আমি মনে করি না যে এটি কাজ করবে। a %in% bকিনা তা পরীক্ষা এন্ট্রিগুলির aমধ্যে উপস্থিত b, যখন match(a, b)আয় ম্যাচ প্রকৃত সূচকের। যেহেতু আমরা অনুমান করতে পারি যে ইনপুটটি বৈধ, তাই ব্যবহার করে %in%কেবল TRUEএস এর ভেক্টর ফিরে আসবে ।
জেএডি

আরফ, সত্য। আমি এটি সি ('দীর্ঘ', 'সংক্ষিপ্ত', 'বিরতি') দিয়ে পরীক্ষা করেছি।
ওয়াইসিআর

কারণ আপনি যখন কোনও বুলিয়ান ভেক্টরকে খাওয়ান [, তখন এটি ব্যাখ্যা করা হয় [which(bool) == TRUE], যা আপনার উদাহরণ হিসাবে দেখাবে [c(1,2,3)]যা ফলস্বরূপ সঠিক আউটপুট দেয়।
জেএডি

বদলে sep=' - 'আপনি ব্যবহার করতে পারেন s=' - '2 জন্য কম বাইট
রিফ্ট

4

রাদা , 73 57 47 46 40 44 বাইট

f&a{a~=*`s\w+|l;Rr;ong;rr;p\w+;-; ; - `/";"}

এটি অনলাইন চেষ্টা করুন!

নিয়ম পরিবর্তনের কারণে +4 বাইট (অবশ্যই ব্যবহার করা উচিত) Rrrr কোনও 4 বর্ণের পরিবর্তে করা )।

পূর্ববর্তী কোড:

{[[split()|["Bzzz"]if[_="long"]else["Bz"]if[_1="short"]else["-"]]&" - "]}

ব্যবহার করে Mmmএবং Mm1 বাইট সংক্ষিপ্ত।
এটাকো

@ATaco এটা প্রশ্নের সালে বলেন যে "লং শব্দসমূহ 4 অক্ষর দীর্ঘ হওয়া উচিত, এবং সংক্ষিপ্ত শব্দ 2 অক্ষর বিশিষ্ট হওয়া উচিত"
ফার্গুসক

এটিাকো, দয়া করে নোট করুন যে মাপদণ্ডে আরও প্রশ্নের উত্তর নির্দিষ্ট করা হয়েছে।
tisaconundrum

4

সি (জিসিসি) , 93 77 76 বাইট

-২ বাইটস সিফিয়োকে ধন্যবাদ!
-1 বাইট ধন্যবাদ সাইওসকে!

একটি ইনপুট হিসাবে একটি NULL সমাপ্ত ** চর বা সমতুল্য লাগে।

f(char**a){for(;*a;*++a&&printf(" - "))printf(**a&6?**a&1?"Rr":"Rrrr":"-");}

এটি অনলাইন চেষ্টা করুন!

ব্যাখ্যা:

f(char**a){
  // While the string at the current position is not NULL
  for(;*a;
    // Advances the pointer to the next string
    // Then if the current string is not NULL, prints a delimiter
    *++a&&printf(" - ")
  )
    /* 
      If the 1st char of the string is not a 'p'
        If the 1st char is not a 'l'
          Prints "Rr"
        Else
          Prints "Rrrr"
      Else:
        Prints "-"
     */
    printf(**a&6?**a&1?"Rr":"Rrrr":"-");
}

2
I think you can combine a++,*a into *++a to save two bytes, and take advantage of the vague "sound" definition to use *a instead of "Rrrr" to save another four bytes.
Scepheo

Your second suggestion is genius!
scottinet

1
Can you move part of the increment stage of the for-loop to the body instead of being comma-separated?
Cyoce

This indeed saves a byte. Good catch!
scottinet


3

Batch, 88 bytes

@set/ps=
@set s=%s: = - %
@set s=%s:long=Rrrr%
@set s=%s:short=Rr%
@echo %s:pause=-%

Takes input on STDIN. Unfortunately loop overhead costs 26 bytes so this is just boring replacements.


2
Suggested edit to remove all of the @s
Stephen

@Stephen Yes, I got the notification...
Neil

Nice! Just two things, though: I counted that answer to be 84 bytes long, not 88. Also, OP has replaced Mmmm and Mm with Rrrr and Rr, it would be nice to update your answer c:
Matheus Avellar

Batch as of what platform? I doubt MS-DOS 6.22 would do what XP does when in enhanced command mode.
TOOGAM

@TOOGAM Yeah, when I say Batch I usually mean Windows NT's CMD.EXE's version.
Neil


2

PHP, 113 bytes

<?$s=[];for($i=1;$i<$argc;$i++){$c=$argv[$i][0];$s[]=($c<'m')?'Rrrr':(($c<'q')?'-':'Rr');}echo implode(' - ',$s);

Try it online!

First attempt at code golf, so probably a lot of optimisations available!


2

Vim (52 bytes)

:s/long/Rrrr/ge|s/short/Rr/ge|s/pause/-/ge|s/ / - /genter

Can probably be made shorter...


Stringing the commands together like this stops the train if one of them errors IE if there's no pause or something in the given string, the replacements after the one that failed won't work. You can either split them on separate lines or put an e flag at the end
nmjcman101

Corrected the error. I still feel there ought to be some way to speed it up, but the only other way I thought of (after turning "pause" into a dash, s/[^ -]/r/, capitalize the first R after every space, trim four-r to two-r) came out longer.
David Heyman

1

Excel, 100 bytes

=REPLACE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"long","- Bzzz"),"short","- Bz"),"pause","- -"),1,2,"")

Per examples, Input is SPACE separated string, as is output.

Question itself does not mention a SPACE requirement, allowing for a slightly shorter 97 byte solution:

=REPLACE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"long","-Bzzz"),"short","-Bz"),"pause","--"),1,1,"")

1

AutoIt, 145 bytes

EXECUTE(STRINGREPLACE('MSGBOX(0,0,STRINGSTRIPWS(====INPUTBOX(0,0),"PAUSE",""),"LONG","Rrrr"),"SHORT","Rr")," "," - "),4))',"=","STRINGREPLACE("))

(AutoIt is really bad choice for code golf, tried my best to make it small as possible)


Welcome to the site! :)
James

1

Alice, 37 bytes

/ lRnrhR
\""orgrp-""!yi'."?-e"ySNo?@/

Try it online!

Explanation

This program makes the following substitutions:

  • l, hR
  • o, n, gr
  • p-
  • Space → Space
  • Everything else → Nothing
"longhp "!i.?eyN?"RrrrR- "y' " - "So@

"longhp "    Push this string
!            Immediately move to tape
i            Take input string
.            Duplicate
?ey          Remove all instances of the characters "longhp " from copy
N            Remove the remaining characters from the original, leaving only "longhp "
?"RrrrR- "y  Replace the characters in "longhp " with the corresponding characters in "RrrrR- "
' " - "S     Replace all spaces with " - "
o            Output
@            Terminate

1

Sed, 50 bytes

Takes input from stdin, prints to stdout

s/l\w*/Rrrr -/g
s/s\w*/Rr -/g
s/p\w*/- -/g
s/ -$//

Edit - saved 2 bytes

Sed, 40 bytes

Copying idea from Nitrodon's answer

s/[srtaue]//g
y/lhongp/RRrrr-/
s/ / - /g

Edit: saved another 2 bytes



0

Paradoc (v0.2.10), 21 bytes (CP-1252)

Wμ‹6&'r\°"-":Ãu}« rTc

Try it online!

Takes a string on the stack and results in a string on the stack. Prepend i to turn into a full program that reads from STDIN.

Uses &6 like the Pyke answer and everybody else, but joins the tokens together slightly differently, by adding a "-" token after each noise, deleting the last one, and then joining these tokens by spaces. Seems to save a byte over joining by " - ".

Explanation:

W                     .. Break into words
 μ             }      .. Map over this block:
  ‹                   .. Take the first character
   6&                 .. Binary AND with 6, to get 4, 2, or 0
     'r               .. Character "r"
       \              .. Swap top two of stack
        °             .. Replicate, to get "rrrr", "rr", or ""
         "-"          .. Push string "-"
            :         .. Duplicate on stack
             Ã        .. Compute the max...
              u       .. ... underneath the top of the stack (so, of the
                      .. second and third elements on the stack, i.e. the
                      .. string of "r"s and "-")
                      .. The mappped block ends here; we now have
                      .. something like ["rrrr", "-", "-", "-", "rr", "-"]
                «     .. Take all but the last
                  r   .. Join with spaces (this built-in's name is two
                      .. characters, the first of which is a space)
                   Tc .. Title-case

v0.2.11 will support shaving two more bytes by replacing with x and "-" with '-.



0

Ruby, 67 bytes

p ARGV[0].split(' ').map{|w|w<'m'?'Rrrr':w<'q'?'-':'Rr'}.join ' - '

This is Johan Karlsson's JavaScript solution ported to Ruby. If you like this answer, you should upvote Johan's answer.

The key idea is to compare the word strings 'short', etc. to a single character in order to distinguish between words.

| Word  | < 'm' | < 'q' | Output |
|-------|-------|-------|--------|
| short | false | false | 'Rr'   |
| long  | true  | N/A   | 'Rrrr' |
| pause | false | true  | '-'    |

Or, in alphabetical order:

  • long
  • m
  • pause
  • q
  • short

Try it online!


0

Ruby, 78 bytes

p ARGV[0].chars.map{|c|{p:'-',o:'Rr',g:'rr',' '.to_sym=>' - '}[c.to_sym]}.join

The only important parts of the input are p, o, g, and space... ignore the rest.

  • short becomes o
  • long becomes og
  • pause becomes p

Try it online!



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