Challenge 41 – Digital Time
Challenge 41 involved converting time from a 24 hour clock, to a digital clock using the following conversions.
- 10 digHours in a day.
- 10 digSecs in a digHour
- 4 diggyDos in a digSec
Format digital time as follows digHours:digSecs^diggyDos.
Note the accuracy of a diggyDo should be only computed to the nearest 10th of a unit.
The following is prototype function to compute digital time from a 24 hour time. Please fill in the missing information and use any data type you like in order to get the MOST ACCURATE result.
- Given a time in 24 hour units into Digital time per the above conversions.
- Any programming language can be used.
- Winner will be judged on accuracy and completeness of the solution.
Winners (out of approximately 25 respondents)
Thanks to everybody for your responses to SCS Coding Challenge #41!!!
Congratulations to Matt Kent for his fine efforts to come up with a workable algorithm.
|Name||Prize Winner||Good Answer|
Monthly Programming Tidbits
Avoid unnecessary variables
Back in 80s, programming books used to teach use to declare a variable for nearly everything! Look at this piece of code that reads two numbers from the console and prints the maximum:
My eyes are popping out as I’m declaring all these variables! What is the focus of this code? Two numbers and their maximum. So, firstInput and secondInput, which are strings read from the input, are not the focus of the code. All we care about is a number read from the console. The temporary string we receive from the console is not the focus here. So, these two variables are not adding any value to this code in terms of readability. They’re just creating noise in the code.
We can read an input from the console and convert it to a number in one line:
So, avoid declaring unnecessary variables. Use variables to increase the readability of the code.
Coding Challenge #42
Please stay tuned, SCS Coding Challenge #42 will be published this week. Details will follow. The winner will be awarded based upon the best approach.