Skip to content

Instantly share code, notes, and snippets.

@t-shinkai00
Last active August 16, 2023 16:48
Show Gist options
  • Save t-shinkai00/3db2a421f807fbd9d80206d45ab587fd to your computer and use it in GitHub Desktop.
Save t-shinkai00/3db2a421f807fbd9d80206d45ab587fd to your computer and use it in GitHub Desktop.
raksul-codegolf
from itertools import groupby
def run_length(logo):
res = []
for line in logo.splitlines():
compressed = [(key, len(list(group))) for key, group in groupby(line)]
res.append(compressed)
return res
def remove_key(arr):
res = ""
for line in arr:
for i, (key, cnt) in enumerate(line):
res += f"{cnt}"
if i != len(line) - 1:
res += " "
res += ","
return res
import numpy as np
def convert_36decimal(s):
res = ""
for i in s.split(","):
for k in i.split():
res += np.base_repr(int(k), 36)
res += " "
return res
raksul_logo = \
""" ###############
#########################
################################
########### ##### ##########
######## ##### #########
####### ##### #######
####### ##### #######
###### ##### #### #######
###### ############ ######
##### ############### ######
##### #################### ######
##### ########### ########### ######
##### ############## ########### #####
###### ######### ##### ######### #####
##### ######### ##### ###### #####
###### ########### ##### ##### #####
##### ############## ##### ##### ######
############## ###### ##### ##### #####
########## ###### ##### ##### #####
######## ###### ##### ###### #####
###### ###### ############## #####
###### ###### ############### #####
##### ###### ####### ######## #####
##### ###### ##### ######## #####
##### ###### #### ######## #####
###### ###### ## ######## #####
##### ###### ######## ######
##### ###### ######### #####
##### ####### ######### #####
##### ######## # ######### ######
##### ################ #### ######## ######
###### ###################### #############
###### ############## ###########
####### ####### ########
###### #######
######## #######
######### ########
########### ##########
###############################
########################
##############
"""
if __name__ == '__main__':
arr = run_length(raksul_logo)
# [[(' ', 27), ('#', 15)], [(' ', 22), ('#', 25)], [(' ', 19), ('#', 32)], [(' ', 16), ('#', 11), (' ', 4), ('#', 5), (' ', 7), ('#', 10)], [(' ', 14), ('#', 8), (' ', 9), ('#', 5), (' ', 11), ('#', 9)], [(' ', 12), ('#', 7), (' ', 12), ('#', 5), (' ', 14), ('#', 7)], [(' ', 10), ('#', 7), (' ', 14), ('#', 5), (' ', 16), ('#', 7)], [(' ', 9), ('#', 6), (' ', 16), ('#', 5), (' ', 1), ('#', 4), (' ', 13), ('#', 7)], [(' ', 8), ('#', 6), (' ', 17), ('#', 12), (' ', 13), ('#', 6)], [(' ', 7), ('#', 5), (' ', 19), ('#', 15), (' ', 11), ('#', 6)], [(' ', 6), ('#', 5), (' ', 17), ('#', 20), (' ', 10), ('#', 6)], [(' ', 5), ('#', 5), (' ', 15), ('#', 11), (' ', 3), ('#', 11), (' ', 9), ('#', 6)], [(' ', 4), ('#', 5), (' ', 13), ('#', 14), (' ', 5), ('#', 11), (' ', 8), ('#', 5)], [(' ', 3), ('#', 6), (' ', 10), ('#', 9), (' ', 3), ('#', 5), (' ', 7), ('#', 9), (' ', 9), ('#', 5)], [(' ', 3), ('#', 5), (' ', 8), ('#', 9), (' ', 6), ('#', 5), (' ', 9), ('#', 6), (' ', 11), ('#', 5)], [(' ', 2), ('#', 6), (' ', 5), ('#', 11), (' ', 7), ('#', 5), (' ', 8), ('#', 5), (' ', 13), ('#', 5)], [(' ', 2), ('#', 5), (' ', 3), ('#', 14), (' ', 7), ('#', 5), (' ', 7), ('#', 5), (' ', 14), ('#', 6)], [(' ', 2), ('#', 14), (' ', 2), ('#', 6), (' ', 7), ('#', 5), (' ', 5), ('#', 5), (' ', 17), ('#', 5)], [(' ', 2), ('#', 10), (' ', 6), ('#', 6), (' ', 7), ('#', 5), (' ', 3), ('#', 5), (' ', 19), ('#', 5)], [(' ', 1), ('#', 8), (' ', 9), ('#', 6), (' ', 7), ('#', 5), (' ', 2), ('#', 6), (' ', 19), ('#', 5)], [(' ', 1), ('#', 6), (' ', 11), ('#', 6), (' ', 7), ('#', 14), (' ', 18), ('#', 5)], [(' ', 1), ('#', 6), (' ', 11), ('#', 6), (' ', 7), ('#', 15), (' ', 17), ('#', 5)], [(' ', 2), ('#', 5), (' ', 11), ('#', 6), (' ', 7), ('#', 7), (' ', 2), ('#', 8), (' ', 15), ('#', 5)], [(' ', 2), ('#', 5), (' ', 11), ('#', 6), (' ', 7), ('#', 5), (' ', 5), ('#', 8), (' ', 14), ('#', 5)], [(' ', 2), ('#', 5), (' ', 11), ('#', 6), (' ', 7), ('#', 4), (' ', 7), ('#', 8), (' ', 12), ('#', 5)], [(' ', 2), ('#', 6), (' ', 10), ('#', 6), (' ', 7), ('#', 2), (' ', 10), ('#', 8), (' ', 11), ('#', 5)], [(' ', 3), ('#', 5), (' ', 10), ('#', 6), (' ', 20), ('#', 8), (' ', 9), ('#', 6)], [(' ', 4), ('#', 5), (' ', 9), ('#', 6), (' ', 21), ('#', 9), (' ', 7), ('#', 5)], [(' ', 4), ('#', 5), (' ', 8), ('#', 7), (' ', 22), ('#', 9), (' ', 5), ('#', 5)], [(' ', 5), ('#', 5), (' ', 6), ('#', 8), (' ', 12), ('#', 1), (' ', 10), ('#', 9), (' ', 3), ('#', 6)], [(' ', 6), ('#', 5), (' ', 4), ('#', 16), (' ', 2), ('#', 4), (' ', 12), ('#', 8), (' ', 1), ('#', 6)], [(' ', 7), ('#', 6), (' ', 1), ('#', 22), (' ', 14), ('#', 13)], [(' ', 8), ('#', 6), (' ', 6), ('#', 14), (' ', 17), ('#', 11)], [(' ', 9), ('#', 7), (' ', 10), ('#', 7), (' ', 19), ('#', 8)], [(' ', 11), ('#', 6), (' ', 35), ('#', 7)], [(' ', 12), ('#', 8), (' ', 30), ('#', 7)], [(' ', 14), ('#', 9), (' ', 24), ('#', 8)], [(' ', 16), ('#', 11), (' ', 16), ('#', 10)], [(' ', 19), ('#', 31)], [(' ', 23), ('#', 24)], [(' ', 28), ('#', 14)]]
str1 = remove_key(arr)
# "27 15,22 25,19 32,16 11 4 5 7 10,14 8 9 5 11 9,12 7 12 5 14 7,10 7 14 5 16 7,9 6 16 5 1 4 13 7,8 6 17 12 13 6,7 5 19 15 11 6,6 5 17 20 10 6,5 5 15 11 3 11 9 6,4 5 13 14 5 11 8 5,3 6 10 9 3 5 7 9 9 5,3 5 8 9 6 5 9 6 11 5,2 6 5 11 7 5 8 5 13 5,2 5 3 14 7 5 7 5 14 6,2 14 2 6 7 5 5 5 17 5,2 10 6 6 7 5 3 5 19 5,1 8 9 6 7 5 2 6 19 5,1 6 11 6 7 14 18 5,1 6 11 6 7 15 17 5,2 5 11 6 7 7 2 8 15 5,2 5 11 6 7 5 5 8 14 5,2 5 11 6 7 4 7 8 12 5,2 6 10 6 7 2 10 8 11 5,3 5 10 6 20 8 9 6,4 5 9 6 21 9 7 5,4 5 8 7 22 9 5 5,5 5 6 8 12 1 10 9 3 6,6 5 4 16 2 4 12 8 1 6,7 6 1 22 14 13,8 6 6 14 17 11,9 7 10 7 19 8,11 6 35 7,12 8 30 7,14 9 24 8,16 11 16 10,19 31,23 24,28 14,"
str2 = convert_36decimal(str1)
# "RF MP JW GB457A E895B9 C7C5E7 A7E5G7 96G514D7 86HCD6 75JFB6 65HKA6 55FB3B96 45DE5B85 36A9357995 35896596B5 265B7585D5 253E7575E6 2E267555H5 2A667535J5 18967526J5 16B67EI5 16B67FH5 25B67728F5 25B67558E5 25B67478C5 26A672A8B5 35A6K896 4596L975 4587M955 5568C1A936 654G24C816 761MED 866EHB 97A7J8 B6Z7 C8U7 E9O8 GBGA JV NO SE"
###############
#########################
################################
########### ##### ##########
######## ##### #########
####### ##### #######
####### ##### #######
###### ##### #### #######
###### ############ ######
##### ############### ######
##### #################### ######
##### ########### ########### ######
##### ############## ########### #####
###### ######### ##### ######### #####
##### ######### ##### ###### #####
###### ########### ##### ##### #####
##### ############## ##### ##### ######
############## ###### ##### ##### #####
########## ###### ##### ##### #####
######## ###### ##### ###### #####
###### ###### ############## #####
###### ###### ############### #####
##### ###### ####### ######## #####
##### ###### ##### ######## #####
##### ###### #### ######## #####
###### ###### ## ######## #####
##### ###### ######## ######
##### ###### ######### #####
##### ####### ######### #####
##### ######## # ######### ######
##### ################ #### ######## ######
###### ###################### #############
###### ############## ###########
####### ####### ########
###### #######
######## #######
######### ########
########### ##########
###############################
########################
##############
[print("".join(" "*int(i,36)+"#"*int(j,36)for i,j in zip(l[::2],l[1::2])))for l in "RF MP JW GB457A E895B9 C7C5E7 A7E5G7 96G514D7 86HCD6 75JFB6 65HKA6 55FB3B96 45DE5B85 36A9357995 35896596B5 265B7585D5 253E7575E6 2E267555H5 2A667535J5 18967526J5 16B67EI5 16B67FH5 25B67728F5 25B67558E5 25B67478C5 26A672A8B5 35A6K896 4596L975 4587M955 5568C1A936 654G24C816 761MED 866EHB 97A7J8 B6Z7 C8U7 E9O8 GBGA JV NO SE".split()]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment