0% found this document useful (0 votes)
13 views

Advance Programming 1 - Alasso

The document describes two programming tasks - the first involves comparing ratings of challenges created by Alice and Bob and calculating their scores, while the second task involves calculating the absolute difference between the sums of diagonals of a square matrix. Both tasks provide explanations of the problems and code snippets to solve them.

Uploaded by

Avnish Ranjan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Advance Programming 1 - Alasso

The document describes two programming tasks - the first involves comparing ratings of challenges created by Alice and Bob and calculating their scores, while the second task involves calculating the absolute difference between the sums of diagonals of a square matrix. Both tasks provide explanations of the problems and code snippets to solve them.

Uploaded by

Avnish Ranjan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment 1

Student Name: Alasso.me UID: 21BCS


Branch: CSE Section/Group:
Semester: 5th Date of Performance:07/08/23
Subject Name: Advanced Programming Lab Subject Code:21CSP314

TASK 1

1. Aim: The aim is to compare the ratings of two challenges created by


Alice and Bob, calculate their respective scores based on the
comparisons, and return the scores as a list with Alice's score first and
Bob's score second.

2. Objective:The objective is to develop a program that takes the


ratings of two challenges created by Alice and Bob, compares the
ratings for each category, calculates their scores, and produces a list
representing the comparison points, with Alice's score first and Bob's
score second.

3. Script :

import math
import os
import random
import re
import sys

def compareTriplets(a, b):


DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
alice,bob=0,0
for i,j in zip(a,b):
if i>j: alice+=1
if i<j: bob+=1
return alice,bob

if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')

a = list(map(int, input().rstrip().split()))

b = list(map(int, input().rstrip().split()))

result = compareTriplets(a, b)

fptr.write(' '.join(map(str, result)))


fptr.write('\n')

fptr.close()

4.OUTPUT
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

LEARNING OUTCOMES

(I) Array Manipulation: This task involves working with arrays


(triplets) to compare corresponding elements. Learning how to
iterate through arrays, access specific elements, and perform
comparisons is a fundamental skill in programming.

(II) Conditional Logic: The use of conditional statements (if-elif-


else) to determine the points awarded to Alice and Bob based on
the comparisons helps learners understand how to make decisions
in code and handle different scenarios.

TASK 2

1.AIM: The Aim is to , calculate the absolute difference between the


sums of its diagonals of square matrix.

2.OBJECTIVE : The objective is to create a function that takes a


square matrix as input, calculates the sums of its left-to-right and
right-to-left diagonals, and then calculates the absolute difference
between these two diagonal sums. The function should return this
absolute difference as the final output.

3.SCRIPT :
import math
import os
import random
import re
import sys
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

def diagonalDifference(arr):
final = len(arr) - 1
diferenca_diagonais = 0
for indice, linha in enumerate(arr):
diferenca_diagonais += linha[indice] -
linha[final - indice]
return abs(diferenca_diagonais)

if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')

n = int(input().strip())

arr = []
for _ in range(n):

arr.append(list(map(int, input().rstrip().split())))

result = diagonalDifference(arr)

fptr.write(str(result) + '\n')

fptr.close()

4.OUTPUT
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

5. LEARNING OUTCOMES

(I). Algorithmic Thinking: This problem encourages you to think


algorithmically, breaking down the task into smaller steps to efficiently
calculate the diagonal sums and absolute difference.

(II). Mathematical Logic: You'll use mathematical concepts to


calculate the diagonal sums and the absolute difference, enhancing your
ability to apply mathematical logic in programming.

You might also like