|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming | |
Programming Challenge
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#71 (permalink) | |||||||||||||||
|
Photography nut
![]() |
Quote:
I ran yours for fun against the 172K word list. Quite impressive Code:
real 0m1.947s user 0m0.344s sys 0m0.028s
__________________
"UNIX was never designed to keep people from doing stupid things, because that policy would also keep them from doing clever things." - Doug Gwyn Try out the latest Programming Challenge Quote:
CPU-Z Validation @ 2.97-prime95 stable 16 hours @ 1.48v Proof | CPU-Z Validation @ 3.15 Getting Mouse Side Buttons to work in Linux, Compile a custom Kernel, More
|
|||||||||||||||
|
|
|
|
#72 (permalink) | |||||||||||||
|
With great difficulty
![]() |
My prof would have a bone to pick with me if the results had been anything else. The first few labs in my freshman C and UNIX course revolved around loading a dictionary (first with a resizing array, then a linked list, then whatever you want - meaning go learn how to make a trie if you want an A)
__________________
|
|||||||||||||
|
|
|
|
#73 (permalink) | ||||||||||||||
|
Photography nut
![]() |
Code:
#!/usr/bin/env ruby
unless ARGV.size == 2
puts "Usage: ruby wordsort.rb scram_file wordlist_file"
exit 0
end
scram = Hash.new
File.open(ARGV[0]).each do |word|
word.chop!
scram[word.split(//).sort.join] = word
end
File.open(ARGV[1]).each do |word|
word.chop!
#print "#{word} " if scram.has_key? word.split(//).sort.join
end
Code:
$ time ruby wordsort-hash.rb shuffle.txt 172K-words.txt real 0m0.356s user 0m0.304s sys 0m0.004s Note the commented out "print" line if it printed out everything to the terminal it'll obviously take longer: real 0m3.832s rabidgnome: The execution time on yours if nothing it outputted. Code:
$ time ./a.out real 0m0.353s user 0m0.324s sys 0m0.024s
__________________
"UNIX was never designed to keep people from doing stupid things, because that policy would also keep them from doing clever things." - Doug Gwyn Try out the latest Programming Challenge Quote:
CPU-Z Validation @ 2.97-prime95 stable 16 hours @ 1.48v Proof | CPU-Z Validation @ 3.15 Getting Mouse Side Buttons to work in Linux, Compile a custom Kernel, More
Last edited by dangerousHobo : 08-02-08 at 09:24 PM |
||||||||||||||
|
|
|
|
#74 (permalink) | |||||||||||||
|
With great difficulty
![]() |
Good call with the hashtable, I'm throwing together a quick one in C to compare performance (only cheating a little bit
__________________ ). They should be similar (both are constrained by the length of the input, the trie from moving through the tree letter by letter, the table because it has to hash the string). I think the hashtable will have better constant factors though, because it doesn't have to move through a tree - it just has to jump into a table
|
|||||||||||||
|
|
|
|
#75 (permalink) | ||||||||||||||
|
Photography nut
![]() |
For fun I wrote it in perl too.
Not as elegant as ruby Code:
#!/usr/bin/env perl
use warnings;
use strict;
if ($#ARGV+1 < 2) {
print "Usage: perl wordsort.pl scram_file wordlist_filen";
exit(0);
}
my %scram = ();
open(FILE, $ARGV[0]) || die "could not open file $ARGV[0]";
foreach (<FILE>) {
chomp($_);
my $sorted = join( "", sort { lc($a) cmp lc($b) } split(//,$_) ); # alphabetical sort
$scram{$sorted} = $_;
}
close(FILE);
open(FILE2, $ARGV[1]) || die "could not open file $ARGV[1]";
foreach (<FILE2>) {
chomp($_);
print "matched: $_ " if $scram{join( "", sort { lc($a) cmp lc($b) } split(//,$_) )};
}
close(FILE2);
print "n";
__________________
"UNIX was never designed to keep people from doing stupid things, because that policy would also keep them from doing clever things." - Doug Gwyn Try out the latest Programming Challenge Quote:
CPU-Z Validation @ 2.97-prime95 stable 16 hours @ 1.48v Proof | CPU-Z Validation @ 3.15 Getting Mouse Side Buttons to work in Linux, Compile a custom Kernel, More
|
||||||||||||||
|
|
|
|
#76 (permalink) | ||||||||||||||
|
Photography nut
![]() |
The Challenge:
Ok this week I'm hoping to see some more submissions so we'll try one thats hopefully a little easier. Write a program that can print out a shape given the desired number of lines and the character to be used. The shapes that your program can handle is up to you, but of course the more the better. Creativity and elegance are weighed to decide the winner. There is no prize, just bragging rights. Any language is welcome. ![]() Deadline: Wednesday August 13th at 11:00pm EST. Post any questions you have.
__________________
"UNIX was never designed to keep people from doing stupid things, because that policy would also keep them from doing clever things." - Doug Gwyn Try out the latest Programming Challenge Quote:
CPU-Z Validation @ 2.97-prime95 stable 16 hours @ 1.48v Proof | CPU-Z Validation @ 3.15 Getting Mouse Side Buttons to work in Linux, Compile a custom Kernel, More
|
||||||||||||||
|
|
|
|
#77 (permalink) | ||||||||||||||
|
Photography nut
![]() |
Only three shapes.
Code:
#!/usr/bin/env ruby
if ARGV.size < 2
puts "Useage: ruby shape.rb [shape] [char] {size}"
exit 0
end
SHAPE = ARGV.shift
CHAR = ARGV.shift
if SHAPE !~ /triangle|diamond|square/
puts "unknown shape....exiting"
exit 0
end
if ARGV[0]
Size = ARGV.shift.to_i
else
Size = 5
end
def pad(pos, shape)
case shape
when 'triangle' : " "*CHAR.size*(Size+1 - pos)
when 'diamond' : " "*CHAR.size*(Size/2+1 - pos)
end
end
case SHAPE
when 'square'
(1..Size).each { puts CHAR*Size }
when 'triangle'
(1..Size).each { |n| puts pad(n, 'triangle') + ("#{CHAR}"+" "*CHAR.size)*n }
when 'diamond'
(1..Size/2+1).each { |n| puts pad(n, 'diamond') + ("#{CHAR}"+" "*CHAR.size)*n }
(Size/2).downto(1) { |n| puts pad(n, 'diamond') + ("#{CHAR}"+" "*CHAR.size)*n }
end
__________________
"UNIX was never designed to keep people from doing stupid things, because that policy would also keep them from doing clever things." - Doug Gwyn Try out the latest Programming Challenge Quote:
CPU-Z Validation @ 2.97-prime95 stable 16 hours @ 1.48v Proof | CPU-Z Validation @ 3.15 Getting Mouse Side Buttons to work in Linux, Compile a custom Kernel, More
|
||||||||||||||
|
|
|
|
#78 (permalink) | |||||||||||
|
Programmer
![]() |
Something I'm working on: PHP + SVG. Should be able to do virtually any shape when done. Draws an SVG, calls rsvg to rasterize it, then processes it through the gd libraries and generates some ascii art. Works in a terminal as well. (granted, for the currently hard-coded drawing, you need a really big terminal window) (it'll work perfectly in a standard 80-wide terminal now)
Shouldn't take much time to add some options. (done) Question: Do you want some compensation for the none-square aspect of a typical console font? (I'll add an option later) Shapes so far: - Rectangles - Circles - Lines - Star - Triangle - Diamond - OCN Logo - haha, had to draw it myself Specify a shape with do=[square | circle | line | star | triangle | diamond | ocn], size with &size=[##], character with &char=[character] Default is a square, size of 80, char=# PHP Code:
__________________
Retired Compiz Developer
Ubuntu Alpha Tester
Last edited by OasisGames : 08-11-08 at 07:13 PM Reason: Added OCN logo. Like I said, should be able to do anyt shape. |
|||||||||||
|
|
|
|
|
#79 (permalink) | |||||||||||||
|
With great difficulty
![]() |
More string manipulation huh? If my haskell book gets here I might take a whack at this
__________________
|
|||||||||||||
|
|
|
|
#80 (permalink) | ||||||||||||
|
Overclocker in Training
|
im taking my :turd: ms compiler and going home
|
||||||||||||
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|