This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hello Dudes! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts("Enter your name:") | |
name = gets | |
puts("Enter your age:") | |
age = gets | |
puts("Enter your address:") | |
address = gets | |
puts name + age + address |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Interactive ruby ready. | |
> help | |
> 2 + 6 | |
=> 8 | |
Success! | |
> 4 * 10 | |
=> 40 | |
> 5 - 12 | |
=> -7 | |
> 40 / 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Write a program that asks fro a starting year | |
#and ending year and then put all leap years | |
#between them including them if they are leap years | |
puts "Give me the start year" | |
start_year = gets | |
puts "Give me the end year" | |
end_year = gets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_prime_number? number | |
index = 2 | |
tmp = 0 | |
while index <= number | |
if tmp < 1 | |
if (number % index) == 0 | |
tmp += 1 | |
end | |
else | |
return false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def give_greates_common_divisor(x,y) | |
x.to_i.gcd(y.to_i) | |
end | |
puts "Give the first number" | |
x = gets | |
puts "Give the second number" | |
y = gets | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#factorial | |
def factorial(x) | |
if x <= 1 | |
return 1 | |
else | |
x * factorial(x - 1) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_a_palindrome?(str) | |
str.to_s.chomp == str.to_s.chomp.reverse | |
end | |
puts " give me a word" | |
w = gets | |
puts (is_a_palindrome? w) ? "Is a Palindrome": "Is not | |
a Palindrome" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def give_the_longest(array_strings) | |
longest_string = "" | |
array_strings.split(',').each do |x| | |
if x.length > longest_string.length | |
longest_string = x | |
end | |
end | |
longest_string | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
irb(main):001:0> [1,1,1] - [1] | |
=> [] | |
irb(main):002:0> [1,2,3,5].delete(5) | |
=> 5 | |
irb(main):003:0> [1,2,3,5].delete_at(2) | |
=> 3 | |
irb(main):004:0> [1,2,3,5].pop(1) | |
=> [5] | |
irb(main):005:0> [1,2,3,5].pop(8) | |
=> [1, 2, 3, 5] |
OlderNewer