-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathexampleScript.ns
84 lines (67 loc) · 1.98 KB
/
exampleScript.ns
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
recipe isNumber(noodle string)
frozen noodle stringSize = len(string)
frozen noodle numberChrs = ["0" "1" "2" "3" "4" "5" "6" "7" "8" "9"]
noodle chrFound = false
noodle chrIndex = 0
noodle currentChr
noodle numberChrIndex
noodle foundNumberChr
while chrIndex < stringSize && !chrFound
currentChr = at(string chrIndex)
numberChrIndex = 0
foundNumberChr = false
while numberChrIndex < 10 && !foundNumberChr
if currentChr == at(numberChrs numberChrIndex)
foundNumberChr = true
eat
numberChrIndex++
eat
if !foundNumberChr
chrFound = true
eat
chrIndex++
eat
!chrFound
eat
recipe sort(noodle array)
frozen noodle arraySize = len(array)
noodle arrayIndex = 0
noodle currentElem
noodle nextElem
noodle sorted = false
while !sorted
arrayIndex = 0
sorted = true
while arrayIndex < arraySize - 1
currentElem = at(array arrayIndex)
nextElem = at(array arrayIndex+1)
if currentElem > nextElem
set(array arrayIndex nextElem)
set(array arrayIndex+1 currentElem)
sorted = false
else
arrayIndex++
eat
eat
eat
array
eat
recipe main()
noodle input = ""
noodle numbers = []
serve("Welecome to the number sorter! Type `sort` to sort numbers.\n\n")
while input != "sort"
serve("Type a number to add to the list: ")
input = receive()
if isNumber(input)
append(numbers num(input))
else
if input != "sort"
serve(" " input " is not a valid number\n")
eat
eat
eat
serve("\n Original number list: " numbers "\n")
serve(" Sorted number list: " sort(numbers) "\n\n")
eat
main()