Code Monkey home page Code Monkey logo

ruby_challenges's Introduction

#Ruby Code challenges!!

  1. Fork this repo

  2. Clone it.

  3. Write your code in the quiz.rb file.

  4. Once you think you have it commit, push and send me a pull request

In these puzzles, we are building a function which finds prime numbers! This is a good example of a challenge which may be asked of you at a coding interview. To find prime numbers, we break the problem into two steps:

  • Given a number, find all of its divisors.
  • If a number only has two divisors, it is prime!

##Divisors

###Objective

Given an integer, output an array of its divisors.

Your method is called divisor

###Divisor

A divisor of a number evenly divides it. For example:

3 is a divisor of 6, because 6 % 3 == 0.
10 is a divisor of 100, because 100 % 10 == 0.
4 is a divisor of 4, because 4 % 4 == 0.

2 is not a divisor of 3, because 3 % 2 == 1.

###Input

An integer n, such that 0 < n < Inf.

###Ouput

An array of the divisors of the input integer.

###Examples

Input: 7
Output: [1, 7]

Input: 27
Output: [1, 3, 9, 27]

Input: 30
Output: [1, 2, 3, 5, 6, 10, 15, 30]

##Primes

###Objective

Given an integer, return an array of prime numbers up to that integer. Use the divisor function written in Divisors.

your method is called prime

###Prime Number

A prime number is a number which is divisible by only two numbers -- 1 and itself. The number 1 is divisible by only one number, 1, so it is not prime. The first ten prime numbers are:

2, 3, 5, 7, 11, 13, 17, 19, 23, 29

###Input

A positive integer n, such that 0 < n < Inf

###Output

An array of all prime numbers up to and including the input integer.

###Examples

Input: 7
Output: [2, 3, 5, 7]

Input: 48
Output: [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]

###Fibonacci 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, ...

your mission, if you choose to accept it is to write a method fib that takes an integer and returns an array of the fibonacci sequence up to that number

###Input

A positive integer n, such that 0 < n < Inf

###Output

An array of the fibonacci sequence up to and including the input number ordered from least to greatest.

###Examples

Input: 13  
Output: [1,1,2,3,5,8,13]

Input: 73
Output: [1,1,2,3,5,8,13,21,34,55]

ruby_challenges's People

Contributors

toneloke avatar

Watchers

James Cloos avatar Brian Frager avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.