সাধারণ এএসসিআইআই গ্যান্ট


31

এটি একটি সহজ: একটি ASCII গ্যান্ট চার্ট মুদ্রণ করুন ।

প্রদত্ত টাস্কের ব্যাপ্তি (শুরুর সময় - শেষ সময় টিপলস), -প্রতিটি টাস্কের সময়কালের জন্য অক্ষরের আকারে একটি গ্যান্ট টাইমলাইন মুদ্রণ করুন - প্রতিটি টাস্ককে একটি নতুন লাইনে।

উদাহরণ

বলুন আমার কাজগুলির ব্যাপ্তি 28->35, 34->40, 39->44হ'ল, গ্যান্ট এইরকম দেখবে:

                            -------
                                  ------
                                       -----

বিশেষ উল্লেখ

  • আপনি একটি সম্পূর্ণ প্রোগ্রাম, একটি নামকৃত ফাংশন বা কোনও বেনামি ফাংশন লিখতে পারেন।
  • আপনার প্রোগ্রাম / ফাংশনটি STDIN এর মাধ্যমে বা যুক্তি হিসাবে কাজগুলি গ্রহণ করবে ।
  • প্রতিটি টাস্কের একটি স্ট্রিং হিসাবে প্রতিনিধিত্ব করা উচিত start->endযেখানে startএবং endআছে ইন্টিজার । কার্যগুলি স্পেস বা কমা দ্বারা পৃথক করা হয়। বিকল্পভাবে , আপনি এটি পূর্ণসংখ্যার টুপল হিসাবে বা 2 সংখ্যার অ্যারে / সংগ্রহ হিসাবে পেতে পারেন। (উদাহরণস্বরূপ, জাভাস্ক্রিপ্টে আপনি এটি এটি হিসাবে পেতে পারেন [start,end]- এটি অনুমোদিত)।
  • যেকোন অ-নেতিবাচক সংখ্যা (আর্গুমেন্ট) সমর্থন করা উচিত।
  • এটি পরিষ্কার করার জন্য, কার্য সংগ্রহের একক যুক্তি অনুমোদিত নয়। আপনি হয় একটি একক স্ট্রিং আর্গুমেন্টকে পার্স করতে পারেন, বা শূন্য বা আরও বেশি কার্য যুক্তি সমর্থন করতে পারেন। যেখানে টাস্ক একটি টিপল বা আকার 2 এর সংগ্রহ।
  • আপনি ধরে নিতে পারেন কেবল বৈধ ইনপুট দেওয়া হবে। তার মানে, প্রতিটি কাজের ইতিবাচক সময়কাল থাকে has
  • রিটার্ন মানটি কিছু যায় আসে না, আপনার কোডটি অবশ্যই STDOUT এ টাইমলাইন মুদ্রণ করবে।
  • আউটপুট: প্রতিটি কার্যক্রমে startফাঁকা স্থান এবং এর পরে (end-start)\n
  • বলা বাহুল্য, আউটপুট লাইনগুলি আনুষ্ঠানিকভাবে ইনপুট (কার্য) আদেশের সাথে অর্ডার করা উচিত।
  • \nঅনুমতি দেওয়ার আগে স্পেস ফাঁকা রাখা , যদি এটি আপনাকে সহায়তা করে।

পরীক্ষার মামলা

Input:
(empty)

Output:
(empty)


Input:
0->7,5->6,3->6

Output:
-------
     -
   ---


Input:
5->20,5->20,2->10,15->19

Output:
     ---------------
     ---------------
  --------
               ----

জয়লাভ

  • এটি তাই সর্বনিম্ন কোড দৈর্ঘ্য (বাইটে) জিতে।
  • Ditionতিহ্যগতভাবে, টাই ব্রেকার আগের পোস্ট।
  • "স্ট্যান্ডার্ড লুফোলগুলি আর মজার নয়"।

-----

সম্পাদনা

আপনারা অনেকেই বুঝতে পেরেছিলেন যে এটির একটি একক টাস্ক সংগ্রহের আর্গুমেন্ট থাকার অনুমতি রয়েছে এবং যেহেতু এটির সাথে মূল ভার্সাগুলির প্রয়োজনীয়তার মধ্যে খুব একটা আলাদা নয়, এখন আপনি যদি ব্যবহার করতে না চান তবে এটি একটি একক সংগ্রহের যুক্তি রাখার অনুমতি পেয়েছে you varargs বিকল্প, অথবা যদি আপনার ভাষা varargs সমর্থন করে না।


