このテーマをインストール

Learning Scala, Haskell & Clojure. While simultaneously still trying to grasp the most basic OOP principles and patterns. I find it difficult to write good code. Maybe I am retarted.

Solution to http://cotpi.com/p/48/

Given the number of all positive divisors of an unknown positive integer and the product of those divisors, how can one find the unknown integer?

Let \(x\) be the number in question; \(\{\alpha_i\}, i = \overline{1,N}\) — set of all positive divisors of \(x\) where \(N\) is the number of those divisors; \(q = \prod \alpha_i\). Now, \(x = \prod p_i^{n_i}, i=\overline{0,K}\), where \(p_i\) are primes. Also we can represent each divisor \(\alpha_i\) as \(\prod_{j=1}^K p_j^{s_{i,j}}\), where \(0 \leq s_{i,j} \leq n_j\) and \(n_j\) is the power of \(j\)th prime in our factorization. From this we can see that there are \(\prod (n_i + 1) = N\) divisors of \(x\). Also there are \(\frac{N}{n_i+1}\) different divisors of \(x\) with \(i\)th prime in some fixed power. Since \(i\)th prime of our factorization can take powers \(0, 1, \ldots, n_i\) and for each power there are \(\frac{N}{n_i+1}\) divisors then total power of \(p_i\) in \(q\) will equal to \(\frac{n_i (n_i +1)}{2}\frac{N}{n_i+1} = \frac{n_i N}{2}\). Hence \(q = \prod p_i^{\frac{n_i N}{2}} = \left(\prod p_i^{n_i}\right)^\frac{N}{2} = x^\frac{N}{2}\). Thus \(x = q^\frac{2}{N}\).

Unity terraforming.

var particle : GameObject; var hit : RaycastHit; var darticle : Terrain; function OnMouseDrag () { var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition); if (Physics.Raycast (ray, hit)) { var nw = new Vector3(hit.point.x, hit.point.y, hit.point.z); nw.y = particle.transform.position.y; particle.transform.position = nw; } var data : TerrainData = darticle.terrainData; var p = w2t(darticle, hit.point); var oldHs = data.GetHeights(p.x, p.y, 20, 20); var m : float; for(var i = 0; i < 20; i++) { for(var j = 0; j < 20; j++) { m += oldHs[i, j] / 400; } } for( i = 0; i < 20; i++) { for (j = 0; j < 20; j++) { var d = Mathf.Sqrt((i - 10) * (i - 10) + (j - 10) * (j - 10)); if( d <= 10 ) { oldHs[i, j] = oldHs[i, j] - (oldHs[i,j] - m) / (d + 1); } } } data.SetHeights(p.x, p.y, oldHs); } function w2t (terrain : Terrain, worldPos : Vector3) : Vector2 { var terrainLocalPos = worldPos - terrain.transform.position; var normalizedPos = Vector2(Mathf.Round(Mathf.InverseLerp(0.0, terrain.terrainData.size.x, terrainLocalPos.x) * terrain.terrainData.heightmapWidth), Mathf.Round(Mathf.InverseLerp(0.0, terrain.terrainData.size.z, terrainLocalPos.z) * terrain.terrainData.heightmapHeight)); return normalizedPos; }

Storing data

After working with MySQL on high loads the desire to have something “better” wouldn’t surprise anybody. We have several options in what kind of databases we can use. There are realtional DBs and their SQL, there are OODBs, there are lots and lots of NoSQL solutions.

Relational DBs are numerous but very few of them are actually widely used. MySQL, PostgerSQL and Oracle. These three are probably the most well known nowadays. MySQL isn’t really that good, Oracle is really that expensive and PostrgeSQL is something in between and I need yet to use it under some heavy load to get to know it better.

OODBs are something that was hyped some time ago but had never emerged as a really big thing. And all information about those that are still alive is either advertising or very scarse and/or old. Maybe they are awesome. Maybe one day I will have enough free energy to look at them closely and use in some project.

NoSQL is all the hype. But they have real problems. First there is no such thing as a NoSQL DB model. They are all different and they all solve different problems, and sometimes it is hard to understand which ones are best for what. Second, all of them are very buggy except, probably, memcached which doesn’t have persistence so it is not a real alternative for traditional DB. It really makes me shiver when I read release notes for a new stable minor version of some NoSQL DB and they say something like “blah blah used to crash all nodes”, “issuing foo bar used to corrupt persistent storage forever” and stuff like this. I mean at least traditional SQL DBs generally stroe what you tell them to and do not tend to corrupt their storage randomly. It really scares me from using these new products in production.

*Please, if you read this somehow, note that I do not write these posts as posts. I just throw some thoughts I have on a subject to get rid of them. I have to write things down to free my mind a little. I also do not write often so I have to learn how to do it now, being 24 years old. It’s painful for me as well. *

What am I doing? Dammit!

Oh noes! Me learning C++!

Motown is just so fucking awesome.

jartur

SICP again. Why?

; 1.3 (defn som [x y z] (let [ssq (fn [a b] (+ (* b b) (* a a)))] (if (> x y) (if (> z y) (ssq x z) (ssq x y)) (if (> z x) (ssq y z) (ssq y x)))))

; 1.7 (defn sqrt-iter [x] (let [avg (fn [x y] (/ (+ x y) 2))] (loop [guess 1.0 x x] (let [improved (avg guess (/ x guess)) good-enough? (< (Math/abs (- guess improved)) 0.0001)] (if good-enough? improved (recur improved x))))))

JAPAN.