how to use code to create a Pyramid
Moderator: DosItHelp
Re: how to use code to create a Pyramid
Ach, Of course.
I was trying to think of a way to get rid of the quotes, and failed to see the obvious.
I'm tapped out of ideas for further "improvement"
Dave Benham
I was trying to think of a way to get rid of the quotes, and failed to see the obvious.
I'm tapped out of ideas for further "improvement"
Dave Benham
Re: how to use code to create a Pyramid
I tweaked Aacinis first version; "pyramid.bat":
I also tweaked dbenhams version improved by Aacini (73 Bytes):
penpen
Code: Select all
@cmd /q /e:on /v:on /cset "rows=17"^&set "line=A"^
&(for /l %%a in (2,1,%rows%) do set "line= !line!")^
&for /l %%a in (1,1,%rows%) do echo(!line!^&set "line=!line: A=AAA!"
I also tweaked dbenhams version improved by Aacini (73 Bytes):
Code: Select all
@set s= A
:A
@echo %s%&set s=%s: A=AAA%&goto%s:~0,2%A
:AA
penpen
Re: how to use code to create a Pyramid
penpen wrote:I also tweaked dbenhams version improved by Aacini (73 Bytes):Code: Select all
@set s= A
:A
@echo %s%&set s=%s: A=AAA%&goto%s:~0,2%A
:AA
penpen
I like this code very much!
But you may omit the zero in "goto%s:~0,2%A", so the result may be 1 byte shorter...
Antonio
Re: how to use code to create a Pyramid
I just realized penpen took 3 steps forward, and 2 steps back.
Aacini already pointed out the unnecessary 0.
The old way of manipulating the string with a substring and appending is actually shorter than the find/replace.
Down to 70 bytes
Dave Benham
Aacini already pointed out the unnecessary 0.
The old way of manipulating the string with a substring and appending is actually shorter than the find/replace.
Down to 70 bytes
Code: Select all
@set s= A
:A
@echo %s%&set s=%s:~1%AA&goto%s:~,2%A
:AA
Dave Benham
Re: how to use code to create a Pyramid
Getting so much enjoyment out of this thread.
Re: how to use code to create a Pyramid
I could remove the second label (68 bytes):
penpen
Code: Select all
@set s= A
:A
@ 2>nul echo%s%&&set s=%s:~1%AA&&goto A
penpen
Re: how to use code to create a Pyramid
Animated_Diamond.bat:
Antonio
Code: Select all
@echo off
setlocal EnableDelayedExpansion
set "seed=10"
set "spaces= "
cls
echo/
for /L %%# in () do (
echo/
set /A "i=9-seed, seed=(seed+1)%%10"
for /L %%i in (0,1,9) do (
set /A j=i, i+=1
set "digits="
for /L %%j in (0,1,%%i) do (
set /A "j=(j+1)%%10"
set "digits=!digits! !j!"
)
set "spaces=!spaces:~1!"
echo !spaces!!digits!
)
set /A i+=1
set "spaces=!spaces! "
for /L %%i in (1,1,9) do (
set /A j=i, i+=2
set "digits="
for /L %%j in (%%i,1,9) do (
set /A "j=(j+1)%%10"
set "digits=!digits! !j!"
)
echo !spaces!!digits!
set "spaces=!spaces! "
)
echo/
timeout /T 1 > CON
)
Antonio
Re: how to use code to create a Pyramid
penpen wrote:I could remove the second label (68 bytes):Code: Select all
@set s= A
:A
@ 2>nul echo%s%&&set s=%s:~1%AA&&goto A
penpen
One byte shorter:
Code: Select all
@set s= A
:A
@echo%s% 2>nul&&set s=%s:~1%AA&&goto A
Antonio
Re: how to use code to create a Pyramid
@Aacini: Nice Diamond
I'm unsure if such a "pyramid.bat" (53 byte) is allowed (probably not):
But it were more dynamic than before:
Beside this i am currently out of ideas.
penpen
I'm unsure if such a "pyramid.bat" (53 byte) is allowed (probably not):
Code: Select all
@set s=%~1A
:A
@echo%s% 2>nul&&set s=%s:~1%AA&&goto A
But it were more dynamic than before:
Code: Select all
Z:\>pyramid.bat
Z:\>pyramid.bat " "
A
Z:\>pyramid.bat " "
A
AAA
Z:\>pyramid.bat " "
A
AAA
AAAAA
Z:\>pyramid.bat " "
A
AAA
AAAAA
AAAAAAA
Z:\>pyramid.bat " "
A
AAA
AAAAA
AAAAAAA
AAAAAAAAA
penpen
Re: how to use code to create a Pyramid
For some reason penpen's and Aacini's last two versions give the wrong output on my Win7 machine. If you don't mind a garbage output file (called A of course), this is also 68 bytes:
Code: Select all
@set s= A
:A
@echo %s%&set s=%s:~1%AA&goto%s:~,2%A 2>A
Re: how to use code to create a Pyramid
I have no access to win 7, and winxp output seems to be ok.misol101 wrote:For some reason penpen's and Aacini's last two versions give the wrong output on my Win7 machine.
There is only an additional space at the end (which should be allowed);
if not just use the "2>nul" in front of the echo (adding a byte).
Could you post this output, if it is something different?
penpen
PS: 4 am... gn8 to all.
Re: how to use code to create a Pyramid
penpen: Oops, sorry, my bad, too late at night I guess. I had two versions in the same file, essentially looking like:
which jumps to the wrong :A and produces:
However when I had:
it produced the right output (it's too late for me to think of why)
Anyway, this still goes, and it's down to 62 :
Code: Select all
@set s= A
:A
@ 2>nul echo%s%&&set s=%s:~1%AA&&goto A
@goto :eof
@set s= A
:A
@echo %s%&set s=%s:~1%AA&goto%s:~,2%A 2>A
which jumps to the wrong :A and produces:
Code: Select all
A
AAA
AAAAA
AAAAAAA
AAAAAAAAA
AAAAAAAAAAA
AAAAAAAAAAAAA
AAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
However when I had:
Code: Select all
@set s= A
:A
@echo %s%&set s=%s:~1%AA&goto%s:~,2%A 2>A
@goto :eof
@set s= A
:A
@echo %s%&set s=%s:~1%AA&goto%s:~,2%A 2>A
it produced the right output (it's too late for me to think of why)
Anyway, this still goes, and it's down to 62 :
Code: Select all
@set s= A
:A
@set s=%s:~1%AA&echo%s% 2>A&&goto A
Re: how to use code to create a Pyramid
I like the new one - now we could remove the extra space after the A's in the output (but still 66/64 bytes):
penpen
Code: Select all
@set s= A
:A
@set s=%s:~1%AA&2>nul echo%s%&&goto A
Code: Select all
@set s= A
:A
@set s=%s:~1%AA&2>A echo%s%&&goto A
penpen