how to read a data file that contain "name grade" and Calculate the GPA in clips - readfile

how to calculate the GPA in clips after reading from the file
the file is:
a 10 9 13 7
b 12 3 10 14
c 8 10 12 10
d 15 8 14 9
output:
a (10 9 13 7) 9.75
b (12 3 10 14) 9.75

Use the open function to open the file. You can use the readline function to grab a line of data and then use the explode$, nth$, and rest$ functions to grab the name and list of grades. Here's an example reading from standard input rather than a file:
CLIPS (6.4 2/9/21)
CLIPS> (bind ?i (readline))
a 10 9 13 7
"a 10 9 13 7"
CLIPS> (bind ?i (explode$ ?i))
(a 10 9 13 7)
CLIPS> (nth$ 1 ?i)
a
CLIPS> (bind ?grades (rest$ ?i))
(10 9 13 7)
CLIPS>

Related

How to separate data from a file [duplicate]

This question already has answers here:
C++ how to use fstream to read tab-delimited file with spaces
(3 answers)
Problem reading a tab delimited file in C++
(1 answer)
Reading tab-separated values from text file into array
(2 answers)
Reading numbers from a space delimited text file in C++
(5 answers)
Closed 4 months ago.
I have a lab assignment where I have to get data from a file and separate the party id meal cost, how many adults or kids are in the party, if it is a weekend when they bought the meal and the total bill. This is what the data file contains.
1 10 0 S Y 100.00
2 27 3 D Y 57.50
3 125 17 D N 0.00
4 4 0 S N 25.00
5 0 25 S Y 23.75
6 250 43 D N 500.00
7 0 0 D N 0.0
8 10 0 R Y 10.00
9 17 3 D R 15.00
10 5 0 D Y 275.00
11 -3 10 D Y 20.00
12 14 -1 S N 30.00
13 20 3 D Y -10.00
I know how to get input from the file but I don't know how to separate all this data to different int variables and bool and what not.
I tried making int variables and getting the file to input data into the variables but it would just copy what is on the file into the variables.

Loop a matrix and a vector

I have a vector with 2 elements a_destinations that represent the source and destination with two integers. 2 4 or 5 1...
I have a matrix test as follows:
0 15 15 15 13 13 15 15 13 13 15 15 15 13 15 15
2 1 2 2 2 2 2 2 2 2 10 2 2 2 10 2
6 1 2 3 3 3 6 6 6 6 6 6 6 6 6 6
7 2 2 3 4 4 2 7 7 7 7 7 7 7 7 7
8 3 3 3 4 5 3 3 8 8 3 3 3 8 3 3
9 4 4 4 4 5 4 4 4 9 4 4 4 9 4 4
7 2 2 2 2 2 6 7 7 7 11 11 7 7 11 7
12 6 6 3 3 3 6 7 8 8 12 12 12 12 12 12
9 7 7 7 4 4 7 7 8 9 7 7 7 9 7 7
13 8 8 8 8 5 8 8 8 9 13 13 13 13 13 13
14 1 11 11 11 11 11 11 11 11 10 11 11 11 14 14
12 6 6 12 12 12 6 12 12 12 10 11 12 12 10 12
15 7 7 7 7 7 7 7 7 13 11 11 12 13 11 15
0 12 12 12 9 9 12 12 9 9 12 12 12 13 12 12
15 10 10 10 10 10 10 10 10 10 10 10 10 10 14 15
0 12 12 12 12 12 12 12 12 12 14 12 12 12 14 15
where test[i][j] represents the path from i to j
each time test[i][j] != j we do the loop again
Example:
path from 2 to 4 >> test[2][4] = 3, test[3][4] = 4: we output: 2, 3, 4
path from 1 to 7 >> test[1][7] = 2, test[2][7] = 6 , test[6][7] = 7: we output 1, 2 ,6, 7
I tried as follows:
std::vector<vector<int>> test;
test = Graphe->P; // MATRIX IS FILLED like on top
vector< int > a_destinations; // Vector with the destinations: 2 4 or 5 10 or 1 4 ...
for ( unsigned i = 0; i < test.size(); i++){
for (unsigned j = 0; j< test.size(); j++){
for (unsigned k = 0; k < a_destinations->size() - 1 ; k ++){
if ( a_destinations->at(k) == i && a_destinations->at(k+1) == j ){
if (test[i][j] == a_destinations->at(k+1)){
cout << a_destinations->at(k) << ", " <<test[i][j];
} else {
cout << a_destinations->at(k) << ", " << test[a_destinations->at(k)][j];
}
cout << ", " << test[i][j];// << ", " << a_destinations->at(k+1);
}
}
}
}
But i end up with 2 destinations always.

