SIAS-Cyber-Club / Weekly-Coding-Sessions

3 stars 1 forks source link

Problem 1 #1

Closed SIAS-Cyber-Club closed 2 months ago

SIAS-Cyber-Club commented 2 months ago

"We've detected some temporal anomalies," one of Santa's Elves at the Temporal Anomaly Research and Detection Instrument Station tells you. She sounded pretty worried when she called you down here. "At 500-year intervals into the past, someone has been changing Santa's history!" "The good news is that the changes won't propagate to our time stream for another 25 days, and we have a device" - she attaches something to your wrist - "that will let you fix the changes with no such propagation delay. It's configured to send you 500 years further into the past every few days; that was the best we could do on such short notice." "The bad news is that we are detecting roughly fifty anomalies throughout time; the device will indicate fixed anomalies with stars. The other bad news is that we only have one device and you're the best person for the job! Good lu--" She taps a button on the device and you suddenly feel like you're falling. After feeling like you've been falling for a few minutes, you look at the device's tiny screen. "Error: Device must be calibrated before first use. Frequency drift detected. Cannot maintain destination lock." Below the message, the device shows a sequence of changes in frequency (your puzzle input). A value like +6 means the current frequency increases by 6; a value like -3 means the current frequency decreases by 3. For example, if the device displays frequency changes of +1, -2, +3, +1, then starting from a frequency of zero, the following changes would occur: Current frequency 0, change of +1; resulting frequency 1. Current frequency 1, change of -2; resulting frequency -1. Current frequency -1, change of +3; resulting frequency 2. Current frequency 2, change of +1; resulting frequency 3. In this example, the resulting frequency is 3. Here are other example situations: +1, +1, +1 results in 3 +1, +1, -2 results in 0 -1, -2, -3 results in -6 Starting with a frequency of zero, what is the resulting frequency after all of the changes in frequency have been applied?

VidishaPonnappa commented 2 months ago

// l -> List def freq(l): return sum(l)

iShahDhruva commented 2 months ago

//input = [0, 2, -1] frequency = 0

for numbers in input: frequency += numbers

print(frequency)

pramati108 commented 2 months ago

def calculate_resulting_frequency(changes): return sum(changes)

Example usage

if name == "main": frequency_changes = [+1, -2, +3, +1] print("Resulting frequency:", calculate_resulting_frequency(frequency_changes))

Lil-Nug commented 2 months ago
def f(in):
    print(sum(in))
Midnightscorpion commented 2 months ago
// "freq" is the frequency resulting after all changes
        int freq = 0;
        //Run through the for loop to check each element
        for(int i = 0; i < p1.length; i++){
            // if the element in a positive integer
            if(p1[i] > 0){
                //increase the value of freq
                freq = freq + p1[i];
            }
            // else decrease the value of freq
            else if (p1[i] < 0){
                freq = freq + p1[i];
            }
        }
        return freq;