Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Interesting gismo
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Aange10




PostPosted: Sat Dec 17, 2011 1:56 pm   Post subject: Interesting gismo

This little bucket sorter I used in helping somebody a while back. I find it entertaining to make it execute organizing like 100,000 numbers. (Pretty sure 600K numbers is 40 something billion repetitions of the for loop xD)

Anyways, enjoy.

Turing:
% ________ Record _________
type BucketData :
    record
        num, name : string
    end record
   
% ________ Get the Input _________
var n : int
put "How many numbers would you like to organize?"
get n
var number : array 1 .. n of int
var buckets : flexible array 1 .. 0 of BucketData

View.Set ("offscreenonly")
% ________ How many  buckets we will have ________
new buckets, ceil (n / 10)


% _________ Intialize ________
for i : 1 .. upper (number)
    % Random number between 1 and whatever n is
    number (i) := Rand.Int (1, n)
end for

for i : 1 .. upper (buckets)
    buckets (i).num := ""
    buckets (i).name := "Bucket " + intstr ((i * 10) - 9) + " - " + intstr (i * 10)
end for



% ________ Organize the Bucket (by 10s) ________
% Go through by 10s
for j : 10 .. upper (number) + 10 by 10
    % Go through the array
    for i : 1 .. upper (number)
        if number (i) > (j - 10) and number (i) <= j then
            % We are using a string so we don't add our numbers, and we
            % use | so we can tell the numbers apart
            buckets ((j div 10)).num += intstr (number (i)) + "|"
        end if
    end for
    cls
    put "Loading: ", (j/(upper(number) + 10)) * 100, "%"
    View.Update
end for

View.Set ("text")
% _________ Show the buckets __________
for i : 1 .. upper (buckets)
    put buckets (i).name + ": " + buckets (i).num
end for
View.Update

Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: