Skip to content

Commit

Permalink
fix some logic errors
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Sep 9, 2024
1 parent f4fc7e8 commit f9ed1bf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/lua.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ concurrency:
jobs:
test:
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
Expand Down
19 changes: 10 additions & 9 deletions lua/src/p0076.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,36 @@ return {
local sum = 100
local counts = {}

for i = 1, 101 do
for i = 0,100,1
do
counts[i] = 0
end

counts[2 + 1] = 0
counts[2] = 0

while counts[100 + 1] == 0
while counts[100] == 0
do
counts[2 + 1] = counts[2 + 1] + 2
counts[2] = counts[2] + 2

if sum >= 100
then
answer = answer + (100 + counts[2 + 1] - sum) / 2
answer = answer + (100 + counts[2] - sum) / 2
idx = 2

repeat
counts[idx + 1] = 0 -- please remember lua is 1-indexed
counts[idx] = 0
idx = idx + 1
counts[idx + 1] = counts[idx + 1] + idx
counts[idx] = counts[idx] + idx

for i = (idx - 1),101,1
for i = idx,100,1
do
sum = sum + counts[i]
end
until sum <= 100
end

sum = 0
for i = 1,101,1
for i = 0,100,1
do
sum = sum + counts[i]
end
Expand Down

0 comments on commit f9ed1bf

Please sign in to comment.