Prevent replacing of single variable expressions in sympy.cse - python-3.x
I want extract and replace common expressions in a set of equations using sympy.cse
When I run sympy.cse(eqs) I get the results below. How can I prevent sympy.cse to extract single variables eg. replacing S2_comp3 with -x0. (I have noticed that all these single variables are their negative)
result
([(x0, -S2_comp3),
(x1, -S_source_comp3),
(x2, S_source_total/S1_total),
(x3, -S_source_comp1),
(x4, -S_source_comp2),
(x5, -S_source_comp4),
(x6, -S2_comp1),
(x7, -S2_comp2)],
[S2_comp3*eff_c3 - S6_comp3,
S6_comp3 + S9_comp3 + x0,
S1_comp3 + S2_comp3 + S3_comp3 + S4_comp3 + x1,
S1_comp3*x2 + x1,
S1_comp1*x2 + x3,
S1_comp2*x2 + x4,
S1_comp4*x2 + x5,
-S1_comp1 - S1_comp2 - S1_comp3 - S1_comp4 - S1_comp5 + S1_total,
S1_comp1 + S2_comp1 + S3_comp1 + S4_comp1 + x3,
S2_comp1*eff_c1 - S6_comp1,
S6_comp1 + S9_comp1 + x6,
S1_comp2 + S2_comp2 + S3_comp2 + S4_comp2 + x4,
S2_comp2*eff_c2 - S6_comp2,
S6_comp2 + S9_comp2 + x7,
S1_comp4 + S2_comp4 + S3_comp4 + S4_comp4 + x5,
-S2_comp4 - S2_comp5 + S2_total + x0 + x6 + x7,
S1_comp5 + S2_comp5 + S3_comp5 + S4_comp5 - S_source_comp5])
With
eqs = [S2_comp3*eff_c3 - S6_comp3,
-S2_comp3 + S6_comp3 + S9_comp3,
S1_comp3 + S2_comp3 + S3_comp3 + S4_comp3 - S_source_comp3,
S1_comp3*S_source_total/S1_total - S_source_comp3,
S1_comp1*S_source_total/S1_total - S_source_comp1,
S1_comp2*S_source_total/S1_total - S_source_comp2,
S1_comp4*S_source_total/S1_total - S_source_comp4,
-S1_comp1 - S1_comp2 - S1_comp3 - S1_comp4 - S1_comp5 + S1_total,
S1_comp1 + S2_comp1 + S3_comp1 + S4_comp1 - S_source_comp1,
S2_comp1*eff_c1 - S6_comp1,
-S2_comp1 + S6_comp1 + S9_comp1,
S1_comp2 + S2_comp2 + S3_comp2 + S4_comp2 - S_source_comp2,
S2_comp2*eff_c2 - S6_comp2,
-S2_comp2 + S6_comp2 + S9_comp2,
S1_comp4 + S2_comp4 + S3_comp4 + S4_comp4 - S_source_comp4,
-S2_comp1 - S2_comp2 - S2_comp3 - S2_comp4 - S2_comp5 + S2_total,
S1_comp5 + S2_comp5 + S3_comp5 + S4_comp5 - S_source_comp5]
With
var = [S6_comp3,
S2_comp3,
S9_comp1,
S2_comp1,
S2_comp5,
S1_comp1,
S2_comp4,
S1_comp4,
S1_comp2,
S9_comp2,
S6_comp1,
S1_comp3,
S1_comp5,
S9_comp3,
S2_comp2,
S6_comp2,
S1_total]
For situations like this where the return value is not as you like it, the postprocess option can be used. For example,
def noneg(r,e):
rv = []
negs = []
for i in range(len(r)):
o, n = r[i]
if (-n).is_Symbol:
for j in range(i + 1, len(r)):
oj, nj = r[j]
r[j] = oj, nj.subs(o, n)
negs.append((o, n))
else:
rv.append((o, n))
for o, n in reversed(negs):
e = [ei.subs(o, n) for ei in e]
return rv, e
>>> print filldedent(cse(your_eqs, postprocess=noneg))
([(x2, 1/S1_total)], [S2_comp3*eff_c3 - S6_comp3, -S2_comp3 + S6_comp3
+ S9_comp3, S1_comp3 + S2_comp3 + S3_comp3 + S4_comp3 -
S_source_comp3, S1_comp3*S_source_total*x2 - S_source_comp3,
S1_comp1*S_source_total*x2 - S_source_comp1,
S1_comp2*S_source_total*x2 - S_source_comp2,
S1_comp4*S_source_total*x2 - S_source_comp4, -S1_comp1 - S1_comp2 -
S1_comp3 - S1_comp4 - S1_comp5 + S1_total, S1_comp1 + S2_comp1 +
S3_comp1 + S4_comp1 - S_source_comp1, S2_comp1*eff_c1 - S6_comp1,
-S2_comp1 + S6_comp1 + S9_comp1, S1_comp2 + S2_comp2 + S3_comp2 +
S4_comp2 - S_source_comp2, S2_comp2*eff_c2 - S6_comp2, -S2_comp2 +
S6_comp2 + S9_comp2, S1_comp4 + S2_comp4 + S3_comp4 + S4_comp4 -
S_source_comp4, -S2_comp1 - S2_comp2 - S2_comp3 - S2_comp4 - S2_comp5
+ S2_total, S1_comp5 + S2_comp5 + S3_comp5 + S4_comp5 -
S_source_comp5])
Related
CS50 Pset 4 Blur | Invalide operands to binary expression
Currently working on the blur function for the Pset4 of CS50 It is a lot of text and probably not the most optimal way of doing things but I am not worried about that right now. void blur(int height, int width, RGBTRIPLE image[height][width]) { // Set blur as a RGBTRIPLE RGBTRIPLE blur[1][1]; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { // Check for corner or edge if (i == 0 && j == 0) // If top left corner { blur[i][j].rgbtBlue = (image[i][j].rgbtBlue + image[i][j + 1].rgbtBlue + image[i - 1][j].rgbtBlue + image[i - 1][j + 1].rgbtBlue) / 4; blur[i][j].rgbtGreen = (image[i][j].rgbtGreen + image[i][j + 1].rgbtGreen + image[i - 1][j].rgbtGreen + image[i - 1][j + 1].rgbtGreen) / 4; blur[i][j].rgbtRed = (image[i][j].rgbtRed + image[i][j + 1].rgbtRed + image[i - 1][j].rgbtRed + image[i - 1][j + 1].rgbtRed) / 4; } else if (i == 0 && j == (width - 1)) // If top right corner { blur[i][j].rgbtBlue = (image[i][j].rgbtBlue + image[i][j - 1].rgbtBlue + image[i - 1][j].rgbtBlue + image[i - 1][j - 1].rgbtBlue) / 4; blur[i][j].rgbtGreen = (image[i][j].rgbtGreen + image[i][j - 1].rgbtGreen + image[i - 1][j].rgbtGreen + image[i - 1][j - 1].rgbtGreen) / 4; blur[i][j].rgbtRed = (image[i][j].rgbtRed + image[i][j - 1].rgbtRed + image[i - 1][j].rgbtRed + image[i - 1][j - 1].rgbtRed) / 4; } else if (i == (height - 1) && j == 0) // If bottom left corner { blur[i][j].rgbtBlue = (image[i][j].rgbtBlue + image[i][j + 1].rgbtBlue + image[i + 1][j].rgbtBlue + image[i + 1][j + 1].rgbtBlue) / 4; blur[i][j].rgbtGreen = (image[i][j].rgbtGreen + image[i][j + 1].rgbtGreen + image[i + 1][j].rgbtGreen + image[i + 1][j + 1].rgbtGreen) / 4; blur[i][j].rgbtRed = (image[i][j].rgbtRed + image[i][j + 1].rgbtRed + image[i + 1][j].rgbtRed + image[i + 1][j + 1].rgbtRed) / 4; } else if (i == (height - 1) && j == (width - 1)) // If bottom right corner { blur[i][j].rgbtBlue = (image[i][j].rgbtBlue + image[i][j - 1].rgbtBlue + image[i + 1][j].rgbtBlue + image[i + 1][j - 1].rgbtBlue) / 4; blur[i][j].rgbtGreen = (image[i][j].rgbtGreen + image[i][j - 1].rgbtGreen + image[i + 1][j].rgbtGreen + image[i + 1][j - 1].rgbtGreen) / 4; blur[i][j].rgbtRed = (image[i][j].rgbtRed + image[i][j - 1].rgbtRed + image[i + 1][j].rgbtRed + image[i + 1][j - 1].rgbtRed) / 4; } else if (i == 0) // If top edge { blur[i][j].rgbtBlue = (image[i][j].rgbtBlue + image[i][j - 1].rgbtBlue + image[i][j + 1].rgbtBlue + image[i + 1][j - 1].rgbtBlue + image[i + 1][j].rgbtBlue + image[i + 1][j + 1].rgbtBlue) / 6; blur[i][j].rgbtGreen = (image[i][j].rgbtGreen + image[i][j - 1].rgbtGreen + image[i][j + 1].rgbtGreen + image[i + 1][j - 1].rgbtGreen + image[i + 1][j].rgbtGreen + image[i + 1][j + 1].rgbtGreen) / 6; blur[i][j].rgbtRed = (image[i][j].rgbtRed + image[i][j - 1].rgbtRed + image[i][j + 1].rgbtRed + image[i + 1][j - 1].rgbtRed + image[i + 1][j] + image[i + 1][j + 1]) / 6; } else if (j == 0) // If left edge { blur[i][j].rgbtBlue = (image[i + 1][j].rgbtBlue + image[i + 1][j + 1].rgbtBlue + image[i][j].rgbtBlue + image[i][j + 1].rgbtBlue + image[i - 1][j].rgbtBlue + image[i - 1][j + 1].rgbtBlue) / 6; blur[i][j].rgbtGreen = (image[i + 1][j].rgbtGreen + image[i + 1][j + 1].rgbtGreen + image[i][j].rgbtGreen + image[i][j + 1].rgbtGreen + image[i - 1][j].rgbtGreen + image[i - 1][j + 1].rgbtGreen) / 6; blur[i][j].rgbtRed = (image[i + 1][j].rgbtRed + image[i + 1][j + 1].rgbtRed + image[i][j].rgbtRed + image[i][j + 1].rgbtRed + image[i - 1][j] + image[i - 1][j + 1]) / 6; } else if (i == (height - 1)) // If bottom edge { blur[i][j].rgbtBlue = (image[i + 1][j].rgbtBlue + image[i + 1][j + 1].rgbtBlue + image[i + 1][j - 1].rgbtBlue + image[i][j + 1].rgbtBlue + image[i][j].rgbtBlue + image[i][j + 1].rgbtBlue) / 6; blur[i][j].rgbtGreen = (image[i + 1][j].rgbtGreen + image[i + 1][j + 1].rgbtGreen + image[i + 1][j - 1].rgbtGreen + image[i][j + 1].rgbtGreen + image[i][j].rgbtGreen + image[i][j + 1].rgbtGreen) / 6; blur[i][j].rgbtRed = (image[i + 1][j].rgbtRed + image[i + 1][j + 1].rgbtRed + image[i + 1][j - 1].rgbtRed + image[i][j + 1].rgbtRed + image[i][j] + image[i][j + 1]) / 6; } else if (j == (width - 1)) // If right edge { blur[i][j].rgbtBlue = (image[i + 1][j].rgbtBlue + image[i + 1][j - 1].rgbtBlue + image[i][j].rgbtBlue + image[i][j - 1].rgbtBlue + image[i - 1][j].rgbtBlue + image[i - 1][j - 1].rgbtBlue) / 6; blur[i][j].rgbtGreen = (image[i + 1][j].rgbtGreen + image[i + 1][j - 1].rgbtGreen + image[i][j].rgbtGreen + image[i][j - 1].rgbtGreen + image[i - 1][j].rgbtGreen + image[i - 1][j - 1].rgbtGreen) / 6; blur[i][j].rgbtRed = (image[i + 1][j].rgbtRed + image[i + 1][j - 1].rgbtRed + image[i][j].rgbtRed + image[i][j - 1].rgbtRed + image[i - 1][j] + image[i - 1][j - 1]) / 6; } else { // Calculate blur value for each RGB blur[i][j].rgbtBlue = (image[i - 1][j - 1].rgbtBlue + image[i - 1][j].rgbtBlue + image[i - 1][j + 1].rgbtBlue + image[i][j - 1].rgbtBlue + image[i][j].rgbtBlue + image[i][j + 1].rgbtBlue + image[i + 1][j - 1].rgbtBlue + image[i + 1][j].rgbtBlue + image[i + 1][j + 1].rgbtBlue) / 9; blur[i][j].rgbtGreen = (image[i - 1][j - 1].rgbtGreen + image[i - 1][j].rgbtGreen + image[i - 1][j + 1].rgbtGreen + image[i][j - 1].rgbtGreen + image[i][j].rgbtGreen + image[i][j + 1].rgbtGreen + image[i + 1][j - 1].rgbtGreen + image[i + 1][j].rgbtGreen + image[i + 1][j + 1].rgbtGreen) / 9; blur[i][j].rgbtRed = (image[i - 1][j - 1].rgbtRed + image[i - 1][j].rgbtRed + image[i - 1][j + 1].rgbtRed + image[i][j - 1].rgbtRed + image[i][j].rgbtRed + image[i][j + 1].rgbtRed + image[i + 1][j - 1].rgbtRed + image[i + 1][j].rgbtRed + image[i + 1][j + 1].rgbtRed) / 9; // Change each RGB value of pixel to blur value image[i][j].rgbtBlue = blur[i][j].rgbtBlue; image[i][j].rgbtGreen = blur[i][j].rgbtGreen; image[i][j].rgbtRed = blur[i][j].rgbtRed; } } } return; } when I compile I get this : **helpers.c:104:141: error: invalid operands to binary expression ('int' and 'RGBTRIPLE') ...image[i + 1][j].rgbtRed + image[i + 1][j - 1].rgbtRed + image[i][j].rgbtRed + image[i][j - 1].rgbtRed + image[i - 1][j]... ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~** It only shows this for the rgbtRed values when I am checking the edges I'm very confused because it compiles fine if I get rid of the statements that checks for edges. Even the ones that check for corners work fine. If you guys know what's up please help me. Thank you!
...image[i][j + 1].rgbtRed + image[i][j] + image[i][j + 1]) / 6; I believe you forgot to put .rgbtRed 's in the last lines of your 4 edge checks.
Stuck on a program in Python
I am doing an assignment for school and I just can't get past the final hurdle. I've only been doing coding for about 2 weeks and this is beyond me on how to fix. I am hoping someone here can help me in any way possible. We need to make an Eiffel Tower with Python that has an adjustable size, and we cannot use any statements we haven't learned. The only ones I know at the moment are the math operators, if, print, newlines, and basic formatting. Here are the basics of my assignment and how I've gone about it: https://imgur.com/a/e0Aas1z here is my code in python: size = int(input('Enter Eiffel Tower Size:\n')) print(' ' * ((size * 2) + (size - 1)) + '$') print(((' ' * (size * 3 - 2)) + '|Z|' + '\n') * int(size * 1.5), end='') print(' ' * ((size * 3) - (size + 2)) + '/' + 'Z' * (size * 2 + 1) + '\\') print(' ' * ((size * 3) - (size + 2)) + 'H' + ' ' * (size * 2 + 1) + 'H') print(' ' * ((size * 3) - (size + 2)) + 'H' + ' ' * (size * 2 + 1) + 'H') print(' ' * (size - 2) + '/' + '%' * (size * 4 +1) + '\\') print((' ' * (size - 3) + '##' + ' ' * (size * 4 + 1) + '##' + '\n') * int(size // 1.5), end='') print((' ' * (size - 4) + '##' + ' ' * (size * 4 + 1) + ' ##' + '\n') * int(size // 1.5)) Any number 4 or less causes my last line to become broken, and the program to print incorrectly. I'm at my wits end trying to figure this out and I don't know what else to try.
You just need to get the tower off the edge of the console. Add more space on the left for each print statement: size = 2 print(' ' * (size + (size * 2) + (size - 1)) + '$') print(((' ' * (size + size * 3 - 2)) + '|Z|' + '\n') * int(size * 1.5), end='') print(' ' * (size + (size * 3) - (size + 2)) + '/' + 'Z' * (size * 2 + 1) + '\\') print(' ' * (size + (size * 3) - (size + 2)) + 'H' + ' ' * (size * 2 + 1) + 'H') print(' ' * (size + (size * 3) - (size + 2)) + 'H' + ' ' * (size * 2 + 1) + 'H') print(' ' * (size + size - 2) + '/' + '%' * (size * 4 +1) + '\\') print((' ' * (size + size - 3) + '##' + ' ' * (size * 4 + 1) + '##' + '\n') * int(size // 1.5), end='') print((' ' * (size + size - 4) + '##' + ' ' * (size * 4 + 1) + ' ##' + '\n') * int(size // 1.5)) Output $ |Z| |Z| |Z| /ZZZZZ\ H H H H /%%%%%%%%%\ ## ## ## ##
Why does my lp file give #number for each variable?
I am using Ilog Cplex with Visual C++ 2015 to solve my problem. Generally, when I export lp file of my problem, the lp file will not contain any #number(such #0, #1, and so on) for variables. It is like this: \ENCODING=ISO-8859-1 \Problem name: IloCplex Minimize obj: Ope(1,1,1) + Ope(1,1,2) + Ope(1,1,3) + Ope(1,1,4) + Ope(1,1,5) + Ope(1,1,6) + Ope(1,1,7) + Ope(1,1,8) + Ope(1,1,9) + Ope(1,1,10) + Ope(1,1,11) + Ope(1,1,12) + Ope(1,1,13) + Ope(1,1,14) + Ope(1,1,15) + Ope(1,1,16) + Ope(1,1,17) + Ope(1,1,18) + Ope(1,1,19) + Ope(1,1,20) + Ope(1,1,21) + Ope(1,1,22) + Ope(1,1,23) + Ope(1,1,24) + Ope(1,2,1) + Ope(1,2,2) + Ope(1,2,3) + Ope(1,2,4) + Ope(1,2,5) + Ope(1,2,6) + Ope(1,2,7) + Ope(1,2,8) + Ope(1,2,9) + Ope(1,2,10) + Ope(1,2,11) + Ope(1,2,12) + Ope(1,2,13) + Ope(1,2,14) + Ope(1,2,15) + Ope(1,2,16) + Ope(1,2,17) + Ope(1,2,18) + Ope(1,2,19) + Ope(1,2,20) + Ope(1,2,21) + Ope(1,2,22) + Ope(1,2,23) + Ope(1,2,24) + Ope(2,1,1) + Ope(2,1,2) + Ope(2,1,3) + Ope(2,1,4) + Ope(2,1,5) + Ope(2,1,6) + Ope(2,1,7) + Ope(2,1,8) + Ope(2,1,9) + Ope(2,1,10) + Ope(2,1,11) + Ope(2,1,12) + Ope(2,1,13) + Ope(2,1,14) + Ope(2,1,15) + Ope(2,1,16) + Ope(2,1,17) + Ope(2,1,18) + Ope(2,1,19) + Ope(2,1,20) + Ope(2,1,21) + Ope(2,1,22) + Ope(2,1,23) + Ope(2,1,24) + Ope(2,2,1) + Ope(2,2,2) + Ope(2,2,3) + Ope(2,2,4) + Ope(2,2,5) + Ope(2,2,6) + Ope(2,2,7) + Ope(2,2,8) + Ope(2,2,9) + Ope(2,2,10) + Ope(2,2,11) + Ope(2,2,12) + Ope(2,2,13) + Ope(2,2,14) + Ope(2,2,15) + Ope(2,2,16) + Ope(2,2,17) + Ope(2,2,18) + Ope(2,2,19) + Ope(2,2,20) + Ope(2,2,21) + Ope(2,2,22) + Ope(2,2,23) + Ope(2,2,24) However, today I add some constraints to my model, the lp file gives #number to each variable. It is like this: \ENCODING=ISO-8859-1 \Problem name: IloCplex Minimize obj: Ope(1,1,1)#0 + Ope(1,1,2)#1 + Ope(1,1,3)#2 + Ope(1,1,4)#3 + Ope(1,1,5)#4 + Ope(1,1,6)#5 + Ope(1,1,7)#6 + Ope(1,1,8)#7 + Ope(1,1,9)#8 + Ope(1,1,10)#9 + Ope(1,1,11)#10 + Ope(1,1,12)#11 + Ope(1,1,13)#12 + Ope(1,1,14)#13 + Ope(1,1,15)#14 + Ope(1,1,16)#15 + Ope(1,1,17)#16 + Ope(1,1,18)#17 + Ope(1,1,19)#18 + Ope(1,1,20)#19 + Ope(1,1,21)#20 + Ope(1,1,22)#21 + Ope(1,1,23)#22 + Ope(1,1,24)#23 + Ope(1,2,1)#24 + Ope(1,2,2)#25 + Ope(1,2,3)#26 + Ope(1,2,4)#27 + Ope(1,2,5)#28 + Ope(1,2,6)#29 + Ope(1,2,7)#30 + Ope(1,2,8)#31 + Ope(1,2,9)#32 + Ope(1,2,10)#33 + Ope(1,2,11)#34 + Ope(1,2,12)#35 + Ope(1,2,13)#36 + Ope(1,2,14)#37 + Ope(1,2,15)#38 + Ope(1,2,16)#39 + Ope(1,2,17)#40 + Ope(1,2,18)#41 + Ope(1,2,19)#42 + Ope(1,2,20)#43 + Ope(1,2,21)#44 + Ope(1,2,22)#45 + Ope(1,2,23)#46 + Ope(1,2,24)#47 + Ope(2,1,1)#48 + Ope(2,1,2)#49 + Ope(2,1,3)#50 + Ope(2,1,4)#51 + Ope(2,1,5)#52 + Ope(2,1,6)#53 + Ope(2,1,7)#54 + Ope(2,1,8)#55 + Ope(2,1,9)#56 + Ope(2,1,10)#57 + Ope(2,1,11)#58 + Ope(2,1,12)#59 + Ope(2,1,13)#60 + Ope(2,1,14)#61 + Ope(2,1,15)#62 + Ope(2,1,16)#63 + Ope(2,1,17)#64 + Ope(2,1,18)#65 + Ope(2,1,19)#66 + Ope(2,1,20)#67 + Ope(2,1,21)#68 + Ope(2,1,22)#69 + Ope(2,1,23)#70 + Ope(2,1,24)#71 + Ope(2,2,1)#72 + Ope(2,2,2)#73 + Ope(2,2,3)#74 + Ope(2,2,4)#75 + Ope(2,2,5)#76 + Ope(2,2,6)#77 + Ope(2,2,7)#78 + Ope(2,2,8)#79 + Ope(2,2,9)#80 + Ope(2,2,10)#81 + Ope(2,2,11)#82 + Ope(2,2,12)#83 + Ope(2,2,13)#84 + Ope(2,2,14)#85 + Ope(2,2,15)#86 + Ope(2,2,16)#87 + Ope(2,2,17)#88 + Ope(2,2,18)#89 + Ope(2,2,19)#90 + Ope(2,2,20)#91 + Ope(2,2,21)#92 + Ope(2,2,22)#93 + Ope(2,2,23)#94 + Ope(2,2,24)#95 I do not want #number to appear in my lp file. What should I do?
The LP file format does not allow arbitrary names for variables and/or constraints. You can find details in the user manual at CPLEX > File formats > LP file format. If any of your variables or constraints has a name that is not supported in the LP file format then this name has to be changed. To avoid the new name clashing with any existing name, CPLEX appends #number to all names in your model. One likely/frequent unsupported name is a name that starts in e. Try to avoid such names in case you want to export to LP.
im created a word scrambler and i am having difficulty implementing a block of code that scrambles each word individually
print (' ') print ('=================================') print ('Options:') print ('A.) Hello world ---> olHle dlWro') print ('B.) Hello world ---> Hlelo Wlord') while True: #changes input to lowercase letters sctype = input('Enter scramble type') sclower = sctype.lower() #if 'a' or 'b' not in sctype: #print ('follow directions') #input and input related variables print ('There is a 26 character limit') text = input(' Type your message or word: ') length = len(text) remaining = 26 - length counter = 1 just a fancy cage for length and remaining print ('============================') print ('||Length:', length, 'Remaining:', remaining, '||') print ('============================') letter order and loop for option A dash replaces spaces in original text with dashes a fills in extra character space with spaces so length = 26 b scrambles a in the order it is given if sclower == 'a': print ('Results for option A') print (' ') dash = text.replace(" ", "-") a = dash + ' ' * remaining b = a[25] + a[0] + a[24] + a[1] + a[23] + a[2] + a[22] + a[3] + a[21] + a[4] + a[20] + a[5] + a[19] + a[6] + a[18] + a[7] + a[17] + a[8] + a[16] + a[9] + a[15] + a[10] + a[14] + a[11] + a[13] + a[12] a = b scrambles a the amount its original text length is if a == b: while counter <= length: b = a[25] + a[0] + a[24] + a[1] + a[23] + a[2] + a[22] + a[3] + a[21] + a[4] + a[20] + a[5] + a[19] + a[6] + a[18] + a[7] + a[17] + a[8] + a[16] + a[9] + a[15] + a[10] + a[14] + a[11] + a[13] + a[12] a = b nospaces = b.replace(" ", "") #deletes all spaces made in var a nodashes = nospaces.replace("-", " ") #changes all dashes to spaces print (counter, '.)', nodashes) counter += 1 print (' ') option b elif sclower == 'b': print ('Results for option B') print (' ') dash = text.replace(" ", "-") a = dash + ' ' * remaining b = a[21] + a[23] + a[20] + a[25] + a[22] + a[24] + a[19] + a[2] + a[18] + a[0] + a[16] + a[1] + a[17] + a[4] + a[15] + a[3] + a[14] + a[5] + a[13] + a[7] + a[11] + a[6] + a[10] + a[9] + a[12] + a[18] a = b if a == b: while counter <= length : b = a[21] + a[23] + a[20] + a[25] + a[22] + a[24] + a[19] + a[2] + a[18] + a[0] + a[16] + a[1] + a[17] + a[4] + a[15] + a[3] + a[14] + a[5] + a[13] + a[7] + a[11] + a[6] + a[10] + a[9] + a[12] + a[18] a = b nospaces = b.replace(" ", "") nodashes = nospaces.replace("-", " ") print (counter, '.)', nodashes) counter += 1 print (' ') if input("Repeat the program? (Y/N)").strip().upper() != 'Y': break i need to impliment the code below into the code above. this will allow the program to scramble each word within a string individually instead of all at once counter = 0 text = 'Hello World' split = str.split(text) for str in split: no_name = split[counter] scramble = c[4] + c[0] + c[3] + c[1] + c[2] counter += 1 print (scramble, end=" ") PLEASE NOTE: the variable "text" should allow user input in the final version, above is just an example of the structure
How can I reverse the direction of arrow shown in this jsfiddle http://jsfiddle.net/5qaL886d/1/
I want to display arrow in the reverse directions of this jsfiddle http://jsfiddle.net/5qaL886d/1/ I an not understanding which attributes to change to do so. Thanks in advance..
The arrows in this snippet are drawn "by hand", i.e. the arrow points are calculated manually. So what you need to do is to recalculate them, so that they are located at the different end. Normally, the arrows are supposed to be created using "defs" (it is much easier) but in this case they seem to cause issues with IE10, therefore drawn by hand. Anyways, here is the updated version of the snippet, with arrows "reversed", but without reversing the input data. You just need to change signs here and there: var dx = d.target.x - d.source.x, dy = d.target.y - d.source.y, dr = Math.sqrt(dx * dx + dy * dy), theta = Math.atan2(dy, dx) - Math.PI / 7.85, d90 = Math.PI / 2, dtxs = d.source.x + 6 * Math.cos(theta), dtys = d.source.y + 6 * Math.sin(theta); return "M" + d.source.x + "," + d.source.y + "A" + dr + "," + dr + " 0 0 1," + d.target.x + "," + d.target.y + "A" + dr + "," + dr + " 0 0 0," + d.source.x + "," + d.source.y + "M" + dtxs + "," + dtys + "l" + (3.5 * Math.cos(d90 - theta) + 10 * Math.cos(theta)) + "," + (-3.5 * Math.sin(d90 - theta) + 10 * Math.sin(theta)) + "L" + (dtxs - 3.5 * Math.cos(d90 - theta) + 10 * Math.cos(theta)) + "," + (dtys + 3.5 * Math.sin(d90 - theta) + 10 * Math.sin(theta)) + "z"; http://jsfiddle.net/4kmhugof/1/