What could I code?

Maximilian

Lifer
Feb 8, 2004
12,604
15
81
I want to code something... I don't know what though. Im familiar but still inexperienced with Java. I thought about contributing to an open source project but tbh im probably not good enough to do that (yet!) which is why I want to code something, to get better, gain more experience and stay fresh with what ive already learned. My current degree is focusing more on interaction design and big picture stuff at the moment so I want to do some coding in my spare time.

Any ideas? A game might be fun! Dont know how I would start with that though.
 

purbeast0

No Lifer
Sep 13, 2001
53,290
6,120
126
code up a tetris game or a maze where you drag something through it. check out slick2d.

the other classic project is an rss reader.

game and application programming are fairly different though as far as the structures and how things work.
 

RampantAndroid

Diamond Member
Jun 27, 2004
6,591
3
81
There are a bunch of engines out there with tutorials, last I looked. If you can't find them, I'll dig some up after work.
 

code65536

Golden Member
Mar 7, 2006
1,006
0
76
Laziness is a virtue.

That's always a great source of inspiration: my very first attempts at programming were a series of programs that I wrote back in middle school to do my math homework for me.

I also tried writing simple games, but that wasn't rewarding at all--a lot of work for something that might entertain me for a few minutes at most. But the little utilities, timesavers, etc. that I created to reduce tedium and address my personal pain points are indispensable and still useful years later.
 

RampantAndroid

Diamond Member
Jun 27, 2004
6,591
3
81
Laziness is a virtue.

That's always a great source of inspiration: my very first attempts at programming were a series of programs that I wrote back in middle school to do my math homework for me.

I also tried writing simple games, but that wasn't rewarding at all--a lot of work for something that might entertain me for a few minutes at most. But the little utilities, timesavers, etc. that I created to reduce tedium and address my personal pain points are indispensable and still useful years later.

I'll agree with this - I wrote a rendering engine for my college senior project and it wasn't something I'd do again. A lot of pain for very little gain. Find something you like and go with it. Most rewarding for me might have been a neural network...

Actually, most rewarding was an internship with Broadcom working on their HD DVD/BluRay players (and also working with MS on the HD DVD side.) I had a brief heart attack on in the internship of "oh balls I don't know what I'm doing I should change majors" (I had one semester left at that point...) and slowly got used to writing code that shipped. Best experience I had. Esp since one of the players I worked on went to CES, and I was working some mildly crazy hours to fix bugs for a CES demo and fixing issues for a holiday launch of other players.
 
Last edited:

mrjminer

Platinum Member
Dec 2, 2005
2,739
16
76
A couple of my first ones were:

-A crossword puzzle that randomly generates a correct board.
-A wordsearch that randomly generates a correct board (forward, backward, diagonal, diagonal backwards, etc.)
 

Train

Lifer
Jun 22, 2000
13,578
73
91
www.bing.com
Laziness is a virtue.

That's always a great source of inspiration: my very first attempts at programming were a series of programs that I wrote back in middle school to do my math homework for me.

lol, my first program was a C64 Program that "showed the work" on my math problems.

Only problem was I didn't finish it until summer time. Got a D in math that year.
 

Spydermag68

Platinum Member
Apr 5, 2002
2,614
98
91
I have been doing the problems from projectEuler.net. So far I have solved 38 problems. Some of them take a few minutes to program and some have taken weeks to figure out. I worked on 351 on and off for a month. I finally solved it but the program took 1 hour and 40 minutes to get the answer.
 

MagnusTheBrewer

IN MEMORIAM
Jun 19, 2004
24,122
1,594
126
Write something you're familiar with like a music player, Atm emulator, elevator controller or, maybe even a textpad clone.
 

Red Squirrel

No Lifer
May 24, 2003
69,166
12,969
126
www.anyf.ca
lol, my first program was a C64 Program that "showed the work" on my math problems.

Only problem was I didn't finish it until summer time. Got a D in math that year.

I remember doing the same thing LOL. There was this one type of math problem that we had to do like 100's of em, it was just ridiculous so I did enough of them for me to understand the concept then I just automated the rest. It took less time to write the program than it would have taken to do them all.

The big thing right now is mobile apps, maybe look into what it takes to code a basic game. Even basic games like flappy bird make millions, so you could try to see if you can make a hit like that.
 

Maximilian

Lifer
Feb 8, 2004
12,604
15
81
Think ill give projecteuler a shot and try and code tetris as well! I managed to set up that slick2D thing yesterday :thumbsup:
 

smakme7757

Golden Member
Nov 20, 2010
1,487
1
81
One of the ways i found projects for myself was to look at something i actually paid for and then try to make a decent clone of it. Maybe not with a fancy UI, but still functional just without all the non essential bells and whistles.

a Winzip clone was one of the first I think, just as an example.
 

Leros

Lifer
Jul 11, 2004
21,867
7
81

smackababy