1
পয়েন্ট 3 পরিষ্কার মনে হচ্ছে। তবে পাইন্ট 5 ( To make it clear...) মোটেই পরিষ্কার নয়।
edc65

ঠিক আছে, আমাকে আবার জবাব দেওয়া যাক: আপনি কোনও ফাংশন লিখতে পারবেন না যা স্ট্রিং না হলে আপনি ঠিক একটি যুক্তি গ্রহণ করে। এটি আমরা যে কয়েকটি টিপলস নিয়ে কথা বলছি তা যদি হয় তবে সেগুলি কোনও সংগ্রহের মধ্যে আবৃত না হয়ে যুক্তি হিসাবে আপনার ফাংশনে প্রেরণ করা যেতে পারে। উদাহরণস্বরূপ, জাভাস্ক্রিপ্টে: আপনি argumentsফাংশনটির মধ্যে পুনরাবৃত্তি করতে পারেন, তবে আপনি এটি ধরে নিতে পারেন না যে arguments[0]এটি কার্যগুলির একটি অ্যারে।
জ্যাকব

8
সমস্ত ভাষার জন্য কেবল অ্যারে / তালিকা / ভেক্টর / ইত্যাদি হিসাবে ইনপুটটিকে কেন অনুমতি দেবেন না? ব্যক্তিগত পছন্দটি বেশ দুর্বল কারণে বলে মনে হচ্ছে।
ডুরকনব

1
ভার্জস বনাম আর্গুমেন্ট লিস্টটি একটি সম্পূর্ণ সিন্ট্যাকটিক পার্থক্য এবং এই প্রশ্নের বিধিগুলি আমার মতে ব্যাখ্যার একটি অপ্রয়োজনীয় এবং স্বেচ্ছাসেবী ডিগ্রি পর্যন্ত রেখে দেয়।
জন

2
@ জ্যাকব জ্ঞান অর্জন করে। ভবিষ্যতের চ্যালেঞ্জগুলির জন্য, আমি যতটা সম্ভব একটি ইনপুট স্পষ্টের লক্ষ্যে সুপারিশ করব: ম্যানলিং ইনপুট চ্যালেঞ্জের অংশ হওয়া উচিত নয়।
আদম

উত্তর:


14

সিজেম, 16 14 বাইট

q~{S.*~'-e]N}/

এটি ইনপুট হিসাবে তালিকার একটি তালিকা প্রত্যাশা করে। উদাহরণ স্বরূপ:

[[5 20] [5 20] [2 10] [5 19]]

দেয়:

     ---------------
     ---------------
  --------
     --------------

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

q~                      e# Read the input and parse it as a list of list
  {         }/          e# Go over each item in the list in a for loop
   S                    e# S is basically this string - " "
    .*                  e# Multiply each item of the first list with the corresponding index
                        e# item of the second list. This basically repeats the space
                        e# X times where X is the first number of the tuple. The second
                        e# number remains untouched as the second list was only 1 char long
      ~                 e# Unwrap the space string and second number containing list
       '-               e# Put character '-' on stack
         e]             e# Make sure that the space is filled with - to its right so as to
                        e# make the total length of the string equal to the second number
           N            e# Put a newline. After all iterations, the result is printed
                        e# automatically to STDOUT

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


20

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

স্ট্রিং গুণকে ব্যবহার করে সোজা সমাধান :)

for x,y in input():print' '*x+'-'*(y-x)

ইনপুট বিন্যাস যেমন গ্রহণ করে:

((5,20),(5,20),(2,10),(15,19))

এটি এখানে দেখুন।


11

ব্রেইনফাক, 120 115 111 বাইট

কমপক্ষে এটি জাভা থেকে কম সংক্ষিপ্ত :) ইনপুটটি বাইটের একটি তালিকা, যেখানে প্রতিটি জুটি গ্যান্টের একক লাইন।

++++[->++++++++<]>[->+>+<<]++++++++++>>+++++++++++++>+[,[->+>+<<]>>[-<<+>>],<[->-<<<<.>>>]>[-<<<.>>>]<<<<<.>>>]

চেষ্টা

http://copy.sh/brainfuck/

charমান সহ ইনপুট অফ ইনপুট সেট করুন \0। উদাহরণ ইনপুট: \5\20\5\20\2\10\15\19

নোট করুন যে ইনপুটটির মানটির সেট-এ এর \0পার্শ্ব প্রতিক্রিয়াটি হবে যে ইনপুটটিতে শূন্য সংখ্যা উপস্থিত থাকলে আর কোনও ইনপুট পড়তে হবে না (এবং এভাবে প্রোগ্রামটি থামানো হবে)। বিএফ-এ কখন ইনপুট শেষ হয়ে যায় তা জানার উপায় নেই।

ব্যাখ্যা *

++++[->++++++++<]>  #Store <space> at index 1                   
[->+>+<<]           #Move index 1 to index 2 and 3
++++++++++          #Increment index 1 to <newline>
>>                  #Move to index 3
+++++++++++++       #Increment index 3 to <dash>    
>                   #Move to (empty) index 4
+                   #Increment to start the main loop
[                   #Main loop
,                   #Read first number to index 4
[->+>+<<]>>[-<<+>>] #Copy index 4 to index 5 (index 5 can now be altered)
,                   #Read second number (the number pair is now stored at index 5 and 6)
<                   #Move to first number (index 5)
[->-<<<<.>>>]       #Decrement index 5 and 6 and print <space> until index 5 equals zero
>                   #move to second input (index 6)
[-<<<.>>>]          #Decrement index 6 and print <dash> until index 6 equals zero
<<<<<.>>>           #Print <newline> and move to index 4 (original first number)
]                   #End of main loop

* (মন্তব্যের কারণে আপনি এটি সংকলন / পরিচালনা করতে সক্ষম হবেন না)


6
জাভা => বিশ্বের চেয়ে ছোট ব্রেনফাক শীঘ্রই শেষ হবে।
অ্যালেক্স এ

1
ব্যাখ্যা আসলে জরিমানা করা উচিত। কেবলমাত্র bf কমান্ডগুলি এখানে রয়েছে <এবং আছে> এবং তারা পুরোপুরি ভারসাম্যপূর্ণ।
আন্ডারগ্রাউন্ডোমোনাইল

@ندرগ্রাউন্ডোমোরিয়েল খুব ভাল লেগেছে, আমি সেগুলি ভারসাম্যপূর্ণ কিনা তা দেখার চেষ্টাও করিনি;)
রল্ফ ツ

8

পাইথ, 36 22 19 14 বাইট

এটি আমার প্রথম পাইথ প্রোগ্রাম। জাকুব গল্ফকে 5 বাইট আউট করতে সহায়তা করেছিল!

FNQ<s*V" -"NeN

এটি ফর্মটিতে ইনপুট আশা করে [[5,20], [5,20], [2,10], [15,19]]

আপনি এটি অনলাইনে চেষ্টা করতে পারেন ।


5

সি ++ 14, 69 বাইট

[]{int a,b;for(;cin>>a>>b;){cout<<setw(b)<<string(b-a,'-')+'\n';}}();

প্রথম বার গল্ফিং, এটি দিয়ে শুরু করা ভাল সমস্যা ছিল!


2
আপনি প্রয়োজন নেই std::উপর cinএবং cout?
অ্যালেক্স এ।

3

কে, 18 বাইট

`0:" -"@{&x,y-x}.'

ইনপুট হিসাবে জোড়াগুলির তালিকা প্রত্যাশা করে:

  `0:" -"@{&x,y-x}.'(0 7;5 6;3 6)
-------
     -
   ---
  `0:" -"@{&x,y-x}.'(5 20;5 20;2 10; 15 19)
     ---------------
     ---------------
  --------
               ----
  `0:" -"@{&x,y-x}.'()

আমি 'ডট-অ্যাপ্লিকেশন ( ) ব্যবহার করে প্রতিটি ( ) টিপল আনপ্যাক করি .যাতে ল্যাম্বদার ভিতরে আমার যথাক্রমে xএবং প্রারম্ভিক এবং শেষের মানটি অ্যাক্সেস yহয়। তারপরে আমি এগুলিকে একটি (সূচনা, দৈর্ঘ্য) টিপল ( x,y-x) এ পুনরায় সংশ্লেষ করি এবং "যেখানে" ( &) প্রয়োগ করি । এটি আমার মতো আউটপুট দেয়:

  {&x,y-x}.'(0 7;5 6;3 6)
(1 1 1 1 1 1 1
 0 0 0 0 0 1
 0 0 0 1 1 1)

