Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

deleted 27 characters in body
Source Link
MarcMush
  • 6.9k
  • 15
  • 18

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

Try it online!

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

Try it online!

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

Try it online!

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

Try it online!

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

Try it online!

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

Try it online!

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

Try it online!

Source Link
MarcMush
  • 6.9k
  • 15
  • 18

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

Try it online!

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

Try it online!

AltStyle によって変換されたページ (->オリジナル) /