diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2020-04-28 11:38:34 +0200 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2020-04-28 11:38:34 +0200 |
commit | 3d9ed1423566757c1364ad6799ebe2b0a770f8cb (patch) | |
tree | 4856d5d3d1959b72cbcbeb10a87428b67a4306a2 | |
parent | dcb6e60f9b1f2ef0e853c64534caea42e20ed87b (diff) | |
download | gcd-3d9ed1423566757c1364ad6799ebe2b0a770f8cb.tar.gz |
Add R
-rwxr-xr-x | gcd.r | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -0,0 +1,28 @@ +#!/usr/bin/env Rscript + +# R - https://www.r-project.org/ +# +# Usage: +# ./gcd.r 11 22 33 121 +# [1] 11 +# +# Or: +# Rscript ./gcd.r 11 22 33 121 +# [1] 11 +# + +gcd <- function (a, b) { + if (b == 0) { + a + } else { + gcd(b, a %% b) + } +} + +gcdn <- function(ns) { + Reduce(gcd, ns) +} + +args <- commandArgs(trailingOnly=TRUE) +ns <- mapply(as.integer, args) +gcdn(ns) |