Code Monkey home page Code Monkey logo

prime-ruby's Introduction

Implementing Prime

Objectives

  1. Practice iteration and looping.
  2. Practice defining methods and controlling return values.

Instructions

Fork and clone this repository. Run the test suite to learn what is required of you.

You'll be defining a method, prime?(), that takes in an integer argument and returns a boolean of whether or not that integer is a prime number.

A few things to think about:

  • What defines an integer as a prime number? Research algorithms for how to determine if a number is prime.
  • How do you create a range of numbers? How do you turn a range into an array so that it can be iterated over?

Requirements:

  • Do not use any other Ruby library. You must build a method that can verify whether a number is prime. Don't require 'math' and just piggyback off their implementation of prime number.

Advanced

Think about the efficiency of your algorithm. How many iterations does it do? Look into Benchmarking in Ruby and profile a few different approaches to implementing prime?().

Resources

prime-ruby's People

Contributors

ahimmelstoss avatar annjohn avatar arelenglish avatar aviflombaum avatar bhollan avatar curiositypaths avatar deniznida avatar fislabstest avatar fs-lms-test-bot avatar ihollander avatar jonbf avatar kthffmn avatar markedwardmurray avatar maxwellbenton avatar mendelb avatar peterbell avatar sarogers avatar sgharms avatar shmuwol avatar sophiedebenedetto avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

prime-ruby's Issues

will not fork lab with open button

just hit open to start lab and learn ide popped up but does not show that lab has been forked and when I submitted lab via learn submit it is not showing that it has been pushed and lab completed.

readme clean up

remove front matter, add objectives, clarify instructions

Suggest a simpler solution

Suggest having a solution that's more aligned with what Learners should know at this point in the curriculum. Something like this:

def prime?(n)
  n == 0 || n == 1 ? false : (2..n-1).to_a.all?{|d| n % d != 0}
end

Testing Issue(negative integer)

I may be missing something, but it appears prime_spec.rb from the Implementing Prime lab only checks for false returns for 0,1,4,40, and 101013. No negative integers are being tested!

I only came to this conclusion after helping someone else with the lab and noticing they took that specific situation into account. My original code didn't take negatives into account but still passed all tests(It was an easy fix, and I submitted an update).

Others may also have code that passed rspec tests but doesn't truly check for prime numbers!

Figured it might be worth looking at.

Thanks,

-Colby

Enumerators - Order in Curriculum

This might sound like a strange complaint, but it seems like this "Introduction to Enumerators" chapter would have been incredibly useful far earlier in the curriculum, perhaps during the Arrays section. We've been using '.each' fairly extensively already, and to have this incredibly useful definition of what '.each' and '.collect' do right after, say, the "badges" lab seems to be putting the cart before the horse.

`2` needs to be checked.

2 is the only even prime and is sometimes overlooked. Certain implementations will also start with a base divisor of 3 in order to increment by 2 and skip over even numbers; some students seem to be forgetting about two as a prime.

I also agree with the other open issue; the solution is not only quite confusing, but a somewhat odd and extremely slow implementation of the sieve of eratosthenes that actually ends up being slower than n/2 due to the overhead before it actually calculates. (This could be ameliorated with memoization, or a different implementation, or both.)

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.