তারপরে আমাকে কেবল এই র‌্যাগড ম্যাট্রিক্স ( " -"@) ব্যবহার করে একটি 2-অক্ষরের অ্যারেতে সূচক করতে হবে এবং এটিকে সব স্টাডআউট ( 0:) এ প্রেরণ করতে হবে ।


3

জাভাস্ক্রিপ্ট ( ইএস 6) ), 63

3 বাইট সংরক্ষিত thx @apsillers সম্পাদনা করুন
63 বাইট এফ থেকে অ্যাসাইনমেন্ট গণনা না করে একটি বেনামি ফাংশন অনুমোদিত।

অনুরোধ অনুসারে প্যারামিটারগুলির একটি চলক সংখ্যার একটি ফাংশন।
একক প্যারামিটার হিসাবে কার্যগুলির তালিকা সহ একটি ফাংশন।

নীচে স্নিপেট চলমান পরীক্ষা করুন (শুধুমাত্র এক্সমা স্ক্রিপ্ট,, কেবল ফায়ারফক্স)

F=l=>l.map(t=>console.log(' '.repeat(l=t[0])+'-'.repeat(t[1]-l)))

// TEST

// for this test, redefine console.log to have output inside the snippet
console.log = (...x) => O.innerHTML += x + '\n';

console.log('* Empty'); F([]);
console.log('\n* [0,7],[5,6],[3,6]'); F([[0,7],[5,6],[3,6]])
console.log('\n* [5,20],[5,20],[2,10],[15,19]');F([[5,20],[5,20],[2,10],[15,19]]);
<pre id=O></pre>


একটি গ্লোবালকে বরাদ্দ t[0]করে একটি বাইট সংরক্ষণ করুন (বা আপনি বিশ্বব্যাপী করতে না lচাইলে আপনি নিরাপদে এটি নির্ধারণ করতে পারেন)। এছাড়াও, অনুমানটি "একটি নামযুক্ত ফাংশন বা একটি অনামী ফাংশন" এর অনুমতি দেয় যাতে আমার মনে হয় আপনি F=আপনার বাইট গণনাটিতে বাদ দিতে পারেন ।
অ্যাপসিলাররা

@ অ্যাপ্লায়ার্স আমি চিন্তাভাবনা মিস করেছি anonymous। ধন্যবাদ
edc65

3

স্কালা, 67 63 59 বাইট

(r:Seq[(Int,Int)])⇒for((s,e)←r)(println(" "*s+"-"*(e-s)))

ব্যবহার: res0()বা res0(Seq(28->35, 34->40, 39->44))ইত্যাদি

অভিব্যক্তির জন্য একটি 4 বাইট শেভ করার জন্য গিলাদ ধন্যবাদ!


2

রুবি: 35 টি অক্ষর

->*t{t.map{|s,e|puts' '*s+?-*(e-s)}

নমুনা রান:

irb(main):001:0> ->*t{t.map{|s,e|puts' '*s+?-*(e-s)}}.call [0,7], [5,6], [3,6]
-------
     -
   ---

একাধিক দ্বি-উপাদান অ্যারে গ্রহণের জন্য আপডেট হয়েছে, প্রতিটি কাজের জন্য প্রদর্শন করার জন্য একটি। (আমি মনে করি আপডেটের প্রয়োজনীয়তা এটিই প্রত্যাশা করে))


2

জাভাস্ক্রিপ্ট (ES6), 61/66 অক্ষর

আমার উত্তরটি @ edc65 দ্বারা পোস্ট করা একটির সাথে প্রায় একই, তবে কিছু উন্নতি সহ। যেহেতু একক অ্যারেগুলিতে কাজ করার অনুমতি নেই (সুতরাং ফাংশনটিকে এভাবে বলা হবে a([3,4], [7,15], [0,14], [10, 15]):), সঠিকটি হ'ল ( নাম নির্ধারণ ছাড়াই 66 66 টি অক্ষর ):

a=(...x)=>x.map(([c,d])=>console.log(' '.repeat(c)+'-'.repeat(d-c)))

এবং যদি একটি অ্যারে আর্গুমেন্টের অনুমতি দেওয়া হয় (সুতরাং এর মতো কল করা কল a([[3,4], [7,15], [0,14], [10, 15]])) : তবে এটি ( নির্ধারিত বিনা 61 টি চর ) হবে:

a=x=>x.map(([c,d])=>console.log(' '.repeat(c)+'-'.repeat(d-c)))

