General Discussion Undecided where to post - do it here. |
Reply to Thread New Thread |
![]() |
#1 |
|
|
![]() |
![]() |
#3 |
|
Originally posted by Ari Rahikkala
Well, hell. I must say that I managed to impress myself with Haskell. Here's mine. A combination of C and bash: First I took a wordlist (only 5 letter words) with one word on each line. Then I used gedit to add in a series of bash commands (using find/replace on the newlines) so I got a second file like this. 5letscr.sh Code: Code
#!/bin/bash bash jmb2.sh abaca . . . bash jmb2.sh zymes jmb2.sh Code: Code
#!/bin/bash gcc -o jmb2.out jmb2.c echo $1 > jmbtmpfile ./jmb2.out < jmbtmpfile > words2.sh rm jmbtmpfile bash ./words2.sh jmb2.c Code: [code]#include #include int rvd5(int a, int b, int c, int d, int e); int rvd6(int a, int b, int c, int d, int e, int f); main() { char word[80]; int count, tag, i, j, k, l, m, n; for (count=0; (word[count] = getchar()) != '\n'; ++count) ; tag = count; printf ("#!/bin/bash\n"); printf ("rm -f jmbtmpfile\n"); if (tag == 5) { for (i = 0; i |
![]() |
![]() |
#4 |
|
|
![]() |
![]() |
#6 |
|
|
![]() |
![]() |
#7 |
|
|
![]() |
![]() |
#8 |
|
|
![]() |
![]() |
#9 |
|
|
![]() |
![]() |
#11 |
|
|
![]() |
![]() |
#12 |
|
|
![]() |
![]() |
#13 |
|
|
![]() |
![]() |
#14 |
|
|
![]() |
![]() |
#15 |
|
Good idea . It took the execution time of my Haskell program for going through /usr/share/dict/words (234937 lines, 2486824 bytes) from ~1.7 seconds to ~1.5 seconds. Perhaps you can go even further, how do these ideas sound to you.
- drop all matching vowels - drop very rare consinents like x and z - restrict the 3 other letters to consinents only - drop all matching consinents The base posibilities are 26^5th power = 11,881,376 With agressive culling its 5 * 4 * 19 * 18 * 17 = 116,280 A full two orders of magnitude reduction |
![]() |
![]() |
#18 |
|
|
![]() |
![]() |
#19 |
|
So we've seen Linux geek code (Ari), physicist/mathematician code (KH), and now for some software engineer code (in Java for variety):
Code: Code
import java.io.IOException; public class Anagram { int size, count; char[] arr; public static void main(String[] args) throws IOException { String input = args[0]; size = input.length(); count = 0; arr = new char[size]; for (int i = 0; i < size; i++) arr[i] = input.charAt(i); anagram(size); } public static void rotate(int anagramSize) { int i; int position = size - anagramSize; char temp = arr[position]; // 1st letter for (i = position + 1; i < size; i++) // push the rest left arr[i - 1] = arr[i]; arr[i - 1] = temp; // now put the 1st on the end } public static void anagram(int anagramSize) { int limit; if (anagramSize != 1) // if 1, this is useless this is useless so don't do anything { for (int i = 0; i < anagramSize; i++) { anagram(anagramSize - 1); // anagram the last bits if (anagramSize == 2) // the innermost anagram { for (int i = 0; i < size; i++) // display it System.out.print(arr[i]); System.out.println(); } // end if else rotate(anagramSize); // rotate word } // end for } // end if } // end anagram() } |
![]() |
Reply to Thread New Thread |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|