Problem 1 ver. 1: brute-force solution

March 2nd, 2009 by Ivan Lakhturov | 0 | Category: Programming | Tags: |

Let us start with solutions to Project Euler problems. I will always start with brute-force solutions if those are possible and later on post optimized solutions. Every solution will be given in Scheme (R6RS) along with quick estimate of complexity. The reason for solving those problems is training myself in Scheme and, of course, fun.

Find the sum of all the multiples of 3 or 5 below 1000.

Solution:

  1.  

This is the simplest straightforward approach. Backward-recursion is used, with tail-recursion optimization, which is obligatory for all Scheme implementations, will be transformed into iteration. Backward direction is to simplify a function signature (otherwise an extra parameter is needed).

The complexity is O(n), assuming the (mod) operation is atomic. More strictly, the number of operations is 2*n. By the way, in R5RS (mod) is called (remainder).

Portage bug: global "doc" use flag

February 24th, 2009 by Ivan Lakhturov | 0 | Category: Linux | Tags: |

Meditating whether to merge docs for some package, I asked myself "why not to grab all those tons of mans available and store them locally?" Indeed, there's plenty of space on modern HDDs. So, I've set globally the "doc" flag and run rebuild of the whole system.

Strangely enough, adding this flag seems to require recompilation of binaries, but that's not the worse thing. Rebuild proccess just hangs on kdelibs package (exactly when installing help docs). Pressing Ctrl+C and trying again several times gives the same. I've hit upon such a phrase in a handbook:

The best way of enabling the doc USE flag is doing it on a per-package basis via /etc/portage/package.use, so that you get documentation only for packages that you are interested in. Enabling this flag globally is known to cause problems with circular dependencies.

What a poor excuse this sounds to me! Anyway, disabled that flag and recompiled everything back.

Hacking WordPress engine a bit

February 21st, 2009 by Ivan Lakhturov | 0 | Category: Miscellaneous | Tags: |

Just switched to a new WordPress theme (skin). Despite minimalistic, had to threw out several things from a sidebar.

I didn't like the default behaviour of the engine, when it's printing shortened versions of postings at the home page. Moreover, dereferencing links on that page is an awful feature. So, I've run into the engine and changed the_excerpt() function to the_content() one in files index.php, archive.php and search.php. Now it's ok. The following WordPress help topics were useful: The Loop, Changing Read More tag behaviour, however, I've not read them, just looked through.

Later on I'll backup and upgrade the engine to a new version. It'd nice to find proper colorizer for code-tag, preferably for Scheme and C# (the latest I'll update to handle Nemerle-code). I have also to look how to print tags (not html ones) near a posting. And does the latest engine's version support OpenID?

Bug, compiling PLT-Scheme

February 19th, 2009 by Ivan Lakhturov | 0 | Category: Linux, Programming | Tags: | |

The most easy-to-use Scheme compiler/interpreter is PLT, simple IDE is included. Emerging the latest ebuild gives errors under -O3 optimization flag, I confirmed it at the bugtracker. The solution is to switch temporarily to -O2.

Installing KDE

February 19th, 2009 by Ivan Lakhturov | 2 comments | Category: Linux | Tags:

I installed X, then KDE using the following manuals:

Building by itself caused no troubles. But testing clean X after the first step brought a problem with unresponsive mouse and keyboard, I couldn't even drop back to console with Ctrl+Alt+Backspace. Some gentoo forum topic (don't remember which) gave a solution - adding

Option "AllowEmptyInput" "false"

to the section "ServerFlags" of xorg.conf helped.

I wanted to install Gnome as well, but there are two packages blocking each other, namely avahi and mdnsresponder, one is default for Gnome, another for KDE, they both do the same and cannot live together on the same system. Strange, a year ago, when I assembled a Gentoo system with KDE and Gnome, there was no such problem. Anyway, there is a topic at the forum suggesting some solutions, but I'll try them later, no need to hurry with Gnome currently.

Installing Gentoo pure system

February 18th, 2009 by Ivan Lakhturov | 0 | Category: Linux | Tags:

My m/b (ASUS M3N78-VM) requires the kernel 2.6.25 or newer, even the latest Gentoo livecd didn't boot on my system. I used the SystemRescueCd on USB to boot it. Important thing was to load it with 64-bit kernel (in 32-bit we cannot be chroot'ed into 64-bit stage-3 gentoo image). Then everything was according to the Gentoo Handbook. As I wanted everything optimized for my CPU (quad-core Phenom), it was neccessary to update a toolchain. GCC at the Gentoo stable branch cannot compile with -march=amdfam10 flag, so I switched competely to the testing branch. I updated toolchain, then built the latest kernel (2.6.28-r1) and some must-have terminal applications - everything went smoothly.

And yes, the m/b works in AHCI-mode, max of 6 SATA-devices are accessible. This I couldn't get under Windows.

Plans for future

February 16th, 2009 by Ivan Lakhturov | 0 | Category: Linux, Programming | Tags: | | | |

Nemerle is waiting, but it have to wait more, while I'm learning Scheme. I have a plan to solve some problems from Project Euler, first with brute-force (however, it is not always possible), then using smarter ways, and post some solutions here under the tags "projecteuler" and "scheme".

Another thing, I am setting up currently a Gentoo Linux system on my workstation, so, some postings about this will come under the tag "gentoo". One of the reasons to install it is an unexpected difficulty with SATA-drives under Windows. The motherboard (Asus M3N78-VM) supports SATA-devices in three modes: SATA (only three accessible), RAID and AHCI. The latest is preferable for me, as I need more than three drives.

It was understandable when WinXP 64-bits (I didn't try any 32-bits systems, as I need more than 4 Gb of RAM) refused to work in AHCI-mode despite all my tricks with this and that, particlularly, manufacturer's drivers embedding with the nLite tool. But when Vista x64 with proper drivers could not load after switching m/b into AHCI, I decided that it's time to try Linux again. I prefer Gentoo, one of the most hardcore distributions available.

Updating Nemerle 7860 -> 8060 rev.

June 30th, 2008 by Ivan Lakhturov | 0 | Category: Programming | Tags: |

Just updated the compiler and integration from revision 7860 to 8060. Had no chances to look carefully for changes in this big gap, only read the log, and what I noticed is the following.

Compiler: a fix for incremental rebuild (7883), which should preserve a bit more time while building now. Extension methods should be now externally visible (7893). Filter method for Hashtable is implemented (7917). Some tweaks for locations (7956, 7970, 7980, 7982), some changes for literals parsing (8045), those should be good for refactoring features. The integration is merged into the compiler trunk (8060)!

Integration: new batch for building appeared (7952). Highlights for tail calls (7967). Rename refactoring (7968 etc.): good work by Sergei Tulentsev, regardless of the feature maturity (I'll check it out later). 'Go to type' navigation feature (7969). Inline refactoring (7990), I'm already interested. Some WPF support (8017). April CTP (8018), currently the last, I guess. VS2005 support is dropped (8018), quite a decision, I'd rather say.

Building of the compiler (with help of Compiler\buildandreg.cmd) passed all the stages flawlessly. Compiling the integration (Compiler\VsIntegration\build_dev.cmd), there are warnings about circular dependencies, but as I remember, that's some glitch from the past that is not breaking anything, but hard to circumvent. In other respects the integration builds without obstacles, that's good.

Opening my pet project under VS2008 with an experimental hive ("C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe" my-pet-project.sln /rootsuffix Exp /RANU)... success. Building... errors... obviously, some references fell off (referenced namespace 'System.Runtime.Serialization.Formatters.Soap' does not exist). Adding them back, compiling, success.

Jumping from Error List and Output windows to a source doesn't work now. Checking out Rename refactoring for a local variable: it's working, cool! Inline refactoring: doesn't work. Anyway, that's a good
startup. Ok, I'll proceed another day.

Plan for this blog

June 30th, 2008 by Ivan Lakhturov | 0 | Category: Programming | Tags: | |

This blog will be devoted solely to my programming trials, in particularly with the Nemerle programming language and its integration subproject with Visual Studio. I have little time now for doing that, as I am currently a Ph.D. student in the Netherlands (mathematical physics), but I'm interested very much e.g. in implementing refactoring for Nemerle.

I already spent around a year (of leisurely work) for the Nemerle integration project and implemented for instance such features, as Find usages, Highlight symbol and a mini-framework for extensive testing of such stuff. Then I made a large break in playing with the integration (however, continuing with Nemerle itself) lasting up to now, and I'm planning to proceed with it, contributing from time to time.