├── README.md ├── Day 21: Generics (C#) ├── Day 0: Hello World ├── Day 15: Linked Lists (C#) ├── Day 16: Exceptions ├── Day 17: More Exceptions ├── Day 19: Interfaces (C#) ├── Day 18: Queues and Stacks ├── Day 13: Abstract Classes (C#) ├── Day 27: Testing ├── Day 24: More Linked Lists (C#) ├── Day 29: Bitwise AND ├── Day 28: RegEx, Patterns and Intro to Databases ├── Day 3: Intro to Conditional Statements ├── Day 14: Scope (C#) ├── Day 9: Recursion ├── Day 22: Binary Search Trees (C#) ├── Day 23: BST Level Order Traversal (C#) ├── Day 1: Data Types ├── Day 26: Nested Logic ├── Day 2: Operators ├── Day 5: Loops ├── Day 25: Running Time and Complexity (C#) ├── Day 4: Class vs. Instance ├── Day 12: Inheritance (C#) ├── Day 7: Arrays ├── Day 8: Dictionaries and Maps ├── Day 6: Let's Review ├── Day 20: Sorting ├── Day 10: Binary Numbers └── Day 11: 2D Arrays /README.md: -------------------------------------------------------------------------------- 1 | # 30DaysOfCode-Javascript 2 | My javascript (and C#) solutions to the 30 Days Of Code challenge on HackerRank. 3 | -------------------------------------------------------------------------------- /Day 21: Generics (C#): -------------------------------------------------------------------------------- 1 | /* https://www.hackerrank.com/challenges/30-generics */ 2 | 3 | public static void printArray(T[] input) 4 | { 5 | foreach(T value in input) 6 | Console.WriteLine(value); 7 | } 8 | -------------------------------------------------------------------------------- /Day 0: Hello World: -------------------------------------------------------------------------------- 1 | function processData(inputString) { 2 | // Your first line of output goes here 3 | process.stdout.write("Hello, World."); 4 | 5 | // Write the second line of output 6 | process.stdout.write("\n" + inputString); 7 | } 8 | -------------------------------------------------------------------------------- /Day 15: Linked Lists (C#): -------------------------------------------------------------------------------- 1 | /* https://www.hackerrank.com/challenges/30-linked-list */ 2 | 3 | public static Node insert(Node head,int data) 4 | { 5 | //Complete this method 6 | if (head == null) 7 | return new Node(data); 8 | head.next = insert(head.next,data); 9 | return head; 10 | } 11 | -------------------------------------------------------------------------------- /Day 16: Exceptions: -------------------------------------------------------------------------------- 1 | /* https://www.hackerrank.com/challenges/30-exceptions-string-to-integer */ 2 | 3 | function main() { 4 | var S = readLine(); 5 | 6 | try{ 7 | console.log(parseInt(S).toString().replace('NaN', 'Bad String')); 8 | } 9 | 10 | catch(e){ 11 | console.log("Bad String"); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /Day 17: More Exceptions: -------------------------------------------------------------------------------- 1 | /* https://www.hackerrank.com/challenges/30-more-exceptions */ 2 | 3 | var Calculator = function() { 4 | Calculator.prototype.power = function(n,p) { 5 | 6 | if (n < 0 || p < 0) 7 | throw ("n and p should be non-negative"); 8 | else 9 | var x = Math.pow(n,p); 10 | return x; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Day 19: Interfaces (C#): -------------------------------------------------------------------------------- 1 | /* https://www.hackerrank.com/challenges/30-interfaces */ 2 | 3 | public class Calculator : AdvancedArithmetic 4 | { 5 | public int divisorSum(int x) 6 | { 7 | int sum = 0; 8 | for (int i = 1; i < x + 1; i++) 9 | { 10 | if (x%i == 0) 11 | sum+= i; 12 | } 13 | 14 | return sum; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Day 18: Queues and Stacks: -------------------------------------------------------------------------------- 1 | /* https://www.hackerrank.com/challenges/30-queues-stacks */ 2 | 3 | function Solution(){ 4 | //Write your code here 5 | this.stack = []; 6 | this.queue = []; 7 | 8 | Solution.prototype.pushCharacter = this.stack.push; 9 | Solution.prototype.popCharacter = this.stack.pop; 10 | Solution.prototype.enqueueCharacter = this.queue.push; 11 | Solution.prototype.dequeueCharacter = this.queue.shift; 12 | } 13 | -------------------------------------------------------------------------------- /Day 13: Abstract Classes (C#): -------------------------------------------------------------------------------- 1 | // https://www.hackerrank.com/challenges/30-abstract-classes 2 | 3 | //Write MyBook class 4 | class MyBook : Book{ 5 | private int price = 0; 6 | public MyBook(String title, String author, int price) : base(title, author){ 7 | this.price = price; 8 | } 9 | 10 | public override void display(){ 11 | Console.Write("Title: {0} \nAuthor: {1} \nPrice: {2}", title, author, price); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Day 27: Testing: -------------------------------------------------------------------------------- 1 | // https://www.hackerrank.com/challenges/30-testing 2 | //This challenge isn't really worth much. You just have to print a test case 3 | 4 | console.log(5); 5 | console.log("4 3"); 6 | console.log("-1 0 4 2"); 7 | console.log("6 1"); 8 | console.log("-2 -4 -5 0 3 4"); 9 | console.log("5 3"); 10 | console.log("0 -1 5 6 7"); 11 | console.log("3 2"); 12 | console.log("-9 0 10"); 13 | console.log("7 6"); 14 | console.log("-9 -8 -7 0 9 10 11"); 15 | -------------------------------------------------------------------------------- /Day 24: More Linked Lists (C#): -------------------------------------------------------------------------------- 1 | /* https://www.hackerrank.com/challenges/30-linked-list-deletion */ 2 | 3 | public static Node removeDuplicates(Node head){ 4 | //Write your code here 5 | if (head == null || head.next == null) 6 | return head; 7 | 8 | if (head.data == head.next.data) 9 | { 10 | head.next = head.next.next; 11 | removeDuplicates(head); 12 | } 13 | else 14 | removeDuplicates(head.next); 15 | return head; 16 | } 17 | -------------------------------------------------------------------------------- /Day 29: Bitwise AND: -------------------------------------------------------------------------------- 1 | /* https://www.hackerrank.com/challenges/30-bitwise-and */ 2 | 3 | function main() { 4 | var t = parseInt(readLine()); 5 | for(var a0 = 0; a0 < t; a0++){ 6 | var n_temp = readLine().split(' '); 7 | var n = parseInt(n_temp[0]); 8 | var k = parseInt(n_temp[1]); 9 | 10 | var a = k - 1; 11 | var b = (~a) & -(~a); 12 | 13 | if ( (a | b) > n ) 14 | console.log(a - 1); 15 | else 16 | console.log(a); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Day 28: RegEx, Patterns and Intro to Databases: -------------------------------------------------------------------------------- 1 | /* https://www.hackerrank.com/challenges/30-regex-patterns */ 2 | 3 | function main (){ 4 | var n = parseInt(readLine()); 5 | var arr = []; 6 | for (var i = 0; i < n; i++) 7 | arr.push(readLine()); 8 | 9 | var gmail = arr.filter(function(x) { return(x.includes("@gmail.com")) }); 10 | gmail.sort(); 11 | var names = gmail.map(function(x) { return(x.slice(0,x.indexOf(' '))) }); 12 | 13 | names.forEach(function(name) { 14 | console.log(name); 15 | }) 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Day 3: Intro to Conditional Statements: -------------------------------------------------------------------------------- 1 | /*Given an integer, , perform the following conditional actions: 2 | 3 | If n is odd, print Weird 4 | If n is even and in the inclusive range of 2 to 5, print Not Weird 5 | If n is even and in the inclusive range of 6 to 20, print Weird 6 | If n is even and greater than 20, print Not Weird 7 | */ 8 | 9 | function main() { 10 | var N = parseInt(readLine()); 11 | 12 | if (N%2 != 0 || (N > 5 && N < 21)) 13 | console.log("Weird"); 14 | else 15 | console.log("Not Weird") 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Day 14: Scope (C#): -------------------------------------------------------------------------------- 1 | /* */ 2 | 3 | public Difference(int[] array) 4 | { 5 | elements = array; 6 | } 7 | 8 | public void computeDifference() 9 | { 10 | int max = -999; 11 | int min = 999; 12 | 13 | for (int i = 0; i < elements.Length; i++) 14 | { 15 | if (elements[i] < min) 16 | min = elements[i]; 17 | if (elements[i] > max) 18 | max = elements[i]; 19 | } 20 | 21 | maximumDifference = Math.Abs(max - min); 22 | } 23 | -------------------------------------------------------------------------------- /Day 9: Recursion: -------------------------------------------------------------------------------- 1 | /* https://www.hackerrank.com/challenges/30-recursion */ 2 | 3 | function processData(input) { 4 | //Enter your code here 5 | console.log(factorial(input)); 6 | } 7 | 8 | function factorial(n){ 9 | if (n == 0) 10 | return 1; 11 | else 12 | return (n*(factorial(n - 1))); 13 | } 14 | 15 | process.stdin.resume(); 16 | process.stdin.setEncoding("ascii"); 17 | _input = ""; 18 | process.stdin.on("data", function (input) { 19 | _input += input; 20 | }); 21 | 22 | process.stdin.on("end", function () { 23 | processData(_input); 24 | }); 25 | -------------------------------------------------------------------------------- /Day 22: Binary Search Trees (C#): -------------------------------------------------------------------------------- 1 | /* https://www.hackerrank.com/challenges/30-binary-search-trees */ 2 | 3 | static int getHeight(Node root){ 4 | //Write your code here 5 | 6 | if (root == null) 7 | return -1; 8 | else 9 | { 10 | int leftHeight = getHeight(root.left); 11 | int rightHeight = getHeight(root.right); 12 | return (1 + Max(leftHeight,rightHeight)); 13 | } 14 | } 15 | 16 | public static int Max(int a, int b){ 17 | if (a - b > 0 || a == b) 18 | return a; 19 | else return b; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /Day 23: BST Level Order Traversal (C#): -------------------------------------------------------------------------------- 1 | /* https://www.hackerrank.com/challenges/30-binary-trees */ 2 | 3 | static void levelOrder(Node root){ 4 | //Write your code here 5 | Queue Q = new Queue(); 6 | Q.Enqueue(root); 7 | 8 | while (Q.Count > 0) 9 | { 10 | Node curNode = (Node)Q.Peek(); 11 | if (curNode.left != null) 12 | Q.Enqueue(curNode.left); 13 | if (curNode.right != null) 14 | Q.Enqueue(curNode.right); 15 | Console.Write(curNode.data + " "); 16 | Q.Dequeue(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Day 1: Data Types: -------------------------------------------------------------------------------- 1 | // Declare second integer, double, and String variables. 2 | var i2; 3 | var d2; 4 | var s2; 5 | // Read and save an integer, double, and String to your variables. 6 | i2 = parseInt(readLine()); 7 | d2 = parseFloat(readLine()); 8 | s2 = readLine(); 9 | // Print the sum of both integer variables on a new line. 10 | console.log(i + i2); 11 | // Print the sum of the double variables on a new line. 12 | console.log((d + d2).toFixed(1)); 13 | // Concatenate and print the String variables on a new line 14 | // The 's' variable above should be printed first. 15 | console.log(s + s2); 16 | -------------------------------------------------------------------------------- /Day 26: Nested Logic: -------------------------------------------------------------------------------- 1 | /* https://www.hackerrank.com/challenges/30-nested-logic */ 2 | 3 | function processData(input) { 4 | 5 | var dates = input.split("\n"); 6 | var a = dates[0].split(" ").map(Number); 7 | var b = dates[1].split(" ").map(Number); 8 | var actDate = new Date( a[2] , a[1] , a[0] ); 9 | var expDate = new Date( b[2] , b[1] , b[0] ); 10 | var fine = 0 11 | 12 | if ( actDate <= expDate ) 13 | fine = 0; 14 | else if ( a[1] == b[1] && a[2] == b[2] ) 15 | fine = 15*(a[0] - b[0]); 16 | else if (a[2] == b[2]) 17 | fine = 500*(a[1] - b[1]); 18 | else 19 | fine = 10000; 20 | 21 | console.log(fine); 22 | } 23 | -------------------------------------------------------------------------------- /Day 2: Operators: -------------------------------------------------------------------------------- 1 | function processData(input) { 2 | //Enter your code here 3 | var inputArray = input.split('\n'); 4 | 5 | var n = parseFloat(inputArray[0]); 6 | var tipperc = parseFloat(inputArray[1]); 7 | var taxperc = parseFloat(inputArray[2]); 8 | var tip = n*tipperc/100; 9 | var tax = n*taxperc/100; 10 | var MealCost = Math.round(n+tip+tax); 11 | 12 | console.log("The total meal cost is " + MealCost + " dollars."); 13 | } 14 | 15 | process.stdin.resume(); 16 | process.stdin.setEncoding("ascii"); 17 | _input = ""; 18 | process.stdin.on("data", function (input) { 19 | _input += input; 20 | }); 21 | 22 | process.stdin.on("end", function () { 23 | processData(_input); 24 | }); 25 | -------------------------------------------------------------------------------- /Day 5: Loops: -------------------------------------------------------------------------------- 1 | /* https://www.hackerrank.com/challenges/30-loops */ 2 | 3 | process.stdin.resume(); 4 | process.stdin.setEncoding('ascii'); 5 | 6 | var input_stdin = ""; 7 | var input_stdin_array = ""; 8 | var input_currentline = 0; 9 | 10 | process.stdin.on('data', function (data) { 11 | input_stdin += data; 12 | }); 13 | 14 | process.stdin.on('end', function () { 15 | input_stdin_array = input_stdin.split("\n"); 16 | main(); 17 | }); 18 | 19 | function readLine() { 20 | return input_stdin_array[input_currentline++]; 21 | } 22 | 23 | /////////////// ignore above this line //////////////////// 24 | 25 | function main() { 26 | var N = parseInt(readLine()); 27 | 28 | for (var x = 1; x < 11; x++) 29 | { 30 | var result = N*x; 31 | console.log(N.toString() + " x " + x + " = " + result.toString()); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /Day 25: Running Time and Complexity (C#): -------------------------------------------------------------------------------- 1 | /* https://www.hackerrank.com/challenges/30-running-time-and-complexity */ 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | class Solution { 7 | static void Main(String[] args) { 8 | /* Enter your code here. */ 9 | int n = int.Parse(Console.ReadLine()); 10 | 11 | for(int i = 0; i < n; i++) 12 | { 13 | int x = int.Parse(Console.ReadLine()); 14 | isPrime(x); 15 | } 16 | } 17 | 18 | public static void isPrime(int n) { 19 | bool isPrime = n > 1; 20 | for(int i = 2; i <= Math.Sqrt(n); i++) { 21 | if (n % i == 0) { 22 | isPrime = false; 23 | break; 24 | } 25 | } 26 | 27 | Console.WriteLine(isPrime ? "Prime" : "Not prime"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Day 4: Class vs. Instance: -------------------------------------------------------------------------------- 1 | /*https://www.hackerrank.com/challenges/30-class-vs-instance*/ 2 | 3 | function Person(initialAge){ 4 | // Add some more code to run some checks on initialAge 5 | var age = initialAge; 6 | this.amIOld=function(){ 7 | // Do some computations in here and print out the correct statement to the console 8 | if (age < 13 && age > -1) 9 | console.log("You are young."); 10 | else if (age < 18 && age > 12) 11 | console.log("You are a teenager."); 12 | else if (age > 17) 13 | console.log("You are old."); 14 | else 15 | { 16 | console.log("Age is not valid, setting age to 0.") 17 | age = 0; 18 | this.amIOld(); 19 | } 20 | 21 | }; 22 | this.yearPasses=function(){ 23 | // Increment the age of the person in here 24 | age ++; 25 | }; 26 | } 27 | -------------------------------------------------------------------------------- /Day 12: Inheritance (C#): -------------------------------------------------------------------------------- 1 | //https://www.hackerrank.com/challenges/30-inheritance 2 | 3 | class Student : Person{ 4 | private int[] testScores; 5 | 6 | public Student(string FN, string LN, int I, int[] scores):base(FN,LN,I) 7 | { 8 | this.testScores = scores; 9 | } 10 | 11 | public char calculate() 12 | { 13 | int avg=0; 14 | int sum=0; 15 | 16 | for(int i=0;i=90 && avg<=100) 26 | return('O'); 27 | else if(avg>=80 && avg<=90) 28 | return('E'); 29 | else if(avg>=70 && avg<=80) 30 | return('A'); 31 | else if(avg>=55 && avg<=70) 32 | return('P'); 33 | else if(avg>=40 && avg<=55) 34 | return('D'); 35 | else if(avg<40) 36 | return('T'); 37 | return('X'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Day 7: Arrays: -------------------------------------------------------------------------------- 1 | /* https://www.hackerrank.com/challenges/30-arrays */ 2 | 3 | process.stdin.resume(); 4 | process.stdin.setEncoding('ascii'); 5 | 6 | var input_stdin = ""; 7 | var input_stdin_array = ""; 8 | var input_currentline = 0; 9 | 10 | process.stdin.on('data', function (data) { 11 | input_stdin += data; 12 | }); 13 | 14 | process.stdin.on('end', function () { 15 | input_stdin_array = input_stdin.split("\n"); 16 | main(); 17 | }); 18 | 19 | function readLine() { 20 | return input_stdin_array[input_currentline++]; 21 | } 22 | 23 | /////////////// ignore above this line //////////////////// 24 | 25 | function main() { 26 | var n = parseInt(readLine()); 27 | arr = readLine().split(' '); 28 | arr = arr.map(Number); 29 | var result = ""; 30 | 31 | for (var i = n - 1; i > -1; i--) 32 | { 33 | result = result + arr[i] + " "; 34 | } 35 | console.log(result); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /Day 8: Dictionaries and Maps: -------------------------------------------------------------------------------- 1 | /* https://www.hackerrank.com/challenges/30-dictionaries-and-maps */ 2 | //Code from commentor in discussions section 3 | 4 | function processData(input) { 5 | input = input.split('\n') 6 | var N = parseInt(input[0]) 7 | 8 | var phonebook = [] 9 | for (var k = 0; k< N; k++){ 10 | var line = input[k+1] 11 | line = line.split(' ') 12 | phonebook[line[0]] = line[1] 13 | } 14 | 15 | for (var k = N+1; k < input.length; k++ ){ 16 | var num = (phonebook[input[k]]) 17 | if (num !== undefined){ 18 | console.log(input[k]+'='+num) 19 | } else { 20 | console.log('Not found') 21 | } 22 | } 23 | 24 | } 25 | 26 | process.stdin.resume(); 27 | process.stdin.setEncoding("ascii"); 28 | _input = ""; 29 | process.stdin.on("data", function (input) { 30 | _input += input; 31 | }); 32 | 33 | process.stdin.on("end", function () { 34 | processData(_input); 35 | }); 36 | -------------------------------------------------------------------------------- /Day 6: Let's Review: -------------------------------------------------------------------------------- 1 | /* https://www.hackerrank.com/challenges/30-review-loop */ 2 | 3 | function processData(input) { 4 | //Enter your code here 5 | message = input.split("\n"); 6 | 7 | var n = parseInt(message[0]); 8 | 9 | for (var x = 0; x < n; x++) 10 | { 11 | var m = message[x + 1]; 12 | var l = m.length; 13 | var arr = m.split(''); 14 | var ra = ""; 15 | var rb = ""; 16 | 17 | for (var y = 0; y < l; y++) 18 | { 19 | if (y%2 == 0) 20 | ra = ra + arr[y]; 21 | else 22 | rb = rb + arr[y]; 23 | } 24 | console.log(ra + " " + rb); 25 | 26 | } 27 | } 28 | 29 | process.stdin.resume(); 30 | process.stdin.setEncoding("ascii"); 31 | _input = ""; 32 | process.stdin.on("data", function (input) { 33 | _input += input; 34 | }); 35 | 36 | process.stdin.on("end", function () { 37 | processData(_input); 38 | }); 39 | -------------------------------------------------------------------------------- /Day 20: Sorting: -------------------------------------------------------------------------------- 1 | /* https://www.hackerrank.com/challenges/30-sorting */ 2 | 3 | /////////////// ignore above this line //////////////////// 4 | 5 | function main() { 6 | var n = parseInt(readLine()); 7 | a = readLine().split(' '); 8 | a = a.map(Number); 9 | var totalSwaps = 0; 10 | 11 | for (var i = 0; i < n; i++) { 12 | // Track number of elements swapped during a single array traversal 13 | var numberOfSwaps = 0; 14 | 15 | for (var j = 0; j < n - 1; j++) { 16 | // Swap adjacent elements if they are in decreasing order 17 | if (a[j] > a[j + 1]) { 18 | swap(j, j + 1, a); 19 | numberOfSwaps++; 20 | totalSwaps++; 21 | } 22 | } 23 | 24 | // If no elements were swapped during a traversal, array is sorted 25 | if (numberOfSwaps == 0) { 26 | break; 27 | } 28 | } 29 | console.log("Array is sorted in "+totalSwaps+" swaps."); 30 | console.log("First Element: " + a[0]); 31 | console.log("Last Element: " + a[n-1]); 32 | 33 | } 34 | 35 | function swap(x,y,array) 36 | { 37 | var b = array[y]; 38 | array[y] = array[x]; 39 | array[x] = b; 40 | } 41 | -------------------------------------------------------------------------------- /Day 10: Binary Numbers: -------------------------------------------------------------------------------- 1 | /* https://www.hackerrank.com/challenges/30-binary-numbers */ 2 | 3 | process.stdin.resume(); 4 | process.stdin.setEncoding('ascii'); 5 | 6 | var input_stdin = ""; 7 | var input_stdin_array = ""; 8 | var input_currentline = 0; 9 | 10 | process.stdin.on('data', function (data) { 11 | input_stdin += data; 12 | }); 13 | 14 | process.stdin.on('end', function () { 15 | input_stdin_array = input_stdin.split("\n"); 16 | main(); 17 | }); 18 | 19 | function readLine() { 20 | return input_stdin_array[input_currentline++]; 21 | } 22 | 23 | /////////////// ignore above this line //////////////////// 24 | 25 | function main() { 26 | var n = parseInt(readLine()); 27 | var arr = []; 28 | 29 | while(n != 0){ 30 | if (n%2 == 0) 31 | arr.push(0); 32 | if (n%2 == 1) 33 | arr.push(1); 34 | n = Math.floor(n/2); 35 | } 36 | 37 | var max = 0; 38 | var cur = 0; 39 | 40 | 41 | for (var i = 0, len = arr.length; i < len; i++) { 42 | if (arr[i] == 1) 43 | cur++; 44 | else if (arr[i] == 0){ 45 | if (cur > max) 46 | max = cur; 47 | cur = 0; 48 | } 49 | } 50 | 51 | if (cur > max) 52 | max = cur; 53 | 54 | console.log(max); 55 | } 56 | -------------------------------------------------------------------------------- /Day 11: 2D Arrays: -------------------------------------------------------------------------------- 1 | /* https://www.hackerrank.com/challenges/30-2d-arrays */ 2 | 3 | process.stdin.resume(); 4 | process.stdin.setEncoding('ascii'); 5 | 6 | var input_stdin = ""; 7 | var input_stdin_array = ""; 8 | var input_currentline = 0; 9 | 10 | process.stdin.on('data', function (data) { 11 | input_stdin += data; 12 | }); 13 | 14 | process.stdin.on('end', function () { 15 | input_stdin_array = input_stdin.split("\n"); 16 | main(); 17 | }); 18 | 19 | function readLine() { 20 | return input_stdin_array[input_currentline++]; 21 | } 22 | 23 | /////////////// ignore above this line //////////////////// 24 | 25 | function main() { 26 | var arr = []; 27 | for(arr_i = 0; arr_i < 6; arr_i++){ 28 | arr[arr_i] = readLine().split(' '); 29 | arr[arr_i] = arr[arr_i].map(Number); 30 | } 31 | 32 | var sumarr = []; 33 | 34 | var h = 0; 35 | for (var i = 0; i < 4; i++) { 36 | for (var j = 0; j < 4; j++) { 37 | sumarr[h] = arr[i][j] + arr[i][j+1] + arr[i][j+2] 38 | + arr[i+1][j+1] + arr[i+2][j] + arr[i+2][j+1] 39 | + arr[i+2][j+2]; 40 | h++; 41 | } 42 | } 43 | 44 | sumarr.sort(); 45 | 46 | var max = -99999; 47 | for (var x = 0; x < 16; x++){ 48 | if (sumarr[x] > max) 49 | max = sumarr[x]; 50 | } 51 | 52 | console.log(max); 53 | } 54 | 55 | --------------------------------------------------------------------------------