recursion

Reversing a sentence using recursion in java

我是研究僧i 提交于 2020-02-06 04:43:41
问题 I am trying to reverse a sentence using recursion and print it out backwards. Right now after it prompts me to type in a sentence, it does not allow me to enter any input and ends. Is there something wrong with sc.nextLine()? How do I input a sentence as a string. private static void testNum3() { System.out.print("Type in a sentence:"); String sentence= sc.nextLine(); System.out.println(reverse(sentence)); } public static String reverse (String sentence) { if (sentence.length()== 0) return

Transform object data with recursive

删除回忆录丶 提交于 2020-02-05 06:00:40
问题 I try to transform data with recursive but I can't, I'm very newbie for recursive please help me Is it need to do with recursive or not what you guy think, Please help me (sorry for my english) This is my data const mock = [ { $: { id: '001' } }, { $: { id: '002' }, question: [{ $: { id: 'r001' }, prompt: 'some-r001', choices: [{ question: [ { $: { id: 'r001-1' }, prompt: 'some-r001-1', choices: [{ question: [{ $: { id: 'r001-1-1' }, prompt: 'some-r001-1-1', choices: [""], }] }] }, { $: { id:

Create an unknown number of programmatically defined variables

半腔热情 提交于 2020-02-05 05:44:05
问题 I have a recursive function that can produce a difficult-to-know number of expressions, each needing a new variable multiplied to it. These variables will later be removed out by calculations involving integration or residue. How can I develop these unknown number of variables? Maybe indexed? All examples I've seen on the internet are working with an a priori known object of a definite size, e.g. "item" in How can you dynamically create variables via a while loop? or Accessing the index in

Easier way to find nodes in a dataframe

一世执手 提交于 2020-02-05 05:18:29
问题 Given a parent, I would like to get its nodes, of level N (original dataframe is way larger) child| level| parent| 40| 1| 40| 21| 2| 40| 18| 2| 40| 37| 3| 21| 2| 3| 18| 85| 3| 21| 14| 4| 37| 58| 4| 2| 47| 4| 37| 34| 4| 85| 45| 4| 18| 32| 4| 2| 47| 4| 85| 88| 4| 85| 12| 4| 37| What I do: def get_children(x, tree, lst): for nod in tree[tree['parent'] == x]['child']: get_children(nod, tree, lst) lst.append(nod) and then I filter all nodes of level N. I would like another way because there are

Can one express catamorphism through Data.Function.fix?

吃可爱长大的小学妹 提交于 2020-02-04 05:33:29
问题 I have this lovely fixana function here that performs about 5 times faster than her sister ana . (i have a criterion report to back me on this) ana alg = Fix . fmap (ana alg) . alg fixana alg = fix $ \f -> Fix . fmap f . alg Can I express their cousin cata in the same fashion? cata f = f . fmap (cata f) . unFix It seems to me that I cannot, but I have been humbled by my S.O. fellows quite a few times in the past. 回答1: Actually, this has nothing to do with catamorphisms. Whenever a function is

creating watchfolder in Python, that performs certain operations

泪湿孤枕 提交于 2020-02-04 03:47:29
问题 Currently I'm working on project which aims on creating watchfolder in Python that would perform certain operations. I read about watchdog library and I'm trying to implement it right now. My code is based on: Using watchdog of python to monitoring afp shared folder from linux Here is structure of folders and subfolders on which operations have to be performed. https://imgur.com/mYhZydf The main folder watchfolder contain subfolders subfolX observed recursively. At the beginning, There is

How to find the next unbalanced brace?

别等时光非礼了梦想. 提交于 2020-02-03 08:39:05
问题 The regex below captures everything up to the last balanced } . Now, what regex would be able to capture everything up to the next unbalanced } ? In other words, how can I can get ... {three {four}} five} from $str instead of just ... {three {four}} ? my $str = "one two {three {four}} five} six"; if ( $str =~ / ( .*? { (?> [^{}] | (?-1) )+ } ) /sx ) { print "$1\n"; } 回答1: So you want to match [noncurlies [block noncurlies [...]]] "}" where a block is "{" [noncurlies [block noncurlies [...]]]

Runtime error when trying to logout django

瘦欲@ 提交于 2020-02-03 07:20:46
问题 When I try to logout from my django project, I get the following error: "maximum recursion depth exceeded while calling a Python object" Here is the url for the logout button: url(r'^logout', 'users.views.logout', name='logout'), And here is the view: from django.shortcuts import render from deck1.models import Card from django.template import RequestContext from django.shortcuts import render_to_response from django.http import HttpResponseRedirect, HttpResponse from django.contrib.auth

How to generate breadcrumbs using recursion on database row data?

北战南征 提交于 2020-02-02 19:57:26
问题 I have to make a breadcrumb menu which comes database. So made this function function file_list($path) { $result = array(); $q = "SELECT staticTitle,staticId,parentId FROM tbl_static_pages WHERE staticId = $path"; $run = mysql_query($q); while($row = mysql_fetch_array($run)) { if($row['parentId'] > 1) { echo $row['staticTitle']; $result = file_list($row['parentId']); return $result; // INSERTED }else { return $result; } } I have a database structure like this: id | parentId | title 3 | 1 |

How to generate breadcrumbs using recursion on database row data?

十年热恋 提交于 2020-02-02 19:50:06
问题 I have to make a breadcrumb menu which comes database. So made this function function file_list($path) { $result = array(); $q = "SELECT staticTitle,staticId,parentId FROM tbl_static_pages WHERE staticId = $path"; $run = mysql_query($q); while($row = mysql_fetch_array($run)) { if($row['parentId'] > 1) { echo $row['staticTitle']; $result = file_list($row['parentId']); return $result; // INSERTED }else { return $result; } } I have a database structure like this: id | parentId | title 3 | 1 |