From f040c492d180218c48700a4b35c3a6186c5373f1 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 27 Jan 2009 03:20:10 +0100 Subject: [PATCH] Update Tuesday, 27th of January, Anno Domini MMIX, at the hour of the Tiger Signed-off-by: Johannes Schindelin --- index.html | 113 +++++++++++++++++++++++++++++++------------------- source-1233022809.txt | 51 +++++++++++++++++++++++ sovrce-1232992321.txt | 26 ++++++++++++ 3 files changed, 148 insertions(+), 42 deletions(-) create mode 100644 source-1233022809.txt create mode 100644 sovrce-1232992321.txt diff --git a/index.html b/index.html index efc0f7545a..71c1fb835d 100644 --- a/index.html +++ b/index.html @@ -12,6 +12,7 @@ Table of contents:

- Older posts + Older posts
@@ -86,6 +86,75 @@
+
Tuesday, 27th of January, Anno Domini MMIX, at the hour of the Tiger
+ +

Fun with calculus after midnight

+ +

+

+ Problem: what is the shortest way of defining a variable consisting of N + spaces? I.e. for N=80 the result will look something like +

+ + + +
+
                                                                
+
+ + +
+
+s='    '
+s="$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s"
+
+
+
+

+ Let's see. Let the minimal number of characters needed be A(N). For + simplicity, let's say that we only use one variable. Then, certainly, A(N) + cannot be larger than 5+N, as we could define a variable using 1 character + for the name, 1 for the equal sign, 2 for the quotes, and one for the semicolon + or newline character (whichever). +

+ Now, let's assume N is a product K*L. Then certainly, A(N) cannot + be larger than A(K)+5+2*L, as we could first define a variable that has + exactly K spaces and then use that to define the end result (in the example + above, K=5 and L=20). +

+ So, for which N=K*L is it better to use two definitions instead of one? +

+ Simple calculus says that 5+K*L>5+K+5+2*L must hold true, or (after some + scribbling): L>1+7/(K-2). Which means that it makes no sense to define + a variable with 1 or 2 spaces first, which is kinda obvious (writing '$s' + alone would use two characters, so we could write the spaces right away). +

+ But what for the other values? For K=3, L must be at least 9 to make + sense (in other words, N must be at least 27). For K=4, L needs + to be greater or equal to 5 (N>=20), the next pairs are (5,4), + (6,3), (7,3), (8,3), (9,3) and starting with K=10, any + L>1 makes sense. +

+ The second definition can also contain spaces at the end, however, so for any + N=K*L+M, A(N) cannot be larger than A(K)+5+2*L+M. +

+ Not surprisingly, this leads to exactly the same L>1+7/(K-2) (as we can + append the M spaces in the last definition, no matter if we use 1 or + 2 definitions). +

+ However, that means that as soon as N>=18, we should use two definitions, + prior to that, it makes no sense. +

+ So for N<18, A(N)=5+N. +

+ But what K should one choose, i.e. how many spaces in the first definition? + In other words, what is A(N) given that we use two definitions? +

+ That will have to wait for another midnight. Just a teaser: A(80)=36. Oh, + and with 80 characters, you can define a string of 9900 spaces... +

Monday, 26th of January, Anno Domini MMIX, at the hour of the Dog

Valgrind takes a loooong time

@@ -590,46 +659,6 @@ $ git ls-files --stage | sort -k2 | uniq -d -s7 -w40

Which is good, because if they were not that funny, they would be pretty sad.

-
Thursday, 22nd of January, Anno Domini MMIX, at the hour of the Dragon
-
-

Sverre's hat

- -

-

- The fun part about a blog is that you can talk about less technical stuff. - For example, Sverre's hat. -

- Let me start a bit earlier, so that you get the context. -

- Last year, at the GitTogether, - we had an unconference style - conference, which basically meant that it was our job to decide what - we want to talk about. -

- It turned out to be pretty hard, because there was so much we wanted to - discuss, and because we wanted to get to know each other, and we wanted to - do some hacking. -

- So to help us decide what subjects, and in which order we wanted to have - scheduled, Shawn opened a series on - Google Moderator, a nifty, yet simple application which allows a group - to agree quickly on an agenda. -

