Finland is Missing the Bowling Alley or How to Find the First Pin
The linked article discusses well why it is hard for Finnish software startups to become major worldwide players.
5 More Red Flags for Suspicious Files 🚩
3 days ago
Yet another computer programming blog.
halts P = 無
1{h; r [file]
D;}
2{x; G; }
h - "Replace the contents of the hold space with the contents of the pattern space."
r [file] - "Queue the contents of filename to be read and inserted into the output stream at the end of the current cycle, or when the next input line is read. Note that if filename cannot be read, it is treated as if it were an empty file, without any error indication."
D - "Delete text in the pattern space up to the first newline. If any text is left, restart cycle with the resultant pattern space (without reading a new line of input), otherwise start a normal new cycle."
x - "Exchange the contents of the hold and pattern spaces."
G - "Append a newline to the contents of the pattern space, and then append the contents of the hold space to that of the pattern space. "
sed -i '1{h; r /tmp/license
D;}
2{x; G; }' *.[ch]
if (x < UINT_MAX-1)
puts("foo");
else
puts("bar")
%1 = load i32* %x, align 4
%2 = icmp ult i32 %1, -2
br i1 %2, label %bb, label %bb1
bb:
%3 = call i32 @puts(i8* getelementptr ([4 x i8]* @.str, i32 0, i32 0)) nounwind
br label %bb2
bb1:
%4 = call i32 @puts(i8* getelementptr ([4 x i8]* @.str1, i32 0, i32 0)) nounwind
br label %bb2
bb2:
ucfirst(reverse(lower(Lime)))
after a similar tool called Lime for testing Java programs, developed here as well).
int input(void);
int main() {
int i = input();
int j = input();
if (i > j) {
i = i / (0*j); // ouch
} else {
i = j;
}
return i;
}
{i: 892648572, j: -1285173836}
-------module.c--------
int bar(void);
int hooray() {
return bar() + 42;
}
-----------------------
-------bar.cpp--------
int bar(void) {
return 7;
}
-----------------------
$ g++ -c -O0 -o bar.o bar.cpp
$ gcc -c -O0 -o module.o module.c
$ gcc -O0 bar.o module.o
module.o: In function `hooray':
module.c:(.text+0x7): undefined reference to `bar'
collect2: ld returned 1 exit status
-- [clip] --
00000000 <_Z3barv>:
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: b8 07 00 00 00 mov $0x7,%eax
8: 5d pop %ebp
9: c3 ret
-- [/clip] --
-------bar.cpp--------
extern "C" {
int bar(void) {
return 7;
}
}
-----------------------
$ g++ -c -O0 -o bar.o bar.cpp
$ gcc -O0 bar.o module.o
Exception in thread "main" java.lang.UnsatisfiedLinkError: no gcd in java.library.pathGoogle reminded me of LD_LIBRARY_PATH, but setting it to the current path did not help. I kept having the same error.
Exception in thread "main" java.lang.UnsatisfiedLinkError: Gcd.gcd(II)IIt was still an UnsatisfiedLinkError, but it dropped the talk about java.library.path.
public class Gcd {
public static native int gcd(int a, int b) throws IllegalArgumentException;
static {
System.loadLibrary("Gcd");
}
}
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class Gcd */
#ifndef _Included_Gcd
#define _Included_Gcd
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: Gcd
* Method: gcd
* Signature: (II)I
*/
JNIEXPORT jint JNICALL Java_Gcd_gcd
(JNIEnv *, jclass, jint, jint);
#ifdef __cplusplus
}
#endif
#endif
#include "Gcd.h"
JNIEXPORT jint JNICALL
Java_Gcd_gcd(JNIEnv *env, jclass cl, jint a, jint b)
{
if (a < 0 || b < 0) {
jclass ex = env->FindClass(
"java/lang/IllegalArgumentException");
env->ThrowNew(ex, "Both arguments must be positive.");
env->DeleteLocalRef(ex);
return -1;
}
while (a != b) {
if (a > b) {
a -= b;
} else {
b -= a;
}
}
return a;
}
public class Test {
public static void main(String[] args) {
System.out.println("gcd(12,24) = " + Gcd.gcd(12, 24));
}
}
CC=g++
INCLUDE=-I/usr/lib/jvm/java-1.5.0-sun-1.5.0.16/include/linux/ -I/usr/lib/jvm/java-1.5.0-sun-1.5.0.16/include
libGcd.so: Gcd.o
$(CC) -shared -o libGcd.so Gcd.o
Gcd.o: Gcd.cpp
$(CC) $(INCLUDE) -O3 -c Gcd.cpp
clean:
rm -f libGcd.so Gcd.o
import sys
from subprocess import *
p1 = Popen(["git", "log"], stdout=PIPE)
p2 = Popen(["grep", "^Date"], stdin=p1.stdout, stdout=PIPE)
p3 = Popen(["awk", "{printf \"%d \", $5}"], stdin=p2.stdout, stdout=PIPE)
output = p3.communicate()[0]
hours = output.split()
stats = {}
for h in range(0,24):
stats[h] = 0
for h in hours:
stats[int(h)] += 1
for k in stats.keys():
print "%02d: %s" % (k, "*"*stats[k])
00: *****
01: ***
02:
03: **
04:
05:
06:
07:
08:
09:
10: **
11: *****
12: ************
13: ************
14: **********************************
15: **********************
16: ************
17: **********
18: **
19: ***
20: ***
21: **
22: *
23:
\renewcommand\bibname{Foo}Another thing: why must the scripting language used in BibTeX style files (.bst) be so confusing? Anyone knows what this language is, or is this just an adhoc language created for that single purpose? Anyhow, I'd like to find a manual for it.
cfold’ f z [] = z
cfold’ f z (x:xs) = f x z (\y -> cfold’ f y xs)
cfold f z l = cfold’ (\x t g -> f x (g t)) z l
(\x t g -> (*) x (g t))It says that given the head of the list, x, a base value for the fold, t, and the function g that yields the result of the fold for the tail of the list when it is given t, the result of the whole fold is the list head multiplied by the value of the fold for the list tail.
cfold (+) 0 [1]
(\f z l -> cfold' (\x t g -> f x (g t)) z l) (+) 0 [1]
cfold' (\x t g -> (+) x (g t)) 0 [1]
(\f z (x:xs) -> f x z (\y -> cfold' f y xs)) (\x t g -> (+) x (g t)) 0 [1]
(\x t g -> (+) x (g t)) 1 0 (\y -> cfold' (\x t g -> (+) x (g t)) y [])
(+) 1 ((\y -> cfold' (\x t g -> (+) x (g t)) y []) 0)
(+) 1 0
1
$ cd ~/koodi/auto<tab> <enter>
$ j auto <enter>
Then we compile with -O3:#include <stdio.h>
unsigned long int fib(int n) {
if (n < 3)
return 1;
return fib(n-2) + fib(n-1);
}
int main() {
int i;
for (i=1; i < 46; i++)
printf("fib(%d) = %ld\n", i, fib(i));
return 0;
}
llvm-gcc -O3 fib.c -o fib-llvm-gcc
gcc -O3 fib.c -o fib-gcc
time ./fib-llvm-gcc
real 0m3.053s
user 0m3.052s
sys 0m0.000s
time ./fib-gcc
real 0m11.176s
user 0m11.173s
sys 0m0.004s
wc fib-llvm-gcc.S
108 288 1900 fib-llvm-gcc.S
wc fib-gcc.S
291 738 4485 fib-gcc.S
"Baker, Cooper, Fletcher, Miller, and Smith live on different floors of an apartment house that contains only five floors. Baker does not live on the top floor. Cooper does not live on the bottom floor. Fletcher does not live on either the top or the bottom floor. Miller lives on a higher floor than does Cooper. Smith does not live on a floor adjacent to Fletcher's. Fletcher does not live on a floor adjacent to Cooper's. Where does everyone live?" (SICP, pp. 418)A Haskell version of the (almost) same solution follows (Control.Monad and Data.List are needed):
Nondeterminism allows us to omit writing the loops that try all possible execution paths. Nondeterministic computing can be imagined as if the computer simultaneously tried all the possible branches of a computation, where the computation branches every time there are multiple choices to proceed, and stops the branches that yield no result, and finally, returns all results from the succeeded branches.type Name = String
type Floor = Int
adjacent :: Floor -> Floor -> Bool
adjacent a b = abs (a-b) == 1
distinct :: [Floor] -> Bool
distinct l = l == nub l
dinesman :: [[(Name,Floor)]]
dinesman = do
baker <- [1..5]
cooper <- [1..5]
fletcher <- [1..5]
miller <- [1..5]
smith <- [1..5]
guard (distinct [baker,cooper,fletcher,miller,smith])
guard (baker /= 5)
guard (cooper /= 1)
guard (not (fletcher == 1) || fletcher == 5))
guard (miller > cooper)
guard (not (adjacent smith fletcher))
guard (not (adjacent fletcher cooper))
return [("Baker", baker),
("Cooper", cooper),
("Fletcher", fletcher),
("Miller", miller),
("Smith", smith)]
class Monad m => MonadPlus m whereThe operation mzero denotes failure while the operation mplus denotes choice or combination. Here are the semantics of the operations:
mzero :: m a
mplus :: m a -> m a -> m a
mzero >>= f = mzeroThe first reads that if a failure is applied on some action, the result is still a failure. The second reads that if something other than a failure is added to a failure, the result is the non-failure thing. The third reads that if a failure is added to something other than a failure, the result is again the non-failure thing. The two previous definitions are thus analogous to logical OR. The last one reads that the mplus binary operation is associative.
a `mplus` mzero = a
mzero `mplus` b = b
a `mplus` (b `mplus` c) = (a `mplus` b) `mplus` c
instance MonadPlus [] whereThe previous means that with lists, the empty list represents a failure and appending represents combination.
mzero = []
a `mplus` b = a ++ b
guard :: MonadPlus m => Bool -> m ()So guard is an operation that takes a boolean expression and returns a () value meaning "no information" if the boolean argument evaluates to true, and mzero if the boolean argument evaluates to false.
guard True = return ()
guard False = mzero
"The functional style of programming canWhat could be added is the concept of recursion.
be summarized with the following characteristics:
- referential transparency
- higher-order functions
- lazy evaluation
- pattern matching
Referential transparency is the term used
traditionally to express that the value of
an expression depends only on the values
of its subexpressions, and that the value
of each occurrence of an object is the
same, irrespective of the context. In other
words, side effects are ruled out. Functions
being higher-order means that they are
first-class values and can, for instance,
be stored in data structures and
returned as result of function calls. Lazy
evaluation is tantamount to "nonstrictness,"
meaning that the value of an object is not
computed until it is actually needed, and
thus the value of an argument may be
undefined when calling and executing the
function. Pattern matching is a general
term used to express the mechanism applied
when trying to make X and Y identical in an
equation X = Y where X and Y are expressions.
Pattern matching is restricted in functional
programming to introduce bindings only to
the left-hand side X when solving such an
equation."
(Paakki, J. 1995. Attribute grammar paradigms—a high-level methodology in language implementation. ACM Comput. Surv. 27, 2 (Jun. 1995), page 236.)