Archive | Uncategorized RSS for this section

Clean Code

Meaningful Names


1. Intention Revealing Names
2.

Intention Revealing Names


The name of a variable, function or class should describe its purpose.
If the name requires a comment, the name does not reveal its intent.

public var hp:int; //health
public var health:int; 

By using meaningful names, it makes it easier to understand the what the code does within a particular function or class.

//Before
for(c in cArray){
switch(t.color){
case 1: c.stop(); break;
case 2: c.slow(); break;
case 3: c.move(); break;
default: c.stop(); break;
}
}
//After
for(car in cars){
switch(trafficLight.color){
case RED: car.stop(); break;
case YELLOW: car.slow(); break;
case GREEN: car.move(); break;
default: car.stop(); break;
}
}

Avoid Disinformation


A simple disinformation is using letters O,0,I,l (disinformative names)

if(l==1 && 0==O)
{
l = 0;
O = 1;
}
else
{
l = O = 1;
}

Another would be using abbreviations…

var ap:AP; //it could be referring to 
// ability points?
// action points?
// attack power? ... disinformative

Use Pronounceable Names


It makes it easier to understand and remember, and while discussing
this with a friend, your friend would not misunderstand what you are
trying to convery.
Alex: “Hey Alice, could you check grispratebimoneva?”
Alice: What???
Alex: “Could you check group success rate by monster evasion?”
Alice: “Oh that? Sure”

private var _grpSrateByMonEva; //before
private var _groupSuccessRateByMonsterEvasion; //after

Use Searchable Names


If you use short names, it would be very difficult to search for a particular variable name or function name. Using long name is better. Below is an example of using short name. If you would like to search for e variable, you have to encounter a few unnecessary variables such as ae, be, ce along the way. Names should be unique!

function getTotalClick(e:Event):void
{
trace(e);
if(ae== e){doA();}
else if (be == e) {doB();}
else if (ce == e) {doC();}
}
function getTotalClick(event:Event):void
{
trace(e);
if(ae == event){doA();}
else if (be == event) {doB();}
else if (ce == event) {doC();}
}
Advertisements

PSLE Mathematic 2009 Questions and Suggested Answers – Chocolates and Sweets by Jim and Ken (includes list of mathematic questions)

Primary School Leaving Examination (PSLE)


The Primary School Leaving Examination (PSLE) is a national examination taken by all students in Singapore near the end of their sixth year in primary … (reference from Wikipedia)

“Jim bought some chocolates and gave half of it to Ken.
Ken bought some sweets and gave half of it to Jim.
Jim ate 12 sweets and Ken ate 18 chocolates.
The ratio of Jim’s sweets to chocolates became 1:7
The ratio of Ken’s sweets to chocolates became 1:4.
How many sweets did Ken buy?”

Solution by using algebra!


Let x be the number of sweets bought
Let y be the number of chocolates bought

From Jim:
Since he has x/2 -12 sweets, y/2 chocolates and there are 7 times as many chocolates as there are sweets,
7 (x/2 – 12) : y/2
14 (x/2 – 12) : y
7x – 168 : y
7x – 168 = y

From Ken:
Since he has x/2 sweets, y/2 -18 chocolates and there are 4 times as many chocolates as there are sweets,
y/2 – 18 : 4(x/2)
y/2 – 18 : 2x
y – 36 : 4x
y = 4x + 36

Solving simultaneously and eliminating y,
Make y the subject of formula for both equations, i.e.

7x – 168 = y
and
4x + 36 = y

Therefore,
7x – 168 = 4x + 36
3x = 204
x = 68

Solution by guessing without any algebra!


This method is thinking like a young school kid who doesn’t know how to do it in algebra.
Very simple and easy. However, this need to guessing when both Jim and Ken becomes equal.

For Jim:
(1+12) : (7 x 1) = 13 : 7
(2+12) : (7 x 2) = 14 :14
(3+12) : (7 x 3) = 15 : 21
:
(21+12) : (7 x 21) = 33 : 147
(22+12) : (7 x 22) = 34 : 154

