Page 3 of 6 FirstFirst 12345 ... LastLast
Results 21 to 30 of 56

Thread: Beginner Programming Challenge 13

  1. #21
    Join Date
    Apr 2007
    Location
    NorCal
    Beans
    1,149
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Beginner Programming Challenge 13

    Quote Originally Posted by lavinog View Post
    Does assigning __actions in the class initializer waste memory when there are multiple Account objects?
    Won't there be multiple copies of this list for each account?
    I'm calling instance methods, so the dictionary containing them has to be an instance variable.

    Also how did you add the color? (did you manually do it, or is there a tool?)
    http://www.challenge-you.com/bbcode
    Last edited by schauerlich; June 7th, 2010 at 08:30 AM.
    Posting code? Use the [code] or [php] tags.
    I don't care, I'm still free. You can't take the sky from me.

  2. #22
    Join Date
    Jan 2010
    Location
    Not Texas
    Beans
    340
    Distro
    Ubuntu 14.04 Trusty Tahr

    Lightbulb Re: Beginner Programming Challenge 13

    Quote Originally Posted by lisati View Post
    Huh? I wasn't think of lists, but of debit and credit.

    In a real-world bookkeeping system......
    Yeah, strike the part about not having a resizeable array. I think I edited that out, if not you can use a resizeable array. I will only create 200 account numbers in my test and will only expect 200 to be created. Nobody has to implement a static limit, however. Please read the rest of this post to understand why. Otherwise, your code is fine.


    Notarika>
    Quote Originally Posted by Notarika View Post
    To clarify, according to the contest rules, does using the stl iterator violate the rules? E.g.
    OK, from what I see, is not 'iter' similar to the list with comparable built-in functions accompanying it? If so, it is acceptable given the same restrictions set for the other one. Simple built-in functions are acceptable such as insert, append...

    So yes, that is acceptable.


    For everybody else too>
    Anyways, for others as well, after anybody uploads code, within 24 hours I will test your code. Then I will PM you on how the program handled everything, general comments, as well as the time it took to handle 2100 random. The real final test will include something like 10,000 or 20,000 randomly generated transactions.

    How verbose the program is varies on the programmers tastes as long as, at the very least, the end balance of the accounts is apparent. Even just printing the balance at the end of each transaction would work perfectly. One person just printed the balances at the very end. Either of these implementations is fine.

    Finally, just a quick bit about judging. Although most of the categories will be more or less pass/fail, which will be a cursory glance for me, one category will be looked at much closer. I have simply divided the points among each category [25% each] and then the extra credit [20% extra]. The hash key will be challenging, though rewarding to learn and for judging consideration. Edit: in light of recent changes to make this challenge more beginner friendly, how much someone learns/grows with their program will be considered. It's hard to really elaborate on this, but needless to say it's of benefit to any programmers poking their head into the world of programming.

    To summarize the above again, most people *should* get 75% of the points. If you use a hash key to store/retrieve account numbers and/or balances you will be simply awarded the 20% [supposing it is genuinely used]. Otherwise, the contest will come down to time.

    The only one worth mentioning in detail is the time. Here is exactly how I will judge who gets what for their time. First off, I will make a file with 10,000 or 20,000 account numbers. I will have transactions for non-existing account numbers. If an account number doesn't exist AND the transaction is not a deposit [or something that does the same thing], the account number should not be created. I will put alot of non-existent account numbers in there and I will put a penalty in this category if account numbers are just blindly created. I'm really testing how fast your subroutine searches for account numbers and the only way to really test it is to see how long it takes to go through all your account numbers [if applicable].

    Anyways, so let's say we have the following times for processing the file:

    Person 1: 5 seconds
    Person 2: 4 seconds
    Person 3: 2 seconds
    Person 4: .5 seconds
    Person 5: .6 seconds

    Person 4 has the lowest time and will be awarded 100% of points for this category. Here is how the rest's points will be calculated.

    Person 1: 1/(5/.5) = 10%
    Person 2: 1/(4/.5) = 12.5%
    Person 3: 1/(2/.5) = 25%
    Person 4: 1/(.5/.5)= 100%
    Person 5: 1/(.6/.5)= 83.3%

    Please note: I will post everybody's times [possibly anonymously, as in just a list of times] one week before the competition ends to give people a chance to possibly change. Since I would have PM'ed you your time(s), you can easily know what score you will get here.

    Like I said, this will be the only category that will be assessed technically, the rest are essentially pass fail. I want the challenge to be a learning experience, and if you wrote good, readable, straight-forward code, I want you to know this. I'm not trying to nit-pick anyone. The speed is important however.

    That said, kudos to those who have submitted code so far and I look forward to seeing more novel implementations by others.

    Keep up the great work!!
    Last edited by texaswriter; June 8th, 2010 at 06:27 AM.

  3. #23
    Join Date
    Sep 2009
    Location
    UK
    Beans
    535
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Beginner Programming Challenge 13

    @schauerlich, I like how your bank has an overdraft charge!

    Quote Originally Posted by texaswriter View Post
    If an account number doesn't exist AND the transaction is not a deposit [or something that does the same thing], the account number should not be created. I will put alot of non-existent account numbers in there and I will put a penalty in this category if account numbers are just blindly created.
    My current program does create accounts if they don't exist. How will the list of valid accounts be made available to the program? Will the file be passed in as a filename as a command line argument or something different?
    DMedia - Distributed Media Library
    LaVida - A simulation game for Linux
    AskUbuntu

  4. #24
    Join Date
    Sep 2009
    Location
    UK
    Beans
    535
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Beginner Programming Challenge 13

    Here is a perl version that is significantly faster than my ruby version (though a bit uglier too). This version does not create accounts out of thin air like the other one did:

    Code:
    #!/usr/bin/env perl
    #
    #       challenge13.pl
    #       
    #       Copyright 2010
    #       
    #       This program is free software; you can redistribute it and/or modify
    #       it under the terms of the GNU General Public License as published by
    #       the Free Software Foundation; either version 2 of the License, or
    #       (at your option) any later version.
    #       
    #       This program is distributed in the hope that it will be useful,
    #       but WITHOUT ANY WARRANTY; without even the implied warranty of
    #       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    #       GNU General Public License for more details.
    #       
    #       You should have received a copy of the GNU General Public License
    #       along with this program; if not, write to the Free Software
    #       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
    #       MA 02110-1301, USA.
    
    use strict;
    use warnings;
    
    #if --speed is given as the first argument, the program will go as fast as it can
    #if --debug is given the program will print the balance after each transaction
    #otherwise the program will just try to make the results look nice
    
    my $mode = 2;
    if ($ARGV[0] eq '--debug') {
    	$mode = 1;
    } elsif ($ARGV[0] eq '--speed') {
    	$mode = 0;
    }
    
    my %accounts = ();#hash for storing/retrieving accounts
    
    sub dep { #function to deposit money into account
    		my ($account, $amount) = @_;#arguments - account_number, amount
    		if (exists $accounts{$account}) {#if account exists
    				$accounts{$account} += $amount; #add deposit amount to account balance
    		} else {#if account doesn't exist
    				$accounts{$account} = $amount; #create account with balance amount
    		}
    		return $accounts{$account}; #return new balance
    }
    
    sub fee { #function to charge a fee to the account
    		my ($account, $amount) = @_;#arguments - account_number, amount
    		if (exists $accounts{$account}) {#if account exists
    				$accounts{$account} -= $amount; #take fee amount from account balance
    		} else {#if account doesn't exist
    				warn "What do you mean '$account', there is no such account!\n";
    		}
    		return $accounts{$account}; #return new balance
    }
    
    sub wd { #function to withdraw from account
    		my ($account, $amount) = @_;#arguments - account_number, amount
    		if (exists $accounts{$account}) {#if account exists
    				if ($accounts{$account} >= $amount) {#only succeed if enough balance
    					$accounts{$account} -= $amount; #take fee amount from account balance
    				} else {
    					warn "You can't withdraw $amount if you only have $accounts{$account}!\n";
    				}
    		} else {#if account doesn't exist
    				warn "What do you mean '$account', there is no such account!\n";
    		}
    		return $accounts{$account}; #return new balance	
    }
    
    sub parse {
    		my $str = shift;
    		my ($trans, $account, $amount) = split(' ', $str);
    		#parse transaction_type account_num amount
    		$amount += 0; #turn amount into a number
    		$account += 0; 
    		#ensure account is a number. This ensures numerical sorting of accounts as a opposed to alphabetical
    		if ($trans eq 'wd' || $trans eq 'cred') {#withdraw commands
    				return wd($account, $amount);
    		} elsif ($trans eq 'fee') {#fee command
    				return fee($account, $amount);
    		} elsif ($trans eq 'dep' || $trans eq 'deb') {#deposit commands
    				return dep($account, $amount);
    		} else {#warning on incorrect commands
    				warn "'$trans' is not a transaction I understand! I do understand:\n
    	dep or deb = where money is put in
    	wd or cred = where money is taken out (as long as you have enough)
    	fee = where money is taken out (even if you don't have enough)\n";
    		} 
    		return '0';
    }
    
    if ($mode == 1) {#debug
    	while (<STDIN>) {#loop over input
    		print "BALANCE: £" . parse($_) . "\n";#apply transactions and print new balance
    	} 
    } else {
    	while (<STDIN>) {#loop over input
    		parse($_);
    	} 
    }
    
    print "-" x 33 . "\n";
    
    if ($mode) {
    		foreach (sort {$a <=> $b} keys(%accounts)) {
    			print "Account: $_   Balance: £$accounts{$_}\n";
    		}
    } else {#speed
    		foreach (keys(%accounts)) {
    			print "Account: $_   Balance: £$accounts{$_}\n";
    		}
    }
    I've tested it along side the other versions using a randomly generated file of 100000 transactions and 9 accounts. For some reason all gave slightly different end values. I can't work out why.

    Here are the final values from my generated file:

    Code:
    D:
    Account: 0   Balance: £1802
    Account: 1   Balance: £121082
    Account: 2   Balance: £49366
    Account: 3   Balance: £82473
    Account: 4   Balance: £85320
    Account: 5   Balance: £30468
    Account: 6   Balance: £8256
    Account: 7   Balance: £83802
    Account: 8   Balance: £133931
    time:
    real	0m0.700s
    user	0m0.644s
    sys	0m0.052s
    
    
    perl:
    Account: 0   Balance: £1802
    Account: 1   Balance: £121082
    Account: 2   Balance: £49366
    Account: 3   Balance: £82482
    Account: 4   Balance: £85327
    Account: 5   Balance: £30468
    Account: 6   Balance: £8287
    Account: 7   Balance: £83802
    Account: 8   Balance: £133931
    time:
    real	0m5.260s
    user	0m0.568s
    sys	0m0.232s
    
    
    python:
    Account: 0   Balance: £1886.0
    Account: 1   Balance: £121012.0
    Account: 2   Balance: £49427.0
    Account: 3   Balance: £82461.0
    Account: 4   Balance: £85291.0
    Account: 5   Balance: £30552.0
    Account: 6   Balance: £8262.0
    Account: 7   Balance: £83858.0
    Account: 8   Balance: £134224.0
    time:
    real	0m16.346s
    user	0m1.556s
    sys	0m0.512s
    
    
    ruby:
    Account: 0   Balance: £1799.0
    Account: 1   Balance: £120789.0
    Account: 2   Balance: £49354.0
    Account: 3   Balance: £81845.0
    Account: 4   Balance: £85353.0
    Account: 5   Balance: £30411.0
    Account: 6   Balance: £8317.0
    Account: 7   Balance: £83781.0
    Account: 8   Balance: £133888.0
    time:
    real	1m11.668s
    user	0m9.665s
    sys	0m13.201s
    Last edited by dv3500ea; June 8th, 2010 at 02:16 PM. Reason: The printed accounts are now in numerical order not alphabetical
    DMedia - Distributed Media Library
    LaVida - A simulation game for Linux
    AskUbuntu

  5. #25
    Join Date
    Jan 2008
    Beans
    4,757

    Re: Beginner Programming Challenge 13

    Quote Originally Posted by dv3500ea View Post
    I've tested it along side the D version and the python version. For some reason all 3 give slightly different end values. I can't work out why.
    Oh the inconsistencies!

    dv3500, if you compile the D code with -fdebug it will print out all calculations as it does it.

    Do the same for Perl, and if an inconsistency crops up between return values, see what the number is and what the return value *should* be.

    Regards
    Last edited by ibuclaw; June 7th, 2010 at 04:11 PM.

  6. #26
    Join Date
    Jan 2008
    Beans
    4,757

    Re: Beginner Programming Challenge 13

    Actually, I've just made a slight adjustment on my side, switched to longs instead of doubles. Probably loose some precision, but gains some more speed.

    Regards

  7. #27
    Join Date
    Sep 2009
    Location
    UK
    Beans
    535
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Beginner Programming Challenge 13

    On running the following for each program:
    Code:
    fee 1 1
    deb 2 1
    dep 3 1
    wd 4 1
    cred 5 1
    I get:
    Code:
    D:
    Account: 1	Balance: £-1
    Account: 2	Balance: £1
    Account: 3	Balance: £1
    Account: 4	Balance: £0
    Account: 5	Balance: £0
    
    perl:
    Account: 2   Balance: £1
    Account: 3   Balance: £1
    
    python:
    Account: 2   Balance: £1.0
    Account: 3   Balance: £1.0
    
    ruby:
    Account: 1   Balance: £-1.0
    Account: 2   Balance: £1.0
    Account: 3   Balance: £1.0
    Account: 4   Balance: £0
    Account: 5   Balance: £0
    That explains some of the difference, although not the differences between the perl + python version and D + ruby. It's possible for the ruby version I forgot to clear /tmp files

    Oh yeah, the python version charges 10 on overdraft.
    Last edited by dv3500ea; June 7th, 2010 at 09:11 PM.
    DMedia - Distributed Media Library
    LaVida - A simulation game for Linux
    AskUbuntu

  8. #28
    Join Date
    Jan 2010
    Location
    Not Texas
    Beans
    340
    Distro
    Ubuntu 14.04 Trusty Tahr

    Exclamation Re: Beginner Programming Challenge 13

    Quote Originally Posted by dv3500ea View Post
    @schauerlich, I like how your bank has an overdraft charge!



    My current program does create accounts if they don't exist. How will the list of valid accounts be made available to the program? Will the file be passed in as a filename as a command line argument or something different?
    Schauerlich> Great questions: First off, don't worry about files being passed, though if built-in routines are already there you can leave them there [if you wish]... I will redirect input, so act like all input is going to come from the keyboard.

    I will specifically design the test file to only deposit money in 200 accounts. So, as was said above, *no built-in checks need to be made on whether 200 accounts were entered*. Essentially, just assume an account needs to be created when it doesn't exist & a deposit or debit is being made [i.e. money being put into the account].

    To everybody> I do want to reiterate this: This Beginner Programming Challenge was intended to teach people the use of hash keys by having beginners research hash keys and implement their own. To extend the challenge to people who don't feel comfortable doing this yet, any competitors who merely complete the functionality any way of their choosing are welcome as well. This competition is also to anyone who feels challenged, so if at first you just need to build the program without a hash routine, I welcome you to compete at the level you need to to properly learn. Afterwards, if you need further challenge, you can consider research hashing routines.

    If the scoring daunts you, just ignore it and enjoy learning and completing the challenge. Anybody who even participates has won because they have gained experience and otherwise learned. Since I will only be judging beginner's challenges, don't worry about your code not "measuring up".

    Otherwise, please enjoy your experience and I welcome more beginner programmers.

    Non-beginner programmers> If anybody feels they are not a beginner, you are feel to write code for the competition and even send it to me, but I would ask that inform me if you are an advanced programmer so I know who to consider. Also, if you are an advanced programmer try to restrain from submitting code *right away*. Wait a week or two before submitting code if you are a non-beginner.

    Ibuclaw> EDIT: I'm allowing these basic hash routines that seem to be built-in to many languages array functions. This doesn't count for extra credit. I highly recommend beginners first make their program with whatever storage/retrieval method they want, then afterwards try to make their own hashing routine just for the practice. This is a reversal of what was here previously. I had no idea so many languages implemented hash methods in basic arrays. This reversal is to make the competition as beginner-friendly as possible. I understand it can be daunting making a program that encompasses a lot of ground. Try making a viable program using whatever account retrieval/storage method you can and then worry about trying different methods later.

    Good luck and have fun!!
    Last edited by texaswriter; June 8th, 2010 at 06:23 AM.

  9. #29
    Join Date
    Sep 2009
    Location
    UK
    Beans
    535
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Beginner Programming Challenge 13

    Quote Originally Posted by texaswriter View Post
    If anybody else is aware of a similarity in their code, I would ask that you inform me and/or reimplement this feature.
    I'm not exactly sure what a hashing routine is, but perl has an inbuilt data type called a hash which consists of key/value pairs (I think this is the same as a ruby hash, a python dict or a javascript object). I have used this as the main storage/retrieval mechanism for accounts. The keys of the hash are account numbers and the values are balances.

    Quote Originally Posted by ibuclaw View Post
    Actually, I've just made a slight adjustment on my side, switched to longs instead of doubles. Probably loose some precision, but gains some more speed.
    I can't do that in perl - it decides for you what type (int/float) the number is. My main optimisation has been to not write to stdout until the end of the program. This makes a surprisingly large speed improvement; approximately by a factor of 10.
    DMedia - Distributed Media Library
    LaVida - A simulation game for Linux
    AskUbuntu

  10. #30
    Join Date
    Apr 2007
    Location
    NorCal
    Beans
    1,149
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Beginner Programming Challenge 13

    Quote Originally Posted by dv3500ea View Post
    I can't do that in perl - it decides for you what type (int/float) the number is. My main optimisation has been to not write to stdout until the end of the program. This makes a surprisingly large speed improvement; approximately by a factor of 10.
    I/O is a huge time killer. I wasn't going for speed, I wanted to make it as clear as possible what transactions were and weren't performed, and why.
    Posting code? Use the [code] or [php] tags.
    I don't care, I'm still free. You can't take the sky from me.

Page 3 of 6 FirstFirst 12345 ... LastLast

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
  •