Python Pattern Challenge

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

Thalidomide Vintage Ad Shirt $22.14

DMT Has Friends For Me Shirt $21.68

Thalidomide Vintage Ad Shirt $22.14

  1. 1 month ago
    Anonymous

    >most efficient way
    store it as string to be displayed

  2. 1 month ago
    Anonymous

    import timeTravel

    timeTravel.toTheGoodOlDays()

  3. 1 month 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

    • 1 month ago
      Anonymous

      keyed

    • 1 month 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.

      • 1 month ago
        Anonymous

        fr fr

      • 1 month 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

        • 1 month 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.

          • 1 month 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

    • 1 month ago
      Anonymous

      two more weeks, comrade pidorenko

    • 1 month ago
      Anonymous

      Good morning sir

    • 1 month ago
      Anonymous

      52 more weeks, vatnik

  4. 1 month ago
    Anonymous

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

  5. 1 month ago
    Anonymous

    Iterate line by line with a bunch of if checks.

  6. 1 month 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)]))

    • 1 month ago
      Anonymous

      frick

  7. 1 month 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

    • 1 month 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. 1 month ago
    Anonymous

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

    • 1 month ago
      Anonymous

      >for i in b'yttx7fHHO':
      Wat

      • 1 month ago
        Anonymous

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

  9. 1 month ago
    Anonymous

    print("""

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

    • 1 month 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. 1 month 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>"]))

    • 1 month ago
      Anonymous

      Still the shortest non-meme solution.

  11. 1 month ago
    Anonymous

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

  12. 1 month 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?

    • 1 month 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

    • 1 month 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.

      • 1 month ago
        Anonymous

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

        • 1 month 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

        • 1 month 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. 1 month 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. 1 month ago
    Anonymous

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

    • 1 month ago
      Anonymous

      holy based. now do it with a url request

      • 1 month 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

        • 1 month ago
          Anonymous

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

  15. 1 month 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. 1 month ago
    Anonymous

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

    • 1 month ago
      Anonymous

      chuds can't code

    • 1 month ago
      Anonymous

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

  17. 1 month 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);
    }

    • 1 month ago
      Anonymous
    • 1 month 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

      • 1 month 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*~~
        }

      • 1 month 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. 1 month ago
    Anonymous

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

  19. 1 month ago
    Anonymous

    I did it in J.

    • 1 month ago
      Anonymous

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

      • 1 month 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. 1 month ago
    Anonymous

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

  21. 1 month 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. 1 month ago
    Anonymous

    They forgot to add in the dots in between

  23. 1 month ago
    Anonymous

    Reminder that pure languages mog shithon.

    • 1 month ago
      Anonymous
    • 1 month ago
      Anonymous

      >jpg
      nein

  24. 1 month ago
    Anonymous

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

  25. 1 month ago
    Anonymous

    Post the hardest most complex way to achieve that

    • 1 month ago
      Anonymous

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

    • 1 month ago
      Anonymous

      see

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

    • 1 month 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*~~

      • 1 month 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. 1 month ago
    OS MASTER

    prtin("卍)"

  27. 1 month ago
    Anonymous

    >tripgay
    >passgay
    >backwards swastika

  28. 1 month ago
    Anonymous

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

  29. 1 month 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. 1 month ago
    Anonymous

    The final solution.

  31. 1 month ago
    Anonymous

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

  32. 1 month ago
    Anonymous

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

    • 1 month 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. 1 month ago
    Anonymous

    scheiss hurensoehne

  34. 1 month ago
    Anonymous

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

  35. 1 month ago
    Anonymous

    now make it spin

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