ঘূর্ণায়মান সর্পিল


12

অক্ষরের একটি সর্পিলকে উপস্থাপন করে এমন একটি বর্গক্ষেত্র দেওয়া হয়েছে, এটি ঘোরান!

সর্পিলটি কেন্দ্র থেকে শুরু হয় এবং ঘড়ির কাঁটার বিপরীতে বাইরের প্রান্তে চলে যায়, কেন্দ্রের বাম দিকে শুরু করে:

987
216
345

এটি স্ট্রিংয়ে অনুবাদ করে 123456789। ঘূর্ণন সম্পন্ন করা হয় বাম , তাই আপনি যদি ঘোরাতে এটা এক অবস্থান, এটা হবে 234567891। এটি প্রতিনিধিত্ব করে:

198
327
456

ইনপুট

ইনপুটটিতে সর্পিল এবং এটিকে ঘোরানোর দূরত্ব নিয়ে গঠিত।

দূরত্ব সর্বদা একটি ধনাত্মক পূর্ণসংখ্যা বা শূন্য হতে পারে এবং আপনার ভাষার ডেটা টাইপ সীমাতে ক্যাপ করা যায়।

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

ধরে নিন যে সমস্ত অক্ষর বর্ণানুক্রমিক [A-Za-z0-9]।

আউটপুট

আউটপুট হল ঘোরানো সর্পিল। এটি একাধিক লাইনে স্কোয়ার হওয়া উচিত (মুদ্রিত হোক বা ফিরে হোক)।

উদাহরণ

ইনপুট

3
tne
atd
bin

আউটপুট

bat
nit
den

ইনপুট

18
efilr
naepo
umshf
tootr
butte

আউটপুট

rettu
omseb
oofft
trliu
hpean

এটি কোড গল্ফ, যথারীতি স্কোর বাইটে গণনা করা হয়।

উত্তর:


6

সিজেম, 45 44 বাইট

]]l~LqN/{(W%@+\zW%}h;m<{1$,/(W%a@W%z+\s}h;N*

এটি এখানে পরীক্ষা করুন।

ব্যাখ্যা

অলস সমাধান: সর্পিলটি মোড়ক করুন, সিজেমের অন্তর্নির্মিত অ্যারে রোটেশনটি ব্যবহার করুন, সর্পিলটি আবার রোল করুন।

]]       e# Push [""]. We'll later use this to roll up the spiral.
l~       e# Read the integer and evaluate it.
L        e# Push an empty string: we'll unroll the input into this.
qN/      e# Read the spiral and split it into lines.
{        e# While the top of the stack is truthy...
  (W%    e#   Pull the first line off the spiral and reverse it.
  @+     e#   Pull up the string we've built so far and prepend the reversed line.
  \zW%   e#   Swap with the remaining spiral, and rotate the spiral.
}h       e# This terminates when the centre character has been added to the string and
         e# the spiral becomes an empty array.
;        e# Discard the empty array.
         e# Note that we've unrolled the spiral from outside in, but we've also built up
         e# the string in reverse, which gives us the string from inside out.
m<       e# Rotate to the left by the given number of characters.
{        e# While the top of the stack is truthy...
  1$,    e#   Copy the spiral so far and get the number of lines.
  /      e#   Split the string into chunks of that size.
  (W%a   e#   Pull off the first chunk, reverse it and wrap it in an array.
  @zW%   e#   Pull up the spiral so far, rotate it.
  +      e#   Prepend the chunk to the spiral as a line.
  \s     e#   Swap with the other chunks and flatten them into a string again.
}h       e# This terminates when the string has been used up completely.
;        e# Discard the empty string.
N*       e# Join the lines with linefeed characters.
আমাদের সাইট ব্যবহার করে, আপনি স্বীকার করেছেন যে আপনি আমাদের কুকি নীতি এবং গোপনীয়তা নীতিটি পড়েছেন এবং বুঝতে পেরেছেন ।
Licensed under cc by-sa 3.0 with attribution required.