[Solved] How can I toggle a boolean number?

Your approach is correct and will work as well. Just you need to wrap it into a function. Another way is using ^ (Bitwise XOR) to do that functional and more clean: function toggleNumber( $num ) { return $num ^= 1; } Online Demo That function gets the number and does XOR with 1 on … Read more

[Solved] How to get the day number in a month in c# [closed]

public static IEnumerable<int> DaysInMonth(int year, int month, DayOfWeek dow) { DateTime monthStart = new DateTime(year, month, 1); return Enumerable.Range(0, DateTime.DaysInMonth(year, month)) .Select(day => monthStart.AddDays(day)) .Where(date => date.DayOfWeek == dow) .Select(date => date.Day); } Your example: var wednesdaysInSeptember2015 = DaysInMonth(2015, 9, DayOfWeek.Wednesday); Console.Write(String.Join(“,”, wednesdaysInSeptember2015)); // 2,9,16,23,30 For what it’s worth, here is a performance optimized version: … Read more

[Solved] Big double number up to two decimal places [closed]

The number is being rounded up correctly The scientific notation 1.13452289575668E8 means 1.3 x 108 which is 113452289.5756680071353912353515625 double d = 1.13452289575668E8; System.out.println(new BigDecimal(d)); gives 113452289.5756680071353912353515625 round to 2 decimal places is 113452289.58 2 solved Big double number up to two decimal places [closed]

[Solved] c++ Check if string is valid Integer or decimal (both negative and positive cases)

The answer was a simple Regex: bool regexmatch(string s){ regex e (“[-+]?([0-9]*\.[0-9]+|[0-9]+)”); if (regex_match (s,e)) return true; return false; } It will return true on integers (i.e. 56, -34) and floating point numbers (i.e. 6.78, -34.23, 0.6) as expected. 3 solved c++ Check if string is valid Integer or decimal (both negative and positive cases)

[Solved] Add one to C# reference number

Homework or not, here’s one way to do it. It’s heavily influensed by stemas answer. It uses Regex to split the alphabetical from the numeric. And PadLeft to maintain the right number of leading zeroes. Tim Schmelters answer is much more elegant, but this will work for other types of product-numbers as well, and is … Read more

[Solved] Converting number into word

Try this : ten_thousand = number/10000; number = number%10000; thousand = number/1000; number = number%1000; hundred = number/100; number = number%100; ten = number/10; number = number%10; unit = number; solved Converting number into word

[Solved] Python – Read string from log file

Can be extracted with a simple regular expression, as long as the text file is in the same format as the Python log output you posted (Returns all of them): import re file=””.join([i for i in open(“yourfileinthesamefolder.txt”)]) serials=re.findall(“u’serial_number’: u'(.+)'”,file) print(serials) I suggest reading up on how to use regular expressions in Python: Regular Expression HOWTO … Read more

[Solved] C# array of numbers

Your code is unnecessarily complex. use default .Net implementations to make your code readable and understandable. string skaiciai = “skaiciai.txt”; string[] lines = File.ReadAllLines(skaiciai); // use this to read all text line by line into array of string List<int> numberList = new List<int>(); // use list instead of array when length is unknown for (int … Read more

[Solved] reaching the goal number [closed]

I would take a dynamic-programming approach: def fewest_items_closest_sum_with_repetition(items, goal): “”” Given an array of items where each item is 0 < item <= goal and each item can be used 0 to many times Find the highest achievable sum <= goal Return any shortest (fewest items) sequence which adds to that sum. “”” assert goal … Read more

[Solved] #JAVA – Programme calculates the sum of numbers from 1 to 10,000 (including 1 and 10,000) omitting numbers numbers whose hundred digit is 2 or 3 [closed]

You can use modulus to find the last 3 digits and then check that with your condition. public printNum() { int num = 0; while (num < 10000) { num++; int last3Digits = num % 1000; if (!(last3Digits >= 200 || last3Digits <= 399)){ System.out.println(num); } } } Hope this solves it 3 solved #JAVA … Read more

[Solved] Check input numbers in prolog

Since you tried something for your isDigit/1 predicate I’ll help about that : Version with an if structure : isDigit(X) :- ( number(X), X >= 0, X =< 8 -> true ; writeln(‘[0-8] AND Number’), fail). Version with a disjunction (as you tried in your OP) : isDigit(X) :- number(X), X >= 0, X =< … Read more

[Solved] Number formatting

Just change your if condition and remove 1x zero, so from this: if ($number < 10000) { return pm_number_format($number); } to this: if ($number < 1000) { return pm_number_format($number); } Input: 1 12 123 1234 12345 123456 1234567 12345678 123456789 Output: 1 12 123 1.2K //<–See output as you wanted 12.3K 123.5K 1.2M 12.3M 123.5M … Read more

[Solved] How many words fit in 4 bits

Answer 1) With the 4 bits we can write 16 different numbers. As we have 4 different position of bits let’s say ABCD where A,B,C,D are representing 1 bit. Each position A,B,C,D has two possible input 0 or 1 so each position is having 2 possible inputs. So for 4 positions total different outputs = … Read more