Project Euler / programming problems

I think whatever option was about installing/upgrading everything.

It’s a little confusing that it returns you to that prompt afterward and you have to exit.

1 Like

I find the thing quite confusing.

It takes me to the command menu with the ascii art, asks me the “enter, 1, 3” question, asks me it a second time, tries to install something and fails, and complains that it can’t find a shortcut.

I’ve installed the devkit version, and the version without the devkit, gone through a wizard, and downloaded and unzipped the zipped version, and uninstalled everything about three times.

Cannot get it to work.

1 Like

This “Windows” program, try uninstalling it. I hear it causes many problems

6 Likes

That second time I think it’s just checking whether you want to do anything else and you should exit. Maybe that’s all you needed? Give it a reboot for good measure.

I’m going to just cut my losses for now and use Ideone. I’ll try again another day.

Black mark for accessibility though.

3 Likes
Ruby
def problem_1
	sumN = 0;
	
	for i in (3...1000).step(3)
		sumN += i;
	end
	
	for i in (5...1000).step(5)
		sumN += i if i % 3 != 0;
	end
	
	return sumN;
end

2 Likes

I was reading a bit about ruby. It’s funny but also cool to have .. and both work and do slightly different things :slight_smile:

3 Likes

Any idea why $i isn’t increasing in my Perl code on Ideone?

I’m trying to use Strawberry Perl but it’s not beginner-friendly.

I stuck a print $i; into the first for loop and it just gave me 0, 0, 0…

Huh. The TutorialsPoint interpreter admits that $i is increasing but won’t increment $sumN.

I think I should uninstall Strawberry Perl (which I was trying to use with Notepad++) and get the package that comes with Padre.

sub problem_1 {
	$sumN = 0;
	
	for ($i = 3; $i < 1000; $i += 3) {
		$sumN += i;
	}
	
	for ($i = 5; $i < 1000; $i += 5) {
		if ($i % 3 != 0) {
			$sumN += i;
		}
	}
	
	return $sumN;
}

Afaik c style for loops are looked down on in perl. That said I think you’re missing my before the $i init in both loops. Not sure though.

I was going off this page, that doesn’t mention my.

Here’s a better tutorial regarding for loops in Perl

2 Likes

Not sure then. I never tried these “online” compilers/executers. You should just run things locally.

my @a = (1..999);
foreach(@a){
	print("$_","\n");
}

Now that is some slick syntax

1 Like

Also microsoft is close to being done fully integrating linux into windows. If you go to windows features (can be found in control panel) and enable a feature that’s called something like “linux subsystem in windows”, wait for it to install, then you’ll get access to “bash” (idk the location but you can find it in the search), opening which will prompt you with some settings for the user, and after all of that you’ll be able to use an entire subsystem of debian (or have they stuck with ubuntu specifically?) through that terminal natively, no virtual machines needed. You can use that for programming because linux is made for programmers and it’s very comfortable to work in.

2 Likes

I know they worked with Canonical (for the uninitiated, the company that makes Ubuntu) to get this feature running, and it’s Ubuntu by default, but it looks like you can pick a different distro if you want:

I installed Padre with Perl, and I ran the C-style code again, and I even added the my specifiers.

It still does what the TutorialsPoint online compiler did: increments $i but doesn’t increment $sumN. I don’t get it.

OH! MISSED A SIGIL REEEEEEEEE

Shouldn’t it be dollar sign i? I wonder what it thinks it is that it successfully ran.

1 Like

Hahaha, I’m happy it was that simple, even though I look like an idiot.

Just like missing atari.

i probably has the mathematical value. Which is why Ideone said I was trying to modify a constant.

I didn’t spot that either with the forum’s syntax highlight that is all grey to me basically, but it was very visible with the proper highlighting.

I even missed it twice.

Here’s the working code, covered with my blood, sweat, tears and other bodily fluids:

sub problem_1 {
	my $sumN = 0;
	
	for (my $i = 3; $i < 1000; $i += 3) {
		$sumN += $i;
	}
	
	for (my $i = 5; $i < 1000; $i += 5) {
		if ($i % 3 != 0) {
			$sumN += $i;
		}
	}
	
	return $sumN;
}