The document outlines a coding challenge for CDAC-Mumbai, consisting of six tasks that require the creation of functions for various programming problems. These tasks include checking for the presence of the digit 7 in an array, validating a PIN, determining if a number is Harshad, comparing two-digit numbers from card arrays, encoding and decoding messages, and counting square integers within a range. Each task includes examples to illustrate the expected functionality of the functions.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
12 views2 pages
Code Test 27 Jan 2025
The document outlines a coding challenge for CDAC-Mumbai, consisting of six tasks that require the creation of functions for various programming problems. These tasks include checking for the presence of the digit 7 in an array, validating a PIN, determining if a number is Harshad, comparing two-digit numbers from card arrays, encoding and decoding messages, and counting square integers within a range. Each task includes examples to illustrate the expected functionality of the functions.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2
CDAC-Mumbai
Subject: Coding Challenge
Date:27-01-2025 Total Marks:06 Time duration: 1:00hrs. Batch: Aug24 1. Create a function that takes an array of numbers and return "Boom!" if the digit 7 appears in the array. Otherwise, return "there is no 7 in the array". Examples sevenBoom([1, 2, 3, 4, 5, 6, 7]) ➞ "Boom!" // 7 contains the number seven. sevenBoom([8, 6, 33, 100]) ➞ "there is no 7 in the array" // None of the items contain 7 within them. sevenBoom([2, 55, 60, 97, 86]) ➞ "Boom!" // 97 contains the number seven. 2. Create a function that will test if a string is a valid PIN or not via a regular expression. A valid PIN has: Exactly 4 or 6 characters. Only numeric characters (0-9). No whitespace. Examples validate("121317") ➞ true validate("1234") ➞ true validate("45135") ➞ false validate("89abc1") ➞ false validate("900876") ➞ true validate(" 4983") ➞ false 3. A number is said to be Harshad if it's exactly divisible by the sum of its digits. Create a function that determines whether a number is a Harshad or not. Examples isHarshad(75) ➞ false // 7 + 5 = 12 // 75 is not exactly divisible by 12 isHarshad(171) ➞ true // 1 + 7 + 1 = 9 4. You have a pack of 5 randomly numbered cards, which can range from 0-9. You can win if you can produce a higher two-digit number from your cards than your opponent. Return true if your cards win that round. Examples winRound([2, 5, 2, 6, 9], [3, 7, 3, 1, 2]) ➞ true // Your cards can make the number 96 // Your opponent can make the number 73 // You win the round since 96 > 73 winRound([2, 5, 2, 6, 9], [3, 7, 3, 1, 2]) ➞ true winRound([1, 2, 3, 4, 5], [9, 8, 7, 6, 5]) ➞ false winRound([4, 3, 4, 4, 5], [3, 2, 5, 4, 1]) ➞ false 5. It's time to send and receive secret messages. Create two functions that take a string and an array and returns a coded or decoded message. The first letter of the string, or the first element of the array represents the Character Code of that letter. The next elements are the differences between the characters: e.g. A +3 --> C or z -1 --> y. Examples encrypt("Hello") ➞ [72, 29, 7, 0, 3] // H = 72, the difference between the H and e is 29 (upper- and lowercase). // The difference between the two l's is obviously 0. decrypt([ 72, 33, -73, 84, -12, -3, 13, -13, -68 ]) ➞ "Hi there!" encrypt("Sunshine") ➞ [83, 34, -7, 5, -11, 1, 5, -9] 6. Watson likes to challenge Sherlock's math ability. He will provide a starting and ending value describing a range of integers. Sherlock must determine the number of square integers within that range, inclusive of the endpoints (note that a square integer is an integer which is the square of an integer, e.g. 1, 4, 9, 16, 25, 36, 49). For example: The range is a=24 and b=49, inclusive. There are three square integers in the range: 25, 36 and 49. Complete the squares function that returns an integer representing the number of square integers in the inclusive range from a to b. Examples squares(3, 9) ➞ 2 squares(17, 24) ➞ 0 squares(1, 1000000000) ➞ 31622