Last active
March 17, 2018 00:33
-
-
Save mrwm/98683cb98d53617c3b623bf6d489c665 to your computer and use it in GitHub Desktop.
extra credit for math 42 @sjsu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ECHO OFF | |
echo This script is only accurate up to 45. | |
echo Anything larger will be an overflow. | |
:vars | |
set /p stop="Enter end number: " | |
set num1=0 | |
set num2=0 | |
set c=0 | |
echo 0: 0 | |
set /a "c+=1" | |
if %stop% LSS 0 ( | |
echo Bad ARG | |
pause | |
exit | |
) | |
:loop | |
set /a "stop=%stop%-1" | |
if %num1% EQU 0 ( | |
set /a "num2+=1" | |
) | |
set /a out="%num1% + %num2%" | |
set num1=%num2% | |
set num2=%out% | |
if %c% LSS 10 ( | |
echo %c%: %out% | |
) | |
if %c% GEQ 10 ( | |
echo %c%: %out% | |
) | |
set /a "c=%c%+1" | |
if %stop% GEQ 0 ( | |
goto loop | |
) | |
echo end | |
pause | |
exit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# A simple script that calculates the nth number | |
# Usage: math.sh $n | |
# where $n is the number you want to stop at | |
num1=0 | |
num2=0 | |
c=0 | |
echo " 0: 0 " | |
let c+=1 | |
until [ $[ $c + 1 ] -gt $1 ]; do | |
let c+=1 | |
if [ $num1 -eq 0 ]; then | |
let num2+=1 | |
fi | |
out=$[ $num1 + num2 ] | |
num1=$num2 | |
num2=$out | |
if [ $c -lt 10 ]; then | |
echo " $c: $out " | |
else | |
echo " $c: $out " | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment