Beginner Algorithms in Ruby: Sum of Multiples of 3 and 5

/* given a limit, collect all the multiples of 3 or 5 up to 1 less than the limit, and return the sum of those multiples*/create a function to collect the multiples that takes a limit as an argument
define data-type/structure for the storing
create a loop for each non-zero number to 1 less than limit
test each one of those numbers against some mathematical evaluation, and if either comes back true, shovel that number into my defined data structure
return that data
end
create a function that uses the other function to return a sum, that also takes in the limit as an argument
define our sum and set a base, in this case 0
call our first function, and use its return to do some math
return that math
end
$ruby <file name>.rb
class name class attributes - need to read, not write   create objects asap when given a limit
upon creation, make the limit variable accessible
make our multiples immediately available too by calling a function that will return a data-type that is a collection of our multiples
end
function to return collection of multiple
make use of our limit, but make sure to go 1 less
do some math, evaluate, what returns true goes into our collection
return that collection
end
function to add up those multiples
do math and return the sum
end
end

--

--

--

web developer making apps for people with appetite

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

100 Days of VR: Day 18 Creating Weapon Ammo in Unity

Lambda Labs — Development Journal — Labs 09 — Week 01

Dijkstra and Floyd Warshall Floyd War

Release Notes: Eclipse Che 5.2

Work with JSON files with Azure SQL

Building Workflows with Jenkins

Django Tutorial #6: Home Page

Laravel Advance | Laravel 7/8 Notification Tutorial | Create Notification with Laravel 7/8

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
aaron feingold

aaron feingold

web developer making apps for people with appetite

More from Medium

“To understand recursion, one must first understand recursion.”

Recursion

Natural Languages and Programming Languages

RegEx & Love Letters?!