<?php
function buildLevel
(array $words, $level) { // с первым уровнем все просто
if ($level === 1) return [implode(' ', $words)]; if ($level === 2) {
// со вторым чуть по сложнее...
$result = [];
$chunk = [];
while(count($words) >= $level) { // отделяем первое слово из "строки" и зановим его к первому "слагаемому"
}
return $result;
}
throw new \Exception
(sprintf('Not implemented for level %d for now', $level)); }
PD9waHAKZnVuY3Rpb24gYnVpbGRMZXZlbChhcnJheSAkd29yZHMsICRsZXZlbCkgewogICAgLy8g0YEg0L/QtdGA0LLRi9C8INGD0YDQvtCy0L3QtdC8INCy0YHQtSDQv9GA0L7RgdGC0L4KICAgIGlmICgkbGV2ZWwgPT09IDEpIHJldHVybiBbaW1wbG9kZSgnICcsICR3b3JkcyldOwogICAgaWYgKCRsZXZlbCA9PT0gMikgewogICAgICAgIC8vINGB0L4g0LLRgtC+0YDRi9C8INGH0YPRgtGMINC/0L4g0YHQu9C+0LbQvdC10LUuLi4KICAgICAgICAkcmVzdWx0ID0gW107CiAgICAgICAgJGNodW5rID0gW107CiAgICAgICAgd2hpbGUoY291bnQoJHdvcmRzKSA+PSAkbGV2ZWwpIHsKICAgICAgICAJLy8g0L7RgtC00LXQu9GP0LXQvCDQv9C10YDQstC+0LUg0YHQu9C+0LLQviDQuNC3ICLRgdGC0YDQvtC60LgiINC4INC30LDQvdC+0LLQuNC8INC10LPQviDQuiDQv9C10YDQstC+0LzRgyAi0YHQu9Cw0LPQsNC10LzQvtC80YMiCiAgICAgICAgICAgIGFycmF5X3B1c2goJGNodW5rLCBhcnJheV9zaGlmdCgkd29yZHMpKTsgCiAgICAgICAgICAgICRyZXN1bHRbXSA9IGFycmF5X21lcmdlKFtpbXBsb2RlKCcgJywgJGNodW5rKV0sIFtpbXBsb2RlKCcgJywgJHdvcmRzKV0pOwogICAgICAgIH0KCiAgICAgICAgcmV0dXJuICRyZXN1bHQ7CiAgICB9CgogICAgdGhyb3cgbmV3IFxFeGNlcHRpb24oc3ByaW50ZignTm90IGltcGxlbWVudGVkIGZvciBsZXZlbCAlZCBmb3Igbm93JywgJGxldmVsKSk7Cn0KCiR3b3JkcyA9IGV4cGxvZGUoJyAnLCAnYSBiIGMgZCcpOwp2YXJfZHVtcChidWlsZExldmVsKCR3b3JkcywgMSkpOwp2YXJfZHVtcChidWlsZExldmVsKCR3b3JkcywgMikpOw==