Here is a small script I wrote for the fun of it. Originally I wanted to put it on twitter, but it got a bit too large for it. This made the code very compact, but also quite unreadable. However, I just made a blog post on it, and don't plan to expand or modify it any further. Pretty simple being, it converts a string to a Lempel-Ziv-Welch (LZW) encoded (semi-human-readable) string. Enjoy.
# Variable initialization
s = 'to be or not to be. ' * 100
t = ''
d = ['']
c = ''
l = false
# Algorithm
s.each_byte do |b|
l = true
t << b.chr
unless d.include? t
d.push t
c << d.index(t.chop).to_s << t[t.length-1].chr
t = ''
l = false
end
end
if l == true
c << d.index(s[s.length-1].chr).to_s
end
# Output
puts 'original: ' << s.length.to_s
puts 'compressed: ' << c.length.to_s
p c
The benefit of this 'compression' isn't high, but it's something. For example, "to be or not to be. " is converted from 20 to 27 "compressed" characters. However, the same phrase, but used 100 times in succession (as in the example) gets compressed from 2000 to 846 characters.

6 comments:
Freak :D
Okay, I'm not much better. I started again coding Assembler on friday ;P *love the old Zilog Z80*
Aw, I currently only have experience with Intel 8088's and the like. Assembler is totally funny until you ram your head into the wall.
Ruby's actually the only truly "pretty" language I've ever seen :P
Not to bring this up out of the blue, but do you ever plan on returning to libwiisprite? There have been a couple of interesting unofficial updates, and to this day I still think it is the best game programming library for Wii Homebrew out there right now. Far more useful than GRRLIB and libwiigui.
Oh, I thought libwiigui was fairly feature complete? I haven't yet looked at the structure of libwiigui, but it seemed more than usable for me.
Actually, I have been playing with the idea, but I don't have too much time for it and my build system I used last time is also not what it once was. I will look into libwiisprite again once I find some time for it (first thing to do would be a 'lil bit cleaning and restructuring some parts I don't like. Hrmpf)
I have a few issues with libwiigui.
1)I still haven't gotten anything to render with it. It lacks an object (you had GameWindow) that that takes care of video initialization and leaves you to do your own. However, it does need some sort of initialization somewhere for the library so I think my rendering problem is related to that.
2)It lacks a proper sprite class. I actually did write a wrapper (which was really simple to do in the end - Just add collision routines to GuiImage) but confusing as hell to get to the end. However, because of 1), I still haven't tested it.
3)Less is more sometimes ;)
4)It's very confusing overall. It took me days of staring at it to even get started trying to program with it. Now that I have, I'm not sure what I'm doing wrong :S
Despite this, if you can get past it's initial frustrations and add a working sprite class, it probably is the most feature complete library out there. It even has sound support :O
I was working on some simple programs with it to demonstrate to others how to use the library, but I haven't had much time and I still have the rendering issue :S
Great to hear libwiisprite is still in your thoughts :D I'd be willing to help out a little, so let me know if you ever need anything.
BTW are you still thinking about galaxy stations?
I'm getting a lot of queries related to Galaxy Stations lately, so of course I'm thinking about developing on it further.
However, I have other ideas, as for example switch development to PC, to get a larger developer and of course user base. Lots of people I know don't own a Wii, so that's kinda the reason.
Post a Comment