Results 1 to 1 of 1

Thread: prolog newbie question.

  1. #1
    Join Date
    Sep 2008
    Location
    Bangalore,India
    Beans
    982
    Distro
    Ubuntu 10.04 Lucid Lynx

    prolog newbie question.

    I'm trying to draw some textual figure astrrick on screen using prolog recursion, like the following.

    ?- bars(3).
    *
    ***
    *****
    *
    *
    ?- bars(4).
    *
    ***
    *****
    *******
    *
    *
    Till now i'm able to draw till this much, i could not figure out how exactly to draw this textual figure. So i ended up writing this junk!

    bars([]).

    bars([N|L]) :-
    stars(N),nl,
    bars(L).

    stars(N) :-
    N>0,
    write(*),
    N1 is N-1,
    stars(N1).

    stars(N) :-
    N=<0.

    Any help would be appreciated. I'm not able to print and show proper asterick in forum post too, basically it starts from middle n descends.
    Last edited by abhilashm86; September 14th, 2011 at 05:52 PM.
    Abhilash Muthuraj-views
    I always believe that Linux,
    "In a world of no walls or fences, we don't need WINDOWS or GATES"
    New to Ubuntu??

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •