fork download
  1. #!/bin/bash
  2.  
  3. function normalizeTimeInput()
  4. {
  5. local -r inputTime="${1}"
  6. local outputTime="${inputTime//\'/:}"
  7. outputTime="${outputTime//\"/:}"
  8. echo "${outputTime}"
  9. }
  10.  
  11. function addTime()
  12. {
  13. local inputTimes=("${@}")
  14. local hours=0
  15. local minutes=0
  16. local seconds=0
  17. local milliseconds=0
  18.  
  19. local tod="" # tod is time of day. Meaning units of hours:minutes:seconds:milliseconds
  20.  
  21. for time in "${inputTimes[@]}"; do
  22. #echo "${time}" | grep -oE "([[:digit:]]:)+[[:digit:]]+"
  23. tod=$(echo "${time}" | grep -oE "[[:digit:]]+:[[:digit:]]+:[[:digit:]]+")
  24.  
  25. millisecond=$(echo "${tod}" | cut -f 3 -d ':')
  26. second=$(echo "${tod}" | cut -f 2 -d ':')
  27. minute=$(echo "${tod}" | cut -f 1 -d ':')
  28.  
  29. #echo millisecond=$millisecond
  30. # Strip leading zeroes and add.
  31. milliseconds=$(( ${milliseconds} + ${millisecond##0} ))
  32. seconds=$(( ${seconds} + ${second##0} ))
  33. minutes=$(( ${minutes} + ${minute##0} ))
  34.  
  35. done
  36.  
  37. echo $minutes, $seconds, $milliseconds
  38. seconds=$((${seconds} + ${milliseconds} / 1000 ))
  39. milliseconds=$((${milliseconds} % 1000 ))
  40.  
  41. minutes=$((${minutes} + ${seconds} / 60 ))
  42. seconds=$((${seconds} % 60 ))
  43.  
  44. hours=$((${hours} + ${minutes} / 60 ))
  45. minutes=$((${minutes} % 60 ))
  46.  
  47. echo $hours hours, $minutes minutes, $seconds seconds, $milliseconds milliseconds
  48. }
  49.  
  50. times=(
  51. "1'34\"277" # Mario Kart Stadium
  52. "1'38\"995" # Water Park
  53. "1'48\"224" # Sweet Sweet Canyon
  54. "1'48\"077" # Thwomp Ruins
  55. "1'43\"830" # Mario Circuit
  56. "2'01\"586" # Toad Harbor
  57. "1'53\"354" # Twisted Mansion
  58. "1'55\"385" # Shy Guy Falls
  59. "1'57\"221" # Sunshine Airport
  60. "1'52\"119" # Dolphin Shoals
  61. "1'55\"367" # Electrodrome
  62. "1'40\"545" # Mount Wario
  63. "1'59\"329" # Cloudtop Cruise
  64. "1'46\"413" # Bone-Dry Dunes
  65. "1'57\"655" # Bowser's Castle
  66. "1'58\"454" # Rainbow Road
  67. "1'23\"642" # Wii Moo Moo Meadows
  68. "1'22\"953" # GBA Mario Circuit
  69. "1'46\"080" # DS Cheep Cheep Beach
  70. "1'45\"563" # N64 Toad's Turnpike
  71. "1'52\"431" # GCN Dry Dry Desert
  72. "1'12\"833" # SNES Donut Plains 3
  73. "1'54\"778" # N64 Royal Raceway
  74. "2'00\"477" # 3DS DK Jungle
  75. "1'50\"581" # DS Wario Stadium
  76. "1'46\"298" # GCN Sherbet Land
  77. "1'50\"508" # 3DS Music Park
  78. "1'57\"720" # N64 Yoshi Valley
  79. "1'41\"292" # DS Tick-Tock Clock
  80. "1'57\"960" # 3DS Piranha Plant Slide
  81. "1'52\"441" # Wii Grumble Volcano
  82. "1'19\"274" # N64 Rainbow Road
  83. "1'41\"253" # GCN Yoshi Circuit
  84. "1'38\"502" # Excitebike Arena
  85. "1'40\"081" # Dragon Driftway
  86. "1'50\"788" # Mute City
  87. "2'01\"373" # Wii Wario's Gold Mine
  88. "1'25\"569" # SNES Rainbow Road
  89. "1'44\"738" # Ice Ice Outpost
  90. "1'46\"905" # Hyrule Circuit
  91. "1'01\"836" # GCN Baby Park
  92. "1'41\"432" # GBA Cheese Land
  93. "1'45\"405" # Wild Woods
  94. "1'42\"158" # 3DS Neo Bowser City
  95. "1'43\"489" # GBA Ribbon Road
  96. "1'39\"680" # Super Bell Subway
  97. "1'23\"189" # Big Blue
  98. )
  99.  
  100. normTimes=()
  101. timesStr=""
  102.  
  103. function normalizeInputs()
  104. {
  105. for time in "${times[@]}"; do
  106. normTimes+=($(normalizeTimeInput "${time}"))
  107. done
  108. }
  109.  
  110. normalizeInputs
  111. addTime "${normTimes[@]}"
Success #stdin #stdout 0.51s 5300KB
stdin
Standard input is empty
stdout
50, 1889, 23060
1 hours, 21 minutes, 52 seconds, 60 milliseconds