0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

smallbasicでリカーシブル

Last updated at Posted at 2015-05-12

局所変数が無いので、Stakを利用するようです。

階乗

n = 6
Stack.PushValue("s", n)
Stack.PushValue("s", n) 
fact()
ret = Stack.PopValue("s")
n = Stack.PopValue("s")
TextWindow.WriteLine(n + "! = " + ret)
  
Sub fact
  n = Stack.PopValue("s")
  If (n < 0) Then
    TextWindow.WriteLine("ng")
    Stack.PushValue("s", 0)
  ElseIf (n = 0) Then
    Stack.PushValue("s", 1)
  Else
    Stack.PushValue("s", n)
    Stack.PushValue("s", n - 1)
    fact()
    s = Stack.PopValue("s") * Stack.PopValue("s")
    Stack.PushValue("s", s)
  EndIf
EndSub

コフ曲線

Turtle.Speed = 9
Turtle.X = 100
Turtle.y = 300
Turtle.Show()
Turtle.TurnRight()
Turtle.PenDown()
n = 4
go()
Turtle.Hide()

Sub go  
  If n < 1 Then
    Turtle.Move(5)
  Else
    Stack.PushValue("s", n)  
    n = n - 1
    go()
    Turtle.Turn(-60)
    go()
    Turtle.Turn(120)
    go()
    Turtle.Turn(-60)
    go()
    n = Stack.PopValue("s")
  EndIf
EndSub

ファイル一覧

rootDir = "D:\"
Stack.PushValue("dirs", rootDir)
While (Stack.GetCount("dirs") > 0)
  dirName = Stack.PopValue("dirs")
  files = File.GetFiles(dirName)
  For i = 1 To Array.GetItemCount(files)
    TextWindow.WriteLine(files[i])
  EndFor
  subDir = File.GetDirectories(dirName)
  For i = 1 To Array.GetItemCount(subDir)
    Stack.PushValue("dirs", subDir[i])
  EndFor
EndWhile
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?