Yahoo pipes - any way to combine items? - yahoo

I'm working on a pipe and am having trouble with combining two lists of items.
List 1:
[0] letter - a
[1] letter - b
[2] letter - c
List 2:
[1] word - apple
[2] word - banana
[3] word - cake
I'd like something which emits the following:
List 3:
[1] letter - a
word - apple
[2] letter - b
word - banana
[3] letter - c
word - cake
I can't figure out for the life of me how to do this simple operation.

What you ask is verbose and complicated to do in Yahoo Pipes. If you still want to go through the trouble, here's my solution:
In this example, List 1 is a Yahoo search for "apples" and List 2 a Yahoo search for "oranges".
The main pipe starts with a list of numbers. This list is cut to the length of List 1.
Then for each number n, the n-th item of List 1 is attached to the numbered item.
Then for each number n, the n-th item of List 2 is attached to the numbered item.
Finished.
You probably want to clean things up a bit. Add a proper title, remove the number value, etc.
Notes:
I used alto maltés' list of numbers. It's not a part of Yahoo Pipes, so it might stop working.
I used two n-th item pipes. Maybe this can be simplified.
If List 2 is shorter than List 1, the last element of List 2 is used. This should be easy to change if necessary.

Related

How would I find the top 3 words from a textfile that are next to each other

This will be done in python but I would like to know how to approach it.
So say I have a text file with the contents of a book. I don't want to find the top word, I want to find the top 3 words in a row. For example, "The cat opened" is 3 words in a row, "the and is" are the top 3 words.
I can explain further if needed. Thanks!
Read the file from start to finish, one word at a time. Keep the last three words you read in memory, and increment the key (word1, word2, word3) in a dictionary. If the key didn't exist, initialize it to zero and move on.
When you've walked through the whole text, you walk through the dictionary to find the keys with the highest counter.

Adding items in a list randomly 100 times in Python

Hey all I just started learning about programming and this is problem I need to solve but I just can't get it:
Get your computer to produce its 100 first utterances. These utterances are sequences of 1, 2, 3,
or 4 random syllables sampled from the list:
[“ba”,”bi”,”bu”,”ga”,”gi”,”gu”].
You have to write a program that prints 100 random utterances of this type. For each utterances you have to select a random length (of 1, 2,3 or 4 syllables) for each utterance, plus randomly sample the chosen number of syllables from the set above.
So there's no point just giving you code, or you won't learn anything, but here are some ingredients:
You'll want a for loop that runs 100 times to give 100 utterances.
Inside that loop, you need a random number from 1 to 4 (for the number of syllables). You could import the random module and use randint to get the number. Let's say you call this number n_syll. Also, initialize an empty string to hold your word.
Then, still inside the original for loop, you need to make the actual word. Start another for loop that runs n_syll times. On each iteration, randomly select the syllable (see How to randomly select an item from a list?). Concatenate it with the word string.
When you pop outside the inner loop, you should have a random word. Just print it!
This isn't the most elegant way to do it, but it'll get the job done.
If any of these steps are too hard, maybe run through the Codecademy Python tutorial to get familiar with the basics of the language.

Generating Bulls and Cows secret word with given n String inputs

I am stuck on this problem for quite a while, it is basically reverse engineering bulls and cow game.
Read more here: http://rosettacode.org/wiki/Bulls_and_cows
I am not able to develop a logic for the problem given below, if you can think of a solving approach please comment the same.
Problem Statement:
Given few clue words(of form ABCD/DBCA etc) and the number of cows and bulls for each word,program
should be able to work out the actual word by evaluating the given clue words and generate the output secret word.
TEST CASES:
Input:
4
DBCC 0 2
CDAB 2 1
CAAD 1 2
CDDA 2 0
Output:
BDAA
The idea is to reduce the space of possible solutions. Before you start, all 4^4 combinations are possible. After you read the first clue [DBCC 0 2 ], you can eliminate a number of possible solutions, in this particular example you can eliminate all states which have a D in the first place, all which have a B in the second place and so on. Just eliminate all possible solutions which do not "fit" the current clue.
Do this with each clue, until only one solution is left. Another interesting problem of course is how to generate good clue patterns.
The way I did it is:
1. Generate all possible words, put them in a list (array)
2. Randomly select one of them (first question)and ask for clues
3. Take the answer (let's say it is 2,1)
4. Start comparing that question with
first, second, ..., to the last word from the list
5. if they give the same clue: count them, plac

sorting cards with wildcards

i am programming a card game and i need to sort a stack of cards by their rank. so that they form a gapless sequence.
in this special game the card with value 2 could be used as a wild card, so for example the cards
2 3 5
should be sorted like this
3 2 5
because the 2 replaces the 4, otherwise it would not be a valid sequence.
however the cards
2 3 4
should stay like they are.
restriction: there an be only one '2' used as a wildcard.
2 2 3 4
would also stay like it is, because the first 2 would replace the ACE (or 1, whatever you call it).
the following would not be a valid input sequence, since one of the 2s must be use as a wildcard and one not. it is not possible to make up a gapless sequence then.
2 4 2 6
now i have a difficulty to figure out if a 2 is used as a wildcard or not. once i got that, i think i can do the rest of the sorting
thanks for any algorithmic help on this problem!
EDIT in response to your clarification to your new requirement:
You're implying that you'll never get data for which a gapless sequence cannot be formed. (If only I could have such guarantees in the real world.) So:
Do you have a 2?
No: your sequence must already be gapless.
Yes: You need to figure out where to put it.
Sort your input. Do you see a gap? Since you can only use one 2 as a wildcard, there can be at most one gap.
No: treat the 2 as a legitimate number two.
Yes: move the 2 to the gap to fill it in.
EDIT in response to your new requirement:
In this case, just look for the highest single gap, and plug it with a 2 if you have a 2 available.
Original answer:
Since your sequence must be gapless, you could count the number of 2s you have and the sizes of all the gaps that are present. Then just fill in the highest gap for which you have a sufficient number of 2s.

Adding results from two 'Count' modules in Yahoo Pipes

How to add (sum up) results from two 'count' modules in Yahoo pipes ?
Suppose one 'count' module displays 4 and other one displays 5, now how can I add these results 4+5
Thanks
Connect the first count to the input of a Simple Math and the second count to the value of the same Simple Math.
If you need three counts, then just use another Simple Math with the result of the first Simple Math as the input, and the third count as the value. Repeat to infinity (and beyond).

Resources