how to print a list vertically python

>list1=[1,2,3,4]
>list2=[5,6,7,8]
>list3=[9,10,11,12]
>list4=[13,14,15,16]
>list5=[17,18,19,20]
>lists=[list1,list2,list3,list4,list5
I want to print the following code so that it outputs this way:
4 8 12 16 20
3 7 11 15 19
2 6 10 14 18
sorry didn't knew it ignored new lines:
1 5 9 13 17
Thanks in advance (new to python)
One way you could achieve this is to zip up the reversed lists and simply print all the elements out.
list1=[1,2,3,4]
list2=[5,6,7,8]
list3=[9,10,11,12]
list4=[13,14,15,16]
list5=[17,18,19,20]
for l1, l2, l3, l4, l5 in zip(reversed(list1), reversed(list2), reversed(list3), reversed(list4), reversed(list5)):
print(l1, l2, l3, l4, l5, end=' ')
output
4 8 12 16 20 3 7 11 15 19 2 6 10 14 18 1 5 9 13 17

How to print 10 number 10 times,9 number 9 times etc..Using Python

Output should be like this
10 10 10 10 10 10 10 10 10 10
9 9 9 9 9 9 9 9 9
8 8 8 8 8 8 8 8
7 7 7 7 7 7 7
.
.
.
1
tyr it dear
l = [1,2,3,4,5,6,7,8,9,10]
d = []
for i in l:
d.extend([i]*i)
print d[::-1]

Can I use Lists in R as a proxy to data frame having unequal number of columns?

My understanding as far as data frame in R is that it has to be rectangular. It is not possible to have a data frame with unequal column lengths. Can I use the lists in R to achieve this? What are he pros and cons for such an approach?
You can use lists to store whatever you want, even dataframes or other lists! You can indeed assign different length vectors, or even completely different objects. It gives you the same functionality as dataframes in that you can index using the dollar sign:
> fooList <- list(a=1:12, b=1:11, c=1:10)
> fooList$a
[1] 1 2 3 4 5 6 7 8 9 10 11 12
> fooDF <- data.frame(a=1:10, b=1:10, c=1:10)
> fooDF$a
[1] 1 2 3 4 5 6 7 8 9 10
But numeric indexing is different:
> fooList[[1]]
[1] 1 2 3 4 5 6 7 8 9 10 11 12
> fooDF[,1]
[1] 1 2 3 4 5 6 7 8 9 10
as well as the structure and printing method:
> fooList
$a
[1] 1 2 3 4 5 6 7 8 9 10 11 12
$b
[1] 1 2 3 4 5 6 7 8 9 10 11
$c
[1] 1 2 3 4 5 6 7 8 9 10
> fooDF
a b c
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
5 5 5 5
6 6 6 6
7 7 7 7
8 8 8 8
9 9 9 9
10 10 10 10
Simply said a dataframe is a matrix and a list more of a container.
A list is meant to keep all sorts of stuff together, and a dataframe is the usual data format (a subject/case for each row and a variable for each column). It is used in a lot of analyses, allows to index the scores of a subject, can be more easilly transformed and other things.
However if you have unequal length columns then I doubt each row resembles a subject/case in your data. In that case I guess you don't need much of the functionality of dataframes.
If each row does resemble a subject/case, then you should use NA for any missing values and use a data frame.