Page 1 of 1

## 8 Replies - 1588 Views - Last Post: 24 January 2010 - 07:30 AM

### #1 mostyfriedman

• The Algorithmi

Reputation: 729
• Posts: 4,473
• Joined: 24-October 08

Posted 21 April 2009 - 05:27 PM

Description: the function isprime finds if the number is prime or not
```isprime x | x == 2 = True
| mod x 2 == 0 = False
| divisibleByOdd x 3 == False = True
| otherwise = False

divisibleByOdd x y | mod x y == 0 = True
| y*y <= x = divisibleByOdd x (y+2)
| otherwise = False

```

Is This A Good Question/Topic? 0

## Replies To: prime number tester (HASKELL)

### #2 mostyfriedman

• The Algorithmi

Reputation: 729
• Posts: 4,473
• Joined: 24-October 08

## Re: prime number tester (HASKELL)

Posted 21 April 2009 - 05:27 PM

Description: the function isprime finds if the number is prime or not
```isprime x | x < 2 = False
| x == 2 || x == 3 = True
| mod x 2 == 0 = False
| divisibleByOdd x 3 == False = True
| otherwise = False

divisibleByOdd x y | mod x y == 0 = True
| y*y <= x = divisibleByOdd x (y+2)
| otherwise = False

```

### #3 Eman_321

Reputation: -1
• Posts: 2
• Joined: 24-January 10

## Re: prime number tester (HASKELL)

Posted 24 January 2010 - 07:18 AM

divisors :: Int -> [Int] divisors x = [x `div` n| n <- [x,x-1..1], x `mod`n==0&&x>=0] isPrime :: Int -> String isPrime x |divisors x == [1,x] ="A Prime Number" |x<=0 = error "Not a positive prime" |otherwise ="Not A Prime Number"

### #4 Eman_321

Reputation: -1
• Posts: 2
• Joined: 24-January 10

## Re: prime number tester (HASKELL)

Posted 24 January 2010 - 07:18 AM

divisors :: Int -> [Int] divisors x = [x `div` n| n <- [x,x-1..1], x `mod`n==0&&x>=0] isPrime :: Int -> String isPrime x |divisors x == [1,x] ="A Prime Number" |x<=0 = error "Not a positive prime" |otherwise ="Not A Prime Number"

### #5 Eman_321

Reputation: -1
• Posts: 2
• Joined: 24-January 10

## Re: prime number tester (HASKELL)

Posted 24 January 2010 - 07:20 AM

divisors :: Int -> [Int] divisors x = [x `div` n| n <- [x,x-1..1], x `mod`n==0&&x>=0] --isPrime is based on divisors isPrime :: Int -> String isPrime x |divisors x == [1,x] ="A Prime Number" |x<=0 = error "Not a positive prime" |otherwise ="Not A Prime Number"

### #6 Eman_321

Reputation: -1
• Posts: 2
• Joined: 24-January 10

## Re: prime number tester (HASKELL)

Posted 24 January 2010 - 07:20 AM

the full code isnt showin..why not =S?

### #7 Eman_321

Reputation: -1
• Posts: 2
• Joined: 24-January 10

## Re: prime number tester (HASKELL)

Posted 24 January 2010 - 07:23 AM

divisors :: Int -> [Int] divisors x = [x `div` n| n <- [x,x-1..1], x `mod`n==0&&x>=0] isPrime :: Int -> String isPrime x |divisors x == [1,x] ="A Prime Number" |x<=0 = error "Not a positive prime" |otherwise ="Not A Prime Number" ``` ```
``` ```
``` Was This Post Helpful? 0 ipb.global.registerReputation( 'rep_post_2106007', { app: 'forums', type: 'pid', typeid: '2106007' }, parseInt('0') ); Back to top MultiQuote Quote + Reply // Show multiquote for JS browsers \$('multiq_2106007').show(); if( \$('toggle_post_2106007') ) { \$('toggle_post_2106007').show(); } ```
``` ```
``` ```
``` ```
``` #8 Eman_321   New D.I.C Head Reputation: -1 Posts: 2 Joined: 24-January 10 ```
``` Re: prime number tester (HASKELL) Posted 24 January 2010 - 07:26 AM ```
``` how do i paste code in forum? ``` ``` isnt working ```
``` ```
``` Was This Post Helpful? 0 ipb.global.registerReputation( 'rep_post_2106008', { app: 'forums', type: 'pid', typeid: '2106008' }, parseInt('0') ); Back to top MultiQuote Quote + Reply // Show multiquote for JS browsers \$('multiq_2106008').show(); if( \$('toggle_post_2106008') ) { \$('toggle_post_2106008').show(); } ```
``` ```
``` #9 Eman_321   New D.I.C Head Reputation: -1 Posts: 2 Joined: 24-January 10 Re: prime number tester (HASKELL) Posted 24 January 2010 - 07:30 AM simpler way [code] divisors :: Int -> [Int] divisors x = [x `div` n| n <- [x,x-1..1], x `mod`n==0&&x>=0] isPrime :: Int -> String isPrime x |divisors x == [1,x] ="A Prime Number" |x<=0 = error "Not a positive prime" |otherwise ="Not A Prime Number" [code/] Was This Post Helpful? 0 ipb.global.registerReputation( 'rep_post_2106009', { app: 'forums', type: 'pid', typeid: '2106009' }, parseInt('0') ); Back to top MultiQuote Quote + Reply // Show multiquote for JS browsers \$('multiq_2106009').show(); if( \$('toggle_post_2106009') ) { \$('toggle_post_2106009').show(); } #10 Eman_321   New D.I.C Head Reputation: -1 Posts: 2 Joined: 24-January 10 Re: prime number tester (HASKELL) Posted 24 January 2010 - 07:30 AM what the...lol Was This Post Helpful? 0 ipb.global.registerReputation( 'rep_post_2106010', { app: 'forums', type: 'pid', typeid: '2106010' }, parseInt('0') ); Back to top MultiQuote Quote + Reply // Show multiquote for JS browsers \$('multiq_2106010').show(); if( \$('toggle_post_2106010') ) { \$('toggle_post_2106010').show(); } ← Previous Topic Functional Programming Snippets Next Topic → Page 1 of 1 ```
``` ```
``` .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; } Related TopicsbetaWhy Computer Science Students Cheat? - Interesting Read [Lisp] Check If A Number Is Prime Best And Most Popular Programming Languages For Doing Number Theory? Pre-alpha Demo Of A Super Lightweight Haskell Game Engine - Rendering / Game Engine In Haskell :) Q&A With The Experts [Lisp] Largest Prime Factor In Clojure Q&A- Answers Q And A With The Pros - The Answers - Our Pro's Answer Your Questions Interviewing For Software Tester Position - Help Project Euler Problems - Math/programming Challenges //<![CDATA[ // Lightbox Configuration LightboxOptions = Object.extend({ fileLoadingImage: 'https://dreamincode.net/forums/public/style_images/DIC/lightbox/loading.gif', fileBottomNavCloseImage: 'https://dreamincode.net/forums/public/style_images/DIC/lightbox/closelabel.gif', overlayOpacity: 0.8, // controls transparency of shadow overlay animate: true, // toggles resizing animations resizeSpeed: 7, // controls the speed of the image resizing animations (1=slowest and 10=fastest) borderSize: 10, //if you adjust the padding in the CSS, you will need to update this variable // When grouping images this is used to write: Image # of #. // Change it for non-english localization labelImage: "Image", labelOf: "of" }, window.LightboxOptions || {}); /* Watch for a lightbox image and set up our downloadbutton watcher */ document.observe('click', (function(event){ var target = event.findElement('a[rel^=lightbox]') || event.findElement('area[rel^=lightbox]'); if (target) { event.stop(); gbl_addDownloadButton(); } }).bind(this)); var _to = ''; var _last = ''; function gbl_addDownloadButton() { if ( typeof( ipsLightbox.lightboxImage ) != 'undefined' && ipsLightbox.lightboxImage.src ) { if ( _last != ipsLightbox.lightboxImage.src ) { if ( ! \$('gbl_d') ) { \$('bottomNav').insert( { top: "<div id='gbl_d' style='text-align:right;padding-bottom:4px;'></div>" } ); } \$('gbl_d').update( "<a href='"+ ipsLightbox.lightboxImage.src + "' target='_blank'><img src='https://dreamincode.net/forums/public/style_images/DIC/lightbox/download-icon.png' /></a>" ); _last = ipsLightbox.lightboxImage.src; } } /* Check for init and then keep checking for new image */ _to = setTimeout( "gbl_addDownloadButton()", 1000 ); } //]]> ```
` `
` `
``` General Discussion Caffeine Lounge Corner Cubicle Student Campus Software Development Industry News Introduce Yourself Nightmare.In.Code Programming Help C and C++ VB.NET Java C# Python PHP Mobile Development ASP.NET .NET Framework Ruby Game Development Assembly Databases ColdFusion VB6 Other Languages 52 Weeks Of Code Web Development Web Development HTML & CSS JavaScript Graphic Design Flash & ActionScript Blogging SEO & Advertising Web Servers & Hosting Site Check Follow & Share window.___gcfg = {lang: 'en'}; (function() {var po = document.createElement("script"); po.type = "text/javascript"; po.async = true;po.src = "https://apis.google.com/js/plusone.js"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(po, s); })(); Tutorials Programming C++ Tutorials Java Tutorials VisualBasic Tutorials VB.NET Tutorials C# Tutorials PHP Tutorials ColdFusion Tutorials Database Tutorials Web Development HTML Tutorials JavaScript Tutorials CSS Tutorials Flash Tutorials Photoshop Tutorials Reference Sheets Code Snippets C Snippets C++ Snippets Java Snippets Visual Basic Snippets C# Snippets VB.NET Snippets ASP.NET Snippets PHP Snippets Python Snippets Ruby Snippets ColdFusion Snippets SQL Snippets Assembly Snippets Functional Programming Snippets Perl Snippets HTML/CSS Snippets Javascript Snippets Flash/ActionScript Snippets ASP Snippets Linux, Unix, and Bash Snippets Other Languages Snippets Regex DIC Chatroom Join our IRC Chat Bye Bye Ads ```
``` FAQ | Team Blog | Feedback/Support | Advertising | Terms of Use | Privacy Policy | About Us Copyright 2001-2018 MediaGroup1 LLC, All Rights ReservedA MediaGroup1 LLC Production - Version 6.0.2.1.36Server: secure3 google.load('search', '1',{nocss: true}); jQuery(document).ready(function() { jQuery("#cse-search-box").submit(function () { var customSearchControl = new google.search.CustomSearchControl('000872085005376217422:zamd_7elal4'); customSearchControl.setLinkTarget(google.search.Search.LINK_TARGET_SELF); tb_show("Dream.In.Code Search Results - Powered By <img src='http://www.google.com/cse/images/google_custom_search_smwide.gif'>", "#TB_inline?height=480&width=800"); var drawOptions = new google.search.DrawOptions(); customSearchControl.draw(document.getElementById("TB_ajaxContent"), drawOptions); customSearchControl.execute(document.getElementById("query").value); return false; }); }); (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-69851-1', 'auto'); ga('send', 'pageview'); //AD BLOCK FOR JEREMY var test = document.createElement('div'); test.innerHTML = '&nbsp;'; test.className = 'adsbox'; document.body.appendChild(test); window.setTimeout(function() { if (test.offsetHeight === 0) { document.body.classList.add('adblock'); ga('send', 'event', 'Ad Setting', 'Adblock', 'Enabled'); } test.remove(); }, 400); _qoptions={ qacct:"p-d4Szpdj6xMw-o" }; function _dmBootstrap(file) { var _dma = document.createElement('script'); _dma.type = 'text/javascript'; _dma.async = true; _dma.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + file; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(_dma); } function _dmFollowup(file) { if (typeof DMAds === 'undefined') _dmBootstrap('cdn2.DeveloperMedia.com/a.min.js');} (function () { _dmBootstrap('cdn1.DeveloperMedia.com/a.min.js'); setTimeout(_dmFollowup, 2000);})(); ```
` SyntaxHighlighter.config.clipboardSwf = 'http://cdn.dreamincode.net/syntax/scripts/clipboard.swf'; SyntaxHighlighter.all(); `