You are not logged in.

#1 2009-02-24 09:09:26

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

a simple game: name that pkg

I don't know what gave me this idea, but here it is anyway... a simple multiple choice game that presents a package description followed by 4 package names. All  you have to do is pick the right name.

By default it uses locally installed packages. You can pass it the option "--all" to use all packages from the sync database. Passing it a number will change the number of default options.

It keeps track of the number of correct answers and winning streaks. It's not difficult because many of the package descriptions mention the package. Some of them are tricky though, and it can be interesting to see the descriptions of some of the things on  your system.

At the end of the day though, this is basically pointless.


name_that_pkg.pl

#!/usr/bin/perl
use warnings;
use strict;

use Term::ANSIColor;


my $info = (grep {$_ eq '--all'} @ARGV) ? `pacman -Si` : `pacman -Qi`;
push @ARGV, 4;
my $a = (grep {($_ =~ m/^\d+$/) and $_ > 0} @ARGV)[0];

my @list;
my $name;


$info =~ s/\n\s\s+/ /g;
foreach my $line (split "\n", $info)
{
  if ($line =~ m/^Name\s+:\s+(\S+)/)
  {
    $name = $1;
  }
  elsif ($line =~ m/^Description\s+:\s+(.+)$/)
  {
    push @list, "$name : $1";
  }
}


my $n = scalar @list;
my ($correct, $total, $streak, $best_streak) = (0,0,0,0);

my $ans;
while (1)
{
  my $c_name;
  my $c_desc;
  my @names;
  my $c = int(rand($a));
  for (my $i=0; $i<$a; $i++)
  {
    my ($name,$desc) = &split_line($list[int(rand($n))]);
    if (grep {$name eq $_} @names)
    {
      $i--;
      next;
    }
    push @names, $name;
    if ($i == $c)
    {
      ($c_name,$c_desc) = ($name,$desc);
      $c_desc =~ s/\Q$c_name\E/*/gi;
    }
  }
  print "description: $c_desc\n";
  my $j = 1;
  foreach my $name (@names)
  {
    print "$j) $name\n";
    $j++;
  }
  print "x) exit\n";
  print "answer: ";

  my $ans = <STDIN>;
  chomp $ans;
  last if (lc($ans) eq 'x');

  $total++;
  print "\n";
  if ($ans == $c + 1)
  {
    $correct++;
    $streak++;
    $best_streak = $streak if ($streak > $best_streak);
    print color ('bold green'), 'correct', color ('reset'), "\n";
  }
  else
  {
    $streak = 0;
    print color ('bold red'), 'incorrect', color ('reset'), " (answer: $c_name)\n";
  }
  print "current score: $correct/$total ",int(100 * $correct / $total),"%\n";
  print "current streak: $streak\n";
  print "best streak: $best_streak\n\n";
}

sub split_line
{
  return ($_[0] =~ m/^(\S+) : (.+?)\s*$/);
}

Last edited by Xyne (2009-02-24 19:08:51)


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#2 2009-02-24 10:27:39

robmaloy
Member
From: Germany
Registered: 2008-05-14
Posts: 263

Re: a simple game: name that pkg

lol

great game,
maybe you should out-regex package names from descriptions:

description: Libassuan is the IPC library used by some GnuPG related software
1) libassuan
2) binutils
3) fontconfig
4) thunar-archive-plugin
x) exit


☃ Snowman ☃

Offline

#3 2009-02-24 12:39:56

u_no_hu
Member
Registered: 2008-06-15
Posts: 453

Re: a simple game: name that pkg

May be you can strip the name of the package from the description....See below!!

description: xbindkeys allows you to launch shell commands with your keyboard or your mouse under X Window
1) dosfstools
2) xbindkeys
3) xdialog
4) virtualbox-ose
x) exit
answer:

Don't be a HELP VAMPIRE. Please search before you ask.

Subscribe to The Arch Daily News.

Offline

#4 2009-02-24 13:40:30

bender02
Member
From: UK
Registered: 2007-02-04
Posts: 1,328

Re: a simple game: name that pkg

Well if package names would follow arch packaging guidelines, this wouldn't happen wink

Offline

#5 2009-02-24 13:41:24

ArchArael
Member
Registered: 2005-06-14
Posts: 504

Re: a simple game: name that pkg

lol

Most of slackware users would really appreciate this game.

Offline

#6 2009-02-24 14:12:40

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: a simple game: name that pkg

Have you considered seeking therapy for having too much time on your hands?

Offline

#7 2009-02-24 17:40:01

evr
Arch Linux f@h Team Member
Registered: 2009-01-23
Posts: 554

Re: a simple game: name that pkg

this is awesome, haha.  I must agree that you have too much time on your hands though smile

Last edited by evr (2009-02-24 17:40:14)

Offline

#8 2009-02-24 18:23:50

shining
Pacman Developer
Registered: 2006-05-10
Posts: 2,043

Re: a simple game: name that pkg

bender02 wrote:

Well if package names would follow arch packaging guidelines, this wouldn't happen wink

I guess we had to wait for Xyne's game to really understand the full value of this guideline.


pacman roulette : pacman -S $(pacman -Slq | LANG=C sort -R | head -n $((RANDOM % 10)))

Offline

#9 2009-02-24 19:11:06

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: a simple game: name that pkg

It's not that I have too much time on my hands (the opposite, actually), just that I'm easily sidetracked. This only took 10-15 minutes anyway.

I've updated the script to replace the package name with "*", which works well enough for most descriptions with some notable exceptions:

description: * is a language and envi*onment fo* statistical computing and g*aphics
1) shared-mime-info
2) gen-init-cpio
3) r
4) medit

Last edited by Xyne (2009-02-24 19:13:17)


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#10 2009-02-24 23:16:46

Ghost1227
Forum Fellow
From: Omaha, NE, USA
Registered: 2008-04-21
Posts: 1,422
Website

Re: a simple game: name that pkg

description: None
1) dcraw
2) dmraid
3) perl-bit-vector
4) tidyhtml

...so not helpful...


.:[My Blog] || [My GitHub]:.

Offline

#11 2009-02-24 23:33:22

dyscoria
Member
Registered: 2008-01-10
Posts: 1,007

Re: a simple game: name that pkg

description: Gives a fake root environment, useful for building packages as a non-privileged user
1) fakeroot
x) exit

This game is too easy tongue


flack 2.0.6: menu-driven BASH script to easily tag FLAC files (AUR)
knock-once 1.2: BASH script to easily create/send one-time sequences for knockd (forum/AUR)

Offline

#12 2009-02-24 23:42:38

Ranguvar
Member
Registered: 2008-08-12
Posts: 2,549

Re: a simple game: name that pkg

This game is awesome!! Thanks, Xyne big_smile Pretty easy, yeah, but still funny.

And it's sweet that it also lets one find problematic names/descriptions in packages too big_smile

Offline

#13 2009-02-25 01:04:19

dannytatom
Member
From: Seattle, WA
Registered: 2009-02-02
Posts: 229
Website

Re: a simple game: name that pkg

Definitely a fun game, learned a few new things about some libraries that had been installed as deps. tongue


dnyy in IRC & Urban Terror

Offline

Board footer

Powered by FluxBB