How to Find Ratio and GCF of 2 numbers swift
Suppose my 2 numbers are 15 and 550.
I want to find ratio of this 2 numbers and to find ratio of 2 number first thing i need is GCF (Greatest Common Factor) but i don't know how to do this in swift.
GCF of above 2 number is 5
Once i found GCF than i can easily find ratio from below.
let a : Int = 15
let b : Int = 500
let strA = String((a/5))
let strB = String((b/5))
print(String.init(format: "%@:%@", strA, strB))
how can i calculate GCF?
Thanks in advance.
See also questions close to this topic

How to import JTCalendar to swift 4
I am creating an app where calendar is used to select date for searching functionality.
I am currently using FSCalendar to do it as below.
But need to scroll the days title "Mon Tue Wed Thu Fri Sat Sun" also along with the dates when we scroll it. In FSCalendar its not available. So thought to change the library and got the JTCalendar library which also scrolls the days
Ive been following the answer from https://stackoverflow.com/a/42501561/5515165 to try with JTCalendar. But as said Im not able to "import JTCalendar" even after installing cocoapod.
Please help!

Are WebSocket messages cached on iOS?
Strange but I cannot find any information on that: if I write a [large] message to the WebSocket stream on iOS and the execution gets back to my code, is the message already sent or somehow buffered?
I'm using Starscream library but it just uses CFStreams.

two tableviews with two different tableview cells
I have two tableviews with two different custom tableview cells.. and am doing this:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) > UITableViewCell { if tableView == self.tableview { let cell = tableview.dequeueReusableCell(withIdentifier: "matchescell") as! MatchesTableViewCell // ...... return cell } else { let cell = tableview.dequeueReusableCell(withIdentifier: "filtercell") as! FilterTableViewCell // ...... return cell } }
but i keep getting this:
on this line:
let cell = tableview.dequeueReusableCell(withIdentifier: "filtercell") as! FilterTableViewCell
What am doing wrong?!

Calculating the number of buyers that are at every hour from 00:00 to 24:00 in the store with tidyverse
I need to calculate the number of buyers in a store at each hour of the day. I have reproduced the data from another similar problem but that seemed not to answer the problem I am looking for. I do not want to calculated the length of stay in the store but want to calculate the occupancy of the store, by counting all buyers in the store, at each hour of the day. I need to do this only with tidyverse and lubridate.
df < structure(list(ID = c(101, 102, 103, 104, 105, 106, 107), Time_in = structure(c(1326309720, 1326309900, 1328990700, 1328997240, 1329000840, 1329004440, 1329004680), class = c("POSIXct", "POSIXt"), tzone = ""), Time_out = structure(c(1326313800, 1326317340, 1326317460, 1326324660, 1326328260, 1326335460, 1326335460), class = c("POSIXct", "POSIXt"), tzone = "")), .Names = c("ID", "Adm", "Disc"), row.names = c(NA, 7L), class = "data.frame")

Logic/Algorithm  Storing Chosen Items in a List as Ints  And undoing this again?
I've seen someone's code and they've got a list of items and they're saving the chosen item by an int. These are the same ints that represent bits, e.g. 1,2,4,8,16,32,64,etc.
I understand the concept of this, because you can just get one final value, and work out exactly what has been chosen, as every variation will still have a unique total.
My question is, what would be the calculation to undo the total into the separate ints again? (So that I can work out the chosen objects)
I can't conceptualise it. This looks like it would be a lot more memory efficient for applications, rather than storing lists of chosen objects etc.
Could anyone help me get the chosen items back out of the final number?
(I did try a google search, but I wasn't sure quite how to word it so I didn't find much!)
Thanks

Loan C# console app, interest total doesn't start at zero
I've got this working the way it should, except the output for the first row shows the running total for interest payment as already summarized, instead the same as the first interest amount. So if the first month is 1.05 interest, running total for first month should show 1.05. Second month would be 1.05 + new interest amount. Right now it shows for example above, 2.10 as first month total. Where is my logic screwed?
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Loan_Program { class Loan { //declare variables private double LoanAmount, InterestRate; private int LoanLength; //Constructor of Loan class that takes amount, rate and years public Loan(double amount, double rate, int years) { this.LoanAmount = amount; this.InterestRate = (rate / 100.0) / 12.0; this.LoanLength = years; } //returns the monnthly payment public double GetMonthlyPayment() { int months = LoanLength * 12; return (LoanAmount * InterestRate * Math.Pow(1 + InterestRate, months)) / (Math.Pow(1 + InterestRate, months)  1); } //Calculates totl interterest paid and doubles it, then returns the amount public double TotalInterestPaid(double number1,double number2) { double TotalInterest = number1+number2; return TotalInterest; } //prints the amortization of Loan public void LoanTable() { double monthlyPayment = GetMonthlyPayment();//calculates monthly payment double principalPaid = 0; double newBalance = 0; double interestPaid = 0; double principal = LoanAmount; double totalinterest = 0; //nonth, payment amount, principal paid, interest paid, total interest paid, balance Console.WriteLine("{0,10}{1,10}{2,10}{3,10}{4,10}{5,10}", "Payment Number", "Payment Amt", "Interest Paid", "Principal paid","Balance Due","Total Interest Paid"); for (int month = 1; month <= LoanLength * 12; month++) { // Compute amount paid and new balance for each payment period interestPaid = principal * InterestRate; principalPaid = monthlyPayment  interestPaid; newBalance = principal  principalPaid; totalinterest += interestPaid; // Output the data item Console.WriteLine("{0,10}{1,10:N2}{2,10:N2}{3,10:N2}{4,10:N2}{5,10:N2}", month, monthlyPayment, interestPaid, principalPaid, newBalance, TotalInterestPaid(totalinterest,interestPaid)); // Update the balance principal = newBalance; } } } }
Main Program
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Loan_Program { class LoanTest { static void Main(string[] args) { //declare variables double amount; double rate; int years; //prompt loan amount Console.WriteLine("Enter loan amount"); amount = Convert.ToDouble(Console.ReadLine());//accepts console input and assigne to variable //prompt for rate Console.WriteLine("Enter annual interest rate"); rate = Convert.ToDouble(Console.ReadLine());//accepts console input and assigne to variable //prompt for monhts Console.WriteLine("Enter number of years"); years = Convert.ToInt32(Console.ReadLine());//accepts console input and assigne to variable Loan loan = new Loan(amount, rate, years);//create new instance, send values to the class loan.LoanTable(); Console.ReadKey(); } } }