ডাউনওয়ার্ড রেস


10

আপনার কাজটি এমন একটি প্রোগ্রাম তৈরি করা যা চূড়ান্ত সংখ্যা দৌড়ের শোডাউনতে পূর্বের অঙ্কগুলিতে এলোমেলো সংখ্যা যুক্ত করে।

প্রতিটি রেসার (কলাম) 0 থেকে শুরু হয় এবং রেস এর প্রতিটি ধাপে পূর্বের যোগফলের সাথে 1 বা 0 যোগ করে যতক্ষণ না সমস্ত রেসারের জয়ের জন্য প্রয়োজনীয় স্কোর পৌঁছে যায়। 1 বা 0 টি এলোমেলোভাবে বেছে নেওয়া উচিত (এলোমেলো স্ট্যান্ডার্ড সংজ্ঞা এখানে পাওয়া যাবে )। আউটপুট এই বিন্যাসে প্রতি কলামে একটি রেসারকে উপস্থাপন করে প্রতিযোগিতার ফলাফল প্রদর্শন করবে:

>> racers:5,score needed:2

0 0 0 0 0 # all racers start at 0
+ + + + + # add
1 0 0 0 1 # random 1 or 0
= = = = = # equals
1 0 0 0 1 # sum
+ + + + +
0 0 0 0 1
= = = = =
1 0 0 0 2 # winner!
+ + + +  
1 1 1 1  
= = = =  
2 1 1 1  
  + + +  
  1 1 1  
  = = =  
  2 2 2   # losers

দ্রষ্টব্য: কেবলমাত্র সংখ্যা, +, এবং = আউটপুটে অন্তর্ভুক্ত করা দরকার।

ইনপুট

আপনার প্রোগ্রামটি ইনপুট হিসাবে নিম্নলিখিত দুটি পরামিতি গ্রহণ করবে:

  1. রেসারের সংখ্যা (কলাম), যা অবশ্যই দু'জনের বেশি হতে হবে
  2. জয়ের জন্য প্রয়োজনীয় স্কোর, যা অবশ্যই একের বেশি হওয়া উচিত

এটি কোড-গল্ফ - সর্বনিম্ন বাইটস সহ প্রোগ্রামটি।

সম্পাদনা করুন: 9 এর অ-প্রয়োগযোগ্য সর্বোচ্চ স্কোর রয়েছে - এটি কলামটির অখণ্ডতা রক্ষা করার জন্য to এছাড়াও, কলামগুলির মধ্যে ফাঁকা স্থানগুলি আউটপুটে বাদ দেওয়া যেতে পারে।


সর্বাধিক সংখ্যক কলাম এবং সর্বাধিক স্কোর যা সমর্থন করতে হবে?
ন্যানোফারাড

এখানে কোনও সংজ্ঞায়িত সর্বোচ্চ নেই, সুতরাং এটি সর্বনিম্নের মতো হবে: কমপক্ষে তিনটি কলাম এবং দুটি স্কোর of
এটলোলজিস্ট

3
প্রয়োজনীয় স্কোরের দুটি অঙ্ক থাকবে?
লিকি নুন

4
"কেবল সংখ্যা, +, এবং = আউটপুটে অন্তর্ভুক্ত করা দরকার" " জায়গা সম্পর্কে কি?
ফাঁস নুন

স্পেসগুলি সংরক্ষণ করার দরকার নেই, তারা স্বচ্ছতার জন্য উদাহরণ হিসাবে রয়েছে। দুটি সংখ্যা সম্পর্কে ভাল প্রশ্ন - আমি মনে করি একটি সর্বোচ্চ স্কোর আছে, যা নয়টি। আমি প্রশ্নটি সম্পাদনা করব।
এটোলজিস্ট

উত্তর:


5

জেলি, 37 36 33 বাইট

,‘X
0Ç<³$пµżIFµ“+=”ṁṖ⁸żF
ÇСḊz⁶G

ডেনিসকে 3 বাইট ধন্যবাদ

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

ব্যাখ্যা

,‘X                    Helper link. Argument: n. Radomly return n or n+1.

 ‘                     Increment n
,                      Pair. Yield [n, n+1]
  X                    Return a random item from the pair.

0Ç<³$пµżIFµ“+=”ṁṖ⁸żF   Monadic link. Argument: s. Generate one racer.

0                       Start with value 0.
  <³$пµ                While value is less than s:
 Ç                        Use helper link to increment current value.
                        Collect intermediate results in a list.
         I              Compute consecutive differences.
        ż               Zip intermediate results with their next increment value 0 or 1.
          Fµ            Flatten. Let's call the current list A.
                        Odd items of A are racer state and even items are random 0 or 1.
            “+=”        Yield "+=".
                 Ṗ      Yield A without its last element.
                ṁ       Mold i.e Repeat the characters of the string until it contains length(A)-1 characters.
                  ⁸ż    Zipwith. Pair the elements of A with the correponding characters
                    F   Flatten.

ÇСṫ2z” G               Main link. Arguments: s (score needed), r (#racers)

ÇС                     Call the link above r times.
                        Generate a list of r racers.
   Ḋ                    Remove first element of the list (its a garbage s value)
    z⁶                  Transpose with space as fill value.
      G                 Grid. Format the result.

আপনি প্রথম সহায়ক সহায়িকার লিঙ্কটি ,‘X(বর্ধিত এন এর সাথে যুক্ত , এলোমেলো পছন্দ সহ) প্রতিস্থাপন করতে পারেন । মূল লিঙ্কে (ডিকু) এবং ভেরিয়েবলের সাথে ṫ2প্রতিস্থাপন করা যেতে পারে ।
ডেনিস


2

টিএসকিউএল, 367 345 341 বাইট

Golfed

DECLARE @r int=20, -- racers
        @g char=2  -- goal

DECLARE @ varchar(99)=REPLICATE('0',@r)a:PRINT @
DECLARE @A varchar(99)='',@s varchar(99)='',@i int=0WHILE @i<@r
SELECT
@i+=1,@A+=char(43-x*11),@s+=IIF(x=1,' ',LEFT(y,1)),@=RIGHT(@,@r-1)+IIF(x=1,' ',REPLACE(LEFT(@,1)+y,@g+1,' '))FROM(SELECT
IIF(LEFT(@,1)IN('',@g),1,0)x,ROUND(RAND(),0)y)z
PRINT @A+'
'+@s+'
'+REPLACE(@A,'+','=')IF @>''goto a

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

Ungolfed:

DECLARE @r int=10, -- racers
        @g char=2  -- goal

DECLARE @ varchar(99)=REPLICATE('0',@r)
a:
PRINT @
DECLARE @A varchar(99)='',@s varchar(99)='',@i int=0

WHILE @i<@r
  SELECT
    @i+=1,
    @A+=char(43-x*11),
    @s+=IIF(x=1,' ',LEFT(y,1)),
    @=RIGHT(@,@r-1)+IIF(x=1,' ',REPLACE(LEFT(@,1)+y,@g+1,' '))
  FROM(SELECT IIF(LEFT(@,1)IN('',@g),1,0)x,ROUND(RAND(),0)y)z

PRINT @A+'
'+@s+'
'+REPLACE(@A,'+','=')

IF @>''GOTO a

নোট করুন যে পরীক্ষার সাইটে এলোমেলো বীজ সর্বদা একই থাকে, প্রতিবার একই ফলাফল দেয়, স্টুডিও পরিচালনায় এটি বিভিন্ন ফলাফল দেয়। রেসারের জন্য বিভিন্ন মান এবং বিভিন্ন চিত্র পেতে লক্ষ্য ব্যবহার করতে পারে


1

পাইথন 3, 237 বাইট

from random import*
def f(n,t):
 x='0'*n,;i=j=0;y=''
 while' '*n!=x[i]:
  if j==n:j=0;x+=y,;y='';print(x[i]);i+=1
  y+=' 'if x[i][j]in(' ',str(t))else eval(["'+'","str(randint(0,1))","'='","str(int(x[i-3][j])+int(x[i-1][j]))"][i%4]);j+=1

একটি ফাংশন যা স্টুডুটের মাধ্যমে ইনপুট নেয় এবং প্রিন্ট করে STDOUT। এই পদ্ধতিটি এই সত্যটি ব্যবহার করে যে আউটপুট সমস্ত রেসারের জন্য '+ মান = মান' ফর্মের চারটি সময়কালের একটি চক্র অনুসরণ করে। কাউন্টার মডুলো ফোর ব্যবহার করে স্ট্রিং হিসাবে প্রতিটি ধাপের জন্য কাঙ্ক্ষিত মান যুক্ত একটি তালিকা এতে সূচিযুক্ত করা যেতে পারে এবং পাইথনের ইওল ফাংশন ব্যবহার করে ফলাফলটি মূল্যায়ন করা যায়।

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

from random import*                       Import Python's random module to access the
                                          randint function
def f(n,t):                               Function with input number of racers n and target
                                          number t
x='0'*n,;i=j=0;y=''                       Initialise return tuple storage x, state number
                                          i, racer number j and append string y for x
while' '*n!=x[i]:                         Loop through all j for some i. If the current
                                          state consists only of spaces, all racers have
                                          finished, so stop
y+=...eval([...][i%4])...                 Index into list, using i mod 4, to find the
                                          desired process for the cycle step, and append to
                                          y
(If first step of cycle)
...+...                                   Plus sign
(If second step of cycle)
...str(randint(0,1))...                   Random number from (0,1)
(If third step of cycle)
...=...                                   Equals sign
(If fourth step of cycle)
...str(int(x[i-3][j])+int(x[i-1][j]))...  Addition of random number to previous racer
                                          'score'
...' 'if x[i][j]in(' ',str(t))...         But append space if the racer has previously
                                          finished, or has reached the target
...j+=1                                   Increment j
if j==n:j=0;x+=y,;y='';print(x[i]);i+=1   If j=n, all j must have been looped through.
                                          Reset j, append new state y to x, reset y, print
                                          current state to STDOUT and increment i. When
                                          this first executes, x contains only the initial
                                          state, meaning that this is printed and the cycle
                                          starts with the second state.

আইডিয়নে চেষ্টা করে দেখুন


1

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

from random import*
def c(p,w,r=[],l=0):
 while p:
	p-=1;s='0'
	while`w`>s[-1]:s+="+%s="%randint(0,1);s+=`eval(s[-4:-1])`;l+=2
	r+=[s]
 for z in map("".join,zip(*(t+l*' 'for t in r))):print z

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


পাইথন 3 , 200 বাইট

from random import*
def c(p,w,r=[],l=0):
 while p:
  p-=1;s='0'
  while str(w)>s[-1]:s+="+%s"%randint(0,1);s+="=%s"%eval(s[-3:]);l+=2
  r+=[s]
 for z in map("".join,zip(*(t+l*' 'for t in r))):print(z)

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


0

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

import random
r=5
w=2
s=(0,)*r
while s.count(w)<len(s):
    print ''.join(map(lambda a:str(a),s))+"\n"+'+'*len(s)
    s = tuple(map(lambda x: x<w and x+random.randrange(2) or x,s))
    print ''.join(map(lambda a:str(a), s))+"\n"+'='*len(s)
    s = tuple([x for x in s if x!= w])

আর আর কোথায়? রেসার্স এবং ডাব্লু এর জয়ের স্কোর

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


2
আমি আপনার প্রোগ্রামটি পরীক্ষা করেছি, এটি প্রশ্নের হিসাবে বর্ণিত ফলাফলটি দেখায় না, সবকিছু বামে সরানো হয়েছে।
t-clausen.dk

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