203 Squarefree Binomial Coefficients.sf 401 B

123456789101112131415161718192021
  1. #!/usr/bin/ruby
  2. # Author: Daniel "Trizen" Șuteu
  3. # Date: 22 September 2016
  4. # License: GPLv3
  5. # Website: https://github.com/trizen
  6. # https://projecteuler.net/problem=203
  7. # Runtime: 0.142s
  8. func pascal(rows) {
  9. var table = Hash()
  10. for n in (^rows) {
  11. table{(0..n -> map {|k| binomial(n, k) })...} = ()
  12. }
  13. table.keys.map {|n| Num(n) }.grep { .is_square_free }.sum
  14. }
  15. say pascal(51)