venta: (Default)
[personal profile] venta
So, sums. I can, broadly speaking, do sums. I have a degree in maths.

However, interest rate calculations have always baffled me. Sure, if you ask me to calculate 3 months compound interest at a monthly rate of x% I know what to do. However, when it comes to real examples of mortgages and credit cards, I can't work out what the sum I need to do is. I'm still slightly baffled about the interest charged me when I was a day late paying my credit card off in full in March.

Today, the BBC carried a story about a loanshark. It includes the following statement about someone who borrowed £1000:

"...to pay £49 a week over 60 weeks, making the total amount he had to
repay £2,940 at 917% APR."

Now, if we approximate 60 weeks to a year, then surely that's an annual interest rate of no more than 294%. The quoted APR isn't even in vaguely the right ballpark.

So... have I completely failed to understand APR ? (Wikipedia's page on the subject didn't really help with the definition.) Or is the BBC publishing unmitigated wank in the name of investigative journalism ?

Edit It turns out I'd failed to understand APR, and the BBC is cleared in this instance.

Date: 2008-07-29 03:37 pm (UTC)
From: [identity profile] onebyone.livejournal.com
Hmm.

My home number is 2 5-digit primes times 8, but with the country code is 24 times a prime.
My mobile number double a prime. It still is with the country code added.

Also: gosh, PCs are fast these days. I'm sure it used to take time to factor a 12-digit decimal number.

Date: 2008-07-29 03:57 pm (UTC)
chrisvenus: (Default)
From: [personal profile] chrisvenus
I'm sure it used to take time to factor a 12-digit decimal number.

Google for ways to do it and try some of the javascript methods. That will make it feel like the old days... (yeah, I tried that first and given the ones I found seemed to be saying "for i = 2 to testnumber/2" I'm not that surprised that it failed a lot. :)

Date: 2008-07-29 04:06 pm (UTC)
From: [identity profile] onebyone.livejournal.com
Well, here's my Code of Awesomeness (Not). It doesn't take a measurable amount of time to factor a phone number - it's no visibly slower than the case where I leave out the argument:

#include "stdlib.h"
#include "stdio.h"

int main(int argc, char **argv) {
	if (argc < 2) {
		printf("oops\n");
		exit(1);
	}

	long long tofactor;
	sscanf(argv[1], "%lld", &tofactor);
	printf ("factor %lld\n", tofactor);

	while ((tofactor % 2) == 0) {
		tofactor = tofactor / 2;
		printf("2\n");
	}

	long long i = 3;
	while (i*i <= tofactor) {
		if ((tofactor % i) == 0) {
			tofactor = tofactor / i;
			printf("%lld\n", i);
			continue;
		}
		i+=2;
	}
	printf("%lld\n", tofactor);

	exit(0);
}


pm215 will almost certainly now point out a bug in it. Like the fact that it loops infinitely if you input 0.

Date: 2008-07-29 04:09 pm (UTC)
chrisvenus: (Default)
From: [personal profile] chrisvenus
Well, my final approach was even simpler than that:


chris@the:~$ factor 07775771223
7775771223: 3 11 19 37 571 587

Date: 2008-07-29 04:12 pm (UTC)
From: [identity profile] onebyone.livejournal.com
Well if you knew that was there (which I didn't), why did you go looking for javascript versions? ;-)

Date: 2008-07-29 04:16 pm (UTC)
chrisvenus: (Default)
From: [personal profile] chrisvenus
My google fu was weak. It threw up javascript ones only first. It was only when I realised how bad all the web based ones seemed that I realised you must have had a different way and googled further. I had assumed until your comment that my last method was the one you had used. :)

Date: 2008-07-29 04:16 pm (UTC)
From: [identity profile] venta.livejournal.com
Interesting to note (or not) that this Code of Awesomeness arrived in an email comment, and I really couldn't make head nor tail of it. Which worried me rather.

I'vev just seen it here - ie with the formatting correct - and it's easily readable.

I've never met a more convincing argument for nice, tidy indenting :)

Date: 2008-07-29 04:32 pm (UTC)
From: [identity profile] onebyone.livejournal.com
I also note that I now have an upper bound on how long a brace-formatting standard lasts before I revert to modified K&R.

Date: 2008-07-29 04:36 pm (UTC)
From: [identity profile] venta.livejournal.com
modified K&R

... or "the right way", as it should more commonly be known ;)

Date: 2008-07-29 04:39 pm (UTC)
pm215: (Default)
From: [personal profile] pm215
Since you asked:
* giving it the argument 0 makes it loop forever printing out '2's
* for powers of 2 it prints a spurious '1' factor
* non-numeric arguments are silently accepted and treated as 0
* it accepts negative arguments, which it probably shouldn't

:-)

Date: 2008-07-29 04:46 pm (UTC)
From: [identity profile] onebyone.livejournal.com
I refer you to the white-on-white text at the end of the post containing the code.

I do count the spurious 1 as a bug, actually.

Date: 2008-07-30 12:35 am (UTC)
From: [identity profile] onebyone.livejournal.com
non-numeric arguments are silently accepted and treated as 0

I think actually they're silently accepted and an uninitialised value is factored. sscanf doesn't do the same thing as atoi when it can't find the format it's looking for.

Profile

venta: (Default)
venta

December 2025

S M T W T F S
 123456
78910111213
14151617181920
212223 24252627
28293031   

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Dec. 27th, 2025 05:47 am
Powered by Dreamwidth Studios