in reply to Pimp my code - Schwartzian transform maybe?
It uses a lookup but also inverts the logic so that an 'R' will return a high number (yours returned 1). Any $flags string that contains an 'R' will be higher than any combination without an 'R' and so on for the others.
You would need to reflect the change in your sort routine.
I would consider processing these values beforehand maybe adding them to @tagIndexes.
Update:#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %flagvalues = ( R => 2**6, T => 2**5, B => 2**4, I => 2**3, F => 2**2, L => 1, ); my $flags = 'RRTBLXUC'; print flagValue($flags); sub flagValue{ $flags = shift; my $weight; my %unique_flags = map { $_ => undef } split //, $flags; for my $flag (keys %unique_flags){ $weight += exists $flagvalues{$flag} ? $flagvalues{$flag} : 0; # print "$flag -> $weight\n"; } return $weight; }
It also relies on any flag appearing only once.
Update 2:
Updated to only weigh a flag once.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Pimp my code - Schwartzian transform maybe?
by GrandFather (Saint) on May 08, 2006 at 12:05 UTC |