I have a class of point which has X and Y and a class of Line which has 2 points in it.
I want to check if 2 lines cut, how can I do that ?
Related
I have a survey data baseline and endline. I am trying to plot bar plot for qualification of the respondent in each group (baseline/endline).
I am using the following code:
graph bar, over(qualification) over(time)
It is giving me different output from what I want.
I want the bars for endline and baseline for each category to be present parallel.
I am also attaching a reference picture to get the better idea about what I want.
The order of the over options of graph bar matters.
Consider this example:
clear
input x str1 a b
1 "a" 1
2 "a" 2
3 "b" 1
4 "b" 2
end
graph bar x, over(a) over(b) title("over(a) over(b)")
graph bar x, over(b) over(a) title("over(b) over(a)")
It looks like you need to swap the order of your over options.
You’re given a chess board with dimension n x n. There’s a king at the bottom right square of the board marked with s. The king needs to reach the top left square marked with e. The rest of the squares are labeled either with an integer p (marking a point) or with x marking an obstacle. Note that the king can move up, left and up-left (diagonal) only. Find the maximum points the king can collect and the number of such paths the king can take in order to do so.
Input Format
The first line of input consists of an integer t. This is the number of test cases. Each test case contains a number n which denotes the size of board. This is followed by n lines each containing n space separated tokens.
Output Format
For each case, print in a separate line the maximum points that can be collected and the number of paths available in order to ensure maximum, both values separated by a space. If e is unreachable from s, print 0 0.
Sample Input
3
3
e 2 3
2 x 2
1 2 s
3
e 1 2
1 x 1
2 1 s
3
e 1 1
x x x
1 1 s
Sample Output
7 1
4 2
0 0
Constraints
1 <= t <= 100
2 <= n <= 200
1 <= p <= 9
I think this problem could be solved using dynamic-programing. We could use dp[i,j] to calculate the best number of points you can obtain by going from the right bottom corner to the i,j position. We can calculate dp[i,j], for a valid i,j, based on dp[i+1,j], dp[i,j+1] and dp[i+1,j+1] if this are valid positions(not out of the matrix or marked as x) and adding them the points obtained in the i,j cell. You should start computing from the bottom right corner to the left top, row by row and beginning from the last column.
For the number of ways you can add a new matrix ways and use it to store the number of ways.
This is an example code to show the idea:
dp[i,j] = dp[i+1,j+1] + board[i,j]
ways[i,j] = ways[i+1,j+1]
if dp[i,j] < dp[i+1,j] + board[i,j]:
dp[i,j] = dp[i+1,j] + board[i,j]
ways[i,j] = ways[i+1,j]
elif dp[i,j] == dp[i+1,j] + board[i,j]:
ways[i,j] += ways[i+1,j]
# check for i,j+1
This assuming all positions are valid.
The final result is stored in dp[0,0] and ways[0,0].
Brief Overview:
This problem can be solved through recursive method call, starting from nn till it reaches 00 which is the king's destination.
For the detailed explanation and the solution for this problem,check it out here -> https://www.callstacker.com/detail/algorithm-1
So I have a file similar to this
A 1 foo bar 1
A 1 foo bar 2
B 3 foo bar 5
B 3 foo bar 6
Where the first column is an ID, the second column is the number of times I need the line repeated. The output should look like this
A foo bar 1
A foo bar 2
B foo bar 5
B foo bar 6
C foo bar 5
C foo bar 6
D foo bar 5
D foo bar 6
However, since the files I am trying to use are rather big, the expanding is ultra slow. Any ideas? :)
EDIT1: Code I did, I did have two inputs, one file with the columns i showed before and one with just IDs and counts separated by a dash.
for ID in $(cat $ID_File);do
grep "^$ID[^0-9]" $IN > temp2.txt
Cycles=$(echo $ID| sed 's/.*-//')
for i in $(seq 1 1 $Cycles);do
cut -f2- temp2.txt| awk '{print '$Start_ID'"\t"$0}'>> $OUT
Start_ID=$(( $Start_ID + 1 ))
done
done
I found the answer! Instead of looking through the file several times with grep I used the following Python script that goes through the file just once.
FILE='A.txt'
ID=''
Prefix='A'
Number=1
First=1
Current=[]
OUT='B.txt'
f=open(File,'w')
for line in open(FILE):
line1=line.split('\t')
if ID!=line1[0] and First==0:
ID=line1[0]
for i in range(0,int(Current[0][1])):
for j in range(0,len(Current)):
f.write(' '.join([Prefix+str(Number)]+Current[j][2:]))
Number=Number+1
Current=[]
Current.append(line1)
elif ID!=line1[0] and First==1:
ID=line1[0]
First=0
Current.append(line1)
elif ID==line1[0]:
Current.append(line1)
Not the most elegant way to do it, but it gets the job done fast relatively quickly.
Please, i have a question about gnuplot.
Here is the file i work on:
1 129 130
2 129 129
3 129 130
4 129 129
5 129 ---
As you see the last line has no value in the third column.
Here is my command:
plot "mesuresSecondscen.txt" using 1:2 with linespoints lt 26 pt 26 tit 'Kernel of 129s' axis x1y1, "mesuresSecondscen.txt" using 1:3 with linespoints lt 21 pt 13 tit 'With-My-Approach' axis x1y1
Example: http://tinyurl.com/p2rfde9
I'd like to set the symbol 'X' in red in the place of the absent value
Is that possible please ?
Thank you so much for answer.
Kind regards.
There is a fundamental problem with your question, which is that you want to place a red "X", but where? If the value is missing you need to provide the coordinate value in some other way to know where you want to place the symbol. Anyway, for demonstration purposes I will assume you want to place it where the second column value lies. The function valid(n) can test if the value in column n is valid (returns 1) or not (returns 0). Using a conditional expression we can ask gnuplot to place a big red "X" at y = column(2) every time it encounters non-valid data:
plot "mesuresSecondscen.txt" using 1:2 with linespoints lt 26 pt 26 tit 'Kernel of 129s' axis x1y1, \
"mesuresSecondscen.txt" using 1:3 with linespoints lt 21 pt 13 tit 'With-My-Approach' axis x1y1, \
"mesuresSecondscen.txt" u 1:(valid(3) == 1 ? 1/0 : $2) pt 2 lc 1 ps 3 lw 3
The last line tests if the third column's value is valid, if it is valid (valid(3) = 1) it ignores that point, if it is not valid (valid(3) = 0) it places a big red "X" at y = column(2).
I am trying plot data sets consisting of 3 coordinates:
X-coordinate, x-coordinate and the number of occurrences.
example:
1 2 10
3 1 2
3 2 1
I would like to draw for every line a dot at x,y with a diameter which is depending on the third value.
Is that possible with Gnuplot?
Create a 2D plot with variable point size. See the demo.
Example:
plot 'dataFile.dat' u 1:2:3 w points lt 1 pt 10 ps variable
This is basically equivalent to the existing answer, just shorter:
plot 'dataFile.dat' with circles
Credit: Gnuplot: plot with circles of a defined radius