How to write a Java or Javascript program which organizes data give in alphabetical order? - alphabetical

I want to be able to compile and run a java or javascript program which allows me to write words randomly then it assorts them alphabetically. How would this be done? is their any public domain codes that do this?
Thank You

Javascript's array.sort() method would work fine:
http://www.w3schools.com/jsref/jsref_sort.asp
var a = [1, 4, 2, 90, 34];
a = a.sort();
I don't know much with java, but it looks like it has a similar thing:
http://www.tutorialspoint.com/java/util/arrays_sort_int.htm
This question has been asked before, by the way, so be sure to do some research before asking.

Create a list of your words and then use java.util.Collections.sort(yourList)

Related

Trying to print a generator object with a short code

It probably has been asked before,
But I couldn't find something like that,
I'm trying to print a generator object:
n="12234451"
print(*[n[c]for c in range(len(n))if n[c]!=n[c-1]or c==0],sep="")
I usually use something like that, however, I'm wondering if it's the most efficient way to do it
(without changing the fact that the expression is in the print)
Thanks for your time

Creating graphs using code from Pari-GP, but using Sage's graphing tools

everyone!
I know this is probably a dumb question, but I'm having a lot of trouble with Sage, and it's frustrating the hell out of me. To give a bit of an explanation, I code entirely in pari-gp. I don't have a single problem with my code in pari-gp, I'm just having trouble with interfacing my code with Sage. Which, this is something Sage bolsters, that you can run pari-gp code within sage. I essentially want to run all my processes in pari-gp, but I want to exploit all of Sage's graphing protocols.
What I want to do couldn't be easier. I have a well working function test(x,y), which produces a real number. I don't have any problems running this in pari, everything is kosher. All I want to do is make a graph of test(x,y) = z. Now I know how to run this command in sage, but I don't know how to interface such that test is actually a program running from Pari code.
I'd love to program all my stuff in Sage, but that's just impossible. I need the language Pari, so before you say that I could just translate everything in Sage, it's impossible. I just can't wrap my head around how to interface Pari with Sage. I know it's possible; hell, they advertise it on the main website. I'm just very unclear about how to do the following:
1.) Read a file from my pari-gp root directory: gp.read("myfile.gp").
2.) Inherit the functions, such that gp("test(x,y)"), now runs as though it runs in the GP terminal.
3.) Graph said function test(x,y) using Sage's graphing protocols.
Any help is greatly appreciated. I know I'm just forgetting to do something dumb, or I'm missing a step in how I'm doing it.
Any help is greatly appreciated!
Let us start with:
sage: gp("test(x, y) = sin(x*y)")
(x,y)->sin(x*y)
sage: gp("test(1, 1)")
0.84147098480789650665250232163029899962
sage: type(_)
<class 'sage.interfaces.gp.GpElement'>
So the printed version of gp("test(1, 1)") looks like a number, but it is not a float instance. Note that py3 has some f-strings, so we can easily plug in values of variables x, y inside the gp("test(...)") . I will use f-strings to define the sage function...
And we are not far away from the final plot:
sage: f = lambda x, y: float( gp(f"test({x}, {y})") )
sage: plot3d(f, [0, pi], [0, pi])
Launched html viewer for Graphics3d Object

How do I split individual character within a list that is within a list?

I am working on a project in Python, and I stumbled across this hindrance.
I have something like this:
[['abcde'],['bcdef']]
How do I make it such that it gives me this? :
[['a','b','c','d','e'],['b','c','d','e','f']]
Thank you for helping
It would be better if you start reading docs
[list(string) for string in given_list]
or otherwise
list(map(list,given_list))

add quotes("") to a value in groovy

Even after googling a lot i couldn't find the solution for the query to which i'm going to ask so, please don't mind if its a silly question since i'm new to programming and this "Groovy" so here is my question.
I'm writing a script in groovy where it reads a file contains data like this
[a,b,c,d,e]
I want to find the length/size, as groovy is not recognizing it as string i'm getting exceptions so, i need the above one as below i.e.
[a,b,c,d,e] ---> ["a","b","c","d","e"]
please provide me the solution or let me know a way to achieve it.
Thanks in advance.
In groovy, easy to perform operations on strings. Added a file sample.txt which contains [a, b, c, d, e], for converting this to List<String>, used collect as
new File('../sample.txt').getText('UTF-8')
.tokenize(',[]').collect { it as String }.asList().size()
Online IDE: https://ideone.com/06k6Nj

How to compare Strings and put it into another program?

i´ve got small problem and before I spend even more time in trying to solve it i´d like to know if what I want to do is even possible ( and maybe input on how to do it^^).
My problem:
I want to take some text and then split it into different strings at every whitespace (for example "Hello my name is whatever" into "Hello" "my" "name" "is" "whatever").
Then I want to set every string with it´s own variable so that I get something alike to a= "Hello" b= "my" and so on. Then I want to compare the strings with other strings (the idea is to get addresses from applications without having to search through them so I thought I could copy a telephone book to define names and so on) and set matching input to variables like Firstname , LastName and street.
Then, and here comes the "I´d like to know if it´s possible" part I want it to put it into our database, this means I want it to copy the string into a text field and then to go to the next field via tab. I´ve done something like this before with AutoIT but i´ve got no idea how to tell AutoIT whats inside the strings so I guess it must be done through the programm itself.
I´ve got a little bit of experience with c++, python and BATCH files so it would be nice if anyone could tell me if this can even be done using those languages (and I fear C++ can do it and I´m just to stupid to do so).
Thanks in advance.
Splitting a string is very simple, there is usually a built in method called .split() which will help you, the method varies from language to language.
When you've done a split, it will be assigned to an array, you can then use an index to get the variables, for example you'd have:
var str = "Hello, my name is Bob";
var split = str.split(" ");
print split[0]; // is "Hello,"
print split[1]; // is "my" etc
You can also use JSON to return data so you could have an output like
print split["LastName"];
What you're asking for is defiantly possible.
Some links that could be useful:
Split a string in C++?
https://code.google.com/p/cpp-json/

Resources