সিজেম, 94 92 82 বাইট
এটি 92 বাইট সংস্করণ। 82 বাইট সংস্করণ অনুসরণ করা হয়।
l~1$,:L,:)m*{1bL=},\e!\m*{~W<{/(\e_}%}%{::+)-!},{{_,,\f<1fb}%2ew{:&,(},!}={{(2*'_*'[\']}/N}/
এটি প্রতিটি সম্ভাব্য উপায়ে ইটকে পার্টিশন করে এবং কেবলমাত্র যা বৈধ take আপাতত সুন্দর ব্রুট ফোর্স কিন্তু এখনও আমার মেশিনের জাভা ইন্টারপ্রেটারে প্রায় 10 সেকেন্ডের মধ্যে শেষ পরীক্ষার মামলাটি চালায় ।
ব্যাখ্যা :
কোডটি 5 ভাগে বিভক্ত:
1) দৈর্ঘ্যের একটি অ্যারে দেওয়া হয়েছে L
, কীভাবে আমরা সকলে এটি ভাগ করে নিতে পারি H
।
l~1$,:L,:)m*{1bL=},
l~ e# Read the input as string and evaluate it.
`$,:L e# Copy the array and take its length. Store that in L
,:) e# Get an array of 1 to L
m* e# Cartesian power of array 1 to L of size H (height of wall)
{1bL=}, e# Take only those parts whose sum is L
এর পরে, আমাদের ইনপুট অ্যারে এইচ ইটের স্তরগুলিতে বিভক্ত করার সমস্ত সম্ভাব্য উপায় রয়েছে।
2) ইনপুট অ্যারের সমস্ত ক্রমশক্তি পান এবং তারপরে সমস্ত অনুমতিগুলির জন্য সমস্ত পার্টিশন পান
\e!\m*{~W<{/(\e_}%}%
\e! e# Put the input array on top of stack and get all its permutations
\m* e# Put the all possible partition array on top and to cartesian
e# product of the two permutations. At this point, every
e# permutation of the input array is linked up with every
e# permutation of splitting L sized array into H parts
{ }% e# Run each permutation pair through this
~W< e# Unwrap and remove the last part from the partition permutation
{ }% e# For each part of parts permutation array
/ e# Split the input array permutation into size of that part
(\ e# Take out the first part and put the rest of the parts on top
e_ e# Flatten the rest of the parts so that in next loop, they can be
e# split into next part length
এর পরে, আমাদের ইনপুট ইটগুলির সমস্ত সম্ভাব্য বিন্যাস একটি H
স্তর ইটের প্রাচীরের মধ্যে রয়েছে।
3) কেবলমাত্র সেই লেআউটগুলিই ফিল্টার করুন যার ইটের দৈর্ঘ্য সমান
{::+)-!},
{ }, e# Filter all brick layouts on this condition
::+ e# Add up brick sizes in each layer
)-! e# This checks if the array contains all same lengths.
এই ফিল্টারটি শেষ হওয়ার পরে, সমস্ত লেআউটগুলি নিখুঁত আয়তক্ষেত্রগুলি হবে।
4) স্থিতির মানদণ্ডের সাথে মেলে যা প্রথম ইটের লেআউটটি বের করুন
{{_,,\f<1fb}%2ew{:&,(},!}=
{ }= e# Choose the first array element that leaves truthy on stack
{ }% e# For each brick layer
_,, e# Create an array of 0 to layer length - 1
\f< e# Get all sublists starting at 0 and ending at 0
e# through length - 1
1fb e# Get sum of each sub list. This gives us the cumulative
e# length of each brick crack except for the last one
2ew e# Pair up crack lengths for every adjacent layer
{ }, e# Filter layer pairs
:& e# See if any cumulative crack length is same in any two
e# adjacent layers. This means that the layout is unstable
,( e# make sure that length of union'd crack lengths is greater
e# than 1. 1 because 0 will always be there.
! e# If any layer is filtered through this filter,
e# it means that the layer is unstable. Thus negation
এই পদক্ষেপের পরে, আমাদের কেবল বিন্যাসটি মুদ্রণ করতে হবে
5) লেআউট প্রিন্ট করুন
{{(2*'_*'[\']}/N}/
{ }/ e# For each brick layer
{ }/ e# For each brick
(2*'_* e# Get the (brick size - 1) * 2 underscores
'[\'] e# Surround with []
N e# Newline after each layer
এটি এখানে অনলাইনে চেষ্টা করুন
82 বাইট
l~:H;{e_mrH({H-X$,+(mr)/(\e_}%_::+)-X${_,,\f<1fb}%2ew{:&,(},+,}g{{(2*'_*'[\']}/N}/
এটি প্রায় 92 92 বাইট সংস্করণের সাথে সমান, এটির এলোমেলো স্পর্শ ব্যতীত আপনি যদি 92 বাইট সংস্করণটির ব্যাখ্যাটি পড়ে থাকেন তবে 82 বাইট সংস্করণে 3, 4 এবং 5 এর অংশগুলি হুবহু একইরকম হয়, যখন অংশ 1 এবং 2 থেকে সমস্ত ক্রিয়াকলাপগুলি পুনরাবৃত্তি করার পরিবর্তে, এই সংস্করণটি এলোমেলোভাবে একটির উত্পন্ন করে একযোগে ক্রমায়ন, অংশ 3 এবং 4 ব্যবহার করে এটি পরীক্ষা করে এবং তারপরে অংশ 3 এবং 4 এর পরীক্ষা ব্যর্থ হলে প্রক্রিয়াটি পুনরায় আরম্ভ করে।
এটি প্রথম 3 টি পরীক্ষার ক্ষেত্রে ফলাফলগুলি খুব দ্রুত মুদ্রণ করে। উচ্চতা = 5 পরীক্ষার কেসটি এখনও আমার কম্পিউটারে আউটপুট দেয়নি।
পার্থক্য ব্যাখ্যা
l~:H;{e_mrH({H-X$,+(mr)/(\e_}%_::+)-X${_,,\f<1fb}%2ew{:&,(},+,}g
l~:H; e# Eval the input and store the height in H
{ ... }g e# A do-while loop to iterate until a solution is found
e_mr e# Flatten the array and shuffle it.
H({ }% e# This is the random partition generation loop
e# Run the loop height - 1 times to get height parts
H-X$,+( e# While generating a random size of this partition, we
e# have to make sure that the remaining parts get at least
e# 1 brick. Thus, this calculation
mr) e# Get a random size. Make sure its at least 1
/(\e_ e# Similar to 92's part 2. Split, pop, swap and flatten
_::+)- e# 92's part 3. Copy and see if all elements are same
X${_,,\f<1fb}%2ew{:&,(}, e# 92's part 4. Copy and see if layers are stable
+, e# Both part 3 and 4 return empty array if
e# the layout is desirable. join the two arrays and
e# take length. If length is 0, stop the do-while
এই সংস্করণটির জন্য ধারণাটি এলোমেলোভাবে দিয়েছিল (এটি পান?)
এটি অনলাইনে চেষ্টা করে দেখুন