55 lines
1.8 KiB
Text
55 lines
1.8 KiB
Text
Module NonoBlock {
|
|
Form 80,40
|
|
Flush
|
|
Print "Nonoblock"
|
|
Data 5, (2, 1)
|
|
Data 5, (,)
|
|
Data 10, (8,)
|
|
Data 15, (2,3,2,3)
|
|
Data 5, (2,3)
|
|
Def BLen(a$)=(Len(a$)-1)/2
|
|
Function UseLetter(arr) {
|
|
Dim Base 0, Res$(Len(arr))
|
|
Link Res$() to Res()
|
|
Def Ord$(a$)=ChrCode$(Chrcode(a$)+1)
|
|
L$="A"
|
|
i=each(arr)
|
|
While i {
|
|
Res$(i^)=String$("|"+L$, Array(i))+"|"
|
|
L$=Ord$(L$)
|
|
}
|
|
=Res()
|
|
}
|
|
Count=0
|
|
For i=1 to 5
|
|
Read Cells, Blocks
|
|
Blocks=UseLetter(Blocks)
|
|
Print str$(i,"")+".", "Cells=";Cells, "", iF(len(Blocks)=0->("Empty",), Blocks)
|
|
PrintRow( "|", Cells, Blocks, &Count)
|
|
CheckCount()
|
|
Next I
|
|
Sub CheckCount()
|
|
If count=0 Then Print " Impossible"
|
|
count=0
|
|
End Sub
|
|
Sub PrintRow(Lpart$, Cells, Blocks, &Comp)
|
|
If len(Blocks)=0 Then Comp++ :Print Format$("{0::-3} {1}", Comp, lpart$+String$("_|", Cells)): Exit Sub
|
|
If Cells<=0 Then Exit Sub
|
|
Local TotalBlocksLength=0, Sep_Spaces=-1
|
|
Local Block=Each(Blocks), block$
|
|
While Block {
|
|
Block$=Array$(Block)
|
|
TotalBlocksLength+=Blen(Block$)
|
|
Sep_Spaces++
|
|
}
|
|
Local MaxLengthNeed=TotalBlocksLength+Sep_Spaces
|
|
If MaxLengthNeed>Cells Then Exit Sub
|
|
block$=Array$(Car(Blocks))
|
|
local temp=Blen(block$)
|
|
block$=Mid$(Block$, 2)
|
|
If Len(Blocks)>1 Then block$+="_|" :temp++
|
|
PrintRow(Lpart$+block$, Cells-temp, Cdr(Blocks), &Comp)
|
|
PrintRow(lpart$+String$("_|", 1), Cells-1,Blocks, &Comp)
|
|
End Sub
|
|
}
|
|
NonoBlock
|