Page 1 of 3 123 LastLast
Results 1 to 10 of 30

Thread: thinBASIC coding challenge #1

  1. #1
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    thinBASIC coding challenge #1

    Hi guys,

    I think some coding challenge from time to time could be nice thing, showing how thinBASIC can be used.
    I would recommend basic, common tasks.

    Here is my idea:

    Assignment
    Write a script which will count all characters in text stored in inString.
    You can use thinBASIC + all standard modules ( which come with default installation ).

    Please use following skeleton, but code should be general - to count occurience of all possible characters from ASCII 0 to 255 ( do not optimize just for characters in "sample" string below )
    [code=thinbasic]

    dim inString as string = repeat$(1000,"Hi there, how it goes ?"+CHR$(0))

    dim t1, t2 as quad

    t1 = gettickcount

    ' ... insert code here ...

    t2 = gettickcount

    ' ... display results here ...

    [/code]
    Output must look as on attached image ( sorted from most to less used ).

    Winner is...
    ...person achieving shortest time of character count

    End of contest
    Friday 13th, April 2007 CHANGED


    I am looking forward to your tries!,
    Petr


    P.S. My version is attached below but do not download it till Friday !
    Attached Images Attached Images
    Attached Files Attached Files
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: thinBASIC coding challenge #1

    Hey Petr,

    thanks for the idea. Nice, nice one.
    Created a dedicated forum.

    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  3. #3
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: thinBASIC coding challenge #1

    Sounds good, I am not good at optimizing but going the other way, slowing down

    Might be good idea to test all final scripts on the same computer to see comparative speeds.

    I hope have time to get involved, been hectic and still lots to do. Good luck!!
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  4. #4
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: thinBASIC coding challenge #1

    Hi,

    Eros, thanks a lot for new section

    kryton - do not give up
    If you will need more time I can move the deadline few days more.
    Comparsion on one computer would be nice, also it is the only method which should reflect results correctly.


    Bye,
    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  5. #5

    Re: thinBASIC coding challenge #1

    Coding challenger?

    I can't be out, what are rules? Can I develop a specific module?
    Please (if possible) extend the expiration date, I will be in vacation until the april 10. >

    Ciao,
    Roberto.
    http://www.thinbasic.com

  6. #6

    Re: thinBASIC coding challenge #1

    Good idea, but count even characters below 32?

  7. #7
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: thinBASIC coding challenge #1

    Roberto,

    rule is simple: just count every ascii char in inString and for each report number of occurences.
    Petr did also a substitute loop to be able to print out chars below code 32.

    Ciao
    Eros

    PS: vacation? ???
    Who authorized them ;D
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  8. #8
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: thinBASIC coding challenge #1

    Hi,

    Mike - yes, of course Full old good ASCII ( tabelator as well as cr, lf are used frequently )
    Roberto - as you have no authorization for vacations ...
    Ok, moved end of contest to Firday 13th to make contest accessible for all.
    But I can't accept module as contest entry, you would depress us with some assembly light speed ;D
    Just thinBASIC + any of standard modules.


    Bye and thanks,
    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  9. #9
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: thinBASIC coding challenge #1

    OK, here it is my version.
    I will entitle it "The power of pointers". See results

    Ciao
    Eros

    UPDATED: added comments
    Attached Images Attached Images
    Attached Files Attached Files
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  10. #10

    Re: thinBASIC coding challenge #1

    Wow I see, you are power(s basic) users ;D

    Here is my version

    [code=thinbasic] uses "Stat"

    dim inString as string = repeat$(1000,"Hi there, how it goes ?"+CHR$(0))
    dim n as long = len(inString)
    dim aData1(n) as byte
    dim aData2(n*2) as DWORD
    dim aData(256) as string
    dim i as long
    dim sText as string
    dim s as string
    dim t1, t2 as quad

    t1 = gettickcount

    poke$(varptr(aData1(1)),PeeK$(STRPTR(inString),n))
    Stat_CopyArray(aData1, aData2)
    Stat_Histogram(aData2,1)

    for i=1 to 256
    if aData2(i+n)>0 then
    select case aData2(i)
    case 0
    s=" NUL"
    case 32
    s=" SPC"
    case else
    s=" "+chr$(aData2(i))
    end select
    aData(i)=ltrim$(str$(aData2(i + n)))+" "+s
    end if
    next

    array sort aData, descend

    for i=1 to 256
    if len(aData(i)) then
    sText=sText+aData(i)+$CRLF
    end if
    next

    t2 = gettickcount
    msgbox 0, "Result of text analysis ("+ltrim$(STR$(n))+" bytes)"+$CRLF+$CRLF+sText+$CR+$CR+"Operation took:"+STR$( (t2-t1)/1000, 3)+" seconds", %MB_OK or %MB_ICONINFORMATION, "Results"
    [/code]

    I don't post result here, please take a pleasure to discovery it by yourself.

    Regards,
    Roberto
    http://www.thinbasic.com

Page 1 of 3 123 LastLast

Similar Threads

  1. tbgl coding challenge
    By kryton9 in forum TBGL General
    Replies: 4
    Last Post: 10-06-2007, 21:42

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

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