Lifer
Oct 30, 2008
27,024
79
86
lol, my first program was a C64 Program that "showed the work" on my math problems.

Only problem was I didn't finish it until summer time. Got a D in math that year.

I wrong a program in my computer science class that parsed the files and edited the variable names to match the ridiculous naming conventions required. Sadly, I was nearly finished with the class by the time I got it working though well enough to simply run it and turn in the code. =(

Laziness is the mother of all invention! It is funny how much work we are willing to put in to that we can be lazy about something else.
 

RampantAndroid

Diamond Member
Jun 27, 2004
6,591
3
81
I wrong a program in my computer science class that parsed the files and edited the variable names to match the ridiculous naming conventions required. Sadly, I was nearly finished with the class by the time I got it working though well enough to simply run it and turn in the code. =(

Laziness is the mother of all invention! It is funny how much work we are willing to put in to that we can be lazy about something else.

...learn to name things correctly from the start, or get something like resharper.

Also, learn to comment things correctly, lest Stylecop come along and fail your build for a missing XML comment. ;)
 

Cerb

Elite Member
Aug 26, 2000
17,484
33
86
Wow... project euler problem 3 took my method 16 minutes to complete. Efficiency fail :eek: Got the right answer though!

http://projecteuler.net/problems
16 minutes? Wow. How'd you go about it? :twisted:

PE has a lot of work on primes, so it's worth the effort, if you plan to do more of them, to implement a fairly efficient prime finding method. If using a scripting language, the creation and updating of sieve can often be slow, but you can reverse-engineer the logic of a sieve into several different looping constructs, of varying degrees of efficiency.
 

Maximilian

Lifer
Feb 8, 2004
12,604
15
81
16 minutes? Wow. How'd you go about it? :twisted:

PE has a lot of work on primes, so it's worth the effort, if you plan to do more of them, to implement a fairly efficient prime finding method. If using a scripting language, the creation and updating of sieve can often be slow, but you can reverse-engineer the logic of a sieve into several different looping constructs, of varying degrees of efficiency.

I made this beast of a method and a threaded one to go along with it. Managed to cut it down to 8 minutes but still a far cry from the one minute goal. Maybe with an overclocked octocore with 16 threads :D

Code:
public static void problem3(Long aNumber, Integer numberOfThreads) throws InterruptedException, ExecutionException
    {
        final ExecutorService service;
        long executionTime;
        long startTime = System.currentTimeMillis();
        long finishTime = 0;
        
        service = Executors.newFixedThreadPool(numberOfThreads);
        List<List> resultsLists = new ArrayList<>();
        List <FutureTask<List>> taskList = new ArrayList<>();
        List<Problem3Thread> threadsList = new ArrayList<>();
        Boolean addToFinal;
        Long addToFinalNumber;
        
        //half the number because nothing over halfway will divide
        Long numberHalved = (aNumber / 2) + 1;
        
        //each thread needs a range to work on, this will be the increment between
        //ranges for each thread
        Long numberForThreads = numberHalved / numberOfThreads;
        
        //to avoid loss due to division add to the final number of
        // the last thread to execute
        addToFinalNumber = numberHalved % numberOfThreads;
        
        if (addToFinalNumber == 0)
        {
            addToFinal = false;
        }
        else
        {
            addToFinal = true;
        }
        
        //create a number of threads to operate on a different range of the number
        //this will speed up calculation time on larger numbers
        int count = 0;
        Long currentStart = 3L;
        Long currentFinish = numberForThreads;
        while (count < numberOfThreads)
        {
            threadsList.add(new Problem3Thread(currentStart, currentFinish, aNumber));
            
            //to avoid loss due to division add to the final number of
            // the last thread to execute, this is where it is added
            if (count + 2 == numberOfThreads && addToFinal)
            {
                currentStart = currentFinish;
                currentFinish = currentFinish + numberForThreads + addToFinalNumber;
            }
            else
            {
                currentStart = currentFinish;
                currentFinish = currentFinish + numberForThreads;
            }
            count++;
        }
        
        //create tasks for each thread, this is needed when using callable
        //instead of runnable
        for (Problem3Thread aThread : threadsList)
        {
            taskList.add(new FutureTask<>(aThread));
        }
        
        //start each task
        for (FutureTask aTask : taskList)
        {
            service.submit(aTask);
        }
        
        //get results from each task
        for (FutureTask aTask : taskList)
        {
            resultsLists.add((List<Long>) aTask.get());
        }
        
        service.shutdown();
        
        //format the results by putting them all in a set to remove any
        // possible duplicates
        Iterator resultsIterator = resultsLists.iterator();
        Set<Long> finalResults = new HashSet<>();
        while (resultsIterator.hasNext())
        {
            List<Long> aResultsList = (List<Long>) resultsIterator.next();
            finalResults.addAll(aResultsList);
            
        }
        
        //find the largest prime factor out of the results
        Long currentLargest = 0L;
        for (Long aLong : finalResults)
        {
            if (aLong > currentLargest)
            {
                currentLargest = aLong;
            }
        }
        
        //if there were no results but it was an even number the largest prime
        // factor was 2
        if (finalResults.isEmpty() && aNumber % 2 == 0)
        {
            System.out.println("The largest prime factor was: " + 2);
        }
        else
        {
            System.out.println("The prime factors were: " + finalResults);
            System.out.println("The largest prime factor was: " + currentLargest);
            service.shutdown();
            finishTime = System.currentTimeMillis();
            executionTime = finishTime - startTime;
            System.out.println("Execution time: " + executionTime);
        }
    }

The threads it executes:
Code:
public class Problem3Thread implements Callable
{
    List<Long> divisibleNumbers = new ArrayList<>();
    List<Long> divisiblePrimeNumbers = new ArrayList<>();
    Long start;
    Long finish;
    Long numberToWorkOn;
    
    public Problem3Thread(Long startInput, Long finishInput, Long numberToWorkOnInput)
    {
        start = startInput;
        finish = finishInput;
        numberToWorkOn = numberToWorkOnInput;
    }
   
    @Override
    public Object call() throws Exception 
    {
        //ensure number is odd, the only even prime is 2
        if (start % 2 == 0)
        {
            start--;
        }
        System.out.println("Thread " + Thread.currentThread() + " start " + start + " finish " + finish);
        Long currentNumber = start;
        //find divisible numbers, only checking odd numbers
        while (currentNumber <= finish)
        {
            if (numberToWorkOn % currentNumber == 0)
            {
                divisibleNumbers.add(currentNumber);
                System.out.println("Divisible number " + currentNumber + " from thread " + Thread.currentThread());
            }
            currentNumber = currentNumber + 2;
        }
        
        //find prime numbers out of the divisible ones found
        for (Long aPrime : divisibleNumbers)
        {
            System.out.println("Current number being tested for prime factor " + aPrime);
            Boolean continueLoop = true;
            Long currentPotientialPrime = aPrime;
            Long currentModulus = 3L;
            while (continueLoop)
            {
                if (currentModulus >= currentPotientialPrime)
                {
                    //prime found
                    divisiblePrimeNumbers.add(aPrime);
                    continueLoop = false;
                    System.out.println("Divisible prime found " + aPrime);
                }
                
                if (currentPotientialPrime % currentModulus == 0)
                {
                    //not prime
                    continueLoop = false;
                }
                currentModulus = currentModulus + 2;
            }
        }
        return divisiblePrimeNumbers;
    }

Part of the challenge is to find a solution that runs in under 1 minute.

You're going to need to find primes to solve a handful more problems, so it might be useful to figure out how to do it. This is the method I used and it runs in a second. http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes

Yeah I definitely need to look into that lol.
 

smackababy

Lifer
Oct 30, 2008
27,024
79
86
...learn to name things correctly from the start, or get something like resharper.

Also, learn to comment things correctly, lest Stylecop come along and fail your build for a missing XML comment. ;)

These weren't meaningful names. You had to preface every variable with the type and there was something else entirely arbitrary. There is no reason I need to name a variable stringLastNameNonConstant or something stupid.
 

code65536

Golden Member
Mar 7, 2006
1,006
0
76
These weren't meaningful names. You had to preface every variable with the type and there was something else entirely arbitrary. There is no reason I need to name a variable stringLastNameNonConstant or something stupid.

Making Wrong Code Look Wrong


(Even "Systems" notation is sometimes useful, like if I'm reviewing code in the form of a patch file; IDEs are not always available.)
 

Red Squirrel

No Lifer
May 24, 2003
69,166
12,969
126
www.anyf.ca
Wow... project euler problem 3 took my method 16 minutes to complete. Efficiency fail :eek: Got the right answer though!

http://projecteuler.net/problems

That's neat, I might play around with that. Been wanting to start some programming projects but been out of the loop in so long, this might be a fun way to get my feet wet again, and I've always been obsessed with finding ways to make something efficient.

I used to cringe in college when they taught bubble sorting as being a viable way to sort data.
 

RampantAndroid

Diamond Member
Jun 27, 2004
6,591
3
81
These weren't meaningful names. You had to preface every variable with the type and there was something else entirely arbitrary. There is no reason I need to name a variable stringLastNameNonConstant or something stupid.

That actually can be quite useful as code notes - sometimes you have no autocomplete or no formatting. Sometimes you have notepad. Another naming convention I've seen is m_doesThisWork or mDoesThisWork to signify a member variable, ptr means point, itr means iterator and so forth. It's an incredibly useful naming mechanism when you're sifting through a codebase that's thousands of files and millions of lines of code and all you care about is a header file somewhere or a specific function.

You also have to realize many companies will have rules on how you code. Where I am, we enforce stylecop or fxcop and many stylecop warnings come through as errors that block binplace from occurring. So while you may not like it - you HAVE to do it.