C# Challenge #1 – Blog Application


In an effort to commit myself to learning C# I am starting a series of challenges.  The first one is to create a simple blogging application.  Preliminarily I plan to include the following features:

  • Post creation/editing
  • Commenting
  • Subscribing
  • Login for admin
  • List of IPs for admin with the ability to block them

Think it will be pretty easy with ASP.NET backing my application.  The entire source will be available either on github or as a Visual Studio Project for downloading.  I’ll post updates on my progress.

Project Euler Problem 9 (in Haskell)


My solution to PE 9 can be found at:

https://github.com/austinprete/project_euler/blob/master/euler9.hs

Again, a very simple solution using list comprehensions.   I might look around and find other solutions to compare it to.  I came across this problem at the same time as reading Learn You A Haskell For Great Good, which solves a problem similar to this.  Whilst I didn’t look at the book’s code when I wrote this, I’m sure it’s similar.  For the sake of originality I might try solving it using a different method.

Project Euler Problem 6 (in Haskell)


My solution to PE 6 in Haskell can be found at:

https://github.com/austinprete/project_euler/blob/master/euler6.hs 

Another one line solution thanks to list comprehensions, one of my favorite features of Haskell.  I invite any other Haskellists with different ideas of how to solve this, or any other Project Euler problem I solve, to leave them in the comments of my posts.

Monty Hall Proof (in Python)


As a quick diversion from my Project Euler/Haskell posts, I’m writing an entry on my monty hall problem proof that I wrote in Python a little while back.  As I warned you in the past my programming skills are a little bit rusty*, and at the time of writing this solver it was my first Python code in about a year.  (*Arguably the product of switching between languages to often.)  Therefore the code is probably mediocre at best, which might be an overstatement.  Anyway, the following is the fairly simple python code.

def game():
	i = 0
	switch_car_count = 0
	car_count = 0

	while i < 1000:
		doors = ['goat', 'car', 'goat' ]
		rand = random.randint(0, 2)
		door = doors[rand]
		del doors[rand]
		doors.remove('goat')
		door2 = doors[0]
		i = i + 1

		if door == 'car':
			car_count = car_count + 1

		if door2 == 'car':
			switch_car_count = switch_car_count + 1
	return [car_count, switch_car_count]

def results(total_count, total_switch_count, compare):
	average_count = total_count / 1000
	average_switch_count = total_switch_count / 1000
	print average_count
	print average_switch_count
	print compare

def main():
	i = 0
	total_count = 0
	total_switch_count = 0
	compare = 0

	while i < 1000:
		[car_count, switch_car_count] = game()

		total_count = car_count + total_count
		total_switch_count = switch_car_count + total_switch_count
		i = i + 1

		if car_count < switch_car_count:
			compare = compare + 1
	results(total_count, total_switch_count, compare)

main()

This yields the output:

333
666
1000

These values respectfully represent average winnings with keeping original, average winnings with switching, and total number of times switching was the better yielding option.

This code should be fairly straight forward to anybody familiar with Python basics.  Any questions or suggestions about my code should be posted in the comments and I will hopefully reply promptly.

Project Euler Problem 1 (in Haskell)


I began solving the problems from Project Euler today and thought I’d document my solutions.  Because of WordPress’ lack for Haskell syntax highlighting and wanting to keep all my solutions in one place, the code can be found at:

https://github.com/austinprete/project_euler/blob/master/euler1.hs

Haskell’s list comprehensions lent themselves to this kind of problem and made the task trivial.   If I had any C# skills I’d write an imperative solution to see the code difference but I can’t say I do.   Guess that’s on the waiting list.


Welcome


Welcome to my blog!  I regularly swim in the waters of C# and Python and I have recently found the beautiful, functional oasis known as Haskell.  I’m in my teens and have only been programming seriously for a year so, in which time I’ve played around with a few too many languages to be particularly good in any of them.  That said, hopefully I can transform my thoughts and projects into a source of knowledge about .NET, Python, and Haskell.

Until next time,

Austin

Follow

Get every new post delivered to your Inbox.