# Search Results

• ### convert an int to list of individual digitals more faster?

##### - by user478514
All, I want define an int(987654321) <= [9, 8, 7, 6, 5, 4, 3, 2, 1] convertor, if the length of int number < 9, for example 10 the list will be [0,0,0,0,0,0,0,1,0] , and if the length 9, for example 9987654321 , the list will be [9, 9, 8, 7, 6, 5, 4, 3, 2, 1] >>> i 987654321 >>> l [9, 8, 7, 6, 5, 4, 3, 2, 1] >>> z = [0]*(len(unit) - len(str(l))) >>> z.extend(l) >>> l = z >>> unit [100000000, 10000000, 1000000, 100000, 10000, 1000, 100, 10, 1] >>> sum([x*y for x,y in zip(l, unit)]) 987654321 >>> int("".join([str(x) for x in l])) 987654321 >>> l1 = [int(x) for x in str(i)] >>> z = [0]*(len(unit) - len(str(l1))) >>> z.extend(l1) >>> l1 = z >>> l1 [9, 8, 7, 6, 5, 4, 3, 2, 1] >>> a = [i//x for x in unit] >>> b = [a[x] - a[x-1]*10 for x in range(9)] >>> if len(b) = len(a): b[0] = a[0] # fix the a[-1] issue >>> b [9, 8, 7, 6, 5, 4, 3, 2, 1] I tested above solutions but found those may not faster/simple enough than I want and may have a length related bug inside, anyone may share me a better solution for this kinds convertion? Thanks!

• ### Looking for an appropriate design pattern

##### - by user1066015
I have a game that tracks user stats after every match, such as how far they travelled, how many times they attacked, how far they fell, etc, and my current implementations looks somewhat as follows (simplified version): Class Player{ int id; public Player(){ int id = Math.random()*100000; PlayerData.players.put(id,new PlayerData()); } public void jump(){ //Logic to make the user jump //... //call the playerManager PlayerManager.jump(this); } public void attack(Player target){ //logic to attack the player //... //call the player manager PlayerManager.attack(this,target); } } Class PlayerData{ public static HashMap<int, PlayerData> players = new HashMap<int,PlayerData>(); int id; int timesJumped; int timesAttacked; } public void incrementJumped(){ timesJumped++; } public void incrementAttacked(){ timesAttacked++; } } Class PlayerManager{ public static void jump(Player player){ players.get(player.getId()).incrementJumped(); } public void incrementAttacked(Player player, Player target){ players.get(player.getId()).incrementAttacked(); } } So I have a PlayerData class which holds all of the statistics, and brings it out of the player class because it isn't part of the player logic. Then I have PlayerManager, which would be on the server, and that controls the interactions between players (a lot of the logic that does that is excluded so I could keep this simple). I put the calls to the PlayerData class in the Manager class because sometimes you have to do certain checks between players, for instance if the attack actually hits, then you increment "attackHits". The main problem (in my opinion, correct me if I'm wrong) is that this is not very extensible. I will have to touch the PlayerData class if I want to keep track of a new stat, by adding methods and fields, and then I have to potentially add more methods to my PlayerManager, so it isn't very modulized. If there is an improvement to this that you would recommend, I would be very appreciative. Thanks.

• ### Cannot Find Symbol Method?

##### - by Aaron
In my driver program, This line gives me cannot find symbol error and I don't know why, the method is clearly defined in the SavingsAccount class, and I can refer to all other methods in my driver program but just not that one, I tried changing the type to double, and etc but still not working. Refer to ** Account acct2 = new SavingsAccount (name); acct2.calculateBalance(); SavingsAccount Class Inherited from Account Class: public class SavingsAccount extends Account { private final short minBalance = 0; private double overdraftFee; private double yearlyInterestRate = 0.02; private double interestAmount; public SavingsAccount (String name) { super(name); } public double withdraw (double amount) { if (accountBalance - amount >= minBalance) { accountBalance -= amount; System.out.print ("Withdraw Successful"); } else { accountBalance -= amount; overdraftFee = accountBalance * (0.10); accountBalance += overdraftFee; System.out.print ("Withdraw Succesful, however overdraft fee of 10% has been applied to your account"); } return accountBalance; } **public void calculateBalance () { interestAmount = (accountBalance * yearlyInterestRate); accountBalance += interestAmount; }** public String toString() { return super.toString() + " Interest Received: " + interestAmount; } } Account class, if needed import java.util.Random; import java.text.NumberFormat; public abstract class Account { protected double accountBalance; protected long accountNumber; protected String accountHolder; public Account (String name) { accountHolder = name; accountBalance = 0; Random accountNo = new Random(); accountNumber = accountNo.nextInt(100000); } public double deposit (double amount) { accountBalance += amount; return accountBalance; } public String toString() { NumberFormat accountBal = NumberFormat.getCurrencyInstance(); return "Account Balance: " + accountBal.format(accountBalance) + "\nAccount Number: " + accountNumber; } public String getAccountHolder() { return accountHolder; } public double getAccountBalance() { return accountBalance; } public abstract double withdraw (double amount); }

• ### Playing craps, asking and printing

##### - by Angelo Mejia
How do I ask the amount of games of craps someone wants to play and print the number of wins as a result of n number of games? Also How do I make a table in the main method using the previous methods I have? A table like this but shows the results: Percent Wins Games Experiment Number 1 2 3 4 5 6 7 8 9 10 100 1000 10000 100000 1000000 public class CrapsAnalysis { public static int rollDie( int n) { return (int)(Math.random()*n) + 1 ; } public static int rollDice( ) { int die1 ; int die2 ; die1 = rollDie(6) ; die2 = rollDie(6) ; return die1 + die2 ; } public static boolean playOneGame( ) { int newDice ; //repeated dice rolls int roll ; //first roll of the dice int playerPoint = 0 ; //player point if no win or loss on first roll newDice = rollDice() ; roll = rollDice() ; if (roll == 7 || roll == 11) return true; else if (roll == 2 || roll == 3 || roll == 12) return false; else { playerPoint = roll; newDice = rollDice(); do { newDice = rollDice(); } while (newDice != playerPoint || newDice != 7) ; if (newDice == 7) return false; else return true; } } public static int playGames ( int n ) { int numWon = 0; for (int i = 1; i <= n; i++) if(playOneGame()) numWon++; return numWon; } public static void main(String[] args) { //Don't know how to ask and print out the results of the number of wins depending on the n number of games played } }

• ### What is the optimum way to select the most dissimilar individuals from a population?

##### - by Aaron D
I have tried to use k-means clustering to select the most diverse markers in my population, for example, if we want to select 100 lines I cluster the whole population to 100 clusters then select the closest marker to the centroid from each cluster. The problem with my solution is it takes too much time (probably my function needs optimization), especially when the number of markers exceeds 100000. So, I will appreciate it so much if anyone can show me a new way to select markers that maximize diversity in my population and/or help me optimize my function to make it work faster. Thank you # example: library(BLR) data(wheat) dim(X) mdf<-mostdiff(t(X), 100,1,nstart=1000) Here is the mostdiff function that i used: mostdiff <- function(markers, nClust, nMrkPerClust, nstart=1000) { transposedMarkers <- as.array(markers) mrkClust <- kmeans(transposedMarkers, nClust, nstart=nstart) save(mrkClust, file="markerCluster.Rdata") # within clusters, pick the markers that are closest to the cluster centroid # turn the vector of which markers belong to which clusters into a list nClust long # each element of the list is a vector of the markers in that cluster clustersToList <- function(nClust, clusters) { vecOfCluster <- function(whichClust, clusters) { return(which(whichClust == clusters)) } return(apply(as.array(1:nClust), 1, vecOfCluster, clusters)) } pickCloseToCenter <- function(vecOfCluster, whichClust, transposedMarkers, centers, pickHowMany) { clustSize <- length(vecOfCluster) # if there are fewer than three markers, the center is equally distant from all so don't bother if (clustSize < 3) return(vecOfCluster[1:min(pickHowMany, clustSize)]) # figure out the distance (squared) between each marker in the cluster and the cluster center distToCenter <- function(marker, center){ diff <- center - marker return(sum(diff*diff)) } dists <- apply(transposedMarkers[vecOfCluster,], 1, distToCenter, center=centers[whichClust,]) return(vecOfCluster[order(dists)[1:min(pickHowMany, clustSize)]]) } }

• ### Multithreading for loop while maintaining order

##### - by David
I started messing around with multithreading for a CPU intensive batch process I'm running. Essentially I'm trying to condense multiple single page tiffs into single PDF documents. This works fine with a foreach loop or standard iteration but can be very slow for several 100 page documents. I tried the following based on a some examples I found to use multithreading and it has significant performance improvements however it obliterates the page order instead of 1,2,3,4 it will be 1,3,4,2,6,5 on what thread completes first. My question is how would I utilize this technique while maintaining the page order and if I can will it negate the performance benefit of the multithreading? Thank you in advance. PdfDocument doc = new PdfDocument(); string mail = textBox1.Text; string[] split = mail.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); int counter = split.Count(); // Source must be array or IList. var source = Enumerable.Range(0, 100000).ToArray(); // Partition the entire source array. var rangePartitioner = Partitioner.Create(0, counter); double[] results = new double[counter]; // Loop over the partitions in parallel. Parallel.ForEach(rangePartitioner, (range, loopState) => { // Loop over each range element without a delegate invocation. for (int i = range.Item1; i < range.Item2; i++) { f_prime = split[i].Replace(" " , ""); PdfPage page = doc.AddPage(); XGraphics gfx = XGraphics.FromPdfPage(page); XImage image = XImage.FromFile(f_prime); double x = 0; gfx.DrawImage(image, x, 0); } });

• ### R Random Data Sets within loops

##### - by jugossery
Here is what I want to do: I have a time series data frame with let us say 100 time-series of length 600 - each in one column of the data frame. I want to pick up 4 of the time-series randomly and then assign them random weights that sum up to one (ie 0.1, 0.5, 0.3, 0.1). Using those I want to compute the mean of the sum of the 4 weighted time series variables (e.g. convex combination). I want to do this let us say 100k times and store each result in the form ts1.name, ts2.name, ts3.name, ts4.name, weight1, weight2, weight3, weight4, mean so that I get a 9*100k df. I tried some things already but R is very bad with loops and I know vector oriented solutions are better because of R design. Thanks Here is what I did and I know it is horrible The df is in the form v1,v2,v2.....v100 1,5,6,.......9 2,4,6,.......10 3,5,8,.......6 2,2,8,.......2 etc e=NULL for (x in 1:100000) { s=sample(1:100,4)#pick 4 variables randomly a=sample(seq(0,1,0.01),1) b=sample(seq(0,1-a,0.01),1) c=sample(seq(0,(1-a-b),0.01),1) d=1-a-b-c e=c(a,b,c,d)#4 random weights average=mean(timeseries.df[,s]%*%t(e)) e=rbind(e,s,average)#in the end i get the 9*100k df } The procedure runs way to slow. EDIT: Thanks for the help i had,i am not used to think R and i am not very used to translate every problem into a matrix algebra equation which is what you need in R. Then the problem becomes a little bit complex if i want to calculate the standard deviation. i need the covariance matrix and i am not sure i can if/how i can pick random elements for each sample from the original timeseries.df covariance matrix then compute the sample variance (t(sampleweights)%*%sample_cov.mat%*%sampleweights) to get in the end the ts.weighted_standard_dev matrix Last question what is the best way to proceed if i want to bootstrap the original df x times and then apply the same computations to test the robustness of my datas thanks

• ### JavaScript: Is there a better way to retain your array but efficiently concat or replace items?

##### - by Michael Mikowski
I am looking for the best way to replace or add to elements of an array without deleting the original reference. Here is the set up: var a = [], b = [], c, i, obj; for ( i = 0; i < 100000; i++ ) { a[ i ] = i; b[ i ] = 10000 - i; } obj.data_list = a; Now we want to concatenate b INTO a without changing the reference to a, since it is used in obj.data_list. Here is one method: for ( i = 0; i < b.length; i++ ) { a.push( b[ i ] ); } This seems to be a somewhat terser and 8x (on V8) faster method: a.splice.apply( a, [ a.length, 0 ].concat( b ) ); I have found this useful when iterating over an "in-place" array and don't want to touch the elements as I go (a good practice). I start a new array (let's call it keep_list) with the initial arguments and then add the elements I wish to retain. Finally I use this apply method to quickly replace the truncated array: var keep_list = [ 0, 0 ]; for ( i = 0; i < a.length; i++ ){ if ( some_condition ){ keep_list.push( a[ i ] ); } // truncate array a.length = 0; // And replace contents a.splice.apply( a, keep_list ); There are a few problems with this solution: there is a max call stack size limit of around 50k on V8 I have not tested on other JS engines yet. This solution is a bit cryptic Has anyone found a better way?

• ### Improve Efficiency in Array comparison in Ruby

##### - by user2985025
Hi I am working on Ruby /cucumber and have an requirement to develop a comparison module/program to compare two files. Below are the requirements The project is a migration project . Data from one application is moved to another Need to compare the data from the existing application against the new ones. Solution : I have developed a comparison engine in Ruby for the above requirement. a) Get the data, de duplicated and sorted from both the DB's b) Put the data in a text file with "||" as delimiter c) Use the key columns (number) that provides a unique record in the db to compare the two files For ex File1 has 1,2,3,4,5,6 and file2 has 1,2,3,4,5,7 and the columns 1,2,3,4,5 are key columns. I use these key columns and compare 6 and 7 which results in a fail. Issue : The major issue we are facing here is if the mismatches are more than 70% for 100,000 records or more the comparison time is large. If the mismatches are less than 40% then comparison time is ok. Diff and Diff -LCS will not work in this case because we need key columns to arrive at accurate data comparison between two applications. Is there any other method to efficiently reduce the time if the mismatches are more thatn 70% for 100,000 records or more. Thanks

• ### How can I create an array of random numbers in C++

##### - by Nick
Instead of The ELEMENTS being 25 is there a way to randomly generate a large array of elements....10000, 100000, or even 1000000 elements and then use my insertion sort algorithms. I am trying to have a large array of elements and use insertion sort to put them in order and then also in reverse order. Next I used clock() in the time.h file to figure out the run time of each algorithm. I am trying to test with a large amount of numbers. #define ELEMENTS 25 void insertion_sort(int x[],int length); void insertion_sort_reverse(int x[],int length); int main() { clock_t tStart = clock(); int B[ELEMENTS]={4,2,5,6,1,3,17,14,67,45,32,66,88, 78,69,92,93,21,25,23,71,61,59,60,30}; int x; cout<<"Not Sorted: "<<endl; for(x=0;x<ELEMENTS;x++) cout<<B[x]<<endl; insertion_sort(B,ELEMENTS); cout <<"Sorted Normal: "<<endl; for(x=0;x<ELEMENTS;x++) cout<< B[x] <<endl; insertion_sort_reverse(B,ELEMENTS); cout <<"Sorted Reverse: "<<endl; for(x=0;x<ELEMENTS;x++) cout<< B[x] <<endl; double seconds = clock() / double(CLK_TCK); cout << "This program has been running for " << seconds << " seconds." << endl; system("pause"); return 0; }

• ### Triangulation in 3D Space

##### - by w3b_wizzard
Disclaimer: This is for class, however I'm fresh out of ideas and a nudge in the right direction would be much appreciated. Also, this needs to be implemented in raw C, so no fancy libraries can be used. I have to write a search and rescue simulator for submarines, it has to find a probe that is randomly placed in 3D space in a grid from of the MAX_XYZ (100000). The only tools I'm given are a "ping" which will give the magnitude of the distance between a certain sub and the probe. The goal is to optimize the costs of this entire operation so a brute force attempt, like looking at every single coordinate, won't work. Hence I was thinking triangulation. Now, it makes loads of sense to me, place three subs, each one of them uses their ping to get the distance between them and the probe. Since each sub have a known distance relative to one another, it's easy to build the base of a tetrahedron with them, and the results of the ping will point to a certain coordinate, the problem I'm having is how to figure out the elevation, or the height, of the tetrahedron. So what I have as data is the following: Distances between subs (In vector format) Angles between each subs (very easy to compute) Distance between each sub and the probe (3 segments from the base to the peak) Angles inside each of the outer 3 surfaces of the tetrahedron. I tried finding some sort of relationship with the vertices of the tetrahedron and the relative angles in each of them, however all I found had to deal with tetrahedrons built with equilateral triangles, which isn't much help. I have the impression this can be easily solved with trig but either I'm not seeing it or I need more coffee. Any suggestions would be appreciated!

• ### Windows 2008 R2 CA and auto-enrollment: how to get rid of >100,000 issued certificates?

##### - by HopelessN00b
The basic problem I'm having is that I have 100,000 useless machine certificates cluttering up my CA, and I'd like to delete them, without deleting all certs, or time jumping the server ahead, and invalidating some of the useful certs on there. This came about as a result of accepting a couple defaults with our Enterprise Root CA (2008 R2) and using a GPO to auto-enroll client machines for certificates to allow 802.1x authentication to our corporate wireless network. Turns out that the default Computer (Machine) Certificate Template will happily allow machines to re-enroll instead of directing them to use the certificate they already have. This is creating a number of problems for the guy (me) who was hoping to use the Certificate Authority as more than a log of every time a workstation's been rebooted. (The scroll bar on the side is lying, if you drag it to the bottom, the screen pauses and loads the next few dozen certs.) Does anyone know how to DELETE 100,000 or so time-valid, existing certificates from a Windows Server 2008R2 CA? When I go to delete a certificate now, now, I get an error that it cannot be delete because it's still valid. So, ideally, some way to temporarily bypass that error, as Mark Henderson's provided a way to delete the certificates with a script once that hurdle is cleared. (Revoking them is not an option, as that just moves them to Revoked Certificates, which we need to be able to view, and they can't be deleted from the revoked "folder" either.) Update: I tried the site @MarkHenderson linked, which is promising, and offers much better certificate manageability, buts still doesn't quite get there. The rub in my case seems to be that the certificates are still "time-valid," (not yet expired) so the CA doesn't want to let them be deleted from existence, and this applies to revoked certs as well, so revoking them all and then deleting them won't work either. I've also found this technet blog with my Google-Fu, but unfortunately, they seemed to only have to delete a very large number of certificate requests, not actual certificates. Finally, for now, time jumping the CA forward so the certificates I want to get rid of expire, and therefore can be deleted with the tools at the site Mark linked is not a great option, as would expire a number of valid certificates we use that have to be manually issued. So it's a better option than rebuilding the CA, but not a great one.

• ### What does transactions per seconds for a load balancer mean

##### - by Anurag
I was looking at the product matrix of webmux 592G(load balancer). It says maximum connections per sec = 2.8M Maximum number of transactions = 100,000 What does the above numbers mean. Does above means that load balancer can have 2.8M connections open but only 100K of them will be active per seconds. Also incase any one has used webmux 592G do you guys know in practice how many connections it can have open and what qps it can serve

• ### What would be a good alternate for the SugarCRM email databse?

##### - by Chaz Black
My company has between 50,000 - 100,000 contacts that is currently being managed in excel. The director of marketing wants an email database to work in junction with Microsoft Exchange and our budget is \$5,000 for the program. SugarCRM seems great but what other programs are comparable?

• ### Rule of thumb in RAM estimate for static pages? [closed]

##### - by IMB
Possible Duplicate: How do you do Load Testing and Capacity Planning for Web Sites I've seen tutorials saying they can run decent websites on 64MB RAM (Debian/Lighttpd/PHP/MySQL) however it's not clearly defined how much hits/traffic a "decent" site gets. Is there a rule of thumb on how much RAM a web server needs? To keep things simple, let's say you're running a site with static content and it's averaging at 100,000 hits per hour (HTML + images combined, no MySQL). How much RAM is the minimum requirement for that?

• ### Oracle saves with Oracle Database 11g and Advanced Compression

##### - by jenny.gelhausen
Oracle Corporation runs a centralized eBusiness Suite system on Oracle Database 11g for all its employees around the globe. This clustered Global Single Instance (GSI) has scaled seamlessly with many acquisitions over the years, doubling the number of employees since 2001 and supporting around 100,000 employees today, 24 hours a day, 7 days a week around the world. In this podcast, you'll hear from Raji Mani, IT Director for Oracle's PDIT Group, on how Oracle Database 11g and Advanced Compression is helping to save big on storage costs. var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); try { var pageTracker = _gat._getTracker("UA-13185312-1"); pageTracker._trackPageview(); } catch(err) {}

• ### Parsing google site speed in analytics

##### - by Kevin Burke
I'm having a hard time making heads or tails of the Site Speed graphs in Google Analytics. Our site speed is fluctuating wildly from month to month, despite a large sample (the report is "based on 100,000's of visits) and a consistent web set up (static files served from an EC2 instance running nginx behind a load balancer). Here's our site speed, with each datapoint representing a week worth of data. Over this time period we modified our source and HTTP headers to increase our cache hits on static resources by 5x. Why would it fluctuate so much? Is there any way to get more reliable information from those graphs?

• ### SUN Customers and Partners, preview My Oracle Support

##### - by chris.warticki
Preview My Oracle Support - now! Take advantage of My Oracle Support before full migration. Oracle Global Customer Support invites you to preview some of the support platform's key capabilities. With the preview to My Oracle Support, Sun customers and partners can have immediate access to: My Oracle Support Community, with live advisor webcasts, active moderation by Oracle/Sun support engineers, user interaction, best practices presentations, and news and announcements Knowledgebase, with more than 900,000 articles, including more than 100,000 Sun Support articles and documents.   -Chris Warticki twittering @cwarticki Join one of the Twibes - http://twibes.com/MyOracleSupport or http://twibes.com/OracleSupport

• ### App Fabric Service Bus and Access Control Pricing

##### - by kaleidoscope
The Service Bus costs \$3.99 per Connection-month on a consumption basis for individually provisioned connections. Data transfers charges would also apply. Or, if you are able to forecast your needs ahead of time, you can purchase “Packs” of Connections. For example: \$9.95 for a pack of 5 Connections, \$49.75 for a pack of 25, \$199.00 for a pack of 100, or \$995 for a pack of 500, plus data transfer charges. Connection Packs represent an effective rate of \$1.99 per Connection-month. Access Control will be priced at \$1.99 per 100,000 Transactions, which includes token requests and management operations, plus associated data transfer. Typically, Service Bus developers depend on Access Control to secure their Connections. More Information: http://azurefeeds.com/post/865/Announcing_Windows_Azure_platform_commercial_offer_availability_and_updated_AppFabric_pricing.aspx   Amit, S

• ### FREE Windows Azure Platform Compute and Storage through the Cloud Essentials Pack for Partners

##### - by Eric Nelson
It can be difficult to find something to look forward to in January – but this year it was a little easier as a) I got lots of great Xbox 360 games and b) the Windows Azure Platform element of the Cloud Essentials Pack for Microsoft Partner Network partners went live. I have previously explained what the Cloud Essentials Pack is and how you can access – but at the time I couldn’t share the details of the Windows Azure Platform element. The Windows Azure Platform element is now available. It gives you each month, for FREE: Windows Azure: 750 hours of extra small compute instance 25 hours of small compute instance 3GB of storage and 250,000 storage transactions SQL Azure: 1 SQL Azure Web Edition database (5GB) Windows Azure AppFabric: App Fabric with 100,000 Access Control transactions and 2 Service Bus connections Plus: Data Transfer:  3GB in and 6GB out (More details of the offer) To activate this offer You need to: Sign your company up to Microsoft Platform Ready (NB: there are other routes to get this benefit – but I know about MPR) Read about Microsoft Platform Ready Visit http://www.microsoftcloudpartner.com/ and sign up.