TeamWork Technical Log

The apprentice staff gave us a Teamwork assignment two weeks ago. It consists in developing the code for 8 CodeJam problems in 4 different languages: Dart, Kotlin, Python, and Typescript. Around these two weeks, I had several meetings with my team to develop the programs in python and then we divided the translation into different languages. I didn't know Typescript before, but I have learned the Node library these weeks. My own participation was the translation of Equal sum and D1000000 to Typescript. My main blockers were the codes to communicate the inputs through the console. Up next I will give a quick overview of the problems and the solutions that we came up with.
CodeJam Problems
Punched Cards
3D Printing
D1000000
Chain Reaction
Twisty Little Passages
Double Or One Thing
Equal Sum
Weightlifting

Punched Cards

Google Link: Punched Cards

Back to the Top

3D Printing

Google Link: 3DPrinting

Back to the Top

D10000000

Google Link: D1000000

While the most typical type of dice have 6 sides, each of which shows a different integer 1 through 6, there are many games that use other types. A dk is a die with k sides, each of which shows a different integer 1 through K. A d6 is a typical die, a d4 has four sides, and a d1000000 has one Million sides.

In this problem, we start with a collection of N dice. The I-th die is a dSi, that is, it has Si sides showing integers 1 through Si. A straight length L starting at x is the list of x. We want to choose Some of the dice (possible all) and pick one number from each to form A straight. What is the longest straight we can form in this way?

INPUT: The first line of the input gives the number of test cases, T. T test cases follow. Each test case is described in two lines. The first line of a test case contains a single integer N, the number of dice in the game. The second line contains N integers S1, S2, S3…SN, each representing the number of sides of a different die.

D1000000 sample

In this program, I worked in the translation of languages. I translated it to Typescript. It wasn't easy because we had to build the interface to communicate through the Console. I couldn't do it alone but by a team, we find the solution was to use ReadLine library in Node documentation.


We open the library

const readline = require('readline');
let rl = readline.createInterface(process.stdin, process.stdout);



//FIRST
// The program starts here
// Reads input from the console and run all the cases

const lines : string[] = [];
rl.on('line', line => lines.push(line)).on('close', () => runAllTests(lines));


This command starts saving the inputs into a string. After the user uses the close command (control+ C <-- in Mac), the read line closes and it goes to a function named "runAllTest". This function redirects the information to another one to translate the data and again redirects the neat data to a Solve function.

All this process means that we need to catch the whole data to start working with them. After the read line it's closed we have to defragment the whole string to catch out what goes where. It's a tough process. For example, in python all this process is reduced by an input() line.

This approach wasn't easy but we did a great job having communication in the team to help each other with our research to solve the problem. I couldn't have done it alone, it was great to have support to complement what I was thinking. When I was trying to fix the problem I was stock trying to search another way to use document.write() or promt().

Back to the Top

Chain Reaction

Google Link: Chain Reaction

Back to the Top

Twisty Little Passages

Google Link: Twisty Little Passages

Back to the Top

Double or One Thing

Google Link: Double or One Thing

Back to the Top

Equal Sum

Google Link: Equal Sum

You are given a set of distinct integers. You need to separate them into two non-empty subsets such that each element belongs to exactly one of them and the sum of all elements of each subset is the same. An anonymous tip told us that the problem above was unlikely to be solved in polynomial time (or something like that), so we decided to change it. Now you get to decide what half of the integers are!

This is an interactive problem with three phases. In phase 1, you choose N distinct integers. In phase 2, you are given other N integers that are distinct from each other and from the ones you chose in phase 1. In phase 3, you have to partition those 2N integers into two subsets, both of which sum to the same amount. All 2N integers are to be between 1 and 10^9, inclusive, and it is guaranteed that they sum up to an even number.

EqualSum sample

In the picture above, I show you the example of only one case. The first input should be the number of cases. The next line consists of the judge's selection of length for lists to sum. Our code is calculating the first set of numbers to sum, that's our first output. Then, the judge gives us a set of numbers with the length they selected before. Our code calculation is the sum of the first set and the second set. The output's a set that contains a series of numbers that you can sum. That sum's the same for the output set as the hide set with the rest of the numbers.

To make an aproch for the solution I had to understand the code. It was more difficult than my personal assignment. A looked for help with my team to find another view of point. Then we discovered a math solution to solve the the N list of numbers we need to build the equal sum.

We know N can be only 100 (you can find it in Google Link ), so we calculate the first 30 data with binary numbers (The justify is because a large number in binary occupy less space) then, we add to this list the rest of the numbers given for the judge. It depends on the N length they selected after the case. Indeed, this representation can be reached with the 30 first powers of 2, and thus the remaining N-30 numbers we need to provide can be whatever other numbers inside 1 and 10^9.

After that, was easy to think about how to separate the numbers to build two lists with equal sums. For example: if our hole list was {5 5 1 11} we can have one list {5 5 1} and another {11}, it doesn't matter how many integers have, it's about the sum of the inside numbers in the list.

Part of my job was to translate the program to Typescript. Again, my main problem was how to introduce the inputs to the running program. Now I had a better idea of what to do. Even though I had built communication from the last problem I translated, now I have dynamic inputs to ask.



// using module 'readline'
const readline = require('readline');

// creates an interface to receive input and print output
let rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});


This is an approach I did with my team. We figured out that we need to use the command on() to do the whole code inside and use a condition to control and close the program when the cases are done. To ask for the cases we used a question() request.

rl.question('', (cases) => {
// Assigns T cases through line of input
T = Number(cases);

rl.on('line', (input) => {
HERE WE WRITE THE WHOLE MAIN CODE
}).on('close', () => {
process.exit
})
})

I processed the inputs inside the parseInteger() function and then I called the information of first and second input need to calculate the lists.


// function to parse strings into two different variables

const parseInteger = (input: string) => {
let value = input.split(' ').map((str) => Number(str));
return value;
}


All this work, again, wasn't easy to build because at the first moment it was overwhelming this kind of blockers when you have the date due soon for this assignment. However, as a team, we resolve the problem with several meetings to brainstorm ideas. In the end, I'm proud od the communication that my team built to help each other with blockers.

Back to the Top

WeightLifting

Google Link: WeightLifting

Back to the Top Back to the Top