Posted by: bud1setiawan | October 2, 2007

Pan Cake Problem

cooking the perfect stack of pancakes on a grill is a tricky business, because no matter how hard you try all pancakes in any stack have different diameters. for neatness’s sake, however, you can sort the stack by size such that each pancake is smaller than all pancakes below it. the size of a pancake is given by its diameter.

sorting a stack is done by a sequence of pancake “flips.” A flip consist of inserting a spatula between two pancakes in a stack and flipping (reversing) all the pancakes on the spatula (reversing the sub-stack). A flip is specified by relative to the entire stack. the bottom pancake has position 1, while the top pancake on a stack of n pancakes has position n.

A stack is specified by giving the diameter of each pancake in the stack in the order in which the pancakes appear. For example, consider the three stacks of pancakes below in which pancake 8 is the top-most pancake of the left stack :

8 7 2
4 6 5
6 4 8
7 8 4
5 5 6
2 2 7

the stack on the left can be transformed to the stack in the middle via flip(3). The middle stack can be transformed into the right stack via the command flip(1).

input
the input consist of a sequence of stacks of pancakes, Each stack consist of between 1 and 30 pancakes and each pancake will have an integer diameter between 1 and 100. the input is terminated by EOF. Each stack is given as a single line of input with the top pancake on a stack appearing first on a line, the bottom pancake appearing last, and all pancakes separated by a space.

output
for each stack of pancakes, your program should echo the original stack on one line, followed by a sequence of flips that result in sorting the stack of pancakes so that the largest pancake is on the bottom and the smallest on the top. the sequence of flips for each stack should be terminated by a 0 (number 0), indicating no more flips necessary. once a stack is sorted, no more flips should be made.

sample input
1 2 3 4 5
5 4 3 2 1
5 1 2 3 4

sample output
1 2 3 4 5
0
5 4 3 2 1
1 0
5 1 2 3 4
1 2 0

solution

well, this is a kind of a real long line of code with comments scattered around everywhere. i have no intention or motivation at all except trying to write a good OOP code full with its documentataion : the JAvadox. I have already tried to strip it and yielded less than 100 lines but the code above is still the full complete version.

Posted by: bud1setiawan | September 30, 2007

BBC sleep profiler : good for you, owl!

Your profile summary

Your sleep is very well optimised, scoring 81 %.You said you sometimes have a problem with sleep, though you are not at all sleepy during the day, which indicates your body is getting the sleep it needs. Quality of sleep is more important than quantity. You may find your personalised advice below useful for the odd bad night.

Body and Health

You are an “Owl”

  • You are built to be at your best later in the day. Surprisingly, it also means your body clock is more flexible than people with standard or lark-like body clocks.
  • Ideally, people should wake at the same time everyday, but being an owl, you can probably cope quite well when your sleep pattern is disrupted.

Now you’re a teenager you need more sleep

  • At your age, you need a lot of sleep – usually around nine hours is normal. This is due to all the changes your body is going through. If you’re feeling sleepy during the day, go to bed earlier to get the sleep you need.

Environment

Excellent, your bedroom is optimised for sleep

  • By keeping your bedroom as simply somewhere to sleep you are giving yourself the maximum chance of doing just that.
  • Having items that are used for fun or work would change how you view your room; from somewhere designed for rest, relaxation and a good night’s sleep to a stimulating work or play area.

Making your bedroom more comfortable

  • As you’ve noticed, temperature has a big influence on how well you sleep. The body needs to cool by about 0.5°C at the start of sleep.
  • If the weather’s too hot, it will be difficult to cool, even by this small amount. Keep the window open and buy a fan.
  • If it’s too cold, your body will be working extra hard to produce heat, keeping your core temperature up.
  • Think about what you wear in bed. Breathable natural materials such as cotton are best for comfort.

Lifestyle

Exercise routines can help

  • Regular exercise is a great way of improving your sleep – but be careful not to exercise close to bed time as this produces stimulants that stop the brain from relaxing quickly.

How to optimise your naps

  • When on your night-shift, a 15 minute nap can relieve tiredness for about an hour or two and should not affect your ability to sleep after work.
  • But if you nap too long, you will fall into ‘deep’ sleep, and feel worse when you wake up. So, set your alarm to restrict your nap to 20 minutes to get the maximum benefit from it.

Optimising your shifts and sleep

  • From your answers it looks like you are coming home from work just when everyone else is getting up to go to work. This can cause problems for sleep.
  • Your natural (or ‘circadian’) rhythm of sleep and wakefulness is affected each morning by sun light – your body will be getting signals to wake up just as you are driving home to go to bed.
  • It’s probably impossible to avoid the daylight, but try to limit your exposure before going to bed. When you wake, get outside as much as possible.

You know what works.

  • Well done – the things you do to help you sleep should be working – did you know there are real scientific reasons?
  • A warm bath offers a chance to relax (vital for a good night’s sleep) and in a more practical way, it makes the blood vessels in your extremities dilate and help cool the body.
  • There’s new evidence that hormones released during sexual activity can promote sleep.

