Post by tsh73 on May 26, 2024 13:27:39 GMT
It happened as part of student task.
Given a string, set it inside a matrix,
then do some transforms on this matrix (line swaps etc)
First question is, what size that matrix should be?
Some testing shows it should be near square, around sqr(len(txt$))+1 size.
So yo can do things like this
or that ;)
and of cource
Given a string, set it inside a matrix,
then do some transforms on this matrix (line swaps etc)
First question is, what size that matrix should be?
Some testing shows it should be near square, around sqr(len(txt$))+1 size.
So yo can do things like this
Mine i
s a lo
ng and
a sad
tale!
or that ;)
Just BASI
C is an e
asy and p
owerful p
rogrammin
g languag
e for Win
dows.____
and of cource
SATOR
AREPO
TENET
OPERA
ROTAS
'text to grid
'given a text, get size of minimal rectangular grid it fits
goto [skipTest]
for l = 1 to 100
m = int(sqr(l))
m=m+(m*m<l)
print l, m, m*m,
call findMinRect l, minW, minH
print minW, minH, minW* minH, int((m*m-minW* minH)/(m*m)*100);"%"
next
[skipTest]
print
txt$="Mine is a long and a sad tale!"
print txt$
call findMinRect len(txt$), minW, minH
gosub [printRect]
print
txt$="Just BASIC is an easy and powerful programming language for Windows."
print txt$
call findMinRect len(txt$), minW, minH
gosub [printRect]
end
[printRect]
c=0
for i = 1 to minH
for j = 1 to minW
c=c+1
c$=mid$(txt$,c,1)
if c$="" then c$="_" 'then out of string, should use spaces (but they are invisible)
print c$;
next
print 'new line
next
return
sub findMinRect txtLen,byRef minW, byRef minH
m = int(sqr(txtLen))
m=m+(m*m<txtLen)
minS=1e6
found = 0
for h = 2 to m 'I want it al least 2 lines
for w = 2 to m
s=w*h
if s>=txtLen then found = 1: exit for
next
if found then
if s<minS then minS=s: minW=w: minH=h
end if
next
end sub