Let's hack
Two weeks ago, on Saturday, I and some amazing female developers participated in a hackathon which was tagged sheCodes. This was my second time participating in a hackathon and I had to make use of lessons learnt from my previous experience.
In preparation for the hackathon, I shared some hackathon etiquettes with the team which I’ll talk about, then we listed out tasks that we might do and delegated responsibility base on our strengths. We made sure we had someone to cover the following aspects: presentations, design, front-end development and back-end development.
The theme for the hackathon was finding solutions to genuine gender problems in Nigeria and the hackathon lasted for about 3hours. After the hackathon, my team was the first runner-up. I’ll be talking about the solutions we came up with for the first question and then my solutions to the other 3 questions.
Question 1
We were asked to design an app/website/platform that we think can help prevent or solve the current case of missing Chibok girls.
Solution
We looked at this question from the angle that the kidnap had already occurred and we needed a way to notify the relevant authorities what had happened.
We used the 5 Ws and 1H problem-solving technique to come up with our solution.
- Who was experiencing the problem?
- What were the effects of the problem?
- When did the problem occur or when did it start happening?
- Where did the problem occur?
- Why did the problem happen?
- How can we solve the problem?
The user stories we came up with were:
- User witnesses a kidnap
- The user opens the app and is immediately granted access to capture event via camera and write a description of what happened.
- Image captured, location and other necessary information which will be gotten from google map API.
- Information is sent out to people in that location via geofencing(especially, the nearest police stations).
- Information will be sent out to social media (Twitter, Facebook, etc), tagging news or security groups (you may need to look for twitter and/or Facebook handles that this news can be reported to).
We did not have enough time to implement the solution, but we presented what we had which is getting the information from the user and saving it to Firebase.
Question 2
Write a function that accepts an array of four dates and predicts the next 24 dates that a given lady will experience her period. The dates represent five recorded consecutive start dates of a lady’s menstrual cycle.
Conditions
- If the menstrual gap between two periods is less than or equal to 27, then we assume that the dates were recorded in error and the lady’s menstrual gap is assumed to be 28 days.
- If all gaps are different, take the average of all gaps
- If the menstrual gap between two periods is more than or equal to 31, then we assume that the dates were recorded in error yet again and the lady’s menstrual gap is assumed to be 30 days.
Test Data
["2017–01–01", "2017–01–28", "2017–02–25", "2017–03–25", "2017–04–23"]
Rough Solution
I worked on the algorithm after the hackathon and this was the first solution I came up with before refactoring:
const menstrualDates = (periodDates) => {
var startDate, nextDate, timeDifference, differenceInDays, avg, sum, differenceArray = [];
//check for the length of the array
if (periodDates.length > 5) {
return;
}
//sort the array
const newPeriodDates = periodDates.sort(function (a, b) {
return new Date(a) - new Date(b);
});
//find the difference between dates
for (var i = 0; i < newPeriodDates.length; i++) {
startDate = new Date(newPeriodDates[i]);
nextDate = new Date(newPeriodDates[i + 1]);
timeDifference = Math.abs(nextDate.getTime() - startDate.getTime());
differenceInDays = Math.ceil(timeDifference / (1000 * 3600 * 24));
//Make 28 for < 28 and 30 > 28
if (isNaN(differenceInDays) === false) {
var newDifference = (newDifference < 28) ? 28 : 30;
differenceArray.push(newDifference);
}
}
//Add the difference
differenceArray.reduce(function (a, b) {
sum = a + b;
return sum;
}, 0);
//Get Average and generate the next 24 dates
average = Math.round(sum / differenceArray.length);
for (var j = 0; j < 25; j++) {
startDate.setTime(startDate.getTime() + average * 86400000);
console.log(startDate);
}
};
Improved Solution
const menstrualDates = (periodDates) => {
if (periodDates.length > 5) {
return;
}
const newPeriodDates = periodDates.sort(function (a, b) {
return new Date(a) - new Date(b);
});
const differenceInDates = newPeriodDates.map((val, index) => {
if (index === 0) return 0;
return Math.ceil(Math.abs(new Date(newPeriodDates[index]) - new Date(newPeriodDates[index - 1])));
}).map(val => val / ((1000 * 3600 * 24))).map(Number);
const greaterThanOrEqualTo27 = differenceInDates.filter((val) => val <= 27 && val !== 0);
const containUniqKeys = (new Set(differenceInDates)).size === differenceInDates.length;
const greaterThan31Days = differenceInDates.filter((val) => val > 30);
let additionalDays;
if (greaterThanOrEqualTo27.length > 0) {
additionalDays = 28;
}
else if (containUniqKeys) {
total = differenceInDates.reduce((acc, val) => acc + val, 0);
additionalDays = Math.abs(total / periodDates.length);
}
else if (greaterThan31Days.length > 0) {
additionalDays = 30;
}
let startCountDate = new Date(newPeriodDates[newPeriodDates.length - 1]);
for (var j = 0; j < 25; j++) {
startCountDate.setTime(startCountDate.getTime() + additionalDays * 86400000);
console.log(startCountDate);
}
};
Expected Result Format
Tue May 23 2017 01:00:00 GMT+0100 (WAT) Thu Jun 22 2017 01:00:00 GMT+0100 (WAT) Sat Jul 22 2017 01:00:00 GMT+0100 (WAT) Mon Aug 21 2017 01:00:00 GMT+0100 (WAT) Wed Sep 20 2017 01:00:00 GMT+0100 (WAT) Fri Oct 20 2017 01:00:00 GMT+0100 (WAT) Sun Nov 19 2017 01:00:00 GMT+0100 (WAT) Tue Dec 19 2017 01:00:00 GMT+0100 (WAT) Thu Jan 18 2018 01:00:00 GMT+0100 (WAT) Sat Feb 17 2018 01:00:00 GMT+0100 (WAT) Mon Mar 19 2018 01:00:00 GMT+0100 (WAT) Wed Apr 18 2018 01:00:00 GMT+0100 (WAT) Fri May 18 2018 01:00:00 GMT+0100 (WAT) Sun Jun 17 2018 01:00:00 GMT+0100 (WAT) Tue Jul 17 2018 01:00:00 GMT+0100 (WAT) Thu Aug 16 2018 01:00:00 GMT+0100 (WAT) Sat Sep 15 2018 01:00:00 GMT+0100 (WAT) Mon Oct 15 2018 01:00:00 GMT+0100 (WAT) Wed Nov 14 2018 01:00:00 GMT+0100 (WAT) Fri Dec 14 2018 01:00:00 GMT+0100 (WAT) Sun Jan 13 2019 01:00:00 GMT+0100 (WAT) Tue Feb 12 2019 01:00:00 GMT+0100 (WAT) Thu Mar 14 2019 01:00:00 GMT+0100 (WAT) Sat Apr 13 2019 01:00:00 GMT+0100 (WAT) Mon May 13 2019 01:00:00 GMT+0100 (WAT)
Question 3
The ideal download manager works the following way. It sends a HTTP request for a file with headers that request for ranges that split the file so that the download can commence at different sections concurrently on individual threads. Once the downloads are completed, the download manager merges the individual files and “voila”, your file has been downloaded. Here are 11 parts of a binary file saved in a zip file. Your task is to merge these parts to produce a file. The name of the file has been persisted in the parts.
Solution
During the hackathon, we didn’t attempt this question because there wasn’t enough time to do this. I finally did this when I got home and it was the simplest of the questions.
Each of the 11 files is binary files, and we have to concatenate the files into one file using cat(command used in Unix/Linux).
cat picture1 picture2 picture3 ... > newFile
And Viola, the images can be viewed when you open the newFile.
Question 4
Here is a zip file with the JSON file of JSON objects accounts.json. It denotes bank accounts for several account holders. Represent the data graphically using any graph of your choosing. You may use pie charts, bar charts, line charts, doughnut chart and any fields of the data in your chart(s). What can you deduce about the gender dispersion of people and their accounts? What we want to see is your ability to represent data and give on-the-spot insights.
Solution
This question was solved by my team-mate using Chart.js, but I’ll be solving this using D3.js. They both can do the job, and this is based solely on preference. Check out the code.
Insights
There are no major differences in the number of female and male employees in each state.
Hackathon Etiquettes
Here are the etiquettes I and my colleagues use when preparing for hackathons.
- Ensure your idea is perfectly suited to the theme of the hackathon (if there’s a set theme by the organisers).
- Run your idea by someone with some experience in product building.
- Reverse engineer:
- # Start with the question: What do you want to demo? If possible make your presentation slides before you start writing code. Then walk backwards to the features you need to build. Never jump right in after the idea phase. There’s never enough time during hackathons and you have to maximise the time.
- If possible let your team have a mix of senior and junior developers. Variety is better.
- The demo:
- # The final presentation most times is the x-factor that determines who wins a hackathon. Your demo must showcase your idea/product/app in a way that connects with both the judges and the overall audience. You must go straight into the vital parts of your product/app and highlight it so it sinks in.
You can read more on these etiquettes here.
Before you go…
If you have a different solution to the questions above, I will love you to share. Thank you!
I think i was at a hackathon, sometime last year with some similar Qs, (with the exception of the Chibok Girls Question, MC calculation). We (my team) didn't win though, neither were we among's the runner-ups, but it was fun.
Awesome!
nice