Today I practised two interesting logical thinking problems.
My main goal was not to write a program immediately. Instead, I wanted to understand the problems think about the logic and solve them step by step.
1. Chocolate Wrapper Problem
Chocolate Wrapper Problem
Given:
Total money = ₹100
1 chocolate = ₹5
3 wrappers = 1 additional chocolate
Step 1: Buy chocolates
₹100 ÷ ₹5 = 20 chocolates.
Step 2: Exchange wrappers
Initially, 20 chocolates = 20 wrappers.
Exchange 18 wrappers for 6 chocolates.
Now you have 2 old wrappers + 6 new wrappers = 8 wrappers.
Exchange 6 wrappers for 2 chocolates.
Now you have 2 wrappers + 2 new wrappers = 4 wrappers.
Exchange 3 wrappers for 1 chocolate.
Now you have 2 wrappers + 1 new wrapper = 3 wrappers.
Exchange 3 wrappers for 1 chocolate
20 + 6 + 2 + 1 + 1 = 30 chocolates
I had ₹100 and each chocolate cost ₹5.
Initially I could buy 20 chocolates. After that I used the wrappers to exchange them for additional chocolates.
I repeated the exchange process until I could not exchange any more wrappers.
My final answer: 30 chocolates.
2. Chapathi Story
Next morning 8 chapathis were remaining.
We need to find the original number of chapathis (n).
Step 1: Work backwards
After dinner remaining chapathis = 8.
He ate 1/3 at dinner so 2/3 remained.
Therefore:
8*3/2=12
Before dinner = 12 chapathis.
Step 2: Before lunch
He ate 1/3 at lunch, so 2/3 remained.
12*3/2=18
Before lunch = 18 chapathis.
Step 3: Before breakfast
He ate 1/3 at breakfast so 2/3 remained.
18*3/2=27
Original chapathis = 27.
In this problem Viyan ate one-third of the remaining chapathis during breakfast, lunch and dinner.
The next morning 8 chapathis were remaining.
Instead of calculating forwards I decided to work backwards.
After doing the calculations I found that the maid originally prepared 27 chapathis.
My final answer: 27 chapathis.
What I Learned
- Logical thinking is important before programming.
- Dry runs help us understand each calculation.
- Flowcharts help us visualise the solution.
- Working backwards is a useful problem-solving technique.
- Programming becomes easier when the logic is clear.
Top comments (0)