- It worked quite well; However, that little saboteur displayed his sense of - humor so overtly that some entertaining Gitter put the question "Should Sverre - wear a hat?" on the agenda. -

- Sure enough, the subject got voted up, and eventually, we got Sverre a hat: -

-

-

- By the way, another thing I like about this blog engine is that there are no - comments... Nothing is more annoying than leaving a comment on a blog, - forgetting about it for a few months, and then finding somebody answered - ages ago. -

- Update: Sverre says it was dsymonds idea. -

diff --git a/source-1233022809.txt b/source-1233022809.txt new file mode 100644 index 0000000000..dc8a0ae959 --- /dev/null +++ b/source-1233022809.txt @@ -0,0 +1,51 @@ +Fun with calculus after midnight + +Problem: what is the shortest way of defining a variable consisting of ''N'' +spaces? I.e. for ''N=80'' the result will look something like + + +s=' ' +s="$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s" + + +Let's see. Let the minimal number of characters needed be ''A(N)''. For +simplicity, let's say that we only use one variable. Then, certainly, ''A(N)'' +cannot be larger than ''5+N'', as we could define a variable using 1 character +for the name, 1 for the equal sign, 2 for the quotes, and one for the semicolon +or newline character (whichever). + +Now, let's assume ''N'' is a product ''K*L''. Then certainly, ''A(N)'' cannot +be larger than ''A(K)+5+2*L'', as we could first define a variable that has +exactly ''K'' spaces and then use that to define the end result (in the example +above, ''K=5'' and ''L=20''). + +So, for which ''N=K*L'' is it better to use two definitions instead of one? + +Simple calculus says that ''5+K*L>5+K+5+2*L'' must hold true, or (after some +scribbling): ''L>1+7/(K-2)''. Which means that it makes no sense to define +a variable with 1 or 2 spaces first, which is kinda obvious (writing '$s' +alone would use two characters, so we could write the spaces right away). + +But what for the other values? For ''K=3'', ''L'' must be at least 9 to make +sense (in other words, ''N'' must be at least 27). For ''K=4'', ''L'' needs +to be greater or equal to 5 (''N>=20''), the next pairs are ''(5,4)'', +''(6,3)'', ''(7,3)'', ''(8,3)'', ''(9,3)'' and starting with ''K=10'', any +''L>1'' makes sense. + +The second definition can also contain spaces at the end, however, so for any +''N=K*L+M'', ''A(N)'' cannot be larger than ''A(K)+5+2*L+M''. + +Not surprisingly, this leads to exactly the same ''L>1+7/(K-2)'' (as we can +append the ''M'' spaces in the last definition, no matter if we use 1 or +2 definitions). + +However, that means that as soon as ''N>=18'', we should use two definitions, +prior to that, it makes no sense. + +So for ''N<18'', ''A(N)=5+N''. + +But what ''K'' should one choose, i.e. how many spaces in the first definition? +In other words, what is ''A(N)'' given that we use two definitions? + +That will have to wait for another midnight. Just a teaser: ''A(80)=36''. Oh, +and with 80 characters, you can define a string of 9900 spaces... diff --git a/sovrce-1232992321.txt b/sovrce-1232992321.txt new file mode 100644 index 0000000000..eb0fa04937 --- /dev/null +++ b/sovrce-1232992321.txt @@ -0,0 +1,26 @@ +#!/usr/bin/perl + +@A = (0, 6); +@B = (0, 1); +@C = ("", "(0,1)"); + +$N = 100000; +for ($i = 2; $i < $N; $i++) { + $A[$i] = 5 + $i; + $B[$i] = 1; + $C[$i] = "(0,$i)"; + for ($j = 3; $j <= $i / 2; $j++) { + $k = int($i / $j); + $l = $i - $j * $k; + $tmp = $A[$j] + 5 + 2 * $k + $l; + if ($A[$i] > $tmp) { + $A[$i] = $tmp; + $B[$i] = $B[$j] + 1; + $C[$i] = $C[$j] . " ($k,$l)"; + } + } +} + +for ($n = 1; $n < $N; $n++) { + printf("% 5d: % 5d %d %s\n", $n, $A[$n], $B[$n], $C[$n]); +} -- 2.11.4.GIT