Qbasicnews.com
June 23, 2018, 02:42:45 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: 1 [2]
  Print  
Author Topic: Kangaroo problem, np complete :)  (Read 19076 times)
Lanzaa
Forum Regular
**
Posts: 105



« Reply #15 on: October 02, 2003, 11:57:54 PM »

Well can someone post a very simple version of this for me.

This is because I'm in 9th grade math (geometry) and he said it was 10th grade extra credit
so i will be confused
Logged
SCM
Wandering Guru
***
Posts: 311



« Reply #16 on: October 03, 2003, 12:10:45 AM »

Copy the program and run it.  It displays each move.  Use a small number of kangaroos to start.  You should see a pattern.
Logged

hrist Jesus came into the world to save sinners, of whom I am first.(I Timothy 1:15)

For God so loved the world, that He gave His only begotten Son,
that whoever believes in Him should not perish, but have eternal life.(John 3:16)
Lanzaa
Forum Regular
**
Posts: 105



« Reply #17 on: October 03, 2003, 12:19:41 AM »

Sure i can solve it by myself i just need to figure out  how to program it

all i know is the # of steps used = "n + 1" ^ 2
counting the first one >_< as #1
Logged
SCM
Wandering Guru
***
Posts: 311



« Reply #18 on: October 03, 2003, 03:26:55 PM »

Lanzaa,

I am sorry I didn't respond earlier.  I didn't know what to say.  You say that you want to be able to write a program to solve it, but you want a simpler program as an example.  I could rewrite it, but then you wouldn't have the chance to do it yourself.  I am very happy to help you, but if you are to have any satisfaction in writing the program, you will have to do most of the work.

Please, run the program with n = 4.  Then group the moves by which way the moving kangaroo is facing (R or L).  Then look for a pattern in those groups.  This determines your loop structure.  When you think you have it, try it with n = 3 to verify it.  Let me know what you find.  (What is the initial pattern?  When does it change?  What is the next pattern that comes up?  When Does it begin? What happened between these two patterns?)
Logged

hrist Jesus came into the world to save sinners, of whom I am first.(I Timothy 1:15)

For God so loved the world, that He gave His only begotten Son,
that whoever believes in Him should not perish, but have eternal life.(John 3:16)
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #19 on: October 03, 2003, 07:55:37 PM »

Here is my solution. I suddenly remembered it was in my outbox!!  :rotfl:

I also saw a typo... it was "do" instead of "to" in the question....

Code:

'The point of this program is to solve
'the Kangaroo Problem, defined as follows:

'There are N kangaroos crossing a bridge from both sides.
'(so 2N kangaroos total)
'
'They need to get to their respective other sides.
'The only problem is that the bridge is so narrow
'that they can only move forward and not sideways.
'
'At first the kangaroos line up like this: >>>_<<< (n = 3)
'They need to line up like this:           <<<_>>>
'
'Kangaroos can HOP and JUMP.
'A kangaroo HOP moves the Kangaroo forward one space: >_ to _>
'A kangaroo JUMP moves the Kangaroo forward two spaces: ><_ to >_>
'
'How to HOP and JUMP the kangaroos to the other side?
'(two kangaroos can't occupy one space!)
'HINT Try to solve the problems with small N's first!
'
'
'
'

'ANALYSIS
'An analysis of the problem proceeds in the following fashion:
'Try to solve N = 1 through N = 4 yourself, and look at any patterns emerging.
'You will then be able to extrapolate the general method...

' Try N=1
'>_< 0) they meet                      2
'_>< 1) hop one space       HOP  > ++  1
'<>_ 2) jump one space      JUMP < --  3
'<_> 3) hop one space: done HOP  > ++  2

' Now try N=2
'>>_<< 0) they meet                    3
'>_><< 1) hop one space     HOP  > ++  2
'><>_< 2) jump one space    JUMP < --  4
'><><_ 3) hop one space     HOP  < +-  5
'><_<> 4) jump one space    JUMP > -+  3
'_<><> 5) jump one space    JUMP > -+  1
'<_><> 6) hop one space     HOP  < +-  2
'<<>_> 7) jump one space    JUMP < --  4
'<<_>> 8) hop one space     HOP  > ++  3

' Now try N=3
'>>>_<<< 00) they meet                  4
'>>_><<< 01) hop one space   HOP  > ++  3 -1
'>><>_<< 02) jump one space  JUMP < --  5 +2
'>><><_< 03) hop one space   HOP  < +-  6 +1
'>><_<>< 04) jump one space  JUMP > -+  4 -2
'>_<><>< 05) jump one space  JUMP > -+  2 -2
'_><><>< 06) hop one space   HOP  > ++  1 -1
'<>_><>< 07) jump one space  JUMP < --  3 +2
'<><>_>< 08) jump one space  JUMP < --  5 +2
'<><><>_ 09) jump one space  JUMP < --  7 +2
'<><><_> 10) hop one space   HOP  > ++  6 -1
'<><_<>> 11) jump one space  JUMP > -+  4 -2
'<_<><>> 12) jump one space  JUMP > -+  2 -2
'<<_><>> 13) hop one space   HOP  < +-  3 +1
'<<<>_>> 14) jump one space  JUMP < --  5 +2
'<<<_>>> 15) hop one space   HOP  > ++  4 -1

'ANSWER:

CLS
PRINT : INPUT "Number of kangaroos on each side? ", N%
PRINT
move.amount% = N% * N% + 2 * N%
spaces.amount% = N% * 2 + 1
DIM SHARED move(move.amount%) AS INTEGER
DIM SHARED type1(move.amount%) AS INTEGER
DIM SHARED kangaroo.string$: kangaroo.string$ = SPACE$(spaces.amount%)

FOR i% = 1 TO spaces.amount%
SELECT CASE i%
CASE IS < N% + 1: MID$(kangaroo.string$, i%, 1) = ">"
CASE IS = N% + 1: MID$(kangaroo.string$, i%, 1) = "_"
CASE IS > N% + 1: MID$(kangaroo.string$, i%, 1) = "<"
END SELECT
NEXT i%
k% = 0: j% = 0: k2% = 0: counter% = 1: counter2% = 1

FOR i% = 1 TO move.amount% \ 2
IF j% = k% THEN k% = k% + 1: j% = 0: move(i%) = -1 ELSE j% = j% + 1
IF j2% = k2% THEN k2% = k2% + 1: j2% = 1: temp% = 1 - temp% ELSE j2% = j2% + 1
type1%(i%) = temp%
NEXT i%

FOR i% = move.amount% \ 2 + 1 TO move.amount%
i2% = move.amount% - i% + 1: move%(i%) = move%(i2%): type1(i%) = type1(i2%)
NEXT i%

cur.empty% = N% + 1: s1$ = "_"
FOR i% = 1 TO move.amount%
IF type1(i%) THEN next.empty% = cur.empty% - move%(i%) - 2 ELSE next.empty% = cur.empty% + move(i%) + 2
s2$ = MID$(kangaroo.string$, next.empty%, 1)
MID$(kangaroo.string$, next.empty%, 1) = s1$
MID$(kangaroo.string$, cur.empty%, 1) = s2$
cur.empty% = next.empty%
PRINT kangaroo.string$ + " "; : IF move%(i%) THEN PRINT "hop" ELSE PRINT "jump"
IF CSRLIN = 24 THEN
1 : IF INKEY$ = "" THEN GOTO 1
CLS
END IF
NEXT i%

SYSTEM
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #20 on: July 11, 2009, 02:19:16 AM »

I was looking for a binary search on the intertubes, and found this. Sorry to
xhantt. I did not see your post. I believe the correct line should be "'A kangaroo JUMP moves the Kangaroo forward two spaces: >>_ to >_>"

Is it too late?  Cheesy
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Clippy
Member
*
Posts: 84



« Reply #21 on: July 11, 2009, 05:05:58 PM »

LOL, I think so! About 6 years too late!  Roll Eyes
Logged

LPG
Member
*
Posts: 61

semper ubi sub ubi (always wear under wear)


« Reply #22 on: October 30, 2009, 12:21:20 AM »

Lol, there is a flash game of this: http://www.novelgames.com/flashgames/game.php?id=2&l=e
This website has lots of other clever puzzles as well.
Logged

WHILE RPG$ <> "complete" : make up silly excuses :WEND
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #23 on: January 25, 2010, 03:27:48 PM »

Nice.
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Pages: 1 [2]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!