The combo game

  • The FTB Forum is now read-only, and is here as an archive. To participate in our community discussions, please join our Discord! https://ftb.team/discord

Someone Else 37

Forum Addict
Feb 10, 2013
1,876
1,440
168
That only looks complicated because it's all smashed into one line. Also because LISP.
Code:
(defn spam-s        ;Define function calles spam-s that spams a string with the letter s
  [in]              ;Takes one argument, a string.
  (if (empty? in)   ;If the input string is empty, we've reached the end
    "ssssss"        ;so return a bunch of s
    (str "sssss"    ;If there's still more string go go, concatenate some s
      (first in)            ;with the first character in the input string
      (spam-s (rest in))))) ;and whatever you get when you spam-s the rest of the input string
Also, I don't know of a function that already does what I want it to, so there's that.
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
Too lazy to make acleaner solution and I am not sure if this will work because I can't test it but lets have some fun with lua. if there are problems with the syntax I blame the fact that I also work with php currently
Code:
function spamS (stri)
local newStr= ""
for i = 1, #stri do
    local c = str:sub(i,i)
    if c =="s" then
     local spam= math.random()*10
     for times=0,spam do
       newStr=newStr.."s"
     end
   else
   newStr=newStr..c
  end
end
end
edit fixed a derp
 
Last edited:

Someone Else 37

Forum Addict
Feb 10, 2013
1,876
1,440
168
I don't know LUA very well, but I can kind of figure out what that's trying to do... which does not seem to be the same thing that my function does.

user=> (defn spam-s [in] (if (empty? in) "ssssss" (str "sssss" (first in) (spam-s (rest in)))))
#'user/spam-s
user=> (spam-s "Hi, lens!")
"sssssHsssssisssss,sssss ssssslsssssesssssnsssssssssss!ssssss"
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
mine only places mores "s" in place of an s

I guess I could also used math.random(10) but meh:p
the ".." is to concatenate
there probably are better ways to write such a function though.
 

Someone Else 37

Forum Addict
Feb 10, 2013
1,876
1,440
168
This behaves more like yours:
Code:
(defn spam2
  [in]
  (if (empty? in)   ;If the input string is empty
    ""              ;return an empty string
    (str (first in) ;If not, return the first character
         (if (or (= (first in) \s)  ;followed by... if the first character is s or S
                 (= (first in) \S))
           (apply str (repeat (rand-int 10) \s))  ;a random number of s
           "")                                    ;or nothing, if the character wasn't s or S
         (spam2 (rest in))))) ;And follow all that with whatever you get by spamming the rest of the string.
Code:
user=> (defn spam2 [in] (if (empty? in) "" (str (first in) (if (or (= (first in) \s) (= (first in) \S)) (apply str (repeat (rand-int 10) \s)) "") (spam2 (rest in)))))
#'user/spam2
user=> (spam2 "This is Sparta!")
"Thisssss isss Sssssssparta!"
user=> (spam2 "This is Sparta!")
"Thissssssssss isssssssss Ssssssssssparta!"
user=> (spam2 "This is Sparta!")
"Thissss isssssss Ssssssssparta!"
user=> (spam2 "This is Sparta!")
"Thissssssss isssssssss Ssparta!"
user=> (spam2 "This is Sparta!")
Basically, after each s or S, it inserts a random number of s.