ACQUIRING KNOWLEDGE WITH EXAMPLES




$ruby -rdebug euler-two.rb 
Debug.rb
Emacs support available.

/usr/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:57:        RUBYGEMS_ACTIVATION_MONITOR.enter
(rdb:1) r
/usr/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:57:        RUBYGEMS_ACTIVATION_MONITOR.enter
(rdb:1) 
r
/usr/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:57:        RUBYGEMS_ACTIVATION_MONITOR.enter
(rdb:1) next
/usr/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:143:    RUBYGEMS_ACTIVATION_MONITOR.exit
(rdb:1) next
euler-two.rb:3:n1, n2 = 1, 2
(rdb:1) next
euler-two.rb:4:sum = 0
(rdb:1) print n1
1nil
(rdb:1) print n2
2nil
(rdb:1) next
euler-two.rb:6:while n2 < 4000000
(rdb:1) print n2
2nil
(rdb:1) next
euler-two.rb:7:sum += (n2 % 2 == 0) ? n2 : 0
(rdb:1) next
euler-two.rb:7:sum += (n2 % 2 == 0) ? n2 : 0
(rdb:1) print sum
0nil
(rdb:1) next
euler-two.rb:8:n1, n2 = n2, (n1 + n2) # iterate through fibonacci seq
(rdb:1) print sum
2nil
(rdb:1) next
euler-two.rb:8:n1, n2 = n2, (n1 + n2) # iterate through fibonacci seq
(rdb:1) next
euler-two.rb:7:sum += (n2 % 2 == 0) ? n2 : 0
(rdb:1) next
euler-two.rb:7:sum += (n2 % 2 == 0) ? n2 : 0
(rdb:1) print sum
2nil
(rdb:1) next
euler-two.rb:8:n1, n2 = n2, (n1 + n2) # iterate through fibonacci seq
(rdb:1) print sum
2nil
(rdb:1) continue
/usr/lib/ruby/2.1.0/debug.rb:290:in `eval':undefined local variable or method `continue' for main:Object
	from /usr/lib/ruby/2.1.0/debug.rb:290:in `rescue in debug_eval'
	from /usr/lib/ruby/2.1.0/debug.rb:287:in `debug_eval'
	from /usr/lib/ruby/2.1.0/debug.rb:661:in `block in debug_command'
	from /usr/lib/ruby/2.1.0/debug.rb:400:in `catch'
	from /usr/lib/ruby/2.1.0/debug.rb:400:in `debug_command'
	from /usr/lib/ruby/2.1.0/debug.rb:859:in `trace_func'
	from /usr/lib/ruby/2.1.0/debug.rb:1085:in `block in '
	from euler-two.rb:8:in `
