Skip to content

mvhs-apcs/methods2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

First Time Computer Setup

Install a package named bundler using the ruby program gem.

    $ gem install bundler

If you get a connection refused error (likely because of the school filter), run this command instead.

    $ gem install bundler --source http://rubygems.org

First Time Project Setup

In your project folder, install the testing packages using bundler.

    $ bundle

Testing Your Code

Run the tests

    $ ruby test.rb

Instructions

Implement the following methods.

Start with the tests, then use them to create your method.

Make a commit after correctly implementing each method.

DO NOT print inside of methods.

  1. elevenish?

    A number is elevenish if it is a multiple of eleven or one greater than a multiple of eleven.

    Parameters

    Name Type Notes
    n int The number to check

    Return

    Type Value
    boolean true when n is elevenish,
    false otherwise.
  2. ice_cream_party

    You are having a party with amounts of ice cream and candy. Return the int outcome of the party encoded as 0=bad, 1=good, or 2=great. A party is good (1) if both ice cream and candy are at least 5. However, if either ice cream or candy is at least double the amount of the other one, the party is great (2). However, in all cases, if either ice cream or candy is less than 5, the party is always bad (0).

    Parameters

    Name Type Notes
    ice_cream int The amount of ice cream at the party
    candy int The amount of candy at the party

    ####Return

    Type Value
    int 0 when the party is bad
    1 when the party is good
    2 when the party is great
  3. successful_squirrel_party?

    When squirrels get together for a party, they like to have nuts. A squirrel party is successful when the number of nuts is between 40 and 60, inclusive. Unless it is the weekend, in which case there is no upper bound on the number of nuts. Return true if the party with the given values is successful, or false otherwise.

    Parameters

    Name Type Notes
    nuts int The amount of nuts at the party
    is_weekend boolean true when it is the weekend,
    false during the week

    Return

    Type Value
    boolean true when the party is successful,
    false when it is not
  4. ticket

    You have a lottery ticket, with ints a, b, and c on it. This makes three pairs, which we'll call ab, bc, and ac. Consider the sum of the numbers in each pair. If any pair sums to exactly 10, the result is 10. Otherwise if the ab sum is exactly 10 more than either bc or ac sums, the result is 5. Otherwise the result is 0.

    Parameters and Return

    Determine the parameters and return type of the method yourself from the problem statement.

  5. ###in_order?

    Given three ints, a b c, return true if b is greater than a, and c is greater than b. However, with the exception that if "bOk" is true, b does not need to be greater than a.

    Parameters

    Name Type Notes
    a int Any integer
    b int Any integer
    c int Any integer
    bOK boolean true when b is okay, false when it is not

    Return

    Type Value
    boolean true when a, b, and c are in ascending order,
    unless b is okay then it can be not greater than a.
    false otherwise
  6. less_by_ten?

    Given three ints, a b c, return true if one of them is 10 or more less than one of the others.

    Parameters and Return

    Determine the parameters and return type of the method yourself from the problem statement.

  7. fizz_string

    Given a string str, if the string starts with "f" return "Fizz". If the string ends with "b" return "Buzz". If both the "f" and "b" conditions are true, return "FizzBuzz". In all other cases, return the string unchanged.

    Parameters and Return

    Determine the parameters and return type of the method yourself from the problem statement.

  8. first_last_six? Given an array of integers, return true if 6 appears as either the first or last element in the array. The array will be length 1 or more.

    Learn about Ruby Arrays and how they can be used.

    Parameters

    Name Type Notes
    list Array An array of integers,
    the length of which is at least 1

    Return

    Type Value
    boolean true when a 6 is the first or last element of the list,
    false otherwise
  9. rotate_left

    Given an array of 3 integers, return an array with the elements "rotated left" so 1, 2, 3 yields 2, 3, 1.

    Parameters

    Name Type Notes
    trio Array An array of 3 integers

    Return

    Type Value
    Array A version of trio with the numbers rotated left one place
  10. double23?

    Given an integer array, return true if the array contains 2 twice, or 3 twice. The array will have 0, 1, or 2 elements.

    Parameters and Return

    Determine the parameters and return type of the method yourself from the problem statement.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages