3
Just for fun, I wanted to see how little lines I could solve this problem in, using python. I managed to condense my code into 9 lines.
size = int(input("Size: "))
a = [x for x in range(size-2, -1, -1)] if size % 2 == 0 else [x for x
in range(size-2, 0, -1)]
b, counter = a[::-1], 0
print("\n"+"\\"+"#"*size+"/") #top
for i in a[::2]: print("#"+" "*counter+"\\"+" "*i +"/"+ " "*counter+
"#"); counter += 1
if size % 2 != 0: print("#"+" "*counter+"X"+ " "*counter+ "#")
counter = int((size-2)/2)
for i in b[::2]: print("#"+" "*counter+"/"+" "*i +"\\"+ " "*counter+
"#"); counter -= 1
print("/"+"#"*size+"\\"+"\n") #bottom
as you can probably tell by the output the code is meant to produce
flags based on an integer from the user
with even number flags looking like this
\####/
#\ /#
# \/ #
# /\ #
#/ \#
/####\
and odd number flags looking like this, with the cross in the middle
\#####/
#\ /#
# \ / #
# X #
# / \ #
#/ \#
/#####\
I just wanted to see if anyone else could beat me, one of my classmates did it in four lines. Good luck :)
code with the least number of lines and bytes wins!
2Hi, Since this is programming challenges, you need a winning criteria explicitly stated. The easiest would be code-golf and at the end of the problem add the the statement
The shortest code in bytes for each language wins. Because in it's current state the community will most likely vote to close your problem. – LiefdeWen – 2017-12-18T08:13:53.8973Also limiting solutions to only one language is also a bad idea, maybe remove the python only requirement, someone is sure to answer in python anyway – LiefdeWen – 2017-12-18T08:15:23.580
4Note that "fewest number of lines" is not a good winning criterion, as most languages can easily put their whole code in one line. Even in python you can simply write
exec"code"to get everything in one line. – Laikoni – 2017-12-18T08:28:35.760Sandbox can be a great place to bounce ideas off of: https://codegolf.meta.stackexchange.com/questions/2140/sandbox-for-proposed-challenges/
– Neil – 2017-12-18T08:38:25.360This isn't an exact duplicate. This one only has # at the edge with spaces in the open areas while the other one is filled with #. It's not different enough for me cast a reopen vote though, especially while it's still restricted to python. Also it should say "least bytes." "lines and bytes" is two conflicting criteria. – Level River St – 2017-12-18T12:20:22.297
@LevelRiverSt Could it be turned into a
tipsquestion? – Arnauld – 2017-12-18T13:13:47.627