Untitled

mail@pastecode.io avatar
unknown
nim
a year ago
2.9 kB
8
Indexable
Never
import strutils, random, std/sequtils, std/sugar

const age = 29
const daysInYear = 365
const days = age * daysInYear

echo "age is: ", age, " | days in year: ", daysInYear, " | total days in age: ", days

echo "divisible by 3? ", daysInYear mod 3 == 0

# 1 in = 2.54 cm
const heightCM = 182.88

const cmToInches = 2.54

const inchesInFeet = 12.0

const heightInches = heightCM / cmToInches

const heightFeet = heightInches / inchesInFeet

echo "Your height in CM: ", heightCM, " | Height in Inches: ", heightInches, " | Height in Feet: ", heightFeet

const firstName = "Jordan"
const lastName = "Ibanez"

var fullName = firstName & " " & lastName

echo fullName

#[
Alice earns $400 every 15 days. 
Bob earns $3.14 per hour and works 8 hours a day, 7 days a week. 
After 30 days, has Alice earned more than Bob? (Hint: use relational operators)
]#

var aliceEarningsBiMonthly = 400.0
var aliceEarningsDaily = aliceEarningsBiMonthly / 15.0

var bobEarningsHourly = 3.14
var bobHoursADay = 8.0
var bobEarningsDaily = bobEarningsHourly * bobHoursADay

let daysInMonth = 30.0

let aliceMonthly = aliceEarningsDaily * daysInMonth
let bobMonthly = bobEarningsDaily * daysInMonth

let aliceEarnsMoreThanBob = aliceMonthly > bobMonthly

echo "Does alice earn more than bob in a month? ", (if aliceEarnsMoreThanBob: "yes" else: "no")

let blah = "frank"

case blah
of "hi":
  echo "it's hi"
of "bye":
  echo "it's bye"


case 0:
of 1:
  echo "1"
of 2:
  echo "2"
else:
  discard

for letter in "Hello wurld":
  echo letter

echo "0000000000000000000000"

for index,letter in "world":
  echo "index ", index, " is letter ", letter

var i = 0

inc i
inc i
inc i

echo i
echo "---"

for i in 0..<10:
  echo i

echo "--"
  
echo i

var overFlowTest: uint8 = 123

while true:
  echo overFlowTest

  let oldVal = overFlowTest

  inc overFlowTest

  if oldVal > overFlowTest:
    break


var name = "jordan4ibanez"

for index,letter in name:
  case letter:
  of 'a','e','i','o','u':
    echo letter
  else:
    name[index] = '_'

echo name

var tester: uint8 = 0

while true:
  if tester mod 3 == 0 and tester mod 5 == 0:
    echo "fizzbuzz"
  elif tester mod 3 == 0:
    echo "fizz"
  elif tester mod 5 == 0:
    echo "buzz"
  else:
    echo tester



  let old = tester
  inc tester
  if old > tester:
    break


const sampleSize = 20
var inches = newSeq[float](sampleSize)
var centimeters = newSeq[float](sampleSize)

for index in 0..< sampleSize:
  inches[index] = (float)index

for index, inchMeasurement in inches:
  centimeters[index] = inchMeasurement * cmToInches

echo " _______________ "
echo "| inch  |  cm   |"
echo "|---------------|"

const maxWidth = 6

for index in 0..< sampleSize:
  let inch = ($inches[index]).alignLeft(maxWidth, ' ')

  let cm = ($centimeters[index]).alignLeft(maxWidth, ' ')

  echo "| ", inch, "| ", cm, '|'
  
echo " --------------- "