summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-03-08 23:20:19 -0600
committerJesse Luehrs <doy@tozt.net>2013-03-08 23:35:46 -0600
commit8cc12384694f26af5d8cd928c1dc9d552204ac94 (patch)
tree111688c50a9339cf7f5bd6b19548a8e9c4b4b3d2
parent2e59cea2032a4c2c9a29f361fe280b5d6fa01136 (diff)
downloadrosalind-8cc12384694f26af5d8cd928c1dc9d552204ac94.tar.gz
rosalind-8cc12384694f26af5d8cd928c1dc9d552204ac94.zip
subs
-rw-r--r--SUBS.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/SUBS.rs b/SUBS.rs
new file mode 100644
index 0000000..4b99a0e
--- /dev/null
+++ b/SUBS.rs
@@ -0,0 +1,20 @@
+extern mod rosalind;
+use rosalind::io::input_line;
+
+fn substrings(haystack: &str, needle: &str) -> ~[uint] {
+ let mut indices = ~[];
+ do str::find_str(haystack, needle).while_some |start| {
+ indices.push(start + 1);
+ str::find_str_from(haystack, needle, start + 1)
+ }
+ indices
+}
+
+fn main() {
+ let haystack = input_line();
+ let needle = input_line();
+
+ let indices = substrings(haystack, needle);
+
+ io::println(str::connect(indices.map(|i| fmt!("%u", *i)), " "))
+}