LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > General
User Name
Password
General This forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!

Notices


Reply
  Search this Thread
Old 09-12-2009, 05:32 AM   #31
brianL
LQ 5k Club
 
Registered: Jan 2006
Location: Oldham, Lancs, England
Distribution: Slackware64 15; SlackwareARM-current (aarch64); Debian 12
Posts: 8,302
Blog Entries: 61

Rep: Reputation: Disabled

I thought it was an error message in Klingon:
You have moved the mouse. Windows will now shut down.
 
Old 09-12-2009, 06:45 AM   #32
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Debian Testing
Posts: 19,192
Blog Entries: 4

Rep: Reputation: 475Reputation: 475Reputation: 475Reputation: 475Reputation: 475
Ah, I have so few words of wisdom that it's nice to have them noticed
 
Old 09-12-2009, 08:30 AM   #33
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
Jiml8 good point on the don't subtract from space. Made a few more compact versions just for you

Code:
#!/usr/bin/perl

$var = "Doogsauumauipnt >)! Zov qatsfd!ovr!ieipt!fjlues >) Wiau brf zovr!tirfe!fbvprjtf uedhoidam copkt? Pmebsf jndlvdf bt!lfatt!ooe!spfuwbrf fnhioefrjnh copk- uhf ptiess!cbn!bf xhbtfvfr- j.f.- qhzsjct,!mbti,!euc/";
@lets = ($var =~ m/(.)/g);

for ($i = 0; $i <= $#lets; $i += 2) {
    next if ($lets[$i] eq " ");
    $lets[$i] = pack('c', unpack('c', $lets[$i])-1);
}

$ans = join('', @lets);
print "$ans\n";
and

Code:
#!/usr/bin/perl

$var = "Doogsauumauipnt >)! Zov qatsfd!ovr!ieipt!fjlues >) Wiau brf zovr!tirfe!fbvprjtf uedhoidam copkt? Pmebsf jndlvdf bt!lfatt!ooe!spfuwbrf fnhioefrjnh copk- uhf ptiess!cbn!bf xhbtfvfr- j.f.- qhzsjct,!mbti,!euc/";

for ($i = 0; $i < length($var); $i += 2) {
        next if (substr($var,$i,1) eq " ");
        substr($var, $i, 1, pack('c', unpack('c', substr($var, $i, 1))-1));
}
print "$var\n";
and finally (though this one suffers from the last character not being translated, and won't work in all perls)

Code:
#!/usr/bin/perl

$var = "Doogsauumauipnt >)! Zov qatsfd!ovr!ieipt!fjlues >) Wiau brf zovr!tirfe!fbvprjtf uedhoidam copkt? Pmebsf jndlvdf bt!lfatt!ooe!spfuwbrf fnhioefrjnh copk- uhf ptiess!cbn!bf xhbtfvfr- j.f.- qhzsjct,!mbti,!euc/";

$var =~ s/(.)(?{ $n = pack('c', unpack('c', $^N)-1); $n = " " if ($n le " ") })(.)/$n$2/g;
print "$var\n";
edit - added this one (just cause that pack/unpack looks ugly)
Code:
#!/usr/bin/perl

$var = "Doogsauumauipnt >)! Zov qatsfd!ovr!ieipt!fjlues >) Wiau brf zovr!tirfe!fbvprjtf uedhoidam copkt? Pmebsf jndlvdf bt!lfatt!ooe!spfuwbrf fnhioefrjnh copk- uhf ptiess!cbn!bf xhbtfvfr- j.f.- qhzsjct,!mbti,!euc/";

$var =~ s/(.)(?{ $n = chr(ord($^N)-1); $n = " " if ($n le " ") })(.)/$n$2/g;
print "$var\n";

Last edited by estabroo; 09-12-2009 at 11:08 PM. Reason: for the horde
 
Old 09-12-2009, 05:32 PM   #34
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
Well, alright. I can compress mine too. Readability doesn't suffer too much. I do have to declare variables though; compiler won't do it for me on the fly.
Code:
#include <stdio.h>
#include <string.h>
void main()
{
	char data[] = "Doogsauumauipnt >)! Zov qatsfd!ovr!ieipt!fjlues >) Wiau brf zovr!tirfe!fbvprjtf uedhoidam copkt? Pmebsf jndlvdf bt!lfatt!ooe!spfuwbrf fnhioefrjnh copk- uhf ptiess!cbn!bf xhbtfvfr- j.f.- qhzsjct,!mbti,!euc/",*linestart = data,*lineptr;
	for(lineptr = linestart;lineptr <= linestart + strlen(data);lineptr+=2){if(*lineptr != 0x20) --*lineptr;}
	printf("%s\n",data);
}
Since C doesn't have sophisticated string handling, I don't think I can squeeze much more out of this. Want to run some timing exercises and see which is faster?

Last edited by jiml8; 09-12-2009 at 05:51 PM.
 
Old 09-12-2009, 05:41 PM   #35
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
lol, now we just need an erlanger to one-liner it for us
 
Old 09-12-2009, 05:59 PM   #36
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
Wow. You posted fast. I updated my code after you posted, without being aware you HAD posted. Shortened it a bit more.
 
Old 09-12-2009, 06:28 PM   #37
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
hehe, I'd bet the C is faster. All of this reminded me of a great programming challenge site, its solving math problems (some of them are even crypto), the basic idea is to write a program in any language that'll solve the problem with a bonus challenge of making it run in under a minute.

http://projecteuler.net/
 
Old 09-12-2009, 11:02 PM   #38
Kenhelm
Member
 
Registered: Mar 2008
Location: N. W. England
Distribution: Mandriva
Posts: 360

Rep: Reputation: 170Reputation: 170
Using bash and tr
Code:
text='Doogsauumauipnt >)! Zov qatsfd!ovr!ieipt!fjlues >) Wiau brf zovr!tirfe!fbvprjtf uedhoidam copkt? Pmebsf jndlvdf bt!lfatt!ooe!spfuwbrf fnhioefrjnh copk- uhf ptiess!cbn!bf xhbtfvfr- j.f.- qhzsjct,!mbti,!euc/'

charset=$(echo -e "$(printf '\\x%x' {33..126})")
for ((n = 0; n < ${#text}; n += 2));do
  echo -n "${text:n:1}" | tr "$charset" " $charset"
  echo -n "${text:n+1:1}"
done

Congratulations =)  You passed our idiot filter =) What are your three favorite technical books? Please include at least one software engineering book, the others can be whatever, i.e., physics, math, etc.

Last edited by Kenhelm; 09-12-2009 at 11:23 PM.
 
Old 09-12-2009, 11:18 PM   #39
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
Got the regex one fixed now, shorter and handles that pesky last character.

Code:
#!/usr/bin/perl

$var = "Doogsauumauipnt >)! Zov qatsfd!ovr!ieipt!fjlues >) Wiau brf zovr!tirfe!fbvprjtf uedhoidam copkt? Pmebsf jndlvdf bt!lfatt!ooe!spfuwbrf fnhioefrjnh copk- uhf ptiess!cbn!bf xhbtfvfr- j.f.- qhzsjct,!mbti,!euc/";

$var =~ s/([^ ])(?{ $n = chr(ord($^N)-1); })(.?)|( .)(?{ $n = $^N })/$n$2/g;
print "$var\n";
 
Old 09-12-2009, 11:24 PM   #40
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
Wow Kenhelm, very nice, I wouldn't have given bash enough credit to be able to do it.
 
Old 09-13-2009, 11:59 AM   #41
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
Quote:
Originally Posted by Kenhelm View Post
Using bash and tr
Code:
text='Doogsauumauipnt >)! Zov qatsfd!ovr!ieipt!fjlues >) Wiau brf zovr!tirfe!fbvprjtf uedhoidam copkt? Pmebsf jndlvdf bt!lfatt!ooe!spfuwbrf fnhioefrjnh copk- uhf ptiess!cbn!bf xhbtfvfr- j.f.- qhzsjct,!mbti,!euc/'

charset=$(echo -e "$(printf '\\x%x' {33..126})")
for ((n = 0; n < ${#text}; n += 2));do
  echo -n "${text:n:1}" | tr "$charset" " $charset"
  echo -n "${text:n+1:1}"
done

Congratulations =)  You passed our idiot filter =) What are your three favorite technical books? Please include at least one software engineering book, the others can be whatever, i.e., physics, math, etc.
Dang you beat me to it! I was going to give it a shot in bash (and likely still will, so I'm not peeking at how you did it) but nice job! Bash is the language I'm currently most able with -- I'm not much for C, perl, python, etc..

I have a couple ideas to try out.. This kind of stuff keeps the brain fresh & juicy

I think it'd be cool to see this in Lisp too, if that can be done. Any takers?

Sasha

Last edited by GrapefruiTgirl; 09-13-2009 at 12:00 PM.
 
Old 09-13-2009, 01:14 PM   #42
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
And, in PHP:
Code:
#!/usr/bin/php
<?php
$data="Doogsauumauipnt >)! Zov qatsfd!ovr!ieipt!fjlues >) Wiau brf zovr!tirfe!fbvprjtf uedhoidam copkt? Pmebsf jndlvdf bt!lfatt!ooe!spfuwbrf fnhioefrjnh copk- uhf ptiess!cbn!bf xhbtfvfr- j.f.- qhzsjct,!mbti,!euc/";
for($ii=0;$ii<strlen($data);$ii+=2){if($data[$ii]<>" ")$data[$ii] = chr(ord($data[$ii]) - 1);}
echo $data."\n";
?>
You do need to have the command line php interpreter installed for this one. I could also make this one obscure by using regex's. Maybe I will.

edit: Here is the regexp version in PHP.
Code:
#!/usr/bin/php
<?php
$data="Doogsauumauipnt >)! Zov qatsfd!ovr!ieipt!fjlues >) Wiau brf zovr!tirfe!fbvprjtf uedhoidam copkt? Pmebsf jndlvdf bt!lfatt!ooe!spfuwbrf fnhioefrjnh copk- uhf ptiess!cbn!bf xhbtfvfr- j.f.- qhzsjct,!mbti,!euc/";
echo preg_replace("((.)(.)?)e" ,"(\"\\1\" != \" \")?chr(ord('\\1') - 1).'\\2':'\\1\\2'", $data)."\n";
?>
And this regexp does handle that pesky last character.

Last edited by jiml8; 09-13-2009 at 04:13 PM.
 
Old 09-13-2009, 11:31 PM   #43
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
Question bash + awk solution

Ok! While I'm semi-impressed with what I have come up with (because it's the first time I've ever used awk for anything), it has a bug.

Here's the code:

Code:
#!/bin/bash
data="Doogsauumauipnt >)! Zov qatsfd!ovr!ieipt!fjlues >) Wiau brf zovr!tirfe!fbvprjtf uedhoidam copkt? Pmebsf jndlvdf bt!lfatt!ooe!spfuwbrf fnhioefrjnh copk- uhf ptiess!cbn!bf xhbtfvfr- j.f.- qhzsjct,!mbti,!euc/"
i=$((0)); leng=$(($(echo "$data" | awk '{ if (length($0) > len) len = length($0) } END { print len }')))
while ((i <= $leng)); do
output="$output$(echo $(($(printf %d "'$(echo ${data:$((i)):1} | gawk '{ printf("%c",int($0)); } {print}')")-1)) | gawk '{ printf("%c",$0); }')${data:$((i+1)):1}"
i=$((i+2))
done
echo "$output"
..and here's the output (note the two characters which I have no clue why they are appearing -- but I'm working on it.)

Code:
bash-3.1$ sh decode
Congratulations =)  You passed our idiot filter =)What are your three favorite technical books?Please include at least one software engineering book, the others can be whatever, i.e., physics, math, etc.
bash-3.1$

Last edited by GrapefruiTgirl; 09-14-2009 at 08:10 AM. Reason: executed length computation only once -- speeds up execution. Changed some awks to gawks
 
Old 09-14-2009, 01:51 AM   #44
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
Anyone want to do it in Fortran? I might try; I used to program a LOT of Fortran, but the last time I did was in about 1990 and I have never programmed for the gnu fortran compiler. Might be awhile before it is running.

We also need someone to step up and do it in python. And there was a request for lisp.

While we're at it, is Modula still in use? Pascal? Forth?
 
Old 09-14-2009, 08:47 AM   #45
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
Here is a python one (far from optimal)

Code:
#!/usr/bin/python

import re

def decode(m):
        a = m.group(0)
        if (len(a) == 2):
                a = m.group(1)
                b = m.group(2)
        else:
                b = ""
        if (a != " "):
                a = chr(ord(a)-1) 
        return a + b


text = "Doogsauumauipnt >)! Zov qatsfd!ovr!ieipt!fjlues >) Wiau brf zovr!tirfe!fbvprjtf uedhoidam copkt? Pmebsf jndlvdf bt!lfatt!ooe!spfuwbrf fnhioefrjnh copk- uhf ptiess!cbn!bf xhbtfvfr- j.f.- qhzsjct,!mbti,!euc/";

var = re.sub("(.)(.)|(.)", decode, text)
print var
GrapefruiTGirl - the problem your seeing is the subtract from space issue
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
A little instability in my Slackware, Need to decipher these errors BobNutfield Slackware 13 08-20-2008 10:02 AM
Can Someone help me to decipher this error? randell6564 Ubuntu 2 10-15-2006 04:20 PM
How to decipher this C declaration? CM019 Programming 6 05-28-2006 06:01 PM
Can anyone decipher my K3b error message? Trinity22 Linux - Software 3 04-21-2004 09:01 PM
Try to decipher this :) Whitehat General 42 06-29-2003 06:42 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > General

All times are GMT -5. The time now is 08:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration