w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
cannot implicity convert type localhost.Coin to Coin
It pretty much looks like you have two different definitions of Coin(). That is what the exception tells you. Considering your remarks, you've perhaps added the Coin() object twice; one time in the client/website and once in the service? To verify this assumption, try if the following works: // [comment this] Coin c = new Coin(); WebService w = new WebService(); var c = w.transferCoin(ListBox1.SelectedValue); Here, you do not use the Coin object, as defined on your site. But more the object as defined in the service.

Categories : C#

Coin Change analysis
The dynamic programming solution to this problem is clearly O(k * n) (nested loops, blah blah blah) where k is the number of coins and n is the amount of money that change is being made for. I don't know what you mean by non-dynamic programming solution. Sorry, you're going to have specify what algorithm you mean. The greedy algorithm fails in some cases, so you shouldn't be referring to that. Do you mean the linear programming solution? That's a terrible approach to this problem because we don't know what the complexity is, and it's possible to make it run arbitrarily slowly. I also don't know what you mean by "change it for the dynamic one."

Categories : Algorithm

change coin implementation issue
Your first algorithm is wrong. DP[5] = 2 {1,1,1,1,1}, {5} DP[6] = DP[5] + DP[1] = 3 you are counting {5,1} twice. EDITED So the standard trick for doing this is that you keep a count of the denomination you are allowed to use DP[i,m] = DP[i-coin[m],m] + DP[i,m-1] which means number of ways of making a change of i amount using coins in range[1..m]. This is obviously, you either use the mth denomination or you don't. The second algorithm you are using is doing the same trick but is a really clever way to do that, take the ith coin and see what all change you can generate using it. This will avoid over counting because you avoid doing things like {1,5} and {5,1}.

Categories : Algorithm

Algorithm for making two histograms proportional, minimizing units removed
Seems to me that the problem is equivalent (if you consider each histogram as a N-dimensional vector), to minimizing the Manhattan length |R|, where R=xA-B, A and B are your 'vectors' and x is your proportional scale. |R| has a single minimum (not necessarily an integer) so you can find it fairly rapidly using a simple bisection algorithm (or something akin to Newton's method). Then, assuming you want a solution where the proportion is an integer, test the two cases ceil(x), and floor(x), to find which has the smallest Manhattan length (and that is the number of observations you need to remove). Proof that the problem is not NP-hard: Consider an inefficient 'solution' whereby you removed all N observations from all the bins. Now both A and B are equal to the 'zero' histogram 0 = (0,0

Categories : Performance

"Charge changing" algorithm
Your intuition for when the problem is solvable isn't quite right. Half of all instances are insoluble whenever n = 2 (mod 3). One way to see this is by doing a few steps of reducing the appropriate system of equations (mod 2). Another way to see that there's some redundancy is to see that flipping the first, fourth, seventh, ... (n-1)st affects exactly the same set of characters as flipping the second, fifth, eight, ... nth. As for an algorithm for solving these problems: There are two possible choices for the first flip. Once you've decided whether to flip around the first character, the value of the first character tells you whether you need to flip around the second character. Then the value of the second character tells you whether to flip around the third character. And so fo

Categories : Algorithm

JQuery Algorithm for changing DIV offset if still in view
Think I've sorted this. Just in case anyone finds this... $("#SFPanLeft").click(function () { var x = $("#SFHolder").width(); var y = $("#stretchflex").offset().left; var z = $("#stretchflex").get(0).scrollWidth; /* using scrollWidth fixes */ $("#x").html("X : " + x.toString()); $("#y").html("Y : " + y.toString()); $("#z").html("Z : " + z.toString()); if (x < (z + y)) { /* updated algorithm */ var left = $("#stretchflex").offset().left left -= 176 $("#stretchflex").css({ left: left + 'px' }); }; });

Categories : Javascript

Changing HiddenField value in codebehind no changing in Javascript function in order to use showModalDialog
Watch the casing on your Parameters variable. Also try using RegisterStartupScript instead of RegisterClientScriptBlock. The difference is the former will put your javascript at the bottom of the page while the latter puts it at the top. This will cause the script to run before the document it fully loaded. ScriptManager.RegisterStartupScript(Page, Page.GetType, DateTime.Now.ToString, "<script type='text/javascript'> ShowWindow(); </script>", False)

Categories : Javascript

Regarding changing bash file and making new directory for mongodb
Can you add it to your bashrc? cd nano .bashrc mongodb="path_To_mongodb.exe" ## add this to bashrc, save and quit. Then restart terminal. Make sure there no spaces. Replace "path_To_mongodb.exe" with the actual path to your exe. Make sure it's in the right file, and saved, and terminal restarted, and if you're trying it in a script, expand the variables by adding shopt -s expand_aliases source ~/.bashrc to the start of the script.

Categories : Osx

TERCOM algorithm - Changing from single thread to multiple threads in CUDA
The basic problem here is that you have a memory race in the code, centered around the use of f as both some sort of thread local scratch space and an output variable. Every concurrent thread will be trying to write values into the same locations in f simultaneously, which will produce undefined behaviour. As best as I can tell, the use of f as scratch space isn't even necessary at all and the main computational section of the kernel could be written as something like: if(idx < n && idy < m) { for(float g=0; g<N; g++) { float fval = tex2D (tex, idx+(g-2)*offset_x+0.5f, idy+(g-2)*offset_y+0.5f); MAD += abs(measurements[(int)g]-fval); } min=MAD; pos[0]=idx; pos[1]=idy; } [disclaimer: written in browser, use at own risk] At the en

Categories : Algorithm

Changing Letters Algorithm, works in JSBIN but not in Coderbyte, seeking clarification
Seems like a bug on their back-end JS runner indeed. As you've stated, your code runs fine and should be accepted. Worth reporting it to their support imo. Here's an alternative solution specifying a function as second parameter to .replace(): function LetterChanges(str) { return str.replace(/[a-z]/ig, function(c) { return c.toUpperCase() === 'Z' ? 'A' : String.fromCharCode(c.charCodeAt(0) + 1); }).replace(/[aeiou]/g, function(c) { return c.toUpperCase(); }); }

Categories : Javascript

UIProgressView doesn't change height after changing appearance, but change after rotating device
Make sure the view (or at least the rectangle you care about) is being redrawn when you set the appearance. Call the method setNeedsDisplay whenever you set the appearance. The height of your UIProgressView would change on autorotation, because your views are re-laid out and redrawn when you rotate.

Categories : Iphone

Benchmark algorithm to change perceptive brightness?
You don't need to reverse the luminance equation, you just have to figure out the ratio to your desired luminance. From your example: //target luminance = 80 srcR = 120 srcG = 33 srcB = 213 srcLum = 79.533 destLum = 80 ratio = (destLum / srcLum) = 1.0058717... destR = (srcR * ratio) = 120.705 destG = (srcG * ratio) = 33.194 destB = (srcB * ratio) = 214.251 You'll have to decide how you want to round them to get int values, but that's the general idea. Going from 79.5 to 80 isn't much of a change, though, so you won't see much. If you were going to 40, you'd end up with RGB(60,17,107). As Mark Ransom points out below, once one of your values hits 255, you'll have to make a choice. To increase the luminance past that point, you'll either be changing the hue or the saturation(or both)

Categories : Image

Flipping a coin using RandomGenerator
Every time you call flipCoin() the method runs, so it runs once on the line println(flipCoin()); and once on if (flipCoin() == "heads"). The results of the two calls may not be the same, you should store the result and then use the result, so: while (true){ String result=flipCoin(); System.out.println(result); if (result.equals("heads")){ break; } } Note also that using == with strings will (under most circumstances) always give false; this is because == asks if they are literally the same object, not if their contents are equal (two pieces of paper can both have "hi" written on them but they are not the same piece of paper). .equals compares the contents of the two strings (i.e. if they say the same word(s)). I have kept my modifi

Categories : Java

Pseudocode for coin-flipping game
Pseudo-code is words written that may or may not eventually run but describes the problem that you are trying to solve as though it does. Here is an example of pseudo-code given the problem: flip_coin output_result_of_coin_flip And truly, we can make this be actual code that will run. The flow chart is a little bit more complicated, in that you have choices of what the flow chart should look like, is it UML compliant, etc? Regardless, it should communicate the flow through your program to result in what you need it to do. An example of a flow-chart is such: Read more at Wikipedia

Categories : Ruby

Flipping two sided coin in Android
faced the same problem few days ago, found the solution in class FlipAnimator that you can find here: FlipAnimatorClass it is pretty easy, actually: you just have to pass to FlipAnimator the two sides of the coin. The class is pretty easy to understand, I think, and it is practically doing what g00dy suggested in his comment above.

Categories : Android

C++ Coin flip program error
Each time you call FlipCoin function you flip. Thus, you flip twice in each iteration of your while function. You may consider passing flip as reference to FlipCoin: #include <iostream> #include <string> #include "random.h" using namespace std; void FlipCoin (string &flip); int main() { string flip; int consecutiveHeads = 0; int totalFlips = 0; while (consecutiveHeads<3) { totalFlips++; FlipCoin(flip); if (flip == "heads") { consecutiveHeads++; } else { consecutiveHeads = 0; } cout <<totalFlips<<" "<< flip << " " << consecutiveHeads <<endl; } cout <<"It took "<< totalFlips <<" coin flips to get 3 consecutive heads."<&

Categories : C++

Optimal Strategy For Coin Game
if you want to compute the amount of money that you can definitely win, you have to assume that your opponent is trying to maximize his/her own result, which amounts to minimizing yours (since the sum of your gains is always equal to v1 + ... + vn). What your formula is computing is what you can win if your opponent always make the wrong (from his/her point of view) move.

Categories : Algorithm

javascript best algorithm for min() with 2 or more arguments?
i think the Min() is ok From W3schools : Return the number with the lowest value: var a=Math.min(5,10); var b=Math.min(0,150,30,20,38); var c=Math.min(-5,10); var d=Math.min(-5,-10); var e=Math.min(1.5,2.5); The result of a,b,c,d, and e will be: 5 0 -5 -10 1.5

Categories : Javascript

To resolve a merge conflict, how do I see what change the other branch was making?
You have done a pull --rebase, so you already have 'their' commits on your local branch (HEAD). You might have applied some of your commits until the conflict arrised. Therefore you can check all the changes by commits: git log -p file You can further narrow it down by adding revision range from common ancestor: git log -p common..HEAD file When the pull --rebase already applied 2 of your commits before the conflict arrised (you see them as last commits in the log) and wish to see just 'their' changes against the common ancestor: git log -p common..HEAD^^ file

Categories : GIT

Making jenkins plugin - change context path
According to documentation, default is /, hence don't give any config and try. Also ensure maven-hpi-plugin 1.65 or later (used by parent POM 1.401 or later).

Categories : Java

Making the same change to every line in a BED/Interval file in python
step one open the file file = open("somefile.txt") step 2 get the lines lines = list(file.readlines()) file.close() step 3 use a list comprehension new_lines = ["chr"+line for line in lines] step 4 write new lines back to file with open("somefile.txt","w") as f: f.writelines(new_lines) In order to not store all the lines in memory file1 = open("some.txt") file2 = open("output.txt","w") for line in file1: print >> file2, "chr"+ line file1.close() file2.close() then just copy output.txt to your original filename

Categories : Python

Should I change the axis or the degree for making flip upwards/downwards?
You want to change the axis of rotation, to the X axis in your case. Basically, use rotateX() instead of rotateY() So here's the updated fiddle and the CSS: .flip { position: relative; -webkit-perspective: 1000; -moz-perspective: 1000; -ms-perspective: 1000; -o-perspective: 1000; perspective: 1000; } .flip .flip-front, .flip .flip-back { position: absolute; top: 0; left: 0; -webkit-transform-style: preserve-3d; -moz-transform-style: preserve-3d; -ms-transform-style: preserve-3d; -o-transform-style: preserve-3d; transform-style: preserve-3d; -webkit-backface-visibility: hidden; -moz-backface-visibility: hidden; -ms-backface-visibility: hidden; -o-backface-visibility: hidden; backface-visibility: hidden; -webkit

Categories : HTML

coin-slider js gallery, want to add fade effect
Under the default values at the end just change the values of spw and sph to 1. Javascipt file: spw: 1, // squares per width sph: 1, // squares per height effect: 'rain'

Categories : Javascript

Coin Exchange in java Code stackOverflowError
When this part (array[i]*(int)(money/array[i])) equals zero your are a victim of infinite recursion where you are calling the function with the same amount of money You can change it to : if(money >= array[i]) countCombine += count(array,money - (array[i]*(int)(money/array[i]))); so you will never get a zero here, but test it for more examples as i didn't test it a lot , but I think that it is logically right

Categories : Java

Javascript algebra/algorithm maths
If it is an algebra question... since h1 = h2 you may exclude them and get. w1*1.98 = w2*0.6355 w1 + w2 = 1367 Put it into some solver and get { w1 = 332.1462435480787, w2 = 1034.853756451921 }.

Categories : Javascript

Javascript quicksort algorithm implementation
You can simulate the stack with an array, which can be longer. I did very limited testing with this, but it seemed to work. function sort(a) { var stack = [[0, a.length]]; while (1) { var stackLength = stack.length; if (! stackLength) { break; } var l = stack[stackLength - 1][0], r = stack[stackLength - 1][1]; if (l >= r - 1) { stack.pop(); continue; } var p = r - 1; var y = l; var tmp; for (var i = l; i < r - 1; i++) if (a[i] < a[p]) { tmp = a[i]; a[i] = a[y]; a[y] = tmp; y++; } tmp = a[y]; a[y] = a[r - 1]; a[r - 1] = tmp; stack.pop(); stack.push([y + 1, r]); stack.push([l, y]); } return a; }

Categories : Javascript

is this valid JavaScript arrays comparing algorithm?
As an alternative, if you just want to check if both arrays are exactly the same you could just do this: var a = [1,2,3,4]; var b = [1,2,3,4]; JSON.stringify(a) == JSON.stringify(b); //= true That should work with arrays of numbers and strings.

Categories : Javascript

Image scaling or DOM duplicating algorithm in JavaScript?
As far as I can see you're limited to two options: Either double the size of the individual dom-pixels Or if this is not possible, scale your pixelmap over twice the number of dom-pixels (so add every pixel twice and copy each row at the end) Of course the first option is by far the most efficient one, but it seems the environment you're working in is quite restrictive, so I assume this is not possible.

Categories : Javascript

Animating a recursive backtracking algorithm in javascript
You could program it asynchronously using for example deferreds. jQuery provides an implementation of deferreds and you could have a look at this example which uses timeouts: http://api.jquery.com/deferred.promise/#example-0 Of course you need only one timeout which always resolves (succeeds).

Categories : Javascript

Assistance with minimax algorithm for connect four in Javascript
Your evaluation function is assigning value to positional features that have no value. Having two contiguous cells in a row has no value. Having three in a row has no value either if the fourth cell can be occupied by the opponent without allowing a win elsewhere. Simplify. For Connect Four you only need to care about whether the position is a win or a loss or if the position can be won or lost on the next move. If it's a win, return a large positive value. If it's a loss, return a large negative value. If the position can be won or lost on the next move, extend the search depth one ply for this branch and call minimax() again, returning the result. The latter will avoid the horizon effect to which all fixed depth minimax searches are susceptible. Otherwise return zero.

Categories : Javascript

Converting an algorithm using numpy.irfft to JavaScript
I'm having a hard time reproducing your issue. I've thrown together a toy problem in both numpy and nfftd in an attempt to replicate your issue with amplitudes, and I'm failing. Toy Problem I've calculated a discrete sin wave (10 points), and have put the sin wave through the transform you describe above, though I've replaced the random function with a random array that doesn't change from one iteration to the next. Python Code First, the python code: # create the discrete sin wave buf = np.sin(np.linspace(0,2*np.pi,10)) # run through transform described by sebpiq amp = np.abs(np.fft.rfft(buf)) ph = np.array([ 3.69536029, 1.99564315, 1.046197 , 4.43086754, 0.01415843, 3.53100037]) ph = ph*1j amp = amp * np.exp(ph) buf = np.fft.irfft(amp) And the results: array([-0.28116423,

Categories : Javascript

Algorithm for selecting a range of number in javascript
Use Array.prototype.slice: var start = 0; var newArr = arr.slice(start, start + 4);

Categories : Javascript

making javascript jshint compliant
Here's your onselect method using a switch-case: onselect: function (p) { switch (p) { case 'Accordions': content = "[accordion_wrap]<br>[accordions title="Title Goes Here"]This is where some content goes...[/accordions]<br>[accordions title="Title Goes Here"]This is where some content goes...[/accordions]<br>[accordions title="Title Goes Here"]This is where some content goes...[/accordions]<br>[/accordion_wrap]"; tinymce.execCommand('mceInsertContent', false, content); break; case 'Accordions With Icons': content = "[accordion_wrap]<br>[accordions accordionicon="icon-globe" title="Title Goes Here"]This is where some content goes...[/accordions]<br>[accordions accordionicon="icon-globe" title="Title Goes Here

Categories : Javascript

Making PhP code executes first before Javascript
On initial page load: The process flow looks like this: Server Side code -> sends data to client -> browser begins rendering and executing JS On form Submit: Client Executes code (javascript) -> Sends data to server -> Server gets data and processes to change the way this works you would want to do an ajax or post form submit and on "success" then execute the above JavaScript. You can post to the same page or change it to a RESTful service. Here are examples of AJAX and POST functions from jQuery: AJAX $.ajax({ type: "POST", url: url, data: data, success: success, dataType: dataType }); POST (JS) $.post('ajax/test.html', function(data) { $('.result').html(data); }); Here is the result specifically for you, taking the two snippets above. JavaScript/jQuery

Categories : PHP

Making an HTTP Request When there is a Javascript
You need to use another URL: #!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; my $json_uri = "https://familysearch.org/search/records?count=20&query=%2Bgivenname%3ALester%20%2Bsurname%3AYoungblood%20%2Bevent_place_level_1%3AGeorgia%20%2Bevent_place_level_2%3AWhitfield%20%2Bevent_place_level_3%3ACarbondale%20%2Bgender%3AM&collection_id=2000219"; my $lwp = LWP::UserAgent->new; my $req = HTTP::Request->new( 'GET', $json_uri ); $req->header( 'Content-Type' => 'application/json' ); my $res = $lwp->request($req); if ( not $res->is_success ) { warn "Bad response :("; sleep(1); die; }

Categories : Javascript

javascript: making a calendar navigation bar
When you are using document.write the second time the calender function is called, you are rewriting the whole HTML and your <head> tags gets lost. That happens when you use document.write after the page finished loading, you should use this instead: <!DOCTYPE html> <html> <style> table { border-collapse:collapse; } table img { width:50px; height:50px; } td,table { border-color:blue; text-align:center; } td:hover { cursor:pointer; background-color:yellow; } </style> <head> </head> <body> <script> var date=new Date(); var mn=['JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC']; y=date.getFullYear(); m=date.getMonth(); function preyear() { y -= 1; calendar(); } function premonth(){ m -= 1; calenda

Categories : Javascript

Javascript - Making a function asynchronous
It's got nothing to do with async, variable assignment doesn't work like that. element is a local variable to your titleCase function, so doing that assignment doesn't have any effect outside the function. You need to return a value: function titleCase(element) { return element.replace(/([^W_]+[^s-]*) */g, function(txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); }); } var var1 = "UPPER CASE"; var var2 = "lower case"; var var3 = "MiXeD CaSe"; var1 = titleCase(var1); var2 = titleCase(var2); var3 = titleCase(var3); console.log(var1, var2, var3);

Categories : Javascript

Javascript setInterval not making it into function
process_chunk has not been assigned a value yet, when you pass it into setInterval. Move the line: var interval = setInterval(process_chunk, 1000); To right before (and right after the anonymous function is assigned to process_chunk): doneVar += 1; Or if you are looking for hoisting the function then use a function declaration rather than an expression: function process_chunk() { Both versions will solve your problem.

Categories : Javascript

Python-Modulus-Stuck with a coin-for-given-dollar-amount scenario
i think your algorithm is too complicated, you don't need all the elifs and the elses just check with and if and then modidy the remaining amount until you get to zero something like this penny = 1 nickel = 5 dime = 10 quarter = 25 q = 0 d = 0 n = 0 p = 0 i = input("Please enter an amount no more than 1 dollar(in cents): ") i = int(i) if i>=25: q = i/quarter i %= quarter if i>=10: d = i/dime i%=dime if i>=5: n = i/nickel i %= nickel if i>0: p = i/penny i = 0 print "The coins are %i quarters, %i dimes, %i nickels and %i pennys." %(q , d, n, p) >>> Please enter an amount no more than 1 dollar(in cents): 99 The coins are 3 quarters, 2 dimes, 0 nickels and 4 pennys. >>> Please enter an amount no more than 1 dollar(in cents):

Categories : Python

Coin Toss program not working Visual Studio 2010
Here is a modified code which runs fine with me in eclipse : #include<stdio.h> #include<stdlib.h> #include<time.h> int result; int flip(); int main(void) { srand(time(NULL)); int heads = 0; int tails = 0; unsigned counter; for(counter = 1; counter <= 100; counter++) { result = flip(); if(result == 1) { printf("Heads "); heads++; } else { printf("Tails "); tails++; } } printf("Heads: %d Tails: %d ", heads, tails); return 0; } int flip() { result = 1 + rand() % 2; if (result == 1) return 1; if (result == 2) return 0; } Mistakes: In main , you forgot 'return 0 ' statement. In flip

Categories : C



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.