Archive

Archive for the ‘Computer science and math’ Category

Math jokes

June 29th, 2008 No comments

From here.

An engineer, a physicist and a mathematician are staying in a hotel.
The engineer wakes up and smells smoke. He goes out into the hallway and sees a fire, so he fills a trash can from his room with water and douses the fire. He goes back to bed.
Later, the physicist wakes up and smells smoke. He opens his door and sees a fire in the hallway. He walks down the hall to a fire hose and after calculating the flame velocity, distance, water pressure, trajectory, etc. extinguishes the fire with the minimum amount of water and energy needed.
Later, the mathematician wakes up and smells smoke. He goes to the hall, sees the fire and then the fire hose. He thinks for a moment and then exclaims, “Ah, a solution exists!” and then goes back to bed.

Asked if he believes in one God, a mathematician answered:
” Yes, up to isomorphism.”

A mathematician, scientist, and engineer are each asked: “Suppose we define a horse’s tail to be a leg. How many legs does a horse have?” The mathematician answers “5″; the scientist “1″; and the engineer says “But you can’t do that!

One day a farmer called up an engineer, a physicist, and a mathematician and asked them to fence of the largest possible area with the least amount of fence.
The engineer made the fence in a circle and proclaimed that he had the most efficient design.
The physicist made a long, straight line and proclaimed “We can assume the length is infinite…” and pointed out that fencing off half of the Earth was certainly a more efficient way to do it.
The Mathematician just laughed at them. He built a tiny fence around himself and said “I declare myself to be on the outside.”

A mathematician belives nothing until it is proven
A physicist believes everything until it is proven wrong
A chemist doesn’t care
biologist doesn’t understand the question.

Two male mathematicians are in a bar. The first one says to the second that the average person knows very little about basic mathematics. The second one disagrees, and claims that most people can cope with a reasonable amount of math.
The first mathematician goes off to the washroom, and in his absence the second calls over the waitress. He tells her that in a few minutes, after his friend has returned, he will call her over and ask her a question. All she has to do is answer one third x cubed.
She repeats “one thir — dex cue”?
He repeats “one third x cubed”.
Her: `one thir dex cuebd’? Yes, that’s right, he says. So she agrees, and goes off mumbling to herself, “one thir dex cuebd…”.
The first guy returns and the second proposes a bet to prove his point, that most people do know something about basic math. He says he will ask the blonde waitress an integral, and the first laughingly agrees. The second man calls over the waitress and asks “what is the integral of x squared?”.
The waitress says “one third x cubed” and while walking away, turns back and says over her shoulder “plus a constant!”

Just another wget clone

June 10th, 2008 No comments

While nothing interesting is happening in my life I post my recent program. Simply wget clone, with -m option it downloads all images and some stylesheets from the page and changes them to local adresses. Sorry for Polish comments and names in source file.

Source

Współczynnik durności ankiety

May 12th, 2008 2 comments

W sobotę po kolokwium (tak, było w sobotę…) czekając na ludzi, zaczepił mnie jakiś student psychologii z prośbą o wypełnienie ankiety. Tematem ankiety była seksualność. Miałem chwilę czasu i byłem ciekawy, o co chodzi (tak, zaciekawiła mnie ta seksualność), więc przystąpiłem do wypełniania.

Budowa ankiety była dosyć prosta. Zawierała jakieś 40-50 pytań tak/nie typu “czy miewasz erotyczne sny z X?”, “czy uprawiałeś seks z X?”, “czy potrafisz być czuły wobec X?”, “czy podniecają Cię ładne/ładni X?”, “czy czujesz potrzebę zrealizowania się w związku z X?”, gdzie pytania o numerach nieparzystych miały zamiast X słowo “dziewczynami”, a reszta ─ “chłopakami”. Nie powiem, jak odpowiadałem, w każdym razie zaznaczyłem niektóre z tych parzystych. :>

Przy okazji wpadłem na pomysł współczynnika durności testu. Większość z nich zawiera potwarzające się pytania, tylko inaczej sformułowane. Ma to na celu wyeliminowanie czegośtam, nieważne. W każdym razie, jeśli jest tego za dużo, to to irytuje.

Teraz zacznie się matematyka. Niech Q będzie zbiorem pytań ankiety, a relacja = określona na zbiorze [tex]Q^2[/tex] jest zdefiniowana następująco:

Jeśli a i b należą do zbioru Q, to a = b [tex]\Longleftrightarrow[/tex] a pyta o to samo, co b.

Oczywistym jest, że = jest relacją równoważności. Napis [a] (dla a należącego do Q) będzie oznaczał klasę abstrakcji względem tej relacji (dla humanistów: zbiór wszystkich pytań pytających o to samo, co a). Współczynnik durności ankiety, S, definiuje wzór:

[tex]S = \frac{|Q|}{| \lbrace [a] | a \in Q \rbrace|}[/tex]

Czyli innymi słowy stosunek liczby pytań do liczby pytań unikalnych. :> Teraz trzeba wymyślić jakąś skalę, ja przyjąłem, że do 1,1 ankieta normalna, do 1,4 jest normalnym psychologicznym testem, a do 2,0 jest durna. Powyżej 2,0 staje się niepoważna.

LOLCode Compiler (my own!)

April 23rd, 2008 No comments

Hah! My dream have come through! I wrote my first compiler with my own lexer and parser. It compiles LOLCode (slightly modified version, see in specification [in polish, but only output language]) to stack machine language. My project contains also stack machine which interprets output files and prints them in human readable assembler and three examples of LOLCode programs. It’s all GPL so you can learn how it works. It’s written in C and I didn’t have much time to write pretty dynamic arrays and If someone will fix it, I would be verry happy. If you’ve got question about how it works, go ahead, write me and ask.

Source: http://www.srednikpe.org/src/lcc/

Mój plan na semestr letni

February 23rd, 2008 No comments

Przy okazji pobawiłem się Google Spreadsheet. ;)

http://spreadsheets.google.com/pub?key=pGWzSN9qMru5kSDOS6VN_Sg

pyhttpd – a tiny HTTP deamon written in Python

February 11th, 2008 No comments

It’s for my Python Course. It provides only very basic HTTP, but yet can be used for simple WWW hosting. Source.

Features:

  • GET and POST methods
  • New thread for new connection
  • Directory listing
  • Error pages
  • Document index
  • Deafult type and charset
  • Python scripts ;)
  • Configuration file
  • … and my own modules to handle these

TODOs:

  • Logging
  • Much more stability (exceptions handling, etc.)
  • Sending gzipped or chunked data (if accepted)
  • Range headers
  • … and many, many other

To run just edit pyhttpd.conf and change Port and Document root. Then type “python pyhttpd.py” and it should be now listening for connections.

How to run a python script and its output send to client? Pyhttpd checks if the requesting file is a python one. If so then it opens a python interpreter by a pipe, sends _GET and _POST dictionaries and file contents. And finally, sends interpreter outputs to client.

_GET and_POST are just dictionaries with variable names as keys. So if there is a foobar.py?i=500 request then _GET will be { ‘i’ : ’500′ } (note that this is always a string value).

It’s GPL if someone asked.

JZW Interpreter source and examples

September 9th, 2007 1 comment

All right. I said I’ll show my jzwi source and here it is: http://www.srednikpe.org/src/jzwi/

It is almost ended. It doesn’t only check local variable if they have unique names. I’m too lazy to do that. But after all it works fine and quite fast (compared to other interpreters written by my colleagues).

To run jzwi program just run “jzwi program.jzw argument1 argument2 …”.

It’s all licensed on GPL (any version). There is no guarantee that it’ll work. ;)

JZWI

August 22nd, 2007 No comments

Uff… I have nearly finished my jzwi interpreter, just few minor fixes I will make in a week…

JZWI means “Język z wykładu improved” (“Language from lecture improved”). On our programming language theory subject we defined syntax using BNF notation and then we define formal semantic of this language (which is quite simmilar to Pascal/ALGOL).

It was our lab project to write a parser, converter to xHTML/LaTeX, an interpreter or full compiler in Haskell. It wasn’t as difficult as I thought, but I had to rewrite many parts of the code, ’cause firstly I wrote only simply parser, then simply converter and then I decided to try interpreter.

It costed me few nights and days, but I am very happy, when I see how beautifully it runs insertion sort. ;) Full source will be uploaded within few days. I have to lay off from vim and ghc. ;)

Uff… maybe I’ll check insertion sort once more. :>