Skip to content

Instantly share code, notes, and snippets.

@Hc747
Created August 22, 2019 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hc747/b05b061e0f0d2db795a2691f3ac4674f to your computer and use it in GitHub Desktop.
Save Hc747/b05b061e0f0d2db795a2691f3ac4674f to your computer and use it in GitHub Desktop.
Laura's Logbook Hours
import java.time.Duration
class AppMain {
static final def day_hours = [
[h:7, m:20],
[h:4, m:35],
[h:2, m:15],
[h:4, m:50],
[h:5, m:55],
[h:5, m:50],
[h:3, m:45],
[h:3, m:5],
[h:2, m:35],
[h:5, m:10],
[h:3, m:20],
[h:5, m:55],
[h:3, m:20],
[h:5, m:25],
]
static final def night_hours = [
[h:0, m:55],
[h:2, m:20],
[h:1, m:40],
[h:0, m:0],
[h:0, m:0],
[h:0, m:25],
[h:0, m:25],
[h:1, m:50],
[h:1, m:55],
[h:1, m:5],
[h:1, m:40],
[h:0, m:30],
[h:3, m:15],
[h:5, m:30],
]
static final def first_incorrect_page_day = [
[h:1, m:40],
[h:0, m:35],
[h:1, m:20],
[h:1, m:20],
[h:0, m:45],
[h:0, m:50],
[h:1, m:40],
[h:20, m:0],
]
static final def second_incorrect_page_day = [
[h:1, m:20],
[h:0, m:30],
[h:0, m:35],
[h:0, m:45],
[h:0, m:50],
[h:1, m:0],
[h:2, m:15],
]
static final def second_incorrect_page_night = [
[h:0, m:25],
]
public static void main(String[] args) {
final def running_day = sum(day_hours)
final def running_night = sum(night_hours)
final def incorrect_page_day_1 = sum(first_incorrect_page_day)
final def incorrect_page_day_2 = sum(second_incorrect_page_day)
final def incorrect_page_night_2 = sum(second_incorrect_page_night)
println("Running day: $running_day")
println("Running night: $running_night")
println("Incorrect page 1 - day: $incorrect_page_day_1")
println("Incorrect page 2 - day: $incorrect_page_day_2")
println("Incorrect page 2 - night: $incorrect_page_night_2")
final def total_day = running_day + incorrect_page_day_1 + incorrect_page_day_2
final def total_night = running_night + incorrect_page_night_2
println("Total day: $total_day")
println("Total night: $total_night")
final def total_overall = total_day + total_night
println("Total overall: $total_overall")
}
private static final Duration sum(def times) {
def duration = Duration.ZERO
for (def time in times) {
final def addend = Duration.ofHours(time.h) + Duration.ofMinutes(time.m)
duration += addend
}
return duration
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment