🚀 Day 12 of #30DaysOfCode Back to Learning ! Today I explored a cool concept: 👉 Adding two integers without using the + operator in Python! Instead of +, I used bitwise operations: 🔹 XOR (^) → gives the sum without carry 🔹 AND (&) + LEFT SHIFT (<<) → handles the carry 💻 Code: def add_without_plus(a, b): while b != 0: carry = a & b # common bits (carry) a = a ^ b # sum without carry b = carry << 1 # shift carry to the left return a🧠 How it works: ✔️ XOR adds bits where only one is 1 ✔️ AND finds carry bits ✔️ Shift carry left and repeat until no carry remains 📌 Example: For 5 + 3: 5 = 101 3 = 011 ---------- XOR = 110 (6) AND = 001 → carry = 010 (after shift) Repeat until carry = 0 → result = 8 → Final Result = 8 ✅ ✨ This helped me understand how addition actually works at the binary level! #Python #Coding #30DaysOfCode #Programming #Bitwise #Learning #TechJourney
Adding Integers without Plus Operator in Python
More Relevant Posts
-
Check out my latest blog published blog on Medium about coding practices that made my project cleaner, more structured, and easier to manage. As a student working on my second-semester project, I started applying concepts like modular programming, virtual environments, logging, and secure configuration handling. Initially, they felt like extra effort. But over time, I realized how much they improve code quality and maintainability. In this blog, I’ve shared practical insights on: • Using virtual environments to avoid dependency conflicts • Managing dependencies with requirements.txt • Structuring projects using modular execution • Replacing print statements with proper logging • Keeping configs clean with .ini files • Securing sensitive data using AES encryption These small practices, when combined, make your codebase more professional and scalable. If you're building projects (especially as a beginner), adopting these early can save a lot of time and effort later. Would love to hear your thoughts and feedback! #Python #SoftwareDevelopment #CodingPractices #LearningInPublic #StudentsInTech #Programming #CleanCode https://lnkd.in/gW-QtcgV
To view or add a comment, sign in
-
Learning from Upsolving a Hard Problem on LeetCode Recently, I upsolved a Hard problem from Biweekly Contest 179 on LeetCode, and it gave me a really valuable insight into Dynamic Programming (DP). Key Takeaway: Sometimes, Tabulation fails while Memoization works better. Here’s why 1. In Tabulation (Bottom-Up), we often compute all possible states of the DP table — even those that are never needed to reach the final answer. 2. This can lead to unnecessary computations and, in some cases, TLE (Time Limit Exceeded). 3. In contrast, Memoization (Top-Down) only computes the states that are actually required, thanks to recursion + caching. 4. This makes it more efficient in problems where the state space is large but only a subset is relevant. My Experience: I initially implemented a Tabulation approach, but it resulted in TLE due to redundant state computations. Switching to Memoization helped me compute only the necessary states — and the solution passed efficiently! Lesson Learned: 1. Don’t blindly choose Tabulation over Memoization. 2. Always analyze the state space and transitions. 3. If many states are irrelevant, Memoization might be the better choice. This was a great reminder that choosing the right approach matters just as much as solving the problem itself. #LeetCode #DynamicProgramming #Memoization #Tabulation #Coding #ProblemSolving #TechLearning #SoftwareEngineering #DSA #Upskilling
To view or add a comment, sign in
-
-
LeetCode Progress 32/50 — Generate Parentheses Today I worked on a problem focused on recursion and backtracking 🧩 💡 The challenge was to generate all possible combinations of well-formed parentheses for a given number of pairs. 🧠 Approach: Used a backtracking approach by recursively adding opening and closing parentheses while maintaining valid combinations at each step. This ensured only well-formed patterns were generated. ⏱ Time Complexity: O(4ⁿ / √n) 💡 What I learned: This problem highlighted how backtracking can be used to systematically explore valid combinations while pruning invalid paths early. 📈 Strengthening understanding of recursion and improving confidence in solving pattern-generation problems. #LeetCode #DSA #Backtracking #ProblemSolving #Cpp #CodingJourney #Consistency 🚀
To view or add a comment, sign in
-
-
One step closer🔥 LeetCode Progress 49/50 — Decode Ways I worked on a fundamental problem focused on dynamic programming and string decoding 🧩 💡 The challenge was to find the number of ways to decode a given digit string into letters (A–Z mapping). 🧠 Approach: Used dynamic programming to track valid decoding ways at each index. Handled edge cases like leading zeros and invalid two-digit combinations carefully. ⏱ Time Complexity: O(n) 💡 What I learned: This problem improved my understanding of DP state building and how to break a problem into smaller subproblems with valid transitions. 📈 Strengthening dynamic programming fundamentals and logical thinking for complex string problems. #LeetCode #DSA #DynamicProgramming #Strings #ProblemSolving #Cpp #CodingJourney #Consistency 🚀
To view or add a comment, sign in
-
-
🚀 Day 39 of solving LeetCode problems Today I tackled LeetCode 128: Longest Consecutive Sequence — a great problem to strengthen knowledge of HashSet and optimal searching techniques. 🔹 Problem Summary: Given an unsorted array of integers, find the length of the longest consecutive elements sequence. 🔹 Key Learning: ✅ Using a HashSet helps achieve O(n) time complexity ✅ Efficiently detecting sequence starts avoids unnecessary checks ✅ Importance of optimizing brute-force approaches 🔹 Takeaway: Sometimes the smartest solution is not sorting first — using the right data structure can save a lot of time. #LeetCode #DayChallenge #CodingJourney #Java #DSA #ProblemSolving #Programming #CodingSkills #HashSet #Algorithms
To view or add a comment, sign in
-
-
Shipping software is more than writing code that works locally. I recently built and published QuickQRForge, a lightweight Python package for generating QR codes, and documented the full process from source code to public release. This project was a great opportunity to demonstrate more than just application development: - Python package architecture - CI/CD pipeline automation - release validation - build and publish workflows - public package distribution through PyPI The result is a project that goes beyond “it works on my machine” and shows what it takes to build, automate, and ship software properly. I wrote a breakdown of the full process here: https://lnkd.in/gsaqGwX7 #Python #DevOps #CICD #SoftwareEngineering #PyPI #Automation #GitHubActions #DeveloperTools
To view or add a comment, sign in
-
-
SIGMATEK Automation Always solving problems, finding a way and getting it done. Our Timothy Hatchard once again demonstrates our approach with #LASAL #Python #Github for bootdisc creation and version tracking...bang on... 🎯 #SigmatekUK #SmartAutomation #SDIAS #UKmanufacturing
The problem with automation is that a lot of it isn’t automated... yet. Versioning used to be annoying. In this video I walk through my new typical PLC workflow: create a branch, change logic, commit, open a pull request, review, and merge. The commit is then tagged with a version, an action runner picks it up, triggers Class2 via Python scripting to compile and create a bootdisk, and automatically builds a release containing it and the project files. The bootdisk can be plugged into the PLC to load the project without a laptop. LASAL’s native support for source control, combined with built‑in Python scripting, makes it possible to run reproducible actions directly from GitHub workflows. This enables proper PLC version tracking, traceable changes, and multiple developers working on the same project without losing history. You could take it further by automating unit tests or automating the project revision, but that’s enough for one day. #SigmatekUK #PLC #git #GitHub
To view or add a comment, sign in
-
🚀 #GeeksforGeeks 365 Day Problem Solving 🚀 Day-49 📌 Problem: Given a string s, replace all spaces ' ' with "%20" ✔ Maintain original order ✔ Only replace spaces 🧠 Example: Input: s = "i love programming" ✅ Output: "i%20love%20programming" 💡 Key Insight: ✔ Simple string transformation problem ✔ Each space expands to 3 characters → %20 👉 Just traverse and build result ⚡ Approach: ✔ Initialize empty string result ✔ Traverse each character: If ' ' → append "%20" Else → append character 📊 Complexity Analysis: ⏱ Time Complexity: O(n) 📦 Space Complexity: O(n) 🧠 What I Learned: ✔ Basic string manipulation ✔ Handling character replacement efficiently ✔ Common real-world problem (URL encoding) ✅ Day 49 Completed 🚀 Strengthening basics in String Processing 💪 #GeeksforGeeks #gfg365 #coding #learning #CodingChallenge #ProblemSolving #DSA #365DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 54 | LeetCode Learning Journal Today I solved Range Sum Query Immutable using C++. This problem was a great introduction to optimizing repeated queries using preprocessing! 🔑 Key Points: • Used Prefix Sum Array to store cumulative sums • Precomputed values to avoid recalculating sums every time • Answered each query in O(1) time • Focused on reducing time complexity from brute force O(n) to optimal 🌱 What I Learned: • How preprocessing can drastically improve performance • Concept of prefix sums and their real-world use • Trade-off between space and time complexity • Writing cleaner and efficient query-based logic #LeetCode #100DaysOfCode #DSA #CodingJourney #CPlusPlus #Algorithms #Day54 🚀
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development