Problem Backup Calendar - RobAllan27/CodingProblems GitHub Wiki
Project Backup Calendar with Increasing Disk Storage
This project looks to create a backup calendar for a year. The program takes as an input
- N disk drives
- A calendar Date
- and a radix ā to say how often a disk cyle should run. Rather than simply rotating this disks, where a different ones is sued in strict rotation, and they are cycled, this allows some disks to hold progressively older data. If N were 7 and there was simple roarion policy then
- Disk1 on monday
- Disk2 on Tuesday etc The business rationale for this is that if a data corruption issue is only found after a period of time, we have a disk to revert back to. We only take one backup a day though
Thus if the radix is 2 (i.e. binary, then the first disk will be used) and we have 3 disks
- Day 1 ā Disk 1
- Day 2 - Disk 2
- Day 3 ā Disk 1
- Day 4 - Disk 3
- Day 5 ā Disk 1
- Day 6 - Disk 2
- Day 7 - Disk 1
- Day 8 - Disk 3 If the radix is 3, then disk 1 is used twice, then disk 2, then twice more for disk 1, then disk 2, then twice more disk A, then disk 3. Allow for cases where the user mis-calculates how many disk he need - he should have a set of n tapes (or other media) will allow backups for 2nā1 days. If he did not give you enough disks, then return the first disk. ā ie he should have 10 disks for the year ina binary system for example.
Algorithm
- This is based on the Towers of Hanoi problem.
- Translate a date into a day of year - as a number.
- Translate it into a number expressed to radix (e.g. if radux is 2 it is binary number).
- Then work from the least significant character, and find the position of the first non zero value
- If the first non zero position is say Y and Y is greater than the supplied number of disk, then a as fall back we will simply use the first disk.
For example - if we have a radix of 2 and x represents the day of year
-
x is 1 to bits 1 - first non zero is 4th character (from the right) - use 1st disk.
-
x is 2 to bits 10 - first non zero is 4th character (from the right) ā use 2nd disk.
-
x is 3 to bits 11- first non zero is 4th character (from the right) - use 1st disk.
-
x is 27 to bits 11011- first non zero is 4th character (from the right) - use 4th disk.
-
x is 28 to bits 11100- first non zero is 4th character (from the right) - use 4th disk. Further if we have a radix of 3, then for the 27th and 28th day in base 3
-
x is 27 translated to radix(3) 1000 - first non zero is 4th character (from the right) - use 4th disk.
-
x is 28 translated to radix(3) 1001 - fist non zero character is the 1st character (from the right) - use the 1st disk
Test Cases
The following test cases are provided radix 2 i.e. 2 day base cycle ############### Should have 9 test disks Check if only 8 disks at day 256 that we use disk 1 ā¢ x is 1 to bits 1 ā¢ x is 2 to bits 10 ā¢ x is 27 to bits 11011 ā¢ x is 28 to bits 11100 ā¢ x is 256 to bits 100000000 ā¢ x is 257 to bits 100000001 ā¢ x is 364 to bits 101101100 ā¢ x is 365 to bits 101101101
getDiskChoiceForDate(int numberOfDisks, int radix, String dateInQuestion) - -eg.g 9,2,ā01-Jan-2018ā
radix 3 i.e. 3 day base cycle ############### Should have 6 test disks
Check if only 3 disks at day 27 that we use disk 1 ā¢ x is 1 to bits 1 ā¢ x is 2 to bits 2 ā¢ x is 27 to bits 1000 ā¢ x is 28 to bits 1001 ā¢ x is 364 to bits 111111 ā¢ x is 365 to bits 111112
radix 4 i.e. 4 day base cycle ############### Should have 5 test disks Check if only 3 disks at day 27 that we use disk 1 ā¢ x is 1 to bits 1 ā¢ x is 2 to bits 2 ā¢ x is 3 to bits 3 ā¢ x is 27 to bits 123
ā¢ x is 28 to bits 130 ā¢ x is 256 to bits 10000 ā¢ x is 364 to bits 11230 ā¢ x is 365 to bits 11231
Detailed Test cases - method along with the expected results
getDiskChoiceForDate(9,2,"01-Jan-2018"),1); getDiskChoiceForDate((9,2,"02-Jan-2018"),2); getDiskChoiceForDate((9,2,"27-Jan-2018"),1); getDiskChoiceForDate((9,2,"28-Jan-2018"),3); getDiskChoiceForDate((9,2,"13-Sep-2018"),9); getDiskChoiceForDate((8,2,"13-Sep-2018"),1); getDiskChoiceForDate((10,2,"13-Sep-2018"),9); getDiskChoiceForDate((9,2,"30-Dec-2018"),1); getDiskChoiceForDate((9,2,"31-Dec-2018"),3); getDiskChoiceForDate(6,3,"01-Jan-2018"),1); getDiskChoiceForDate((6,3,"02-Jan-2018"),1); getDiskChoiceForDate((6,3,"27-Jan-2018"),4); getDiskChoiceForDate((3,3,"27-Jan-2018"),1); getDiskChoiceForDate((6,3,"28-Jan-2018"),1); getDiskChoiceForDate((6,3,"20-Nov-2018"),5); getDiskChoiceForDate((6,3,"30-Dec-2018"),1); getDiskChoiceForDate((6,3,"31-Dec-2018"),1); getDiskChoiceForDate(5,4,"01-Jan-2018"),1); getDiskChoiceForDate((5,4,"02-Jan-2018"),1); getDiskChoiceForDate((5,4,"27-Jan-2018"),1); getDiskChoiceForDate((5,4,"28-Jan-2018"),2); getDiskChoiceForDate((5,4,"13-Sep-2018"),5); getDiskChoiceForDate((4,4,"13-Sep-2018"),1); getDiskChoiceForDate((5,4,"30-Dec-2018"),2); getDiskChoiceForDate((5,4,"31-Dec-2018"),1);