Skip to content

Instantly share code, notes, and snippets.

@sudhackar
Last active September 8, 2018 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sudhackar/42b7c23ac301c59050e93536ef90b937 to your computer and use it in GitHub Desktop.
Save sudhackar/42b7c23ac301c59050e93536ef90b937 to your computer and use it in GitHub Desktop.
strict digraph "" {
graph [ordering="out"];
null[label=""];
C -> G;
C -> H;
G -> M;
G -> N;
F -> S;
F -> U;
H -> null;
H -> W;
J -> Z;
J -> A;
L -> P;
L -> Y;
O -> J;
O -> K;
P -> O;
P -> E;
S -> L;
T -> F;
T -> V;
W -> X;
W -> I;
Z -> C;
Z -> D;
}
Display the source blob
Display the rendered blob
Raw
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 2.40.1 (20161225.0304)
-->
<!-- Pages: 1 -->
<svg width="458pt" height="836pt"
viewBox="0.00 0.00 458.00 836.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 832)">
<polygon fill="#ffffff" stroke="transparent" points="-4,4 -4,-832 454,-832 454,4 -4,4"/>
<!-- null -->
<g id="node1" class="node">
<title>null</title>
<ellipse fill="none" stroke="#000000" cx="171" cy="-90" rx="27" ry="18"/>
</g>
<!-- T -->
<g id="node2" class="node">
<title>T</title>
<ellipse fill="none" stroke="#000000" cx="387" cy="-810" rx="27" ry="18"/>
<text text-anchor="middle" x="387" y="-806.3" font-family="Times,serif" font-size="14.00" fill="#000000">T</text>
</g>
<!-- F -->
<g id="node3" class="node">
<title>F</title>
<ellipse fill="none" stroke="#000000" cx="351" cy="-738" rx="27" ry="18"/>
<text text-anchor="middle" x="351" y="-734.3" font-family="Times,serif" font-size="14.00" fill="#000000">F</text>
</g>
<!-- T&#45;&gt;F -->
<g id="edge1" class="edge">
<title>T&#45;&gt;F</title>
<path fill="none" stroke="#000000" d="M378.2854,-792.5708C374.0403,-784.0807 368.8464,-773.6929 364.1337,-764.2674"/>
<polygon fill="#000000" stroke="#000000" points="367.237,-762.6477 359.6343,-755.2687 360.976,-765.7782 367.237,-762.6477"/>
</g>
<!-- V -->
<g id="node4" class="node">
<title>V</title>
<ellipse fill="none" stroke="#000000" cx="423" cy="-738" rx="27" ry="18"/>
<text text-anchor="middle" x="423" y="-734.3" font-family="Times,serif" font-size="14.00" fill="#000000">V</text>
</g>
<!-- T&#45;&gt;V -->
<g id="edge2" class="edge">
<title>T&#45;&gt;V</title>
<path fill="none" stroke="#000000" d="M395.7146,-792.5708C399.9597,-784.0807 405.1536,-773.6929 409.8663,-764.2674"/>
<polygon fill="#000000" stroke="#000000" points="413.024,-765.7782 414.3657,-755.2687 406.763,-762.6477 413.024,-765.7782"/>
</g>
<!-- S -->
<g id="node5" class="node">
<title>S</title>
<ellipse fill="none" stroke="#000000" cx="315" cy="-666" rx="27" ry="18"/>
<text text-anchor="middle" x="315" y="-662.3" font-family="Times,serif" font-size="14.00" fill="#000000">S</text>
</g>
<!-- F&#45;&gt;S -->
<g id="edge3" class="edge">
<title>F&#45;&gt;S</title>
<path fill="none" stroke="#000000" d="M342.2854,-720.5708C338.0403,-712.0807 332.8464,-701.6929 328.1337,-692.2674"/>
<polygon fill="#000000" stroke="#000000" points="331.237,-690.6477 323.6343,-683.2687 324.976,-693.7782 331.237,-690.6477"/>
</g>
<!-- U -->
<g id="node6" class="node">
<title>U</title>
<ellipse fill="none" stroke="#000000" cx="387" cy="-666" rx="27" ry="18"/>
<text text-anchor="middle" x="387" y="-662.3" font-family="Times,serif" font-size="14.00" fill="#000000">U</text>
</g>
<!-- F&#45;&gt;U -->
<g id="edge4" class="edge">
<title>F&#45;&gt;U</title>
<path fill="none" stroke="#000000" d="M359.7146,-720.5708C363.9597,-712.0807 369.1536,-701.6929 373.8663,-692.2674"/>
<polygon fill="#000000" stroke="#000000" points="377.024,-693.7782 378.3657,-683.2687 370.763,-690.6477 377.024,-693.7782"/>
</g>
<!-- L -->
<g id="node7" class="node">
<title>L</title>
<ellipse fill="none" stroke="#000000" cx="315" cy="-594" rx="27" ry="18"/>
<text text-anchor="middle" x="315" y="-590.3" font-family="Times,serif" font-size="14.00" fill="#000000">L</text>
</g>
<!-- S&#45;&gt;L -->
<g id="edge5" class="edge">
<title>S&#45;&gt;L</title>
<path fill="none" stroke="#000000" d="M315,-647.8314C315,-640.131 315,-630.9743 315,-622.4166"/>
<polygon fill="#000000" stroke="#000000" points="318.5001,-622.4132 315,-612.4133 311.5001,-622.4133 318.5001,-622.4132"/>
</g>
<!-- P -->
<g id="node8" class="node">
<title>P</title>
<ellipse fill="none" stroke="#000000" cx="279" cy="-522" rx="27" ry="18"/>
<text text-anchor="middle" x="279" y="-518.3" font-family="Times,serif" font-size="14.00" fill="#000000">P</text>
</g>
<!-- L&#45;&gt;P -->
<g id="edge6" class="edge">
<title>L&#45;&gt;P</title>
<path fill="none" stroke="#000000" d="M306.2854,-576.5708C302.0403,-568.0807 296.8464,-557.6929 292.1337,-548.2674"/>
<polygon fill="#000000" stroke="#000000" points="295.237,-546.6477 287.6343,-539.2687 288.976,-549.7782 295.237,-546.6477"/>
</g>
<!-- Y -->
<g id="node9" class="node">
<title>Y</title>
<ellipse fill="none" stroke="#000000" cx="351" cy="-522" rx="27" ry="18"/>
<text text-anchor="middle" x="351" y="-518.3" font-family="Times,serif" font-size="14.00" fill="#000000">Y</text>
</g>
<!-- L&#45;&gt;Y -->
<g id="edge7" class="edge">
<title>L&#45;&gt;Y</title>
<path fill="none" stroke="#000000" d="M323.7146,-576.5708C327.9597,-568.0807 333.1536,-557.6929 337.8663,-548.2674"/>
<polygon fill="#000000" stroke="#000000" points="341.024,-549.7782 342.3657,-539.2687 334.763,-546.6477 341.024,-549.7782"/>
</g>
<!-- O -->
<g id="node10" class="node">
<title>O</title>
<ellipse fill="none" stroke="#000000" cx="243" cy="-450" rx="27" ry="18"/>
<text text-anchor="middle" x="243" y="-446.3" font-family="Times,serif" font-size="14.00" fill="#000000">O</text>
</g>
<!-- P&#45;&gt;O -->
<g id="edge8" class="edge">
<title>P&#45;&gt;O</title>
<path fill="none" stroke="#000000" d="M270.2854,-504.5708C266.0403,-496.0807 260.8464,-485.6929 256.1337,-476.2674"/>
<polygon fill="#000000" stroke="#000000" points="259.237,-474.6477 251.6343,-467.2687 252.976,-477.7782 259.237,-474.6477"/>
</g>
<!-- E -->
<g id="node11" class="node">
<title>E</title>
<ellipse fill="none" stroke="#000000" cx="315" cy="-450" rx="27" ry="18"/>
<text text-anchor="middle" x="315" y="-446.3" font-family="Times,serif" font-size="14.00" fill="#000000">E</text>
</g>
<!-- P&#45;&gt;E -->
<g id="edge9" class="edge">
<title>P&#45;&gt;E</title>
<path fill="none" stroke="#000000" d="M287.7146,-504.5708C291.9597,-496.0807 297.1536,-485.6929 301.8663,-476.2674"/>
<polygon fill="#000000" stroke="#000000" points="305.024,-477.7782 306.3657,-467.2687 298.763,-474.6477 305.024,-477.7782"/>
</g>
<!-- J -->
<g id="node12" class="node">
<title>J</title>
<ellipse fill="none" stroke="#000000" cx="207" cy="-378" rx="27" ry="18"/>
<text text-anchor="middle" x="207" y="-374.3" font-family="Times,serif" font-size="14.00" fill="#000000">J</text>
</g>
<!-- O&#45;&gt;J -->
<g id="edge10" class="edge">
<title>O&#45;&gt;J</title>
<path fill="none" stroke="#000000" d="M234.2854,-432.5708C230.0403,-424.0807 224.8464,-413.6929 220.1337,-404.2674"/>
<polygon fill="#000000" stroke="#000000" points="223.237,-402.6477 215.6343,-395.2687 216.976,-405.7782 223.237,-402.6477"/>
</g>
<!-- K -->
<g id="node13" class="node">
<title>K</title>
<ellipse fill="none" stroke="#000000" cx="279" cy="-378" rx="27" ry="18"/>
<text text-anchor="middle" x="279" y="-374.3" font-family="Times,serif" font-size="14.00" fill="#000000">K</text>
</g>
<!-- O&#45;&gt;K -->
<g id="edge11" class="edge">
<title>O&#45;&gt;K</title>
<path fill="none" stroke="#000000" d="M251.7146,-432.5708C255.9597,-424.0807 261.1536,-413.6929 265.8663,-404.2674"/>
<polygon fill="#000000" stroke="#000000" points="269.024,-405.7782 270.3657,-395.2687 262.763,-402.6477 269.024,-405.7782"/>
</g>
<!-- Z -->
<g id="node14" class="node">
<title>Z</title>
<ellipse fill="none" stroke="#000000" cx="171" cy="-306" rx="27" ry="18"/>
<text text-anchor="middle" x="171" y="-302.3" font-family="Times,serif" font-size="14.00" fill="#000000">Z</text>
</g>
<!-- J&#45;&gt;Z -->
<g id="edge12" class="edge">
<title>J&#45;&gt;Z</title>
<path fill="none" stroke="#000000" d="M198.2854,-360.5708C194.0403,-352.0807 188.8464,-341.6929 184.1337,-332.2674"/>
<polygon fill="#000000" stroke="#000000" points="187.237,-330.6477 179.6343,-323.2687 180.976,-333.7782 187.237,-330.6477"/>
</g>
<!-- A -->
<g id="node24" class="node">
<title>A</title>
<ellipse fill="none" stroke="#000000" cx="243" cy="-306" rx="27" ry="18"/>
<text text-anchor="middle" x="243" y="-302.3" font-family="Times,serif" font-size="14.00" fill="#000000">A</text>
</g>
<!-- J&#45;&gt;A -->
<g id="edge23" class="edge">
<title>J&#45;&gt;A</title>
<path fill="none" stroke="#000000" d="M215.7146,-360.5708C219.9597,-352.0807 225.1536,-341.6929 229.8663,-332.2674"/>
<polygon fill="#000000" stroke="#000000" points="233.024,-333.7782 234.3657,-323.2687 226.763,-330.6477 233.024,-333.7782"/>
</g>
<!-- C -->
<g id="node15" class="node">
<title>C</title>
<ellipse fill="none" stroke="#000000" cx="135" cy="-234" rx="27" ry="18"/>
<text text-anchor="middle" x="135" y="-230.3" font-family="Times,serif" font-size="14.00" fill="#000000">C</text>
</g>
<!-- Z&#45;&gt;C -->
<g id="edge13" class="edge">
<title>Z&#45;&gt;C</title>
<path fill="none" stroke="#000000" d="M162.2854,-288.5708C158.0403,-280.0807 152.8464,-269.6929 148.1337,-260.2674"/>
<polygon fill="#000000" stroke="#000000" points="151.237,-258.6477 143.6343,-251.2687 144.976,-261.7782 151.237,-258.6477"/>
</g>
<!-- D -->
<g id="node16" class="node">
<title>D</title>
<ellipse fill="none" stroke="#000000" cx="207" cy="-234" rx="27" ry="18"/>
<text text-anchor="middle" x="207" y="-230.3" font-family="Times,serif" font-size="14.00" fill="#000000">D</text>
</g>
<!-- Z&#45;&gt;D -->
<g id="edge14" class="edge">
<title>Z&#45;&gt;D</title>
<path fill="none" stroke="#000000" d="M179.7146,-288.5708C183.9597,-280.0807 189.1536,-269.6929 193.8663,-260.2674"/>
<polygon fill="#000000" stroke="#000000" points="197.024,-261.7782 198.3657,-251.2687 190.763,-258.6477 197.024,-261.7782"/>
</g>
<!-- G -->
<g id="node17" class="node">
<title>G</title>
<ellipse fill="none" stroke="#000000" cx="99" cy="-162" rx="27" ry="18"/>
<text text-anchor="middle" x="99" y="-158.3" font-family="Times,serif" font-size="14.00" fill="#000000">G</text>
</g>
<!-- C&#45;&gt;G -->
<g id="edge15" class="edge">
<title>C&#45;&gt;G</title>
<path fill="none" stroke="#000000" d="M126.2854,-216.5708C122.0403,-208.0807 116.8464,-197.6929 112.1337,-188.2674"/>
<polygon fill="#000000" stroke="#000000" points="115.237,-186.6477 107.6343,-179.2687 108.976,-189.7782 115.237,-186.6477"/>
</g>
<!-- H -->
<g id="node18" class="node">
<title>H</title>
<ellipse fill="none" stroke="#000000" cx="171" cy="-162" rx="27" ry="18"/>
<text text-anchor="middle" x="171" y="-158.3" font-family="Times,serif" font-size="14.00" fill="#000000">H</text>
</g>
<!-- C&#45;&gt;H -->
<g id="edge16" class="edge">
<title>C&#45;&gt;H</title>
<path fill="none" stroke="#000000" d="M143.7146,-216.5708C147.9597,-208.0807 153.1536,-197.6929 157.8663,-188.2674"/>
<polygon fill="#000000" stroke="#000000" points="161.024,-189.7782 162.3657,-179.2687 154.763,-186.6477 161.024,-189.7782"/>
</g>
<!-- M -->
<g id="node22" class="node">
<title>M</title>
<ellipse fill="none" stroke="#000000" cx="27" cy="-90" rx="27" ry="18"/>
<text text-anchor="middle" x="27" y="-86.3" font-family="Times,serif" font-size="14.00" fill="#000000">M</text>
</g>
<!-- G&#45;&gt;M -->
<g id="edge21" class="edge">
<title>G&#45;&gt;M</title>
<path fill="none" stroke="#000000" d="M83.7307,-146.7307C73.803,-136.803 60.6847,-123.6847 49.5637,-112.5637"/>
<polygon fill="#000000" stroke="#000000" points="51.7933,-109.8436 42.2473,-105.2473 46.8436,-114.7933 51.7933,-109.8436"/>
</g>
<!-- N -->
<g id="node23" class="node">
<title>N</title>
<ellipse fill="none" stroke="#000000" cx="99" cy="-90" rx="27" ry="18"/>
<text text-anchor="middle" x="99" y="-86.3" font-family="Times,serif" font-size="14.00" fill="#000000">N</text>
</g>
<!-- G&#45;&gt;N -->
<g id="edge22" class="edge">
<title>G&#45;&gt;N</title>
<path fill="none" stroke="#000000" d="M99,-143.8314C99,-136.131 99,-126.9743 99,-118.4166"/>
<polygon fill="#000000" stroke="#000000" points="102.5001,-118.4132 99,-108.4133 95.5001,-118.4133 102.5001,-118.4132"/>
</g>
<!-- H&#45;&gt;null -->
<g id="edge17" class="edge">
<title>H&#45;&gt;null</title>
<path fill="none" stroke="#000000" d="M171,-143.8314C171,-136.131 171,-126.9743 171,-118.4166"/>
<polygon fill="#000000" stroke="#000000" points="174.5001,-118.4132 171,-108.4133 167.5001,-118.4133 174.5001,-118.4132"/>
</g>
<!-- W -->
<g id="node19" class="node">
<title>W</title>
<ellipse fill="none" stroke="#000000" cx="243" cy="-90" rx="27" ry="18"/>
<text text-anchor="middle" x="243" y="-86.3" font-family="Times,serif" font-size="14.00" fill="#000000">W</text>
</g>
<!-- H&#45;&gt;W -->
<g id="edge18" class="edge">
<title>H&#45;&gt;W</title>
<path fill="none" stroke="#000000" d="M186.2693,-146.7307C196.197,-136.803 209.3153,-123.6847 220.4363,-112.5637"/>
<polygon fill="#000000" stroke="#000000" points="223.1564,-114.7933 227.7527,-105.2473 218.2067,-109.8436 223.1564,-114.7933"/>
</g>
<!-- X -->
<g id="node20" class="node">
<title>X</title>
<ellipse fill="none" stroke="#000000" cx="207" cy="-18" rx="27" ry="18"/>
<text text-anchor="middle" x="207" y="-14.3" font-family="Times,serif" font-size="14.00" fill="#000000">X</text>
</g>
<!-- W&#45;&gt;X -->
<g id="edge19" class="edge">
<title>W&#45;&gt;X</title>
<path fill="none" stroke="#000000" d="M234.2854,-72.5708C230.0403,-64.0807 224.8464,-53.6929 220.1337,-44.2674"/>
<polygon fill="#000000" stroke="#000000" points="223.237,-42.6477 215.6343,-35.2687 216.976,-45.7782 223.237,-42.6477"/>
</g>
<!-- I -->
<g id="node21" class="node">
<title>I</title>
<ellipse fill="none" stroke="#000000" cx="279" cy="-18" rx="27" ry="18"/>
<text text-anchor="middle" x="279" y="-14.3" font-family="Times,serif" font-size="14.00" fill="#000000">I</text>
</g>
<!-- W&#45;&gt;I -->
<g id="edge20" class="edge">
<title>W&#45;&gt;I</title>
<path fill="none" stroke="#000000" d="M251.7146,-72.5708C255.9597,-64.0807 261.1536,-53.6929 265.8663,-44.2674"/>
<polygon fill="#000000" stroke="#000000" points="269.024,-45.7782 270.3657,-35.2687 262.763,-42.6477 269.024,-45.7782"/>
</g>
</g>
</svg>
debug = False
def the_process(stored, inp, size, fs):
if debug:
print '\t' * fs + \
"the_process({}, {}, {})".format(stored, "".join(inp), size)
idx = 0
global thstr
idx = stored.index(inp[0])
if idx:
the_process(stored[:idx], inp[1:], idx, fs + 1)
if size - 1 != idx:
the_process(stored[1 + idx:1 + idx + size - idx - 1],
inp[idx + 1:], size - idx - 1, fs + 1)
thstr.append(inp[0])
def rev_process(stored, inp, size, fs):
if debug:
print '\t' * fs + \
"rev_process({}, {}, {})".format(stored, "".join(inp), size)
if not size:
return
global thstr
mp = {stored[i]: i for i in xrange(len(stored))}
idx = mp[inp[-1]]
thstr.append(inp[-1])
if size == 1:
return
try:
less_part = max(
loc for loc,
val in enumerate(inp) if mp[val] < idx) + 1
except ValueError:
less_part = 0
rev_process(stored[:idx], inp[:less_part], less_part, fs + 1)
if less_part != size - 1:
rev_process(stored[idx + 1:], inp[less_part:-1],
size - less_part - 1, fs + 1)
if __name__ == "__main__":
thstr = []
stored = "MGNCHXWIZDJAOKPELYSFUTV"
input1 = "TFSLPOJZCGMNHWXIDAKEYUV"
target = "MNGHCWZIJDXOPKLESUVTFYA"
print "sample input : " + input1
the_process(stored, input1, 23, 0)
output1 = "".join(thstr)
print "sample output : " + output1
thstr = []
rev_process(stored, output1, 23, 0)
input1_rev = "".join(thstr)
assert input1 == input1_rev
thstr = []
print "target output : " + target
rev_process(stored, target, 23, 0)
target_rev = "".join(thstr)
print "target input : " + target_rev
thstr = []
the_process(stored, target_rev, 23, 0)
target_out = "".join(thstr)
assert target_out == target
strict digraph "" {
graph [ordering="out"];
A -> X;
X -> C;
C -> G;
G -> M;
G -> N;
C -> H;
X -> D;
D -> I;
I -> W;
I -> Z;
D -> J;
A -> Y;
Y -> E;
E -> K;
E -> L;
K -> O;
K -> P;
Y -> F;
F -> S;
F -> T;
T -> U;
T -> V;
}
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment