Timeline for Code Golf: Your own horizontal pet ASCII snake
Current License: CC BY-SA 3.0
14 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jun 17, 2020 at 9:04 | history | edited | CommunityBot |
Commonmark migration
|
|
Feb 22, 2018 at 14:14 | comment | added | linemade | Thanks for the explanation, mypetlion. Also thanks Turksarama and Ruts for saving me some bytes! | |
Feb 22, 2018 at 14:13 | history | edited | linemade | CC BY-SA 3.0 |
added 9 characters in body
|
Feb 22, 2018 at 7:41 | comment | added | Ruts |
Also tried to remove R=range and used function range twice in your code. This also seems to save 1 byte.
|
|
Feb 22, 2018 at 7:30 | comment | added | Ruts |
I'm not very experienced, but I believe you can win 9 bytes by not introducing variables w and h . Remove line w,h=30,5 and change m=[list(' '*w)for y in R(h)] to m=[list(' '*30)for y in R(5)] . I hope I'm right.
|
|
Feb 21, 2018 at 23:43 | comment | added | Turksarama |
Assign your initial 0 inside your loop and set l after the assignment. This saves you one whole line (m[2][0]=0 is gone) and 2 bytes on the for loop (for i in R(1,30): becomes for i in R(30): ). You will also need to recalculate l after you set the 0. This should take you to 144 bytes.
|
|
Feb 21, 2018 at 18:46 | comment | added | mypetlion |
In python, boolean a subclass of int . So False can be used in place of 0 and True can replace 1 . The ~ is a unary operator for bitwise not and the - operator flips the sign (multiply by -1 ). So ~-(False) evaluates to -1 and ~-(True) evaluates to 0.
|
|
Feb 21, 2018 at 18:34 | comment | added | linemade |
@mypetlion can you explain how l+=random.randint(~-(l<1),l<4) works?
|
|
Feb 21, 2018 at 18:13 | history | edited | linemade | CC BY-SA 3.0 |
deleted 1 character in body
|
Feb 21, 2018 at 17:58 | history | edited | linemade | CC BY-SA 3.0 |
deleted 8 characters in body
|
Feb 21, 2018 at 17:52 | comment | added | mypetlion |
Change m=[[' 'for x in R(w)]for y in R(h)] to m=[list(' '*w)for y in R(h)] to save 7 bytes.
|
|
Feb 21, 2018 at 17:51 | comment | added | Mr. Xcoder | You should be able to remove a lot of spaces and newlines. | |
Feb 21, 2018 at 17:48 | comment | added | mypetlion |
Change l+=random.randint(-1,1) l=0 if l<0 else l l=4 if l>4 else l to l+=random.randint(~-(l<1),l<4) to save 31 bytes.
|
|
Feb 21, 2018 at 17:37 | history | answered | linemade | CC BY-SA 3.0 |