' (rdb:1) puts nil (rdb:1) puts sum 2 nil (rdb:1) puts n1 2 nil (rdb:1) puts n2 3 nil (rdb:1) quit Really quit? (y/n) y $
$python -m pdb euler-three.py 
> /home/jeffrin/beautifulwork/lib/euler-three.py(7)()
-> '''
(Pdb) r
6857
--Return--
> /home/jeffrin/beautifulwork/lib/euler-three.py(17)()->None
-> print n
(Pdb) next
--Return--
> (1)()->None
(Pdb) next
The program finished and will be restarted
> /home/jeffrin/beautifulwork/lib/euler-three.py(7)()
-> '''
(Pdb) next
> /home/jeffrin/beautifulwork/lib/euler-three.py(9)()
-> n = 600851475143
(Pdb) next
> /home/jeffrin/beautifulwork/lib/euler-three.py(11)()
-> i = 2
(Pdb) next
> /home/jeffrin/beautifulwork/lib/euler-three.py(12)()
-> while i * i < n:
(Pdb) print i
2
(Pdb) next
> /home/jeffrin/beautifulwork/lib/euler-three.py(13)()
-> while n % i == 0:
(Pdb) print n
600851475143
(Pdb) print n % i
1
(Pdb) next
> /home/jeffrin/beautifulwork/lib/euler-three.py(15)()
-> i = i + 1
(Pdb) print i
2
(Pdb) next
> /home/jeffrin/beautifulwork/lib/euler-three.py(12)()
-> while i * i < n:
(Pdb) next
> /home/jeffrin/beautifulwork/lib/euler-three.py(13)()
-> while n % i == 0:
(Pdb) print n % i
2
(Pdb) next
> /home/jeffrin/beautifulwork/lib/euler-three.py(15)()
-> i = i + 1
(Pdb) continue
6857
The program finished and will be restarted
> /home/jeffrin/beautifulwork/lib/euler-three.py(7)()
-> '''
(Pdb) 

$python -m pdb project-euler-2.py 
> /home/jeffrin/beautifulwork/lib/project-euler-2.py(13)()
-> '''
(Pdb) next
> /home/jeffrin/beautifulwork/lib/project-euler-2.py(15)()
-> cache = {}
(Pdb) next
> /home/jeffrin/beautifulwork/lib/project-euler-2.py(16)()
-> def fib(n):
(Pdb) next
> /home/jeffrin/beautifulwork/lib/project-euler-2.py(20)()
-> n = 0
(Pdb) next
> /home/jeffrin/beautifulwork/lib/project-euler-2.py(21)()
-> i = 0
(Pdb) next
> /home/jeffrin/beautifulwork/lib/project-euler-2.py(22)()
-> while fib(i) <= 4000000:
(Pdb) next
> /home/jeffrin/beautifulwork/lib/project-euler-2.py(23)()
-> if not fib(i) % 2: n = n + fib(i)
(Pdb) next
> /home/jeffrin/beautifulwork/lib/project-euler-2.py(24)()
-> i = i + 1
(Pdb) next
> /home/jeffrin/beautifulwork/lib/project-euler-2.py(22)()
-> while fib(i) <= 4000000:
(Pdb) next
> /home/jeffrin/beautifulwork/lib/project-euler-2.py(23)()
-> if not fib(i) % 2: n = n + fib(i)
(Pdb) next
> /home/jeffrin/beautifulwork/lib/project-euler-2.py(24)()
-> i = i + 1
(Pdb) continue
4613732
The program finished and will be restarted
> /home/jeffrin/beautifulwork/lib/project-euler-2.py(13)()
-> '''
(Pdb) 

http://www.bytemuse.com/post/fibonacci-spiral/

/* This program has been worked on from http://www.s-anand.net/euler.html */

#include <stdio.h>

sofmul()
{
int n, i;
n = 0;

for (i = 0 ; i < 1000 ; i++) {
if ( !(i % 5) || !(i % 3) )
n = n + i;
}

printf("Sum of the multiples of 3 and 5 below 1000 is %d \n", n);
}
(gdb) bt
#0  pthread_cond_timedwait@@GLIBC_2.3.2 () at ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S:238
#1  0x00007fb512be9443 in ?? ()
#2  0x00007fb512bc9d0d in ?? ()
#3  0x00007fb512bacb0f in ?? ()
#4  0x00007fb512bbc7d1 in ?? ()
#5  0x00007fb512baa03a in ?? ()
#6  0x00007fb51537aea8 in ?? ()
#7  0x00007fb512b7d045 in ?? ()
#8  0x00007fb512b7de1e in ?? ()
#9  0x00007fb512b7cc30 in ?? ()
#10 0x00007fb512569698 in ChromeMain ()
#11 0x00007fb50a541b45 in __libc_start_main (main=0x7fb512569650 <_start+308>, argc=4, argv=0x7fffb310c918, 
    init=, fini=, rtld_fini=, stack_end=0x7fffb310c908) at libc-start.c:287
#12 0x00007fb512569545 in _start ()

/* Part of this program copied from http://www.sanfoundry.com/c-program-multiply-number-4-using-bitwise-operators/ */

#include <stdio.h>

multbitwise()
{

long number;
printf("Enter an integer: ");
scanf("%ld",&number);
number = number << 2;
printf("Result is %ld \n",number);
}

/* http://stackoverflow.com/questions/4456442/interview-multiplication-of-2-integers-using-bitwise-operators */
/* http://www.geeksforgeeks.org/multiply-two-numbers-without-using-multiply-division-bitwise-operators-and-no-loops/ */
/* http://en.wikipedia.org/wiki/Bitwise_operation */
Copyright © 2009,  2010,  2011,  2012,  2013, 2014     BeautifulWork Project    e-mail:  ahiliation@yahoo.co.in
BeautifulWork Project comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law.