Python Pattern Challenge

Well IQfy? What's the most efficient way that you'd go about printing out this religious symbol in Python?

CRIME Shirt $21.68

Yakub: World's Greatest Dad Shirt $21.68

CRIME Shirt $21.68

  1. 2 months ago
    Anonymous

    >most efficient way
    store it as string to be displayed

  2. 2 months ago
    Anonymous

    import timeTravel

    timeTravel.toTheGoodOlDays()

  3. 2 months ago
    Anonymous

    scratch a liberal and fascist will bleed. one of the best sayings of all time and so accurate today with their financing of Azov

    • 2 months ago
      Anonymous

      keyed

    • 2 months ago
      Anonymous

      Rings true today with the Israel/Gaza stuff, really goes to show how easy it is to turn people into something they would never dream of being with the right amount of media and peer pressure.

      • 2 months ago
        Anonymous

        fr fr

      • 2 months ago
        Anonymous

        fr fr

        >you wouldn't want to be one of those virtue signaling liberals now would you goyim
        >isn't it heckin based chungarino how we flat out genocide palestinian kids goy?
        >you can be part of our club, we totally aren't cool with BLM like we were three years ago when they wanted to kill whitey
        >in fact we hate them now because they won't let us put every palestinian into a giant blender
        >no you still can't have your country back
        >yes we will still destroy you if you deny the 6 gajillion
        frick off

        • 2 months ago
          Anonymous

          I said nothing Pro-Israel. All I said was that it's absolutely wild that a large portion of Americans became anti-Semitic as quickly as they did and how easily they became it, going from seeing Israel doing kinda fricked up shit in Gaza to declaring that israelites should be killed off for being israeli pigdogs.

          • 2 months ago
            Anonymous

            they're not even antisemitic though. I'm antisemitic. normalgays are just experiencing a normal amount of non-positive semitism as a result of exposure to typical semitic actions via tiktok

    • 2 months ago
      Anonymous

      two more weeks, comrade pidorenko

    • 2 months ago
      Anonymous

      Good morning sir

    • 2 months ago
      Anonymous

      52 more weeks, vatnik

  4. 2 months ago
    Anonymous

    Sorry. The new python filters block any codes that tries to print politically incorrect output.

  5. 2 months ago
    Anonymous

    Iterate line by line with a bunch of if checks.

  6. 2 months ago
    Anonymous

    d=7

    def t(r):
    r = [(0,1), (0, 2), (1, 1), (1,2), (2, 1), (2,2)]
    for _ in range(6): yield r[_]
    for _ in range(3*len(r)):
    x,y = r.pop(0)
    x,y = y, d-x-1
    r.append((x, y))
    yield x, y

    for i in range(d):
    print(''.join([' ' if (i,j) in [_ for _ in t(r)] else '*' for j in range(d)]))

    • 2 months ago
      Anonymous

      frick

  7. 2 months ago
    Anonymous

    brainlet here, took me about 10< mins

    def printSwastika(n):

    nn = n-1
    m = 2*nn + 1

    tmp_start = '*' + (n-1)*' ' + (n+1)*'*'
    tmp_fh = '*' + (n-1)*' ' + '*' + (n)*' '
    tmp_mid =(2*n + 1)*'*'
    tmp_sh = tmp_fh[::-1]
    tmp_end = tmp_start[::-1]

    print( tmp_start )
    for i in range(m):
    if i < nn: ## first half
    print( tmp_fh )
    elif i == nn: ## middle
    print( tmp_mid )
    else: ## second half
    print( tmp_sh )
    print( tmp_end )

    for the figure, it corresponds to n equal 3

    • 2 months ago
      Anonymous

      d=7

      def t(r):
      r = [(0,1), (0, 2), (1, 1), (1,2), (2, 1), (2,2)]
      for _ in range(6): yield r[_]
      for _ in range(3*len(r)):
      x,y = r.pop(0)
      x,y = y, d-x-1
      r.append((x, y))
      yield x, y

      for i in range(d):
      print(''.join([' ' if (i,j) in [_ for _ in t(r)] else '*' for j in range(d)]))

      all of these implementations are worse than

      >most efficient way
      store it as string to be displayed

      because it literally takes less code and less memory to just stdout a static string

  8. 2 months ago
    Anonymous

    for i in b'yttx7fHHO':
    print(''.join('*' if i >> x & 1 else ' ' for x in range(0, 7*~~

    • 2 months ago
      Anonymous

      >for i in b'yttx7fHHO':
      Wat

      • 2 months ago
        Anonymous

        it's l33t for "b***h hoe"

  9. 2 months ago
    Anonymous

    print("""

    * *****
    * *
    * *
    ********
    * *
    * *
    **** *
    """)

    • 2 months ago
      Anonymous

      this is unironically the right solution. why would you mess with extra logical processing to make a very small, static string? could add newline characters to make it all fit on one line if you wanted, but that's just a personal taste thing. in terms of "efficiency", doing anything but this is just moronic

  10. 2 months ago
    Anonymous

    I'm not that good at codegolfing.
    print("n".join(["".join([[" ","*"][ord(i)>>j&1]for j in range(7)])for i in"~AA~@A>"]))

    • 2 months ago
      Anonymous

      Still the shortest non-meme solution.

  11. 2 months ago
    Anonymous

    T(1) S(1) implementation:
    t = "* ****n* * n* * n*******n * *n * *n**** *n"
    print(t)

  12. 2 months ago
    Anonymous

    Very nice anon. What if we want to generalize the solution, that user can specify the length of the swastika, that if I ask for length of 2, then i’ll get
    * * *
    * * *
    * * *

    and if I specify for length of 4 i’ll get the pattern in OP’s pic? Can you do it in linear time?

    • 2 months ago
      Anonymous

      Although not the same

      brainlet here, took me about 10< mins

      def printSwastika(n):

      nn = n-1
      m = 2*nn + 1

      tmp_start = '*' + (n-1)*' ' + (n+1)*'*'
      tmp_fh = '*' + (n-1)*' ' + '*' + (n)*' '
      tmp_mid =(2*n + 1)*'*'
      tmp_sh = tmp_fh[::-1]
      tmp_end = tmp_start[::-1]

      print( tmp_start )
      for i in range(m):
      if i < nn: ## first half
      print( tmp_fh )
      elif i == nn: ## middle
      print( tmp_mid )
      else: ## second half
      print( tmp_sh )
      print( tmp_end )

      for the figure, it corresponds to n equal 3

      already kind of does it

    • 2 months ago
      Anonymous

      >Can you do it in linear time?

      Although not the same [...]
      already kind of does it

      welp just tried to do a simple check with a test but had to stop it midways since it took too long. Pretty sure that doing concatenations becomes the main bottleneck but right now is bedtime so I won't delve further into it.

      • 2 months ago
        Anonymous

        You're printing out a square, dum-dum.
        It's always going to be O(n^2).

        • 2 months ago
          Anonymous

          This is what separates the college sophomores from the oldgay programmers
          College sophomores will try all the heckin basederino coding challenge tricks they’ve earned to get it into as few characters as possible
          Oldgay programmers will take one look, say “it’s explicitly O(n^2) and optimization’s a waste of time because IO completely mogs everything else” and will, at most, create a subroutine to generate an arbitrary size

        • 2 months ago
          Anonymous

          This is what separates the college sophomores from the oldgay programmers
          College sophomores will try all the heckin basederino coding challenge tricks they’ve earned to get it into as few characters as possible
          Oldgay programmers will take one look, say “it’s explicitly O(n^2) and optimization’s a waste of time because IO completely mogs everything else” and will, at most, create a subroutine to generate an arbitrary size

          Sure, but still the obvious jump near n~700 implies that my code is terrible, regardless of the O(n^2) complexity

  13. 2 months ago
    Anonymous

    I would just do something like this:
    spacemode = 0
    for(i...7)
    spacemode = i < 2 ? i : i == 3 ? 2 : i == 6 ? 3 : 1;
    switch spacemode
    case 0: print("* ****")
    case 1: print("* * ")
    case 2: print("*******")
    case 2: print("**** *")

    Could easily be adjusted for different sizes and such

  14. 2 months ago
    Anonymous

    print(open('symbol.txt').read())

    • 2 months ago
      Anonymous

      holy based. now do it with a url request

      • 2 months ago
        Anonymous

        from selenium import webdriver as w
        print(w.Chrome(options=w.ChromeOptions()).get('https://kek.com/symbol.txt').page_source)

        hitting bloat levels that shouldn't even be possible

        • 2 months ago
          Anonymous

          >bloat
          I think you will find this is just the modern standard for that sort of thing.

  15. 2 months ago
    Anonymous

    def line(string, scale, times):
    [a, b, c, d, e] = string
    for _ in range(times):
    print(a + b * scale + c + d * scale + e)

    n = 2
    line('* ***', n, 1)
    line('* * ', n, n)
    line('*****', n, 1)
    line(' * *', n, n)
    line('*** *', n, 1)

  16. 2 months ago
    Anonymous

    >half the thread is pyshitters
    absolute state of IQfy-nazis

    • 2 months ago
      Anonymous

      chuds can't code

    • 2 months ago
      Anonymous

      What!?
      Python code in a Python Challenge thread?
      wtf

  17. 2 months ago
    Anonymous

    in RUST this is just:
    use Char::*;

    #[derive(Clone)]
    enum Char {
    Star(i32),
    Blank(i32),
    }

    fn print_row(chars: &Vec<Char>) {
    for c in chars {
    match *c {
    Star(i) => (0..i).for_each(|_| print!("*")),
    Blank(i) => (0..i).for_each(|_| print!(" ")),
    }
    }
    print!("n");
    }

    fn main() {
    let rad = 10;

    let top_row = vec![Star(1), Blank(rad - 2), Star(1), Star(rad - 2), Star(1)];
    let mid_top_row = vec![Star(1), Blank(rad - 2), Star(1), Blank(rad - 2), Blank(1)];
    let mid_row = vec![Star((rad * 2) - 1)];

    let mid_bot_row = mid_top_row.iter().cloned().rev().collect();
    let bot_row = top_row.iter().cloned().rev().collect();

    print_row(&top_row);
    (0..(rad - 2)).for_each(|_| print_row(&mid_top_row));
    print_row(&mid_row);
    (0..(rad - 2)).for_each(|_| print_row(&mid_bot_row));
    print_row(&bot_row);
    }

    • 2 months ago
      Anonymous
    • 2 months ago
      Anonymous

      fn print_row(v: &Vec<(&str, usize)>) {
      v.iter().for_each(|(c, i)| print!("{}", c.repeat(*i*~~;
      println!("")
      }

      fn main() {
      let n = 2;

      let top = vec![("*", 1), (" ", n), ("*", 1), ("*", n), ("*", 1)];
      let up1 = vec![("*", 1), (" ", n), ("*", 1), (" ", n), (" ", 1)];
      let mid = vec![("*", 1), ("*", n), ("*", 1), ("*", n), ("*", 1)];
      let up2 = vec![(" ", 1), (" ", n), ("*", 1), (" ", n), ("*", 1)];
      let bot = vec![("*", 1), ("*", n), ("*", 1), (" ", n), ("*", 1)];

      print_row(&top);
      for _ in 1..=n { print_row(&up1) }
      print_row(&mid);
      for _ in 1..=n { print_row(&up2) }
      print_row(&bot);
      }

      I don't understand why i is a reference in for_each

      • 2 months ago
        Anonymous

        Just realised print_row can also be written as
        fn print_row(v: &Vec<(&str, usize)>) {
        println!("{}", v.iter().fold(String::new(), |acc, (c, i)| acc + &c.repeat(*i*~~
        }

      • 2 months ago
        Anonymous

        Just realised print_row can also be written as
        fn print_row(v: &Vec<(&str, usize)>) {
        println!("{}", v.iter().fold(String::new(), |acc, (c, i)| acc + &c.repeat(*i*~~
        }

        I also translated this in Haskell
        print_row :: [(Char, Int)] -> IO ()
        print_row = putStrLn . foldl (acc (i, c) -> acc ++ replicate c i) ""

        main = do
        let n = 2
        let top = [('*', 1), (' ', n), ('*', 1), ('*', n), ('*', 1)]
        let up1 = [('*', 1), (' ', n), ('*', 1), (' ', n), (' ', 1)]
        let mid = [('*', 1), ('*', n), ('*', 1), ('*', n), ('*', 1)]
        let up2 = [(' ', 1), (' ', n), ('*', 1), (' ', n), ('*', 1)]
        let bot = [('*', 1), ('*', n), ('*', 1), (' ', n), ('*', 1)]

        print_row top
        mapM print_row $ replicate n up1
        print_row mid
        mapM print_row $ replicate n up2
        print_row bot

        Idk if there is a better way. Maybe zipping? I tried zipping in Rust and it sucked because of how many iterators it needed and then the type system fricked everything up

  18. 2 months ago
    Anonymous

    Good morning sirs!
    fn main() {
    println!(r#"
    * ****
    * *
    * *
    *******
    * *
    * *
    **** *
    "#);
    }

  19. 2 months ago
    Anonymous

    I did it in J.

    • 2 months ago
      Anonymous

      In J this is just
      ' *'{~|:(+.|.@|:)^:3(3&>+3=7&|)i.7 7
      * ****
      * *
      * *
      *******
      * *
      * *
      **** *

      • 2 months ago
        Anonymous

        Based. I am struggling to learn all this wizardry; if only I had known about (+.|.@|:)^:3...
        I've extended the code to specify the radius:
        ' *'{~(+.|.@|:)^:3 {{(<:y,1)|.(0 0{(1-+:y)){.0=*./"1>{;~i.y}}7
        * *******
        * *
        * *
        * *
        * *
        * *
        *************
        * *
        * *
        * *
        * *
        * *
        ******* *

  20. 2 months ago
    Anonymous

    >python
    Did a while ago in brainfrick. Press a number from 3 to 9 to choose a size (radius).
    >>>++++++++[->++++>++++<<]>+++>>++++++++++<<<<<<+[-,.>>>>>>..<<<<<+++++[<---------->-]>>>.<<<<[->>+>+<<<]>>>[-<<<+>>>]<[>>>.<<<-]>>.<<<<[->>+>+<<<]>>>[-<<<+>>>]<[>>.<<-]>>.>>.<<<<<<[->+>+<<]>>[-<<+>>]<[>>>.<<<<[->>+>+<<<]>>>[-<<<+>>>]<[>>>.<<<-]>>.>>.<<<<<-]>>>...<<<<[->>++>+<<<]>>>[-<<<+>>>]<[>>.<<-]>>>>.<<<<<<[->+>+<<]>>[-<<+>>]<[>>>>.<<<<<[->>+>+<<<]>>>[-<<<+>>>]<[>>>.<<<-]>>.<<<<[->>+>+<<<]>>>[-<<<+>>>]<[>>>.<<<-]>>.>>.<<<<<-]>>>..<<<<[->>+>+<<<]>>>[-<<<+>>>]<[>>.<<-]<<[->>+>+<<<]>>>[-<<<+>>>]<[>>>.<<<-]>>.>>...<<<<<<[-]+]

  21. 2 months ago
    Anonymous

    rate
    #include <stdio.h>
    int main(void)
    {
    enum{N=7,R=N/2+1,K=N*N};
    int v[K]={0},i,j,k;
    for (i=0;j=i%R,k=i/R,i<R*R;++i)v[j+R-1+k*N]=!j|!k;
    for (i=0;k=i%K,i<2*K;++i)v[k]|=v[N-1-k/N+k%N*N];
    for (i=0;i<K;++i){printf("%c%c",v[i]?'*':' ',(i%N==N-1)*'n');}
    }

  22. 2 months ago
    Anonymous

    They forgot to add in the dots in between

  23. 2 months ago
    Anonymous

    Reminder that pure languages mog shithon.

    • 2 months ago
      Anonymous
    • 2 months ago
      Anonymous

      >jpg
      nein

  24. 2 months ago
    Anonymous

    Wonder if someone could do something cool with Turtle to draw this

  25. 2 months ago
    Anonymous

    Post the hardest most complex way to achieve that

    • 2 months ago
      Anonymous

      Implement it as a closed form function for a polar plot of complex numbers.

    • 2 months ago
      Anonymous

      see

      >python
      Did a while ago in brainfrick. Press a number from 3 to 9 to choose a size (radius).
      >>>++++++++[->++++>++++<<]>+++>>++++++++++<<<<<<+[-,.>>>>>>..<<<<<+++++[<---------->-]>>>.<<<<[->>+>+<<<]>>>[-<<<+>>>]<[>>>.<<<-]>>.<<<<[->>+>+<<<]>>>[-<<<+>>>]<[>>.<<-]>>.>>.<<<<<<[->+>+<<]>>[-<<+>>]<[>>>.<<<<[->>+>+<<<]>>>[-<<<+>>>]<[>>>.<<<-]>>.>>.<<<<<-]>>>...<<<<[->>++>+<<<]>>>[-<<<+>>>]<[>>.<<-]>>>>.<<<<<<[->+>+<<]>>[-<<+>>]<[>>>>.<<<<<[->>+>+<<<]>>>[-<<<+>>>]<[>>>.<<<-]>>.<<<<[->>+>+<<<]>>>[-<<<+>>>]<[>>>.<<<-]>>.>>.<<<<<-]>>>..<<<<[->>+>+<<<]>>>[-<<<+>>>]<[>>.<<-]<<[->>+>+<<<]>>>[-<<<+>>>]<[>>>.<<<-]>>.>>...<<<<<<[-]+]

    • 2 months ago
      Anonymous

      Implement it as a closed form function for a polar plot of complex numbers.

      Inspired
      r = 3
      d = 2 * r + 1

      points = set.union(
      {(i, r) for i in range(d)},
      {(r, j) for j in range(d)},
      {(i, 0) for i in range(r)},
      {(0, j) for j in range(r, d)},
      {(i, d - 1) for i in range(r, d)},
      {(d - 1, j) for j in range(r)},
      )

      print('n'.join(''.join('*' if (i, j) in points else ' ' for j in range(d)) for i in range(d*~~

      • 2 months ago
        Anonymous

        Also
        r = 3
        d = 2 * r + 1

        def point(i, j):
        return (j == r and 0 <= i < d
        or i == r and 0 <= j < d
        or j == 0 and 0 <= i < r
        or i == 0 and r < j < d
        or j == d - 1 and r < i < d
        or i == d - 1 and 0 <= j < r)

        print('n'.join(''.join('*' if point(i, j) else ' ' for j in range(d)) for i in range(d*~~

  26. 2 months ago
    OS MASTER

    prtin("卍)"

  27. 2 months ago
    Anonymous

    >tripgay
    >passgay
    >backwards swastika

  28. 2 months ago
    Anonymous

    It would be harder to implement it if the pattern was angled.

  29. 2 months ago
    Anonymous

    don't @ me
    x = 7;
    y = 7;
    h = x/2;
    for (let i=0; i<y; i++) {
    let line = "";
    for (let j=0; j<x; j++) {
    let star = i === Math.floor(h) || j === Math.floor(h);
    star = star || (j === 0 && i < h) || (i === 0 && j > h);
    star = star || (j === x-1 && i > h) || (i === y-1 && j < h);
    line += star ? "*" : " ";
    }
    console.log(line);
    }

  30. 2 months ago
    Anonymous

    The final solution.

  31. 2 months ago
    Anonymous

    print('* ****','* *','* *','*'*7,' * *',' * *','**** *',sep='n')

  32. 2 months ago
    Anonymous

    x, i = 349939169379577, 1
    while x:
    print(" *"[x & 1], end="n "[i % 7])
    x, i = x >> 1, i + 1

    • 2 months ago
      Anonymous

      For general size
      r = 3
      d = 2 * r + 1

      x = 1 + (1 << r) + ((1 << r) - 1 << r + 1)
      x += sum(1 + (1 << r) << i*d for i in range(1, r))
      x += ((1 << d) - 1 << r*d)
      x += sum((1 << r) + (1 << d - 1) << i*d for i in range(r + 1, d - 1));
      x += (1 << r) - 1 + (1 << r) + (1 << d - 1) << (d - 1)*d

      i = 1
      while x:
      print(' *'[x & 1], end='' if i % d else 'n')
      x, i = x >> 1, i + 1

      (Using a gap in the first part of the if in end makes it more square)

  33. 2 months ago
    Anonymous

    scheiss hurensoehne

  34. 2 months ago
    Anonymous

    i wouldnt trust any code in this thread besides the pre-formated print() chads

  35. 2 months ago
    Anonymous

    now make it spin

Leave a Reply to Anonymous Cancel reply

Your email address will not be published. Required fields are marked *