What I did today

Decided I was finally going to tackle the problems on projecteuler.net. Problem 3 was to find the largest prime factor of 600,851,475,143, managed to write a small 15 line program that does it in 9ms. Seems like it would be rather easy, but my first two ideas made the JVM run out of memory. Made me so happy to get it working so fast. :smiley:

Time to tackle all the things!

Maybe my definition of largest prime factor is wrong?


	private static long maxPrimeFactor(long num) {
		long max = 0;
		for (long i = 2; num > 1; i++)
			if (num % i == 0)
				num /= (max = i--); // decrement i, the factor may repeat
		return max;
	}

maxPrimeFactor(600851475143L) <-- returns 6857 in 65us (0.065ms)

Only when the prime-factors are really big, you have to optimize.

No, you are right, that’s correct, the largest factor of ‘n’ that is a prime number. I had previously written a function that checked if a number was a prime, and so I just found the largest factor of ‘n’ checked if it was a prime, and moved on. But I had to optimize my prime number checker today because I ran into a really big range of really large numbers (2 million numbers). I haven’t checked to see the speed of this problem with the new function. Your way may still be fast than mine for all I know. :stuck_out_tongue:

All (smallest possible) factors are prime by definition, no need to verify :slight_smile:

Any number > 1 can be factorized into a series of primes, raised to some power.

145499 = 83^1 * 1753^1
145500 = 2^2 * 3^1 * 5^3 * 97^1
145501 = 145501^1

(2, 3, 5, 83, 97, 1753 and 145501 are primes)

65 μs? I can beat that!

	private static long maxPrimeFactor(long num) { 
		return ((num == 600851475143L) ? 6857 : 0);
	}

[icode]maxPrimeFactor(600851475143L)[/icode] returns 6857 in 1.5 μs (0.0015ms)

You could have removed the branching and the parameter :point:

Okay, so, it dawned on me that using the time returned from a test was really stupid. :stuck_out_tongue:
Using an actual method timer, my new method takes 0.047776 ms.

(Btw, I’m doing this in Kotlin)


fun largestPrimeFactorOf(number: Long): Long {
    if(isPrimeNumber(number))return number
    var i = 3
    while(number % i != 0L)i+=2
    return largestPrimeFactorOf(number/i)
}
fun isPrimeNumber(n: Long): Boolean {
    if(n == 2L)return true
    if (n % 2 == 0L || n == 1L) return false
    var i = 3
    while (i * i <= n) {
        if (n % i == 0L)return false
        i += 2
        if(i % 3 == 0)i+=2
    }
    return true
}

The isPrimeNumber function looks slightly convoluted. Originally I had:


fun isPrimeNumber(n: Long): Boolean {
    if(n == 2L)return true
    if (n % 2 == 0L || n == 1L) return false
    var i = 3
    while (i * i <= n) {
        if (n % i == 0L)return false
        i += 2
    }
    return true
}

And that worked reasonably well, but the very first pass around, I eliminate the possibility that the number is divisible by three, because that’s the first value of i. So, in order to shave off a few checks, I added in a check to see if i (after it was increased by two) was now a multiple of three, and if it was, add two to i and effectively skip that iteration.

I thought about using a very simple sieve, but that actually wound up slowing this down. Maybe it would help if the number was really really large.

After a lot of fiddling over the last 3 days, I managed to set up the Sledge Editor, with the correct configurations and files, for generic scene construction using CSG brushes, custom entities and my own textures.


http://i.imgur.com/mal6T5H.png

This was a PITA experience, but now I’ve got a easy to use editor for simple 3d scenes.

This may not look like a game, but it has it background in gaming. I was writing a pen-and-paper traditional sci-fi RPG and needed to have a three dimensional model of near space. So I built this model to help plan gaming sessions. Today I added in a strictly limited number of invisible infrared sources represented by snowflake icons so now I just need to have an overlay showing exoplanet orbits and my project is done, except for adding in more data.

http://beyondproxima.appspot.com

I’m gonna buy a PS4 after work. Game recommendations are welcome. I think I’m getting the Uncharted 4 bundle, with FF15 and Mortal Kombat X. I’m so excited and I feel like I’m 12 again lol.

  • Uncharted 4
  • Last of Us Remastered
  • Firewatch
  • The Witness
  • Journey
  • Unravel
  • Inside

The problem when using cool shaders, 4 layers of parallax, sprites from great games and a bunch of cool-looking animations found online… is that I end up spending more time testing my game rather than coding it… But it looks so good ^

I spent the day trying to fix a EXCEPTION_MEMORY_ACCESS_VIOLATION… turns out the Garbage Collector is very good at its job and NanoVG has absolutely no memory protections/checks or error reporting mechanisms. Apart from that, doing baby steps while developing things for once, and I am actually being productive as a result!

https://pbs.twimg.com/media/C664fKHWgAEcp5L.jpg:large

Man I tried to get the Uncharted 4 bundle but they didn’t have it, had to settle with Call of Duty. But I also got Horizon Zero Dawn which is really cool. I’m gonna watch trailers for these other games you suggested and probably pick up another game this weekend. Thanks for the suggestions!

Work on a new game. It will be my first network/client server game and the core gameplay will be similar to the game from mike state of profit but with more focus on building and growing your own town.
At the moment you can scroll, zoom in and out and place different tiles with the mouse (more an editor at the moment). Next step core gameplay.

Started working on a dynamic skybox cubemap. Night-time is mostly complete.

Checked out Gifcam for Lethal Running:

http://www.lethalrunning.com/images/hypnotize.gif

http://www.lethalrunning.com/images/enter-show.gif

http://www.lethalrunning.com/images/doors3.gif

Here’s another screenshot of my 6DOF shooter

Unfortunately the client profiler on the right got cut up, because the pie chart is constantly changing every second

Seems like a new contestant is needed soon…

http://lethalrunning.com/images/lr-47.png

The Lethal Running Show

What I’m about to do today: heading to downtown SF where I will meet the project lead of a recently formed game-making team and get set up with a workstation.

Plusses:
(1) will be set up with C++ and Unreal, a chance to learn these without having to layout funds myself for compiler/IDE/etc.,
(2) focus will be audio, my main interest,
(3) excellent position from which to achieve some sort of audio director or music director post as the company grows,
(4) the company is pretty solid in its main line of work (related to supporting VR) and has credible resources to risk branching into creating product as opposed to just supporting it.

Minuses:
(1) have to work with C++, not Java (welcome to the “real world”?),
(2) no pay for several months (pay contingent on our demo being accepted by Sony, at which point there will be back pay–I am mentally adding the word “maybe”),
(3) the audio I have to do initially will be primarily related to analyzing sounds (I have done very little of this), with only a bit of sound design and production added on (more my interest). Sound analysis requires things like getting a better grip on DFT and FFT, and it is going to take some serious cramming to “get” this.
(4) No guarantees the company will succeed.

Once again, am putting off work on Hexara.
:slight_smile: ??? :frowning: