Project Euler Problem 17

Check your spelling / letter counts. Seriously. Sixty is 5 letters long, not 6; a false friend numeral.

Also, from the forums: look at the use of the word and. The examples are your friend.

Project Euler Problem 11

Just a hint, so you don’t go down the wrong path. You probably won’t, but if you don’t want any hints, stop reading this article!

PS If you don’t know what Project Euler is, I recommend having a look at their website, or just getting an idea from the problems themselves.

What is Project Euler?

Project Euler is a series of challenging mathematical/computer programming problems that will require more than just mathematical insights to solve. Although mathematics will help you arrive at elegant and efficient methods, the use of a computer and programming skills will be required to solve most problems.

Now problem / puzzle 11:

In the 2020 grid below, four numbers along a diagonal line have been marked in red.

(snip)

The product of these numbers is 26 63 78 14 = 1788696.

What is the greatest product of four adjacent numbers in any direction (up, down, left, right, or diagonally) in the 2020 grid?

Just a hint for those of you who spent too long on this like me: it’s essentially a word search. One of these but with numbers.

You see, when I got the wrong answer a couple times I reread the question, and figure “adjacent” just meant anywhere beside each other – eg a square of four numbers, a t-shape. This is not the case! You don’t need to develop a path-finding bot that navigates 4 numbers, looking for the best options! Although, having done that, it’s actually quite fun! In python, at least, it’s quite concise and the code is pretty-looking.

Bonus points (or a packet of chocolate-coated raisins) to the first person who does implement such an algorithm. The answer I’m looking for is the highest product of the resulting 4 numbers, and leave it in the comments.

Bet I won’t get an answer!

Plain Sight Dedicated Server Crash Fix

Plain Sight was on sale for the staggeringly low £1.60 / £1.20, so I decided to get a copy. It is a very fun, fast-paced game, with lots of great moments – where you pull off an attack a split second before an opponent does the same, or when you detonate just as three people come gunning for you. However, it is not without issues. I am writing this post as I wait for the master server to let me log in and play, and matches will occasionally crash half of the people on the server to the desktop with what looks like an array out-of-bounds exception.

Frustratingly, the dedicated server software itself has problems. One problem occurs even before running – where do you get it from? It is not well-signposted on any of Beatnik Games’ websites. As it stands, you have to go to the members’ area of plainsightgame.com (http://accounts.plainsightgame.com/), where you can download both the server and the client.

(The TLDR version: If you have Steam, use the dedicated server included with that. Strip out whitespace and comments (//) from the example dediconfig.txt on the wiki. If you don’t have Steam or don’t want to faff about, use this zip.)

Now, it is good practice to have an example / default config file available for those that want to just run the server… which the dedicated server zip doesn’t have. So if you run it, it complains about not being able to find the config file and then crashes. Right, no problem, just copy from the wiki page on setting up a dedicated server and paste into the new file dediconfig.txt. Ah, hang on, that crashes the server on launch with a System.FormatException.

Show »

Problem signature:
Problem Event Name: CLR20r3
Problem Signature 01: plainsightserver.exe
Problem Signature 02: 1.0.0.0
Problem Signature 03: 4bc74e1c
Problem Signature 04: mscorlib
Problem Signature 05: 2.0.0.0
Problem Signature 06: 4a275af7
Problem Signature 07: c43
Problem Signature 08: 59
Problem Signature 09: System.FormatException
OS Version: 6.1.7600.2.0.0.256.1
Locale ID: 2057

Stripping out the whitespace and comments lets the server run. I would be more specific, but I can’t actually tell what is causing the problem. It disappeared when I got down to two / one comments, and reappeared when I added another. My debugging skills couldn’t detect any commonality though. Anyway, it runs… briefly. Checking the log file (plainsight.log) shows that it is exiting due to not having the “Updater” directory present. eg:

Show »

0 Connecting to master server(s)...
0 New master server connection status: AwaitingChallenge
633 New master server connection status: VersionCheckFailed
633 New master server connection status: NotConnected
633 New master server connection status: AwaitingChallenge
650 Error Updating: System.IO.DirectoryNotFoundException: Could not find a part of the path 'D:Gamesplainsightdedicated4UpdatercwRsynccwRsync.cmd'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode)
at PlainSightServer.Program.LaunchUpdater()
650 New master server connection status: NotConnected
650 New master server connection status: AwaitingChallenge

Now, you can get this from the directory in your Steam directory that contains the dedicated server (!), or from this zip file: Updater.zip. Now, if you want to continue down this path that’s grand, but for me it *royally* screwed up permissions on that folder, to where I couldn’t even run the server executable file! It is possibly due to the rsync updater running as System / nobody, but even still I feel it’s a bit harsh! Of course, it might just be a Windows 7 thing. Despite that, even when I (think) I had sorted out the permissions, the game was still crashing with an error in KERNELBASE.dll (see below). Eeep. So, what I did at this stage was to make a copy of the Steam version of the dedicated server, copy over my dediconfig.txt file and run that. Then it ran.

For those of you who don’t have Steam, I have created a zip containing the dedicated server with a working dediconfig.txt file: DedicatedServer.zip

Show »

Problem signature:
Problem Event Name: APPCRASH
Application Name: PlainSightServer.exe
Application Version: 1.2.0.0
Application Timestamp: 4c6e7ef9
Fault Module Name: KERNELBASE.dll
Fault Module Version: 6.1.7600.16385
Fault Module Timestamp: 4a5bdbdf
Exception Code: e0434f4d
Exception Offset: 0000b727
OS Version: 6.1.7600.2.0.0.256.1
Locale ID: 2057

Fix for “Current Password No Longer Matches Keyring”

A I may have mentioned, I recently reinstalled Ubuntu (had been using Windows 7 for a few months). Since the reinstall I had changed my common login password for the other computers on the network so of course I updated my user password for the new install.

The slight problem came when I used any application that accessed the keyring (say, network-manager), as there was a password mismatch between my credentials and the keyring. This was because I preserve my /home partition to keep my data (a good practice) and that is where the keyring data gets stored (logically). But it got tiresome to frequently see:

“Enter password to unlock your login keyring. The password you use to login to your computer no longer matches that of your login keyring”

It’s dead easy to fix though.

  1. Go to Applications -> Accessories -> Passwords and Encryption Keys
  2. Right-click on Passwords: login
  3. Select “Change Password”
  4. Enter your old login password (the one that it repeatedly asks for!) in the old password bit, and put your current login password in the new password fields.

And that’s all there is to it!

An Old Video (FEAR – Stolen Kills)

I’ve been posting a fair number of videos to another blog for the folk I play games with (including the other MIA author of posts on this blog Kenny). It’s a good way to relive some moments and also a way for me to practice my cutting and splicing skills.

Long story short, I encoded an updated version of a video I created about three and a half years ago. The old one was small resolution and tiny bitrate. This version is full (source) resolution and a relatively insane bitrate.

FEAR – Stolen Kills (pop-out player if you have JS enabled, non pop-out version here)

Synopsis: I shoot Kenny in the back (with friendly fire on) and I’m rewarded with two kills. Obviously a sounds strategy!
Continue reading →

Playing The Steam Version of Indiana Jones and the Fate of Atlantis

As someone who still has the original floppies for Indiana Jones and the Fate of Atlantis (or IJatFoA, it’s easier that way), I thought I’d give the Steam version a whirl. I picked it up (along with The Last Crusade) probably when it was on sale as part of a bundle.

My initial thoughts are: “what have they done to the music?”, “since when did the characters have voices?” and “this is a lot simpler than what I remember playing as a 7 year old”.
Continue reading →

[Solved] sshd Does Not Run At System Startup (Ubuntu)

Problem:

  • sshd does not appear to start on system boot, but runs fine when started from a terminal with /etc/init.d/ssh start

Cause and Solution:

  • A ListenServer directive in /etc/ssh/sshd_config is making sshd attempt to listen on a not-yet extant address. Change the directive to ListenServer 0.0.0.0

(NB: if you don’t have an /etc/init.d/ssh, you can get one from here)

I had a problem with a machine I am using as a samba fileserver. It would seem that the sshd process was not running at startup, so I would have to log into Gnome and run /etc/init.d/ssh start manually, which was a pain in the arse.

A quick search turned nothing up, except “make sure openssh-server is installed”, which in my case it was. I was about to post to the Ubuntu forums, but first I had a quick look at the syslog (which sshd prints to), where I saw entries like the following:


Jun 27 13:18:56 hermes init: ssh main process (802) terminated with status 255
Jun 27 13:18:56 hermes init: ssh main process ended, respawning
Jun 27 13:18:56 hermes init: ssh main process (806) terminated with status 255
Jun 27 13:18:56 hermes init: ssh main process ended, respawning
Jun 27 13:18:56 hermes init: ssh main process (810) terminated with status 255
Jun 27 13:18:56 hermes init: ssh main process ended, respawning
Jun 27 13:18:56 hermes init: ssh main process (814) terminated with status 255
Jun 27 13:18:56 hermes init: ssh main process ended, respawning
Jun 27 13:18:56 hermes init: ssh main process (818) terminated with status 255
Jun 27 13:18:56 hermes init: ssh main process ended, respawning
Jun 27 13:18:56 hermes init: ssh main process (822) terminated with status 255
Jun 27 13:18:56 hermes init: ssh main process ended, respawning
Jun 27 13:18:56 hermes init: ssh main process (826) terminated with status 255
Jun 27 13:18:56 hermes init: ssh respawning too fast, stopped

My thinking is that sshd was trying to start up before the network interfaces were configured, which was causing it to fail as it had a ListenAddress directive in /etc/ssh/sshd_config.

Commenting out the specific ListenAddress directive and adding ListenAddress 0.0.0.0 to let sshd listen on any address solved the problem. The fileserver has only 1 IP address anyway.

My Short APB Review

(Note: I also posted this over on Slashdot on the story about the fact that APB is to use in-game advertisements)

Having played the beta, my short review of APB is: “drive here, shoot stuff, repeat”. Oops! Seems like I broke the embargo on reviews which was initially set at 10 freakin’ days after release! To their credit (I guess), they rolled that back to merely release day.

A more nuanced look at the game shows they have in fact done some things quite nicely. The “All Points Bulletin” mechanic works very nicely. You’ll be doing a mission when up pops up a notification that a comparable group from the opposing faction has been sent to stop you. It changes the dynamic of the mission and gives you a jolt of adrenaline as you listen out for the roar of the car engine signifying your would-be assassins drawing close. However, these adversarial matchups aren’t without their problems. Say 50% of the time they work and you get a comparable strength team sent against you, resulting in a pitched battle that culminates in either narrow victory or defeat. Perfect! Well, the other 50% of the time you get a team that is woefully underpowered, say one wee neophyte against our group of four. Or massively overpowered, so you “call for backup”, which works maybe 10% of the time. Perhaps the opposition are a full map away and have no way of intercepting you in time. Or they are already at the objective and virtually impossible to budge. The latter gets irritating as there are a few excellent camping spots should you get a VIP ‘escort’ mission. Oh, and I lied about the proportions. Things go right about 25% of the time rather than 50%.

Despite these problems, the gameplay is fun if you have a good group that you are in touch with through some kind of voice comms. The problem is that there is very little variety. Perhaps I’ve been spoiled by Saints Row 2 in this regard, but there seem to be about 3 basic types of mission which leads to the game getting boring quickly – pitched battles or not.

There is also a HUGE amount of customisation, if you’re into that sort of thing. I won’t say more about this as I’m not buying a game to play dress up…

…Which brings me to my next point: pricing. Pinning down the pricing details wasn’t easy, although I did eventually find it on Kotaku or similar. I’ll quote from RPS again:

You can purchase a retail version of APB either in-store or via digital download at standard retail price (SRP $49.99/£34.99/€49.99). The game includes 50 hours of action game play out of the box plus unlimited time in APB’s social districts customising, socialising and trading on the marketplace.

Once your game time is up, you have flexibility to top up your action game time from as little as $6.99 (£5.59, €6.29) for an additional 20 hours, while more frequent players can switch to a 30-day unlimited package for only $9.99 (£7.99, €8.99) with discounts available for 90 and 180 days.

The retail package also contains a bonus 100 RTW points towards your next purchases.

An additional benefit to this evolutionary model is the ability for you to convert your own customisations and rewards to tradable products to give to friends or clan-mates or to place on the Marketplace to earn more RTW points (convertible to game time) or in-game cash. Check back later for more details

The problem is, you are paying full retail price plus a decent fraction of 10 of your local denomination (£/$/€) monthly, for what? Progression seems limited – you can gain prestige with local NPC types to do more missions, but your character doesn’t seem to get much stronger as with more traditional MMOs. It’s not even like EVE where you can claim a small section of the virtual world for your particular gang. Frankly, I’m not sure it is worth paying for a glorified matchmaking service, but that is a judgment call each individual gamer needs to make.

Lastly, technical issues. I left them till last as I don’t like bringing them up for a pre-release version of code, but they need to be mentioned. I experienced frequent crashes, something which seemed to affect a small percentage of users, mostly running 64-bit Windows 7. A redownload of the full 7 GB and reinstall *seemed* to fix it, although I did not have enough time to check this fully. I did experience some graphical slowdowns as well, even on minimal settings running on a PC well above recommended spec. Perhaps this was because optimisations had not yet been applied, again due to it being pre-release.

Lag was also an issue, which I mention in a separate paragraph as APB is a shooter after all. However, there were only 2 european servers up during the beta (EU1 and EU2, natch) and so this may not be a problem if they deploy servers widely. Except if you’re in Australia, it would seem. Sorry, mates!

In short, the game is quite fun in the short term, but I question its longevity and value. I won’t be getting it, but you might.

Extract A Single Image From A Video Using FFMPEG

Dead handy, this:

ffmpeg -i inputfile.mp4 -t 1 -ss 0.5 -s 480x300 -f image2 imagefile.jpg

The various options:

  • -t 1: limit to 1 frame extracted
  • -ss 0.5: point of movie to extract from (ie seek to 0.5 seconds)
  • -s 480x300: frame size of image to output (image resized to fit dimensions)
  • -f image2: forces format

I use this to generate preview stills for jwplayer to use. Dead handy!

Black Screen (KSOD) Vista Solutions

Before I get started, some resources:

I’m looking at a friend’s laptop for him. It boots, gets past the progress bar, but before login or a desktop, the screen goes black with a cursor present which can be moved. There are multitudes of threads and posts about this issue over the internet, ranging as far back as 2006 and as recently as last month (May 1010). Although the symptoms are similar, from what I can see there are several causes each with different fixes.

For example, if the login screen comes up and there is a black screen after, it may be possible to hit Ctrl+Shit+Esc together to bring up Task Manager, from there do File->New Task (Run…), explorer.exe. This will bring up the desktop etcaetera, from where you can run other tools to repair the issue.

Advanced Startup Options Menu

Hit F8 while the computer is booting to bring up this menu. It has a number of potentially useful options, and is probably the easiest and lowest-impact to try first. The following options from that menu have been reported to work for some:

  • Safe Mode (with Networking / Command Prompt)
  • Enable low-resolution video (seems to help with nVidia driver update issues)
  • Last Known Good Configuration
  • Disable Driver Signature Enforcement (helps with some other driver errors in HP laptops, if I remember correctly)

It may also help to choose the Enable Boot Logging option, which should create a file called ntbtlog.txt containing info that might point to the driver or component that is causing issues.

Using the Windows System Recovery tool

The first option on the advanced startup menu listed above is “Repair your computer”. This starts a graphical interface with a number of options which may help.

System Restore

You should try to do a system restore first, if it is enabled. If it isn’t enabled, make sure to enable it when you fix the problem! Click the “System Restore” option on the menu (second item) and choose a restore point from when you believe your computer was previously functional.

Registry Fix

It may be a registry issue. In some cases, it would appear the Shell entry is corrupted. You can sort it by doing the following:

  1. Turn on the computer
  2. As it boots, press F8 to bring up the advanced boot options menu
  3. Select “Repair Your Computer”
  4. From there, login to an admin account (eg Administrator)
  5. Select the bottom option to launch a command prompt
  6. type regedit and hit enter
  7. Navigate through the following keys: HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\Current\Winlogon
  8. One you are at Winlogon, there should be an item on the right panel that says “Shell“. Right click this, and select edit.
  9. Change the value to explorer.exe. If this is already present, this is not your issue!

NOTE: If you try this from the “Repair Windows” option on a Windows Vista install DVD or recovery DVD it won’t work, as that seems to edit the registry on the disc (you will see cmd.exe /k start cmd.exe or similar for the Shell key). For me the “load hive” option was greyed out, if isn’t for you, you can open C:\Windows\system32\config and edit the local registry).

Startup Repair

It might be a long shot, but the startup repair option might help. It is the first option on the System Recovery menu.

Memory

It is unlikely that your RAM is causing this problem, but it is useful to know that Vista does have a tool to check memory, and it can be accessed through the System Recovery tool. I didn’t know this until today, having previously used memtest+ x86 included on Ubuntu LiveCDs.

Chkdsk / SFC

From the command prompt provided by the System Recovery tool, you can also try running chkdsk /f /r to run a disk check. Running sfc /scannow should do a verification of ‘critical windows files and components’, but I could not get this to run as it complained about needing to reboot with an active recovery ongoing – I guess it can’t be run via the system recovery tool.

Renaming Event Viewer Log Folder / Prefetch Folder

(See the good post by ubman on technet here)

There are reports that a problem with the event viewer service can cause this black screen on login. To work around this, start up a command prompt through the recovery tool as above. Then execute:

C:
cd \windows\system32\winevt
ren Logs LogsBad
mkdir Logs

Another report claims PreFetch can cause the issue. Now, the folder for PreFetch can be deleted as Windows will recreate its contents as needed. However, should you wish to keep a backup, start p a command prompt as above and run:

C:
cd \windows\
ren Prefetch PrefetchBad
mkdir Prefetch

Other Options

Apologies for the brevity here, these items I quickly jotted down but I am not able to try some of them myself.

Also on technet, zorglub1789 claims broken file permissions were the cause of his woes. Using icacls to fix these apparently worked. He booted to the recovery console and ran:

icacls C:\* /grant builtin\users:(RX) /T

to grant read and execute permissions to all users.

If you can start safe mode, it may be worthwhile temporarily disabling UAC. If the security centre won’t run in safe mode from the control panel, I think it is accessible via the management console. Hold the windows key + R, then type in mmc. I think you may need to add the Group Policy plugin / manager to MMC.

Another file to check on is C:\wialog.txt. This may contain useful information for troubleshooting what is causing the problem.

Again, if safe mode works, msconfig may prove useful. Hold windows key + R, and type msconfig. Then try disabling services, startup options and so forth until you get a working startup. From there you can work back to the cause of the problem. Apparently one to try is “Low Graphics Boot” (or similar), although I don’t know if there is a difference between this and the advanced startup (F8) option.

Tools

Basic Command-line Backup

If you have an external hard drive, and want to back up the C:\ drive, the following command will do that from a command prompt (see above for how to get a command prompt).
xcopy /h /i /c /k /e /r /y C: E:\backup

Where E: is the drive letter for your external hard drive.

Reset Administrator or other Windows Passwords

There is a tool at http://pogostick.net/~pnh/ntpasswd/ which is very handy for resetting Windows passwords should you not know them. I had to do it in this case as there was no documentation on the default password for this laptop (an Acer), and I can vouch for its utility. Note that you don’t need to know the password for this tool to work.