For Ken
(1) : (4 x 1 + 18) = 1 : 22
(2) : (4 x 2 + 18) = 2 : 26
(3) : (4 x 3 + 18) = 3 : 34
:
(33) : (4 x 33 + 18) = 33 : 150
(34) : (4 x 34 + 18) = 34 : 154

Once both Jim and Ken reaches the same ratio, which is 34:154, then sum them together!

Summary:
34 + 34 = 68 (total sweets)
154 + 154 = 308 (total chocolates)

Solution by doing it mentally!

Jim and Ken had the same number of chocolates after Jim gave half to Ken. And they had the same number of sweets after Ken gave half to Jim.

Jim had 12 fewer sweets than Ken after he ate 12. So Ken’s 1 unit of sweets = Jim’s 1 unit + 12. And so Ken’s 1 : 4 = Jim’s 1 unit + 12 sweets : Jim’s 4 units + 48.

After Ken ate 18 chocolates, Jim had 18 more chocolates than Ken. Jim has 7 units of chocolates, Ken has 4 units + 48. So 3 units = 48 + 18. And so 1 unit = 16 + 6 = 22.

Ken had 22 + 12 = 34 sweets after giving half to Jim. So he bought 34 x 2 = 68 sweets.

Solution by using modeling!


Reference from mycarforum.com (lol what does this do with cars?)
Below is the Leslielai’s elaboration of the diagram above. (on how it works to solve the problem)

PSLEsolution-1

1. We start out by plotting the diagram for Jim, with a unit to indicate the amt of sweets he has left + the dotted area indicating that he has consumed 12 sweets.

2. Next, since we know that the amount of chocolates he has left is 7 times the sweets he has left. Therefore, 7 units

3. Following that, we can now plot Ken’s diagram. Bear in mind that he did not consume any sweet at all and that what he has should be what Jim had initially (inclusive of the dotted area representing the 12 he consumed). This time round we use a regular line to include 12, not dotted line as it still exists. In doing so, we can obviously tell that each unit of Ken’s sweet or chocolates for that matter is equal to one unit of Jim’s, PLUS 12.

4. Follow through by drawing 4 times of the above.

Recall that since the amt of chocolates Jim has (which remains unchanged) should be equal to the amount Ken had at the first. We’ll extend the chocolate diagram for Ken to the same length as Jim’s. This represents the 18 Ken has consumed.

Since in step 3, the units for Ken is drawn in such a way that every unit of his sweets/chocolate is EQUAL to each unit of Jim’s PLUS 12. Therefore, the difference in terms of units between Jim and Ken should equate to all the numerical differences denoted by 12, 12, 12, 12 and 18.

The key here is in mapping Ken’s model. Each unit in Ken’s term is one unit of Jim’s plus 12.

############################################

OTHER PSLE MATHEMATIC QUESTIONS

angle
The above figure is a square. The angle question answer above is 150 degrees. Because the bottom triangle is equilateral triangle. (draw a circular curve through all 3 lines and they become the radii of the incomplete circle otherwise known as the arc)
360 – 60 = 300 degree
300 degree / 4 = 75 degree
75 degree x 2 = 150 degree

Wei Ren’s Answer
pslemath
For those who haven’t figured out the angle question:
There are 2 isosceles triangles that are REALLY out of shape.
If you look at the kite, the 2 angles at the side will add up to the answer.
By taking 360 (total of the angles in the kite) – 60 (angle at bottom of kite),
you get 300 degrees, which is the total of the 2 sides plus the answer.
Since the 2 sides add up to the answer, you can say that 300 degrees = 2 * answer. 300/2 = 150.

TO CLARIFY: Lines BD, AD, CD and BC are EQUAL in length.
BD and ACD are both isosceles triangles. You can see that angles ABD and BAD are equal, and angles ACD and CAD are equal. This means that angles ABD + ACD = angle BAC (answer).
The angles at A, B, C and D all add up to 360. By taking 360 – angle BDC (60), you get angles ABD + ACD + BAC, which equals to BAC + BAC (since ABD + ACD = BAC).
Since BAC + BAC = 300, angle BAC = 150.

