Coding Challenge

Поділитися
Вставка
  • Опубліковано 19 жов 2024

КОМЕНТАРІ • 91

  • @polskus
    @polskus 6 років тому +58

    At my school, they taught us decimal to binary conversion like this (and it would solve your "constraint" to 8 bits):
    I'm going to show you an example what the procedure is:
    Let's say we want to convert 90:
    90 / 2 = 45 Remainder 0
    45 / 2 = 22 Remainder 1
    22 / 2 = 11 Remainder 0
    11 / 2 = 5 Remainder 1
    5 / 2 = 2 Remainder 1
    2 / 2 = 1 Remainder 0
    1 / 2 = 0 Remainder 1
    Now read the remainders from bottom to the top, and you'll get the binary number from left to right:
    1011010
    And you could then code your converting algorithm so that it divides by two and saves the remainder until the number that is getting divided reaches 0

    • @kirkanos771
      @kirkanos771 6 років тому +1

      or you can type (90 >>> 0).toString(2) that is way more faster than the cyclomatically complex algorithm you are trying to use. It was fun in the 90s when you had to optimize computation for your game to run smoothly on a i386. But nowadays, the native methods are going to be faster, anytime.

    • @sigmareaver680
      @sigmareaver680 6 років тому +3

      That's cool. So it'd be something like this psuedo code:
      x = 90, n[]
      while (x)
      n.insert(0, x % 2)
      x = x / 2
      end

    • @polskus
      @polskus 6 років тому

      @@kirkanos771 Yes, Daniel even mentioned that he could just use num.toString(2), but he wanted to show the conversion from decimal to binary. What I don't understand in your proposed code though is why you want to logically shift right by zero and then convert to binary.

    • @polskus
      @polskus 6 років тому +1

      @@sigmareaver680 Yes, and then reverse the Array and you got the numbers in the correct order.

    • @kirkanos771
      @kirkanos771 6 років тому

      IceCreeper28 You can ignore the triple shift operator, it is just there to prevent shifting negative numbers. That could give undesirable effects. It's up to you to use it if you intend to manage the binary representation of negative numbers (it's band dependant though, 32 bits ? yep, i just tried in the console).

  • @Remls
    @Remls 6 років тому +88

    4:52
    "Function ..."
    **writes something not even remotely resembling the word function**

    • @benstoffels5108
      @benstoffels5108 6 років тому

      Haha

    • @Engineer9736
      @Engineer9736 6 років тому +7

      Tijmf6 😂

    • @jamessantiago2253
      @jamessantiago2253 6 років тому +2

      I always type funciton! Function seems to be a difficult word to type! Maybe this is why in javascript we now have arrow functions!

    • @dionzz99
      @dionzz99 5 років тому

      "Shift.."
      "ehi"
      **backspace intensifies**
      "ejot"
      **backspace again**

  • @thorzweegers7616
    @thorzweegers7616 2 роки тому

    You are SO the perfect nerd. Loving your uploads! Thanks!

  • @mayursaroj4360
    @mayursaroj4360 6 років тому +16

    he is so passionate about what he does..i want to be like him..😊😍

    • @picosdrivethru
      @picosdrivethru 2 роки тому

      I know right! It's infectious, I love it.

  • @wowatomica
    @wowatomica 6 років тому

    Dude Dan the happiest shiftman.. your excitement is so contagious!

  • @nick11927
    @nick11927 6 років тому +21

    I was going to make a "clever" joke about Shiftman but you made it for me :(

  • @AfonsodelCB
    @AfonsodelCB 6 років тому

    I was gonna learn this some time in school in the new few months, but I'm glad you explained this before it happen, will make life a lot easier. your explanations are also better than that of most teachers

  • @998joko
    @998joko 6 років тому +4

    please do challenge in Line algorithm like bresenhams line, midpoint line etc.
    i love your entire video...

  • @alexfrasca673
    @alexfrasca673 6 років тому +1

    Hi dan, a bit of visual design advice.. if you want something to appear "on" or "off," you must make the background the darkest (or lightest) color. Otherwise, on and off will be perceived as a similar contrast from the background, so for the viewer it's just kind of confusing. So maybe make the background 51, "off" 100, and "on" 255

  • @GuitarreroDaniel
    @GuitarreroDaniel 4 роки тому

    I love your energy man, great explanation btw

  • @OrangeC7
    @OrangeC7 6 років тому +2

    "tijmf6 shiftBits() {
    }"
    Has a nice ring to it.

  • @shervilgupta92
    @shervilgupta92 6 років тому

    Ive added both kinda shifts by number of bits user specifies.
    :D , man you really have developed my interest in coding again...

  • @DogwafflDan
    @DogwafflDan 6 років тому

    Like it when you cover the old school tricks!

  • @kamoroso94
    @kamoroso94 6 років тому

    Oh Dan, you could look at showing how bit flags work with masking in your next video! Also, if you wanna take this idea to the extreme to really solidify the idea of bit shifting and masking, you could implement a bitmap. Every bit would be like an element in a Boolean array, just stored more compactly as bits.

  • @WildAnimalChannel
    @WildAnimalChannel 6 років тому

    Mr SHIFTman you did some good bit of bit SHIFTing on this SHIFT.

  • @gregcampbell4467
    @gregcampbell4467 6 років тому +1

    10:52 "Is it weird how much fun this is for me?" Dunno, Is it weird how much I enjoy watching you have fun in front of a video camera in a closet?

  • @MrRushifyIt
    @MrRushifyIt 6 років тому +1

    You got so excited at 13:35 :D you're great

  • @mmahgoub
    @mmahgoub 6 років тому

    We love you, Daniel!

  • @RicoGalassi
    @RicoGalassi 5 років тому +1

    do you think it would be hard to do a coding challenge without talking? hahah Love your videos btw! It's nice to hear you think everything out!

  • @eugenetswong
    @eugenetswong 2 роки тому

    Thank you for this and #119. I hope to get good at programming. I figure that bit operations are important.

  • @andremonteiro3408
    @andremonteiro3408 6 років тому +9

    Hey, could you make a coding challenge for a pool game ? It would be cool :D

  • @sebguex1970
    @sebguex1970 6 років тому

    An easier to convert a number from decimal to binary is to see whether the given number can be divided by 2. If it is then the least significant bit (the one that correspond to the power of 0) will be 0, and if it isn't this bit is going to be 1. Then you just have to take you number and divide it by 2 and repeat the process (as dividing by 2 just shifts the bits to the right by 1 place) until you end up with a value of zero. Then you just fill the higher powers with 0
    The algorithm (pseudocode) would be :
    Create an empty string
    Create a copy of your number which I'll call val
    For i between 0 (included) and 8 (excluded) {
    If val % 2 == 1 then add 1 to the front of the string, otherwise add 0
    val = val/2
    If val == 0 then fill the string with zeros from the front until its size is 8 and break from the loop.
    }
    Return the string

  • @willysatrionugroho8086
    @willysatrionugroho8086 5 років тому

    Yup it's interesting because binary is 2 number system while decimal is 10 number system. If you want to get hundreds from thousands just divide it by 10. Same concept applies in any number system, in binary divide it by two, in nonal divide it by 9,in hexadecimal divide it by 16, and so on.

  • @TelosZeratul
    @TelosZeratul 6 років тому +4

    Oh, okay. I forgot about you, the viewer! Auhauhauhaaua. (Daniel getting into the his own world of craziness and creativity)

  • @Ofilafoo
    @Ofilafoo 6 років тому

    You make me love Rainbows. Thanks that you beeing here

  • @nielsdaemen
    @nielsdaemen 2 роки тому

    I had no idea JavaScript supported bitwise operators just like C
    Interesting video as always 😁

  • @Softwareengineeringdev
    @Softwareengineeringdev 6 років тому +1

    Well Explained !

  • @pidi64
    @pidi64 6 років тому +2

    function DecToBinStr(value)
    {
    if(!value) return "0";
    let output = "";
    while(value > 0)
    {
    output = (value & 1) + output;
    value >>= 1;
    }
    return output;
    }

  • @DominicVictoria
    @DominicVictoria 5 років тому

    Just like shifting a base 10 number(Regular numbers we use as humans) either multiplies it or divides it by 10

  • @Engineer9736
    @Engineer9736 6 років тому

    You could have put the updating of the byte array right into the decimalToBinary for loop. Would have saved CPU cycles. This would of course require a rename of the decimalToBinary function. Maybe decimalToByteArray or so.

  • @voiddeepstorage6533
    @voiddeepstorage6533 5 років тому

    Decimal to binary is easy:
    int n = 255
    char[] byte = new char[8];
    int c = 7;
    while(n!=1){
    char[c] = n%2 == 0 ? 1 : 0;
    n /= 2;
    c--;
    }
    ( I dont know if this works 100%, but i have a code that uses the same logic ( n%2 ) that works fine )

  • @sigmareaver680
    @sigmareaver680 6 років тому +1

    Is it possible to request a topic be covered? If so, I'd really like help with concave polygon triangulation and collision detection. I haven't found good explanations online.

    • @TheCodingTrain
      @TheCodingTrain  6 років тому +1

      Please suggest here! github.com/CodingTrain/Rainbow-Topics/issues

  • @edoardomagenta6917
    @edoardomagenta6917 6 років тому

    Maybe, in the next codding challenge, you can try to rappresents atomic orbital shape using functions

  • @TwistedSoul2002
    @TwistedSoul2002 4 роки тому

    I wanted to like this video- you seem very knowledgeable and can definitely explain things well.... the problem I found is that the presentation was a bit ‘scatter brain’.
    The explanation jumps around too much and you reference things we don’t know about.. I’m already confused about *why* we need to binary shift but I only made it to 06:34 before I bailed.
    This would be good as a first take...

  • @pheisar
    @pheisar 6 років тому

    5:42
    Love it!

  • @bastian261198
    @bastian261198 6 років тому +1

    So you are Daniel Shiftman? :D
    Now I watched the video ^^

  • @LaurensVRC
    @LaurensVRC 5 років тому +1

    New coding challenge: two swirling galaxies colliding... :D

  • @georgeyjm
    @georgeyjm 6 років тому +1

    5:44
    I always do this when I'm explaining something to someone...And they just have no idea what I'm "oh"ing and "ah"ing about.

  • @XoIoRouge
    @XoIoRouge 6 років тому +4

    Wait, the next video isn't available?
    Wait, this video was posted a few days ago?
    *I caught up?!* :(

  • @avi12
    @avi12 6 років тому +8

    12:48 My eyes are burning for not using "%=" operator!

    • @alfredomant
      @alfredomant 6 років тому

      avi12
      Oh look! the next Mark Zuckerberg 😂

  • @kevinandrews9302
    @kevinandrews9302 6 років тому

    you should mess around with hexadecimals while you're on the subject of bitwise stuff!

  • @shocelot3482
    @shocelot3482 6 років тому

    Subbed!!

  • @zyada9334
    @zyada9334 6 років тому +27

    Can you make half life 3 using any coding language ?

    • @Engineer9736
      @Engineer9736 6 років тому +2

      lazlo the boy It was a joke. Since the world is already waiting for HL3 since 2004. It has some kind of legendary status.

    • @k.alipardhan6957
      @k.alipardhan6957 5 років тому

      @@thebirdhasbeencharged opengl sucks :P

  • @MyurrDurr
    @MyurrDurr 6 років тому

    *tijmf6*
    Ah yes, my favorite function name

  • @charlesbinet2301
    @charlesbinet2301 6 років тому

    Do it with any base (with a base slider) ;)

  • @user-zu6ts5fb6g
    @user-zu6ts5fb6g 6 років тому

    lol thats so cool!

  • @pacibrzank78
    @pacibrzank78 6 років тому

    Why are you using “let“ instead of “var“?

    • @TheCodingTrain
      @TheCodingTrain  6 років тому

      I talk about let and var in this video: ua-cam.com/video/q8SHaDQdul0/v-deo.html

  • @basilbaby2069
    @basilbaby2069 6 років тому

    💜💜💜

  • @anuraghazra4772
    @anuraghazra4772 6 років тому +1

    I have a question actually, how does p5 knows that the p5's native functions are called outside of draw or setup?

    • @RealSquidicus
      @RealSquidicus 6 років тому +1

      Because when p5 is imported the functions are made global, they can be accessed anywhere.

    • @anuraghazra4772
      @anuraghazra4772 6 років тому +1

      No, i mean when i use any function outside of draw() or setup() p5js gives me - "Did you just try to use p5.js's rect() function? If so, you may want to move it into your sketch's setup() function.
      " - This Warning Message, but how does p5js knows that i am using it outside of setup() or draw()?

    • @WannesMalfait
      @WannesMalfait 6 років тому

      @@anuraghazra4772 you can create your own functions right? Well if you "create" a function that is part of p5 it will first try to treat it as your own function but then see it exists and realise that it should be in setup or draw. That's what I think.

    • @RealSquidicus
      @RealSquidicus 6 років тому

      @@anuraghazra4772 my guess would be because technically everything is being called via either the setup or draw, e.g show has rect/ellipse functions but it gets called from draw, maybe you're trying to call these functions in a different way? It'll give you a warning because I believe the draw function is supposed to know what is being drawn and external calls might mess with it

    • @potatoes8169
      @potatoes8169 6 років тому

      I dont know how they do it, but a possible way to do:
      function onload()
      {
      //....
      //otherstuff here
      SETTINGUP = true;
      setup();
      SETTINGUP = false;
      //otherstuff here
      //..
      }
      function size()
      {
      if(SETTINGUP )
      {
      //...
      }
      else
      console.debug("Warning message blah blah blah ..");
      }
      Anyway thats just my guess. (I didnt check if thats what they do).

  • @aminthemar
    @aminthemar 4 роки тому

    0:01 Hello! Welcome to coding challenge, BITCH!! Shifting...

  • @proki8081
    @proki8081 6 років тому

    Trying to learn to code idea where to start

    • @TheCodingTrain
      @TheCodingTrain  6 років тому

      My beginner playlist (no prior knowledge required) is here: ua-cam.com/video/yPWkPOfnGsw/v-deo.html

  • @bapolino733
    @bapolino733 6 років тому

    You should release more videos with a premier before the actual release

  • @mcfansrandomvids
    @mcfansrandomvids 6 років тому

    Seventh!

  • @neuralengine965
    @neuralengine965 6 років тому

    Where is interesting stuff like ml5.js?

  • @avi12
    @avi12 6 років тому

    11:26 Or just: 2 ** i

  • @patson3910
    @patson3910 3 роки тому

    ahaha you're so cool

  • @sofi-up4kd
    @sofi-up4kd 6 років тому

    holaaaa

  • @sonialangemotion
    @sonialangemotion 6 років тому

    Please make a Voronoi cells coding challenge!!

  • @lennysmileyface
    @lennysmileyface 5 років тому

    90 / 128 = 0r90?? What maths are you doing mate?

  • @AlgyCuber
    @AlgyCuber 6 років тому

    first!!!!

  • @Linxy
    @Linxy 6 років тому

    RIP now we will have horrible codebases where people bitshift instead of using / and *

  • @Flor12344
    @Flor12344 6 років тому

    more premiers

  • @Everything_Music
    @Everything_Music 2 роки тому

    This seems like the mind of someone with ADHD, going all over the place. Good video though :)