From 3d9ed1423566757c1364ad6799ebe2b0a770f8cb Mon Sep 17 00:00:00 2001 From: Igor Pashev Date: Tue, 28 Apr 2020 11:38:34 +0200 Subject: Add R --- gcd.r | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 gcd.r diff --git a/gcd.r b/gcd.r new file mode 100755 index 0000000..d4e11f9 --- /dev/null +++ b/gcd.r @@ -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) -- cgit v1.2.3