Please answer these questions for me:
Q1: Write a method, pow, that takes two (non-negative, integer) numbers, base and exponent and returns base raised to the exponent power. (No fair using Ruby's base ** exponent notation!).
Q2: Write a method, sum which takes an array of numbers and returns the sum of the numbers.
Q3: Write a method, is_prime?, that takes a number num and returns true if it is prime and false otherwise.
You may wish to use the modulo operation: 5 % 2 returns the remainder when dividing 5 by 2: 1. If num is divisible by i, then num % i == 0. (You would not be expected to already know about modulo for the challenge)
Q4: Using your is_prime? method, write a new method, primes that takes a (non-negative, integer) number max and returns an array of all prime numbers less than max.
I am interested in the simplest solutions. If you could include step by step explanations that would be great.
Herve_1
0
Newbie Poster
Recommended Answers
Jump to PostHi,
There is no simplest form of a solution to a problem, without going into the basics.
I never crossed past the PHP forum, but I just did this time. It is not that I am not capable of writing codes in Ruby, but it is because I am so …
All 4 Replies
LastMitch
veedeoo
474
Junior Poster
Featured Poster
veedeoo
474
Junior Poster
Featured Poster
Herve_1
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.