pwd
present working directory
ls
list current directory contents
ls -la
list current directory contents in long format and show hidden files
man <some unix command>
Bring up the manual pages for a command. Type q
to exit
# Long challenge: Based on the following data, | |
# write code that prints out the customer's total, including estimated | |
# sales tax, based on the shipping address they entered. | |
# Your code should work even if the values of the data change. | |
# Your output should look like this: "Your total with tax is $4455.54." | |
shopping_cart = [ | |
{:name => "iPad 2", :price => 499, :quantity => 2}, |
class Cart | |
def initialize | |
@the_cart = [] | |
end | |
def add(item, quantity) | |
@the_cart << { :item => item, :quantity => quantity } | |
end | |
def total |
# Project Euler Problem 2 | |
# Each new term in the Fibonacci sequence is generated by adding the previous two terms. | |
# By starting with 1 and 2, the first 10 terms will be: | |
# 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... | |
# By considering the terms in the Fibonacci sequence whose values do not exceed four million, | |
# find the sum of the even-valued terms. |
# If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. | |
# Find the sum of all the multiples of 3 or 5 below 1000. | |
sum, i = 0, 0 | |
while i < 1000 | |
sum += i if i % 3 == 0 || i % 5 == 0 | |
i += 1 | |
end | |
puts sum # => 233168 |
# if n is 1, end the method and return empty array | |
# set var factor = first number in range 2..n | |
# that has a remainder of 0 when divided by x | |
# x being the current iteration of 2..n | |
# put factor var into an array and then call the | |
# method we are currently in again passing the | |
# value of n divided by the current value of factor | |
def prime_factors(n) | |
return [] if n == 1 |
def is_prime?(n) | |
((2..(Math.sqrt(n)))).each do |i| | |
return false if n % i == 0 | |
end | |
return true | |
end |
# A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 99. | |
# Find the largest palindrome made from the product of two 3-digit numbers. | |
def looped_palindrome(num1,num2=num1) | |
product = 0 | |
while num1 > 900 | |
product = num1 * num2 | |
return product if product.to_s == product.to_s.reverse | |
if num2 > 900 | |
num2 -= 1 |
class Prescription | |
# setter for rx_name | |
def rx_name=(value) | |
@rx_name = value | |
end | |
# setter for patient name | |
def patient_name=(value) | |
@patient_name = value | |
end |