fork download
  1. # your code goes here
  2. """ base58 encoding / decoding functions """
  3. import unittest
  4.  
  5. alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
  6. base_count = len(alphabet)
  7.  
  8. def encode(num):
  9. """ Returns num in a base58-encoded string """
  10. encode = ''
  11.  
  12. if (num < 0):
  13. return ''
  14.  
  15. while (num >= base_count):
  16. mod = num % base_count
  17. encode = alphabet[mod] + encode
  18. num = num / base_count
  19.  
  20. if (num):
  21. encode = alphabet[num] + encode
  22.  
  23. return encode
  24.  
  25. def decode(s):
  26. """ Decodes the base58-encoded string s into an integer """
  27. decoded = 0
  28. multi = 1
  29. s = s[::-1]
  30. for char in s:
  31. decoded += multi * alphabet.index(char)
  32. multi = multi * base_count
  33.  
  34. return decoded
  35.  
  36. class Base58Tests(unittest.TestCase):
  37.  
  38. def test_alphabet_length(self):
  39. self.assertEqual(58, len(alphabet))
  40.  
  41. def test_encode_10002343_returns_Tgmc(self):
  42. result = encode(10002343)
  43. self.assertEqual('Tgmc', result)
  44.  
  45. def test_decode_Tgmc_returns_10002343(self):
  46. decoded = decode('Tgmc')
  47. self.assertEqual(10002343, decoded)
  48.  
  49. def test_encode_1000_returns_if(self):
  50. result = encode(1000)
  51. self.assertEqual('if', result)
  52.  
  53. def test_decode_if_returns_1000(self):
  54. decoded = decode('if')
  55. self.assertEqual(1000, decoded)
  56.  
  57. def test_encode_zero_returns_empty_string(self):
  58. self.assertEqual('', encode(0))
  59.  
  60. def test_encode_negative_number_returns_empty_string(self):
  61. self.assertEqual('', encode(-100))
  62.  
  63. if __name__ == '__main__':
  64. #print encode(int("00B94BA6C51B3D8372D82FDE5DC78773D960B5A82FCDAC8181",16))
  65. print hex(decode("Wh4bh"))
Success #stdin #stdout 0.02s 8132KB
stdin
# Create a new figure for the revised pathophysiology diagram
fig, ax = plt.subplots(figsize=(10, 7))

# Title for the diagram
ax.set_title("Schematic Pathophysiology of Stroke", fontsize=16, fontweight='bold')

# Text boxes for different stages of stroke pathophysiology
# Stroke main category
ax.text(0.5, 0.9, 'Stroke (Ischemic or Hemorrhagic)', fontsize=12, ha='center', va='center', 
        bbox=dict(boxstyle="round,pad=0.3", edgecolor="black", facecolor="#FFCCCC"))

# Ischemic stroke path
ax.text(0.2, 0.75, 'Ischemic Stroke (~85% cases)', fontsize=10, ha='center', va='center', 
        bbox=dict(boxstyle="round,pad=0.3", edgecolor="black", facecolor="#FFFF99"))
ax.text(0.2, 0.65, 'Thrombotic Stroke (Plaque Build-Up)', fontsize=10, ha='center', va='center', 
        bbox=dict(boxstyle="round,pad=0.3", edgecolor="black", facecolor="white"))
ax.text(0.2, 0.55, 'Embolic Stroke (Embolism)', fontsize=10, ha='center', va='center', 
        bbox=dict(boxstyle="round,pad=0.3", edgecolor="black", facecolor="white"))
ax.text(0.2, 0.45, 'Necrosis (Cell Death)', fontsize=10, ha='center', va='center', 
        bbox=dict(boxstyle="round,pad=0.3", edgecolor="black", facecolor="white"))
ax.text(0.2, 0.35, 'Disruption of Plasma Membrane', fontsize=10, ha='center', va='center', 
        bbox=dict(boxstyle="round,pad=0.3", edgecolor="black", facecolor="white"))
ax.text(0.2, 0.25, 'Excitotoxicity, Free Radical Damage', fontsize=10, ha='center', va='center', 
        bbox=dict(boxstyle="round,pad=0.3", edgecolor="black", facecolor="white"))
