Write a function that returns the nth fibonacci value

Assignment Help Programming Languages
Reference no: EM131182173

USE RUBY PROGRAMMING LANGUAGE FOR THE SOLUTION

Problem 1

Where a is an array, a.delete(obj) deletes every item from a that is equal to obj:

>> a

=> [1, 2, 1, 3, 1, 4, 2, 5]

>> a.delete(1)

=> 1

>> a

=> [2, 3, 4, 2, 5]

Write the function delete_first(a, obj) that deletes from a only its first item that is equal to obj, if any. The function returns the modified array.

>> a

=> [1, 2, 1, 3, 1, 4, 2, 5]

>> delete_first(a, 1)

=> [2, 1, 3, 1, 4, 2, 5]

>> a

=> [2, 1, 3, 1, 4, 2, 5]

>> delete_first(a, 1)

=> [2, 3, 1, 4, 2, 5]

>> a

=> [2, 3, 1, 4, 2, 5]

>> delete_first(a, 18)

=> [2, 3, 1, 4, 2, 5]

>> a

=> [2, 3, 1, 4, 2, 5]

Problem 2

The Fibonacci sequence fib is defined thus: fib(1) = fib(2) = 1, and fib(n) = fib(n-1)+fib(n-2) for n>2. Write a functionfib_array(n) that returns an array containing the first n values of the Fibonacci sequence. For example:

print fib_array(1)

# [1]

print fib_array(2)

# [1, 1]

print fib_array(10)

# [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]

Problem 3

Write a function fib(n) that returns the n'th Fibonacci value:

print fib(10)

# 55

print fib(100)

# 354224848179261915075

Reference no: EM131182173

Questions Cloud

Describe how you would ensure data security : Describe what type of SQL Server you recommend, your suggestion for installing it, and the minimum system requirements - Describe how you would ensure data security.
Purchased something from them in the last year : An online store contacts 1000 customers from its list of customers who have purchased something from them in the last year. In all, 696 of the 1000 say that they are very satisfied with the store's Web site. The population in this setting is
Analyze extensive research data : Survey professional journals, magazines, books and other texts for topic source validity, Analyze extensive research data and Combine two specialized areas of expertise with a well-rounded understanding of the sociological and cultural implications o..
Eveluate and provide the annual sales revenues and costs : Calculate and provide the annual sales revenues and costs (other than depreciation). Why is it important to include inflation when estimating cash flows?
Write a function that returns the nth fibonacci value : Write the function delete_first(a, obj) that deletes from a only its first item that is equal to obj, if any. The function returns the modified array.
Determine the conditions on the coefficients : Using the rref command on your calculator, determine the conditions on the coefficients in order for there to be a unique solution.
Improve the survey if it were to be repeated : a. Using complete sentences, list three things wrong with the way the survey was conducted. b. Using complete sentences, list three ways that you would improve the survey if it were to be repeated.
Discuss the differences between legitimate and reward : Discuss the differences between legitimate, reward, coercive, and referent power. Give an example of each or the appropriate uses of these expert powers
Markov analysis and forecasting : 1. According to Markov Analysis and Forecasting describe the internal labor market of the company in terms of job stability, promotion paths and rates, transfer paths and rates, demotion paths and rates, and turnover rates?

Reviews

Write a Review

Programming Languages Questions & Answers

  Write the code for the instantiable class bus

Write the code for the instantiable class Bus, which represents a bus that moves passengers around in a simulated city. Bus objects have a ticket price, a maximum capacity of passengers, and a current number of passengers.

  Two-dimensional array to store weekly hours for employees

Assume the weekly hours for all employees are stored in two-dimensional array. Each row records emaployee's seven-day workhours with seven columns.

  Write a function that accepts temperature in degrees

write a function that accepts temperature in degrees fahrenheit degf andcomputes the corresponding value in degrees

  Write the function definition as a recursive search

Write the function definition as a recursive search, assuming an array-based implementation.

  The ideal hpc programming language

Read the article titled, "The Ideal HPC Programming Language" dated 2010. Article Source: Loh, E. (2010, June). The ideal hpc programming language

  Explain reverse, sort and binary search

Because the C# array is an object member of the Array class it also comes with a number of built-in methods such as Reverse, Sort and Binary Search. You can use the Reverse method

  Describe object-oriented databases.

Describe the database planning and development process. What steps are involved, and what tools may be appropriate or helpful?

  Find the position s of a body in linear motion

How many miles will the car go during the period of acceleration from zero to 60 mph? Use the given program to answer this question - Prepare code to declare variables for s0, v0, a, and t, and then write the code to compute s on the basis of these ..

  Explaining class definition of subclass of square

Write down the class definition of subclass of Square called FancySquare which has a method called getDiagonal. The getDiagonal method gets no arguments.

  Write down a program that will randomly generate a number

write a program that will randomly generate a number from 1 to 100. the user will then guess the number via several

  Create logic for program which contains housekeeping

Create logic for program in pseudocode or flowchart which contains housekeeping, detail loop, and end-of-job modules, and which computes service charge and the original check amount customers owe for writing bad check.

  Create class to store the product name

Choose a fruit or vegetable product that you might commonly find at the farmers market (for example, tomatoes, potatoes, lettuce, apples, cantaloupes, etc). Create a class that stores the product name.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd