simplify

How to simplify this code or a better design?

I am developing a game, the game have different mode. Easy, Normal, and Difficult. So, I'm thinking about how to store the game mode. My first idea is using number to represent the difficulty. Easy = 0 Normal = 1 Difficult = 2 So, my code will have something like this: switch(gameMode){ case 0: //easy break; case 1: //normal b...

Simplifying Jquery code HELP!

I am trying to load two modal dialog boxes with Jquery. Both of them load separate pages using ajax. The only problem is that only one of them works. I think I need to simplify my code but am unsure how. <script type="text/javascript"> $(document).ready(function(){ var dialogOpts = { modal: true, bgiframe: true, a...

Is it possible to join these two regex expressions into one?

Hi folks, i have the following two regular expressions (in order btw). 1. ^~/buying/(.*)\?(.*) => foo= group 1 baa= group 2. 2. ^~/buying/(.*) => foo= group 1 baa= nothing/empty/null/baibai What's i'm trying to do is, if the url has a questionmark, then split it into two groups. Otherwise, just throw all the stuff into th...

jQuery simplifying code (beginner)

I'm getting to grips with jQuery but find myself repeating code over and over again... Surely there's a simpler way to write this: $('#more-mcr, #more-hilton, #more-lpool').hide(); $('#mcr-hatters').hoverIntent(function() { $('#mcr-hilton').stop().animate({opacity: 0.4}); $('#more-mcr').fa...

How to simplify my country select menu PHP/mysql

I have a select menu that displays countries. It looks at the DB and judging by the value in the db shows the option as selected. Is there a simpler way off doing this than: if ($country == 'AG') {echo '<option value="AG" selected="selected">Antigua</option>';} else {echo '<option value="AG">Antigua</option>';}; if ($country == 'AR') ...

PHP: simplify with algorithm?

Hello. Here's a piece of PHP code I think is not very "pretty", I'm sure it's possible to simplify it with for or something. I'm trying to find and algorithm that would work for this, but I can't figure it out, please help me. Here's the code: if(isset($four)) { if(isset($navi[$one][$two][$three][$four])) echo "/content/" . $one . "/...

Simplifying multiple echos

I have a full list of timezones in a select menu like so: <option value="Pacific/Kosrae"> Pacific/Kosrae( +11:00 GMT ) </option> <option value="Pacific/Kwajalein"> Pacific/Kwajalein( +12:00 GMT ) </option> <option value="Pacific/Majuro"> Pacific/Majuro( +12:00 GMT ) </option> <option value="Pacific/Marquesas"> Pacific/Marquesas( -...

how to combine exponents? (x**a)**b => x**(a*b)?

how to simplify exponents in equations in sympy from sympy import symbols a,b,c,d,e,f=symbols('abcdef') j=(a**b**5)**(b**10) print j (a**(b**5))**(b**10) #ans even after using expand simplify # desired output a**(b**15) and if it is not possible with sympy which module should i import in python? edit even if i define 'b' as re...

C#, simplified code to handle both changes and updates of a dependency property

Obviously, I'm not an expert in C#. I would like to simplify this code by using an anonymous handler, or maybe a lambda, not sure. ValueHasChanged is a PropertyChangedCallback used when a dp is changed, it ensures the new object will be monitored for update, so that both changes and updates will be processed using the same code: ProcessN...

How can I simplify my jQuery animation?

How can I simplify my jQuery animation? What is the best way? Code: $("#nav").animate({opacity:0.2},1000); $("#sub_nav").animate({opacity:0.2},1000); $("#user_links").animate({opacity:0.2},1000); $("#logo").animate({opacity:0.2},1000); $(".top_buttons").animate({opacity:0.2},1000); $(".pageheaders").animate({opacity:0.2},1000); $(".hea...

Simplify/Neatify this two-way loop?

I've got my wires crossed somewhere (or I had not enough sleep). I need a two-way loop, and my current code is just plain ugly. Problem: I am running along a linear datastructre using an index. I have an starting index, lets say 120. I want to run alternating into both directions. Example: 120,121,119,122,118,123,117,... I have a sto...

R: Simplify this. Ave or Aggregate with several inputs

How can I write this all in one line? mydata is a zoo series, limit is a numeric vector of the same size tmp <- ave(coredata(mydata),as.Date(index(mydata)),FUN = function(x) ( (cummax(x)-x )) ) tmp <- (tmp < limit) final <- ave(tmp,as.Date(index(mydata)),FUN = function(x) cumprod( x) ) I've tried to use two vectors as argument to ave...

Mathematica Help: FullSimplify does not use conjugate identities

FullSimplify fails to recognize that: a*Conjugate[b] + b*Conjugate[a] = 2 Re[a*b] I have some very complex equations that could be simplified greatly if Mathematica could recognize this simple identity (and that a*Conjugate[b] - b*Conjugate[a] = 2 Im[a*b]). See, Mathematica will not finish solving my equations when written i...