Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

I'm tired and can't sleep

  1. Nov 5, 2010 #1


    User Avatar
    Gold Member

    ...so forgive the stupid game:

    What would be the most efficient way to reproduce the following without using keyboard shortcuts for formatting, or any variant of a quote + copy-paste method?

    Do you know how long this took?
  2. jcsd
  3. Nov 29, 2010 #2


    User Avatar
    Gold Member

    Last edited by a moderator: May 5, 2017
  4. Nov 6, 2012 #3
    Code (Text):

    raphael@raphael:~$ cat bored.java
    public class bored {
        public static void main(String[] args) {
            String r = "";
            int j = 0;
            for(int i = 0; i < args[0].length(); i++) {
                if (args[0].charAt(i) != ' ' && j++ % 2 == 0)
                    r += String.format("[b][u][i]%s[/b][/u][/i]", args[0].charAt(i));
                    r += args[0].charAt(i);
    raphael@raphael:~$ javac bored.java
    raphael@raphael:~$ java bored "Do you know how long this took?"
    [b][u][i]D[/b][/u][/i]o [b][u][i]y[/b][/u][/i]o[b][u][i]u[/b][/u][/i] k[b][u][i]n[/b][/u][/i]o[b][u][i]w[/b][/u][/i] h[b][u][i]o[/b][/u][/i]w [b][u][i]l[/b][/u][/i]o[b][u][i]n[/b][/u][/i]g [b][u][i]t[/b][/u][/i]h[b][u][i]i[/b][/u][/i]s [b][u][i]t[/b][/u][/i]o[b][u][i]o[/b][/u][/i]k[b][u][i]?[/b][/u][/i]
  5. Nov 6, 2012 #4


    User Avatar

    Staff: Mentor

    Code (Text):
    [noparse]borek@invincible ~/python $ cat bored.py
    text='Do you know how long this took?'
    outtext = ''
    switch = 1

    for c in text:
       if c == ' ':
          outtext += ' '
          if switch:
             outtext += '[b][u][i]'+c+'[/i][/u][/b]'
             outtext += c
          switch = 1 - switch

    print outtext
    borek@invincible ~/python $ python bored.py
    [b][u][i]D[/i][/u][/b]o [b][u][i]y[/i][/u][/b]o[b][u][i]u[/i][/u][/b] k[b][u][i]n[/i][/u][/b]o[b][u][i]w[/i][/u][/b] h[b][u][i]o[/i][/u][/b]w [b][u][i]l[/i][/u][/b]o[b][u][i]n[/i][/u][/b]g [b][u][i]t[/i][/u][/b]h[b][u][i]i[/i][/u][/b]s [b][u][i]t[/i][/u][/b]o[b][u][i]o[/i][/u][/b]k[b][u][i]?[/i][/u][/b][/noparse]
    Do you know how long this took?

    If you are really bored you should try to code it in brain**** :surprised

    Sigh, one even can't post a proper name of that language.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Discussions: I'm tired and can't sleep
  1. Can't go back to sleep (Replies: 15)