External tool coding required for Parasoft - parasoft

I know this is not as per guidelines, but i do need some help in parasoft extendaion tool coding part. I have all the logic that is required but dont know how to start
1 . I have 8 digit "50000002"
2 . I have another 8 digit checksum code "12121212"
3 . Now multiply each number with the 8 digit checksum code
5 0 0 0 0 0 0 2
1 2 1 2 1 2 1 2
==================
(5*1)(0*2)(0*1).....(2*2)
==================
4 . Now take the multiples and check if it is greater than equal or less than 9. if the multiples is less than 9, the value should be the number of multiple
For e.g. Last digit was 2*2 = 4 and 4 > 9 is false : so value would be 4
If it is greater then it that number should be subtracted by 9
For e.g. 9*2 = 18 and 18 > 9 is true : so the value would be 18-9 = 9
5 . Then we need to add all the number got from step 4 and use the below formuale
10-MOD(SUM(Step4_value),10)
if the value from the above formula is equal to 10 then it should give number 0 or else the value will the same of the formula.
EDITED

Related

Set half of tesor columns to zero

I have a tensor of size m x n (m rows and n columns).
For example:
[ 5 8 4 3
1 3 5 4
3 9 8 6 ]
I wish to randomly select half of the columns, and set all the values in this columns as zeros.
For our example, it will create something like this:
[ 5 0 4 0
1 0 5 0
3 0 8 0 ]
I'm aware how to set zero randomly half of all the elements,
torch.rand(x.shape) > 0.5
but done randomly without consideration in the columns, which is not helpfull for my case.
Thank you for any help,
Dave
import torch
x = torch.rand(3,4)
x
tensor([[0.0143, 0.1070, 0.9985, 0.0727],
[0.4052, 0.8716, 0.7376, 0.5495],
[0.2553, 0.2330, 0.9285, 0.6535]])
for i in [1,3] : # list has your columns which you want to make zero
x[:,i] = 0

Does binary search in any case work with physical numbers themselves? Excluding 0

If there is a list in numerical order, (1 - 10) will binary search work with it? If the answer is no, can I have an explanation why it won't?
Binary search works with any array that is sorted.
Take searching for 3 as an example; assume we have a list of numbers from 1 to 10.
1 2 3 4 5 6 7 8 9 10
First, we divide it in two.
1 2 3 4 5 6 7 8 9 10
Since 3 is less than 6, we go with the first half.
1 2 3 4 5
Since 3 is less than 4, we go with the first half again.
1 2 3
Since 3 is equal to 3, we go with the second half.
And we have found 3.

pandas: idxmax for k-th largest

Having df of probabilities distribution, I get max probability for rows with df.idxmax(axis=1) like this:
df['1k-th'] = df.idxmax(axis=1)
and get the following result:
(scroll the tables to the right if you can not see all the columns)
0 1 2 3 4 5 6 1k-th
0 0.114869 0.020708 0.025587 0.028741 0.031257 0.031619 0.747219 6
1 0.020206 0.012710 0.010341 0.012196 0.812495 0.113863 0.018190 4
2 0.023585 0.735475 0.091795 0.021683 0.027581 0.054217 0.045664 1
3 0.009834 0.009175 0.013165 0.016014 0.015507 0.899115 0.037190 5
4 0.023357 0.736059 0.088721 0.021626 0.027341 0.056289 0.046607 1
the question is how to get the 2-th, 3th, etc probabilities, so that I get the following result?:
0 1 2 3 4 5 6 1k-th 2-th
0 0.114869 0.020708 0.025587 0.028741 0.031257 0.031619 0.747219 6 0
1 0.020206 0.012710 0.010341 0.012196 0.812495 0.113863 0.018190 4 3
2 0.023585 0.735475 0.091795 0.021683 0.027581 0.054217 0.045664 1 4
3 0.009834 0.009175 0.013165 0.016014 0.015507 0.899115 0.037190 5 4
4 0.023357 0.736059 0.088721 0.021626 0.027341 0.056289 0.046607 1 2
Thank you!
My own solution is not the prettiest, but does it's job and works fast:
for i in range(7):
p[f'{i}k'] = p[[0,1,2,3,4,5,6]].idxmax(axis=1)
p[f'{i}k_v'] = p[[0,1,2,3,4,5,6]].max(axis=1)
for x in range(7):
p[x] = np.where(p[x]==p[f'{i}k_v'], np.nan, p[x])
The loop does:
finds the largest value and it's column index
drops the found value (sets to nan)
again
finds the 2nd largest value
drops the found value
etc ...

Saudi Iqama/National Identity number field validation

Can someone help me with the criteria for field validation for Saudi iqama/National Identification number?
I know for Nationals it should start with 1 and for expats, it should start with 2 and the length should be 10.Anything else. This is for an application which has already seen some bad incoming data creating bugs, so don't want to take chances. Thanks in advance.
For (Id Type=’National Id’)  length = 10 , Id Number must start with ‘1’ in position 1. Multiply every number in an Odd Position (characters in positions 1,3,5..9) by 2. If the multiplication yields a 2 digit number then summate these 2 digits to yield a single digit. Summate the first 9 Characters for the ID number (post multiplication) to yield a 2 digit number (XY). If 10th digit of the ID number equals to “Zero”, then subtract 10 by the digit in position 2 (Y) in the summation total of the first 9 characters to yield a 2 digits (ZN), (N) should be equal to the 10th digit of the ID Number. Else, the 10th digit of the ID Number should be equal to 10 subtracted by the digit in position 2 (Y) in the Summation total of the first 9 Characters.
Saudi ID Number – 1058529940
Position 1 2 3 4 5 6 7 8 9 10
ID Nbr 1 0 5 8 5 2 9 9 4 0
Multiply 2 0 1 8 1 2 9 9 8
Summate 40
Validation Position 10 (value 0) = 10 – Digit 2
of Summation Total (0) = subtraction’s digit 2
e.g. ID Number = 1001244019
Position 1 2 3 4 5 6 7 8 9 10
ID Nbr 1 0 0 1 2 4 4 0 1 9
Multiply 2 0 0 1 4 4 8 0 2
Summate 21
Validation Position 10 (value 9) = 10 – Digit 2
of Summation Total (1)
Try validating using regex. ^[1|2]{1}[0-9]{9}$ this worked for me.
or if you are looking for a code that checks whether the id is correct or incorrect check this GitHub repo: https://github.com/alhazmy13/Saudi-ID-Validator. It's written in different programming languages, an it checks both National ID and Residence ID

how to calculate the specific accumulated amount in t-sql

For each row, I need to calculate the integer part from dividing by 4. For each subsequent row, we add the remainder of the division by 4 previous and current lines and look at the whole part and the remainders from dividing by 4. Consider the example below:
id val
1 22
2 1
3 1
4 2
5 1
6 6
7 1
After dividing by 4, we look at the whole part and the remainders. For each id we add up the accumulated points until they are divided by 4:
id val wh1 rem1 wh2 rem2 RESULT(wh1+wh2)
1 22 5 2 0 2 5
2 1 0 1 (3/4=0) 3%4=3 0
3 1 0 1 (4/4=1) 4%4=0 1
4 2 0 2 (2/4=0) 2%4=2 0
5 1 0 1 (3/4=0) 3%4=3 0
6 7 1 2 (5/4=1) 5%4=1 2
7 1 0 1 (2/4=0) 2%4=1 0
How can I get the next RESULT column with sql?
Data of project:
http://sqlfiddle.com/#!18/9e18f/2
The whole part from the division into 4 is easy, the problem is to calculate the accumulated remains for each id, and to calculate which of them will also be divided into 4