4.0

4.0 | 1 rating Rate this file 3 Downloads (last 30 days) File Size: 1.59 KB File ID: #35787

Recursive Integer Guessing Game

by Adam Gripton

 

21 Mar 2012

A recursive algorithm that queries an objective function to guess an unknown integer.

| Watch this File

File Information
Description

An integer guessing 'game' for a
function `isleq', that returns true for
all values less than or equal to a
mystery number.

Syntax: z=guessgame(isleq,n,k)

In tertiary function notation:

g(n,k) =
  | k==0 :: isleq(n) ? n : n+1;
  | k>0 :: isleq(n+(2^k)-1) ?
            g(n,k-1) : g(n+2^k,k-1);
  | k<0 :: isleq(n+(2^(-k))-1) ?
        g(n,(-k)-1) : g(n+(2^(-k)),k-1);

g(n,-k) for -k negative refers to an
unbounded search [n,inf] with current
search depth up to (n+2^(-k)-1) :

e.g. g(15,-4) denotes [15,30].

g(n,k) for k positive refers to a
search over the interval
[n,(n+(2^(k+1))-1)] :

e.g. guess(63,5) denotes [63,126].

Initial function should be run with n
set as a lower bound (default 1).

Function isleq can be replaced with an
integer instead.

Required Products MATLAB
MATLAB release MATLAB 7.14 (R2012a)
Tags for This File  
Everyone's Tags
binary, bound, divergent, function, game, guess, integer, recursion, recursive, search, tree
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (1)
14 Jun 2012 jackal tao

cool

Contact us