Author |
Topic: Abstract Computer (Read 2827 times) |
|
irrational
Junior Member
Gender:
Posts: 52
|
|
Abstract Computer
« on: Sep 14th, 2006, 10:28am » |
Quote Modify
|
Another M$ interview Question: You have an abstract computer. A variable is defined as a entity that can store a number. You can use as many variable as you need, there are no negetive numbers, all numbers are integers. You do not know the size of the integers, they could be infinitely large, so you can't count on truncating at any point. There are no comparisons allowed, no if statements or anything like that. There are only four operations you can do on a variable. a) You can set a variable to 0. b) You can set a variable = another variable. c) You can increment a variable(only by 1), and its a post increment. d) You can loop. So, if you were to say loop(v1) and v1 = 10, your loop would execute 10 times, but the value in v1 wouldn't change so the first line in the loop can change value of v1 without chaning the no of times you loop. You need to do 2 things. (i) Write a function that decrements by 1. (ii) Write a function that subtracts one variable from another. You can use as many variable as you need, there are no negetive numbers, all numbers are integers. You do not know the size of the integers, they could be infinitely large, so you can't count on truncating at any point. There are NO comparisons allowed, no if statements or anything like that.
|
|
IP Logged |
|
|
|
SMQ
wu::riddles Moderator Uberpuzzler
Gender:
Posts: 2084
|
|
Re: Abstract Computer
« Reply #1 on: Sep 14th, 2006, 10:55am » |
Quote Modify
|
here --SMQ
|
|
IP Logged |
--SMQ
|
|
|
irrational
Junior Member
Gender:
Posts: 52
|
|
Re: Abstract Computer
« Reply #2 on: Sep 14th, 2006, 11:55am » |
Quote Modify
|
Sorry for the re-post.
|
|
IP Logged |
|
|
|
SMQ
wu::riddles Moderator Uberpuzzler
Gender:
Posts: 2084
|
|
Re: Abstract Computer
« Reply #3 on: Sep 14th, 2006, 12:06pm » |
Quote Modify
|
No need to be that embarrassed about it. Happens all the time around here, and we all know that the Search functions are rudimentary at best... --SMQ
|
|
IP Logged |
--SMQ
|
|
|
|