Marbelous, 203 байта
}0}0@1
>>^0&1
--=0@1FF
??&0}0&0
&1
qqqqqq\\\\
//\\pppppp
:p
0000
?K\\?4..}2
<G++<4+5=0\/}0
<B++<3+5?111>1!!
<6++<2+3Mult-2
<3++<1+3+7}2{<
++//mm//mm--
mm..{1..{2{>
{0
:q
}2{2}0
pppppp{0{1
-W
:m
}061
{0{0
Проверьте это здесь (онлайн переводчик).Ввод через аргументы. Библиотеки и цилиндрические доски должны быть включены.
Комментируемая / читаемая версия:
}0 }0 @1 .. .. # 1st column: generate a number from 0 to length/2-1, wait on &1
>> ^0 &1 .. .. # 2nd column: check bottom bit; if zero activate &1, otherwise &0
-- =0 @1 FF .. # FF (wait on &0): if no h/y, set counter to 255 (0xFF)
?? &0 }0 &0 .. # Send copy of full length to :q
&1 .. .. .. ..
qq qq qq \\ \\ # Call :q with counter and length
// \\ pp pp pp # Output of :q falls into :p, which is called repeatedly until done
:p # prints a consonant/vowel pair, and h/y if needed
00 00 .. .. .. .. .. .. # two zeros, to be passed into ?K and ?4
?K \\ ?4 .. }2 .. .. .. # pass through ?K (0-20 = consonants) and ?4 (0-4 = vowels)
<G ++ <4 +5 =0 \/ }0 .. # 1st/2nd column: add 1-4 to skip vowels
<B ++ <3 +5 ?1 11 >1 !! # 3rd/4th column: add 3/6/11/16 to create nth vowel
<6 ++ <2 +3 Mu lt -2 .. # 5th/6th column: if counter is 0, generate either h or y
<3 ++ <1 +3 +7 }2 {< .. # 7th/8th column: if length left to print is 0-1, terminate
++ // mm // mm -- .. .. # mm: add 'a'. 1st/2nd start at 'b' (++)
# 5th/6th start at 'h' (+7)
mm .. {1 .. {2 {> .. .. # output consonant, vowel, h/y to {0, {1, {2
{0 .. .. .. .. .. .. .. # left input (length left): -2 + output to left
# right input (counter until print h/y): -1 + output to right
:q # calls :p, but with the first letter capitalized
}2 {2 }0 .. .. # {2 is an unused output which prevents exit when all outputs are filled
pp pp pp {0 {1 # call :p, and forward return outputs to MB to start loop
-W .. .. .. .. # subtract W (0x20) from the first letter = capitalize it
:m # add 0x61 ('a')
}0 61
{0 {0 # input + 0x61 is returned
Это примерно эквивалентно следующему псевдокоду ( random(a,b)
генерирует числа между a
и b
включительно):
main(length)
if length & 0x01 == 0 then
counter, length_left = q(0xFF, , length)
else
counter, length_left = q(random(0, (length >> 1) - 1), , length)
end
while true do
length_left, counter, consonant, vowel, hy = p(length_left, , counter)
print consonant, vowel, hy
end
p(length_left, , counter)
if length_left <= 1 then terminate_program end
consonant = random(0, 20)
switch consonant
case >16: ++consonant
case >11: ++consonant
case >6: ++consonant
case >3: ++consonant
++consonant
consonant = m(consonant)
vowel = random(0, 4)
switch vowel
case >4: vowel += 5
case >3: vowel += 5
case >2: vowel += 3
case >1: vowel += 3
vowel = m(vowel)
if counter == 0 then
hy = random(0, 1) * 0x11
hy += 7
hy = m(hy)
return length_left - 2, counter - 1, consonant, vowel, hy
q(counter, , length_left)
length_left, counter, consonant, vowel, hy = p(length_left, , counter)
print consonant - 0x20, vowel, hy
return counter, length_left
m(number)
return number + 'a'