discrete and cominatorial math chapter 1_1

Run Settings
LanguageJulia
Language Version
Run Command
#/usr/bin/env julia function trafficMethod( way::String, from::String = "Hsinchu", to::String = "Taipei" )::Function return function () println("form $from to $to by $way") end end function count( a::Array, b::Array, ;rule = "product" )::Integer countA = length(a) countB = length(b) if countA <= 0 || countB <= 0 error("illegal input") end if rule == "sum" return countA + countB end if rule == "product" return countA * countB end error("I don't know the option of $rule mean !\n") end println(""" Ex: Frank wants to go to Taipei. He can choose from bus services or train services to head from home to Hsinchu . From there, he can choose from 2 bus services or 3 train services to head to Taipei. { bus: Kuo-Kuang Greyhound-Line , train: Amtrak Krtco Metro-Taipei } How many ways are there for Hsinchu to get to Taipei? """ ) byBus = [ trafficMethod("Kuo-Kuang") trafficMethod("Greyhound-Line") ] byTrain = [ trafficMethod("Amtrak") trafficMethod("Krtco") trafficMethod("Metro-Taipei") ] println( "We have $(count( byBus, byTrain , rule = "sum" ) ) way to reach it\n" ) println("The rule of product"); player = [ "rock" "paper" "scissors" ] println("Ex:\n How many situation of \"rock paper scissors\" game for two player") println("We have $( count( player, player ) ) situation")
Editor Settings
Theme
Key bindings
Full width
Lines