Skip to content

Instantly share code, notes, and snippets.

@kunst1080 kunst1080/FizzBuzz2.bat
Last active Dec 14, 2015

Embed
What would you like to do?
余剰計算なしのFizzBuzz ( ref: http://kunst1080.hatenablog.com/entry/2013/02/26/224615 )
@echo off
REM dels
del Seq.txt Fizz.txt Buzz.txt FizzBuzz.txt
del merge.txt merge.pass.txt merge.pass.sort.txt
del out.txt
REM sequences
for /L %%i in (1,1,100) do @echo %%i 4 %%i>>Seq.txt
for /L %%i in (3,3,100) do @echo %%i 3 Fizz>>Fizz.txt
for /L %%i in (5,5,100) do @echo %%i 2 Buzz>>Buzz.txt
for /L %%i in (15,15,100) do @echo %%i 1 FizzBuzz>>FizzBuzz.txt
REM merge
copy Seq.txt+Fizz.txt+Buzz.txt+FizzBuzz.txt merge.txt /B
for /f "usebackq tokens=1,2,3" %%a in ("merge.txt") do @(
if %%a lss 10 (echo 00%%a %%b %%c) else if %%a lss 100 (echo 0%%a %%b %%c) else echo %%a %%b %%c) >>merge.pass.txt
sort merge.pass.txt /O merge.pass.sort.txt
REM uniq
for /f "usebackq tokens=1,2,3" %%a in ("merge.pass.sort.txt") do @(
call :uniq %%a %%c) >>out.txt
exit/b
REM subroutine
:uniq
rem %1 … key
rem %2 … data
if not "%PREV%"=="%1" (
set PREV=%1
echo %2
)
exit /b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.