Julia, 175(削除) 175 (削除ここまで) 170 bytes
a->try
r=rotr90
for _=1:4
while sum(a[1,:])<1
a=a[2:end,:]end
a=r(a)end
for _=1:4
a=r(a,a[end])end
a[a[1]]
while sum(a)>0
a[a[1a[a[a[:,1],:]]
a[a[:,1]]
a=a[2:end,2:end]end
a[1]catch
end
returns 0 if L-shaped and nothing otherwise
It's probably not the most efficient approch but I'm glad I could match the javascript answer
Ungolfed version
function f(a)
try
# remove margins
for _=1:4
while sum(a[1,:])<1
a=a[2:end,:]
end
a=rotr90(a)
end
# rotate `a[end]` times, meaning until a[end]==0
for _=1:4
a=rotr90(a,a[end])
end
a[a[1]] # check that a[1]!=0, by erroring if a[1]==0
while sum(a)>0
a[a[1,:]] # check that first line and col are all ones
a[a[:,1]]
a=a[2:end,2:end] # remove first line an col
end
a[1] # check that a is not empty (errors if empty)
catch
nothing
end
end
Julia, 175 bytes
a->try
r=rotr90
for _=1:4
while sum(a[1,:])<1
a=a[2:end,:]end
a=r(a)end
for _=1:4
a=r(a,a[end])end
a[a[1]]
while sum(a)>0
a[a[1,:]]
a[a[:,1]]
a=a[2:end,2:end]end
a[1]catch
end
returns 0 if L-shaped and nothing otherwise
It's probably not the most efficient approch but I'm glad I could match the javascript answer
Ungolfed version
function f(a)
try
# remove margins
for _=1:4
while sum(a[1,:])<1
a=a[2:end,:]
end
a=rotr90(a)
end
# rotate `a[end]` times, meaning until a[end]==0
for _=1:4
a=rotr90(a,a[end])
end
a[a[1]] # check that a[1]!=0, by erroring if a[1]==0
while sum(a)>0
a[a[1,:]] # check that first line and col are all ones
a[a[:,1]]
a=a[2:end,2:end] # remove first line an col
end
a[1] # check that a is not empty (errors if empty)
catch
nothing
end
end
Julia, (削除) 175 (削除ここまで) 170 bytes
a->try
r=rotr90
for _=1:4
while sum(a[1,:])<1
a=a[2:end,:]end
a=r(a)end
for _=1:4
a=r(a,a[end])end
a[a[1]]
while sum(a)>0
a[a[a[:,1],:]]
a=a[2:end,2:end]end
a[1]catch
end
returns 0 if L-shaped and nothing otherwise
It's probably not the most efficient approch but I'm glad I could match the javascript answer
Ungolfed version
function f(a)
try
# remove margins
for _=1:4
while sum(a[1,:])<1
a=a[2:end,:]
end
a=rotr90(a)
end
# rotate `a[end]` times, meaning until a[end]==0
for _=1:4
a=rotr90(a,a[end])
end
a[a[1]] # check that a[1]!=0, by erroring if a[1]==0
while sum(a)>0
a[a[1,:]] # check that first line and col are all ones
a[a[:,1]]
a=a[2:end,2:end] # remove first line an col
end
a[1] # check that a is not empty (errors if empty)
catch
nothing
end
end
Julia, 175 bytes
a->try
r=rotr90
for _=1:4
while sum(a[1,:])<1
a=a[2:end,:]end
a=r(a)end
for _=1:4
a=r(a,a[end])end
a[a[1]]
while sum(a)>0
a[a[1,:]]
a[a[:,1]]
a=a[2:end,2:end]end
a[1]catch
end
returns 0 if L-shaped and nothing otherwise
It's probably not the most efficient approch but I'm glad I could match the javascript answer
Ungolfed version
function f(a)
try
# remove margins
for _=1:4
while sum(a[1,:])<1
a=a[2:end,:]
end
a=rotr90(a)
end
# rotate `a[end]` times, meaning until a[end]==0
for _=1:4
a=rotr90(a,a[end])
end
a[a[1]] # check that a[1]!=0, by erroring if a[1]==0
while sum(a)>0
a[a[1,:]] # check that first line and col are all ones
a[a[:,1]]
a=a[2:end,2:end] # remove first line an col
end
a[1] # check that a is not empty (errors if empty)
catch
nothing
end
end