Skip to content

Instantly share code, notes, and snippets.

View NYiPhoneDeveloper's full-sized avatar

Nat Aguilar NYiPhoneDeveloper

View GitHub Profile
# My first program!
# A factorial program for value i! (integer)!
# example factorial: 6! = 6 * 5 * 4 * 3 * 2 * 1 = 720
factorial = gets()
factorial = factorial.chomp.to_i
number = 0
multiplication = 1
# Another program that I worked on for a few days.
# I'm still a newbie - but I'm practicing my butt off!
class Calculator
print "put first value here: \n"
val_1 = gets()
val_1 = val_1.chomp.to_i
print "Put second value here: \n"
val_2 = gets()
# This is a simple program which gives the |x| absolute value of the integer |x|
# I'm working on an algorithm to get all numbers, floats, bignums, etc.
class Absolute_Value
print "Put an integer please: \n"
int = gets()
int = int.chomp.to_i
if (int < 0)
puts -int
else
puts int
# A basic square program - will develop "inches", "ft", "yards" and add more features later!
class Square
# The math is meant for a square only!!
puts "put the side of the square: "
length = gets()
length = length.chomp.to_f
puts "Would you like: \
\np = perimeter \
\nh = hypotenuse \na = area"
class Electricity
# for this program - we assume all voltage is 120 volts
# This is a program that calculates the watts, resistance, amps
# of something as simple as a lightbulb.
Voltage = 120
puts "Only put one value as an integer: \n\n"
variables = []
variables << Voltage
# Converts temperatures
class Temperature
puts "Put the temperature: \n\
If Fahrenheit, put '75 F' if Celsius, put '75 C' "
# This makes temp into: [number, string_(argument)]
value = gets()
value = value.chomp!.split
# This is where I will give the two elments name-value
temp = value[0].to_f
# What % is x out of y?
class Percent
def initialize(value_x, value_y)
@value_x = value_x
@value_y = value_y
end
def percent
per = @value_x * 100/@value_y
# What % is x out of y
puts "#{@value_x} out of #{@value_y} is #{per}%"
# Thanks for the inspiration Pat :)
class Convert
PI = 3.1415
Rad_to_Deg = 180.0/PI
Deg_to_Rad = PI/180.0
def initialize(number)
@number = number
end
# Converts radians to degrees
class Einstein
# This shows the idea of time dilation. - I.E. Time slows down as you travel closer to the speed of light
def initialize(percent)
@percent = percent
end
def percent_output
Math.sqrt(1-((@percent/100)**2))
end
def percent
percent_output = Math.sqrt(1-((@percent/100)**2))
# Tests for even, or off numbers.
class Testing_Numbers
def initialize(number)
@number = number
end
def method_1
result = (@number % 2) # Trying new things here.
if result == 0
puts "Number is even"