Lim Jeck’s Solution
Image1
Given: ABCD is a square, EG=EF=EH. Find angle GFH.
Since ABCD is a square, AB=BC=CD=DA
As EF=BC=DA and AB=GH, hence EG=EH=AB=GH.
Therefore, triangle EGH is equilateral since EG=GH=EH.
angle GEH=60°
angle GEF=60/2=30°
Triangle EGF is isosceles. Hence, angle FGE= angle GFE = (180-30)/2 = 75°
angle GFE = angle HFE = 75°
Therefore angle GFH= 75X2=150°

Renting Computers


6 friends decided to rent computers from 2pm to 4.30pm. While 4 of them were playing, the other two would watch. If the cycle continues, and each of them played for equal number of minutes, how many minutes will each person get to play? Answer: 100 minutes

Renting Computer Solution

VanillaCake’s Answer
From 2 pm to 4.30 pm -> 2 h 30 min = 150 min
4 x 150 = 600 (Total for 4 computers since there were 4 players)
600 / 6 = 100 min
Amount of playtime that each person get was 100 min

Chua’s Answer
Renting Computer
From 2pm to 4:30pm
total time needed=4.30-2
=2hr 30min
=2*60 + 30
=150min

Since 4 people can play at the same time hence there are 4 comuters
so 150*4=600 hours
time used per user=600/6
=100min
=1hr 40min

Conclusion: it is not healthy to use computer for such a long hour.

Bicycle Race


Mei and Lin were in a bicycle race. Mei was travelling at a constant speed of 20km/hr and they both did not change their speed. When Lin completed half the race, Mei was 3.5km ahead. Mei completed the race at 10.45am. What time did Lin complete the race? Answer: 11.06am

Bicycle Race Solution

Guan Hui’s Answer
Suggested Answer:
3.5 x 2 = 7km(how much ahead is mei if she keep cycling when Lin finish the race)

speed= 20km/h
7km= 7/20 X 1
=0.35 hr
=21 mins (time needed to be 7km ahead for mei)
Time when Lin complete the race = 10.45am+ 21mins
= 11.06am

Puppylover’s Answer
3.5 / 20 x 60 = 10.5 min
Mei took 10.5 min to travel 3.5 km (distance beyond half way mark).
So when Mei reached the half way mark,
Lin would need another 10.5 min to reach the half way mark,
i.e Lin was slower than Mei by 10.5 minutes for half the distance.
Hence for the race, Lin would be slower by 2 x 10.5 = 21 min.
21 min past 10.45 a.m. would be 11.06 a.m. (or use timeline)
Lin reach the finishing line at 11.06 a.m.

Chocolate and Almond Cookies


Sally baked some cookies to sell. 3/4 of them were chocolate cookies and the remaining were almond cookies. After she sold 5/6 of chocolate cookies and 210 almond cookies, she had 1/5 of the cookies left. How many cookies did she sell? Answer: 960

Chocolate and Almond Cookies Solution

Mr Jackie Lim’s Answer
960 cookies were sold.
convert chocolate 3/4 to 30/40 and almond 1/4 to 10/40.
7 units of almond is 210. 1 unit is 30.
Number of units sold is 32u, hence it’s 960.

Chocolates and Sweets by Jim and Ken


Jim bought some chocolates and gave half of it to Ken. Ken bought some sweets and gave half of it to Jim. Jim ate 12 sweets and Ken ate 18 chocolates. The ratio of Jim’s sweets to chocolates became 1 : 7 and the ratio of Ken’s sweets to chocolates became 1:4. How many sweets did Ken buy?. Answer: 68 sweets (Check the solution above)

Curry Puff


Curry puff shop sells puffs at $0.80 each. Offer:Buy 3 get 4th half price. If customer has $50, how many puffs can he buy if he buys as many as he can. Answer: 71 puff

Curry Puff Solution

eugenemon’s Answer
$2.80 = 4 pieces
50 / $2.80 = 17
17 x 4 = 68 pieces
Left $2.40 can buy 3 pieces.
68 + 3 = 71 pieces

