• 1 Post
  • 38 Comments
Joined 2 years ago
cake
Cake day: July 4th, 2023

help-circle
  • I decided to use NAND instead of NOR, but it’s effectively the same thing.

    Scala:

    //main
    @main
    def main(): Unit =
      var i = 15 //Choose any number here
      i = add(i, 1) //this increments i
      println(i)
    
    //Adds 2 numbers in the most intuitive way
    def add(a: Int, b: Int): Int =
      val pairs = split(a).zip(split(b))
      val sumCarry = pairs.scanLeft(false, false)((last, current) => fullAdder(current._1, current._2, last._2))
      return join(sumCarry.map(_._1).tail.reverse)
    
    //Converts an integer to a list of booleans
    def join(list: Seq[Boolean]): Int = BigInt(list.map(if (_) '1' else '0').mkString, 2).toInt
    
    //Converts a list of booleans to an integer
    def split(num: Int): Seq[Boolean] = num.toBinaryString.reverse.padTo(32, '0').map(_ == '1')
    
    //Adds 2 booleans and a carry in, returns a sum and carry out
    def fullAdder (a: Boolean, b: Boolean, c: Boolean): (Boolean, Boolean) =
      (NAND(NAND(NAND(NAND(a, NAND(a, b)), NAND(NAND(a, b), b)), NAND(NAND(NAND(a, NAND(a, b)), NAND(NAND(a, b), b)), c)), NAND(NAND(NAND(NAND(a, NAND(a, b)), NAND(NAND(a, b), b)), c), c)), NAND(NAND(NAND(NAND(a, NAND(a, b)), NAND(NAND(a, b), b)), c), NAND(a, b)))
    
    //The basis for all operations
    def NAND(a: Boolean, b: Boolean): Boolean = !a || !b
    

    EDIT: replaced Integer.parseInt with BigInt(...).toInt to fix NumberFormatException with negative numbers.

    try it online here












  • A hydrogen engine is so much worse for efficiency than a hydrogen fuel cell, and even that is not good compared to batteries. I’d estimate the round trip efficiency of a hydrogen engine to be about 10-15%. So for the same energy that could be used to drive a battery EV 100km, this car from Toyota could drive 12km.

    Additionally, hydrogen is not very energy dense per volume. A compressed hydrogen tank that replaces the boot/trunk of the car would have enough hydrogen for about 100km of range.

    Please let me know if I’m wrong about any of these numbers. For Toyota’s sake, I really hope I’m wrong.




  • The main problem with the new leaf is the lack of battery cooling. After 3 (sometimes 2) rapid charges in a day the battery is at max temperature and the charge rate drastically reduces.

    Unless you already have a CHAdeMO V2G charger, I recommend choosing an EV with battery cooling (almost all of them). You can probably find one with more features and longer range for a lower price than a new Leaf.

    If you aren’t planning on using the car enough to worry about battery overheating, and you enjoy the test drive, it’s not actually a bad car. Just a little overpriced.