Search Results

Search found 69247 results on 2770 pages for 'problem solving'.

Page 9/2770 | < Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >

  • Need some testcases on solving this problem

    - by user285825
    I am trying to solve the minesweeper problem of acm problemset archive, http://uva,onlinejudge,org/index,php?option=com_onlinejudge&Itemid=8&category=13&page=show_problem&problem=1130 I tested with all the possible cases that I can imagine of: 1, minimum 1 1 , 1 1 # 2, maximum upto 100 upto 100 repeat until 100 3, for each position I test for mine 4 4 ,,, ,,,, ,,,, 4 4 ,#,, ,,,, ,,,, ,,,, lastly 4 4 ,,,, ,,,, ,,,, ,,,# 4, for each postion I put a ',' and surround it with mines 4 4 ,### # # # 4 4 , # # # lastly 4 4 # # # , I thought that these are reasonable and representative sets of testcases, But still Wrong answer, I am not sure what else could I test for, I would be glad if someone throw some light on further strategy to test this thing,

    Read the article

  • Solving the problem of finding parts which work well with each other

    - by dotnetdev
    Hi, I have a database of items. They are for cars and similar parts (eg cam/pistons) work better than others in different combinations (eg one product will work well with another, while another combination of 2 parts may not). There are so many possible permutations, what solutions apply to this problem? So far, I feel that these are possible approaches (Where I have question marks, something tells me these are solutions but I am not 100% confident they are). Neural networks (?) Collection-based approach (selection of parts in a collection for cam, and likewise for pistons in another collection, all work well with each other) Business rules engine (?) What are good ways to tackle this sort of problem? Thanks

    Read the article

  • Solving embarassingly parallel problems using Python multiprocessing

    - by gotgenes
    How does one use multiprocessing to tackle embarrassingly parallel problems? Embarassingly parallel problems typically consist of three basic parts: Read input data (from a file, database, tcp connection, etc.). Run calculations on the input data, where each calculation is independent of any other calculation. Write results of calculations (to a file, database, tcp connection, etc.). We can parallelize the program in two dimensions: Part 2 can run on multiple cores, since each calculation is independent; order of processing doesn't matter. Each part can run independently. Part 1 can place data on an input queue, part 2 can pull data off the input queue and put results onto an output queue, and part 3 can pull results off the output queue and write them out. This seems a most basic pattern in concurrent programming, but I am still lost in trying to solve it, so let's write a canonical example to illustrate how this is done using multiprocessing. Here is the example problem: Given a CSV file with rows of integers as input, compute their sums. Separate the problem into three parts, which can all run in parallel: Process the input file into raw data (lists/iterables of integers) Calculate the sums of the data, in parallel Output the sums Below is traditional, single-process bound Python program which solves these three tasks: #!/usr/bin/env python # -*- coding: UTF-8 -*- # basicsums.py """A program that reads integer values from a CSV file and writes out their sums to another CSV file. """ import csv import optparse import sys def make_cli_parser(): """Make the command line interface parser.""" usage = "\n\n".join(["python %prog INPUT_CSV OUTPUT_CSV", __doc__, """ ARGUMENTS: INPUT_CSV: an input CSV file with rows of numbers OUTPUT_CSV: an output file that will contain the sums\ """]) cli_parser = optparse.OptionParser(usage) return cli_parser def parse_input_csv(csvfile): """Parses the input CSV and yields tuples with the index of the row as the first element, and the integers of the row as the second element. The index is zero-index based. :Parameters: - `csvfile`: a `csv.reader` instance """ for i, row in enumerate(csvfile): row = [int(entry) for entry in row] yield i, row def sum_rows(rows): """Yields a tuple with the index of each input list of integers as the first element, and the sum of the list of integers as the second element. The index is zero-index based. :Parameters: - `rows`: an iterable of tuples, with the index of the original row as the first element, and a list of integers as the second element """ for i, row in rows: yield i, sum(row) def write_results(csvfile, results): """Writes a series of results to an outfile, where the first column is the index of the original row of data, and the second column is the result of the calculation. The index is zero-index based. :Parameters: - `csvfile`: a `csv.writer` instance to which to write results - `results`: an iterable of tuples, with the index (zero-based) of the original row as the first element, and the calculated result from that row as the second element """ for result_row in results: csvfile.writerow(result_row) def main(argv): cli_parser = make_cli_parser() opts, args = cli_parser.parse_args(argv) if len(args) != 2: cli_parser.error("Please provide an input file and output file.") infile = open(args[0]) in_csvfile = csv.reader(infile) outfile = open(args[1], 'w') out_csvfile = csv.writer(outfile) # gets an iterable of rows that's not yet evaluated input_rows = parse_input_csv(in_csvfile) # sends the rows iterable to sum_rows() for results iterable, but # still not evaluated result_rows = sum_rows(input_rows) # finally evaluation takes place as a chain in write_results() write_results(out_csvfile, result_rows) infile.close() outfile.close() if __name__ == '__main__': main(sys.argv[1:]) Let's take this program and rewrite it to use multiprocessing to parallelize the three parts outlined above. Below is a skeleton of this new, parallelized program, that needs to be fleshed out to address the parts in the comments: #!/usr/bin/env python # -*- coding: UTF-8 -*- # multiproc_sums.py """A program that reads integer values from a CSV file and writes out their sums to another CSV file, using multiple processes if desired. """ import csv import multiprocessing import optparse import sys NUM_PROCS = multiprocessing.cpu_count() def make_cli_parser(): """Make the command line interface parser.""" usage = "\n\n".join(["python %prog INPUT_CSV OUTPUT_CSV", __doc__, """ ARGUMENTS: INPUT_CSV: an input CSV file with rows of numbers OUTPUT_CSV: an output file that will contain the sums\ """]) cli_parser = optparse.OptionParser(usage) cli_parser.add_option('-n', '--numprocs', type='int', default=NUM_PROCS, help="Number of processes to launch [DEFAULT: %default]") return cli_parser def main(argv): cli_parser = make_cli_parser() opts, args = cli_parser.parse_args(argv) if len(args) != 2: cli_parser.error("Please provide an input file and output file.") infile = open(args[0]) in_csvfile = csv.reader(infile) outfile = open(args[1], 'w') out_csvfile = csv.writer(outfile) # Parse the input file and add the parsed data to a queue for # processing, possibly chunking to decrease communication between # processes. # Process the parsed data as soon as any (chunks) appear on the # queue, using as many processes as allotted by the user # (opts.numprocs); place results on a queue for output. # # Terminate processes when the parser stops putting data in the # input queue. # Write the results to disk as soon as they appear on the output # queue. # Ensure all child processes have terminated. # Clean up files. infile.close() outfile.close() if __name__ == '__main__': main(sys.argv[1:]) These pieces of code, as well as another piece of code that can generate example CSV files for testing purposes, can be found on github. I would appreciate any insight here as to how you concurrency gurus would approach this problem. Here are some questions I had when thinking about this problem. Bonus points for addressing any/all: Should I have child processes for reading in the data and placing it into the queue, or can the main process do this without blocking until all input is read? Likewise, should I have a child process for writing the results out from the processed queue, or can the main process do this without having to wait for all the results? Should I use a processes pool for the sum operations? If yes, what method do I call on the pool to get it to start processing the results coming into the input queue, without blocking the input and output processes, too? apply_async()? map_async()? imap()? imap_unordered()? Suppose we didn't need to siphon off the input and output queues as data entered them, but could wait until all input was parsed and all results were calculated (e.g., because we know all the input and output will fit in system memory). Should we change the algorithm in any way (e.g., not run any processes concurrently with I/O)?

    Read the article

  • Solving problems involving more complex data structures with CUDA

    - by Nils
    So I read a bit about CUDA and GPU programming. I noticed a few things such that access to global memory is slow (therefore shared memory should be used) and that the execution path of threads in a warp should not diverge. I also looked at the (dense) matrix multiplication example, described in the programmers manual and the nbody problem. And the trick with the implementation seems to be the same: Arrange the calculation in a grid (which it already is in case of the matrix mul); then subdivide the grid into smaller tiles; fetch the tiles into shared memory and let the threads calculate as long as possible, until it needs to reload data from the global memory into shared memory. In case of the nbody problem the calculation for each body-body interaction is exactly the same (page 682): bodyBodyInteraction(float4 bi, float4 bj, float3 ai) It takes two bodies and an acceleration vectors. The body vector has four components it's position and the weight. When reading the paper, the calculation is understood easily. But what is if we have a more complex object, with a dynamic data structure? For now just assume that we have an object (similar to the body object presented in the paper) which has a list of other objects attached and the number of objects attached is different in each thread. How could I implement that without having the execution paths of the threads to diverge? I'm also looking for literature which explains how different algorithms involving more complex data structures can be effectively implemented in CUDA.

    Read the article

  • Problem Solving: Algorithm Required Urgently, Plz Help

    - by user616417
    Problem Solving: I've been working on something since last week. I am stuck at a point, where I want to find the minimum number of airplanes required to carry out a flight schedule given below. Plz, try out the brainstorming, i need the algorithm really badly, i'm also short of time. Thank u in advance. The Schedule---- Flight #,From,To,Departure,Arrival,Days,Via 6E 204,Agartala,Delhi,10:15:00,13:55:00,Daily,Kolkata 6E 360,Agartala,Imphal,13:50:00,14:35:00,Mo Th Sa, 6E 204,Agartala,Kolkata,10:15:00,11:00:00,Daily, 6E 360,Agartala,Kolkata,13:50:00,16:15:00,Mo Th Sa,Imphal 6E 362,Agartala,Kolkata,15:25:00,16:15:00,Tu We Fr Su, 6E 153,Ahmedabad,Bangalore,17:00:00,19:00:00,Daily, 6E 212,Ahmedabad,Chennai,9:00:00,12:55:00,Daily,Mumbai 6E 154,Ahmedabad,Delhi,12:30:00,14:00:00,Daily, 6E 211,Ahmedabad,Jaipur,19:10:00,20:20:00,Daily, 6E 410,Ahmedabad,Kolkata,15:00:00,17:30:00,Daily, 6E 212,Ahmedabad,Mumbai,9:00:00,10:10:00,Daily, 6E 409,Ahmedabad,Pune,14:25:00,15:40:00,Ex Sat, 6E 154,Bangalore,Ahmedabad,10:00:00,12:00:00,Daily, 6E 277,Bangalore,Chennai,15:35:00,16:25:00,Daily, 6E 132,Bangalore,Delhi,6:00:00,8:25:00,Daily, 6E 102,Bangalore,Delhi,9:50:00,13:45:00,Ex Sat,Pune 6E 154,Bangalore,Delhi,10:00:00,14:00:00,Daily,Ahmedabad 6E 104,Bangalore,Delhi,11:30:00,14:10:00,Sat, 6E 122,Bangalore,Delhi,17:20:00,20:00:00,Daily, 6E 108,Bangalore,Delhi,19:20:00,23:10:00,Sat,Pune 6E 106,Bangalore,Delhi,19:30:00,22:00:00,Ex Sat, 6E 275,Bangalore,Goa,12:15:00,13:15:00,Daily, 6E 351,Bangalore,Hyderabad,8:25:00,9:25:00,Daily, 6E 152,Bangalore,Hyderabad,19:10:00,20:10:00,Ex Sat, 6E 152,Bangalore,Hyderabad,19:30:00,20:35:00,Sat, 6E 152,Bangalore,Jaipur,19:10:00,22:30:00,Ex Sat,Hyderabad 6E 152,Bangalore,Jaipur,19:30:00,22:30:00,Sat,Hyderabad 6E 351,Bangalore,Kolkata,8:25:00,11:55:00,Daily,Hyderabad 6E 277,Bangalore,Kolkata,15:35:00,19:15:00,Daily,Chennai 6E 402,Bangalore,Mumbai,6:05:00,7:45:00,Daily, 6E 275,Bangalore,Mumbai,12:15:00,14:45:00,Daily,Goa 6E 414,Bangalore,Mumbai,12:45:00,14:20:00,Daily, 6E 412,Bangalore,Mumbai,21:20:00,23:20:00,Daily, 6E 102,Bangalore,Pune,9:50:00,11:10:00,Ex Sat, 6E 108,Bangalore,Pune,19:20:00,20:40:00,Sat, 6E 258,Bhubaneshwar,Delhi,18:55:00,20:55:00,Daily, 6E 257,Bhubaneshwar,Hyderabad,10:40:00,12:05:00,Daily, 6E 257,Bhubaneshwar,Mumbai,10:40:00,13:50:00,Daily,Hyderabad 6E 211,Chennai,Ahmedabad,15:10:00,18:40:00,Daily,Mumbai 6E 275,Chennai,Bangalore,10:50:00,11:40:00,Daily, 6E 302,Chennai,Delhi,11:35:00,15:20:00,Daily,Hyderabad 6E 282,Chennai,Delhi,19:45:00,22:30:00,Daily, 6E 275,Chennai,Goa,10:50:00,13:15:00,Daily,Bangalore 6E 302,Chennai,Hyderabad,11:35:00,12:40:00,Daily, 6E 211,Chennai,Jaipur,15:10:00,20:20:00,Daily,Mumbai/Ahmedabad 6E 523,Chennai,Kolkata,8:20:00,10:30:00,Daily, 6E 277,Chennai,Kolkata,16:55:00,19:15:00,Daily, 6E 211,Chennai,Mumbai,15:10:00,16:50:00,Daily, 6E 524,Chennai,Pune,21:15:00,23:00:00,Daily, 6E 273,Delhi,Agartala,6:15:00,9:45:00,Daily,Kolkata 6E 153,Delhi,Ahmedabad,14:45:00,16:30:00,Daily, 6E 101,Delhi,Bangalore,6:30:00,9:10:00,Ex Sat, 6E 103,Delhi,Bangalore,6:45:00,10:40:00,Sat,Pune 6E 121,Delhi,Bangalore,9:30:00,12:10:00,Daily, 6E 105,Delhi,Bangalore,14:20:00,18:30:00,Ex Sat,Pune 6E 153,Delhi,Bangalore,14:45:00,19:00:00,Daily,Ahmedabad 6E 107,Delhi,Bangalore,15:55:00,18:40:00,Sat, 6E 131,Delhi,Bangalore,20:45:00,23:15:00,Daily, 6E 257,Delhi,Bhubaneshwar,8:10:00,10:10:00,Daily, 6E 301,Delhi,Chennai,7:00:00,11:05:00,Daily,Hyderabad 6E 283,Delhi,Chennai,16:30:00,19:05:00,Daily, 6E 181,Delhi,Goa,9:15:00,13:35:00,Daily,Mumbai 6E 333,Delhi,Goa,11:45:00,14:15:00,Daily, 6E 201,Delhi,Guwahati,5:30:00,7:50:00,Daily, 6E 301,Delhi,Hyderabad,7:00:00,9:00:00,Daily, 6E 257,Delhi,Hyderabad,8:10:00,12:05:00,Daily,Bhubaneshwar 6E 305,Delhi,Hyderabad,14:00:00,15:55:00,Daily, 6E 307,Delhi,Hyderabad,21:00:00,22:55:00,Daily, 6E 201,Delhi,Imphal,5:30:00,9:10:00,Daily,Guwahati 6E 305,Delhi,Kochi,14:00:00,18:25:00,Daily,Hyderabad 6E 273,Delhi,Kolkata,6:15:00,8:20:00,Daily, 6E 203,Delhi,Kolkata,15:00:00,17:05:00,Daily, 6E 209,Delhi,Kolkata,18:30:00,20:45:00,Daily, 6E 183,Delhi,Mumbai,6:45:00,8:35:00,Daily, 6E 181,Delhi,Mumbai,9:15:00,11:35:00,Daily, 6E 481,Delhi,Mumbai,10:50:00,13:50:00,Daily,Vadodara 6E 189,Delhi,Mumbai,14:45:00,16:50:00,Daily, 6E 187,Delhi,Mumbai,17:50:00,19:50:00,Daily, 6E 185,Delhi,Mumbai,20:15:00,22:20:00,Daily, 6E 135,Delhi,Nagpur,8:55:00,10:40:00,Ex Sat, 6E 103,Delhi,Pune,6:45:00,8:45:00,Sat, 6E 135,Delhi,Pune,8:55:00,12:30:00,Ex Sat,Nagpur 6E 105,Delhi,Pune,14:20:00,16:30:00,Ex Sat, 6E 481,Delhi,Vadodara,10:50:00,12:20:00,Daily, 6E 277,Goa,Bangalore,14:05:00,15:00:00,Daily, 6E 277,Goa,Chennai,14:05:00,16:25:00,Daily,Bangalore 6E 334,Goa,Delhi,14:45:00,17:10:00,Daily, 6E 277,Goa,Kolkata,14:05:00,19:15:00,Daily,Bangalore/Chennai 6E 275,Goa,Mumbai,13:45:00,14:45:00,Daily, 6E 202,Guwahati,Delhi,11:00:00,13:25:00,Daily, 6E 201,Guwahati,Imphal,8:25:00,9:10:00,Daily, 6E 208,Guwahati,Jaipur,12:40:00,16:55:00,Daily,Kolkata 6E 208,Guwahati,Kolkata,12:40:00,14:00:00,Daily, 6E 322,Guwahati,Kolkata,15:30:00,16:50:00,Daily, 6E 322,Guwahati,Mumbai,15:30:00,20:20:00,Daily,Kolkata 6E 151,Hyderabad,Bangalore,8:20:00,9:20:00,Daily, 6E 352,Hyderabad,Bangalore,19:40:00,20:40:00,Daily, 6E 258,Hyderabad,Bhubaneshwar,16:40:00,18:20:00,Daily, 6E 301,Hyderabad,Chennai,9:50:00,11:05:00,Daily, 6E 308,Hyderabad,Delhi,6:10:00,8:00:00,Daily, 6E 302,Hyderabad,Delhi,13:10:00,15:20:00,Daily, 6E 258,Hyderabad,Delhi,16:40:00,20:55:00,Daily,Bhubaneshwar 6E 306,Hyderabad,Delhi,21:00:00,23:05:00,Daily, 6E 152,Hyderabad,Jaipur,20:50:00,22:30:00,Ex Sat, 6E 152,Hyderabad,Jaipur,21:10:00,22:30:00,Sat, 6E 305,Hyderabad,Kochi,16:45:00,18:25:00,Daily, 6E 351,Hyderabad,Kolkata,9:55:00,11:55:00,Daily, 6E 257,Hyderabad,Mumbai,12:35:00,13:50:00,Daily, 6E 362,Imphal,Agartala,14:15:00,14:55:00,Tu We Fr Su, 6E 202,Imphal,Delhi,9:40:00,13:25:00,Daily,Guwahati 6E 202,Imphal,Guwahati,9:40:00,10:25:00,Daily, 6E 362,Imphal,Kolkata,14:15:00,16:15:00,Tu We Fr Su,Agartala 6E 360,Imphal,Kolkata,15:05:00,16:15:00,Mo Th Sa, 6E 212,Jaipur,Ahmedabad,7:30:00,8:35:00,Daily, 6E 151,Jaipur,Bangalore,6:00:00,9:20:00,Daily,Hyderabad 6E 212,Jaipur,Chennai,7:30:00,12:55:00,Daily,Mumbai/Ahmedabad 6E 207,Jaipur,Guwahati,8:20:00,12:10:00,Daily,Kolkata 6E 151,Jaipur,Hyderabad,6:00:00,7:40:00,Daily, 6E 207,Jaipur,Kolkata,8:20:00,10:10:00,Daily, 6E 323,Jaipur,Kolkata,17:35:00,23:00:00,Daily,Mumbai 6E 212,Jaipur,Mumbai,7:30:00,10:10:00,Daily,Ahmedabad 6E 323,Jaipur,Mumbai,17:35:00,19:15:00,Daily, 6E 306,Kochi,Delhi,19:00:00,23:05:00,Daily,Hyderabad 6E 306,Kochi,Hyderabad,19:00:00,20:30:00,Daily, 6E 273,Kolkata,Agartala,8:50:00,9:45:00,Daily, 6E 360,Kolkata,Agartala,12:30:00,13:20:00,Mo Th Sa, 6E 362,Kolkata,Agartala,12:30:00,14:55:00,TuWeFrSu,Imphal 6E 409,Kolkata,Ahmedabad,11:10:00,13:50:00,Daily, 6E 275,Kolkata,Bangalore,7:30:00,11:40:00,Daily,Chennai 6E 352,Kolkata,Bangalore,16:50:00,20:40:00,Daily,Hyderabad 6E 275,Kolkata,Chennai,7:30:00,9:50:00,Daily, 6E 524,Kolkata,Chennai,18:15:00,20:25:00,Daily, 6E 210,Kolkata,Delhi,7:45:00,10:05:00,Daily, 6E 204,Kolkata,Delhi,11:40:00,13:55:00,Daily, 6E 274,Kolkata,Delhi,19:45:00,22:10:00,Daily, 6E 275,Kolkata,Goa,7:30:00,13:15:00,Daily,Chennai/Bangalore 6E 207,Kolkata,Guwahati,10:50:00,12:10:00,Daily, 6E 321,Kolkata,Guwahati,13:00:00,14:20:00,Daily, 6E 352,Kolkata,Hyderabad,16:50:00,19:00:00,Daily, 6E 362,Kolkata,Imphal,12:30:00,13:45:00,Tu We Fr Su, 6E 360,Kolkata,Imphal,12:30:00,14:35:00,MoThSa,Agartala 6E 208,Kolkata,Jaipur,14:35:00,16:55:00,Daily, 6E 320,Kolkata,Mumbai,6:00:00,8:30:00,Daily, 6E 322,Kolkata,Mumbai,17:35:00,20:20:00,Daily, 6E 404,Kolkata,Mumbai,18:35:00,21:55:00,Daily,Nagpur 6E 404,Kolkata,Nagpur,18:35:00,20:05:00,Daily, 6E 409,Kolkata,Pune,11:10:00,15:40:00,Ex Sat,Ahmedabad 6E 524,Kolkata,Pune,18:15:00,23:00:00,Daily,Chennai 6E 211,Mumbai,Ahmedabad,17:40:00,18:40:00,Daily, 6E 411,Mumbai,Bangalore,6:20:00,7:50:00,Daily, 6E 413,Mumbai,Bangalore,15:00:00,16:40:00,Daily, 6E 415,Mumbai,Bangalore,21:05:00,22:40:00,Daily, 6E 258,Mumbai,Bhubaneshwar,14:30:00,18:20:00,Daily,Hyderabad 6E 212,Mumbai,Chennai,11:00:00,12:55:00,Daily, 6E 184,Mumbai,Delhi,6:15:00,8:15:00,Daily, 6E 180,Mumbai,Delhi,8:25:00,10:35:00,Daily, 6E 482,Mumbai,Delhi,9:25:00,12:35:00,Daily,Vadodara 6E 188,Mumbai,Delhi,14:25:00,16:35:00,Daily, 6E 186,Mumbai,Delhi,17:50:00,19:55:00,Daily, 6E 182,Mumbai,Delhi,21:15:00,23:20:00,Daily, 6E 181,Mumbai,Goa,12:35:00,13:35:00,Daily, 6E 321,Mumbai,Guwahati,9:20:00,14:20:00,Daily,Kolkata 6E 258,Mumbai,Hyderabad,14:30:00,16:00:00,Daily, 6E 207,Mumbai,Jaipur,5:55:00,7:40:00,Daily, 6E 211,Mumbai,Jaipur,17:40:00,20:20:00,Daily,Ahmedabad 6E 207,Mumbai,Kolkata,5:55:00,10:10:00,Daily,Jaipur 6E 321,Mumbai,Kolkata,9:20:00,12:00:00,Daily, 6E 403,Mumbai,Kolkata,15:35:00,18:50:00,Daily,Nagpur 6E 323,Mumbai,Kolkata,20:05:00,23:00:00,Daily, 6E 403,Mumbai,Nagpur,15:35:00,16:50:00,Daily, 6E 482,Mumbai,Vadodara,9:25:00,10:25:00,Daily, 6E 136,Nagpur,Delhi,18:10:00,19:40:00,Ex Sat, 6E 403,Nagpur,Kolkata,17:20:00,18:50:00,Daily, 6E 404,Nagpur,Mumbai,20:35:00,21:55:00,Daily, 6E 135,Nagpur,Pune,11:20:00,12:30:00,Ex Sat, 6E 410,Pune,Ahmedabad,13:10:00,14:30:00,Ex Sat, 6E 103,Pune,Bangalore,9:15:00,10:40:00,Sat, 6E 105,Pune,Bangalore,17:00:00,18:30:00,Ex Sat, 6E 523,Pune,Chennai,5:55:00,7:40:00,Daily, 6E 102,Pune,Delhi,11:45:00,13:45:00,Ex Sat, 6E 136,Pune,Delhi,16:15:00,19:40:00,Ex Sat,Nagpur 6E 108,Pune,Delhi,21:10:00,23:10:00,Sat, 6E 523,Pune,Kolkata,5:55:00,10:30:00,Daily,Chennai 6E 410,Pune,Kolkata,13:10:00,17:30:00,Ex Sat,Ahmedabad 6E 136,Pune,Nagpur,16:15:00,17:40:00,Ex Sat, 6E 482,Vadodara,Delhi,10:55:00,12:35:00,Daily, 6E 481,Vadodara,Mumbai,12:50:00,13:50:00,Daily,

    Read the article

  • JAVA - Strange problem (probably thread problem) with JTable & Model

    - by Stefanos Kargas
    I am using 2 Tables (JTable) with their DefaultTableModels. The first table is already populated. The second table is populated for each row of the first table (using an SQL Query). My purpose is to export every line of the first table with it's respective lines of the second in an Excel File. I am doing it with a for (for each line of 1st table), in which I write a line of the 1st table in the Excel File, then I populate the 2nd table (for this line of 1st Table), I get every line from the Table (from it's Model actually) and put it in the Excel File under the current line of 1st table. This means that if I have n lines in first table I will clear and populate again the second table n times. All this code is called in a seperate thread. THE PROBLEM IS: Everything works perfectly fine ecxept that I am getting some exceptions. The strange thing is that I'm not getting anything false in my result. The Excel file is perfect. Some of the lines of the exceptions are: Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 0 = 0 at java.util.Vector.elementAt(Vector.java:427) at javax.swing.table.DefaultTableModel.getValueAt(DefaultTableModel.java:632) at javax.swing.JComponent.paint(JComponent.java:1017) at javax.swing.RepaintManager.paint(RepaintManager.java:1220) at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:803) I am assuming that the problem lies in the fact that the second table needs some more time to be populated before I try to get any data from it. That's why I see RepaintManager and paintDirtyRegions in my exceptions. Another thing I did is that I ran my program in debug mode and I put a breakpoint after each population of the 2nd table. Then I pressed F5 to continue for each population of 2nd table and no exception appeared. The program came to it's end without any exceptions. This is another important fact that tells me that maybe in this case I gave the table enough time to be populated. Of course you will ask me: If your program works fine, why do you care about the exceptions? I care for avoiding any future problems and I care to have a better understanding of Java and Java GUI and threads. Why do you depend on a GUI component (and it's model) to get your information and why don't you recreate the resultset that populates your tables using an SQL Query and get your info from the resultset? That would be the best and the right way. The fact is that I have the tables code ready and it was easier for me to just get the info from them. But the right way would be to get everything direct from database. Anyway what I did brought out my question, and answering it would help me understand more things about java. So I posted it.

    Read the article

  • Solving simultaneous equations

    - by Milo
    Here is my problem: Given x, y, z and ratio where z is known and ratio is known and is a float representing a relative value, I need to find x and y. I know that: x / y == ratio y - x == z What I'm trying to do is make my own scroll pane and I'm figuring out the scrollbar parameters. So for example, If the scrollbar must be able to scroll 100 values (z) and the thumb must consume 80% of the bar (ratio = 0.8) then x would be 400 and y would be 500. Thanks

    Read the article

  • What's the best way to learn/increase problem-solving skills?

    - by tucaz
    Hi all! I'm not sure this is the right place to ask this question, neither if this is the right way to ask this question but I hope you help me if it is not. I work as a programmer since I was 15 (will be 24 next week) so learning programming logic was somehow natural during the course of my career and I think that it helped me to get pretty good problem-solving. One thing none of us (programmers) can deny is that programming logic helps us in a lot of fields outside computer programming. So I'd say it is a very valuable resource that one should learn. My girlfriend is not a programmer and graduated in college on a non related course (Foreign Relations) because she didn't know what to study back then. As the years passed she discovered that she liked Logistics and started to work with it almost two years ago. However, since she does not have a technical background (not even basic Math) she is really having a hard time with it. She is already trying to catch up with Math, but even simple questions/brain-teasers are hard to her. For example, trying to find the missing numbers of this sequence: 0, 1, 1, 2, 3, 5, 8, _, _, 34 and so on. We know that this is Fibonacci but if we didn't we would probably be able to get to the correct answer just by "guessing" (using our acquired problem-solving skills). I'm not sure if problem-solving skills or logic are the correct name for it, but this is what I mean: quick solve problems, brain-teasers, find patterns, have a "sharp" mind. So, the question is: what is the best way for someone to learn this kind of skills without being a programmer (or studying algorithms and such)? If you say it is a book, could you please recommend one? Thanks a lot!

    Read the article

  • ASP.NET/VB.NET problem solving help!

    - by Jonesy
    Hi folks, Got a problem I need help with. Basically I'm gonna develop a form (part of a bigger web app) that lists a load of clients and there business contact, tech contact 1, and tech contact 2. The idea is rapid data entry. So one form shows each client with their contacts in dropdowns and I we can change each one then click a save button to do a mass save. the database looks like this: tblClient ClientID ClientName BusinessContact Tech1 Tech2 My idea was to use a repeater to format the data like this: Client Business Contact Tech1 Tech2 Client2 Business Contact Tech1 Tech2 What I'm stuck on is how to do the mass update? Can I do something like for each item in Repeater1 then do an update SQL statement? -- Jonesy

    Read the article

  • div width problem...problem is cross browser

    - by Aakash Sahai
    hello ol. I have a div having two buttons inside it as |Add| and |Cancel|. I didnt set any width to that div intially and as a result they were displayed vertically not in horizontal.then i add width in % to 11.5%.now the display is ok in moz but not in chrome and ie.i cant use pixels neither in height nor width.problem explanied by example |_______| // a textbox |Add| //initially with no width |Cancel| //after width to 11.5% in moz |_______| |Add| |Cancel| //after width to 11.5% in chrome and ie |_______| |Add| |Cancel| so u can see that in moz it is aligned to the above textbox but not in ie and chrome.hope sum ie hack or chrome hack may lead to correct result..or ONLY a MOZ hack..

    Read the article

  • struts datagrid problem - can't solve this problem

    - by shien-angel
    i am creating datagrid using the struts-layout. and i encountered this problem javax.servlet.ServletException: DispatchMapping[/monitor/datagridBL]???????????????????? at org.apache.struts.actions.DispatchAction.getParameter(DispatchAction.java:325) at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:170) at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236) at jp.terasoluna.fw.web.struts.action.RequestProcessorEx.process(RequestProcessorEx.java:149) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196) at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414) at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227) at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125) at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292) at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56) at jp.co.anicom.fw.web.common.controller.RequestEncodeFilter.doFilter(RequestEncodeFilter.java:42) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56) at jp.co.anicom.fw.web.common.controller.SessionExpirationFilter.doFilter(SessionExpirationFilter.java:89) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56) at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3588) at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321) at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121) at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2200) at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2106) at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1428) at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201) at weblogic.work.ExecuteThread.run(ExecuteThread.java:173) i have been looking for ways on how to solve this. would somebody help me please...

    Read the article

  • Problems solving oddly acting labels in ie7.

    - by Qwibble
    Okay so this is sort of a double question so I'll split it into two. First part In modern browsers the main bold labels sit above their corresponding form elements, and align to the left as is expected. However in ie7, they randomly site 10-15px inset. I went through the developer tools and could find nothing to fix it. I've made sure all my margins and padding is reset so I don't really understand =S Here's the page demo - link Maybe some of you ie bug fixing genius's know what the problem is? =D Second part Again with labels, this time the in-line ones resident next to the check boxes and radio buttons. In modern browsers again, the side beside the form elements as expected, but not so in ie7 where they take a new line. I've tried floating, changing margins and everything but to no effect in sitting it in-line with the div.checker or div.radio that is created by the uniform Jquery plugin. Here's the page demo - link Sorry for troubling you with my ie7 problems, I know they arent the most fun to solve. Hopefully someone has the patience to help. Matt

    Read the article

  • Solving for the coefficent of linear equations with one known coefficent

    - by CppLearner
    clc; clear all; syms y a2 a3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % [ 0.5 0.25 0.125 ] [ a2 ] [ y ] % [ 1 1 1 ] [ a3 ] = [ 3 ] % [ 2 4 8 ] [ 6 ] [ 2 ] %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% M = [0.5 0.25 0.125; 1 1 1; 2 4 8]; t = [a2 a3 6]; r = [y 3 2]; sol = M * t' s1 = solve(sol(1), a2) % solve for a2 s2 = solve(sol(2), a3) % solve for a3 This is what I have so far. These are my output sol = conj(a2)/2 + conj(a3)/4 + 3/4 conj(a2) + conj(a3) + 6 2*conj(a2) + 4*conj(a3) + 48 s1 = - conj(a3)/2 - 3/2 - Im(a3)*i s2 = - conj(a2) - 6 - 2*Im(a2)*i sol looks like what we would have if we put them back into equation form: 0.5 * a2 + 0.25 * a3 + 0.125 * a4 a2 + a3 + a4 = 3 2*a2 + 4*a3 + 8*a4 = 2 where a4 is known == 6. My problem is, I am stuck with how to use solve to actually solve these equations to get the values of a2 and a3. s2 solve for a3 but it doesn't match what we have on paper (not quite). a2 + a3 + 6 = 3 should yield a3 = -3 - a2. because of the imaginary. Somehow I need to equate the vector solution sol to the values [y 3 2] for each row.

    Read the article

  • GridView edit problem If primary key is editable (design problem)

    - by Nassign
    I would like to ask about the design of table based on it's editability in a Grid View. Let me explain. For example, I have a table named ProductCustomerRel. Method 1 CustomerCode varchar PK ProductCode varchar PK StoreCode varchar PK Quantity int Note text So the combination of the CustomerCode, StoreCode and ProductCode must be unique. The record is displayed on a gridview. The requirement is that you can edit the customer, product and storecode but when the data is saved, the PK constraint must still persist. The problem here is it would be natural for a grid to be able to edit the 3 primary key, you can only achieve the update operation of the grid view by first deleting the row and then inserting the row with the updated data. An alternative to this is to just update the table and add a SeqNo, and just enforce the unique constraint of the 3 columns when inserting and updating in the grid view. Method 2 SeqNo int PK CustomerCode varchar ProductCode varchar StoreCode varchar Quantity int Note text My question is which of the two method is better? or is there another way to do this?

    Read the article

  • Solving a difficult incomplete type error

    - by ChAoS
    I get an incomplete type error when trying to compile my code. I know that it is related to includes, but my project is large and it uses several templates so I can't find which type is actually incomplete. The error message doesn't help either: Compiling: ../../../addons/ofxTableGestures/src/Graphics/objects/CursorFeedback.cpp In file included from ../../../addons/ofxTableGestures/ext/boost/fusion/include/invoke_procedure.hpp:10, from ../../../addons/ofxTableGestures/src/oscGestures/tuioApp.hpp:46, from /home/thechaos/Projectes/of_preRelease_v0061_linux_FAT/addons/../apps/OF-TangibleFramework/ofxTableGestures/src/Graphics/objects/CursorFeedback.hpp:35, from /home/thechaos/Projectes/of_preRelease_v0061_linux_FAT/addons/../apps/OF-TangibleFramework/ofxTableGestures/src/Graphics/objects/CursorFeedback.cpp:31: ../../../addons/ofxTableGestures/ext/boost/fusion/functional/invocation/invoke_procedure.hpp: In function ‘void boost::fusion::invoke_procedure(Function, const Sequence&) [with Function = void (tuio::CanBasicFingers<Graphic>::*)(long int, float, float, float, float, float), Sequence = boost::fusion::joint_view<boost::fusion::joint_view<boost::fusion::iterator_range<boost::fusion::vector_iterator<const boost::fusion::vector6<long int, float, float, float, float, float>, 0>, boost::fusion::vector_iterator<boost::fusion::vector6<long int, float, float, float, float, float>, 0> >, const boost::fusion::single_view<tuio::CanBasicFingers<Graphic>*> >, boost::fusion::iterator_range<boost::fusion::vector_iterator<boost::fusion::vector6<long int, float, float, float, float, float>, 0>, boost::fusion::vector_iterator<const boost::fusion::vector6<long int, float, float, float, float, float>, 6> > >]’: ../../../addons/ofxTableGestures/src/oscGestures/tuioApp.hpp:122: instantiated from ‘void tuio::AlternateCallback<C, M, E>::run(tuio::TEvent*) [with C = tuio::CanBasicFingers<Graphic>, M = void (tuio::CanBasicFingers<Graphic>::*)(long int, float, float, float, float, float), E = tuio::TeventBasicFingersMoveFinger]’ /home/thechaos/Projectes/of_preRelease_v0061_linux_FAT/addons/../apps/OF-TangibleFramework/ofxTableGestures/src/Graphics/objects/CursorFeedback.cpp:64: instantiated from here ../../../addons/ofxTableGestures/ext/boost/fusion/functional/invocation/invoke_procedure.hpp:88: error: incomplete type ‘boost::fusion::detail::invoke_procedure_impl<void (tuio::CanBasicFingers<Graphic>::*)(long int, float, float, float, float, float), const boost::fusion::joint_view<boost::fusion::joint_view<boost::fusion::iterator_range<boost::fusion::vector_iterator<const boost::fusion::vector6<long int, float, float, float, float, float>, 0>, boost::fusion::vector_iterator<boost::fusion::vector6<long int, float, float, float, float, float>, 0> >, const boost::fusion::single_view<tuio::CanBasicFingers<Graphic>*> >, boost::fusion::iterator_range<boost::fusion::vector_iterator<boost::fusion::vector6<long int, float, float, float, float, float>, 0>, boost::fusion::vector_iterator<const boost::fusion::vector6<long int, float, float, float, float, float>, 6> > >, 7, true, false>’ used in nested name specifier If I copy the conflictive code to a same file I can compile it. So I know that the code itself is OK, the problem is the way I instantiate it. How can I trace the origin of this error? Is there any way to get the trace of the c++ compiler and preprocessor to get more informative messages?

    Read the article

  • Solving the NP-complete problem in XKCD

    - by Adam Tuttle
    The problem/comic in question: http://xkcd.com/287/ I'm not sure this is the best way to do it, but here's what I've come up with so far. I'm using CFML, but it should be readable by anyone. <cffunction name="testCombo" returntype="boolean"> <cfargument name="currentCombo" type="string" required="true" /> <cfargument name="currentTotal" type="numeric" required="true" /> <cfargument name="apps" type="array" required="true" /> <cfset var a = 0 /> <cfset var found = false /> <cfloop from="1" to="#arrayLen(arguments.apps)#" index="a"> <cfset arguments.currentCombo = listAppend(arguments.currentCombo, arguments.apps[a].name) /> <cfset arguments.currentTotal = arguments.currentTotal + arguments.apps[a].cost /> <cfif arguments.currentTotal eq 15.05> <!--- print current combo ---> <cfoutput><strong>#arguments.currentCombo# = 15.05</strong></cfoutput><br /> <cfreturn true /> <cfelseif arguments.currentTotal gt 15.05> <cfoutput>#arguments.currentCombo# > 15.05 (aborting)</cfoutput><br /> <cfreturn false /> <cfelse> <!--- less than 15.05 ---> <cfoutput>#arguments.currentCombo# < 15.05 (traversing)</cfoutput><br /> <cfset found = testCombo(arguments.currentCombo, arguments.currentTotal, arguments.apps) /> </cfif> </cfloop> </cffunction> <cfset mf = {name="Mixed Fruit", cost=2.15} /> <cfset ff = {name="French Fries", cost=2.75} /> <cfset ss = {name="side salad", cost=3.35} /> <cfset hw = {name="hot wings", cost=3.55} /> <cfset ms = {name="moz sticks", cost=4.20} /> <cfset sp = {name="sampler plate", cost=5.80} /> <cfset apps = [ mf, ff, ss, hw, ms, sp ] /> <cfloop from="1" to="6" index="b"> <cfoutput>#testCombo(apps[b].name, apps[b].cost, apps)#</cfoutput> </cfloop> The above code tells me that the only combination that adds up to $15.05 is 7 orders of Mixed Fruit, and it takes 232 executions of my testCombo function to complete. Is there a better algorithm to come to the correct solution? Did I come to the correct solution?

    Read the article

  • Rush Hour - Solving the game

    - by Rubys
    Rush Hour if you're not familiar with it, the game consists of a collection of cars of varying sizes, set either horizontally or vertically, on a NxM grid that has a single exit. Each car can move forward/backward in the directions it's set in, as long as another car is not blocking it. You can never change the direction of a car. There is one special car, usually it's the red one. It's set in the same row that the exit is in, and the objective of the game is to find a series of moves (a move - moving a car N steps back or forward) that will allow the red car to drive out of the maze. I've been trying to think how to solve this problem computationally, and I can really not think of any good solution. I came up with a few: Backtracking. This is pretty simple - Recursion and some more recursion until you find the answer. However, each car can be moved a few different ways, and in each game state a few cars can be moved, and the resulting game tree will be HUGE. Some sort of constraint algorithm that will take into account what needs to be moved, and work recursively somehow. This is a very rough idea, but it is an idea. Graphs? Model the game states as a graph and apply some sort of variation on a coloring algorithm, to resolve dependencies? Again, this is a very rough idea. A friend suggested genetic algorithms. This is sort of possible but not easily. I can't think of a good way to make an evaluation function, and without that we've got nothing. So the question is - How to create a program that takes a grid and the vehicle layout, and outputs a series of steps needed to get the red car out? Sub-issues: Finding some solution. Finding an optimal solution (minimal number of moves) Evaluating how good a current state is Example: How can you move the cars in this setting, so that the red car can "exit" the maze through the exit on the right?

    Read the article

  • Blocking problem, C#, .net, Deserializing XML to object problem

    - by fernando
    Hi I have a blocking problem I have XML file under some url http://myserver/mywebApp/myXML.xml In the below code which I run in Console Application, bookcollection has null Books field :( <books> <book id="5352"> <date>1986-05-05</date> <title> Alice in chains </title> </book> <book id="4334"> <date>1986-05-05</date> <title> 1000 ways to heaven </title> </book> <book id="1111"> <date>1986-05-05</date> <title> Kitchen and me </title> </book> </books> XmlDocument doc = new XmlDocument(); doc.Load("http://myserver/mywebapp/myXML.xml"); BookCollection books = new BookCollection(); XmlNodeReader reader2 = new XmlNodeReader(doc.DocumentElement); XmlSerializer ser2 = new XmlSerializer(books.GetType()); object obj = ser2.Deserialize(reader2); BookCollection books2= (BookCollection)obj; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { [Serializable()] public class Book { [System.Xml.Serialization.XmlAttribute("id")] public string id { get; set; } [System.Xml.Serialization.XmlElement("date")] public string date { get; set; } [System.Xml.Serialization.XmlElement("title")] public string title { get; set; } } } using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml.Serialization; namespace ConsoleApplication1 { [Serializable()] [System.Xml.Serialization.XmlRootAttribute("books", Namespace = "", IsNullable = false)] public class BookCollection { [XmlArray("books")] [XmlArrayItem("book", typeof(Book))] public Book[] Books { get; set; } } }

    Read the article

  • Blocking problem Deserializing XML to object problem

    - by fernando
    I have a blocking problem I have XML file under some url http://myserver/mywebApp/myXML.xml In the below code which I run in Console Application, bookcollection has null Books field :( <books> <book id="5352"> <date>1986-05-05</date> <title> Alice in chains </title> </book> <book id="4334"> <date>1986-05-05</date> <title> 1000 ways to heaven </title> </book> <book id="1111"> <date>1986-05-05</date> <title> Kitchen and me </title> </book> </books> XmlDocument doc = new XmlDocument(); doc.Load("http://myserver/mywebapp/myXML.xml"); BookCollection books = new BookCollection(); XmlNodeReader reader2 = new XmlNodeReader(doc.DocumentElement); XmlSerializer ser2 = new XmlSerializer(books.GetType()); object obj = ser2.Deserialize(reader2); BookCollection books2= (BookCollection)obj; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { [Serializable()] public class Book { [System.Xml.Serialization.XmlAttribute("id")] public string id { get; set; } [System.Xml.Serialization.XmlElement("date")] public string date { get; set; } [System.Xml.Serialization.XmlElement("title")] public string title { get; set; } } } using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml.Serialization; namespace ConsoleApplication1 { [Serializable()] [System.Xml.Serialization.XmlRootAttribute("books", Namespace = "", IsNullable = false)] public class BookCollection { [XmlArray("books")] [XmlArrayItem("book", typeof(Book))] public Book[] Books { get; set; } } }

    Read the article

  • Solving Combinatory Problems with LINQ /.NET4

    - by slf
    I saw this article pop-up in my MSDN RSS feed, and after reading through it, and the sourced article here I began to wonder about the solution. The rules are simple: Find a number consisting of 9 digits in which each of the digits from 1 to 9 appears only once. This number must also satisfy these divisibility requirements: The number should be divisible by 9. If the rightmost digit is removed, the remaining number should be divisible by 8. If the rightmost digit of the new number is removed, the remaining number should be divisible by 7. And so on, until there's only one digit (which will necessarily be divisible by 1). This is his proposed monster LINQ query: // C# and LINQ solution to the numeric problem presented in: // http://software.intel.com/en-us/blogs/2009/12/07/intel-parallel-studio-great-for-serial-code-too-episode-1/ int[] oneToNine = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; // the query var query = from i1 in oneToNine from i2 in oneToNine where i2 != i1 && (i1 * 10 + i2) % 2 == 0 from i3 in oneToNine where i3 != i2 && i3 != i1 && (i1 * 100 + i2 * 10 + i3) % 3 == 0 from i4 in oneToNine where i4 != i3 && i4 != i2 && i4 != i1 && (i1 * 1000 + i2 * 100 + i3 * 10 + i4) % 4 == 0 from i5 in oneToNine where i5 != i4 && i5 != i3 && i5 != i2 && i5 != i1 && (i1 * 10000 + i2 * 1000 + i3 * 100 + i4 * 10 + i5) % 5 == 0 from i6 in oneToNine where i6 != i5 && i6 != i4 && i6 != i3 && i6 != i2 && i6 != i1 && (i1 * 100000 + i2 * 10000 + i3 * 1000 + i4 * 100 + i5 * 10 + i6) % 6 == 0 from i7 in oneToNine where i7 != i6 && i7 != i5 && i7 != i4 && i7 != i3 && i7 != i2 && i7 != i1 && (i1 * 1000000 + i2 * 100000 + i3 * 10000 + i4 * 1000 + i5 * 100 + i6 * 10 + i7) % 7 == 0 from i8 in oneToNine where i8 != i7 && i8 != i6 && i8 != i5 && i8 != i4 && i8 != i3 && i8 != i2 && i8 != i1 && (i1 * 10000000 + i2 * 1000000 + i3 * 100000 + i4 * 10000 + i5 * 1000 + i6 * 100 + i7 * 10 + i8) % 8 == 0 from i9 in oneToNine where i9 != i8 && i9 != i7 && i9 != i6 && i9 != i5 && i9 != i4 && i9 != i3 && i9 != i2 && i9 != i1 let number = i1 * 100000000 + i2 * 10000000 + i3 * 1000000 + i4 * 100000 + i5 * 10000 + i6 * 1000 + i7 * 100 + i8 * 10 + i9 * 1 where number % 9 == 0 select number; // run it! foreach (int n in query) Console.WriteLine(n); Octavio states "Note that no attempt at all has been made to optimize the code", what I'd like to know is what if we DID attempt to optimize this code. Is this really the best this code can get? I'd like to know how we can do this best with .NET4, in particular doing as much in parallel as we possibly can. I'm not necessarily looking for an answer in pure LINQ, assume .NET4 in any form (managed c++, c#, etc all acceptable).

    Read the article

  • Solving the EXC_BAD_ACCESS in WhatATool Part 2

    - by Allen
    #import <Cocoa/Cocoa.h> @interface PolygonShape : NSObject { int numberOfSides, maximumNumberOfSides, minimumNumberOfSides; } @property (readwrite) int numberOfSides, maximumNumberOfSides, minimumNumberOfSides; @property (readonly) float angleInDegrees, angleInRadians; @property (readonly) NSString * name; @property (readonly) NSString * description; -(id) init; -(void) setNumberOfSides:(int)sides; -(void) setMinimumNumberOfSides:(int)min; -(void) setMaximumNumberOfSides:(int)max; -(float) angleInDegrees; -(float) angleInRadians; -(NSString *) name; -(id) initWithNumberOfSides:(int) sides minimumNumberOfSides:(int) min maximumNumberOfSides:(int) max; -(NSString *) description; -(void) dealloc; @end #import "PolygonShape.h" @implementation PolygonShape -(id) init { return [self initWithNumberOfSides:4 minimumNumberOfSides:3 maximumNumberOfSides:5]; } @synthesize numberOfSides, minimumNumberOfSides, maximumNumberOfSides, angleInRadians; -(void) setNumberOfSides:(int)sides { numberOfSides = sides; NSLog(@"The number of sides is off limit so the number of sides is %@.",sides); } -(void)setMaximumNumberOfSides:(int)max { if (maximumNumberOfSides <= 12) { maximumNumberOfSides = max; } } -(void)setMinimumNumberOfSides: (int)min { if (minimumNumberOfSides > 2) { minimumNumberOfSides = min; } } - (id)initWithNumberOfSides:(int)sides minimumNumberOfSides:(int)min maximumNumberOfSides:(int)max { if(self=[super init]) { [self setNumberOfSides:(int)sides]; [self setMaximumNumberOfSides:(int)max]; [self setMinimumNumberOfSides: (int)min]; } return self; } -(float) angleInDegrees { float anglesInDegrees = (180 * (numberOfSides - 2) / numberOfSides); return anglesInDegrees; } -(float)angleInRadiants { float anglesInRadiants = ((180 * (numberOfSides - 2) / numberOfSides) * (180 / M_PI)); return anglesInRadiants; } -(NSString *)name { NSString * output; switch (numberOfSides) { case 3: output = @"Triangle"; break; case 4: output = @"Square"; break; case 5: output = @"Pentagon"; break; case 6: output = @"Hexagon"; break; case 7: output = @"Heptagon"; break; case 8: output = @"Octagon"; break; case 9: output = @"Nonagon"; break; case 10: output = @"Decagon"; break; case 11: output = @"Hendecagon"; break; case 12: output = @"Dodecabgon"; break; default: output = @"Invalid number of sides: %i is greater than maximum of five allowed."; } return output; } -(NSString *)description { NSString * output; NSLog(@"Hello I am a %i-sided polygon (aka a %@) with angles of %f degrees (%f radians).", numberOfSides, output, [self angleInDegrees], [self angleInRadiants]); return [self description]; } -(void)dealloc { [super dealloc]; } @end #import <Foundation/Foundation.h> #import "PolygonShape.h" void PrintPathInfo() { NSLog(@"Section 1"); NSLog(@"--------------------"); NSString *path = [@"~" stringByExpandingTildeInPath]; NSLog(@"My home folder is at '%@'.", path); NSArray *pathComponent = [path pathComponents]; for (path in pathComponent) { NSLog(@"%@",path); } NSLog(@"--------------------"); NSLog(@"\n"); } void PrintProcessInfo() { NSLog(@"Section 2"); NSLog(@"--------------------"); NSString * processName = [[NSProcessInfo processInfo] processName]; int processIdentifier = [[NSProcessInfo processInfo] processIdentifier]; NSLog(@"Process Name: '%@', Process ID: '%i'", processName, processIdentifier); NSLog(@"--------------------"); NSLog(@"\n"); } void PrintBookmarkInfo() { NSLog(@"Section 3"); NSLog(@"--------------------"); NSArray * keys = [NSArray arrayWithObjects: @"Stanford University", @"Apple", @"CS193P", @"Stanford on iTunes U", @"Stanford Mall", nil]; NSArray * objects = [NSArray arrayWithObjects: [NSURL URLWithString: @"http://www.stanford.edu"], @"http://www.apple.com", @"http://cs193p.stanford.edu", @"http://itunes.stanford.edu", @"http://stanfordshop.com",nil]; NSMutableDictionary * dictionary = [NSMutableDictionary dictionaryWithObjects:objects forKeys:keys]; NSEnumerator * enumerator = [keys objectEnumerator]; for (id keys in dictionary) { NSLog(@"key: '%@', value: '%@'", keys, [dictionary objectForKey:keys]); } NSLog(@" "); NSLog(@"These are the ones that has the prefix 'Stanford'."); NSLog(@" "); id object; while (object = [enumerator nextObject]) { if ([object hasPrefix: @"Stanford"]) { NSLog(@"key: '%@', value: '%@'", object, [dictionary objectForKey:object]); } } NSLog(@"--------------------"); NSLog(@"\n"); } void PrintIntrospectionInfo() { NSLog(@"Section 4"); NSLog(@"--------------------"); SEL lowercase = @selector (lowercaseString); NSMutableArray * array = [NSMutableArray array]; [array addObject: [NSString stringWithString: @"Here is a string"]]; [array addObject: [NSDictionary dictionary]]; [array addObject: [NSURL URLWithString: @"http://www.stanford.edu"]]; [array addObject: [[NSProcessInfo processInfo]processName]]; for (id keys in array) { NSLog(@"\n"); NSLog(@"Class Name: %@", [keys className]); NSLog(@"Is Member of NSString: %@", [keys isMemberOfClass:[NSString class]]?@"Yes":@"No"); NSLog(@"Is Kind of NSString: %@", [keys isKindOfClass:[NSString class]]?@"Yes":@"No"); if ([keys respondsToSelector: lowercase]==YES) { NSLog(@"Responds to lowercaseString: %@",[keys respondsToSelector: lowercase]?@"Yes":@"No"); NSLog(@"lowercaseString is: %@", [keys performSelector: lowercase]); } else { NSLog(@"Responds to lowercaseString: %@",[keys respondsToSelector: lowercase]?@"Yes":@"No" ); } } NSLog(@"--------------------"); } void PrintPolygonInfo() { NSMutableArray * array = [NSMutableArray array]; PolygonShape * polygon1 = [[PolygonShape alloc]initWithNumberOfSides:4 minimumNumberOfSides:3 maximumNumberOfSides:7]; [array addObject:polygon1]; [array description]; PolygonShape * polygon2 = [[PolygonShape alloc]initWithNumberOfSides:6 minimumNumberOfSides:5 maximumNumberOfSides:9]; [array addObject:polygon2]; [array description]; PolygonShape * polygon3 = [[PolygonShape alloc]initWithNumberOfSides:12 minimumNumberOfSides:9 maximumNumberOfSides:12]; [array addObject:polygon3]; [array description]; [array release]; [polygon1 release]; [polygon2 release]; [polygon3 release]; } int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; PrintPathInfo(); PrintProcessInfo(); PrintBookmarkInfo(); PrintIntrospectionInfo(); PrintPolygonInfo(); [pool release]; return 0; } //The result was "EXC_BAD_ACCESS", but I couldn't figure out how to resolve this problem.

    Read the article

  • Solving Diophantine Equations Using Python

    - by HARSHITH
    In mathematics, a Diophantine equation (named for Diophantus of Alexandria, a third century Greek mathematician) is a polynomial equation where the variables can only take on integer values. Although you may not realize it, you have seen Diophantine equations before: one of the most famous Diophantine equations is: We are not certain that McDonald's knows about Diophantine equations (actually we doubt that they do), but they use them! McDonald's sells Chicken McNuggets in packages of 6, 9 or 20 McNuggets. Thus, it is possible, for example, to buy exactly 15 McNuggets (with one package of 6 and a second package of 9), but it is not possible to buy exactly 16 nuggets, since no non- negative integer combination of 6's, 9's and 20's adds up to 16. To determine if it is possible to buy exactly n McNuggets, one has to solve a Diophantine equation: find non-negative integer values of a, b, and c, such that 6a + 9b + 20c = n. Write an iterative program that finds the largest number of McNuggets that cannot be bought in exact quantity. Your program should print the answer in the following format (where the correct number is provided in place of n): "Largest number of McNuggets that cannot be bought in exact quantity: n"

    Read the article

< Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >