LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-08-2012, 01:45 PM   #16
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: Disabled

Quote:
Originally Posted by dugan View Post
Yes, but providing a Perl solution would amount to doing his homework for him.
Yes, you are right, but I think the great problem of the OP will be to understand the solution (which is good, he should learn).

My concern is that once anyone uses the searchfunction of LQ in order to find a solution for a similar problem he will be mislead into this thread. Therefore off-topic posts are not very helpful on the long run. Maybe it's the best solution if a Moderator closes this thread.

Markus
 
Old 06-09-2012, 05:15 AM   #17
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
I disagree entirely. These posts are not "off topic". They are expansions of the topic.

First of all, there's nothing special going on here. This kind of thing happens all the time in threads like this. There's an interesting challenge offered, so people naturally tend to want to try their hand at it. Since it's homework, we are deliberately avoiding solving it in the required way, but there's nothing stopping us from playing around with other tools instead. And we post the solutions we come up with in order to share all the different ways there are to solve the problem.

This does also provide valuable advice to the OP, by the way, without giving away the answer directly. Techniques used in one language are very often transferable to another, with just a little adaptation work. Besides, even if they aren't immediately useful, they might teach him something else he can use later on.

In fact, the only serious criticism I'd make concerning this thread would be towards the one person who actually posted a direct Perl solution to a problem that was obviously homework.

And that final argument is a bit weak, don't you think? The thread title itself doesn't mention Perl specifically, it only says "making a number pyramid", so anyone coming across it in a search will expect it to be about that. And if this hypothetical searcher does happen to be looking specifically for a Perl solution, he only has to scan down the thread to see whether one was provided or not; something he's going to do anyway on every thread that appears to match his search topic. Either he'll find something he can use, or he won't and will move on.

Come to think of it, the more solutions we add to the thread, in various languages, the more likely it is to contain something future searchers can use, and the more generally beneficial it will be.

Finally, if the OP would ever return and show us what he finally came up with, or otherwise post a follow up, then we'd be right back on topic, and could hammer out a final solution (or several) in Perl to wrap the thread up with. And if he doesn't show up after a reasonable wait (say a week or so), then we can probably treat the topic as closed, and feel free to post our own anyway.
 
Old 06-09-2012, 05:32 AM   #18
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Quote:
Originally Posted by danielbmartin View Post
That's exactly what happened, and your fix didn't change anything. Maybe I'm being too picky, so I'll hush up now.
I'm sorry, maybe there was some confusion. I didn't provide a "fix" in my last post, I only explained what my code was doing. I had simply used a parameter substitution that assumes an empty variable at the start. When you combined the two versions together, you broke that assumption.

So yes, as long as you run my revised version directly after the first one, you'll have to unset/reset the variable before that part runs.
 
Old 06-09-2012, 06:12 AM   #19
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: Disabled
Quote:
Originally Posted by David the H. View Post
I disagree entirely. These posts are not "off topic". They are expansions of the topic.
...

In fact, the only serious criticism I'd make concerning this thread would be towards the one person who actually posted a direct Perl solution to a problem that was obviously homework.
...
Come to think of it, the more solutions we add to the thread, in various languages, the more likely it is to contain something future searchers can use, and the more generally beneficial it will be.
...
Hi David the H.,

I think you are right, I have to say sorry . I've misinterpreted the OP's "lines of code" as an attempt to find a solution. Therefore I did not mean to do his homework but give him a start with Perl. I realized now that I should have been waiting with posting a solution in Perl.

Markus
 
Old 06-10-2012, 02:15 PM   #20
imran042
Member
 
Registered: Feb 2012
Posts: 35

Original Poster
Rep: Reputation: Disabled
its not a homework... i want to make a number pyramid using #!/usr/bin/perl

i made a half pyramid using nested for, but got errors while trying to make a full one so i need to know

instead of talking, we should help out so that the query is solved and easy for other searchers to find it , maybe get new ideas arising from it.
this is programming and all mind work in different directions, with different logics....
 
Old 06-16-2012, 11:02 AM   #21
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 735

Rep: Reputation: 76
Hi.

This solution uses the extant perl code, then manipulates a copy of the results to produce the pyamid. Intermediate results are displayed with tee:
Code:
#!/usr/bin/env bash

# @(#) s1	Demonstrate numeric pyramid by reflection.
# http://freecode.com/projects/align

pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && $C perl align rev cut

# Generate the tree.
pe
./p1 |
tee f1 

# Reverse tree, remove first character.
rev f1 |
cut -c2- |
tee f2

# Combine them, omitting a delimiter.
pe
paste -d "" <(cat f1) <(cat f2) |
tee f3

# Center each line.
pe
align -ac f3

exit 0
producing:
Code:
% ./s1

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian GNU/Linux 5.0.8 (lenny) 
bash GNU bash 3.2.39
perl 5.10.0
align 1.7.0
rev - ( /usr/bin/rev, 2008-04-28 )
cut (GNU coreutils) 6.10

0
01
012
0123
01234
012345
0123456
01234567
012345678

0
10
210
3210
43210
543210
6543210
76543210

0
010
01210
0123210
012343210
01234543210
0123456543210
012345676543210
01234567876543210

        0
       010
      01210
     0123210
    012343210
   01234543210
  0123456543210
 012345676543210
01234567876543210
See the web site noted for access to the (perl!) code for align.

Best wishes ... cheers, makyo

Last edited by makyo; 06-16-2012 at 11:04 AM.
 
  


Reply



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
Zyxel G-4100v2 | pyramid linux install | wireless hot spot floorripper Linux - Embedded & Single-board computer 0 02-21-2012 03:21 AM
gcc and linux pyramid board shabi Linux - Embedded & Single-board computer 3 06-23-2010 11:42 PM
pyramid (pebble) via-rhine module problem aldar Linux - Hardware 0 11-15-2006 12:07 PM
LXer: Tip of the Trade: Pyramid Linux LXer Syndicated Linux News 0 07-03-2006 10:21 PM
LXer: Microsoft cannot withstand Linux pyramid: philosopher Girardet LXer Syndicated Linux News 0 04-13-2006 06:03 PM

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

All times are GMT -5. The time now is 07:51 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