[Solved] Check where number 1 is in decimal number

I wouldn’t rely too much on the approach you posted in your answer. Use the following function instead: function index_of_one($dec) { // maximum precision is 15 $str = str_replace(‘.’,”,sprintf(‘%.15f’, $dec)); $pos = strpos($str, ‘1’); if ($pos === false) { return -1; } return ($pos + 1); } Example: $dec1 = 1.00000000; $dec2 = 0.10000000; $dec3 … Read more

[Solved] I want to know the count of each item in a list

You can use GroupBy: var voteGroups = Votes.GroupBy(s => s); Now, if you want to know the count of each string use Enumerable.Count: foreach(var voteGroup in voteGroups) Console.WriteLine(“Vote:{0} Count:{1}”, voteGroup.Key, voteGroup.Count()); Another way is using ToLookup: var voteLookup = Votes.ToLookup(s => s); foreach (var voteGroup in voteLookup) Console.WriteLine(“Vote:{0} Count:{1}”, voteGroup.Key, voteGroup.Count()); The lookup has it’s … Read more

[Solved] SQL request with JOIN and COUNT

If I am reading your question right, the result table give you the age ID and Period, and then the count of toys per age ID and Period. Here is how you would write that query: SELECT Ages.ID, Ages.Period, IFNULL(sub.cnt,0) AS Count FROM Ages LEFT JOIN (SELECT Toys.age_id, COUNT(*) AS cnt FROM Toys GROUP BY … Read more

[Solved] Count letters in a string

You can solve the problem by following the steps below like QBrute correctly pointed out. public String countMatches(String main) { //Create an array of the alphabets length main = main.toLowerCase(); int[] foundArray = new int[26]; String output = “”; //Create an alphabets array String[] alphabets = “a b c d e f g h i … Read more

[Solved] programing function in python

I changed 2 things : while n > 1: instead of while n > 0: otherwise your loop never stops n=n//10 instead of n=n/10, where // is the euclidian division, which is what you need here You should try this : def testD(D,n): if D % 2 == 0: return 0 count = 0 while … Read more

[Solved] How to limit items from for loop?

Dont know what you mean there. But here is what I understand from your question <?php for ($i=0; $i< count($contentdinamit[“chart”][“songs”][“song”]); $i++ ) { if(($i+1)<=10){//limit your item by 10 echo'<li class=”up”><a href=”‘ .$contentdinamit[“chart”][“songs”][“song”][“$i”][“artist_name”].'”><strong>’ .$contentdinamit[“chart”][“songs”][“song”][“$i”][“song_name”].'</strong></a><br /><a href=”‘ .$contentdinamit[“chart”][“songs”][“song”][“$i”][“artist_name”].'”>’ .$contentdinamit[“chart”][“songs”][“song”][“$i”][“artist_name”].'</a></li>’; } } ?> 6 solved How to limit items from for loop?

[Solved] Total count in sql

Something like this: CREATE VIEW GetNumberOfStudentswithMajor AS SELECT COUNT(*) FROM dbo.Students where Major1 is not null and Major2 is not null solved Total count in sql

[Solved] Count unique words in table with JS [closed]

Here how I would do it using JavaScript. This code calculates words for whole table. If you need to run it for the row, you should modify it appropriately. var words = []; var uniqueWords = []; $(“td”).each(function(){ words.push($(this).text()) }); $(words).each(function(){ for(var i = 0; i < uniqueWords.length; i++){ var current = uniqueWords[i]; if(current.word.toString() == … Read more