1

এসডাব্লুআই-প্রোলগ, 55 বাইট

a([[A,B]|C]):-tab(A),writef("%r",[-,B-A]),nl,C=[];a(C).

উদাহরণ: a([[5,20],[5,20],[2,10],[15,19]]).আউটপুটস

     ---------------
     ---------------
  --------
               ----

আমি দুঃখিত তবে এই উত্তরের ইনপুট ফর্ম্যাটটি নির্দিষ্টকরণের সাথে মেলে না - প্রতিটি কাজ দুটিতে নয়, একটি যুক্তিতে উপস্থাপন করা উচিত। (যদি আমি এসডব্লিউআই-প্রোলোগ সিন্টেক্সে কিছু মিস না করি যার সাথে আমি পরিচিত নই ...)
জ্যাকব

@ জ্যাকব হ্যাঁ আপনার পোস্টটি পুনরায় পড়ার সময় আমি এটি অনুধাবন করেছি এবং ইতিমধ্যে আমার কোডটিকে এর জন্য অ্যাকাউন্টে পরিবর্তন করেছি।
মারাত্মক করুন

1

হাস্কেল, 76 বাইট

(#)=replicate
f i=putStr$g=<<(read$'[':i++"]")
g(s,e)=s#' '++(e-s)#'-'++"\n"

ইনপুট ফর্ম্যাট হ'ল কমা দ্বারা পৃথক করা টিউপসগুলির একটি স্ট্রিং, যেমন "(1,2),(3,4)"

ব্যবহারের উদাহরণ:

*Main> f "(1,2),(3,4)" 
  -
    -

*Main> f "(0,7),(5,6),(3,6)" 
-------
     -
   ---

এটা কিভাবে কাজ করে: ইনপুট পার্স আমি ইনপুট স্ট্রিং ঘিরা [এবং ]এবং Haskell এর নেটিভ ব্যবহার readপূর্ণসংখ্যা tuples তালিকা জন্য ফাংশন। বাকীটি সহজ: প্রতিটি টিপলের (s,e)জন্য sস্থান অনুসরণ করেe-s ড্যাশগুলি পরে একটি নতুন লাইন পরে এবং সমস্তগুলি একক স্ট্রিংয়ের সাথে যুক্ত করে। ছাপা.

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

শিথিল ইনপুট ফর্ম্যাট সহ:

(#)=replicate
f=putStr.(g=<<)
g(s,e)=s#' '++(e-s)#'-'++"\n"

এখন এটি tuples একটি তালিকা লাগে, যেমন f [(0,7),(5,6),(3,6)]

উপরে বর্ণিত হিসাবে কাজ করে তবে ইনপুট পার্সিং ছাড়াই।


1

জুলিয়া, 44 বাইট

x->for t=x a,b=t;println(" "^a*"-"^(b-a))end

এটি একটি বেনামে ফাংশন তৈরি করে যা ইনপুট হিসাবে টিপলগুলির একটি অ্যারে গ্রহণ করে এবং STDOUT- এ প্রিন্ট করে।

অবহেলিত + ব্যাখ্যা:

function f(x)
    # Loop over the tasks (tuples) in x
    for t in x
        # Assign a and b to the two elements of t
        a,b = t

        # Print a spaces followed by b-a dashes on a line
        println(" "^a * "-"^(b-a))
    end
end

উদাহরণ:

julia> f([(5,20), (5,20), (2,10), (15,19)])
     ---------------
     ---------------
  --------
               ----

julia> f([(0,7), (5,6), (3,6)])
-------
     -
   ---

julia> f([])

অবশ্যই। অসুবিধার জন্য দুঃখিত.
জ্যাকব

@ জ্যাকব: কোনও অসুবিধা নেই। দুর্দান্ত চ্যালেঞ্জ। :)
অ্যালেক্স এ

1

জাভাস্ক্রিপ্ট (ES6), 106 85 80 68 বাইট

আপডেট হওয়া প্রয়োজনীয়তা অনুসারে, কার্যগুলির একটি তালিকা এখন গ্রহণযোগ্য

a=>a.reduce((p,v)=>p+=' '.repeat(z=v[0])+'-'.repeat(v[1]-z)+"\n",'')

শূন্য বা আরও বেশি আর্গুমেন্ট নেয়: 80 বাইট

(...a)=>{s='';a.map(v=>s+=' '[r='repeat'](z=v[0])+'-'[r](v[1]-z)+"\n");return s}

আসল প্রচেষ্টা, 106 বাইট:

(...a)=>{for(i=-1,s='',r='repeat';a.length>++i;){s+=' '[r](a[i][0])+'-'[r](a[i][1]-a[i][0])+"\n"}return s}

যদি এটি ES6 হয়, তবে কেন নয় String.repeat()?
manatwork

@ মানাত্কার আমাকে নতুন কিছু দেখানোর জন্য ধন্যবাদ !! দুর্ভাগ্যবশত কোড গলফ জন্য এটা ব্যবহার করা আসলে আর যে
rink.attendant.6

প্রকৃতপক্ষে, এটি দ্বিমাত্রিক aসত্যই সহায়তা করে না। আমি মনে মনে কিছু ছিল ()=>{for(i=0,s='';a=arguments[i++];)s+='_'.repeat(a[0])+'-'.repeat(a[1]-a[0])+"\n";return s}
manatwork

r = 'পুনরাবৃত্তি'? ... 2 বার? নাহ! a=>a.reduce((p,v)=>p+=' '.repeat(z=v[0])+'-'.repeat(v[1]-z)+"\n",'')
edc65

1
কোনও আউটপুট নেই। Return value does not matter, your code must print the timeline on STDOUT.(এবং আরও সংক্ষিপ্ত হবে)
edc65

1

সি: 108 বাইট

void g(int*l){for(int c=0;*l>=0;c=!c,l++){if(!c)l[1]-=*l;while(l[0]-->0)putchar(c?45:32);c?putchar(10):0;}}

Ungolfed:

void gantt(int*l) {
    for (int c = 0; *l >= 0; c = !c, l++) {
        if (!c) l[1] -= *l;
        while (l[0]-- > 0) putchar(c? 45 : 32);
        c? putchar(10) : 0;
    }
}

পরামিতি হিসাবে শেষ হওয়া পূর্ণসংখ্যার একটি তালিকা করে -1। উদাহরণ স্বরূপ:

int list[] = {
    28, 35,
    34, 40,
    39, 44,
    -1
};
gantt(list);

এটি cলেখার স্থান এবং ড্যাশগুলির মধ্যে টগল করতে ব্যবহার করে।


1
সি স্ট্যাটিক তৈরি করুন - আপনি এর ধরণটি (ড্রপ করতে পারেন) এবং সূচনা করতে পারেন (এটি শূন্য হবে)। সংক্ষিপ্ত *l>=0হিসাবে একই *l+1c&&putcharত্রৈমাসিকের চেয়ে ছোট is তোমাদের স্থলাভিষিক্ত তাহলে c=!cসঙ্গে c^=13(+1 টি বাইট) আপনি পরিবর্তন করতে পারেন c?45:32থেকে 32+c(-3 বাইট)। সরান cথেকে উল্টানো forলুপ শেষে: (c^=13)||putchar(10);c;void g(int*l){for(;*l+1;l++){l[1]-=c?0:*l;while(l[0]--)putchar(32+c);(c^=13)||putchar(10);}}- 94 বাইট।
আরগের

1

পার্ল: 42 41 টি অক্ষর

স্ট্রিং পার্সিংয়ের সাথেও কমপক্ষে একটি সমাধান থাকতে হবে।

s!(\d+)->(\d+),?!$"x$1."-"x($2-$1).$/!ge

নমুনা রান:

bash-4.3$ perl -pe 's!(\d+)->(\d+),?!$"x$1."-"x($2-$1).$/!ge' <<< '0->7,5->6,3->6'
-------
     -
   ---

প্রকৃতপক্ষে আমাদের কাছে ইতিমধ্যে জাভা উত্তরটি রয়েছে যা একটি স্ট্রিংকে বিশ্লেষণ করে :) যাইহোক, পাশাপাশি এটির জন্যও ধন্যবাদ!
জ্যাকব

হ্যাঁ, তবে আমি বুঝতে পারি যে কমা দ্বারা পৃথক হওয়া সংখ্যাগুলি প্রত্যাশা করে, প্রশ্নটিতে উল্লিখিত বিন্যাসটি নয়।
manatwork

1

জাভা 8, 280 275 246 204 195 185 180 বাইট

void g(String t){for(String s:t.split(",")){String[]a=s.split("->");s="";Integer i;for(i=0;i<i.valueOf(a[0]);i++)s+=" ";for(;i<i.valueOf(a[1]);i++)s+="-";System.out.println(s);};};

একটি পদ্ধতি যা কমা-পৃথকীকরণের ইনপুট স্ট্রিং নেয় এবং ফলস্বরূপ আসকি গ্যান্ট চার্টটি স্ট্ডআউটে প্রিন্ট করে।

আমাকে 10 বাইট সংরক্ষণে সহায়তার জন্য durron597 এবং মাস্টার X244 ধন্যবাদ


I think you're allowed to use a method instead.
lirtosiast

It is allowed iff this is the (or a) way to create an anonymous function in Java8. Is it?
Jacob

It's the closest thing Java 8 has to such a feature.
SuperJedi224

If you do Integer i=0; you can do for(;i<i.parseInt;, saving 8 characters.
durron597

I couldn't get it to compile on Ideone, but it appears that it would not accept empty input, as the rules require (t.split(",") would throw an exception).
Nateowami

1

Java, 187 181 197 183 101 bytes

void g(int[][]g){for(int[]i:g)for(int j=0;j<i[1];System.out.print(j++<i[0]?" ":j==i[1]?"-\n":"-"));}

Ungolfed (sort of):

void g(int[][] g){
    for(int[] i : g)
        for(int j = 0; j < i[1]; System.out.print(j++ < i[0] ? " " : j == i[1] ? "-\n" : "-"));
}

Accepts input as 2d array of ints. Thanks to masterX244 for pointing out that this is allowed by the rules.


you can shorten the loops if you use the 3rd bulletpoint of the current question version and varargs for the input
masterX244

@masterX244 Thanks, I missed that. Seems to me like cheating to have it pre-parsed, but if cheating is allowed... whatever. I'll update it when I have time.
Nateowami




1

PowerShell 3.0, 4836 Bytes

$args|%{" "*$_[0]+"-"*($_[1]-$_[0])}

Thanks to Mazzy for saving 12 with a better way to pass in the list

Old code and explanation:

&{param($b="")$b|%{" "*$_[0]+"-"*($_[1]-$_[0])}}

Takes arguments as a list of tuples, e.g. (5,20),(5,20),(2,10),(15,19). Had to default $b to a value to take care of the empty string because it somehow entered the foreach block when called with no input.


36 bytes: $args|%{" "*$_[0]+"-"*($_[1]-$_[0])}. Save as get-asciiGantt.ps1. Test script .\get-asciiGantt.ps1 (5,20) (5,20) (2,10) (15,19)
mazzy

1

R, 117 90 75 bytes

function(y)for(i in 1:ncol(y))cat(" "<y[1,i],"-"<diff(y)[i],"
")
"<"=strrep

Try it online!

Giuseppe golfed at least 29 bytes off my original answer!

The idea is straightforward: print as many " " as necessary followed by as many "-" as required. Input is a 2*L matrix with L the number of pairs. The vectorized function diff is used to get the number of "-".


1
@Giuseppe this is what I get for trying to trying to stick to my original matrix idea while using a for loop... ty!
JayCe


@Giuseppe Transposed y to save a few more :)
JayCe

Now 1- indexed would save 4
JayCe

Nice, use < instead of * and you can get this to 81 bytes
Giuseppe

1

VBA (Excel), 99 90 bytes

Using Immediate Window and [A1] as input eg.0-1,2-5

Thanks to @TaylorSott for cutting some bytes.

b=Split([A1]):For x=0To Ubound(b):c=Split(b(x),"-"):?Spc(c(0)-0)String(c(1)-c(0),"-"):Next

1
If you change the input format to being space delimited rather than being comma delimited, you cang chage the first two clauses from a=[A1]:b=Split(a,",") to b=Split([A1]). Also, you can drop the space before the To in the For loop declaration.
Taylor Scott

Thanks and noted! :D
remoel

0

CoffeeScript, 104 82, 65 bytes

List of tasks (ES6): 65 bytes

(a)->a.map (v)->console.log ' '.repeat(v[0])+'-'.repeat v[1]-v[0]

List of tasks (ES5 variant): 82 bytes

(a)->a.map (v)->j=-1;s='';s+=(if j<v[0]then' 'else'-') while++j<v[1];console.log s

Zero or more arguments: 104 bytes

()->[].slice.call(arguments).map((v)->j=-1;s='';s+=(if j<v[0]then' 'else'-')while++j<v[1];console.log s)

Unminified:

() -> [].slice.call(arguments).map( # convert to array-like arguments to array and loop
 (v) ->
  j = -1 # counter
  s = '' # initialize string
  s += (if j < v[0] then ' ' else '-') while ++j < v[1]
  console.log s # print to STDOUT
)

Not sure from where to where is the JavaScript, CoffeeScript and ECMAScript in your answers, but in ECMAScript you can use Array.from(arguments) instead of [].slice.call(arguments).
manatwork

@manatwork As you can see in my answers (both ES5 and ES6, in CoffeeScript) addressing the changed requirement allowing a list of tasks, I don't need to reference arguments any more.
rink.attendant.6

0

PHP, 94 91 bytes

Takes a list of tasks (e.g. [[5,20],[5,20],[2,10],[15,19]]). Thanks @IsmaelMiguel for the reminder of variable function names.

function x($a){$r=str_repeat;foreach($a as$v){echo$r(' ',$v[0]).$r('-',$v[1]-$v[0])."\n";}}

Original attempt: 94 bytes

function x($a){foreach($a as$v){echo str_repeat(' ',$v[0]).str_repeat('-',$v[1]-$v[0])."\n";}}

73 bytes, PHP4: $R=str_repeat;foreach($G as$v)echo$R(' ',$v[0]),$R('-',$v[1]-$v[0]),'\n'; (replace the \n with a real newline). For this to work, you need to send an array on the key $G, over POST/GET/SESSION/COOKIE...
Ismael Miguel

@IsmaelMiguel According to the question, the input needs to come as an argument or from STDIN.
rink.attendant.6

Does GET parameters count? And I think that GETuses STDIN.
Ismael Miguel

0

PHP, 89 characters (function body)

function gantt($x){array_walk($x,function($a){echo str_pad(str_repeat('-',$a[1]-$a[0]),$a[1],' ',0)."\n";});}

I was going to go for reading strings, but as a lot of the entries were taking arrays of integer pairs, I figured I would follow suit for the sake of brevity.

For each tuple $a in array $x I echo a string of dashes repeated $a[1] - $a[0] times, padded up to the larger number $a[1] with spaces. Then the obligatory newline.


You can make your function name just a single letter to save a few bytes. or better yet, if PHP supports anonymous functions, just omit a function name altogether.
Alex A.

1
Oh I see now what you mean by "function body." You have to count the entire function definition in your score, not just the innards.
Alex A.

1
printf() seems shorter than echo+str_pad(): function gantt($x){array_map(function($a){printf("%$a[1]s␊",str_repeat('-',$a[1]-$a[0]));},$x);} (The ␊ in the code is for a literal newline: just wrap your code there.)
manatwork

1
Actually a good old foreach is better: function g($x){foreach($x as$a)printf("%$a[1]s␊",str_repeat('-',$a[1]-$a[0]));} And this is 79 characters including everything.
manatwork

@AlexA. ah, I've seen golfs where people count or discount function headers. I wasn't sure what to go for, hence why I specified what count was what.
JPMC

0

Gema: 47 characters

<D>-\><D><y>=@left{$1;}@repeat{@sub{$2;$1};-}\n

Sample run:

bash-4.3$ gema '<D>-\><D><y>=@left{$1;}@repeat{@sub{$2;$1};-}\n' <<< '0->7,5->6,3->6'
-------
     -
   ---

0

PostgreSQL: 160 characters

create function g(int[])returns text as
$$select string_agg(lpad(repeat('-',$1[x][2]-$1[x][1]),$1[x][2]),chr(10))from generate_subscripts($1,1)x$$
language sql;

Sample run:

manatwork=# create function g(int[])returns text as
manatwork-# $$select string_agg(lpad(repeat('-',$1[x][2]-$1[x][1]),$1[x][2]),chr(10))from generate_subscripts($1,1)x$$
manatwork-# language sql;
CREATE FUNCTION

manatwork=# select g(array[[0,7],[5,6],[3,6]]);
-------
     -
   ---

0

J, 21 bytes

(' -'#~{.,-~/)"1 ::''

ungolfed

(' -' #~ {. , -~/)"1 ::''

This is essentially just J's copy verb #, but its we're copying the space character head of list {. number of times, and the hyphen character "2nd list element minus 1st list element" number of times: -~/. Sadly this forces us to have to specify the rank "1 explictly, and we need to use Adverse :: to handle the empty case.

Try it online!

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