Hey you!

Postcards are cool! Go send some ->

postme.me

Lychrel numbers

Jan 27 2012

Last night I discovered another cool mathematical concept akin to the Collatz conjecture - Lychrel numbers.

Collatz map fractal in a neighbourhood of the ...

Image via Wikipedia

The idea of a lychrel number is pretty straightforward: Take a number, add its reverse, continue until you reach a palindrome number. If you never reach a palindrome, then this is a Lychrel number.

Something like this:

349 + 943 = 1292,
1292 + 2921 = 4213
4213 + 3124 = 7337
not lychrel

If you’ve ever done any theoretical computer science, you’ll immediately spot a problem. This isn’t a very good algorithm. Problem is with that “never” word in the description – an algorithm is a finite set of steps, when you need an infinite amount of steps to reach a conclusion that’s … not very useful.

Honestly I am not certain what class of problems lychrel numbers fall into. The “not a lychrel number” is a half-decidable problem. It will always tell you when a number is not lychrel but it will never terminate when it is. If my understanding is correct, this would make “is a lychrel number” an non-decidable problem.

Project Euler is kind enough to limit the problem a little bit and make it a fun algorithm to write before bed when your brain is half dead. Find all lychrel candidates under 10,000 assuming it should never take more than 50 iterations.

Solving that problem becomes rather trivial in Haskell:

 
reverse' = read . reverse . show
 
palindrome n = n == reverse' n
 
-- max denotes max recursion depth
lychrel n max
  | max <= 0 = True
  | palindrome$n+r = False
  | otherwise = lychrel (n+r) (max-1)
    where r = reverse' n
 
lychrels max =
  length [x | x <- [1..max], lychrel x 50]

Oh and actually the first number that needs more than 50 iterations to converge into a palindrome is 10677, so the problem is pretty safely stated.

For a final bit of fun, the number 4994, itself a palindrome, is a lychrel candidate.

Enhanced by Zemanta

One response so far

A month wasted

Jan 26 2012

This post is about exams, being in college and jumping through arbitrary hoops set up by arbitrary old men so they can feel arbitrarily important. But most of all it’s about everyone wasting a month of their lives for something that surely a better alternative exists for. I may have written about this before.

English: A crowd has gathered to take part of ...

Image via Wikipedia

I am notorious for sucking at passing exams. I am perhaps even more notorious for disrespecting authority and arbitrary tests of skill. There might be some bias. You have been warned.

My hate of tests started early, when I was doing those aptitude tests for first grade I stopped after five minutes saying something like “Here. That’s enough for you. Bye”.

When you do that at six the examiner goes “Oh my! What a smart little boy, so defiant and thinking for himself!”, at 24 the usual reaction is more along the lines of “Omg what an idiot, who let him out of grade school? The guy can’t even solve the simplest of problems!”

However, exams are upon us and it is once more time to jump through hoops and prove ourselves worthy of being allowed to jump through some more hoops. Just so old men can pat each other on the back and feel good about having taught people something.

A waste of time!

I don’t think there’s a single person in the world who likes exam season, not even the professors and teaching assistants. Just a week ago everyone’s lives were better.

The professors were working on their research and figuring out cool ways to impart knowledge on young impressionable minds. The teaching assistants were also working on their research, while doing a bit of slave work for the professors, imparting knowledge on young impressionable minds and possibly grading some homework.

Most of the students‘ lives revolved around going to class and having knowledge imparted on their young impressionable minds. Some of them were doing research on the side, or some sort of pet project or another, some have jobs – most of them working on exactly the kind of thing they’ll be doing after they graduate – at least that’s how it is in my line of work.

The better students were also studying the more interesting subjects in more detail, because what is said in class just doesn’t feed their hunger for knowledge.

English: School children doing exams inside a ...

Image via Wikipedia

Some of the students – there might be less of these now that I’m not a freshman anymore – had impressive WoW and Skyrim characters.

Enter exam season, stage left, all our lives got twisted upside down.

Suddenly everyone’s productive lives are put on hold for a month while we take the time to jump through hoops and politely ask permission to jump through more.

For a month:

  • professors have to observe students jump through hoops instead of advancing their field
  • teaching assistants must create those hoops and grade the jumping instead of doing research
  • instead of going to cool lectures, students must study
  • instead of being productive on cool projects, students must jump
  • when a hoop is presented a student must not ask “Why the fuck?”, no, they must ask “Can you please turn that on fire as well? And can I do a piruette through it please?”

It’s insane. And stupid.

You come there, often times early in the morning, and are given an exam. Then you are expected to solve four tasks. Each of them must be solved perfeclty on the first try. You have 90 minutes. Good luck.

Remember how they say interviewing candidates should not be based on trivia knowledge or solving “simple” tasks perfectly on the first try under time and situation pressure? [Joel on Software - Guerrilla Guide to Interviewing]

Then why is it considered a good idea to test knowledge of _a whole subject_ like that? There’s no way a normal human being even stands a chance.

I’m lying, of course there is.

English: A wall of "ema" votive plat...

Image via Wikipedia

When you dumb down the whole field into formulaic application of a few algorithms and memorizing a few equations, suddenly everything becomes testable like that. But is this really in the spirit of what we’re trying to achieve here?

I mean, we are, after all, trying to prove who is and who isn’t worthy of being the creme of high thought in this nation and who gets to advance the field, funding for research, stuff like that.

A bunch of mindless automatons following instructions and dutifully obeying authority are sure to do just that! Wait, why do we have computers again?

I can understand this happening in high school … a bit … but college? Seriously? Your idea of a good college education is making sure I know how to follow instructions and apply some basic proofs/algorithms/formulas by hand?

Fuck. That. Shit.

Is there a solution? I don’t know, but I’ve always liked the idea of being given a semester to do a big project involving what we’re being taught in class. It’s a lot more interesting and a better way to learn about something.

PS: there are many bright exceptions to this behavior at my college, it’s just that none of those exams stick in memory because I pass them with a good grade almost without trying.

Enhanced by Zemanta

5 responses so far

A visit to the dentist

Jan 25 2012

It took me six months to work up the courage to make an appointment for the dentist. After some initial confusionI finally managed to bump into someone and magically make an appointment before I could realize what was going on.

An image from 1300s (A.D.) England depicting a...

Image via Wikipedia

I was told to come back in a month.

Today.

The experience taught me two things:

  1. My teeth are made of magic
  2. I am far more afraid of dentists than I had thought

Ever heard of the expression white with fear? Turns out it can actually happen. Just like Tom turns completely white when a train is rushing towards him, so too my face turned white when I was sitting in that damn chair. Nearly fainted too.

I never did like dentists much – seven years since my last appointment after all –  but to nearly faint from fear? Nausea, tunnel vision, white face; the whole shebang! Didn’t even feel that bad, but you know shit’s going down when the dentist removes your glasses “just in case” and puts a wet rag on your forehead.

Lucky for me, I have magical teeth and the tally from all the years of neglect is just:

  • one broken filling
  • three wisdom teeth with some caries
  • inflamed gums

None of that OMG my wisdom teeth are breaking my head and trying to destroy everything!!! I honestly expected much worse, but hey, I’ll take the deal ;)

It also turns out I suck at keeping my mouth open and will be having much fun the next time I visit … something about working on the back teeth and not being able to get the drill completely vertical and maybe not even being able to work on them …

Now my face feels funny from the injection, the optional injection. Can’t imagine the amounts of pain there would be had I not told them that yes, yes I do want that injection thing. You did notice I almost fainted when you were just cleaning my teeth right? WHY ARE YOU ASKING ME THIS!?

Those things take a while to really kick in. She was almost done drilling before I stopped feeling everything and even then just the air blowing over my teeth hurt like hell. Not to even mention the disinfectant.

Another appointment in a few weeks and then I guess I’m good to go for another seven years. Right?

Enhanced by Zemanta

2 responses so far

I Don’t Know

Jan 24 2012

I. Don’t. Know.

Three simple words. Almost impossible to say. As developers, as entrepreneurs, as men we never want to admit we don’t know. If you don’t know, you are weak and an army of angry huns will come to steal your women, your business and your honor.

When founders don’t know what the hell they’re doing, people leave, investors say “maybe” and users aren’t showing up. Especially if they openly admit they don’t know.

But just as some consider not knowing a sign of weakness, always knowing is definitely a sign of weakness. Selling your best guess as absolute fact works very well in the short term, in fact it works spectacularly well – there’s a reason there are whole books devoted to the practice of eliminating excuses from your speech. Phrases like  I think, in my opinion et cetera.

Island of knowledge

Island of knowledge

While it’s important to commit to what you say without hedging and ways to weasel out when you’re proven wrong. It’s even more important to admit when you don’t know. In fact all that hedging just defends you from admitting you are wrong and don’t know.

The best thinkers of our species, like Feynman, Einstein and others, are glorified for their ability to embrace what they don’t know. To look ignorance straight in the face and spit in its eye. Most of us cower from such an opportunity, we like nothing more than to stand firmly in the middle of what we know and never looking beyond the horizon lest there be monsters.

Someone once said Every man lives on an island of knowledge in a sea of ignorance. The bigger your island, the longer the shore of ignorance.

Most people can’t even comprehend how much they don’t know about a subject, because the more you know about something, the more you understand the intricacies involved. A common saying amongst developers is What the fuck man!? How can That Startup spend so much money on that simple problem, it’s just <x>, <y>, <z> and you’re done. I could do it in a week!

Chances are, you don’t know what the hell you are talking about. The hardest problems seem the simplest when given only a cursory glance. So put down the ego for a moment and prove it. Prove that the problem is simple.

You can’t learn what you already know. ;)

Enhanced by Zemanta

2 responses so far

Appcelerator Titanium might’ve made it to my toolbox

Jan 23 2012

Last time I played around with Appcelerator Titanium I didn’t get a chance to really put it through its paces. Mostly because I wasn’t getting anywhere … I remember spending hours, even days, just figuring out how to get a Hello World to run in a simulator.

MoBods Scoop! Development ;-)

Image by Podknox via Flickr

Yesterday was my lucky day! Not only did I get something to run, I actually made something useful. Or rather, I was given a working app and told to add some features and generally make it better a tiny little bit.

Took me way too long – expected when dealing with technology you know nothing about – but at 6am today I had Pickup connecting to the server on the user’s own private channel and talking nicely to the Chrome extension.

By the way this isn’t my project, I just helped out, but from what I saw last night, you want to sign up for the beta. Promise!

Titanium good

  1. It’s Javascript, if you haven’t noticed I love javascript
  2. The same app works both on android and iOS
  3. Titanium API’s are generally simpler than what I’ve seen of native iOS
  4. Properly using the user interface API’s gives you a native look&feel

Titanium bad

  1. The IDE; I don’t like being forced to use an IDE and I very much hate being forced to use a crappy IDE.
  2. Everything looks like it would be pretty much impossible to develop with my usual text editor method
  3. Code once, run everywhere is good in principle, but it usually ends up lacking the polish of a real native app, especially since android and iOS have slightly different UI guidelines and traditions

Conclusion

All in all,  there’s a lot of potential in this Titanium stuff despite the shortcomings. I might just start adding a mobile part to my future projects … there’s certainly some that could use it.

Enhanced by Zemanta

No responses yet

This Haskell is wrong. Why?

Jan 20 2012

English: 5D virtual 3^5 sequential move puzzle...

Image via Wikipedia

The problem I’m trying to solve is the simple but lovely euler 62.

The cube, 41063625 (3453), can be permuted to produce two other cubes: 56623104 (3843) and 66430125 (4053). In fact, 41063625 is the smallest cube which has exactly three permutations of its digits which are also cube.

Find the smallest cube for which exactly five permutations of its digits are cube.

A bit of fun coding after a statistics midterm last night and the solution should be in the bag. Except it isn’t, I am doing something wrong somehow and I can’t figure out what! Hopefully someone a bit better than me can shed some light whether my proposed solution is wrong or I just suck at Haskell.

Algorithm

  1. Generate cubes up to 10,000
  2. Every cube is a pair of a digit-ordered string n^3 and n, for instance (“279″,9)
  3. Order cubes by the string number presentation
  4. Group together all cubes with the same n^3
  5. Pick out groups with the size of 5
  6. Sort by n
  7. Pick the smallest number

Should work in principle right? So why doesn’t the website accept my answer (5027)? My guess is I’m doing something wrong in the sorting and grouping department and I was hoping someone with a bit more knowledge of Haskell could point out where I’m being stupid.

Code

import Data.List
 
cubes::(Num a) => a -> [(String, a)]
cubes 1 = [(show 1, 1)]
cubes n = (sort$show(n^3), n):(cubes $ n-1)
 
sortStrNum (s1, n1) (s2, n2)
  | length s1 == length s2 = compare s1 s2
  | otherwise = compare (length s1) (length s2)
 
permuted_cubes n =
  groupBy (\a b -> fst a == fst b) $ sortBy sortStrNum $ cubes n
 
fives n =
  filter (\xs -> length xs == 5) $ permuted_cubes n
 
comparing p x y = compare (p x) (p y)
 
smallest =
  head $ sortBy (comparing snd) $ head $ fives 100000

The whole thing looks kind of alright to me, no matter how much I poke around it doesn’t seem like something is misbehaving … but it still is.

Ideas?

Enhanced by Zemanta

4 responses so far

Blogging, hats, stuff

Jan 19 2012

Presenting

Presenting

Yesterday I gave a talk at Kiberpipa on the awesome #wwwh weekly event. The talk was about this blog and how after that one insanely popular posteveryone suddenly decided I know what I’m doing and should tell others how its done.

Video at bottom

It’s funny how difficult coming up with a talk is when somebody tweets you Hey, you should totally come give a talk about blogging. The problem with these kinds of talk is that you don’t really know what you’ll be trying to say. Every time you’re up there on stage you should have a message – something to convince the audience of.

Just giving a general talk sucks for that. It invariably turns into something a bit like this post – a rambling conglomerate of sentences that sort of go together. Always reminds me of that one line in a movie: You talk a lot, but you don’t say much.

I guess the overall message of my talk was this:

Patience! It takes a lot of patience and sticking-to-it-ness, don’t do if it isn’t inherently fun for you.

Despite all of that I think the talk was a smashing success. Sure I forgot to even mention hats – was supposed to mention changing the blog’s name from Cthulhu and Other Crazies to A Geek With a Hat … oops? In general the talk ended up a bit rambley, even finished with “Wait, there was something else I wanted to say … oh well. Questions?”

That’s not a very strong ending. The originally planned ending was: But hey, at least I’m no longer The Author on hackernews, but Swizec

All in all, rhetoric sucked, body language was attrocious, hands found their way into pockets several times, but people laughed a few times, asked a bunch of questions and I think everyone had fun. This one girl even asked for actual advice and I thank her for thinking I know enough to give advice about this stuff.

The slides for Blogging, hats, stuff are over at Speakerdeck whose embeds don’t work with WordPress … there is also a video.

Enhanced by Zemanta

2 responses so far

Are you a boy scout coder?

Jan 17 2012

The Boy Scouts have a rule: “Always leave the campground cleaner than you found it.” If you find a mess on the ground, you clean it up regardless of who might have made the mess. /../ the original form by Robert Stephenson Smyth Baden-Powell, was “Try and leave this world a little better than you found it.”

What if we followed a similar rule in our code: “Always check a module in cleaner than when you checked it out.” No matter who the original author was, what if we always made some effort, no matter how small, to improve the module. What would be the result?

by Uncle Bob at O’Reilly commons

Lieut. Gen. Robert Stephenson Smyth Baden-Powe...

Image via Wikipedia

When I first saw this rule in Clean Code I loved it! It’s just such an awesome rule. You come into a file, you clean it up a little bit. Remove a stupid comment, indent something better … anything.

It makes the world a better place and everyone a happy camper right?

Well, this might be great in theory and work well when you are employed by a company where you will spend the next few years of your life. The software you’re working on will live and grow with you, with your team. You are the guy shouting “Fuck this! Who the fuck made this code! This is bloody impossible to maintain!” a year from now.

For a freelancer the situation is a bit different.

Here you are, plomped into the middle of an ongoing project. Decisions have been made, rabbit holes have been followed. The deadline is in a month and as a crack team of one specialist on a tight deadline, you’re making nice gold per hour.

Right there in front of you. A mess. Code so ugly, so horrible, it would make a grown man cry. You’re just supposed to add a feature. Figure out the mess, add two or three lines of code, cross your fingers and hope for the best.

Or should you rewrite the whole function?

Rewriting would be the Right Thing ™ to do. The code will be more maintainable, easier to test, it will save your client a bunch of money down the line. You won’t be maintaining this so you have a responsible towards everyone coming after you to fix something.

But, right now, right this very instance, you are strong-arming the poor client to pay more. Sure, you’re making the code better, but they care about that one feature. Should you really spend three hours rewriting the code instead of one hour adding something and hoping for the best?

On the other hand: When the messy code breaks, and it will break, it will be your fault. You’re the last guy who touched it. Not rewriting will come back to haunt you. The guy who maintains your code will curse you in their sleep and dream of delicious murder. And it’s not even your code!

So what do you do?

Personally I always try to rewrite crappy code. Add testing suites. Anything I can do to make the codebase better. But I always carefully explain the situation to my client. Why am I doing this, how is it benefiting the client. It’s important to make them understand I’m not just inventing work to rake in more gold.

Clients are surprisingly permissive most of the time and I can sleep better at night. win-win!

Enhanced by Zemanta

22 responses so far

Shoes

Jan 16 2012

Shoes are wonderful technology, they protect our feet, they make us look good and there’s a whole culture associated with wearing those things. A culture I, as a man, will never understand.

Shoes on their deathbed

Shoes on their deathbed

Apparently there is a million and one way to wear the wrong kind of shoes to the wrong kind of outfit. For instance, my scruffy shoes … don’t go with any outfit. Or so I’ve been told. I like to think they go with every outfit exactly because they’re scruffy and falling apart. Gives them a bit of character.

But, they are about to die, so I have to find a replacement this week. The thing I don’t understand is: Why do women need so many? A good pair of black leather sneakers covers pretty much every occasion.

  1. They’re comfy, so you can use them for walking to places
  2. Because they’re black leather, they look nice when clean and can be used for business
  3. Because they look kinda nice, they can be used for semi-formal stuff too. Anything that isn’t black- or white- tie really.
  4. If you aren’t a sissy most sport can be done in them as well

The only other pair of shoes you might need is a pair of sandals, if you’re too sissy to go barefoot at the beach in the summer. And while some advocate using a pair of water-proof shoes for special weather, you don’t actually need that. Shoes dry out over night and pretty much all types of shoe I’ve seen gets soaking wet the moment you start thinking of them as being water-proof.

Rubber boots old people use for gardening might be an exception, but those get soaking wet from the inside anyway, so what’s the point?

Last night I asked an internet about the need for multiple shoes and got a rather interesting answer from some girl:

For me I think I have

3 pairs of heeled sandals (to wear with skirts, dresses, or summer clothes)
2 pairs of flip flops
4 pairs of black boots
1 pair of grey boots (for when black doesn’t work with what I’m wearing)
2 pairs of black heels (for dress or black dress pants, ones more business then the other)
2 pairs of black low heeled shoes (business or going somewhere that might include walking)
1 pair of tennis shoes
1 pair of pink heels
1 pair of cobalt blue heels
1 pair of teal heels
2 pairs of low heeled dance shoes
2 pair of latin heeled dance shoes
1 pair of jazz
1 pair of highland
1 pair of low heeled sandals

Those are the ones I can think of off hand.

That’s just too many shoes! Where does she even keep them all? And who has time to buy all those things anyway? And the mental energy it takes to go out and look for shoes … women are truly insane.

An answer from the most well-dressed guy I know was far better in my view:

In general, men don’t need too many shoes short of shoes needed for hobbies. I have two pairs of black shoes, two pairs of brown shoes, and a pair of evening shoes; the rest are activity-specific. Riding boots, hiking boots, dance shoes, boat shoes, cold/wet-climate hiking boots, and so on are only necessary for specific purposes.

That makes sense, having shoes for specific purposes doesn’t really count as having another pair of shoes does it? I certainly wouldn’t think of listing my diving fins or rollerblades under “pairs of shoes” even though they are technically footwear …

Now excuse me while I go meditate on my misery of having to buy a new pair of shoes this week.

Enhanced by Zemanta

5 responses so far

Why you don’t exercise every day

Jan 15 2012

Because you are an idiot.

Can you save a life?

Can you save a life?

But that’s harsh, so let me explain why this makes you an idiot. There was an article posted to HN yesterdayabout why people don’t go to the gym, it included a simple motivational technique of paying yourself to go.

After commenting that the only thing it takes to go to the gym every day is to go to the gym every day, I was downvoted to oblivion. But there’s really nothing more to it than that. You can sugar coat it whichever way you want, you can come up with dozens of motivational techniques – in the end, all it takes is going.

Even if you don’t go to the gym every day, you should still make sure to exercise daily. Here’s how you do it:

  1. Day 1 – exercise when you wake up
  2. Day 2 – exercise when you wake up
  3. Day 3 – exercise when you wake up
  4. Day 4 – eh you’ve exercised three days in a row, might as well do it again
  5. Day N – do the default thing [of exercising]

After a couple of days you have to make a conscius effort not to exercise. The default action is simply to exercise and as humans we love nothing more than not having to make a decision. This is also known as the Seinfeld motivational technique by the way.

Exercise also does a better job of waking you up than coffee, thought I’d mention that.

BUT!

I don’t have time

Richard Branson is one of the busiest humans alive, this is what he has to say about exercising daily:

Tim Ferriss tells this story about how Richard Branson was once asked the single biggest thing most people could do to increase productivity. Due to the fact that he’s one of the busiest men on the planet, every single person in the audience leaned forward with bated breath. His answer? Exercise daily. It improves the quality of your sleep, so you need less. It makes you more emotionally stable, so you’re more motivated. And most importantly, it increases mental clarity, so you’re more focused through-out the day. Branson said that it gives him multiple hours more productivity every day. It’s bull to say you don’t have enough time every day to exercise; if you’re that busy then in fact you don’t have enough time to NOT exercise.

And if you’re anything like the average person who spends a bunch of time commuting, watching television and browsing the online … you have no right to complain about lack of time.

It cuts into family time

A popular complaint in the HN discussion was that exercise cuts into quality time with their families.

Sure … but one day your building will catch fire, or you’ll have a car crash, or _something_. Can you be there for your family when family time involves saving the people you love from death?

No, your flabby office worker muscles won’t cut it and that beer+pizza belly won’t help either. Every man should be able to save his life, and the lives of those he loves! Since this is the 21st century, women should too.

Exercise is hard!

Nobody cares. You’re fat, you’re flabby and you are useless in an emergency. Spending 30 minutes every day doing some basic exercises is nothing compared to the dividends it pays in pretty much all areas of your life.

And if you don’t care about any of that, then do it to make the world a prettier place, one flabby human at a time.

Enhanced by Zemanta

3 responses so far

Older »

« Geeks of america, please start... Shoes »