From 1f9fd3507cfe52a7e394838835f2dd9958100db0 Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 8 Jul 2021 20:28:28 +0200 Subject: Lua solutions for week 075 --- challenge-075/abigail/lua/ch-2.lua | 49 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 challenge-075/abigail/lua/ch-2.lua (limited to 'challenge-075/abigail/lua/ch-2.lua') diff --git a/challenge-075/abigail/lua/ch-2.lua b/challenge-075/abigail/lua/ch-2.lua new file mode 100644 index 0000000000..0765ff81b1 --- /dev/null +++ b/challenge-075/abigail/lua/ch-2.lua @@ -0,0 +1,49 @@ +#!/opt/local/bin/lua + +-- +-- See ../README.md +-- + +-- +-- Run as: lua ch-2.lua < input-file +-- + +for line in io . lines () do + local heights = {} + local h, i + local max_height = 0 + for h in line : gmatch ("%d+") do + h = tonumber (h) + table . insert (heights, h) + if max_height < h then + max_height = h + end + end + + local max_area = 0 + for h = 1, max_height do + local max = 0 + local cur = 0 + for i = 1, #heights do + if heights [i] >= h then + cur = cur + 1 + else + if max < cur then + max = cur + end + cur = 0 + end + end + + if max < cur then + max = cur + end + + local area = max * h + if max_area < area then + max_area = area + end + end + + print (max_area) +end -- cgit