-
Notifications
You must be signed in to change notification settings - Fork 0
/
output.rb
142 lines (111 loc) · 2.23 KB
/
output.rb
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# START of BASE functions
def input(string = 'Enter string')
puts string
gets.chomp
end
def print(string = '')
puts(string)
end
def init_array(dimensions = [10], default_element = nil)
size = dimensions.first
if dimensions.length > 1
dimensions.shift
Array.new(size, init_array(dimensions, default_element))
else
Array.new(size, default_element)
end
end
def openRead(filename)
File.new(filename, 'r')
end
def openWrite(filename)
File.new(filename, 'w')
end
# END of BASE functionsprint("Hello World")
x=3
name="Bob"
y=String(3*27)
Integer("3")
Float("3.14")
print(x)
print(y)
print(name)
def triple(number)
return number*3
end
y=triple(7)
print(y)
names = init_array([5])
names[0]="Ahmad"
names[1]="Ben"
names[2]="Catherine"
names[3]="Dan"
names[4]="Elijah"
print(names[3])
board = init_array([8,8])
board[0][0]="rook"
entry=input("Please enter your name")
if entry=="Harsh"
print("You selected Harsh") elsif entry=="B"
print("You selected B")
else
print("Unrecognised selection")
end
def greeting(name)
print("anyway, hello "+name)
end
greeting(entry)
someText="Computer Science"
print(someText.length)
print(someText.slice(3,3))
for i in 0..7
print(i)
end
while true
answer=input("What is the answer to life, the universe and everything?")
break if answer=="42"
end
while (x % 10 <= 5)
print(x)
x = x + 1
end
print()
print("Counting from given input to 0")
def countDownFrom(number)
while(number > 0)
print(number)
number = number - 1
end
end
countDownAmount = 20
countDownFrom(countDownAmount)
print()
def xor(a, b)
return ((a && !(b)) || (!(a) && b))
end
print(xor(true, true))
something = input("Enter anything")
case something
when "A"
print("You picked A")
when "42"
print("#Douglas Adams")
else
print("You are a slave to the system")
end
myFile = openRead("sample-read.txt")
x = myFile.gets()
myFile.close()
print("First line below")
print(x)
print()
myFile = openRead("sample-read.txt")
while ! myFile.eof?()
print(myFile.gets())
end
myFile.close()
print()
print()
myFile = openWrite("sample-write.txt")
myFile.puts("THIS IS A SAMPLE TEXT FILE CREATED TO SHOW THE WRITE FUNCTIONALITY")
myFile.close()