diff options
| author | Abigail <abigail@abigail.be> | 2021-09-15 00:17:58 +0200 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-09-15 00:17:58 +0200 |
| commit | fa7c33f7b20466dbb35212b79847f9d03bed0d43 (patch) | |
| tree | efe8cf0427019cda8ee4e021c5f0dfcb2a5105e4 | |
| parent | f20371e94fe411d75dbff4d4e2dbbc274f34f227 (diff) | |
| download | perlweeklychallenge-club-fa7c33f7b20466dbb35212b79847f9d03bed0d43.tar.gz perlweeklychallenge-club-fa7c33f7b20466dbb35212b79847f9d03bed0d43.tar.bz2 perlweeklychallenge-club-fa7c33f7b20466dbb35212b79847f9d03bed0d43.zip | |
Lua and Node.js solutions for week 130, part 1
| -rw-r--r-- | challenge-130/abigail/lua/ch-1.lua | 25 | ||||
| -rw-r--r-- | challenge-130/abigail/node/ch-1.js | 29 |
2 files changed, 54 insertions, 0 deletions
diff --git a/challenge-130/abigail/lua/ch-1.lua b/challenge-130/abigail/lua/ch-1.lua new file mode 100644 index 0000000000..6b5479291b --- /dev/null +++ b/challenge-130/abigail/lua/ch-1.lua @@ -0,0 +1,25 @@ +#!/opt/local/bin/lua + +-- +-- See ../README.md +-- + +-- +-- Run as: lua ch-1.lua < input-file +-- + +for line in io . lines () do + local numbers = {} + for n in line : gmatch ("([1-9][0-9]*)") do + if numbers [n] == nil then + numbers [n] = 1 + else + numbers [n] = numbers [n] + 1 + end + end + for number, count in pairs (numbers) do + if numbers [number] % 2 == 1 then + print (number) + end + end +end diff --git a/challenge-130/abigail/node/ch-1.js b/challenge-130/abigail/node/ch-1.js new file mode 100644 index 0000000000..4e9353f3af --- /dev/null +++ b/challenge-130/abigail/node/ch-1.js @@ -0,0 +1,29 @@ +#!/usr/local/bin/node + +// +// See ../README.md +// + +// +// Run as: node ch-1.js < input-file +// + + require ('readline') +. createInterface ({input: process . stdin}) +. on ('line', line => { + let numbers = {} + let input = [... line . matchAll (/[1-9][0-9]*/g)] . map (_ => + _ [0]) + input . forEach (n => { + if (!numbers [n]) { + numbers [n] = 1 + } + else { + numbers [n] ++ + } + }) + for (let n in numbers) { + if (numbers [n] % 2 == 1) { + console . log (n) + } + } +}) |
