cfoley's Profile User Rating: -----

Reputation: 1939 Grandmaster
Group:
Mentors
Active Posts:
4,026 (1.67 per day)
Joined:
11-December 07
Profile Views:
57,222
Last Active:
User is offline Yesterday, 11:31 PM
Currently:
Offline

Previous Fields

Country:
GB
OS Preference:
Who Cares
Favorite Browser:
Who Cares
Favorite Processor:
Who Cares
Favorite Gaming Platform:
Who Cares
Your Car:
Who Cares
Dream Kudos:
225
Expert In:
Java

Latest Visitors

Icon   cfoley has not set their status

Posts I've Made

  1. In Topic: Ramblings of a Python Beginner

    Posted 23 Jul 2014

    I'm not a fan of Processing. I don't really understand what it offers over any other language. You can draw stuff and do animations in Python too.
  2. In Topic: Ramblings of a Python Beginner

    Posted 23 Jul 2014

    Quote

    I would love to learn to make my own tools and extensions, plugins etc...


    Any job you do in font of a computer can be enhanced by programming. People who learn to program in fields other than programming can become more valuable than their skill in either programming or their field. The combination is far greater than the sum of its parts. When you use other people's software, you are limited by their vision. If you can program, the limits are your programming skill and imagination.

    Quote

    programmes that I use can be increased by Python specifically


    Add into the mix that python is a well respected language, it's a no-brainer.

    Quote

    We've been taught some maxScript programming ... but I rather learn a more general programming language


    Programming skills are transferable, no matter the language. Given the choice between a general purpose language (that happens to be embedded in a lot of my field's software) and a scripting language found in only one tool, it's another no brainer. Learn to program a general language and then when you have to do a little bit in a proprietary scripting language, you'll be able to muddle through OK.

    Quote

    Secondly when I did my research into what programming language to learn first I came across these:

    (https://www.futurelearn.com/courses/creative-coding)
    (http://www.processing.org/tutorials/)


    It's good to do research but Processing would be a poor choice, especially considering your goals.
  3. In Topic: Java weird problem

    Posted 23 Jul 2014

    http://thedailywtf.c...en-Numbers.aspx
  4. In Topic: Java weird problem

    Posted 23 Jul 2014

    Not in most of mainland Europe. A comma is the decimal separator there and the Scanner respects the localisation settings.
  5. In Topic: Keep Getting The Answer Wrong for SPOJ

    Posted 23 Jul 2014

    The site won't let me check it without registering. I modified your code so I could run it on my computer. What I did was generate a random list of inputs going by the parameters of the program. It took a LONG time to execute with 200000 numbers! I changed it to 1000 numbers and it took 16 seconds. If we extrapolate, it would be almost an hour for all 200000.

    Just how much faster do we need it to be?
    10 times faster would be 5--6 minutes for the whole dataset. Still too slow.
    100 times faster would be ~30 seconds which is getting better, maybe acceptable.
    1000 times faster would be < 5 seconds which sounds good to me.

    Changing the language won't make that difference. Neither will tweaking the code (I tried modifying yours to use loops instead of a list comprehension -- no difference), turning off the garbage collector won't do it either. You need a different algorithm.

    Here is the code I'm starting with.

    #!/usr/bin/env python3
    import sys
    import gc 
    import random
    
    random.seed(0)
    sampleList = []
    for i in range (1000):
    	sampleList.append(random.randint(1, 500000))
    
    gc.disable() #increase speed at the cost of memory
    for i in sampleList:
    	try:
    		temp = i
    		list = [j for j in range(1, (temp / 2) + 1) if temp % j == 0]
    		print(sum(list))
    	except:
    		break
    sys.exit(0)
    


    It could do with some cleaning up before working any further.

    gc.disable() #increase speed at the cost of memory
    


    This made me sick up a little. Also it made no difference to the runtime for 1000

    sys.exit(0)
    


    Exit at the end of the program is not neccessary

    try:
    except:
    	break
    


    Also not neccessary. All these detract from the core task. We get this:

    import sys
    import gc 
    import random
    
    random.seed(0)
    sampleList = []
    for i in range (1000):
    	sampleList.append(random.randint(1, 500000))
    
    for i in sampleList:
    	list = [j for j in range(1, (i / 2) + 1) if i % j == 0]
    	print(sum(list))
    
    


    And I've just noticed we can simplify creating the random list. Probably also a good idea to extract a function for the core task which is finding and summing the proper divisors.

    import sys
    import gc 
    import random
    
    def sumProperDivisors(n):
    	list = [j for j in range(1, (n / 2) + 1) if n % j == 0]
    	return sum(list)
    
    random.seed(0)
    sampleList = [random.randint(1, 500000) for i in range(1000)]
    for i in sampleList:
    	print(sumProperDivisors(i))
    
    


    Now we need a better algorithm for sumProperDivisors. I won't write it for you but consider this:

    If a number is not divisible by 2, it won't be divisible by 4, 6, 8...
    If a number is not divisible by 3, it won't be divisible by 6, 9, 12...
    etc...

    2 and 3 are the first two in a very important series of numbers. Good luck and let us know how you get on!

My Information

Member Title:
Cabbage
Age:
32 years old
Birthday:
April 7, 1982
Gender:
Location:
Glasgow
Forum Leader:
Java
Years Programming:
20

Contact Information

E-mail:
Click here to e-mail me
Website URL:
Website URL  http://

Comments

Page 1 of 1
  1. Photo

    burakaltr Icon

    06 Mar 2013 - 18:18
    Thanks for Your Precious Input. I Found the character counting thing very bedazzling. I have the code to it that I wrote Myself, but it took me Long to find a subtle Algorithm :)
  2. Photo

    cfoley Icon

    18 Oct 2011 - 03:29
    Cheers! The next one is in progress, but I'm having to learn and write some programs first. It's going to take a little time...
  3. Photo

    Dogstopper Icon

    18 Oct 2011 - 03:24
    Nice blog. Can't wait to see more
  4. Photo

    ayaz 786123 Icon

    25 Feb 2011 - 06:49
    have a nice day sir
  5. Photo

    cfoley Icon

    16 Feb 2011 - 17:26
    Oooh thanks! Your comment is the first I heard!
  6. Photo

    m-e-g-a-z Icon

    16 Feb 2011 - 15:34
    Congrats on becoming a Forum Leader! :)
  7. Photo

    Dogstopper Icon

    08 Jan 2011 - 23:49
    "Cabbage" is much better! :D
  8. Photo

    cfoley Icon

    06 Jan 2011 - 16:19
    Cheers dude!
  9. Photo

    Dogstopper Icon

    06 Jan 2011 - 14:36
    "Purple DIC-headed Warrior" doesn't quite apply now that you got the promotion. Well done!
  10. Photo

    DaneAU Icon

    08 Sep 2010 - 09:19
    "cfoley has no profile comments yet. Why not say hello?"
    I don't have many comments either, so i am only doing what the thingy below said to do, hello cfoley and thanks for the thanks :)
Page 1 of 1