QB / QB64 Discussion Forum      Other Subforums, Links and Downloads
 

 Return to Index  

Is This Hello World Long Enough For You?

March 8 2008 at 6:25 AM
qbguy  (no login)


Response to Fun challenge - 'Hello World'

 

DEFINT A-Z
DIM STACK(9999), ARRAY(9999), TARGETS(9999)
X$ = ">+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++++>-] <.>+++++++++++[<++++++++>-]<-.--------.+++.------.--------.[-]>++++++++[<++++>- ]<+.[-]++++++++++.,"
FOR I = 1 TO LEN(X$)
IF MID$(X$, I, 1) = "[" THEN STACK(STACKP) = I: STACKP = STACKP + 1
IF MID$(X$, I, 1) = "]" THEN
IF STACKP = 0 THEN PRINT "Unmatched ]": STOP
STACKP = STACKP - 1
TARGETS(I) = STACK(STACKP)
TARGETS(STACK(STACKP)) = I
END IF
NEXT
IF (STACKP > 0) THEN PRINT "Unmatched [": STOP
FOR I = 1 TO LEN(X$)
SELECT CASE MID$(X$, I, 1)
CASE "+"
ARRAY(MEMP) = ARRAY(MEMP) + 1
CASE "-"
ARRAY(MEMP) = ARRAY(MEMP) - 1
CASE ">"
MEMP = MEMP + 1
CASE "<"
MEMP = MEMP - 1
CASE ","
ARRAY(MEMP) = ASC(INPUT$(1))
CASE "."
PRINT CHR$(ARRAY(MEMP));
CASE "["
IF (ARRAY(MEMP) = 0) THEN
I = TARGETS(I)
END IF
CASE "]"
IF (ARRAY(MEMP) <> 0) THEN
I = TARGETS(I)
END IF
END SELECT
NEXT



 
 Respond to this message   
Responses

 Copyright © 1999-2014 Network54. All rights reserved.   Terms of Use   Privacy Statement