diff options
| author | Abigail <abigail@abigail.be> | 2021-07-19 15:48:02 +0200 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-07-19 16:17:26 +0200 |
| commit | 1340f41d195abe258ff1664bf0e7b4e5f1dd8990 (patch) | |
| tree | 7fc1345c2fb755ba71103da366fd16301859dfa0 | |
| parent | 4ded51d7ecb942711df0c3dc0c9fca2f3ea1186a (diff) | |
| download | perlweeklychallenge-club-1340f41d195abe258ff1664bf0e7b4e5f1dd8990.tar.gz perlweeklychallenge-club-1340f41d195abe258ff1664bf0e7b4e5f1dd8990.tar.bz2 perlweeklychallenge-club-1340f41d195abe258ff1664bf0e7b4e5f1dd8990.zip | |
Solutions in 17 languages for week 122, part 1.
| -rw-r--r-- | challenge-122/abigail/README.md | 1 | ||||
| -rw-r--r-- | challenge-122/abigail/awk/ch-1.awk | 11 | ||||
| -rw-r--r-- | challenge-122/abigail/bash/ch-1.sh | 11 | ||||
| -rw-r--r-- | challenge-122/abigail/basic/ch-1.bas | 15 | ||||
| -rw-r--r-- | challenge-122/abigail/bc/ch-1.bc | 15 | ||||
| -rw-r--r-- | challenge-122/abigail/befunge-93/ch-1.bf93 | 2 | ||||
| -rw-r--r-- | challenge-122/abigail/c/ch-1.c | 23 | ||||
| -rw-r--r-- | challenge-122/abigail/go/ch-1.go | 28 | ||||
| -rw-r--r-- | challenge-122/abigail/java/ch-1.java | 19 | ||||
| -rw-r--r-- | challenge-122/abigail/lua/ch-1.lua | 18 | ||||
| -rw-r--r-- | challenge-122/abigail/node/ch-1.js | 16 | ||||
| -rw-r--r-- | challenge-122/abigail/pascal/ch-1.p | 24 | ||||
| -rw-r--r-- | challenge-122/abigail/perl/ch-1.pl | 11 | ||||
| -rw-r--r-- | challenge-122/abigail/python/ch-1.py | 19 | ||||
| -rw-r--r-- | challenge-122/abigail/r/ch-1.r | 18 | ||||
| -rw-r--r-- | challenge-122/abigail/ruby/ch-1.rb | 19 | ||||
| -rw-r--r-- | challenge-122/abigail/scheme/ch-1.scm | 27 | ||||
| -rw-r--r-- | challenge-122/abigail/t/ctest.ini | 11 | ||||
| -rw-r--r-- | challenge-122/abigail/tcl/ch-1.tcl | 16 |
19 files changed, 303 insertions, 1 deletions
diff --git a/challenge-122/abigail/README.md b/challenge-122/abigail/README.md index 15e7524445..fff6c14deb 100644 --- a/challenge-122/abigail/README.md +++ b/challenge-122/abigail/README.md @@ -19,6 +19,7 @@ Output: 10, 15, 20, 25, 30, 35, 40, 45, 50, ... ### Solutions * [AWK](awk/ch-1.awk) * [Bash](bash/ch-1.sh) +* [Basic](basic/ch-1.bas) * [bc](bc/ch-1.bc) * [Befunge-93](befunge-93/ch-1.bf) * [C](c/ch-1.c) diff --git a/challenge-122/abigail/awk/ch-1.awk b/challenge-122/abigail/awk/ch-1.awk new file mode 100644 index 0000000000..f801cef43b --- /dev/null +++ b/challenge-122/abigail/awk/ch-1.awk @@ -0,0 +1,11 @@ +#!/usr/bin/awk + +# +# See ../README.md +# + +# +# Run as: awk -f ch-1.awk < input-file +# + +{print ((sum += $1) / NR)} diff --git a/challenge-122/abigail/bash/ch-1.sh b/challenge-122/abigail/bash/ch-1.sh new file mode 100644 index 0000000000..29d3a79f9d --- /dev/null +++ b/challenge-122/abigail/bash/ch-1.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +# +# See ../README.md +# + +# +# Run as: bash ch-1.sh < input-file +# + +while read n; do echo $(((s += n) / ++ c)); done diff --git a/challenge-122/abigail/basic/ch-1.bas b/challenge-122/abigail/basic/ch-1.bas new file mode 100644 index 0000000000..d13b6f7b41 --- /dev/null +++ b/challenge-122/abigail/basic/ch-1.bas @@ -0,0 +1,15 @@ +010 REM +020 REM See ../README.md +030 REM + +040 REM +050 REM Run as: basic.pl ch-1.bas < input-file +051 REM Input file should be terminated with a 0. +060 REM + +100 INPUT n +110 IF n = 0 THEN END +150 s = s + n +160 c = c + 1 +170 PRINT s / c +200 GOTO 100 diff --git a/challenge-122/abigail/bc/ch-1.bc b/challenge-122/abigail/bc/ch-1.bc new file mode 100644 index 0000000000..a1ec963533 --- /dev/null +++ b/challenge-122/abigail/bc/ch-1.bc @@ -0,0 +1,15 @@ +# +# See ../README.md +# + +# +# Run as: bc ch-1.bc < input-file +# +# Terminate the input with 0 +# + +while (1) { + n = read () + if (n == 0) {break} + (s += n) / ++ c +} diff --git a/challenge-122/abigail/befunge-93/ch-1.bf93 b/challenge-122/abigail/befunge-93/ch-1.bf93 new file mode 100644 index 0000000000..9d4d852ed5 --- /dev/null +++ b/challenge-122/abigail/befunge-93/ch-1.bf93 @@ -0,0 +1,2 @@ +088p 0 >>>>>>>>>>>>>>>>>>>>>>>>>>>v +& :1+!#@_ + : 88g1+ :88p / . 55+, > diff --git a/challenge-122/abigail/c/ch-1.c b/challenge-122/abigail/c/ch-1.c new file mode 100644 index 0000000000..4d81d738fd --- /dev/null +++ b/challenge-122/abigail/c/ch-1.c @@ -0,0 +1,23 @@ +# include <stdlib.h> +# include <stdio.h> +# include <string.h> + +/* + * See ../README.md + */ + +/* + * Run as: cc -o ch-1.o ch-1.c; ./ch-1.o < input-file + */ + +int main (void) { + int n; + int s = 0; + int c = 0; + + while (scanf ("%d", &n) == 1) { + printf ("%d\n", (s += n) / ++ c); + } + + return (0); +} diff --git a/challenge-122/abigail/go/ch-1.go b/challenge-122/abigail/go/ch-1.go new file mode 100644 index 0000000000..f7059b6091 --- /dev/null +++ b/challenge-122/abigail/go/ch-1.go @@ -0,0 +1,28 @@ +package main + +// +// See ../README.md +// + +// +// Run as: go run ch-1.go +// + +import ( + "fmt" +) + +func main () { + var n, s, c int; + s = 0 + c = 0 + for { + var _, err = fmt . Scanf ("%d", &n) + if (err != nil) { + break + } + s += n + c ++ + fmt . Printf ("%d\n", s / c) + } +} diff --git a/challenge-122/abigail/java/ch-1.java b/challenge-122/abigail/java/ch-1.java new file mode 100644 index 0000000000..d11ff387c4 --- /dev/null +++ b/challenge-122/abigail/java/ch-1.java @@ -0,0 +1,19 @@ +// +// See ../README.md +// + +// +// Run as: ln ch-1.java ch1.java; javac ch1.java; java ch1 < input-file +// + +import java.util.*; + +public class ch1 { + public static void main (String [] args) { + Scanner scanner = new Scanner (System . in); + int s = 0, c = 0; + while (scanner . hasNext ()) { + System . out . println ((s += scanner . nextInt ()) / ++ c); + } + } +} diff --git a/challenge-122/abigail/lua/ch-1.lua b/challenge-122/abigail/lua/ch-1.lua new file mode 100644 index 0000000000..b20e835f46 --- /dev/null +++ b/challenge-122/abigail/lua/ch-1.lua @@ -0,0 +1,18 @@ +#!/opt/local/bin/lua + +-- +-- See ../README.md +-- + +-- +-- Run as: lua ch-1.lua < input-file +-- + +local s = 0 +local c = 0 + +for n in io . lines () do + s = s + tonumber (n) + c = c + 1 + print (s / c) +end diff --git a/challenge-122/abigail/node/ch-1.js b/challenge-122/abigail/node/ch-1.js new file mode 100644 index 0000000000..4626ee3f41 --- /dev/null +++ b/challenge-122/abigail/node/ch-1.js @@ -0,0 +1,16 @@ +#!/usr/local/bin/node + +// +// See ../README.md +// + +// +// Run as: node ch-1.js < input-file +// + +let s = 0 +let c = 0 + + require ('readline') +. createInterface ({input: process . stdin}) +. on ('line', n => {console . log ((s +=+ n) / ++ c)}) diff --git a/challenge-122/abigail/pascal/ch-1.p b/challenge-122/abigail/pascal/ch-1.p new file mode 100644 index 0000000000..a9cbb89e02 --- /dev/null +++ b/challenge-122/abigail/pascal/ch-1.p @@ -0,0 +1,24 @@ +Program XXX; + +(* *) +(* See ../README.md *) +(* *) + +(* *) +(* Run as: fpc -och-1.out ch-1.p; ./ch-1.out < input-file *) +(* *) + +var + n: integer; + s: integer = 0; + c: integer = 0; + + +begin + while not eof () do begin + readln (n); + s := s + n; + c := c + 1; + writeln (s div c); + end +end. diff --git a/challenge-122/abigail/perl/ch-1.pl b/challenge-122/abigail/perl/ch-1.pl new file mode 100644 index 0000000000..98659c4a39 --- /dev/null +++ b/challenge-122/abigail/perl/ch-1.pl @@ -0,0 +1,11 @@ +#!/opt/perl/bin/perl + +# +# See ../README.md +# + +# +# Run as: perl -pl ch-1.pl < input-file +# + +$_=($;+=$_)/$. diff --git a/challenge-122/abigail/python/ch-1.py b/challenge-122/abigail/python/ch-1.py new file mode 100644 index 0000000000..b2fdeea20c --- /dev/null +++ b/challenge-122/abigail/python/ch-1.py @@ -0,0 +1,19 @@ +#!/opt/local/bin/python + +# +# See ../README.md +# + +# +# Run as: python ch-1.py < input-file +# + +import fileinput + +s = 0 +c = 0 + +for n in fileinput . input (): + s = s + int (n) + c = c + 1 + print (s // c) diff --git a/challenge-122/abigail/r/ch-1.r b/challenge-122/abigail/r/ch-1.r new file mode 100644 index 0000000000..f6b4ad74b0 --- /dev/null +++ b/challenge-122/abigail/r/ch-1.r @@ -0,0 +1,18 @@ +# +# See ../README.md +# + +# +# Run as: Rscript ch-1.r < input-file +# + +stdin <- file ('stdin', 'r') +s <- 0 +c <- 0 +repeat { + n <- readLines (stdin, n = 1) + if (length (n) == 0) { + break + } + cat ((s <- s + as.integer (n)) / (c <- c + 1), "\n") +} diff --git a/challenge-122/abigail/ruby/ch-1.rb b/challenge-122/abigail/ruby/ch-1.rb new file mode 100644 index 0000000000..5bf102ac2a --- /dev/null +++ b/challenge-122/abigail/ruby/ch-1.rb @@ -0,0 +1,19 @@ +#!/usr/bin/ruby + +# +# See ../README.md +# + +# +# Run as: ruby ch-1.rb < input-file +# + +s = 0 +c = 0 + +ARGF . each_line do + |n| + s += n . to_i + c += 1 + puts (s / c) +end diff --git a/challenge-122/abigail/scheme/ch-1.scm b/challenge-122/abigail/scheme/ch-1.scm new file mode 100644 index 0000000000..62d55033a5 --- /dev/null +++ b/challenge-122/abigail/scheme/ch-1.scm @@ -0,0 +1,27 @@ +;;; +;;; See ../README.md +;;; + +;;; +;;; Run as: guile --no-auto-compile ch-1.scm < input-file +;;; + + +(use-modules (ice-9 format)) + +(define s 0) +(define c 0) + +(define (main) + (define n (read)) + (if (not (eof-object? n)) + (begin + (set! s (+ s n)) + (set! c (+ c 1)) + (format #t "~d\n" (/ s c)) + (main) + ) + ) +) + +(main) diff --git a/challenge-122/abigail/t/ctest.ini b/challenge-122/abigail/t/ctest.ini index 13d8fe84d2..eb2bc1aead 100644 --- a/challenge-122/abigail/t/ctest.ini +++ b/challenge-122/abigail/t/ctest.ini @@ -5,5 +5,14 @@ [names]
1-1 = Given Example
-2-1 = Example 1§
+2-1 = Example 1
2-2 = Example 2
+
+[challenges/1/perl]
+exe_args = -pl %RUN_FILE
+
+[challenges/1/bc]
+add_to_input = 0
+
+[challenges/1/basic]
+add_to_input = 0
diff --git a/challenge-122/abigail/tcl/ch-1.tcl b/challenge-122/abigail/tcl/ch-1.tcl new file mode 100644 index 0000000000..b1dcb52e2f --- /dev/null +++ b/challenge-122/abigail/tcl/ch-1.tcl @@ -0,0 +1,16 @@ +# +# See ../README.md +# + +# +# Run as: tclsh ch-1.tcl < input-file +# + +set s 0 +set c 0 + +while {[gets stdin n] >= 0} { + set s [expr $s + $n] + set c [expr $c + 1] + puts [expr $s / $c] +} |
