-
Notifications
You must be signed in to change notification settings - Fork 0
PrimeFactors
Definition of Kata: An individual training exercise (in Karate or other martial arts).
This short teaching episode will teach the basic concepts of writing useful tests, developing using Test-Driven Development (TDD) and refactoring your code.
Let's go back to school for a moment and consider what a Prime Number is: any natural number greater than 1, that is divisble by itself and 1.
The first few prime numbers are therefore: 2,3,5,7,11,13,17,19,23,29,31,33,37.
If we consider what a Factor of a number that divdes exactly into another number. For example, the factors of 12 are: 1, 2, 3, 4, 6 and 12.
Combining these terms will result in Prime Factors being defined as:
All natural numbers, greater than 1, that are divisble by itself and one, which divide exactly into a given number.
Whilst that's a mouthful, let's review a few examples.
The prime factors of 0 are nothing
.
The prime factors of 2 are: 2
The prime factors of 3 are: 3
The prime factors of 5 are: 5
The prime factors of 6 are: 2, 3
The prime factors of 10 are: 2, 5
The prime factors of 12 are: 2, 2, 3
But why?
Well, we first check if 12 is divisible by 2 (which it is). As such, we know that 2 is a prime factor of 12.
Dividing 12 by 2, leaves us with 6. 6 is sadly not a prime number, so we break it down into its prime factors of 2
and 3
.
The prime factors of 50 are: 2, 5, 5