peltorator's blog

By peltorator, 3 years ago, In English

Hi!

I wanted to make a new fun screencast. In this video, I'm solving Codeforces Round #747 (div. 2) but there are two main differences from a regular screencast:

  1. It's a highlight video which means that it's not a 2-hour long video of me thinking about problems but just some fun, interesting, exciting moments.

  2. It's something I called a "Challenge Screencast" which means that there is a challenge I need to complete during the contest. This time the challenge was to not use any loops in the code. So no for loops, no while loops... At all!

https://youtu.be/imGdtb_lB_U

I hope you'll enjoy it! I'll be happy to hear any comments and suggestions for the future challenge screencasts!

  • Vote: I like it
  • +220
  • Vote: I do not like it

| Write comment?
»
3 years ago, # |
  Vote: I like it +43 Vote: I do not like it

Just use this

template<class Cond, class Body>
void while_loop(Cond c, Body b) {
    if (c()) {
        b();
        while_loop(c, b);
    }
}

template<class Init, class Cond, class Step, class Body>
void for_loop(Init i, Cond c, Step s, Body b) {
    i();
    while_loop(c, [&]() { b(); s(); });
}
  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    As I said at the start of the video of course there always are some hacks like using goto or std::generate but I wanted to actually avoid loops or any replacements of loops.

    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it +32 Vote: I do not like it

      That was a joke, but on a more serious side, all of the STL functions internally use loops, and transform is a close as there is to a loop replacement. The recursive solution doesn't use loops at any level.

      • »
        »
        »
        »
        3 years ago, # ^ |
          Vote: I like it +17 Vote: I do not like it

        Ok, sorry :)

        About STL functions. Yes, of course, that is true. But when you use a function like find or accumulate, you're not thinking in terms of loops. You're thinking at a higher level, where you're just performing some operations with sequences. If we would use something like accumulative variable + iota + generate or smth that would actually be just a loop replacement, but I don't think that basic STL usage is "loopy".

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

can't u do recursion?

  • »
    »
    3 years ago, # ^ |
    Rev. 2   Vote: I like it +12 Vote: I do not like it

    Wow. This is really a cool way to do this challenge.

    Spoiler
»
3 years ago, # |
  Vote: I like it +14 Vote: I do not like it

A challenge where you use have to use goto to make your code execute from bottom to top.

»
3 years ago, # |
  Vote: I like it +10 Vote: I do not like it

upvoted cuz I am already having ptsd seeing 5 mins of stream. cant imagine life without loops

»
3 years ago, # |
  Vote: I like it +36 Vote: I do not like it

Man had to spend more time on Stack Overflow than on Codeforces, during the contest XDXD.

»
3 years ago, # |
  Vote: I like it +80 Vote: I do not like it

Can't wait for the second episode in div1

»
3 years ago, # |
  Vote: I like it +8 Vote: I do not like it

You should check out how functional programmers do it. IIRC clyring competes using haskell!

  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I really enjoy haskell. Thank's one of the reasons I decided to do this challenge.

»
3 years ago, # |
  Vote: I like it +10 Vote: I do not like it

This was something different, Loved it!!

»
3 years ago, # |
  Vote: I like it +43 Vote: I do not like it

Suggestion: write every problem in a different language

»
3 years ago, # |
  Vote: I like it +8 Vote: I do not like it

My suggestions :-

  1. Read all the problem statements at once noting necessary details in first 10-15 minutes and then never look at them during the contest.

  2. Only one attempt per problem. You can't resubmit once you get a WA or TLE or a RUNTIME error etc.

  3. Not using #include <bits/stdc++.h> (Not that challenging TBH)

»
3 years ago, # |
  Vote: I like it +49 Vote: I do not like it

Imagine a beginner who didn’t understand the concept from editorial and accidentally open peltorator's codes!

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Now next challenge : Don't use cout or printf in C++. :XD

»
3 years ago, # |
  Vote: I like it +3 Vote: I do not like it

how about not using 'if'