-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cryptogram: Make an easy mode option too
- Loading branch information
Showing
1 changed file
with
5 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
Regexp.SimpleRegexp nonword = Regexp.SimpleRegexp("[^A-Z ]"); | ||
string make_cryptogram(string plain) { | ||
sscanf(plain, "%[0-9. ]%s", string pfx, plain); | ||
string stripped = nonword->replace(upper_case(plain), ""); | ||
stripped = upper_case(plain); //Easy mode: keep the punctuation. | ||
array letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" / 1; | ||
mapping cipher = mkmapping(letters, Array.shuffle(letters + ({ }))); | ||
return replace(stripped, cipher); | ||
return pfx + replace(stripped, cipher); | ||
} | ||
|
||
int main(int argc, array(string) argv) { | ||
foreach (argv[1..], string arg) { | ||
arg = Stdio.read_file(arg) || arg; | ||
foreach (arg / "\n", string line) | ||
write("%s\n%s\n", line, make_cryptogram(line)); | ||
//write("%s\n%s\n", line, make_cryptogram(line)); //Compare? | ||
write("%s\n", make_cryptogram(line)); //Or just show the puzzles? | ||
} | ||
} |