Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
MIS21
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Owen Ilagan
MIS21
Commits
61b66fa9
Commit
61b66fa9
authored
Jun 16, 2016
by
Owen Ilagan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New Code
parent
b6398460
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
96 additions
and
1 deletion
+96
-1
manual_sort.rb
manual_sort.rb
+57
-0
other.rb
other.rb
+38
-0
ruby_demo.rb
ruby_demo.rb
+1
-1
No files found.
manual_sort.rb
0 → 100644
View file @
61b66fa9
def
sort_ascending
(
array
)
# Clone the original array
result
=
array
[
0
..-
1
]
# Do Bubble Sorting
index
=
0
result
.
each
do
sub_array
=
result
[
index
+
1
..-
1
]
sub_index
=
0
sub_array
.
each
do
if
sub_array
[
sub_index
]
<
result
[
index
]
temp
=
result
[
index
]
result
[
index
]
=
sub_array
[
sub_index
]
result
[
index
+
1
+
sub_index
]
=
temp
end
sub_index
+=
1
end
index
+=
1
end
return
result
end
def
sort_descending
(
array
)
# Clone the original array
result
=
array
[
0
..-
1
]
# Do Bubble Sorting
index
=
0
result
.
each
do
sub_array
=
result
[
index
+
1
..-
1
]
sub_index
=
0
sub_array
.
each
do
if
sub_array
[
sub_index
]
>
result
[
index
]
temp
=
result
[
index
]
result
[
index
]
=
sub_array
[
sub_index
]
result
[
index
+
1
+
sub_index
]
=
temp
end
sub_index
+=
1
end
index
+=
1
end
return
result
end
my_array
=
[
512
,
128
,
256
,
1024
,
16
,
64
,
32
,
4
]
puts
"Original Array: "
+
my_array
.
join
(
','
)
puts
"Ascending: "
+
sort_ascending
(
my_array
).
join
(
','
)
puts
"Original Array: "
+
my_array
.
join
(
','
)
puts
"Descending: "
+
sort_descending
(
my_array
).
join
(
','
)
other.rb
0 → 100644
View file @
61b66fa9
# Fibonacci Function from
# http://www.dotnetperls.com/fibonacci-ruby
def
fibonacci
(
n
)
a
=
0
b
=
1
# Compute Fibonacci number in the desired position.
n
.
times
do
temp
=
a
a
=
b
# Add up previous two numbers in sequence.
b
=
temp
+
b
end
return
a
end
# Write first 15 Fibonacci numbers in sequence.
15
.
times
do
|
n
|
result
=
fibonacci
(
n
)
puts
result
end
n
=
15
def
get_fibonacci
(
length
)
array
=
[]
# Write first 15 Fibonacci numbers in sequence.
length
.
times
do
|
n
|
result
=
fibonacci
(
n
)
array
.
push
(
result
)
end
return
array
end
puts
'When N='
+
n
.
to_s
+
' Fibonacci is '
+
get_fibonacci
(
n
).
join
(
','
)
ruby_demo.rb
View file @
61b66fa9
...
@@ -18,7 +18,7 @@ def get_reverse(array)
...
@@ -18,7 +18,7 @@ def get_reverse(array)
return
result
return
result
end
end
puts
numbers
puts
'Numbers are: '
+
numbers
.
join
(
','
)
puts
'Numbers are: '
+
numbers
.
join
(
','
)
puts
'Average value is '
+
get_average
(
numbers
).
to_s
puts
'Average value is '
+
get_average
(
numbers
).
to_s
puts
'Reverse is '
+
get_reverse
(
numbers
).
join
(
','
)
puts
'Reverse is '
+
get_reverse
(
numbers
).
join
(
','
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment