• Re: ?Hello World? Under ITS On PDP-10

    From Anthk@3:633/10 to All on Thu Apr 2 14:03:50 2026
    Mon, 19 Jan 2026 12:12:38 -0500, jayjwa wrote:

    Lawrence D?Oliveiro <ldo@nz.invalid> writes:

    a debugger as your primary user interface, instead. Using the system
    involves issuing an interesting mix of debugging-specific commands
    You're a glass is half full person, eh?

    ITS has C, too, although it's far different than the C we know today or
    even the C in TOPS-20.

    /* guess.c
    * Simple number-guessing game. Enter your guess and try to * match the
    winning number between BEGIN and END. Your * performance will be graded
    if you win.
    * This version was ported from the TOPS-20 KCC version and is * for
    Synder CC. It is very hacky & does no error checking. It * will likely
    break if given wrong input. TODO: Fix this.
    *
    * Build:
    * copy clib; c10std c to your work area (change includes if needed)
    * cc c10std.c * cc guess.c * stinkr * =x c/clib * =l c10std.stk * =l
    guess.stk * =o ts.guess */
    #include "c/stdio.h"
    #include "c/cc.h"

    /* Define the number span the user should guess in. */
    #define BEGIN 1 #define END 50

    int random( min, max ); /* Return rand int between min-
    max
    */
    int get2int( void ); /* Get (up to) 2 digit integer from user
    */


    int main( void ) {
    int guess; /* The user's guess */
    int answer; /* The winning number */
    int tries; /* Running total of attempts by user */

    /* Init stdio and friends as directed by clib; c10std c */
    stdio();

    /* Initialize tries, get the user's guess, and explain
    * what is being done in terms of the game.
    */
    tries = 1;
    cprint( "\t *** Number guessing game! *** \n" );
    cprint( "Try to guess the number between %d and %d.\n", BEGIN,
    END );

    /* Get a randomish number from BEGIN to END */
    answer = random( BEGIN, END);

    /* Loop until success or the user exits with ctrl-z */
    do {
    cprint( "Your guess (ctrl-z to quit): " );
    /* There is no scanf() in Synder C nor strtol! */
    guess = get2int();

    /* cprint( "[DEBUG]: guess is %d.\n", guess );
    cprint( "[DEBUG]: answer is %d.\n", answer ); */

    /* Eval the guess */
    if ( guess < answer ) {
    cprint( "\nGuess higher! -->\n" );
    } else if ( guess > answer ) {
    cprint( "\n\t\t<-- Guess lower!\n" );
    } else {
    cprint( "\n\tBINGO!\n" );

    /* Grade player performance */
    switch ( tries ) {
    case 1:
    cprint( "\nRating: Guessing god. (%d try)
    \n", tries );
    break;
    case 2:
    case 3:
    cprint( "\nRating: Guessing pro. (%d
    tries)\n", tries );
    break;
    case 4:
    case 5:
    case 6:
    cprint( "\nRating: Average guesser. (%d
    tries)\n", tries );
    break;
    default:
    cprint( "\nRating: You're not very good
    at
    this game, are you?\n" );
    }
    /* Exit loop because the player won. */
    break;
    }
    /* Increment the number of tries the player will have
    * needed to win.
    */
    tries++;
    } while ( guess != answer );

    return 0;
    }

    /* Return a randomish integer between min and max integer */
    int random( min, max ) int min, max; {
    int num;

    /* Until I know of a better way to do this, this will
    * work for a game.
    */
    srand( etime() );
    num = rand() % END + BEGIN;
    /* rand() gives a negative occasionally, and goes one
    * below the minimum, BEGIN. Fix this here.
    */
    if ( num < 0 ) num = num * -1;
    if ( num == 0 ) num++;
    return num;
    }

    /* Get (up to) a double digit ASCII Dec integer from stdin and return
    its
    * proper integer value to the caller, converting from the decimal *
    equal that ITS saves for the char the user enters.
    */
    int get2int( void ) {
    int num1, num2;

    /* We must call cgeti twice if we want a two-digit integer. */
    num1 = cgeti( stdin );
    num2 = cgeti( stdin );

    /* Handle case where the user enters one digit then presses
    * Enter. Eat the user's newline if they enter two digits. */
    if ( num2 != '\n' ) getchar();
    /* cprint( "[DEBUG]: num1 is %c num2 is %c\n", num1, num2 ); */

    /* Now the decimal equal of the character must be converted
    * to an actual single integer. Eg, if the user enters "6"
    * the variable will store the number 54 (as in ASCII table).
    */
    if ( (num1 >= 48) && (num1 <= 57) ) {
    /* Adjust to the integer else zero out */
    num1 = num1 - 48;
    } else num1 = 0;
    if ( (num2 >= 48) && (num2 <= 57) ) {
    /* Adust as above. There is a valid integer in
    * slot 2. Return using both slots. That is,
    * tens place and ones place.
    */
    num2 = num2 - 48;
    return (num1 * 10) + (num2 * 1);
    } else {
    /* Slot 2 (one's place) is not valid (eg, users enters
    "3")
    * because it is outside 0-9 range. Return just num1 */
    return num1;
    }
    }

    /* EOF */


    *guess?K!
    *** Number guessing game! ***
    Try to guess the number between 1 and 50.
    Your guess (ctrl-z to quit): 35

    <-- Guess lower!
    Your guess (ctrl-z to quit): 25

    <-- Guess lower!
    Your guess (ctrl-z to quit): 15

    <-- Guess lower!
    Your guess (ctrl-z to quit): 10

    Guess higher! -->
    Your guess (ctrl-z to quit): 12

    Guess higher! -->
    Your guess (ctrl-z to quit): 13

    BINGO!

    Rating: Average guesser. (6 tries)

    :KILL *

    No need for C, even. That under Maclisp would be dumb easy. If you know
    Common Lisp or Elisp, you are at home. Switch the number base to decimal first, and the rest it's just a simple procedure.

    --- PyGate Linux v1.5.13
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Rich Alderson@3:633/10 to All on Thu Apr 2 14:59:52 2026
    Anthk <bozo@dev.null> writes:

    Mon, 19 Jan 2026 12:12:38 -0500, jayjwa wrote:

    [ snip and entire 200 line Pascal program that was unnecessary to quote ]

    No need for C, even. That under Maclisp would be dumb easy. If you know Common Lisp or Elisp, you are at home. Switch the number base to decimal first, and the rest it's just a simple procedure.

    Just to add these three lines.

    Don't do that.

    --
    Rich Alderson news@alderson.users.panix.com
    Audendum est, et veritas investiganda; quam etiamsi non assequamur,
    omnino tamen proprius, quam nunc sumus, ad eam perveniemus.
    --Galen

    --- PyGate Linux v1.5.13
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)