diff options
Diffstat (limited to 'challenge-150/robert-dicicco/ruby')
| -rw-r--r-- | challenge-150/robert-dicicco/ruby/ch-1.rb | 32 | ||||
| -rw-r--r-- | challenge-150/robert-dicicco/ruby/ch-2.rb | 47 |
2 files changed, 79 insertions, 0 deletions
diff --git a/challenge-150/robert-dicicco/ruby/ch-1.rb b/challenge-150/robert-dicicco/ruby/ch-1.rb new file mode 100644 index 0000000000..57459d2a14 --- /dev/null +++ b/challenge-150/robert-dicicco/ruby/ch-1.rb @@ -0,0 +1,32 @@ +#!ruby.exe + +# Author: Robert DiCicco +# Date: 31-JAN-2022 +# Challenge 150 Fibonacci Words (Ruby) + +a = '1234' +b = '5678' + +# recursive routine to create fibonacci series, but using strings + +def Fib ( first, second) + val = first + second + puts val + + # if new string length is less than 51, go another round using new combined string + if val.length < 51 then + Fib( second, val) + else + # return the string if length 51 or greater + return val + end + +end + +puts 'Fibonacci Words' +puts a +puts b + +# get the 51st character +char = Fib(a,b)[50].chr +puts "51st digit is " + char diff --git a/challenge-150/robert-dicicco/ruby/ch-2.rb b/challenge-150/robert-dicicco/ruby/ch-2.rb new file mode 100644 index 0000000000..970e737cb0 --- /dev/null +++ b/challenge-150/robert-dicicco/ruby/ch-2.rb @@ -0,0 +1,47 @@ +#!ruby.exe + +# Author: Robert DiCicco +# Date: 31-JAN-2022 +# Challenge 150 Square-Free Integer (Ruby) + +fsums = [] +LIMIT = 500 + +def factors(num) + arr = [] + (1..num).each do |f| + if num % f == 0 + arr.push(f) + end + end + + return arr +end + +def checkFactors(f) + f.each do |p| + next if p == 1 + if IsPerfectSquare(p) == true + return false + else + next + end + end + + return true +end + +def IsPerfectSquare(num) + Integer.sqrt(num) ** 2 == num +end + +(1..LIMIT).each do |num| + facarr = factors(num) + retval = checkFactors(facarr) + + if retval + fsums.push(num) + end +end + +puts "#{fsums}" |
