summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xDay 2/Day_02bin0 -> 66440 bytes
-rw-r--r--Day 2/Day_02.dSYM/Contents/Info.plist20
-rw-r--r--Day 2/Day_02.dSYM/Contents/Resources/DWARF/Day_02bin0 -> 1532260 bytes
-rw-r--r--Day 2/Day_02.dSYM/Contents/Resources/Relocations/aarch64/Day_02.yml5
-rw-r--r--Day 2/Day_02.swift31
-rw-r--r--Day 2/Untitled.py21
6 files changed, 69 insertions, 8 deletions
diff --git a/Day 2/Day_02 b/Day 2/Day_02
new file mode 100755
index 0000000..5ce52d3
--- /dev/null
+++ b/Day 2/Day_02
Binary files differ
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
new file mode 100644
index 0000000..643e85e
--- /dev/null
+++ b/Day 2/Day_02.dSYM/Contents/Resources/DWARF/Day_02
Binary files differ
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