Search Results

Search found 112 results on 5 pages for 'gregory weir'.

Page 3/5 | < Previous Page | 1 2 3 4 5  | Next Page >

  • Bubble Breaker Game Solver better than greedy?

    - by Gregory
    For a mental exercise I decided to try and solve the bubble breaker game found on many cell phones as well as an example here:Bubble Break Game The random (N,M,C) board consists N rows x M columns with C colors The goal is to get the highest score by picking the sequence of bubble groups that ultimately leads to the highest score A bubble group is 2 or more bubbles of the same color that are adjacent to each other in either x or y direction. Diagonals do not count When a group is picked, the bubbles disappear, any holes are filled with bubbles from above first, ie shift down, then any holes are filled by shifting right A bubble group score = n * (n - 1) where n is the number of bubbles in the bubble group The first algorithm is a simple exhaustive recursive algorithm which explores going through the board row by row and column by column picking bubble groups. Once the bubble group is picked, we create a new board and try to solve that board, recursively descending down Some of the ideas I am using include normalized memoization. Once a board is solved we store the board and the best score in a memoization table. I create a prototype in python which shows a (2,15,5) board takes 8859 boards to solve in about 3 seconds. A (3,15,5) board takes 12,384,726 boards in 50 minutes on a server. The solver rate is ~3k-4k boards/sec and gradually decreases as the memoization search takes longer. Memoization table grows to 5,692,482 boards, and hits 6,713,566 times. What other approaches could yield high scores besides the exhaustive search? I don't seen any obvious way to divide and conquer. But trending towards larger and larger bubbles groups seems to be one approach Thanks to David Locke for posting the paper link which talks above a window solver which uses a constant-depth lookahead heuristic.

    Read the article

  • Help me with a solution for what could be solutioned by virtual static fields... in FPC

    - by Gregory Smith
    Hi I'm doing an event manager in Freepascal Each event is an object type TEvent (=object), each kind of event must derive from this class. Events are differentiated by an integer identificator, assigned dynamically. The problem is that i want to retrieve the event id of an instance, and i can't do it well. All instances of a class(object) have a unique id = so it should be static field. All classes have a diferent id = so it should be virtual. Event ids are assignated in run time, and can change = so it can't be a simple method In sum, I can't put all this together. I'm looking for an elegant solution, i don't want to write a hardcoded table, actualizing it in every constructor... etc, i'd prefer something taking advantage of the polymorphism Can anyone help me with another technical or design solution? I remark I don't want to use class instead of object construct.(property doesn't work on objects? :(

    Read the article

  • MooTools events not firing in IE8

    - by gregory
    I have a Mootools asset created like so: // Create a new asset var asset = new Asset.image(path, { title: this.language.download, events: {click: this.download.bind(this, link)}, }); I have a method of a MooTools object defined as such: download: function(e) { // The path to download console.log('download: ' + e); }, In Firefox the console.log print shows up. In IE8, however, I have no luck. Am I missing something? Any tips or advice would be greatly appreciated. TIA!

    Read the article

  • Why is WPO(whole-program optimization) not doing any improvements in my program size? (FPC 2.4.0)

    - by Gregory Smith
    I use FPC 2.4.0 for WinXP(binary from the official page), also tryed with same version but compiled from source on my comp. I put something like this: I:\pascal\fpc-2.4.0.source\fpc-2.4.0\compiler\ppc386 -FWserver-1.wpo -OWsymbolliveness -CX -XX -Xs- -al -Os -oServer1.o Server I:\pascal\fpc-2.4.0.source\fpc-2.4.0\compiler\ppc386 -FWserver-2.wpo -OWsymbolliveness -Fwserver-1.wpo -Owsymbolliveness -CX -XX -Xs- -al -Os -oServer2.o Server ..(up to 100 times) but always same .wpo files, and same .o sizes(.s, assembly files change intermittently) I also not(through compiler messages), that not used variables are still alive. Also tryed -OWall -owall What am i doing wrong?

    Read the article

  • How can I get at the raw bytes of the request in WCF?

    - by Gregory Higley
    For logging purposes, I want to get at the raw request sent to my RESTful web service implemented in WCF. I have already implemented IDispatchMessageInspector. In my implementation of AfterReceiveRequest, I want to spit out the raw bytes of the message even (and especially) if the content of the message is invalid. This is for debugging purposes. My service works perfectly already, but it is often helpful when working through problems with clients who are trying to call the service to know what it was they sent, i.e., the raw bytes. For example, let's say that instead of sending a well-formed XML document, they post the string "your mama" to my service endpoint. I want to see that that's what they did. Unfortunately using MessageBuffer::CreateBufferedCopy() won't work unless the contents of the message are already well-formed XML. Here's (roughly) what I already have in my implementation of AfterReceiveRequest: // The immediately following line raises an exception if the message // does not contain valid XML. This is uncool because I want // the raw bytes regardless of whether they are valid or not. using (MessageBuffer buffer = request.CreateBufferedCopy(Int32.MaxValue)) { using (MemoryStream stream = new MemoryStream()) using (StreamReader reader = new StreamReader(stream)) { buffer.WriteMessage(stream); stream.Position = 0; Trace.TraceInformation(reader.ReadToEnd()); } request = buffer.CreateMessage(); } My guess here is that I need to get at the raw request before it becomes a Message. This will most likely have to be done at a lower level in the WCF stack than an IDispatchMessageInspector. Anyone know how to do this?

    Read the article

  • How can I list the properties of an object programmatically in VB6?

    - by Gregory Higley
    A friend of mine is working on a legacy VB6 project. I haven't touched that language in ten years, so I'm pretty rusty. Anyway, is there any kind of reflection API for VB6? Specifically, he needs a way to iterate the properties (and types) of a user-created Class. (In other words, not an external COM object, but an internal "Class Module" as it's called.) How can this be done?

    Read the article

  • Why do I not get the correct answer for Euler 56 in J?

    - by Gregory Higley
    I've solved 84 of the Project Euler problems, mostly in Haskell. I am now going back and trying to solve in J some of those I already solved in Haskell, as an exercise in learning J. Currently, I am trying to solve Problem 56. Let me stress that I already know what the right answer is, since I've already solved it in Haskell. It's a very easy, trivial problem. I will not give the answer here. Here is my solution in J: digits =: ("."0)":"0 eachDigit =: adverb : 'u@:digits"0' NB. I use this so often I made it an adverb. cartesian =: adverb : '((#~ #) u ($~ ([:*~#)))' >./ +/ eachDigit x: ^ cartesian : i. 99 This produces a number less than the desired result. In other words, it's wrong somehow. Any J-ers out there know why? I'm baffled, since it's pretty straightforward and totally brute force.

    Read the article

  • How can I generate the Rowland prime sequence idiomatically in J?

    - by Gregory Higley
    If you're not familiar with the Rowland prime sequence, you can find out about it here. I've created an ugly, procedural monadic verb in J to generate the first n terms in this sequence, as follows: rowland =: monad define result =. 0 $ 0 t =. 1 $ 7 while. (# result) < y do. a =. {: t n =. 1 + # t t =. t , a + n +. a d =. | -/ _2 {. t if. d > 1 do. result =. ~. result , d end. end. result ) This works perfectly, and it indeed generates the first n terms in the sequence. (By n terms, I mean the first n distinct primes.) Here is the output of rowland 20: 5 3 11 23 47 101 7 13 233 467 941 1889 3779 7559 15131 53 30323 60647 121403 242807 My question is, how can I write this in more idiomatic J? I don't have a clue, although I did write the following function to find the differences between each successive number in a list of numbers, which is one of the required steps. Here it is, although it too could probably be refactored by a more experienced J programmer than I: diffs =: monad : '}: (|@({.-2&{.) , $:@}.) ^: (1 < #) y'

    Read the article

  • Calculate the digital root of a number

    - by Gregory Higley
    A digital root, according to Wikipedia, is "the number obtained by adding all the digits, then adding the digits of that number, and then continuing until a single-digit number is reached." For instance, the digital root of 99 is 9, because 9 + 9 = 18 and 1 + 8 = 9. My Haskell solution -- and I'm no expert -- is as follows. digitalRoot n | n < 10 = n | otherwise = digitalRoot . sum . map (\c -> read [c]) . show $ n As a language junky, I'm interested in seeing solutions in as many languages as possible, both to learn about those languages and possibly to learn new ways of using languages I already know. (And I know at least a bit of quite a few.) I'm particularly interested in the tightest, most elegant solutions in Haskell and REBOL, my two principal "hobby" languages, but any ol' language will do. (I pay the bills with unrelated projects in Objective C and C#.) Here's my (verbose) REBOL solution: digital-root: func [n [integer!] /local added expanded] [ either n < 10 [ n ][ expanded: copy [] foreach c to-string n [ append expanded to-integer to-string c ] added: 0 foreach e expanded [ added: added + e ] digital-root added ] ] EDIT: As some have pointed out either directly or indirectly, there's a quick one-line expression that can calculate this. You can find it in several of the answers below and in the linked Wikipedia page. (I've awarded Varun the answer, as the first to point it out.) Wish I'd known about that before, but we can still bend our brains with this question by avoiding solutions that involve that expression, if you're so inclined. If not, Crackoverflow has no shortage of questions to answer. :)

    Read the article

  • Building 'flat' rather than 'tree' LINQ expressions

    - by Ian Gregory
    I'm using some code (available here on MSDN) to dynamically build LINQ expressions containing multiple OR 'clauses'. The relevant code is var equals = values.Select(value => (Expression)Expression.Equal(valueSelector.Body, Expression.Constant(value, typeof(TValue)))); var body = equals.Aggregate<Expression>((accumulate, equal) => Expression.Or(accumulate, equal)); This generates a LINQ expression that looks something like this: (((((ID = 5) OR (ID = 4)) OR (ID = 3)) OR (ID = 2)) OR (ID = 1)) I'm hitting the recursion limit (100) when using this expression, so I'd like to generate an expression that looks like this: (ID = 5) OR (ID = 4) OR (ID = 3) OR (ID = 2) OR (ID = 1) How would I modify the expression building code to do this?

    Read the article

  • Use a stylesheet when NOT IE

    - by Sam Gregory
    When i use this code <!--[if IE 6]> <link rel="stylesheet" href="ie6.css" type="text/css" /> <![endif]--> <!--[if !IE]> <link rel="stylesheet" href="not_ie.css" type="text/css" /> <![endif]--> IE 6 does correctly use the specified stylesheet but all other browsers ignore both when they should be using the one that basically states, use this stylesheet if you are not IE. Any ideas?

    Read the article

  • How can I define a verb in J that applies a different verb alternately to each atom in a list?

    - by Gregory Higley
    Imagine I've defined the following name in J: m =: >: i. 2 4 5 This looks like the following: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 I want to create a monadic verb of rank 1 that applies to each list in this list of lists. It will double (+:) or add 1 (>:) to each alternate item in the list. If we were to apply this verb to the first row, we'd get 2 3 6 5 10. It's fairly easy to get a list of booleans which alternate with each item, e.g., 0 1 $~{:$ m gives us 0 1 0 1 0. I thought, aha! I'll use something like +:`>: @. followed by some expression, but I could never quite get it to work. Any suggestions? UPDATE The following appears to work, but perhaps it can be refactored into something more elegant by a J pro. poop =: monad define (($ y) $ 0 1 $~{:$ y) ((]+:)`(]:) @. [)"0 y )

    Read the article

  • Use a styleshhet when NOT IE

    - by Sam Gregory
    When i use this code <!--[if IE 6]> <link rel="stylesheet" href="ie6.css" type="text/css" /> <![endif]--> <!--[if !IE]> <link rel="stylesheet" href="not_ie.css" type="text/css" /> <![endif]--> IE 6 does correctly use the specified stylesheet but all other browsers ignore both when they should be using the one that basically states, use this stylesheet if you are not IE. Any ideas?

    Read the article

  • How can I maximally partition a set?

    - by Gregory Higley
    I'm trying to solve one of the Project Euler problems. As a consequence, I need an algorithm that will help me find all possible partitions of a set, in any order. For instance, given the set 2 3 3 5: 2 | 3 3 5 2 | 3 | 3 5 2 | 3 3 | 5 2 | 3 | 3 | 5 2 5 | 3 3 and so on. Pretty much every possible combination of the members of the set. I've searched the net of course, but haven't found much that's directly useful to me, since I speak programmer-ese not advanced-math-ese. Can anyone help me out with this? I can read pretty much any programming language, from BASIC to Haskell, so post in whatever language you wish.

    Read the article

  • How to filter a list in J?

    - by Gregory Higley
    I'm currently learning the fascinating J programming language, but one thing I have not been able to figure out is how to filter a list. Suppose I have the arbitrary list 3 2 2 7 7 2 9 and I want to remove the 2s but leave everything else unchanged, i.e., my result would be 3 7 7 9. How on earth do I do this?

    Read the article

  • What's the best way to pass a PHP variable to Javascript?

    - by Gregory Bolkenstijn
    I currently echo certain variables in hidden input fields and read them out with Javascript whenever I need them. Me and a colleague are now thinking of generating an extra Javascript file with PHP which only contains all variables for Javascript. This way the variables already exist and there is no extra code in the HTML. What are good ways to pass variables from PHP to Javascript? And how does our solution sound?

    Read the article

  • Accessing Amazon E-Commerce Services through Cocoa Touch

    - by Gregory Hill
    Has anyone successfully accessed AWS (Amazon E-Commerce Services) through Cocoa Touch? I've been digging around, and haven't seen the issue addressed directly. I've created an AWS account, and have seen some sample code for accessing web services through Cocoa, but I'm not quite sure how to tie it all together. If anyone has any sample code, I'd love to see it. I'm just trying to get my head around the concepts.

    Read the article

  • The Current State Of Serving a PHP 5.x App on the Apache, LightTPD & Nginx Web Servers?

    - by Gregory Kornblum
    Being stuck in a MS stack architecture/development position for the last year and a half has prevented me from staying on top of the world of open source stack based web servers recent evolution more than I would have liked to. However I am now building an open source stack based application/system architecture and sadly I do not have the time to give each of the above mentioned web servers a thorough test of my own to decide. So I figured I'd get input from the best development community site and more specifically the people who make it so. This is a site that is a resource for information regarding a specific domain and target audience with features to help users not only find the information but to also interact with one another in various ways for various reasons. I chose the open source stack for the wealth of resources it has along with much better offers than the MS stack (i.e. WordPress vs BlogEngine.NET). I feel Java is more in the middle of these stacks in this regard although I am not ruling out the possibility of using it in certain areas unrelated to the actual web app itself such as background processes. I have already come to the conclusion of using PHP (using CodeIgniter framework & APC), MySQL (InnoDB) and Memcached on CentOS. I am definitely serving static content on Nginx. However the 3 servers mentioned have no consensus on which is best for dynamic content in regards to performance. It seems LightTPD still has the leak issue which rules it out if it does, Nginx seems it is still not mature enough for this aspect and of course Apache tries to be everything for everybody. I am still going to compile the one chosen with as many performance tweaks as possible such as static linking and the likes. I believe I can get Apache to match the other 2 in regards to serving dynamic content through this process and not having it serve anything static. However during my research it seems the others are still worth considering. So with all things considered I would love to hear what everyone here has to say on the matter. Thanks!

    Read the article

< Previous Page | 1 2 3 4 5  | Next Page >