2
голосов
11ответов
696 просмотров

Learning Java and logic using debugger. Did I cheat?

After a break from coding in general, my way of thinking logically faded (as if it was there to begin with...). I'm no master programmer. Intermediate at best. I decided to see if i can write an algorithm to print out the fibonacci sequence in Java. I got really frustrated because it was some...

21
голосов
6ответов
4430 просмотров

Is there a short-circuit OR in PHP that returns the left-most value?

In some languages, you can do $a = $b OR $c OR die("no value"); That is, the OR will short-circuit, only evaluating values from left to right until it finds a true value. But in addition, it returns the actual value that was evaluated, as opposed to just true. In the above example, in PHP, $a ...

2
голосов
2ответов
933 просмотров

MVC: Just me or is IsValidField illogical

While I was writing some code to print out JS when a field is not valid in the ModelState is came to the following method: ModelState.IsValidField(string key) The comment in IntelliSense tells me: Returns true if there is any System.Web.Mvc.ModelError associated or prefixed with the speci...

1
голосов
1ответов
190 просмотров

Crystal Reports compare does not work without trim

{AR_Customer.CustomerType} is a 4 character field {AR_Customer.CustomerType}<>"S" does not return all records where this is true unless I do it this way: trim({AR_Customer.CustomerType})<>"S" in the actual database the NULL fields are the ones I'm missing. So this tells me than NUL...

12
голосов
6ответов
20778 просмотров

How to perform an action every 5 results?

How can I perform an action within a for loop every 5 results? Basically I'm just trying to emulate a table with 5 columns.

5
голосов
5ответов
1065 просмотров

C# code only gives expected results on step through?

Ok so I have a dice throw app... When I step through the code it functions normally and 'results' contains the correct number of throw results and they appear to be random, when I leave the code to run and do exactly the same thing it produces a set of identical numbers. I'm sure this is a logi...

0
голосов
2ответов
978 просмотров

Logic question (universal and existential quantifications)

I have a logical statement that says "If everyone plays the game, we will have fun". In formal logic we can write this as: Let D mean the people playing. Let G be the predicate for play the game. Let F be the predicate for having fun. Thus [VxeD, G(x)] -> [VyeD, F(y)] V is the computer sci...

2
голосов
1ответов
1226 просмотров

Using JavaScript/jQuery to generate fixtures

I'm putting together a tool for a colleague which helps to create a nice fixture list. I got about 2/3 through the tool, collecting various data ... and then I hit a brick wall. It's less of a JavaScript problem and more of a maths/processing brainblock. Lets say I have 4 teams, and they all nee...

2
голосов
3ответов
1699 просмотров

Count up and down elegantly

I'm trying to make a flashing object, i.e., increment it's alpha value from 0 to 255 (gradually) and then back down to 0, and repeat. Is there a way I can do this without using some boolean? Getting it to increment is easy: alpha = time.elapsed()%256; But what's a nice way to get it to count ...

0
голосов
1ответов
156 просмотров

Request-Response logic

public function run() { /* * wrap uri in a decorator */ $uri = new URI(trim(str_replace($this->base_path, "", $_SERVER["REQUEST_URI"]), "/")); /* * fetch appropriate resource from uri */ $this->resource = new Resource($uri); /* * prepare the ...

7
голосов
3ответов
26090 просмотров

power function in prolog

What is wrong with my power function? pow(_,0,1). pow(X,Y,Z) :- pow(X,Y-1,X*Z). ?- pow(2,3,Z). ERROR: Out of global stack

0
голосов
2ответов
1037 просмотров

Validating Timestamp overlaps with PHP

My database holds date, start and end variables. In my code I grab the start and them as the user selects them, and convert them to timestamps like so (all inside a foreach loop).. $selectionDate = strtotime($timeQry['date']); $startTimes[] = strtotime($timeQry['start'],$selectionDate);...

1
голосов
4ответов
454 просмотров

Anybody know of a good logic layout application?

I don't know exactly what to call this kind of application, but I'm looking for a good program that'll allow me to layout and test logical circuits. Something that has ands, ors, xors, nots, transistors, and all the basic logical components. Something kind of like UML except with basic electrical...

0
голосов
7ответов
264 просмотров

Using Boolean operators

This works fine if ((a >= 40 && a <= 50) || (a >= 60 && a <= 80)) // do something How do I do the reverse of it? if ((a < 40 && a > 50) || (a < 60 && a > 80)) // do something The code does not work as expected. I want something like if...

0
голосов
4ответов
107 просмотров

return variable approach

Ok I have ten variables but one needs to be set, but I need to check for each of the values until one is set. I'm doing a SWITCH/CASE statement but I'm not sure if this is the best approach because I don't see how I can return only the variable that I need set. $passed_var = 'A'; // Static $var...

0
голосов
2ответов
84 просмотров

How do you replicate an array whilst keeping the same keys?

Ok. I've written a simple(ish) function to take an argument and return the same argument with the danger html characters replaced with their character entities. The function can take as an argument either a string, an array or a 2D array - 3d arrays or more are not supported. The function is a...

2
голосов
2ответов
1097 просмотров

jQuery sort by rating (desc) and hide divs based on value

I am trying to achieve the following. I have a dozen divs with something like: <div id=1><div>test 1</div><div>4</div></div> <div id=2><div>test2</div><div>1</div></div> <div id=3><div>test3</div><di...

2
голосов
6ответов
451 просмотров

Points system like stackoverflow

I am trying to create a point system in my program similar to stack overflow i.e. when the user does some good deed (activity) his/her points are increased. I am wondering what is the best way to go about implementing this in terms of db schema + logic. I can think of three options: Add an ext...

19
голосов
6ответов
31832 просмотров

What can be the efficient approach to solve the 8 puzzle problem?

The 8-puzzle is a square board with 9 positions, filled by 8 numbered tiles and one gap. At any point, a tile adjacent to the gap can be moved into the gap, creating a new gap position. In other words the gap can be swapped with an adjacent (horizontally and vertically) tile. The objective in the...

1
голосов
2ответов
1080 просмотров

PHP Detect how many URLS in the string

I'm implementing a contact form for a website, and I'd like to avoid using a captcha because I believe it has a negative effect on user experience. Instead, I've decided to trial detecting the number of URLs that have been submitted with the message. I am retrieving the message as a string from...

35
голосов
13ответов
45890 просмотров

jQuery password strength checker

I'm quite new to jQuery, and I've written a simple function to check the strength of a password for each keypress. The idea is that every time a user enters a character, the contents is evaluated to test the strengh of the password they have entered... I'm sure everyone has seen these before. A...

3
голосов
3ответов
717 просмотров

Combinator logic axioms

I'm carrying out some experiments in theorem proving with combinator logic, which is looking promising, but there's one stumbling block: it has been pointed out that in combinator logic it is true that e.g. I = SKK but this is not a theorem, it has to be added as an axiom. Does anyone know of a c...

2
голосов
1ответов
2100 просмотров

Scheduling Script with PHP/MySQL - Help with Logic

I'm looking to develop a small script where users can insert their "schedule." However, I need some help determining the logic of how to create the DB structure and how to input the "time" of the events in the database. One thing to note, however, is that when users enter their "schedule", they...

7
голосов
7ответов
11621 просмотров

How to efficiently paginate large datasets with PHP and MySQL?

As some of you may know, use of the LIMIT keyword in MySQL does not preclude it from reading the preceding records. For example: SELECT * FROM my_table LIMIT 10000, 20; Means that MySQL will still read the first 10,000 records and throw them away before producing the 20 we are after. So, wh...

0
голосов
1ответов
132 просмотров

PHP - Need Help With Logic

I'm currently working on a PHP/MySQL script that does the following, in this order: 1) Checks DB for any videos that need converting 2) Once determined that a video needs to be converted, it begins to convert *3) Notifies the "creator" of video that it's been created. *4) Notifies all users who ...

6
голосов
6ответов
13525 просмотров

Compressing big number (or string) to small value

My ASP.NET page has following query string parameter: …?IDs=1000000012,1000000021,1000000013,1000000022&... Here IDs parameter will always have numbers separated by something, in this case ,. Currently there are 4 numbers but normally they would be in between 3 and 7. Now, I am looking f...

1
голосов
1ответов
205 просмотров

Generic sub-set algorithm problem

I have the following problem. I've got a set of items {a1, a2, a3, ... aN}. Each one of those items can contain another set of items {b1, b2, b3, ... bN}. So the end result looks something like this: a1 b4 b22 b40 b11 b9 a2 b30 b23 b9 b4 b11 a3 b22 b4 b60 b9 As a r...

0
голосов
3ответов
234 просмотров

Why does my localization cookie seem to not want to change?

Why cant I change cookie? If you chose a language you cant change. You have to empty your cookies if you want to change language. Why is that? if (isset($_GET['setLang']) && $_GET['setLang'] == 'en' || isset($_COOKIE['setLang']) && $_COOKIE['setLang'] == 'en') { setcookie("set...

2
голосов
9ответов
328 просмотров

Why are there not more control structures in most programming languages?

Why do most languages seem to only exhibit fairly basic control structures from a logic point of view? Stuff like If ... then, Else..., loops, For each, switch statement, etc. The standard list seems fairly basic from a logic point of view. Why is there not much more in the way of logic syntacti...

-2
голосов
5ответов
2060 просмотров

Or gate using 2 NANDS

The diagrams I've seen for making an OR gate from a NAND gate use 3 NAND gates but if you have both inputs connected to both connectors of a NAND gate and then the output of this gate as inputs to both connectors of a second NAND gate it should behave like an OR gate. So you'd need only 2 gates? ...