Skip to main content
effect -> affect
Source Link
Giuseppe
  • 28.8k
  • 8
  • 9

GPA calculator

A GPA is sort of weighted average based on the grades obtained in certain courses. There are a number of different systems, but for this challenge we'll use the following grades and their numeric values:

A: 4
B: 3
C: 2
D: 1
F: 0
P: —

The grade is P is a special case. For some courses, students can sign up to take a course as Pass/Fail. In the case of a Pass (P), the course has no effect on their GPA whatsoever, but in the case of a Fail (F), the course does effectaffect the GPA.

All courses are weighted by the number of hours/credits they are taken for. So give the following transcript:

Course            Hours   Grade
------            -----   -----
Next Gen Perl       6       A
Advanced C-minar    1       C
Starting with Java  3       B

We would calculate the total points as 35 (6*4 + 1*2 + 3*3), and then divide it by the number of hours, or 10 (6+1+3) for a final GPA of 3.5. If Starting with Java had been given an F, the total points would be 26 with 10 hours, for a GPA of 2.6. However, if it had been a P, the total points would still be 26, but with only 7 hours, the GPA would be 3.71428571429…

Input

An arbitrarily long list/array/sequence/etc of transcript entries. The entries are simply a two item list/array/sequence/etc with one item being an integer value (doesn't have to be an actual Int value, floats are fine) of hours, and the other being the string ('A','B'...). The above example would have been:

[
  [6, 'A'],
  [1, 'C'],
  [3, 'B']
]

You may assume that the list will have at least one computable grade (so no empty transcripts, nor transcripts consisting only of P). If your language does not have strings, then you may use numbers for A/B/C/D/F/P, but their values must be similarly spaced (e.g. 10,11,12,13,14,25)

Output

A number representing the GPA (float or other non-Int value)

Scoring and Restrictions

Codegolf, so shortest code in bytes wins. Standard rules apply.

Sandbox questions

I thought about allowing for either +/- grades (A+, A, A-, B+...) which would definitely prevent using ASCII values as easily, but then that led me to the thought of having a second input which is a list of possible grades with their equivalent value, but I think that would start over complicating it and way over benefit languages with built-in hashing. Thoughts?

GPA calculator

A GPA is sort of weighted average based on the grades obtained in certain courses. There are a number of different systems, but for this challenge we'll use the following grades and their numeric values:

A: 4
B: 3
C: 2
D: 1
F: 0
P: —

The grade is P is a special case. For some courses, students can sign up to take a course as Pass/Fail. In the case of a Pass (P), the course has no effect on their GPA whatsoever, but in the case of a Fail (F), the course does effect the GPA.

All courses are weighted by the number of hours/credits they are taken for. So give the following transcript:

Course            Hours   Grade
------            -----   -----
Next Gen Perl       6       A
Advanced C-minar    1       C
Starting with Java  3       B

We would calculate the total points as 35 (6*4 + 1*2 + 3*3), and then divide it by the number of hours, or 10 (6+1+3) for a final GPA of 3.5. If Starting with Java had been given an F, the total points would be 26 with 10 hours, for a GPA of 2.6. However, if it had been a P, the total points would still be 26, but with only 7 hours, the GPA would be 3.71428571429…

Input

An arbitrarily long list/array/sequence/etc of transcript entries. The entries are simply a two item list/array/sequence/etc with one item being an integer value (doesn't have to be an actual Int value, floats are fine) of hours, and the other being the string ('A','B'...). The above example would have been:

[
  [6, 'A'],
  [1, 'C'],
  [3, 'B']
]

You may assume that the list will have at least one computable grade (so no empty transcripts, nor transcripts consisting only of P). If your language does not have strings, then you may use numbers for A/B/C/D/F/P, but their values must be similarly spaced (e.g. 10,11,12,13,14,25)

Output

A number representing the GPA (float or other non-Int value)

Scoring and Restrictions

Codegolf, so shortest code in bytes wins. Standard rules apply.

Sandbox questions

I thought about allowing for either +/- grades (A+, A, A-, B+...) which would definitely prevent using ASCII values as easily, but then that led me to the thought of having a second input which is a list of possible grades with their equivalent value, but I think that would start over complicating it and way over benefit languages with built-in hashing. Thoughts?

GPA calculator

A GPA is sort of weighted average based on the grades obtained in certain courses. There are a number of different systems, but for this challenge we'll use the following grades and their numeric values:

A: 4
B: 3
C: 2
D: 1
F: 0
P: —

The grade is P is a special case. For some courses, students can sign up to take a course as Pass/Fail. In the case of a Pass (P), the course has no effect on their GPA whatsoever, but in the case of a Fail (F), the course does affect the GPA.

All courses are weighted by the number of hours/credits they are taken for. So give the following transcript:

Course            Hours   Grade
------            -----   -----
Next Gen Perl       6       A
Advanced C-minar    1       C
Starting with Java  3       B

We would calculate the total points as 35 (6*4 + 1*2 + 3*3), and then divide it by the number of hours, or 10 (6+1+3) for a final GPA of 3.5. If Starting with Java had been given an F, the total points would be 26 with 10 hours, for a GPA of 2.6. However, if it had been a P, the total points would still be 26, but with only 7 hours, the GPA would be 3.71428571429…

Input

An arbitrarily long list/array/sequence/etc of transcript entries. The entries are simply a two item list/array/sequence/etc with one item being an integer value (doesn't have to be an actual Int value, floats are fine) of hours, and the other being the string ('A','B'...). The above example would have been:

[
  [6, 'A'],
  [1, 'C'],
  [3, 'B']
]

You may assume that the list will have at least one computable grade (so no empty transcripts, nor transcripts consisting only of P). If your language does not have strings, then you may use numbers for A/B/C/D/F/P, but their values must be similarly spaced (e.g. 10,11,12,13,14,25)

Output

A number representing the GPA (float or other non-Int value)

Scoring and Restrictions

Codegolf, so shortest code in bytes wins. Standard rules apply.

Sandbox questions

I thought about allowing for either +/- grades (A+, A, A-, B+...) which would definitely prevent using ASCII values as easily, but then that led me to the thought of having a second input which is a list of possible grades with their equivalent value, but I think that would start over complicating it and way over benefit languages with built-in hashing. Thoughts?

Source Link

GPA calculator

A GPA is sort of weighted average based on the grades obtained in certain courses. There are a number of different systems, but for this challenge we'll use the following grades and their numeric values:

A: 4
B: 3
C: 2
D: 1
F: 0
P: —

The grade is P is a special case. For some courses, students can sign up to take a course as Pass/Fail. In the case of a Pass (P), the course has no effect on their GPA whatsoever, but in the case of a Fail (F), the course does effect the GPA.

All courses are weighted by the number of hours/credits they are taken for. So give the following transcript:

Course            Hours   Grade
------            -----   -----
Next Gen Perl       6       A
Advanced C-minar    1       C
Starting with Java  3       B

We would calculate the total points as 35 (6*4 + 1*2 + 3*3), and then divide it by the number of hours, or 10 (6+1+3) for a final GPA of 3.5. If Starting with Java had been given an F, the total points would be 26 with 10 hours, for a GPA of 2.6. However, if it had been a P, the total points would still be 26, but with only 7 hours, the GPA would be 3.71428571429…

Input

An arbitrarily long list/array/sequence/etc of transcript entries. The entries are simply a two item list/array/sequence/etc with one item being an integer value (doesn't have to be an actual Int value, floats are fine) of hours, and the other being the string ('A','B'...). The above example would have been:

[
  [6, 'A'],
  [1, 'C'],
  [3, 'B']
]

You may assume that the list will have at least one computable grade (so no empty transcripts, nor transcripts consisting only of P). If your language does not have strings, then you may use numbers for A/B/C/D/F/P, but their values must be similarly spaced (e.g. 10,11,12,13,14,25)

Output

A number representing the GPA (float or other non-Int value)

Scoring and Restrictions

Codegolf, so shortest code in bytes wins. Standard rules apply.

Sandbox questions

I thought about allowing for either +/- grades (A+, A, A-, B+...) which would definitely prevent using ASCII values as easily, but then that led me to the thought of having a second input which is a list of possible grades with their equivalent value, but I think that would start over complicating it and way over benefit languages with built-in hashing. Thoughts?