Balloon’s String


String of 2 big balloons is 90cm
String of 5 small balloons is is 1.2m
If both strings are of the same length, there would be 105 more small balloons than the big balloons.
How many balloons are there altogether? Answer: 345

Balloon’s String Solution

eugenemon’s Answer
2.6667 big = 1.2m
5 small = 1.2m
5 / 2.66667 = 1.8749766
big : small = 1 : 1.8749766
105 / 0.8749766 = 120
Total balloons = 120 x 2.8749766 = 345

Rice for Sale


Shop A has 156kg of rice, while Shop B has 72kg of rice. Each shop sold an equal amount of rice and after that the ratio of the amount of rice left in their shop was 4:1. Find out how much rice has been sold. (3 marks) Answer: 44kg

Paras’s Answer
Since, they sold an equal amount of rice, the original difference remains the same.
The difference is 156-72=84kg. Now the ratio difference is 4-1=3units.
Now, that 3units is = 84 kg. Sho B now has left 1unit so it has 84/3 = 28 kg.
To find out the rice sold , 72kg(what it had before)-28kg(what it has now)=44 kg.

kofplayer’s Answer
Just take 72 – [(156-72)/3]

Pros’s Answer
some of the answers do not sounded logical…
A had 156kg, B has 72 kg.
Same amount of rice sold, hence the deduction from above will be same.
After sales, ratio is 4:1, hence for the 3 parts it is (156-72)kg = 84kg, hence each part is 28kg.
They left a total of 5 parts = 28 x 5 = 140 kg.
As a result, amount of rice sold = (156 + 72) – 140 = 88kg.

Chairs in the Hall


6/14 of the chairs in the hall are in rows of 13. Half of the chairs in the hall are in rows of 7. There are 112 more chairs in rows of 7. The rest of the chairs are stacked up. Find out the total number of chairs in the hall (5 marks) Answer: 1568

Ananto’s Answer
Most Of The Information Given Is To Fool You… All It Says Is

6/14 chairs are in group (You Dont Need To Worry What Are They In A Group Of)
1/2 chairs are in another Group (1/2 = 7/14)
6/14 + 7/14 = 13/14

There are 112 more chairs left.
Therefore the remaining 112 chairs must be 1/14 of all the Chairs…
So All You Do Is Multiply That By 14
So That The Fraction Becomes 14/14 Or In Other Words 100% of The Chairs

In Simple: 112 x 14 = 1568

Fix Solution for Samsung Natural Color Pro 1.0 ICM” appears defective

How to fix Samsung Defective Monitors?


The monitor profile “Samsung – Natural Color Pro 1.0 ICM” appears to be defective.
Please rerun your monitor calibration software.

I encountered this problem when running my Adobe Photoshop CS3. The error message occurs to most Samsung LCD Monitors which is the color management is control by an file with .ICM extension. This causes your screen showing other colors than normal. (example: yellowish). Solution: Apply a new color profile.

samsung error

For Windows XP users

Right-click the desktop, and click “Properties”
Click “Settings” Tab. Click “Advanced” button.
Click “Color Management” Tab.
Click “Add” button (To add a new color profile)
Select “sRGB” or “Adobe RGB”. Click Add.
Click OK once you are done.
Restart computer.

For Windows Vista users

Right-click the desktop, and click “Personalize”
Click “Display Settings” Tab. Click “Advanced Settings” button.
Click “Color Management” button.
Click “Color Management” Tab.
select your monitor and tick the “use my settings for this device”.
Click “Add” button (To add a new color calibration file) to replace the defective one.
Select “sRGB” or “Adobe RGB”. Click Add.
Finally, set the Adobe RGB as the default for the monitor.
Restart computer.

How To Raise A Dragon Walkthrough

About How to Raise A Dragon
The dragon: a majestic and complex beast. How is it born? How does it live and die? Magus X. R. Quilliam’s definitive work, “How to Raise a Dragon,” describes all that is known about these great creatures.

In this game, you can choose every aspect of the life of a dragon, including its appearance, its abilities, and how it treats the humans around it. You can choose to become a wild guardian, a fiery tyrant, a necromantic scourge, and many other unique destinies.

