Skip to content

Instantly share code, notes, and snippets.

@miklund
Last active May 31, 2022 23:20
Show Gist options
  • Save miklund/93a475a4d874d6d45c2b to your computer and use it in GitHub Desktop.
Save miklund/93a475a4d874d6d45c2b to your computer and use it in GitHub Desktop.
2016-02-03 Beginners guide to Amiga Basic
# Title: Beginners guide to Amiga Basic
# Author: Mikael Lundin
# Link: http://blog.mikaellundin.name/2016/02/03/beginners-guide-to-amiga-basic.html
CLS
DIM w%,h%,a%
LET w%=12
LET h%=4
LET a%=w%*h%
PRINT "With the width "; w%
PRINT " and the height "; h%
PRINT " you have the area "; a%
END
CLS
READ w
SUB Title STATIC
PRINT "*** AMIGA IS NOT DEAD, ONLY TAKING A BREAK ***"
END SUB
SUB Separator(stars) STATIC
PRINT STRING$(stars, "*")
END SUB
Separator(w)
Title
Separator(w)
DATA 46
END
CLS
READ max
DIM SHARED numbers(max)
SUB CreateList(max) STATIC
FOR i=1 TO max
LET numbers(i) = INT(RND * 100)
NEXT i
END SUB
SUB SwapValues(i%, j%) STATIC
LET numbers(i%) = numbers(i%) XOR numbers(j%)
LET numbers(j%) = numbers(i%) XOR numbers(j%)
LET numbers(i%) = numbers(i%) XOR numbers(j%)
END SUB
SUB Sort(max) STATIC
FOR i%=1 TO (max - 1)
FOR j%=i%+1 TO max
IF numbers(i%)>numbers(j%) THEN
CALL SwapValues (i, j)
END IF
NEXT j%
NEXT i%
END SUB
SUB PrintList(max) STATIC
FOR i=1 TO max
PRINT numbers(i)
NEXT i
END SUB
CreateList(max)
Sort(max)
PrintList(max)
DATA 20
END
CLS
DIM r,a
LET r=5
READ pi
LET a=r*r*pi
PRINT USING "With the radius ##.##"; r
PRINT USING "we have the area ##.##"; a
DATA 3.14
END
CLS
READ alphabet
DIM phrase$, result$, encChar$, encKey
PRINT "Enter the encryption key (number)"
INPUT encKey
PRINT "Enter the phrase to encrypt (capital letters)
INPUT phrase$
FOR i = 1 TO LEN(phrase$)
LET encChar$ = CHR$(((ASC(phrase$) + encKey) MOD alphabet) + ASC("A"))
LET result$ = result$ + encChar$
LET phrase$ = RIGHT$(phrase$, LEN(phrase$) - 1)
NEXT i
PRINT "Encrypted prase: " result$
DATA 25
END
CLS
DIM result
PRINT "Calculate the factorial of"
INPUT n
LET result = 1
FOR i = n TO 1 STEP -1
LET result = result * i
NEXT i
PRINT n "! = " result
END
CLS
READ max
DIM fib%(max)
LET fib(1) = 1
LET fib(2) = 2
FOR i=3 TO max
LET fib(i) = fib(i - 2) + fib(i -1)
NEXT i
PRINT "Fibonacci"
FOR i=1 TO max
PRINT fib(i)
NEXT i
DATA 10
END
CLS
READ max%
DIM number%, guess%, guesses%
PRINT "The number is between 1-1000."
LET number% = INT(RND * max%) + 1
LET guess% = 1
LET guesses% = 0
WHILE guess% <> number%
PRINT "Guess the number"
INPUT guess%
IF (guess% > number%) THEN
PRINT "Your guess was too high"
ELSE
PRINT "Your guess was too low"
ENDIF
LET guesses% = guesses% + 1
WEND
PRINT USING "You found the number in ## tries"; guesses%
DATA 1000
END
CLS
PRINT "Hello World!"
END
CLS
DIM stars$
PRINT "Enter the height of the pyramid"
INPUT height
FOR i=1 TO height
LET stars$ = ""
FOR j=1 TO (i + i - 1)
LET stars$ = stars$ + "*"
NEXT j
PRINT SPC(height - i) stars$
NEXT i
END
CLS
PRINT "What is your name?"
INPUT n$
PRINT "What is your shoe size?"
INPUT size
PRINT "Hello "; n$
PRINT "your shoe size is ##.##"; size
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment