Help solving a programming challenge optimally Ask Programming |
- Help solving a programming challenge optimally
- I think im close
- How can a open-source project get monetized ?
- Model for concurrent IO in a multiprocess setting
- C# - stream "freezes" while reading despite data available
- Can you work remotely from another country entirely?
Help solving a programming challenge optimally Posted: 02 Sep 2018 03:45 PM PDT Here is the problem: You are given an array of digits 0-9 and an integer n. The array may contain duplicates of any given digit. Find all the integers which can be formed by contatenating digits from the input array and are less than n. Digits from the input array can be repeated in an element in the output. For example, given as inputs [2, 5, 8] and n = 223, then the following should be the output: [2, 5, 8, 22, 25, 28, 52, 55, 58, 82, 85, 88, 222] Obviously any integer with fewer digits than n would be accepted and any with more denied. But how to most efficiently find those with the same number of digits?A solution I know of would be to have nested for loops, one for each digit in the input integer, and form every possible combination of digits from the input array and check it against n. This seems clunky though and I'm wondering if there's a better way. [link] [comments] |
Posted: 02 Sep 2018 08:41 PM PDT So this is my program and this is what it is supposed to do " so that if the search key is in the array, it returns the largest index i for which a[i] is equal to key, but, otherwise, returns –i where i is the largest index such that a[i] is less than key. It should also be modified to deal with integer arrays rather than string arrays. Note: The program should take two command-line arguments, (1) an input file that contains a sorted integer array; and (2) an integer to search for in that array." My program works. But I have specified the array size of arr to 11, because I know that is how many integers there are. If I wanted this to work with any text file that was of a random amount of integers, how would I go about doing that? import java.util.Scanner; import java.io.File; import java.io.IOException; public class BinarySearch { public static int binarysearch(int[] arr, int key) { int lo = 0, hi = arr.length - 1; { while (lo < hi) { int mid = (lo + hi) / 2; if (arr[mid] <= key) lo = mid + 1; if (arr[mid] > key) hi = mid; } if (arr[lo] == key) { return lo; } else if ((arr[lo] != key) && (arr[lo-1] == key)){ return lo - 1; } else{ return (binarysearch( arr,(key-1))* - 1); } } } public static void main(String[] args) throws IOException{ int k = Integer.parseInt(args[1]); Scanner scanner = new Scanner(new File(args[0])); int[] arr = new int[11]; int i = 0; while(scanner.hasNextInt()){ arr[i++] = scanner.nextInt();} scanner.close(); System.out.println(binarysearch(arr, k)); ; } } [link] [comments] |
How can a open-source project get monetized ? Posted: 02 Sep 2018 02:49 AM PDT I would like to create an open source project that would be possible for me to work 24/7 on it but for that i need to get profits from it (and to leave my job). I read this nice article about Evan You (creator of Vuejs) and i found interesting the way how open-project can get fundings by platforms like patreon. But im still not understanding so well how the monetization strategy's work... can someone give me some explanation in depth? And other suggestions of monetization strategies to get funds? [link] [comments] |
Model for concurrent IO in a multiprocess setting Posted: 02 Sep 2018 12:06 PM PDT I've run into a pattern which I'm not quite sure how to solve. Let's say I have a function which creates a database table if it doesn't exist. This call is idempotent and can be run safely multiple times. In a single process multithreaded setting, you can use channels and locks to prevent two threads from calling the function simultaneously, preventing two threads trying to create the same table. But if you've got multiple processes running, there is no real way for them to communicate directly. I could use memcached or another cache layer to lock during the call. Using the memcached add will allow only one process to hold the lock at a time. Is this concurrency safe? Is this the right way to solve this? Database schema is just one example In a really IO heavy situation, you could be taking and releasing the lock in rapid succession. Does memcached scale decently for this? The other option I thought of was to add a retry loop to the idempotent function. If it raises an error, call it again. If the resource was created by another process, it will return immediately. If the resource was not created, it will create it. If the loop reaches its bound, an error is raised. Is this a bad way to solve it? It's definitely simpler and requires no coordination between processes. Edit: to clarify, processes may be on completely different hosts. [link] [comments] |
C# - stream "freezes" while reading despite data available Posted: 02 Sep 2018 04:19 AM PDT Hi, I'm working on a C# application that communicates with the clangd language server. clangd is started as a separate process managed by my C# program and communication works via I/O redirection. My program is exchanging language server protocol request-response pairs with clangd. Requests are sent to clangd via its process' StandardInput stream and responses are read using its process' StandardOutput stream. clangd emits debug information using its process' StandardError stream. I am using async methods for reading and writing in order to keep the user interface responsive. However, after sending the third textDocument/didOpen message, my program freezes while trying to read the response; the UI, of course, stays responsive. ;) Leveraging the debugger I found out, that clangd processes the third Here is my code using the LSP client's methods for sending the textDocument/didOpen message: InitializeLanguageServer is called in the constructor without pragma warning disable CS4014 pragma warning restore CS4014 The requests sent to [link] [comments] |
Can you work remotely from another country entirely? Posted: 02 Sep 2018 09:01 AM PDT So, right now i'm about to start my second year of CS uni and i live in Italy therefore the question i'm posing it's for my future, not what i'm gonna do in a few months. I know that a coding career in Italy while not bad is nowere near how good it is in America (don't wanna move to the rest of Europe cause i'd have to learn a whole new language). So i think at some point i'm gonna end up living in America but before that i always had the dream of spending 1-2 years in Japan since i loved that country since i was a kid, but i hate their work culture and programmers are also paid as much as any other office job. So my question is, is it possible, easy and worth it to get a job from an american company but work remotely in Japan? If yes what downsides should i expect? [link] [comments] |
You are subscribed to email updates from AskProgramming. To stop receiving these emails, you may unsubscribe now. | Email delivery powered by Google |
Google, 1600 Amphitheatre Parkway, Mountain View, CA 94043, United States |
No comments:
Post a Comment