Play Online: How to Raise A Dragon

How To Raise A Dragon Walkthrough

StormWinds: The Lost Campaigns Walkthrough, Review, Tips

About StormWinds The Lost Campaign
StormWinds: The Lost Campaigns is an expansion pack to the first popular shooter released a year ago.
With 6 new campaigns, all new enemies, weapons, and more, there is plenty to keep players busy.
It also explains more of the StormWinds story and sheds some light on this steampunkish universe.

Objective of StormWinds
Similar to StormWinds 1.5, you must defend your fortress from the oncoming enemy waves.
Place turrets in locations of your choice on your fortress, creating the best defense possible to withhold
even the greatest of attacks. Purchase, Repair, upgrade, and move your turrets to find the ultimate defense.

Play Online: Stormwinds The Lost Campaign at ArmorGames.com [Exclusive Bonus Map]
Play Online: Kongregate StormWinds The Lost Campaign [Badges]

StormWinds The Lost Campaign Walkthrough (works for all campaigns)
Here is a comprehensive strategy for every level in the entire game:
– For primary weapon, focus on upgrading “Damage Increase” as its worth more for upgrade points spent.
– For primary weapon, buy “Dual Machine Gun” [$10,000] for the early campaigns.
– If you have sufficient money, sell your previous primary weapon for “Spread Machine Gun” [$15,000].
– Buy “Barrier Decoy” [$1,000] and place it in front of your primary weapon. It acts as a damage sponge.
– Buy “Damage Buffer” [$15,000]. Upgrade only “Buff Strength”. Purchase more if you have the money $$$
– With this strategy [strat], you will owned the enemies with your pure raw damage.

Click here to view Stormwinds The Lost Campaigns Video Walkthrough

Bloody Fun Day Walkthrough, Review, Tip, Cheat

About Bloody Fun Day
What would Death himself do if he were surrounded by ultra-cute critters? Kill them, of course! You play the reaper, who needs to kill red cuties in order to stay alive. Killing other cuties will help charge super powers that make it easier to get to the red cuties. How long can you survive before the dwindling cutie population stifles your life? You can’t help but have a bloody fun day in this addictive puzzler.

Play Online: Bloody Fun Day by urbansquall
Download Link: Play Bloody Fun Day Offline [1.8 Mb] [Music]

Bloody Fun Day Walkthrough Unlimited Mode [by Armatus]
– Golden eggs provides 5,000 points. It’s the only way to get 100,000 points quickly.
– You need large groups. slice cuties so that the resulting eggs will enlarge another group.
– Slice an egg [cost 2 points] rather than a group of cuties to obtain something big.
– Use the any-range-kill and the laser to get a golden egg if it’s the only way to get it before it hatches.
– Once you have a large group, consider using the color change.
– If it changes to red, use the double soul collect to get a huge hp boost.
– If it doesn’t, use the red soul skill to get enough for another round.

Bloody Fun Day Walkthrough Endurance [by ThirdParty]
– Late in the game, you will almost always want to follow Transform with either Harvest or Vampiric Touch.
– Depending on whether you get reds or not, so probably shouldn’t use it when these abilities are uncharged,
– unless you’re in an area that you can afford to leave and come back to later.
– The skills that keep you alive are Harvest, Vampiric Touch, and to a lesser extent Transform.
– Notice that none of these are black. So black is the best color to Transform.
– In the early game or when fortune is favoring you, stockpile.
– Fill up your health meter and the three survival skills, and leave some large clumps of reds sitting about.

Bloody Fun Day Tips [by clockwork247]
Yellow are most valuable as they can change color and give you life.
Blue are next since they can double what you can get black is useless.
Gather yellow, blue, and leave black, once they form a huge patch just change their color and continue on.
Black powers is useful to get golden eggs that spawned on the other side of the crowd you’ve just killed.
The maximum red soul you can store is 40. If you happen to get more than 40, the remaining is wasted.

Bloody Fun Day Special Power
Basic Attack – Kill an adjacent group of cuties. Absorb their souls.
Jump Slash – Kill a group of cuties two tiles away. Absorb their souls. [9 blue]
Harvest – Kill an adjacent group of cuties. Absorb two souls for each cutie [23 blue]
Transform – Randomly change the color of an adjacent group of cuties. They will not be killed. [19 yellow]
Vampiric Touch – Kill an adjacent group of cuties. Absorb souls and convert into red souls. [24 yellow]
Eye Lasers – Eye Lasers. Kill a straight line of cuties. Absorb their souls. [13 black]
Fire Blast – Kill a group of cuties any distance away. Absorb their souls. [18 black]

Bloody Fun Day Score Formula
For Reaping Normal Egg : -2 points per normal egg.
For Reaping Golden Egg : 5,000 points per golden egg.
For Reaping Cutie Group : 2.5*(# of Cuties in group) + 2.5*(# of Cuties in group)^2 = Total Score.

Click here to view how to cheat in Bloody Fun Day

Bunny Invasion 2 Walkthrough Review Tips

About Bunny Invasion 2
Bunny Invasion 2 is a defence game. You play Mr Frost – A retired middle aged man. While he’s in the pub enjoying a drink, a news flash informs him that a new army of evil bunnies are taking over the country once again. He must once again defend the nation from certain destruction.

Bunny Invasion 2 is bursting with original content. 60 levels, over 2 hours of game-play, 10 cut scenes, 10 types of bunny, 3 bosses, 13 weapons to buy along with multiple upgrades for each weapon, 8 general upgrades, A trophy collection system, 58 in total, along with A HUGE amount of extras, 26 of which can be unlocked using the trophies.After each wave of bunnies, you will be able to purchase weapons and upgrades from the shop screen using the money you collected from the previous wave of bunnies.

Play Online:Kongregate GPStudios Bunny Invasion 2

Basic Tutorial
In the weapon shop, you can buy guns, ammo, and upgrades for each weapon you purchased.
In the upgrade shop, you will be able to repair and fortify the building, hire an assistant, even buy deadly dioseases to spread amongst the rabbit community.
You will also have the opportunity to save your game or change the game options.

Game Controls / Instructions
1. Use the mouse to aim and fire.
2. Use the numeric keys 0 to 9 to select a weapon, or [Q] and [E] to scroll through weapons.
3. [A] and [S] keys to throw grenades.
4. SPACEBAR or [R] to reload.
5. Press [P] to pause.

Walkthrough Overview
1. Upgrade .45 Colt
Your basic weapon that has unlimited bullets. This will help you save some cash to buy better weapons.
Upgrade .45 Colt strength and reload speed as you will be using this for some levels.
2. Tec-9 [Uzi/Light-MachineGun]
– Purchase this weapon since it shoots much faster, just hold your left mouse button to shoot.
– I find this weapon less straining to the player’s finger! Upgrade the strength, reload then clip size.
3. Scavengers – Farming Cash in Bunny Invasion 2
– Once you have your Tec-9 upgraded, you can put more focus to your money making upgrade.
– The more money you have, you can spend them on Builders/Assistant/RepairPub/Purchase Bullets
– By maxing this in the early stage, you will be able to upgrade the others much faster.
4. Assistant / Sidekick
– Hire an assistant and upgrade its weapon till $9500.
– He will help you to save some of your bullets, and shoot down enemies while you are shooting/reloading.
5. Deadly Mini Gun
– The maxed Scavengers helps you to obtain MiniGun [the most powerful weapon] around level 35-40.
– Mini Gun is similar to Tec-9, hold left mouse button to shoot. Its extremely fast and no clip size required.
– Try to use burst shot [shoot for few seconds and stop] for Mini Gun to avoid it from overheating.
6. AIDS and Myxomatosis
– AIDS reduces the bunny hitpoints/life and Myxomatosis slows them down.
7. Fortify Pub, RAGE and Builders
– Once all your offense upgrades are completed, you can now max the others.
8. Repair your pub
– In the earlier stage/level/wave, repair your pub to survive. Refer to the wave walkthrough below!
Read More…