ax.text(0.2, 0.15, 'Loss of Neuronal Function', fontsize=10, ha='center', va='center', 
        bbox=dict(boxstyle="round,pad=0.3", edgecolor="black", facecolor="white"))

# Hemorrhagic stroke path
ax.text(0.8, 0.75, 'Hemorrhagic Stroke (~15% cases)', fontsize=10, ha='center', va='center', 
        bbox=dict(boxstyle="round,pad=0.3", edgecolor="black", facecolor="#FF9999"))
ax.text(0.8, 0.65, 'Intracerebral Hemorrhage (ICH)', fontsize=10, ha='center', va='center', 
        bbox=dict(boxstyle="round,pad=0.3", edgecolor="black", facecolor="white"))
ax.text(0.8, 0.55, 'Subarachnoid Hemorrhage', fontsize=10, ha='center', va='center', 
        bbox=dict(boxstyle="round,pad=0.3", edgecolor="black", facecolor="white"))
ax.text(0.8, 0.45, 'Blood Vessel Rupture', fontsize=10, ha='center', va='center', 
        bbox=dict(boxstyle="round,pad=0.3", edgecolor="black", facecolor="white"))
ax.text(0.8, 0.35, 'Blood Accumulation & Pressure', fontsize=10, ha='center', va='center', 
        bbox=dict(boxstyle="round,pad=0.3", edgecolor="black", facecolor="white"))
ax.text(0.8, 0.25, 'Vascular Toxicity, Infarction', fontsize=10, ha='center', va='center', 
        bbox=dict(boxstyle="round,pad=0.3", edgecolor="black", facecolor="white"))
ax.text(0.8, 0.15, 'Neuronal Damage & Loss of Function', fontsize=10, ha='center', va='center', 
        bbox=dict(boxstyle="round,pad=0.3", edgecolor="black", facecolor="white"))

# Add arrows for flow
# Ischemic arrows
ax.annotate('', xy=(0.5, 0.87), xytext=(0.2, 0.78), arrowprops=dict(facecolor='black', arrowstyle="->"))
ax.annotate('', xy=(0.2, 0.63), xytext=(0.2, 0.68), arrowprops=dict(facecolor='black', arrowstyle="->"))
ax.annotate('', xy=(0.2, 0.53), xytext=(0.2, 0.58), arrowprops=dict(facecolor='black', arrowstyle="->"))
ax.annotate('', xy=(0.2, 0.43), xytext=(0.2, 0.48), arrowprops=dict(facecolor='black', arrowstyle="->"))
ax.annotate('', xy=(0.2, 0.33), xytext=(0.2, 0.38), arrowprops=dict(facecolor='black', arrowstyle="->"))
ax.annotate('', xy=(0.2, 0.23), xytext=(0.2, 0.28), arrowprops=dict(facecolor='black', arrowstyle="->"))

# Hemorrhagic arrows
ax.annotate('', xy=(0.5, 0.87), xytext=(0.8, 0.78), arrowprops=dict(facecolor='black', arrowstyle="->"))
ax.annotate('', xy=(0.8, 0.63), xytext=(0.8, 0.68), arrowprops=dict(facecolor='black', arrowstyle="->"))
ax.annotate('', xy=(0.8, 0.53), xytext=(0.8, 0.58), arrowprops=dict(facecolor='black', arrowstyle="->"))
ax.annotate('', xy=(0.8, 0.43), xytext=(0.8, 0.48), arrowprops=dict(facecolor='black', arrowstyle="->"))
ax.annotate('', xy=(0.8, 0.33), xytext=(0.8, 0.38), arrowprops=dict(facecolor='black', arrowstyle="->"))
ax.annotate('', xy=(0.8, 0.23), xytext=(0.8, 0.28), arrowprops=dict(facecolor='black', arrowstyle="->"))

# Hide axes
ax.axis('off')

# Save the figure as a JPEG image
plt.savefig('/mnt/data/Schematic_Pathophysiology_Stroke.jpeg', format='jpeg')

# Display the diagram
plt.show()
stdout
0x1406e058