So this problem was given as an end of the class quiz. I didnt have time to test it out so I tried re-writting it and testing. However for some reason its not working the way I want it and I dont know why.  So you've got a nxn grid given as lists. A robot with an initial starting point given as a tuple. And the path the robot will travel given as "N", "S", "E", "W" within a list.  so input would be something like  make_grid(starting_point, path, size_of_grid) make_grid((0,0),["S","E","S","S"],4)   with an output like  [".","_","_","_"],[".",".","_","_"],["_",".""_""_"],["_",".""_""_"]   where the "." is the robots starting point and traveled path. The "_" are the untraveled areas of the grid. And if it hits the border it stays in the exact same spot. My problem is the result is that it marks the whole column as a traveled path with a period   def check(coord ,size):     if ((coord&lt;0) or (coord&gt;size)):         return True     else:         return False   def make_grid(start, path, size):     n = 0     row = []     while (n &lt; size):         row.append("_")         n += 1     n = 1     grid = [row]     while ( n &lt; size):         grid.append(row)         n +=1      x = start[0]     y = start[1]      grid[x][y] = "."      n = 0     while (n &lt; len(path)):         if (path[n] == "N"):             x -= 1             if (check(x,size)):                 x += 1         elif (path[n] == "E"):             y += 1             if (check(y,size)):                 y -= 1         elif (path[n] == "S"):             x +=1             if (check(x,size)):                 x -=1         elif (path[n] == "W"):             y -=1             if (check(y,size)):                 y += 1         grid[x][y] = "."         n += 1      n = 0     while (n &lt; size):         print grid[n]         n += 1
410
I needed to create a list of lists in Python, so I typed the following: my_list = [[1] * 4] * 3  The list looked like this: [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]    Then I changed one of the innermost values: my_list[0][0] = 5  Now my list looks like this: [[5, 1, 1, 1], [5, 1, 1, 1], [5, 1, 1, 1]]    which is not what I wanted or expected. Can someone please explain what's going on, and how to get around it?
12824
I've been having a problem with these problems for a week now so I thought I'd post it on MSE. Read the text below. . I've also typed it up:  Annabel made a shape by placing identical square tiles in a frame as shown in the diagram above. The tiles are arranged in columns. Each column touches the base but no columns touch the side or top. There are no empty gaps between columns. The frame can be enlarged as needed.  These are the questions. I've also typed them up.    A. Show that it is possible to arrange $7$ tiles so that the ant walks $8,9,10,11,12,13,14,15$ tile edges.   B. Show 6 ways of arranging 7 tiles so that the ant walks a total of 9 tile edges.  C. Show it is possible to arrange 49 tiles so that the ant walks a total of less than 21 tile edges.  D. Show four arrangements of 137 tiles, each arrangement with a different maximum height, so that the ant walks a total of 34 tile edges.  For question $a$, is there a formula relating the number of tile edges exposed to the number of tiles. These are my answers for $a$    For the above picture, it's the left hand side which has the $a$ answers.  However, I'm having a bit of trouble with $b$. I've already got four answers down but where are the other two. My four current answers are in the right hand side of the last image. Also, I'll also appreciate a formula to show the relationship.  I'm also having trouble with $c$. I found out that you get 21 tile edges exposes when you make a $7*7$ square but the answer is asking for less than 21. Can anyone help me. Also, as in the previous questions, a formula to show the relationships would be great.  And for $d$, I am totally lost. I have no idea where to start, and I certainly can't find out four arrangements. So can anyone help me? And as always, a formula is nice  P.S. Please explain this in an understandable formula, as I'm only a Year 7 with the ability to understand linear algebra and parts of quadratics and trigonometry. Also, sorry about the poor imaging.
101984
I am iterating over a list and I want to print out the index of the item if it meets a certain condition. How would I do this?  Example:    testlist = [1,2,3,5,3,1,2,1,6] for item in testlist:     if item == 1:         print position
106641
How do I format a list of questions like this?     I'm getting the equation on a new line below the i) when using enumerate and \list.  I don't want to get rid of \[ and \] either as I like the long integral sign  I get this instead:
67560
I am stuck on the 4 th one.I have done the rest.I have found out the value of a_n.But not getting how to proceed for the 4 th one.
62595
i am writing script which uses different Tools of arcgis and implementing different functionalities .. My script consists in different Functions running in an order. Each function is connected to each other , and works on layers and performs   functions like(update cursor, search cursor ) When function1 finishes execution funciton2 starts and works on the same layer on which first one was working.   The problem is here function2 generates wrong results or works wrong.  works wrong means if a loop is defined to 5 iterations it will runs more then 5 times. like 20, 30 times and generates different results of one value.  When i run each function separately it will works fine. but when i run function in one script it will create problems.  My findings of this are LOCKS which are creating the problem.  Sample Structure of my script:  import arcpy   import math   import sys     import traceback     from arcpy import env    class test:       def __init__(self, workSpace):          self.workSpace = workSpace        # Add Fields       def function1(self):             # Script               return;           # Generate Report       def function2(self):              # Script            rows = arcpy.SearchCursor(self.mapLayerFinal,"","","Shape_Area")           row = rows.next()           while row:                   area = row.Shape_Area                     print "function2"                         destination_cursor = arcpy.UpdateCursor(self.censusLayer, '"DISTRICT_ID" = '+ str(district_id))                   row1 = destination_cursor.next()                   while row1:                           row1.setValue("District_Area",area)                           destination_cursor.updateRow(row1)                            row1 = destination_cursor.next()                    row = rows.next()             return;        t = test(workSpace)   t.function1()   t2 = test(workSpace)   t2.function2()     NOTE: code is tested and working correct if each function is executed separately
95450
Here is the minimum working example:  \documentclass{article} \usepackage{tikz} \usepackage{float} \usepackage{listings} \usepackage{color} \usepackage{textcomp} \usetikzlibrary{shapes,positioning} \begin{document} \centering \begin{tikzpicture}   \node[draw] (PersonLocation Graph) {     \begin{minipage}{.85\linewidth} \begin{lstlisting}[language=XML,escapechar=!]   &lt;collection name=PersonLocation BiMap&gt;   &lt;edge&gt;    &lt;ref&gt;//collection[name=Locations]/loc[name=XXYY]   ! \tikz \node[shape=circle,draw](srchead) {H};!   &lt;/ref&gt;   &lt;ref&gt;//collection[name=Persons]/person[id=4564]   ! \tikz \node[shape=circle,draw](deshead) {E};      %(srchead) edge[&lt;-&gt;, bend left] (deshead.south);    !     &lt;/ref&gt;    &lt;/edge&gt;   ...   ...   ...   &lt;/collection&gt; \end{lstlisting} \end{minipage}  }; \end{tikzpicture} \end{document}   I want to draw an edge from node H to E. I tried  using statement srchead) edge[&lt;->, bend left] (deshead.south); (commented out in the code). Thanks in advance for your input.
46747
Suppose we write each number from $1$ to $n^2$ in an $n\times n$ grid exactly once. Prove there are two adjacent cells such that the absolute value of their difference is not less than $n$.   I think it should be a pigeonhole problem, but the work I did so far was basic observations like if we assume all differences are less than $n$, then neither of $1,2,\dots,2n-2$ could be in the row or the column $n^2$ is placed.  Any hints would be appreciated.
107943
I've looked to another example but struggle to adapt it to my needs. Tikz is new to me.    \begin{center}   \begin{tikzpicture}[every edge/.style={shorten &lt;=1pt, shorten &gt;=1pt}]   \draw (0,0)  node [below] {0} -- (1,0) node [below] {1};   % draw the tick marks   \coordinate (p) at (0,2pt);   \foreach \myprop/\mytext [count=\n] in {0.06/$p_1$,0.06/$p_2$,0.06/$p_3$,0.06/$p_4$,0.06/$p_5$,0.15/$p_6$,0.13/$p_7$,0.14/$p_8$,0.15/$p_9$,0.13/$p_10$}   \draw [decorate,decoration={brace,amplitude=2}] (p)  edge [draw] +(0,-4pt) -- ++(\myprop,0) coordinate (p) node [midway, above=2pt, anchor=south] {\mytext} ;   \path (1,2pt) edge [draw]  ++(0,-4pt); \end{tikzpicture} \end{center}     Latex squeeze all the values together instead of spreading them over the 0 to 1 axis.
30438
I am trying to proof the following algorithm to see if a there exists a path from u to v in a graph G = (V,E).   Reach := {u} LastCardinality := 0 while LastCardinality &lt; |Reach| do   LastCardinality := |Reach|   Next := null   foreach i &lt;- Reach do     foreach j &lt;- V do       if(i,j) exists in E then         Next := Next + {j}   Reach := Reach + Next return Reach   So far I have got that the output needs to be Reach = Goal where Goal = {r | r exists V, there is a path from u to r}. I also have three invariants that I am pretty sure will help prove this.   Reach is always a subset of Goal and Next is always a subset of Goal. After an arbitrary K times through the while loop, for every t that exsits in V, if t has a path of length k+1 from u, then t exists in Reach If Reach is a subset of Goal before the while loop then LastCardinality &lt; |Reach|   I know that to finish up the proof, I need to prove termination, the invariants, and correctness but I have no idea how. I think I need to use induction on the while loop but I am not exactly sure how.   How do I proof those three characteristics about an algorithm?
58979
\documentclass[border=10pt]{standalone} \usepackage{pstricks-add,amsmath,amssymb} \begin{document} \begin{pspicture}[showgrid,arrowinset=0](0,-1)(4,2) \begin{psmatrix}[colsep=.5cm,rowsep=1.2cm] &amp; [name=A]\,\,\,\,\,\,\,\,\,\,\,\,$M_{0,4} \times \mathbb{P}^1 $\\ [name=B]$B$ &amp; [name=C]\,\,\,\,\,\,$M_{0,4}$ \end{psmatrix} \pcline[nodesep=.3]{-&gt;}(B)(C)       \nbput{$\kappa$} \pcline[nodesep=.3]{-&gt;}(A)(C)       \nbput[labelsep=.1]{$\pi$} \naput{\foreach \i in {0.1,0.25,0.4,0.55}{%     \pcline{-&gt;}(\i,-.4)(\i,.45)} \nbput[labelsep=.1]{$\sigma_i$}} \end{pspicture} \end{document}     After see all the answers, done :)   \documentclass[border=10pt]{standalone} \usepackage{pstricks-add,amsmath,amssymb} \begin{document} \begin{psmatrix}[colsep=.5cm,rowsep=1.2cm] &amp; [name=A]\qquad $M_{0,4} \times \mathbb{P}^1 $\\ [name=B]$B$ &amp; [name=C] \quad $M_{0,4}$ \end{psmatrix} \psset{arrowinset=0} \pcline[nodesep=.3]{-&gt;}(B)(C)       \nbput{$\kappa$} \pcline[nodesep=.3]{-&gt;}(A)(C)       \nbput[labelsep=.1]{$\pi$} \naput{\foreach \i in {0.1,0.25,0.4,0.55}{%     \pcline{-&gt;}(\i,-.4)(\i,.45)} \nbput[labelsep=.1]{$\sigma_i$}} \end{document}
113163
\documentclass[margin=5pt]{standalone} \usepackage{tikz} \usetikzlibrary{shapes,calc} \begin{document} \begin{tikzpicture}  \foreach \x [evaluate=\x as \name using \x*20] in{0,0.05,0.1,0.15,...,5}    \node(\name)[regular polygon, regular polygon sides=12,inner sep=0pt,minimum size=\x cm]{};  \node at(1){test}; \end{tikzpicture} \end{document}   I get an error saying that there is no shape named "1". The loop works fine (if you add a "draw" option the 12-polygons show up) except for the evaluating part.  edit: I just discovered that 0.05*20 yields 1,00006 instead of 1, so it cannot find a node named 1. Why is that? How can I get 1 from 0,05*20?
72069
Given [1,2,3,4,5], how can I do something like   1/1, 1/2, 1/3,1/4,1/5, ...., 3/1,3/2,3/3,3/4,3/5,.... 5/1,5/2,5/3,5/4,5/5   I would like to store all the results, find the minimum, and return the two numbers used to find the minimum. So in the case I've described above I would like to return (1,5).  So basically I would like to do something like  for each element i in the list map some function across all elements in the list, taking i and j as parameters store the result in a master list, find the minimum value in the master list, and return the arguments i, jused to calculate this minimum value.  In my real problem I have a list objects/coordinates, and the function I am using takes two coordinates and calculates the euclidean distance. I'm trying to find minimum euclidean distance between any two points but I don't need a fancy algorithm.
24989
I am sorry...as there are too many articles about it.But I can't simple get this.  I am confused in the implementation of AI. I have generated all possible moves of computer's type pieces. Now I can't decide the flow. Whether I need to start a loop for the possible moves of each piece and assign score to it.... or something else is to be done.  Kindly tell me the proper flow/algorithm for this. Thanks    UPDATE:    Now I coded the algorithm but not getting correct moves. Please help me find out the logical error.
38568
Just wanted to share a nice problem.I have given my method below.More answers are welcome.  Consider a rectangular integral grid of size $m*n$.A person has to travel from one end say $(0,0)$ to the diagonally opposite end $(m,n)$.He moves one step at a time towards the east or towards the north(that is,never moves towards the west or south at any time).How many distinct paths exist from the point A to the point C ?
108627
I am just starting to learn using Tikz and am a little lost within its seemingly infinite amount of options and possibilities.  What I am trying to do is visualize a few Matlab function interaction (which one calls which one, what is the in- and output). Since there are only about six subroutines, I place each one manually as a node. This is an example:  \documentclass{article} \usepackage{tikz} \usetikzlibrary{shapes,positioning}  \begin{document}  \begin{tikzpicture}[auto] \node           [rounded rectangle,draw]        (node1)     {Node 1}; \coordinate [above=of node1]                                (input); \node           [rounded rectangle,draw]    at  (-10:6cm) (node2)       {Node 2}; \draw           [-&gt;,very thick]             ([xshift=0.1cm]  input.south)  --                  node {right}                ([xshift=0.1cm]  node1.north); \draw           [-&gt;,very thick]             ([xshift=-0.1cm] node1.north) --                  node {left}                 ([xshift=-0.1cm] input.south); \draw                                            (node1) -- (node2);  \end{tikzpicture}  \end{document}     Now I would like to apply these double in/out arrows I (probably pretty awkwardly) created using xshift to all node connections, so in this example also for the connection between Node 1 and Node 2. Ideally, the space between these two arrows would be the same, independant of their angle and they would nicely connect to the outer line of the nodes. Any idea how I could achieve this? Similar questions I have found only used rectangle and orthogonal lines.
17123
Show that $n$ lines separate the plane into  $\frac{n^2+n+2}{2}$ regions if no two of these lines are parallel and no three pass through a common point.   I know we start with the base case, where, if we call the above equation P(n), P(0), for 0 lines would be 0.  But I really have no idea how to begin the inductive step.  How do we know what k+1 we're supposed to arrive at?  Thanks!