Water collected between towers: Difference between revisions

Content added Content deleted
No edit summary
(Added AutoHotkey)
Line 494: Line 494:
{{Out}}
{{Out}}
<lang AppleScript>{2, 14, 35, 0, 0, 0, 0}</lang>
<lang AppleScript>{2, 14, 35, 0, 0, 0, 0}</lang>

=={{header|AutoHotkey}}==
<lang AutoHotkey>WCBT(oTwr){
l := num := topL := 0, inp := barCh := "", oLvl := []
for i, h in oTwr
topL := h > topL ? h : topL, inp .= h ", "
inp := "[" Trim(inp, ", ") "]"
while (++l <= topL)
for t, h in oTwr
oLvl[l] .= h ? "█" : "≈"
, oTwr[t] := oTwr[t]>0 ? oTwr[t]-1 : 0
for i, l in oLvl{
while (SubStr(l, A_Index, 1) = "≈")
l := StrReplace(l, "≈", " ",,1)
l := reverse(l)
while (SubStr(l, A_Index, 1) = "≈")
l := StrReplace(l, "≈", " ",,1)
oLvl[i] := reverse(l)
}
for i, l in oLvl
l := StrReplace(l, "≈", "≈≈", n), l := StrReplace(l, " ", " ")
, l := StrReplace(l, "█", "██"), barCh := l "`n" barCh, num += n
return [inp, num, barCh]
}
reverse(n){
for i, v in StrSplit(n)
output := v output
return output
}</lang>
Examples:<lang AutoHotkey>data := [[1, 5, 3, 7, 2]
,[5, 3, 7, 2, 6, 4, 5, 9, 1, 2]
,[2, 6, 3, 5, 2, 8, 1, 4, 2, 2, 5, 3, 5, 7, 4, 1]
,[5, 5, 5, 5]
,[5, 6, 7, 8]
,[8, 7, 7, 6]
,[6, 7, 10, 7, 6]]

result := ""
for i, oTwr in data{
x := WCBT(oTwr)
result .= "Chart " x.1 " has " x.2 " water units`n" x.3 "------------------------`n"
}
MsgBox % result</lang>
{{out}}
<pre>Chart [1, 5, 3, 7, 2] has 2 water units
██
██
██≈≈██
██≈≈██
██████
████████
██████████
------------------------
Chart [5, 3, 7, 2, 6, 4, 5, 9, 1, 2] has 14 water units
██
██
██≈≈≈≈≈≈≈≈██
██≈≈██≈≈≈≈██
██≈≈██≈≈██≈≈████
██≈≈██≈≈████████
██████≈≈████████
████████████████≈≈██
████████████████████
------------------------
Chart [2, 6, 3, 5, 2, 8, 1, 4, 2, 2, 5, 3, 5, 7, 4, 1] has 35 water units
██
██≈≈≈≈≈≈≈≈≈≈≈≈≈≈██
██≈≈≈≈≈≈██≈≈≈≈≈≈≈≈≈≈≈≈≈≈██
██≈≈██≈≈██≈≈≈≈≈≈≈≈██≈≈████
██≈≈██≈≈██≈≈██≈≈≈≈██≈≈██████
██████≈≈██≈≈██≈≈≈≈██████████
████████████≈≈████████████████
████████████████████████████████
------------------------
Chart [5, 5, 5, 5] has 0 water units
████████
████████
████████
████████
████████
------------------------
Chart [5, 6, 7, 8] has 0 water units
██
████
██████
████████
████████
████████
████████
████████
------------------------
Chart [8, 7, 7, 6] has 0 water units
██
██████
████████
████████
████████
████████
████████
████████
------------------------
Chart [6, 7, 10, 7, 6] has 0 water units
██
██
██
██████
██████████
██████████
██████████
██████████
██████████
██████████
------------------------</pre>


=={{header|AWK}}==
=={{header|AWK}}==