diff options
| author | NSDepression <avimanyu.apple@gmail.com> | 2025-12-03 11:56:18 +0530 |
|---|---|---|
| committer | NSDepression <avimanyu.apple@gmail.com> | 2025-12-03 11:56:18 +0530 |
| commit | 881957f4f0865000ab978222c9cb694c73180995 (patch) | |
| tree | 9fb3fc40551ff74d21dceabc37afefb957f238eb /Day 2 | |
| parent | 3a93d2d546476c3fb24f72b50e830930a321f969 (diff) | |
| download | AoC-2025-881957f4f0865000ab978222c9cb694c73180995.tar.gz AoC-2025-881957f4f0865000ab978222c9cb694c73180995.zip | |
Day 2.2
Diffstat (limited to 'Day 2')
| -rwxr-xr-x | Day 2/Day_02 | bin | 0 -> 66440 bytes | |||
| -rw-r--r-- | Day 2/Day_02.dSYM/Contents/Info.plist | 20 | ||||
| -rw-r--r-- | Day 2/Day_02.dSYM/Contents/Resources/DWARF/Day_02 | bin | 0 -> 1532260 bytes | |||
| -rw-r--r-- | Day 2/Day_02.dSYM/Contents/Resources/Relocations/aarch64/Day_02.yml | 5 | ||||
| -rw-r--r-- | Day 2/Day_02.swift | 31 | ||||
| -rw-r--r-- | Day 2/Untitled.py | 21 |
6 files changed, 69 insertions, 8 deletions
diff --git a/Day 2/Day_02 b/Day 2/Day_02 Binary files differnew file mode 100755 index 0000000..5ce52d3 --- /dev/null +++ b/Day 2/Day_02 diff --git a/Day 2/Day_02.dSYM/Contents/Info.plist b/Day 2/Day_02.dSYM/Contents/Info.plist new file mode 100644 index 0000000..4906cc6 --- /dev/null +++ b/Day 2/Day_02.dSYM/Contents/Info.plist @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> + <dict> + <key>CFBundleDevelopmentRegion</key> + <string>English</string> + <key>CFBundleIdentifier</key> + <string>com.apple.xcode.dsym.Day_02</string> + <key>CFBundleInfoDictionaryVersion</key> + <string>6.0</string> + <key>CFBundlePackageType</key> + <string>dSYM</string> + <key>CFBundleSignature</key> + <string>????</string> + <key>CFBundleShortVersionString</key> + <string>1.0</string> + <key>CFBundleVersion</key> + <string>1</string> + </dict> +</plist> diff --git a/Day 2/Day_02.dSYM/Contents/Resources/DWARF/Day_02 b/Day 2/Day_02.dSYM/Contents/Resources/DWARF/Day_02 Binary files differnew file mode 100644 index 0000000..643e85e --- /dev/null +++ b/Day 2/Day_02.dSYM/Contents/Resources/DWARF/Day_02 diff --git a/Day 2/Day_02.dSYM/Contents/Resources/Relocations/aarch64/Day_02.yml b/Day 2/Day_02.dSYM/Contents/Resources/Relocations/aarch64/Day_02.yml new file mode 100644 index 0000000..241796a --- /dev/null +++ b/Day 2/Day_02.dSYM/Contents/Resources/Relocations/aarch64/Day_02.yml @@ -0,0 +1,5 @@ +--- +triple: 'arm64-apple-darwin' +binary-path: Day_02 +relocations: [] +... diff --git a/Day 2/Day_02.swift b/Day 2/Day_02.swift index 6d682bd..dc991d6 100644 --- a/Day 2/Day_02.swift +++ b/Day 2/Day_02.swift @@ -37,7 +37,7 @@ print("=======Part 1=======\n\(invalidIdSum)") invalidIdSum = 0 func isRepeating(_ x: Int) -> Bool { - if x == 0 { return false } + if x < 10 { return false } var digits = 0 var temp = x while temp > 0 { @@ -48,19 +48,16 @@ func isRepeating(_ x: Int) -> Bool { for period in 1...(digits / 2) { guard digits % period == 0 else { continue } var divisor = 1 - for _ in 0..<period { - divisor *= 10 - } + for _ in 0..<period { divisor *= 10 } let pattern = x % divisor + guard pattern != 0 else { continue } var reconstructed = 0 var multiplier = 1 for _ in 0..<(digits / period) { reconstructed += pattern * multiplier multiplier *= divisor } - if reconstructed == x { - return true - } + if reconstructed == x { return true } } return false } @@ -72,4 +69,22 @@ ranges.forEach { range in } } } -print("=======Part 2=======\n\(invalidIdSum)")
\ No newline at end of file +print("=======Part 2=======\n\(invalidIdSum)") + +invalidIdSum = 0 +ranges.forEach { group in + for id in group { + let numString = String(id) + let numstrLength = numString.count + if numstrLength < 2 { continue } + for patternLength in 1...(numstrLength / 2) { + let remainder = numString.replacingOccurrences(of: numString[..<numString.index(numString.startIndex, offsetBy: patternLength)], with: "") + if remainder.isEmpty { + invalidIdSum += id + break + } + } + } +} + +print("=======Part 2.2=======\n\(invalidIdSum)")
\ No newline at end of file diff --git a/Day 2/Untitled.py b/Day 2/Untitled.py new file mode 100644 index 0000000..536e83b --- /dev/null +++ b/Day 2/Untitled.py @@ -0,0 +1,21 @@ + + +with open ('input.txt', "r") as file: + content = file.read().strip() +range_groups = content.split(',') +st = [] +sum = 0 + +for group in range_groups: + print (f"Range: {group}") + distinct_nums = group.split("-") + first_value = int(distinct_nums[0]) + last_value = int(distinct_nums[1]) + for num in range(first_value, last_value + 1): + s = str(num) + is_repeating = s in (s + s) [1:-1] + if is_repeating==True: + st.append(num) +for n in st: + sum += n +print (f"Total Sum: {sum} ")
\ No newline at end of file |
