Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Logical problem

Name: Anon 2012-03-28 18:28

I'm learning logical in my school and the teacher throw me this exercise, I think the answer is 7. So I'm here to ask a little help please.

---
class Classe2{
int a;
Classe2 b;
}

main (){
Classe2 a,b;
a = new Classe2();
b = new Classe2();
b.b = a;
a.b = new Classe2();
a.a = 1;
a.b.a = 2;
b.a = 3;
b.b.a = a.a + 3;
print (a.a + b.a);
}

Name: Anonymous 2012-03-28 19:16

The answer is actually 9.

Hint: make a diagram showing boxes, like so:


┌───┐b  ┌───┐b
│  ─┼──→│  ─┼──→ ...
└─┼─┘   └─┼─┘        
 a│      a│
  ↓       ↓
  3       1


Save for the snazzy Unicode drawing of cons cells, which took me way too long to make. You should draw the cells and all their initial values first, and then ``correct'' when they are further mutated. Thus the "one" pictured will become... you'll figure it out.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List