Have you considered caffeine as a way to increase your alertness?

  • Sleep experts say caffeine is a safe, natural chemical that acts as a stimulant so is good way to alleviate tiredness.
  • However, the effect only kicks in after about 20 minutes – so beware if driving – it won’t make you any safer until it is in your system. (The psychological effect of drinking caffeine is probably instantaneous, but only makes you feel more alert).
  • Either as an alternative, or in combination, to alleviate tiredness, you could try napping for 15 minutes – test show a 30% improvement in concentration when you have a coffee and a nap.

Psychological

How to get past your worries and get to sleep

As you’ve spotted, trying to sleep when worried is very difficult, so it would be a good idea to try some techniques to help you relax before trying to sleep.

  • Having a time to calm down after a hectic day is important – try taking a bath, reading a book or taking a gentle walk outside.
  • Simple breathing exercises can also help
  • Some people find that Lavender oil, Valerian or other herbs help them to sleep.
  • If you still have problems, you could try massage, aromatherapy or acupuncture.

Sleep information created with Jim Horne and Clare Anderson of Loughborough University
BBC Sleep profiler

Posted by: bud1setiawan | September 30, 2007

Erdos Problem

The Hungarian Paul Erdos (1913-1996, pronounced as “Ar-dish”) was not only one of the strangest mathematicians of the 20th century, he was also among the most famous ones. He kept on publishing widely circulated papers up to a very high age, and every mathematician having the honor of being a co-author to Erdos is well respected. Not everybody got a chance to co-author a paper with Erdos, so many people were content if they managed to publish a paper with somebody who had published a paper with Erdos. This gave rise to the so-called Erdos numbers. An author who has jointly published with Erdos had Erdos number 1. An author who had not published with Erdos but with somebody with Erdos number 1 obtained Erdos number 2, and so on. Today, nearly everybody wants to know what Erdos number he or she has. Your task is to write a program that computes Erdos numbers for a given set of scientists.

Input :
The input file contains a sequence of scenarios, each scenario consisting of a paper database and a list of ames. A scenario begins with the line “p n”, where p and n are natural numbers with 1 32000 1 n 3000. Following this line are p lines containing descriptions of papers (this is the paper database). A paper is described by a line of the following form:
LastName1, FirstName1, LastName2, Firstname2, …: TitleOfThePaper
The names and the title may contain any ASCII characters between 32 and 126 except commas and colons. There will always be exactly one space character following each comma. The first name may be abbreviated, but the same name will always be written in the same way. In particular, Erdos’ name is
always written as “Erdos, P.”. (Umlauts like ‘ö’,’ä’,…are simply written as ‘o’,’a’, ….)
Example:
Smith, M.N., Martin, G., Erdos, P.:Newtonian forms of prime factors matrices.

After the p papers follow n lines each containing exactly one name in the same format as in the paper database. The line ‘0 0’ terminates the input. No name will consist of more than 40 characters. No line in the input file contains more than 250 characters. In each scenario there will be at most 10 000 different authors.

Output :
For every scenario first print the number of the scenario in the format shown in the sample output. Then print for every author name in the list of names their Erdos number based on the papers in the paper database of the scenario. The authors should be output in the order given in the input file. Authors that do not have any relation to Erdos via the papers have Erdos number infinity. Adhere to the format shown in the sample output.

Sample input :
4
1 1
Smith, M.N., Martin, G., Erdos, P.: Newtonian forms of prime factors
Martin, G.
2 1
Smith, M.N., Martin, G., Erdos, P.: Newtonian forms of prime factors
Smith, M.N., Chen, X., Martin, G.: First order derivates in structured programming
Martin, G.
4 3
Smith, M.N., Martin, G., Erdos, P.: Newtonian forms of prime factors
Erdos, P., Reisig, W. : Stuttering in petri nets
Smith, M.N., Chen, X.: First order derivates in structured programming
Jablonski, T., Hsueh, Z. : Self stabilizing data structures
Smith, M.N.
Hsueh, Z.
Chen, X.
3 1
Smith, M.N., Martin, G., Erdos, P.: Newtonian forms of prime factors
Reisig, W., Jablonski, T., Hsueh, Z. : Self stabilizing data structures
Wahyu, S., Reisig, W., Smith, M.N. : Stuttering in petri nets
Jablonski, T.

Sample output :
Scenario 1
Martin, G. 1
Scenario 2
Martin, G. 1
Scenario 3
Smith, M.N. 1
Hsueh, Z. infinity
Chen, X. 2
Reisig, W. 1
Scenario 4
Jablonski, T. 3

Solution :
code here (.java)

Im writing the code in java, using Properties class as to store the Erdos number and lately i realized that this is actually not-so-good-enough : the algorithm, the lenght of the code, the class and datatypes (i probably should use HashMap or such so, that can be adjusted storing Integer with String-valued-key).

Posted by: bud1setiawan | September 30, 2007

doo be doo..

hey, you know what, i have no idea about what thing or stuff that i should write in this blog anymore..

😦 its dawn, and i havent sleep yet,

Posted by: bud1setiawan | September 3, 2007

starting c/C++

heakak

Older Posts »

Categories