Skip to content

Instantly share code, notes, and snippets.

use std::io;
fn main() {
println!("Enter -1 to exit");
loop {
let n = get_isize("Enter a number: ");
if n == -1 {
break;
}
println!("fibonacci of {} is {}", n, fibonacci(n));
fn main() {
for n in 0..22 {
println!("{}! = {}", n, factorial(n));
}
}
fn factorial(n: isize) -> isize {
// base case
if n == 0 {
1
func CountBits(x int) int {
numBits := 0
for x != 0 {
numBits += x & 1
x >>= 1
}
return numBits
}
/*
Given a binary array, find the maximum number of consecutive 1s in the array
Input: [1, 1, 0, 1, 1, 1]
Output: 3
Note:
- the input array will contain 0 and 1
- the length of the input array is a positive integer and will not exceed 10,000
*/
# /Users/rhuber/.config/tmuxinator/portal.yml
name: portal
root: ~/Code/portal
# Optional tmux socket
# socket_name: foo
# Note that the pre and post options have been deprecated and will be replaced by
# project hooks.
"=========================================================================
" ~My vimrc~
"=========================================================================
"
" Author: Ryan Huber
"
"-------------------------------------------------------------------------
"
set nocompatible
set t_Co=256
func anchor(top: NSLayoutYAxisAnchor?, left: NSLayoutXAxisAnchor?, bottom: NSLayoutYAxisAnchor?, right: NSLayoutXAxisAnchor?, paddingTop: CGFloat, paddingLeft: CGFloat, paddingBottom: CGFloat, paddingRight: CGFloat, width: CGFloat, height: CGFloat) {
translatesAutoresizingMaskIntoConstraints = false
if let top = top {
self.topAnchor.constraint(equalTo: top, constant: paddingTop).isActive = true
}
if let left = left {
self.leftAnchor.constraint(equalTo: left, constant: paddingLeft).isActive = true
}
do_fizzbuzz = fn
(0, 0, _) -> "Fizzbuzz"
(0, _, _) -> "Fizz"
(_, 0, _) -> "Buzz"
(_, _, a) -> a
end
fizzbuzz = fn(n) -> do_fizzbuzz.(rem(n,3), rem(n,5), n) end
@rphuber
rphuber / switchVsIf.js
Created January 19, 2017 16:14
Switch vs if statement evaluation
if ((num % 3 === 0) && (num % 5 === 0)){
return 'fizzbuzz'
} else if (num % 3 === 0) {
return 'fizz'
} else if (num % 5 === 0) {
return 'buzz'
} else if (typeof num === 'number'){
return num
} else {
return false