From 5a28029ad84c590a0f5fa9ee9fc329eeb129809f Mon Sep 17 00:00:00 2001 From: notaero2 Date: Thu, 6 Feb 2025 15:27:20 +0800 Subject: [PATCH 1/4] Added height --- height/input.txt | 5 +++ height/output.txt | 88 +++++++++++++++++++++++++++++++++++++++++++++++ height/stub.dsl | 7 ++++ height/stub.js | 56 ++++++++++++++++++++++++++++++ 4 files changed, 156 insertions(+) create mode 100644 height/input.txt create mode 100644 height/output.txt create mode 100644 height/stub.dsl create mode 100644 height/stub.js diff --git a/height/input.txt b/height/input.txt new file mode 100644 index 0000000..b1c59ac --- /dev/null +++ b/height/input.txt @@ -0,0 +1,5 @@ +4 +1 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 +2 919 918 917 916 915 914 913 912 911 910 909 908 907 906 905 904 903 902 901 900 +3 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 900 +4 918 917 916 915 914 913 912 911 910 909 908 907 906 905 904 903 902 901 900 919 \ No newline at end of file diff --git a/height/output.txt b/height/output.txt new file mode 100644 index 0000000..59b1d9d --- /dev/null +++ b/height/output.txt @@ -0,0 +1,88 @@ +[ 1, + 900, + 901, + 902, + 903, + 904, + 905, + 906, + 907, + 908, + 909, + 910, + 911, + 912, + 913, + 914, + 915, + 916, + 917, + 918, + 919 ] +1 4 +[ 2, + 919, + 918, + 917, + 916, + 915, + 914, + 913, + 912, + 911, + 910, + 909, + 908, + 907, + 906, + 905, + 904, + 903, + 902, + 901, + 900 ] +2 4 +[ 3, + 901, + 902, + 903, + 904, + 905, + 906, + 907, + 908, + 909, + 910, + 911, + 912, + 913, + 914, + 915, + 916, + 917, + 918, + 919, + 900 ] +3 4 +[ 4, + 918, + 917, + 916, + 915, + 914, + 913, + 912, + 911, + 910, + 909, + 908, + 907, + 906, + 905, + 904, + 903, + 902, + 901, + 900, + 919 ] +4 4 diff --git a/height/stub.dsl b/height/stub.dsl new file mode 100644 index 0000000..f60f59a --- /dev/null +++ b/height/stub.dsl @@ -0,0 +1,7 @@ +function(integer_array, findStepBacks, integer_array students) +integer(P) +loop(P) + array(integer, students, 21, single) + invoke(integer_array, steps, findStepBacks, students) + print(integer_array, steps, \n) +endloop \ No newline at end of file diff --git a/height/stub.js b/height/stub.js new file mode 100644 index 0000000..be46873 --- /dev/null +++ b/height/stub.js @@ -0,0 +1,56 @@ + +'use strict'; + +const fs = require('fs'); + +process.stdin.resume(); +process.stdin.setEncoding('utf-8'); + +let inputString = ''; +let currentLine = 0; + +process.stdin.on('data', function(inputStdin) { + inputString += inputStdin; +}); + +process.stdin.on('end', function() { + inputString = inputString.split('\n'); + + main(); +}); + +function readLine() { + return inputString[currentLine++]; +} + +/* + * Complete the 'findStepBacks' function below. + * + * The function is expected to return an INTEGER_ARRAY. + * The function accepts INTEGER_ARRAY students as parameter. + */ + +function findStepBacks(students) { + // Write your code here + + console.log(students) + let steps = [students[0], 4] + return steps +} + +function main() { + const ws = process.stdout; + + const P = parseInt(readLine().trim(), 10); + + for (let PItr = 0; PItr < P; PItr++) { + + const students = readLine().replace(/\s+$/g, '').split(' ').map(studentsTemp => parseInt(studentsTemp, 10)); + + const steps = findStepBacks(students); + + ws.write(steps.join(' ') + '\n'); + } + + ws.end(); +} From 2861d68b00546e2df9d0b2cebd1bafbb24b2e28e Mon Sep 17 00:00:00 2001 From: notaero2 <148041806+notaero2@users.noreply.github.com> Date: Thu, 13 Feb 2025 13:40:03 +0800 Subject: [PATCH 2/4] Update height/input.txt Co-authored-by: Jeremiah Ang --- height/input.txt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/height/input.txt b/height/input.txt index b1c59ac..79475b1 100644 --- a/height/input.txt +++ b/height/input.txt @@ -1,5 +1,9 @@ 4 -1 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 -2 919 918 917 916 915 914 913 912 911 910 909 908 907 906 905 904 903 902 901 900 -3 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 900 -4 918 917 916 915 914 913 912 911 910 909 908 907 906 905 904 903 902 901 900 919 \ No newline at end of file +1 +900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 +2 +919 918 917 916 915 914 913 912 911 910 909 908 907 906 905 904 903 902 901 900 +3 +901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 900 +4 +918 917 916 915 914 913 912 911 910 909 908 907 906 905 904 903 902 901 900 919 \ No newline at end of file From 1d737f6fd54df42aa56f5410e3056595fdc84b61 Mon Sep 17 00:00:00 2001 From: notaero2 Date: Thu, 13 Feb 2025 13:47:43 +0800 Subject: [PATCH 3/4] updated dsl --- height/stub.dsl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/height/stub.dsl b/height/stub.dsl index f60f59a..501f03b 100644 --- a/height/stub.dsl +++ b/height/stub.dsl @@ -1,7 +1,8 @@ -function(integer_array, findStepBacks, integer_array students) +function(integer_array, findStepBacks, integer K, integer_array students) integer(P) loop(P) - array(integer, students, 21, single) - invoke(integer_array, steps, findStepBacks, students) + integer(K) + array(integer, students, 20, single) + invoke(integer_array, steps, findStepBacks, K, students) print(integer_array, steps, \n) endloop \ No newline at end of file From f6bf6cb119b3f7374872b031e8c92fb60a39376f Mon Sep 17 00:00:00 2001 From: notaero2 Date: Thu, 13 Feb 2025 14:38:29 +0800 Subject: [PATCH 4/4] Updated Code Stub --- height/stub.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/height/stub.js b/height/stub.js index be46873..dfad3dc 100644 --- a/height/stub.js +++ b/height/stub.js @@ -1,4 +1,3 @@ - 'use strict'; const fs = require('fs'); @@ -27,14 +26,17 @@ function readLine() { * Complete the 'findStepBacks' function below. * * The function is expected to return an INTEGER_ARRAY. - * The function accepts INTEGER_ARRAY students as parameter. + * The function accepts following parameters: + * 1. INTEGER K + * 2. INTEGER_ARRAY students */ -function findStepBacks(students) { +function findStepBacks(K, students) { // Write your code here + console.log(K) console.log(students) - let steps = [students[0], 4] + let steps = [K, 4] return steps } @@ -44,12 +46,13 @@ function main() { const P = parseInt(readLine().trim(), 10); for (let PItr = 0; PItr < P; PItr++) { + const K = parseInt(readLine().trim(), 10); const students = readLine().replace(/\s+$/g, '').split(' ').map(studentsTemp => parseInt(studentsTemp, 10)); - const steps = findStepBacks(students); + const steps = findStepBacks(K, students); - ws.write(steps.join(' ') + '\n'); + ws.write(steps.join('\n') + '\n'); } ws.end();