Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Toad King
Apr 23, 2008

Yeah, I'm the best

BonzoESC posted:

Write a program that reads positive integers from STDIN. For each integer, print the number of times the digit '1' occurs when counting from zero to that integer.

code:
in.txt:
1
2
5
20
30
40
82
10568

out.txt:
1
1
1
12
13
14
19
4786

code:
function countOnes(num)
{
	num = num.toString();
	var ones = 0;
	for (var i = 0, j = num.length - 1; i < num.length; i++, j--)
	{
		var power = Math.pow(10, j - 1);
		ones += power * j * num[i];
		if (num[i] > 1) ones += power * 10;
		if (num[i] == 1) ones += +num.substring(i + 1) + 1;
	}
	return ones;
}
that one actually took a while of thinking and trail/error to figure out

Adbot
ADBOT LOVES YOU

Toad King
Apr 23, 2008

Yeah, I'm the best
so the windows api has a function called GetGlyphOutline that can be used to get character glyphs from a font, which is just what i needed. but it only works for truetype fonts and just throws up an error on raster fonts. so i go off to find the raster font equivalent for that function

... oh, there is none.

:smith:

Toad King
Apr 23, 2008

Yeah, I'm the best

Gazpacho posted:

well yeah, because that information isn't in a raster font to be gotten

the actual part i was using was grabbing a bitmap of the glyph at a specified size, which seems like it would be easy to do for a raster font, but alas there appears to be no way to do it with the windows api

but i did find this when searching for a solution: http://wine.1045685.n5.nabble.com/Re-1-2-gdi32-GetGlyphOutline-should-fail-for-a-bitmap-font-td5675449.html

"well this is incorrect behavior but the correct behavior breaks other things soooooo gently caress it"

Toad King
Apr 23, 2008

Yeah, I'm the best

Tiny Bug Child posted:



tbc what do you think of php's use as a general scripting language? like for non-web stuff?

Toad King
Apr 23, 2008

Yeah, I'm the best

Tiny Bug Child posted:

well it's not as ideally suited to the environment as it is for the web but it works just fine. i wrote a desktop app using php-gtk once and it turned out ok

quote:

A Year Later...

[5-Aug-2010] Dropping by to let the PHP-GTK community know that development is still happening!

rofl

edit: oh hey lets see what wonderful apps people have made using php-gtk

Adbot
ADBOT LOVES YOU

Toad King
Apr 23, 2008

Yeah, I'm the best

Malcolm XML posted:

it's a halfassed solution which requires an entirely new infrastructure to run /quickly/

not gonna pretend to know how its implemented but this js vm guy seems to think "the implementation cost should be small compared to the potential upside" https://code.google.com/p/v8/issues/detail?id=2599

also lol native client did some poster really suggest that was a better solution than this?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply