From 86532cf2cbb93e85fa6b7ceb5969c2e6400221c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Santiago=20Pereyra=20V=C3=A1zquez?= Date: Sat, 24 Dec 2022 17:53:00 -0600 Subject: [PATCH] punched cards javascript solution uploaded --- solutions/punched-cards/.DS_Store | Bin 0 -> 6148 bytes solutions/punched-cards/input.txt | 4 ++ solutions/punched-cards/punched_cards.js | 47 +++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 solutions/punched-cards/.DS_Store create mode 100644 solutions/punched-cards/input.txt create mode 100644 solutions/punched-cards/punched_cards.js diff --git a/solutions/punched-cards/.DS_Store b/solutions/punched-cards/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..ba54321c34fa790fc798eae2453c7ef90cb0f6f8 GIT binary patch literal 6148 zcmeHKyH3ME5S%3`f@o4w-WNpT4@?w_)O-Mt1PPFpM8uIO-Q{!mM3{XLVGJz=>`J?H zx3_a=PjL?bGTpB(fH8m(T@eQjebaIEo}ENSQEZL|6Et{1Gp~Eq-zSuNibt%m#h%RE&NCi@XR3H^d z1^%T1JhRnCXO05pVPCp&~ND<##$?9=v)HW(WChMQ(e(E>#D%k(df(@otPH^ M)g>(z_zeZ#0jU8iX#fBK literal 0 HcmV?d00001 diff --git a/solutions/punched-cards/input.txt b/solutions/punched-cards/input.txt new file mode 100644 index 00000000..1ab1771a --- /dev/null +++ b/solutions/punched-cards/input.txt @@ -0,0 +1,4 @@ +3 +3 4 +2 2 +2 3 \ No newline at end of file diff --git a/solutions/punched-cards/punched_cards.js b/solutions/punched-cards/punched_cards.js new file mode 100644 index 00000000..9b25a8cf --- /dev/null +++ b/solutions/punched-cards/punched_cards.js @@ -0,0 +1,47 @@ +//Requirements to read the input file +const fs = require('fs'); +const inputFile = fs.readFileSync(0, 'utf8').trim().split('\n'); + +// Function definition +const punchedCards = (input) => { + // Declaring variables + let testCases = input[0], + cols = 0, + rows = 0, + caseNum = 1; + // Loop for each case + while (caseNum <= testCases) { + // Saving rows and columns numbers and create the matrix + rows = input[caseNum].split(' ')[0] * 2; + cols = input[caseNum].split(' ')[1] * 2; + let card = []; + // Loop to circle each row + for (let i = 0; i <= rows; i++) { + card.push(['']); + // Second loop to circle each column + if (i % 2 == 0) { + for (let j = 0; j <= cols; j++) { + card[i][j] = ((j % 2 == 0)? '+' : '-'); + } + } + else { + for (let j = 0; j <= cols; j++) { + card[i][j] = ((j % 2 == 0)? '|' : '.'); + } + } + } + // Replacing the top-left cell + card[0][0] = '.'; + card[0][1] = '.'; + card[1][0] = '.'; + card[1][1] = '.'; + // Printing the result + console.log(`Case #${caseNum}:`); + for (let i = 0; i <= rows; i++) { + console.log(`${card[i].join('')}\n`); + } + caseNum++; + } +}; +// Function call +punchedCards(inputFile); \ No newline at end of file