[-] 18107@aussie.zone 6 points 1 day ago* (last edited 1 day ago)

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

[-] 18107@aussie.zone 52 points 1 year ago

And people wonder why whales beach themselves.

[-] 18107@aussie.zone 218 points 1 year ago

Why limit these fees to foreigners? Why not penalize anyone who is leaving properties empty?

[-] 18107@aussie.zone 51 points 1 year ago

There's no hate like christian love.

[-] 18107@aussie.zone 41 points 1 year ago

The plural of regex is regrets.

[-] 18107@aussie.zone 39 points 1 year ago

This is the worst thing I have seen all year.

[-] 18107@aussie.zone 101 points 1 year ago

The forum post you were referring to.

[-] 18107@aussie.zone 47 points 1 year ago

I have an electric car from 2011. The battery has had no maintenance, and hasn't been replaced.

So far the car has had 2-3 new 12V batteries, at least one new set of tires, windscreen wipers replaced once, and the air conditioner filter replaced a few times. I'm not aware of any other maintenance done to the car.

I suspect the car could have driven up to 150km (95mi) when new, and is now down to 80km (50mi) range. It gets driven no more than 10km in a day, so I suspect it will still be useful to me for another 10 years.

It has saved me a huge amount in fuel, and has barely cost me anything to run.

[-] 18107@aussie.zone 39 points 1 year ago

I really hope those aren't factorials.

[-] 18107@aussie.zone 53 points 1 year ago

Even if cats could talk, and could definately see the stripes, I'm convinced that they wouldn't tell anyone.

[-] 18107@aussie.zone 55 points 1 year ago

I'd recommend an electric car for avoiding oil changes, but I think we still have a few more years until cheap second hand electric cars become available.

view more: next ›

18107

joined 2 years ago