7 kyu

Square and Cubic Factors

Description:

Task:

Your job here is to implement a function factors, which takes a number n, and outputs an array of arrays comprised of two parts, sq and cb. The part sq will contain all the numbers that, when squared, yield a number which is a factor of n, while the cb part will contain all the numbers that, when cubed, yield a number which is a factor of n. Discard all 1s from both arrays.

Both sq and cb should be sorted in ascending order.

What it looks like:

factors(Integer) #=> [
  sq (all the numbers that can be squared to give a factor of n) : Array,
  cb (all the numbers that can be cubed   to give a factor of n) : Array
]
factors(Int32) #=> [
  sq (all the numbers that can be squared to give a factor of n) : Array(Int32),
  cb (all the numbers that can be cubed   to give a factor of n) : Array(Int32)
]
factors(int) #=> [
  sq (all the numbers that can be squared to give a factor of n) : list,
  cb (all the numbers that can be cubed   to give a factor of n) : list
]
factors(Number) #=> [
  sq (all the numbers that can be squared to give a factor of n) : Array,
  cb (all the numbers that can be cubed   to give a factor of n) : Array
]
factors(Number) #=> [
  sq (all the numbers that can be squared to give a factor of n) : Array,
  cb (all the numbers that can be cubed   to give a factor of n) : Array
]

Some examples:

factors(1) #=> [[], []]
  # ones are discarded from outputs

factors(4) #=> [[2], []]
  # 2 squared is 4;   4 is a factor of 4

factors(16) #=> [[2, 4], [2]]
  # 2 squared is  4;  4 is a factor of 16
  # 4 squared is 16; 16 is a factor of 16
  # 2 cubed is    8;  8 is a factor of 16

factors(81) #=> [[3, 9], [3]]
  # 3 squared is  9;  9 is a factor of 81
  # 9 squared is 81; 81 is a factor of 81
  # 3 cubed is   27; 27 is a factor of 81

Also check out my other creations — Keep the Order, Naming Files, Elections: Weighted Average, Identify Case, Split Without Loss, Adding Fractions, Random Integers, Implement String#transpose, Implement Array#transpose!, Arrays and Procs #1, and Arrays and Procs #2.

If you notice any issues or have any suggestions/comments whatsoever, please don't hesitate to mark an issue or just comment. Thanks!

Fundamentals

Stats:

CreatedNov 15, 2016
PublishedNov 15, 2016
Warriors Trained821
Total Skips14
Total Code Submissions1077
Total Times Completed446
Ruby Completions59
Crystal Completions10
Python Completions255
JavaScript Completions163
CoffeeScript Completions13
Total Stars9
% of votes with a positive feedback rating91% of 128
Total "Very Satisfied" Votes108
Total "Somewhat Satisfied" Votes18
Total "Not Satisfied" Votes2
Total Rank Assessments8
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • narayanswa30663 Avatar
  • raulbc777 Avatar
  • JohanWiltink Avatar
  • FArekkusu Avatar
  • saudiGuy Avatar
Ad