ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 26 Aug 2019 09:02:04 -0500How to draw the following graphhttp://ask.sagemath.org/question/47594/how-to-draw-the-following-graph/I want to write the following code in sagemath but unable to write it:
Suppose we consider the group $\Bbb Z_n$.
We consider an element $a\in \Bbb Z_n$ and form the subgroup generated by $a$ i.e. $\langle a\rangle =\{a,2a,3a,\ldots 0\}.$
We form a graph $G$ whose vertices are $\langle a\rangle $ and $\langle a\rangle $ and $\langle b\rangle $ are adjacent if either $\langle a\rangle \subset \langle b\rangle $ or $\langle b\rangle \subset \langle a\rangle $ .
How to plot the graph $G$ is Sagemath?
I am giving an example to clear the question:
Consider $\Bbb Z_4$ then consider $\langle 0\rangle $, $ \langle 1\rangle$ , $ \langle 2\rangle$, $ \langle 3\rangle$
Clearly $\langle 0\rangle =\{0\}$, $ \langle 1\rangle=\{1,2,3,0\}$ , $ \langle 2=\{2,0\}\rangle$, $ \langle 3=\{0,1,2,3\}\rangle$.
Thus the graph $G$ has vertices as $\langle 0\rangle $, $ \langle 1\rangle$ , $ \langle 2\rangle$, $ \langle 3\rangle$ and
$\langle 0\rangle $ is adjacent to $ \langle 1\rangle$ , $ \langle 2\rangle$, $ \langle 3\rangle$,
$\langle 1\rangle $ is adjacent to $ \langle 2\rangle$ , $ \langle 0\rangle$,
$\langle 2\rangle $ is adjacent to $ \langle 1\rangle$ , $ \langle 0\rangle$, $ \langle 3\rangle$
and $\langle 3\rangle $ is adjacent to $ \langle 0\rangle$, $ \langle 2\rangle$
Thus $G$ becomes
https://imgur.com/Ef9P4uzCaptchaMon, 26 Aug 2019 09:02:04 -0500http://ask.sagemath.org/question/47594/How to plot points of size less than 1?http://ask.sagemath.org/question/47573/how-to-plot-points-of-size-less-than-1/I have a huge sequence L (say of length $n=10^6$) and I would like to plot all the points (i,L[i]) for i in range(n).
To do so, the following works.
points([(i,L[i]) for i in range(n)],size=1)
The problem is that `size=1` (for the points) is too large for a satisfactory plotting.
But if $r$ is a fixed float with $0< r <1$, then
points([(i,L[i]) for i in range(n)],size=r)
is interpreted as
points([(i,L[i]) for i in range(n)],size=0)
which is an empty plotting (so not working).
**Question**: How to rewrite the second command line above to really plot points of `size=r`?Sébastien PalcouxFri, 23 Aug 2019 01:09:04 -0500http://ask.sagemath.org/question/47573/Animate 3d surface and add some curves ?http://ask.sagemath.org/question/46284/animate-3d-surface-and-add-some-curves/ I want animate my surface of hyperboloid by adding 2 point then draw a geodesic curve between them .
Thanks for ur help guys Taoufik ahanchaouSat, 20 Apr 2019 01:15:49 -0500http://ask.sagemath.org/question/46284/Line,Plane, Points 3D, Intersection,http://ask.sagemath.org/question/46033/lineplane-points-3d-intersection/Is there a tutorial on
-analytical geometry(vectors) :
plane
line
2D circle in 3D,
plot chains of vectors, basicaly the everything what this thing can do: https://www.geogebra.org/3d?lang=de
well allmost everything in vector geometry
for python or sagemath.
Maybe someone saw a book or tutorial on this
I can not find anything on this.
I have managed to plot points
from sage.plot.plot3d.shapes2 import frame3d
F=frame3d([0,0,0],vector([10,10,10]),color='red')
A=point3d((4,3,2),size=10,color='red',opacity=.5)
e=0.2
eps=vector([4+e,3+e,2+e])
T = text3d('A',eps)
F+A+T
I didnt manage to label, point A(4,3,2), to to do it? I would rather not put the coordinates as a string. Is there something like in c++ "The point is %d"
Is there a better way to plot? I need the frame, since the plot 3d is not accepting, text, or maybe i am wrong?
Would there by a natural way to plot x,y,z axes?
Here is the Code
https://share.cocalc.com/share/a3f14e05-7729-406f-97c5-be5b73646381/vector/ebene.sagews?viewer=sharethethaSat, 06 Apr 2019 12:52:46 -0500http://ask.sagemath.org/question/46033/How to change color AFTER calling "plot"?http://ask.sagemath.org/question/45422/how-to-change-color-after-calling-plot/Suppose I have done
p = plot(x^2) + plot(x^3)
and then I decide I want the image in grayscale. Is there a way to specify this without having to re-plot again?
Thanks in advance for your answers!dsejasMon, 11 Feb 2019 13:51:38 -0600http://ask.sagemath.org/question/45422/Conditional Plot, plot f(x+iy) if g(x+iy) satisfies some kind of conditionhttp://ask.sagemath.org/question/45445/conditional-plot-plot-fxiy-if-gxiy-satisfies-some-kind-of-condition/Let's say I have two functions f(zeta) and g(zeta), and I'd like to have 3D-plot and Contour Plot of f(zeta) if g(zeta) in a certain range.
I have defined f(zeta) and g(zeta), and then I tried this command, but Sage said the syntax is not valid.
B=implicit_plot(lambda x,y : float(f(x+y*I)),if 1<g(x+y*I)<3,(-5,5),(-5,5)))
I am pretty new with Sage math, so please bear with me if the question is too trivial....
JacobsonRadicalWed, 13 Feb 2019 04:55:53 -0600http://ask.sagemath.org/question/45445/__init__() takes exactly 5 arguments (4 given) error in contour plothttp://ask.sagemath.org/question/45446/__init__-takes-exactly-5-arguments-4-given-error-in-contour-plot/ I am trying to make a contour plot of a complex valued function. Let say it is g(z).
I have imported the complex root and ContourPlot command by doing following:
from sage.rings.polynomial.complex_roots import complex_roots
from sage.plot.contour_plot import ContourPlot
I have even successfully plot the 3d-Plot, but I encountered an error stating:
__init__() takes exactly 5 arguments (4 given)
My command is:
C=ContourPlot(lambda x,y:float(green(x+y*I)),(-5,5),(-5,5))
It seems that I did not miss the fifth argument, I tried to add in some commands, such as plot_points, but then Sage said it did not expect these commands..
What did I miss? Thank you!!JacobsonRadicalWed, 13 Feb 2019 05:03:37 -0600http://ask.sagemath.org/question/45446/draw all faces of alcoves (affine root system)http://ask.sagemath.org/question/45354/draw-all-faces-of-alcoves-affine-root-system/I am trying to plot alcoves for in a rank 3 affine root system with some of those alcoves highlighted by having all faces drawn and the others only shown as a wire frame.
The manual on visualising root systems at sagemath.org is quite useful, but I have some effects show that I don't understand.
For some reason while the fundamental alcove will have all faces shown many of the others have not, that is, some faces are missing. Below you find one example code that I have done. For the chosen seq one face is missing, the red one. For other choices of seq one might even see only one face drawn. How do I force to have all faces shown?
L = RootSystem(["A",3,1]).ambient_space()
P = RootSystem(["A",3,1]).weight_space(extended=True)
Lambda = P.fundamental_weights()
W = L.weyl_group()
W0=W.classical()
plot_options = L.plot_parse_options()
seq=[2,3,1,2]
t = 1*Lambda[1]-1*Lambda[2]+1*Lambda[3]
Alcoves=[W.from_reduced_word(w.reduced_word()) for w in W0]
p = L.plot_fundamental_chamber("classical")
p += L.plot_fundamental_weights()
p += L.plot_alcoves(alcoves=Alcoves, wireframe=True)
p += L.plot_alcoves(alcoves=[W.from_reduced_word(seq)])
p += L.plot_alcoves(alcoves=[W.from_reduced_word([])])
p += plot_options.family_of_vectors({t: L(t)})
p.show(frame=False)oloidThu, 07 Feb 2019 09:08:34 -0600http://ask.sagemath.org/question/45354/show all view with same x size of Hanoi's Towershttp://ask.sagemath.org/question/45084/show-all-view-with-same-x-size-of-hanois-towers/
Hi
I did this little program to visualize all Hanoi's Towers steps in Jupyter Notebook sagemath 8.4 ,W10.
why my x-axis is not always the same width size in each view?
figsize=[figSizeXmax,figSizeYmax] does not seem to work.
how can I manage to get the same x length for each graph ?
[Code On Cocalc.com](https://cocalc.com/projects/9c478dc8-084a-43b6-aedc-e027b42adfa8/files/HanoiTower.ipynb?session=default)ortolljThu, 17 Jan 2019 13:19:37 -0600http://ask.sagemath.org/question/45084/Can't display figureshttp://ask.sagemath.org/question/44953/cant-display-figures/hello,
i installed Sage on a new computer this morning,
but i can't display any figures.
That's the error i get :
> /home/xxx/Documents/SageMath/local/lib/python2.7/site-packages/sage/\
repl/rich_output/display_manager.py:592: RichReprWarning: Exception in
_rich_repr_ while displaying object: libtk8.6.so: cannot open shared
object file: No such file or directory
RichReprWarning,
Graphics object consisting of 1 graphics primitive
Anyone got an idea why?
i'm using the notebook of sagemaths
Thanks.tommeTue, 08 Jan 2019 05:15:39 -0600http://ask.sagemath.org/question/44953/What is meant by "graphics primitive" in the sage documentation?http://ask.sagemath.org/question/44100/what-is-meant-by-graphics-primitive-in-the-sage-documentation/ I'm currently learning sage, and I keep seeing the phrase, "graphics primitive" mentioned in the manual, but I'm not quite sure what is meant by that. The closest thing I've found to a definition of it is on the page "Plotting Primitives" where it is defined as "things that know how to draw themselves in 2D". Does this just mean that a primitive is anything predefined by sage, like circles and lines? Also, are there only "graphics primitives" and not any other kind?FubwubsSat, 27 Oct 2018 18:35:38 -0500http://ask.sagemath.org/question/44100/graph vertex labellinghttp://ask.sagemath.org/question/42892/graph-vertex-labelling/I have a graph (poset actually) that has a rational function labelling each vertex. I would like to show just the edges and the vertex labels. If I try to set `vertex_shape='None'` I get a crash deep in matplotlib. If I try anything else I get the marker symbol printed over the label. For example
P = RootSystem(['A',3]).root_poset()
P.show(vertex_color='white')
Will show the graph with circles over the labels. If I shrink the labels, then the edges cover the labels.
If I do
P = RootSystem(['A',3]).root_poset()
P.show(vertex_color='white', vertex_shape='None')
there is a strange crash.deinstTue, 10 Jul 2018 12:11:12 -0500http://ask.sagemath.org/question/42892/Show3d has no partition optionhttp://ask.sagemath.org/question/42820/show3d-has-no-partition-option/ `graph.show(partition = Pi)` works but `graph.show3d(partition =Pi)` doesn't. Is this something that might be fixed in the future? Or is there a workaround? Bjørn Kjos-HanssenWed, 04 Jul 2018 02:19:18 -0500http://ask.sagemath.org/question/42820/Display a graphics object with multiple primativeshttp://ask.sagemath.org/question/42106/display-a-graphics-object-with-multiple-primatives/ I'm trying to show how a set of lines changes with a matrix transformation. The part i am having trouble with is:
g=Graphics()
for c in range(10):
g.add_primitive(parametric_plot(B*vector([x,c]) , (x, 0, 2*pi)))
show(g)
Because it doesn't plott the lines like i wanted but instead gives me
> 'Graphics' object has no attribute 'options'ionsmeFri, 20 Apr 2018 15:02:29 -0500http://ask.sagemath.org/question/42106/Graphics not plotted in same plot?http://ask.sagemath.org/question/41925/graphics-not-plotted-in-same-plot/I'm trying to make a sierpinsky triangle recursively, and i can generate all the triangles (via 3 line segments), however when i go to show my list, the graphics print separately. I saw on the documentation there's a graphics_array, which seems useful, but there weren't many examples and my tinkering with it was pretty much useless, especially since the "adjoin" feature is not yet implemented.
Also tried passing the graphics object "some_lines" to get filled by the function, but it doesn't seem like it accesses the reference. Code attached, maybe you can see a way I can plot all the lines within one sum of graphics, as was my initial attempt:
def draw_tri(some_lines, endpts):
some_lines+=line([endpts[0], endpts[1]], color='blue')
some_lines+=line([endpts[0], endpts[2]], color='blue')
some_lines+=line([endpts[1], endpts[2]], color='blue')
return
def get_mid(x,y):
return (x+y)/2
def recurse_SG(some_lines, n, endpts):
#graphics_sum = graphics_array([line([endpts[0], endpts[1]], color='blue')],3, 1)
if(n==1):
#graphics_sum[i]=draw_tri(endpts)
draw_tri(some_lines, endpts)
else:
recurse_SG(some_lines, n-1, [endpts[0], (get_mid(endpts[0][0], endpts[1][0]), get_mid(endpts[0][1], endpts[1][1])), (get_mid(endpts[0][0], endpts[2][0]), get_mid(endpts[0][1], endpts[2][1]))])
recurse_SG(some_lines, n-1, [endpts[1], (get_mid(endpts[1][0], endpts[0][0]), get_mid(endpts[1][1], endpts[0][1])), (get_mid(endpts[1][0], endpts[2][0]), get_mid(endpts[1][1], endpts[2][1]))])
recurse_SG(some_lines, n-1, [endpts[2], (get_mid(endpts[2][0], endpts[0][0]), get_mid(endpts[2][1], endpts[0][1])), (get_mid(endpts[2][0], endpts[1][0]), get_mid(endpts[2][1], endpts[1][1]))])
show(some_lines, axes=false)Luther13Sun, 08 Apr 2018 20:08:27 -0500http://ask.sagemath.org/question/41925/MatrixPlots with cell entrieshttp://ask.sagemath.org/question/41234/matrixplots-with-cell-entries/ Is there a nice way to combine `MatrixPlot` with something else to have a label in each cell such as in this picture?
![image description](https://i.stack.imgur.com/bgNdN.png)jepstraThu, 22 Feb 2018 11:19:50 -0600http://ask.sagemath.org/question/41234/Plotting in Sagehttp://ask.sagemath.org/question/41250/plotting-in-sage/I have some numbers in two separate arrays, and I want to plot them in such a way that the end result looks more or less like this:
![image description](/upfiles/15194978051374454.png)
Currently, I have a code that looks like this:
res_blue = [...] # data for the blue circles (removed for brevity)
res_red = [...] # data for the red crosses (removed for brevity)
list_plot(res_red, color='red')
But, instead the above code generates only plot with red dots. How can I combine the two arrays in the same plot, choose their color and the shape to be put in the plot?ninhoSat, 24 Feb 2018 12:46:39 -0600http://ask.sagemath.org/question/41250/Plot/Show Png/jpg in sagemath worksheethttp://ask.sagemath.org/question/40501/plotshow-pngjpg-in-sagemath-worksheet/Hello every one, I am testing sagemath for course creation. What is the fastest way to embeed png pictures and diplay them? Something like this: https://paper.dropbox.com/doc/Ubung-Lagebeziehung-Gerade-Gerade-NiPkMCucw7FeDxj15u6aZ?_tk=share_copylink thethaSat, 06 Jan 2018 09:44:00 -0600http://ask.sagemath.org/question/40501/How can i sketch the graph in sage?http://ask.sagemath.org/question/39894/how-can-i-sketch-the-graph-in-sage/ I can't add a picture but i can be described we want to sketch coordinate system in sage and we want to combine with emoji it looks like smiling face eyes should be circle mouth should be triangle who can help to us?selinkirisFri, 01 Dec 2017 10:48:47 -0600http://ask.sagemath.org/question/39894/Can I import a graphic and add to it?http://ask.sagemath.org/question/39285/can-i-import-a-graphic-and-add-to-it/One of my collaborators has made an image of some regions, and now my job is to superimpose a plot on it. So I would like to do something like the following:
pic = load('pic.png')
pts = list_plot(points)
fig = pic + pts
fig.show()
However, I get the error:
IOError: [Errno 2] No such file or directory:
'pic.png.sobj'
Is there a way to get around this, or perhaps convert my png to a sobj? (The path to the file is correct.)diana.davisThu, 26 Oct 2017 14:05:01 -0500http://ask.sagemath.org/question/39285/Sage for win 10 graphics brokenhttp://ask.sagemath.org/question/39207/sage-for-win-10-graphics-broken/I installed Sage 8 native winstall into windows 10, and all graphics plots just give me the broken graphics icon. It works with Sage for Ubuntu on the same windows so it's not my graphics system, IMHO.
Okay, the problem seems to be with Jupyter. If I start the shell from Windows instead, then Sage, then the notebook() for sagenb, the graphics work fine and are very fast. That starts a bash shell, though. Oddly, I have Ubuntu for Windows, ran Sage from that bash shell and it's still slower than the sagenb from the bash shell installed by the windows install. So I guess I'll just run that.cybervigilanteWed, 18 Oct 2017 22:03:02 -0500http://ask.sagemath.org/question/39207/how to plot a circle (without circle())http://ask.sagemath.org/question/38889/how-to-plot-a-circle-without-circle/ Hello,
I know you can plot a circle with circle(x,y,radius), but how do you do it with plot()?germacWed, 20 Sep 2017 15:43:54 -0500http://ask.sagemath.org/question/38889/How to generate graphs random geometric shapes?http://ask.sagemath.org/question/38484/how-to-generate-graphs-random-geometric-shapes/ I would like to create practice problems, rather than reusing old exam questions, to help my students practice solving geometric problems. I would like to use sagetex to produce random variations similar the questions I have listed below. I would supply examples of the pictures, but I do not have enough points to post pictures.
I am wish to be able to make one worksheet where each time it is printed, the values would be randomly assigned and graph would be produced. I know how to assign a random integer value to a variable; however, how to produce the graphs I have no understanding of how to achieve that. Thus for each of the example problems how to make the graph and how to assign the random variability to that graph.
**Example questions**
*The diagram below shows a child’s toy which is made up of a circular hoop, centre O, radius 7 cm. The hoop is suspended in a horizontal plane by three equal strings XA, XB, and XC. Each string is of length 25 cm. The points A, B and C are equally spaced round the circumference of the hoop and X is vertically above the point O.*
- Calculate the length of XO.
- Find the angle, in degrees, between any string and the horizontal plane.
- Write down the size of angle AOB
- Calculate the length of AB.
- Find the angle between strings XA and XB.
*ABCDV is a solid glass pyramid. The base of the pyramid is a square of side 3.2 cm. The vertical height is 2.8 cm. The vertex V is directly above the centre O of the base.*
- Calculate the volume of the pyramid
- The glass weighs 9.3 grams per cm^3. Calculate the weight of the pyramid.
- Show that the length of the sloping edge VC of the pyramid is 3.6 cm
- Calculate the angle at the vertex, BVC
- Calculate the total surface are of the pyramid.
LaoshiSun, 06 Aug 2017 03:20:11 -0500http://ask.sagemath.org/question/38484/Transparency option in streamline plothttp://ask.sagemath.org/question/37728/transparency-option-in-streamline-plot/In most graphics functions it's possible to set the transparency of the plot with the `alpha` option. In a streamline plot, e.g. take
sage: var('x, y')
sage: streamline_plot((y, -x**2 * y - x + y), (x, -3, 3), (y, -3, 3), density=1.4, color='black')
it doesn't work:
sage: var('x, y')
sage: streamline_plot((y, -x**2 * y - x + y), (x, -3, 3), (y, -3, 3), density=1.4, color='black', alpha=0.5)
...
WARNING: Ignoring option 'alpha'=0.500000000000000
...
Is there a workaround for this?
mforetsMon, 29 May 2017 08:20:26 -0500http://ask.sagemath.org/question/37728/Does there exist a GUI web-app that allows for edge contractions and vertex splits?http://ask.sagemath.org/question/35825/does-there-exist-a-gui-web-app-that-allows-for-edge-contractions-and-vertex-splits/I am interested in creating a web-app that allows for graph creation, edge contraction, vertex splits, and then exports to sage.
If anyone knows of something like this already developed please let me know, otherwise any suggestions on how to begin?
ThanksfieldofnodesWed, 30 Nov 2016 11:29:51 -0600http://ask.sagemath.org/question/35825/Drawing Auslander-Reiten quivers with sage possible?http://ask.sagemath.org/question/35638/drawing-auslander-reiten-quivers-with-sage-possible/Hi,
I'd like to draw an Auslander-Reiten quiver with sage. I tried to do this by viewing the Auslander-Reiten quiver as a digraph, but, unfortunately, I was not able to find out how to let sage draw both dashed and solid arrows in one digraph.
Is this possible? If not, is there another way to let sage draw Auslander-Reiten quivers?
Any help would be appreciated.
Edit:
I used the following code:
sage: H=DiGraph()
sage: H.add_edges([(2,1),(2,4),(10,4),(1,3),(4,3),(4,11),(11,6),(3,6),(3,5),(5,7),(6,7),(6,12)])
sage: H.add_edges([(7,8),(7,9),(12,9)])
After having typed
sage: H.show()
a few times I got the following output:
![pic1](/upfiles/1479480509763302.png)
Now, I'd like to draw dahed arrows indicating the Auslander-Reiten translates (e.g. a dashed arrow from 3 to 2).BernFri, 18 Nov 2016 07:49:43 -0600http://ask.sagemath.org/question/35638/Is it possible to embed a plot (or png) within another plot?http://ask.sagemath.org/question/34998/is-it-possible-to-embed-a-plot-or-png-within-another-plot/I have looked at the documentation for 2d plots without any success. I would like to know if it is possible to embed a plot within a plot.
I currently have a set of polygons and I would like to have plots of graphs embedded into each region. Something resembling the attached [image](/upfiles/14752402076305906.png).
Is it possible to achieve this using sagemath's plotting interface?
Thanks!fidbcFri, 30 Sep 2016 07:58:10 -0500http://ask.sagemath.org/question/34998/How to see graph directly after plot() via virtualbox?http://ask.sagemath.org/question/33845/how-to-see-graph-directly-after-plot-via-virtualbox/My laptop is windows7, so I use virtualbox as instructed on the Wiki. However, when I try the plot(), the sage always tell me that "launched png viewer for Graphics object consisting of XX primitives", and so far the only way I can see the image is to save the .png graph somewhere, which is inconvenient. I've seen on Mac that the graph directly popped out after plotting, so is there anyway to let virtualbox to do so?yshuidieSat, 18 Jun 2016 03:07:47 -0500http://ask.sagemath.org/question/33845/Graphics array formattinghttp://ask.sagemath.org/question/33562/graphics-array-formatting/ I'm computing a number of plots (actually collections of 2d polygons) of roughly square aspect ratio, and would like to display them in a reasonable way:
* use two columns
* preserve order
* title each of them
* adjust the size to fill the width of my notebook, disregarding the height
First I displayed each graphics as it arrived, or combined bunches of them into `graphics_array` in order to show them. But my sage notebook (the classical one, not the IPython flavor) failed to preserve order in that case. So I feel that I have to build one big `graphics_array`.
But I've got trouble adjusting its width without specifying its height, and I don't know a suitable height up front. Most of the times if I specify one of the sizes too large, I end up with lots of empty space in one of the directions.
Furthermore, I didn't manage to title the individual graphics, since a `title` attribute to the `polygon2d` call remains without effect, while a `title` attribute to the `show` affects the whole plot and all the nested plots. Constructing an empty `Graphics(title="foo")` doesn't seem to work.
This is on sage 6.10.beta4, so things might have improved since then. If so, I haven't yet found the appropriate locations in the online documentation indicating how this changed.
If you want to try this out: I wanted to format the output of [this code](https://gist.github.com/gagern/e9606b3f12d53ff92c4541e1e7b51d6d) but using two columns and a varying number of rows for each *n*.MvGThu, 26 May 2016 18:41:11 -0500http://ask.sagemath.org/question/33562/Drawing all paths from (0, 0) to (n, n) moving one unit right or uphttp://ask.sagemath.org/question/33201/drawing-all-paths-from-0-0-to-n-n-moving-one-unit-right-or-up/This question is just the same as [this one](http://mathematica.stackexchange.com/questions/112395/how-to-draw-all-paths-from-1-1-to-n-n-by-move-1-0-or-0-1) made for Mathematica. I saw it and I was trying to reproduce it in Sage just for fun, but it's getting longer than I like and I would love to know your approach in Sage. I think it's a great way to learn. This is half of my try:
n=3
A=sum(line([(j, i), (n, i)]) for j in range(n+1) for i in range(n+1))
B=sum(line([(i, j), (i, n)]) for j in range(n+1) for i in range(n+1))
G = Graphics()
G += A + B
G.show(figsize=[4,4], axes=False)
result = []
combinations = [bin(i)[2:] for i in range(1, int('111111', 2))]
for num in combinations:
valid = ''.join(['0']*(6-len(num))) + num
zeros = valid.count('0')
ones = valid.count('1')
if zeros == 3 and ones == 3:
result.append(str(valid))
#At this point all the paths are stored in the variable 'results' in binary form.
#For example '010101' means right, left, right, left, right, left
paths = [[]]
for element in result:
path = []
for index, direction in enumerate(list(element)):
if direction == '0':
path.append((index, index - 1))
else:
path.append((index - 1, index))
paths.append(path)
At this point the list of list called paths is not well constructed. I realized I would have to put some `if` statements to make it work but I'm losing motivation in my solution because it's getting ugly and I don't think is very efficient.
How would you do it?
TARSFri, 22 Apr 2016 22:08:30 -0500http://ask.sagemath.org/question/33201/