Search Results

Search found 1112 results on 45 pages for 'recursive'.

Page 24/45 | < Previous Page | 20 21 22 23 24 25 26 27 28 29 30 31  | Next Page >

  • PHP: Condense array of similar strings into one merged array

    - by Matt Andrews
    Hi everyone. Working with an array of dates (opening times for a business). I want to condense them to their briefest possible form. So far, I started out with this structure Array ( [Mon] => 12noon-2:45pm, 5:30pm-10:30pm [Tue] => 12noon-2:45pm, 5:30pm-10:30pm [Wed] => 12noon-2:45pm, 5:30pm-10:30pm [Thu] => 12noon-2:45pm, 5:30pm-10:30pm [Fri] => 12noon-2:45pm, 5:30pm-10:30pm [Sat] => 12noon-11pm [Sun] => 12noon-9:30pm ) What I want to achieve is this: Array ( [Mon-Fri] => 12noon-2:45pm, 5:30pm-10:30pm [Sat] => 12noon-11pm [Sun] => 12noon-9:30pm ) I've tried writing a recursive function and have managed to output this so far: Array ( [Mon-Fri] => 12noon-2:45pm, 5:30pm-10:30pm [Tue-Fri] => 12noon-2:45pm, 5:30pm-10:30pm [Wed-Fri] => 12noon-2:45pm, 5:30pm-10:30pm [Thu-Fri] => 12noon-2:45pm, 5:30pm-10:30pm [Sat] => 12noon-11pm [Sun] => 12noon-9:30pm ) Can anybody see a simple way of comparing the values and combining the keys where they're similar? My recursive function is basically two nested foreach() loops - not very elegant. Thanks, Matt EDIT: Here's my code so far, which produces the 3rd array above (from the first one as input): $last_time = array('t' => '', 'd' => ''); // blank array for looping $i = 0; foreach($final_times as $day=>$time) { if($last_time['t'] != $time ) { // it's a new time if($i != 0) { $print_times[] = $day . ' ' . $time; } // only print if it's not the first, otherwise we get two mondays } else { // this day has the same time as last time $end_day = $day; foreach($final_times as $day2=>$time2) { if($time == $time2) { $end_day = $day2; } } $print_times[] = $last_time['d'] . '-' . $end_day . ' ' . $time; } $last_time = array('t' => $time, 'd' => $day); $i++; }

    Read the article

  • Finding partial substrings within a string

    - by Peter Chang
    I have two strings which must be compared for similarity. The algorithm must be designed to find the maximal similarity. In this instance, the ordering matters, but intervening (or missing) characters do not. Edit distance cannot be used in this case for various reasons. The situation is basically as follows: string 1: ABCDEFG string 2: AFENBCDGRDLFG the resulting algorithm would find the substrings A, BCD, FG I currently have a recursive solution, but because this must be run on massive amounts of data, any improvements would be greatly appreciated

    Read the article

  • c# parameters question

    - by n00b
    I am new to c# and need help understanding what going on in the following function public bool parse(String s) { table.Clear(); return parse(s, table, null); } where table is a Dictionary. I can see that is is recursive but how is parse being passed three params when it is defined to take just a string?

    Read the article

  • Nested routing in Ruby on Rails

    - by vooD
    My model class is: class Category < ActiveRecord::Base acts_as_nested_set has_many :children, :foreign_key => "parent_id", :class_name => 'Category' belongs_to :parent, :foreign_key => "parent_id", :class_name => 'Category' end def to_param slug end Is it possible to have such recursive route like this: /root_category_slug/child_category_slug/child_of_a_child_category_slug ... and so one Thank you for any help :)

    Read the article

  • Hibernate cascade debug options

    - by Chris
    I have run into various StackOverflowErrors which occur during cascading. These have been extremely time consuming in debugging because I don't know which properties are being cascaded to cause this recursive behavior. Does anyone know of a log setting or some other form of debugging which could tell me specifically what properties are being cascaded?

    Read the article

  • Finding the maximum weight subsequence of an array of positive integers?

    - by BeeBand
    I'm tring to find the maximum weight subsequence of an array of positive integers - the catch is that no adjacent members are allowed in the final subsequence. The exact same question was asked here, and a recursive solution was given by MarkusQ. He provides an explanation, but can anyone help me understand how he has expanded the function? How does this solution take into consideration non-adjacent members?

    Read the article

  • k-combinations of a set of integers in ascending size order

    - by Adamski
    Programming challenge: Given a set of integers [1, 2, 3, 4, 5] I would like to generate all possible k-combinations in ascending size order in Java; e.g. [1], [2], [3], [4], [5], [1, 2], [1, 3] ... [1, 2, 3, 4, 5] It is fairly easy to produce a recursive solution that generates all combinations and then sort them afterwards but I imagine there's a more efficient way that removes the need for the additional sort.

    Read the article

  • Google image Swirl - interactive information visualization

    - by skyde
    I have seen this image swirl effect on a visual thesaurus. Is there any open source code for this? Or research paper explaining how they made it. I don't care about the algorithm to match similar objects. I only am wondering about the effects. From what i understand they are called recursive orbital diagram. Screenshot: google Wonder Wheel google image swirl

    Read the article

  • T-SQL Hierarchy to duplicate Dependent Objects tree view in SQL Server 2005

    - by drewg
    Hi Id like to map the calling stack from one master stored procedure through its hundreds of siblings. i can see it in the dialog, but cannot copy or print it, but couldnt trap anythiing worthwhile in proflier. do you know what sproc fills that treeview? i must be a recursive CTE that reads syscomments or information_schema.routines, but its beyond my chops, though i can imagine it thanks in advance drew

    Read the article

  • recursively add file extension to all files

    - by seengee
    I have a few directories and sub-directories containing files with no file extension. I want to add .jpg to all the files contained within these directories. I have seen bash scripts for changing the file extension but not for just adding one. It also needs to be recursive, can someone help please?

    Read the article

  • python: a way to get an exhaustive, sorted list of keys in a nested dictionary?

    - by saidimu
    exhaustive: - all keys in the dictionary, even if the keys are in a nested dictionary that is a value to a previous-level dictionary key. sorted: - this is to ensure the keys are always returned in the same order The nesting is arbitrarily deep. A non-recursive algorithm is preferred. level1 = { 'a' : 'aaaa', 'level2_1' : {'b': 'bbbbb', 'level3': {'c': 'cccc', 'd': 'dddddd'} }, 'level2_2' : { 'z': 'zzzzzzz' } }

    Read the article

  • Is this grammar SLR?

    - by Mike
    E - A | B A - a | c B - b | c My answer is no because it has a reduce/reduce conflict, can anyone else verify this? Also I gained my answer through constructing the transition diagram, is there a simpler way of finding this out? Thanks for the help! P.S Would a Recursive Descent be able to parse this?

    Read the article

  • Copying only the changed files while mirroring a website

    - by Rishi Verma
    I am using wget to mirror website using this code $ wget \ --recursive \ --no-clobber \ --page-requisites \ --html-extension \ --convert-links \ --restrict-file-names=windows \ --domains website.org \ --no-parent \ www.website.org/tutorials/html/ The next time I run it it starts downloading the same files again, however I want only the changed files to be downloaded next time. I am open to use any other tool or script(preferably PHP,Curl) apart from using wget.

    Read the article

  • Python recursion with list returns None

    - by newman
    def foo(a): a.append(1) if len(a) > 10: print a return a else: foo(a) Why this recursive function returns None (see transcript below)? I can't quite understand what I am doing wrong. In [263]: x = [] In [264]: y = foo(x) [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] In [265]: print y None

    Read the article

  • How do I compare two complex data structures?

    - by Phil H
    I have some nested datastructures, each something like: [ ('foo', [ {'a':1, 'b':2}, {'a':3.3, 'b':7} ]), ('bar', [ {'a':4, 'd':'efg', 'e':False} ]) ] I need to compare these structures, to see if there are any differences. Short of writing a function to explicitly walk the structure, is there an existing library or method of doing this kind of recursive comparison?

    Read the article

< Previous Page | 20 21 22 23 24 25 26 27 28 29 30 31  | Next Page >